-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ESNext by default, full ESM-CJS interop, max minification #1059
Changes from all commits
35a5d74
db60d46
38dd5bd
f15a624
03a48b8
399a00f
a7a956e
f9d4971
abcd457
caedfb3
5c166aa
99539a0
6ed56e3
873f4cf
a93d60e
0c393d3
f73f287
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
"templates" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.4.4", | ||
|
@@ -48,62 +48,62 @@ | |
"@babel/preset-env": "^7.11.0", | ||
"@babel/traverse": "^7.11.5", | ||
"@rollup/plugin-babel": "^5.1.0", | ||
"@rollup/plugin-commonjs": "^11.0.0", | ||
"@rollup/plugin-commonjs": "^19.0.0", | ||
"@rollup/plugin-json": "^4.0.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@rollup/plugin-replace": "^2.2.1", | ||
"@types/jest": "^25.2.1", | ||
"@typescript-eslint/eslint-plugin": "^2.12.0", | ||
"@typescript-eslint/parser": "^2.12.0", | ||
"@types/jest": "^26.0.24", | ||
"@typescript-eslint/eslint-plugin": "^4.28.2", | ||
"@typescript-eslint/parser": "^4.28.2", | ||
"ansi-escapes": "^4.2.1", | ||
"asyncro": "^3.0.0", | ||
"babel-eslint": "^10.0.3", | ||
"babel-plugin-annotate-pure-calls": "^0.4.0", | ||
"babel-plugin-dev-expression": "^0.2.1", | ||
"babel-plugin-macros": "^2.6.1", | ||
"babel-plugin-polyfill-regenerator": "^0.0.4", | ||
"babel-plugin-macros": "^3.1.0", | ||
"babel-plugin-polyfill-regenerator": "^0.2.2", | ||
"babel-plugin-transform-rename-import": "^2.3.0", | ||
"camelcase": "^6.0.0", | ||
"chalk": "^4.0.0", | ||
"enquirer": "^2.3.4", | ||
"eslint": "^6.1.0", | ||
"eslint": "^7.30.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"eslint-config-react-app": "^5.2.1", | ||
"eslint-plugin-flowtype": "^3.13.0", | ||
"eslint-config-react-app": "^6.0.0", | ||
"eslint-plugin-flowtype": "^5.8.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"eslint-plugin-react": "^7.14.3", | ||
"eslint-plugin-react-hooks": "^2.2.0", | ||
"execa": "^4.0.3", | ||
"fs-extra": "^9.0.0", | ||
"jest": "^25.3.0", | ||
"jest-watch-typeahead": "^0.5.0", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"execa": "^5.1.1", | ||
"fs-extra": "^10.0.0", | ||
"jest": "^27.0.6", | ||
"jest-watch-typeahead": "^0.6.4", | ||
"jpjs": "^1.2.1", | ||
"lodash.merge": "^4.6.2", | ||
"ora": "^4.0.3", | ||
"ora": "^5.4.1", | ||
"pascal-case": "^3.1.1", | ||
"prettier": "^1.19.1", | ||
"progress-estimator": "^0.2.2", | ||
"prettier": "^2.3.2", | ||
"progress-estimator": "^0.3.0", | ||
"regenerator-runtime": "^0.13.7", | ||
"rollup": "^1.32.1", | ||
"rollup": "^2.52.8", | ||
"rollup-plugin-sourcemaps": "^0.6.2", | ||
"rollup-plugin-terser": "^5.1.2", | ||
"rollup-plugin-typescript2": "^0.27.3", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"sade": "^1.4.2", | ||
"semver": "^7.1.1", | ||
"shelljs": "^0.8.3", | ||
"tiny-glob": "^0.2.6", | ||
"ts-jest": "^25.3.1", | ||
"tslib": "^1.9.3", | ||
"typescript": "^3.7.3" | ||
"ts-jest": "^27.0.3", | ||
"tslib": "^2.3.0", | ||
"typescript": "^4.3.5" | ||
}, | ||
"devDependencies": { | ||
"@types/eslint": "^6.1.2", | ||
"@types/eslint": "^7.2.14", | ||
"@types/fs-extra": "^9.0.1", | ||
"@types/lodash": "^4.14.161", | ||
"@types/node": "^14.11.1", | ||
"@types/react": "^16.9.11", | ||
"@types/node": "^16.0.1", | ||
"@types/react": "^17.0.14", | ||
"@types/rollup-plugin-json": "^3.0.2", | ||
"@types/sade": "^1.6.0", | ||
"@types/semver": "^7.1.0", | ||
|
@@ -112,18 +112,18 @@ | |
"autoprefixer": "^9.7.4", | ||
"babel-plugin-replace-identifiers": "^0.1.1", | ||
"cssnano": "^4.1.10", | ||
"doctoc": "^1.4.0", | ||
"husky": "^4.2.2", | ||
"np": "^6.4.0", | ||
"pretty-quick": "^2.0.0", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.13.0", | ||
"react-is": "^16.13.0", | ||
"doctoc": "^2.0.1", | ||
"husky": "^7.0.1", | ||
"np": "^7.5.0", | ||
"pretty-quick": "^3.1.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-is": "^17.0.2", | ||
"rollup-plugin-postcss": "^2.5.0", | ||
"styled-components": "^5.0.1", | ||
"tiny-invariant": "^1.1.0", | ||
"tiny-warning": "^1.0.3", | ||
"yarn-deduplicate": "^2.1.1" | ||
"yarn-deduplicate": "^3.1.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Package updates, do not cause test failures. |
||
}, | ||
"husky": { | ||
"hooks": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,15 +33,20 @@ export async function createRollupConfig( | |
...opts, | ||
}); | ||
|
||
const isEsm = opts.format.includes('es') || opts.format.includes('esm'); | ||
|
||
const shouldMinify = | ||
opts.minify !== undefined ? opts.minify : opts.env === 'production'; | ||
opts.minify !== undefined ? opts.minify : opts.env === 'production' || isEsm; | ||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minify ESM output also. |
||
|
||
let formatString = ['esm', 'cjs'].includes(opts.format) ? '' : opts.format; | ||
let fileExtension = opts.format === 'esm' ? 'mjs' : 'cjs'; | ||
|
||
const outputName = [ | ||
`${paths.appDist}/${safePackageName(opts.name)}`, | ||
opts.format, | ||
formatString, | ||
opts.env, | ||
shouldMinify ? 'min' : '', | ||
'js', | ||
fileExtension, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Encode ESM/CJS module status as |
||
] | ||
.filter(Boolean) | ||
.join('.'); | ||
|
@@ -102,14 +107,18 @@ export async function createRollupConfig( | |
esModule: Boolean(tsCompilerOptions?.esModuleInterop), | ||
name: opts.name || safeVariableName(opts.name), | ||
sourcemap: true, | ||
globals: { react: 'React', 'react-native': 'ReactNative' }, | ||
globals: { react: 'React', 'react-native': 'ReactNative', 'lodash-es': 'lodashEs', 'lodash/fp': 'lodashFp' }, | ||
jaredpalmer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exports: 'named', | ||
}, | ||
plugins: [ | ||
!!opts.extractErrors && { | ||
async transform(source: any) { | ||
await findAndRecordErrorCodes(source); | ||
return source; | ||
async transform(code: string) { | ||
try { | ||
await findAndRecordErrorCodes(code); | ||
} catch (e) { | ||
return null; | ||
} | ||
return { code, map: null }; | ||
}, | ||
}, | ||
resolve({ | ||
|
@@ -118,7 +127,7 @@ export async function createRollupConfig( | |
'main', | ||
opts.target !== 'node' ? 'browser' : undefined, | ||
].filter(Boolean) as string[], | ||
extensions: [...RESOLVE_DEFAULTS.extensions, '.jsx'], | ||
extensions: [...RESOLVE_DEFAULTS.extensions, '.cjs', '.mjs', '.jsx'], | ||
}), | ||
// all bundled external modules need to be converted from CJS to ESM | ||
commonjs({ | ||
|
@@ -189,30 +198,48 @@ export async function createRollupConfig( | |
extensions: [...DEFAULT_BABEL_EXTENSIONS, 'ts', 'tsx'], | ||
passPerPreset: true, | ||
custom: { | ||
targets: opts.target === 'node' ? { node: '10' } : undefined, | ||
targets: opts.target === 'node' ? { node: '14' } : undefined, | ||
extractErrors: opts.extractErrors, | ||
format: opts.format, | ||
}, | ||
babelHelpers: 'bundled', | ||
}), | ||
opts.env !== undefined && | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify(opts.env), | ||
}), | ||
replace({ | ||
preventAssignment: true, | ||
'process.env.NODE_ENV': JSON.stringify(opts.env), | ||
}), | ||
sourceMaps(), | ||
shouldMinify && | ||
terser({ | ||
sourcemap: true, | ||
output: { comments: false }, | ||
compress: { | ||
keep_infinity: true, | ||
pure_getters: true, | ||
passes: 10, | ||
}, | ||
ecma: 5, | ||
toplevel: opts.format === 'cjs', | ||
warnings: true, | ||
}), | ||
terser({ | ||
output: { comments: false }, | ||
compress: { | ||
keep_infinity: true, | ||
pure_getters: true, | ||
passes: 10, | ||
}, | ||
ecma: opts.legacy ? 5 : 2020, | ||
module: isEsm, | ||
toplevel: opts.format === 'cjs' || isEsm, | ||
warnings: true, | ||
}), | ||
/** | ||
* Ensure there's an empty default export to prevent runtime errors. | ||
* | ||
* @see https://www.npmjs.com/package/rollup-plugin-export-default | ||
*/ | ||
{ | ||
renderChunk: async (code: string, chunk: any) => { | ||
if (chunk.exports.includes('default') || !isEsm) { | ||
return null; | ||
} | ||
|
||
return { | ||
code: `${code}\nexport default {};`, | ||
map: null, | ||
}; | ||
}, | ||
}, | ||
], | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic assumes Node >14.