diff --git a/package.json b/package.json index 7912cc880..839c38e70 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "pretty-bytes": "5.5.0", "rimraf": "3.0.2", "rollup": "2.38.4", - "rollup-plugin-node-globals": "1.4.0", + "rollup-plugin-polyfill-node": "0.5.0", "rollup-plugin-terser": "7.0.2", "shelljs": "0.8.4", "snapshot-diff": "0.8.1", diff --git a/scripts/build/bundler.js b/scripts/build/bundler.js index 69349bb32..08d66c1e1 100644 --- a/scripts/build/bundler.js +++ b/scripts/build/bundler.js @@ -7,12 +7,11 @@ const webpack = require("webpack"); const { nodeResolve } = require("@rollup/plugin-node-resolve"); const rollupPluginAlias = require("@rollup/plugin-alias"); const commonjs = require("@rollup/plugin-commonjs"); -const nodeGlobals = require("rollup-plugin-node-globals"); +const rollupPluginPolyfillNode = require("rollup-plugin-polyfill-node"); const json = require("@rollup/plugin-json"); const replace = require("@rollup/plugin-replace"); const { terser } = require("rollup-plugin-terser"); const { babel } = require("@rollup/plugin-babel"); -const nativeShims = require("./rollup-plugins/native-shims"); const executable = require("./rollup-plugins/executable"); const evaluate = require("./rollup-plugins/evaluate"); const externals = require("./rollup-plugins/externals"); @@ -130,7 +129,8 @@ function getRollupConfig(bundle) { // ignore `MIXED_EXPORTS` warn warning.code === "MIXED_EXPORTS" || (warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.startsWith("node_modules")) + (warning.importer.startsWith("node_modules") || + warning.importer.startsWith("polyfill-node:"))) ) { return; } @@ -183,8 +183,6 @@ function getRollupConfig(bundle) { evaluate(), json(), rollupPluginAlias(alias), - bundle.target === "universal" && - nativeShims(path.resolve(__dirname, "shims")), nodeResolve({ extensions: [".js", ".json"], preferBuiltins: bundle.target === "node", @@ -199,7 +197,7 @@ function getRollupConfig(bundle) { requireReturnsDefault: "preferred", }), externals(bundle.externals), - bundle.target === "universal" && nodeGlobals(), + bundle.target === "universal" && rollupPluginPolyfillNode(), babel(babelConfig), bundle.minify !== false && bundle.target === "universal" && diff --git a/scripts/build/config.js b/scripts/build/config.js index b99ecd2f1..990734255 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -45,6 +45,9 @@ const parsers = [ "extra.projects = prepareAndTransformProjects(": "extra.projects = [] || prepareAndTransformProjects(", "process.versions.node": "'999.999.999'", + // `rollup-plugin-polyfill-node` don't have polyfill for these modules + 'require("perf_hooks")': "{}", + 'require("inspector")': "{}", }, }, { diff --git a/scripts/build/rollup-plugins/native-shims.js b/scripts/build/rollup-plugins/native-shims.js deleted file mode 100644 index b05ac7d76..000000000 --- a/scripts/build/rollup-plugins/native-shims.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; - -const fs = require("fs"); -const path = require("path"); -const builtins = require("builtin-modules"); - -const EMPTY = "export default {};"; -const PREFIX = "\0shim:"; - -module.exports = function (dir) { - return { - resolveId(importee) { - if (importee.startsWith(PREFIX)) { - return importee; - } - - if (/\0/.test(importee) || !builtins.includes(importee)) { - return null; - } - - const shim = path.resolve(dir, importee + ".mjs"); - if (fs.existsSync(shim)) { - return shim; - } - return PREFIX + importee; - }, - - load(id) { - if (id.startsWith(PREFIX)) { - return EMPTY; - } - }, - }; -}; diff --git a/yarn.lock b/yarn.lock index 591822cc6..585e07f64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1365,6 +1365,15 @@ magic-string "^0.25.7" resolve "^1.17.0" +"@rollup/plugin-inject@^4.0.0": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@rollup/plugin-inject/-/plugin-inject-4.0.2.tgz#55b21bb244a07675f7fdde577db929c82fc17395" + integrity sha512-TSLMA8waJ7Dmgmoc8JfPnwUwVZgLjjIAM6MqeIFqPO2ODK36JqE0Cf2F54UTgCUuW8da93Mvoj75a6KAVWgylw== + dependencies: + "@rollup/pluginutils" "^3.0.4" + estree-walker "^1.0.1" + magic-string "^0.25.5" + "@rollup/plugin-json@4.1.0": version "4.1.0" resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3" @@ -1392,7 +1401,7 @@ "@rollup/pluginutils" "^3.1.0" magic-string "^0.25.7" -"@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0": +"@rollup/pluginutils@^3.0.4", "@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== @@ -1814,11 +1823,6 @@ acorn-walk@^7.1.1: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc" integrity sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA== -acorn@^5.7.3: - version "5.7.4" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e" - integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg== - acorn@^7.1.1, acorn@^7.4.0: version "7.4.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c" @@ -2222,11 +2226,6 @@ bser@2.1.1: dependencies: node-int64 "^0.4.0" -buffer-es6@^4.9.3: - version "4.9.3" - resolved "https://registry.yarnpkg.com/buffer-es6/-/buffer-es6-4.9.3.tgz#f26347b82df76fd37e18bcb5288c4970cfd5c404" - integrity sha1-8mNHuC33b9N+GLy1KIxJcM/VxAQ= - buffer-from@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" @@ -3225,16 +3224,6 @@ estraverse@^5.2.0: resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880" integrity sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ== -estree-walker@^0.5.2: - version "0.5.2" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39" - integrity sha512-XpCnW/AE10ws/kDAs37cngSkvgIR8aN3G0MS85m7dUpuK2EREo9VJ00uvw6Dg/hXEpfsE1I1TvJOJr+Z+TL+ig== - -estree-walker@^0.6.1: - version "0.6.1" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" - integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== - estree-walker@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" @@ -5095,14 +5084,7 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -magic-string@^0.22.5: - version "0.22.5" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.22.5.tgz#8e9cf5afddf44385c1da5bc2a6a0dbd10b03657e" - integrity sha512-oreip9rJZkzvA8Qzk9HFs8fZGF/u7H/gtrE8EN6RjKJ9kh2HlC+yQ2QezifqTZfGyiuAV0dRv5a+y/8gBb1m9w== - dependencies: - vlq "^0.2.2" - -magic-string@^0.25.7: +magic-string@^0.25.5, magic-string@^0.25.7: version "0.25.7" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051" integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA== @@ -5847,11 +5829,6 @@ pretty-format@^26.6.2: ansi-styles "^4.0.0" react-is "^17.0.1" -process-es6@^0.11.6: - version "0.11.6" - resolved "https://registry.yarnpkg.com/process-es6/-/process-es6-0.11.6.tgz#c6bb389f9a951f82bd4eb169600105bd2ff9c778" - integrity sha1-xrs4n5qVH4K9TrFpYAEFvS/5x3g= - progress@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" @@ -6220,17 +6197,12 @@ rimraf@3.0.2, rimraf@^3.0.0, rimraf@^3.0.2: dependencies: glob "^7.1.3" -rollup-plugin-node-globals@1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-node-globals/-/rollup-plugin-node-globals-1.4.0.tgz#5e1f24a9bb97c0ef51249f625e16c7e61b7c020b" - integrity sha512-xRkB+W/m1KLIzPUmG0ofvR+CPNcvuCuNdjVBVS7ALKSxr3EDhnzNceGkGi1m8MToSli13AzKFYH4ie9w3I5L3g== +rollup-plugin-polyfill-node@0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-polyfill-node/-/rollup-plugin-polyfill-node-0.5.0.tgz#afa87f9105233963b89b0f74a2baaac53ab8a232" + integrity sha512-CYPf4vKeZG5w/Ut7TR1lEMKiBT2pHfj1RLnk92whXKFtT8IGkm+TydwgDNpgTXBCI4V528YijyFVMz4dKcR3AA== dependencies: - acorn "^5.7.3" - buffer-es6 "^4.9.3" - estree-walker "^0.5.2" - magic-string "^0.22.5" - process-es6 "^0.11.6" - rollup-pluginutils "^2.3.1" + "@rollup/plugin-inject" "^4.0.0" rollup-plugin-terser@7.0.2: version "7.0.2" @@ -6242,13 +6214,6 @@ rollup-plugin-terser@7.0.2: serialize-javascript "^4.0.0" terser "^5.0.0" -rollup-pluginutils@^2.3.1: - version "2.8.2" - resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" - integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ== - dependencies: - estree-walker "^0.6.1" - rollup@2.38.4: version "2.38.4" resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.38.4.tgz#1b84ea8728c73b1a00a6a6e9c630ec8c3fe48cea" @@ -7245,11 +7210,6 @@ vfile@^4.0.0: unist-util-stringify-position "^2.0.0" vfile-message "^2.0.0" -vlq@^0.2.2: - version "0.2.3" - resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26" - integrity sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow== - vnopts@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/vnopts/-/vnopts-1.0.2.tgz#f6a331473de0179d1679112cc090572b695202f7"