Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
15cafaa
feat(bundle): add exports for test-helpers
joshblack Oct 10, 2022
10ef920
Merge branch 'main' into fix/update-utils-entrypoint
joshblack Oct 10, 2022
e77dc50
chore: update input pattern
joshblack Oct 10, 2022
f182b58
Merge branch 'fix/update-utils-entrypoint' of github.com:primer/react…
joshblack Oct 10, 2022
f0480dd
chore: ignore theme-preval
joshblack Oct 10, 2022
2c3709a
chore: add changeset
joshblack Oct 10, 2022
dd4caea
Merge branch 'main' into fix/update-utils-entrypoint
joshblack Oct 10, 2022
28a9981
docs: update comments
joshblack Oct 10, 2022
cced056
Merge branch 'fix/update-utils-entrypoint' of github.com:primer/react…
joshblack Oct 10, 2022
8f92b57
Update rollup.config.js
joshblack Oct 11, 2022
c2eff70
Merge branch 'main' into fix/update-utils-entrypoint
joshblack Oct 11, 2022
7c6368a
chore: remove fast-glob dep
joshblack Oct 11, 2022
f4ffad0
fix: add support for hooks, polyfills, and utils
joshblack Oct 11, 2022
9105703
chore: add ignore patterns
joshblack Oct 11, 2022
b06fd3f
Merge branch 'main' into fix/update-utils-entrypoint
joshblack Oct 11, 2022
c74a0b3
fix: add constants so all members are exported
joshblack Oct 11, 2022
865e41f
Merge branch 'fix/update-utils-entrypoint' of github.com:primer/react…
joshblack Oct 11, 2022
6a6c2e6
fix: update rollup config to not process process.env.NODE_ENV outside…
joshblack Oct 11, 2022
0095409
refactor(rollup): inline babel config to prevent commonjs transform f…
joshblack Oct 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-eagles-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Refactor rollup to support all lib-esm/\* export patterns and include utils entrypoint
103 changes: 90 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-commonjs": "22.0.2",
"@rollup/plugin-node-resolve": "14.1.0",
"@rollup/plugin-replace": "5.0.0",
"@rollup/plugin-typescript": "8.5.0",
"@size-limit/preset-big-lib": "7.0.3",
"@storybook/addon-a11y": "6.5.9",
Expand Down Expand Up @@ -169,6 +170,7 @@
"eslint-plugin-primer-react": "0.7.4",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
"fast-glob": "3.2.12",
"front-matter": "4.0.2",
"husky": "7.0.4",
"jest": "29.0.1",
Expand Down
90 changes: 84 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,59 @@
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import glob from 'fast-glob'
import {terser} from 'rollup-plugin-terser'
import visualizer from 'rollup-plugin-visualizer'
import packageJson from './package.json'

const input = new Set([
// "exports"
// "."
'src/index.ts',

// "./drafts"
'src/drafts/index.ts',

// "./deprecated"
'src/deprecated/index.ts',

// Make sure all members are exported
'src/constants.ts',

...glob.sync(
[
// "./lib-esm/hooks/*"
'src/hooks/*',

// "./lib-esm/polyfills/*"
'src/polyfills/*',

// "./lib-esm/utils/*"
'src/utils/*'
],
{
cwd: __dirname,
ignore: [
'**/__tests__/**',
'*.stories.tsx',

// File currently imports from package.json
'src/utils/test-deprecations.tsx',

// Files use dependencies which are not listed by package
'src/utils/testing.tsx',
'src/utils/test-matchers.tsx'
]
}
)
])

const extensions = ['.js', '.jsx', '.ts', '.tsx']
const external = [
...Object.keys(packageJson.peerDependencies),
...Object.keys(packageJson.dependencies),
...Object.keys(packageJson.devDependencies)
...Object.keys(packageJson.peerDependencies ?? {}),
...Object.keys(packageJson.dependencies ?? {}),
...Object.keys(packageJson.devDependencies ?? {})
]
function isExternal(external) {
return id => {
Expand All @@ -36,15 +80,41 @@ function isExternal(external) {
}

const baseConfig = {
input: ['src/index.ts', 'src/drafts/index.ts', 'src/deprecated/index.ts'],
input: Array.from(input),
plugins: [
// Note: it's important that the babel plugin is ordered first for plugins
// like babel-plugin-preval to work as-intended
babel({
extensions,
exclude: /node_modules/,
babelHelpers: 'inline',
babelrc: false
babelrc: false,
configFile: false,
presets: [
'@babel/preset-typescript',
[
'@babel/preset-react',
{
modules: false
}
]
],
plugins: [
'macros',
'preval',
'add-react-displayname',
'babel-plugin-styled-components',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
[
'babel-plugin-transform-replace-expressions',
{
replace: {
__DEV__: "process.env.NODE_ENV !== 'production'"
}
}
]
]
}),
commonjs(),
resolve({
Expand Down Expand Up @@ -84,7 +154,15 @@ export default [
...baseConfig,
input: 'src/index.ts',
external: ['styled-components', 'react', 'react-dom'],
plugins: [...baseConfig.plugins, terser(), visualizer({sourcemap: true})],
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true
}),
...baseConfig.plugins,
terser(),
visualizer({sourcemap: true})
],
output: ['esm', 'umd'].map(format => ({
file: `dist/browser.${format}.js`,
format,
Expand Down
2 changes: 1 addition & 1 deletion script/build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -e
npm run clean

# Bundle
npx cross-env NODE_ENV=production rollup -c
npx rollup -c

# Type check
npx tsc --project tsconfig.build.json
Expand Down