Skip to content

Commit

Permalink
Update @rollup/plugin-node-resolve (#13080)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 31, 2021
1 parent 8d4da69 commit 8b137c6
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 143 deletions.
258 changes: 137 additions & 121 deletions Gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -268,129 +268,144 @@ const babelVersion =
function buildRollup(packages, targetBrowsers) {
const sourcemap = process.env.NODE_ENV === "production";
return Promise.all(
packages.map(async ({ src, format, dest, name, filename }) => {
const pkgJSON = require("./" + src + "/package.json");
const version = pkgJSON.version + versionSuffix;
const { dependencies = {}, peerDependencies = {} } = pkgJSON;
const external = Object.keys(dependencies).concat(
Object.keys(peerDependencies)
);
let nodeResolveBrowser = false,
babelEnvName = "rollup";
switch (src) {
case "packages/babel-standalone":
nodeResolveBrowser = true;
babelEnvName = "standalone";
break;
}
const input = getIndexFromPackage(src);
fancyLog(`Compiling '${chalk.cyan(input)}' with rollup ...`);
const bundle = await rollup({
input,
external,
onwarn(warning, warn) {
if (warning.code === "CIRCULAR_DEPENDENCY") return;
if (warning.code === "UNUSED_EXTERNAL_IMPORT") {
warn(warning);
return;
}

// We use console.warn here since it prints more info than just "warn",
// in case we want to stop throwing for a specific message.
console.warn(warning);

// https://github.com/babel/babel/pull/12011#discussion_r540434534
throw new Error("Rollup aborted due to warnings above");
},
plugins: [
rollupBabelSource(),
rollupReplace({
preventAssignment: true,
values: {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
BABEL_VERSION: JSON.stringify(babelVersion),
VERSION: JSON.stringify(version),
},
}),
rollupCommonJs({
include: [
/node_modules/,
"packages/babel-runtime/regenerator/**",
"packages/babel-preset-env/data/*.js",
// Rollup doesn't read export maps, so it loads the cjs fallback
"packages/babel-compat-data/*.js",
"packages/*/src/**/*.cjs",
// See the comment in this file for the reason to include it
"packages/babel-standalone/src/dynamic-require-entrypoint.cjs",
],
dynamicRequireTargets: [
// https://github.com/mathiasbynens/regexpu-core/blob/ffd8fff2e31f4597f6fdfee75d5ac1c5c8111ec3/rewrite-pattern.js#L48
resolveChain(
import.meta.url,
"./packages/babel-helper-create-regexp-features-plugin",
"regexpu-core",
"regenerate-unicode-properties"
) + "/**/*.js",
],
}),
rollupBabel({
envName: babelEnvName,
babelrc: false,
babelHelpers: "bundled",
extends: "./babel.config.js",
extensions: [".ts", ".js", ".mjs", ".cjs"],
}),
rollupNodeResolve({
extensions: [".ts", ".js", ".mjs", ".cjs", ".json"],
browser: nodeResolveBrowser,
preferBuiltins: true,
}),
rollupJson(),
targetBrowsers &&
rollupNodePolyfills({
sourceMap: sourcemap,
include: "**/*.{js,cjs,ts}",
}),
].filter(Boolean),
});

const outputFile = path.join(src, dest, filename || "index.js");
await bundle.write({
file: outputFile,
format,
name,
sourcemap: sourcemap,
exports: "named",
});

if (!process.env.IS_PUBLISH) {
fancyLog(
chalk.yellow(
`Skipped minification of '${chalk.cyan(
outputFile
)}' because not publishing`
)
packages.map(
async ({ src, format, dest, name, filename, envName = "rollup" }) => {
const pkgJSON = require("./" + src + "/package.json");
const version = pkgJSON.version + versionSuffix;
const { dependencies = {}, peerDependencies = {} } = pkgJSON;
const external = Object.keys(dependencies).concat(
Object.keys(peerDependencies)
);
return undefined;
}
fancyLog(`Minifying '${chalk.cyan(outputFile)}'...`);

await bundle.write({
file: outputFile.replace(/\.js$/, ".min.js"),
format,
name,
sourcemap: sourcemap,
exports: "named",
plugins: [
rollupTerser({
// workaround https://bugs.webkit.org/show_bug.cgi?id=212725
output: {
ascii_only: true,
},
}),
],
});
})
const input = getIndexFromPackage(src);
fancyLog(`Compiling '${chalk.cyan(input)}' with rollup ...`);
const bundle = await rollup({
input,
external,
onwarn(warning, warn) {
if (warning.code === "CIRCULAR_DEPENDENCY") return;
if (warning.code === "UNUSED_EXTERNAL_IMPORT") {
warn(warning);
return;
}

// Rollup warns about using babel.default at
// https://github.com/babel/babel-polyfills/blob/4ac92be5b70b13e3d8a34614d8ecd900eb3f40e4/packages/babel-helper-define-polyfill-provider/src/types.js#L5
// We can safely ignore this warning, and let Rollup replace it with undefined.
if (
warning.code === "MISSING_EXPORT" &&
warning.exporter === "packages/babel-core/src/index.ts" &&
warning.missing === "default" &&
[
"@babel/helper-define-polyfill-provider",
"babel-plugin-polyfill-corejs2",
"babel-plugin-polyfill-corejs3",
"babel-plugin-polyfill-regenerator",
].some(pkg => warning.importer.includes(pkg))
) {
return;
}

// We use console.warn here since it prints more info than just "warn",
// in case we want to stop throwing for a specific message.
console.warn(warning);

// https://github.com/babel/babel/pull/12011#discussion_r540434534
throw new Error("Rollup aborted due to warnings above");
},
plugins: [
rollupBabelSource(),
rollupReplace({
preventAssignment: true,
values: {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
BABEL_VERSION: JSON.stringify(babelVersion),
VERSION: JSON.stringify(version),
},
}),
rollupCommonJs({
include: [
/node_modules/,
"packages/babel-runtime/regenerator/**",
"packages/babel-preset-env/data/*.js",
// Rollup doesn't read export maps, so it loads the cjs fallback
"packages/babel-compat-data/*.js",
"packages/*/src/**/*.cjs",
// See the comment in this file for the reason to include it
"packages/babel-standalone/src/dynamic-require-entrypoint.cjs",
],
dynamicRequireTargets: [
// https://github.com/mathiasbynens/regexpu-core/blob/ffd8fff2e31f4597f6fdfee75d5ac1c5c8111ec3/rewrite-pattern.js#L48
resolveChain(
import.meta.url,
"./packages/babel-helper-create-regexp-features-plugin",
"regexpu-core",
"regenerate-unicode-properties"
) + "/**/*.js",
],
}),
rollupBabel({
envName,
babelrc: false,
babelHelpers: "bundled",
extends: "./babel.config.js",
extensions: [".ts", ".js", ".mjs", ".cjs"],
}),
rollupNodeResolve({
extensions: [".ts", ".js", ".mjs", ".cjs", ".json"],
browser: targetBrowsers,
exportConditions: targetBrowsers ? ["browser"] : [],
// It needs to be set to 'false' when using rollupNodePolyfills
// https://github.com/rollup/plugins/issues/772
preferBuiltins: !targetBrowsers,
}),
rollupJson(),
targetBrowsers &&
rollupNodePolyfills({
sourceMap: sourcemap,
include: "**/*.{js,cjs,ts}",
}),
].filter(Boolean),
});

const outputFile = path.join(src, dest, filename || "index.js");
await bundle.write({
file: outputFile,
format,
name,
sourcemap: sourcemap,
exports: "named",
});

if (!process.env.IS_PUBLISH) {
fancyLog(
chalk.yellow(
`Skipped minification of '${chalk.cyan(
outputFile
)}' because not publishing`
)
);
return undefined;
}
fancyLog(`Minifying '${chalk.cyan(outputFile)}'...`);

await bundle.write({
file: outputFile.replace(/\.js$/, ".min.js"),
format,
name,
sourcemap: sourcemap,
exports: "named",
plugins: [
rollupTerser({
// workaround https://bugs.webkit.org/show_bug.cgi?id=212725
output: {
ascii_only: true,
},
}),
],
});
}
)
);
}

Expand Down Expand Up @@ -452,6 +467,7 @@ const standaloneBundle = [
filename: "babel.js",
dest: "",
version: babelVersion,
envName: "standalone",
},
];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rollup/plugin-babel": "^5.2.0",
"@rollup/plugin-commonjs": "patch:@rollup/plugin-commonjs@^17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.4.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
Expand Down
26 changes: 5 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3905,9 +3905,9 @@ __metadata:
languageName: node
linkType: hard

"@rollup/plugin-node-resolve@npm:^11.2.0":
version: 11.2.0
resolution: "@rollup/plugin-node-resolve@npm:11.2.0"
"@rollup/plugin-node-resolve@npm:^11.2.0, @rollup/plugin-node-resolve@npm:^11.2.1":
version: 11.2.1
resolution: "@rollup/plugin-node-resolve@npm:11.2.1"
dependencies:
"@rollup/pluginutils": ^3.1.0
"@types/resolve": 1.17.1
Expand All @@ -3917,23 +3917,7 @@ __metadata:
resolve: ^1.19.0
peerDependencies:
rollup: ^1.20.0||^2.0.0
checksum: 173bb5822b8a6fd3a2c09303efd437711062885099dd1a4a6e91b449b99fcf5a4dc43e7d3836edeaca85ef7235547a193a3011314298ecbc529e8b123c371718
languageName: node
linkType: hard

"@rollup/plugin-node-resolve@npm:^9.0.0":
version: 9.0.0
resolution: "@rollup/plugin-node-resolve@npm:9.0.0"
dependencies:
"@rollup/pluginutils": ^3.1.0
"@types/resolve": 1.17.1
builtin-modules: ^3.1.0
deepmerge: ^4.2.2
is-module: ^1.0.0
resolve: ^1.17.0
peerDependencies:
rollup: ^1.20.0||^2.0.0
checksum: 34576bbd9cfb096ed6fcce256e9210995144ccfd352ef09134507a7c6b479cee20da2896525ebf8bf139d9a31e8eec4b6787ed9de3209ee6610a949dc9f7c268
checksum: ae1bed46a949a1d8c077e021751c0140a523f731bea464ed0bfc3d335096493d1638be2a756f72d96f1f3a00fbdad8ba8fad8e86381d3eafce5ea2dffd62f175
languageName: node
linkType: hard

Expand Down Expand Up @@ -5622,7 +5606,7 @@ __metadata:
"@rollup/plugin-babel": ^5.2.0
"@rollup/plugin-commonjs": "patch:@rollup/plugin-commonjs@^17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch"
"@rollup/plugin-json": ^4.1.0
"@rollup/plugin-node-resolve": ^9.0.0
"@rollup/plugin-node-resolve": ^11.2.1
"@rollup/plugin-replace": ^2.4.0
"@typescript-eslint/eslint-plugin": ^4.18.0
"@typescript-eslint/parser": ^4.18.0
Expand Down

0 comments on commit 8b137c6

Please sign in to comment.