diff --git a/eslint.config.mjs b/eslint.config.mjs index 6c7f9329f40..b8d0a370c1c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -21,6 +21,7 @@ export default defineConfig([ "!test/helpers/*.*", "!test/benchmarkCases/**/*.mjs", "!test/_helpers/**/*.mjs", + "!test/runner/*.js", "test/js/**/*.*", // TODO fix me @@ -83,12 +84,6 @@ export default defineConfig([ } ], // TODO enable me in future - "unicorn/prefer-regexp-test": "off", - "unicorn/prefer-string-slice": "off", - // TODO false positive, need to fix in upstream - "n/prefer-node-protocol": "off", - "n/prefer-global/url": "off", - // TODO enable me in future "prefer-destructuring": "off" } }, @@ -159,6 +154,9 @@ export default defineConfig([ // TODO enable me strict: "off", + // Some our tests contain `package.json` without `engines`, but tests should work on Node.js@10, so let's disable it + "n/prefer-node-protocol": "off", + // No need here, we have custom test logic, so except can be placed in different places "jest/no-standalone-expect": "off", diff --git a/examples/aggressive-merging/README.md b/examples/aggressive-merging/README.md index c0bc4af2f51..b9aeaeda38a 100644 --- a/examples/aggressive-merging/README.md +++ b/examples/aggressive-merging/README.md @@ -29,6 +29,8 @@ a big file... # webpack.config.js ```javascript +"use strict"; + const path = require("path"); const { AggressiveMergingPlugin } = require("../..").optimize; diff --git a/examples/asset-advanced/README.md b/examples/asset-advanced/README.md index 97adf3553d7..b86fde490b2 100644 --- a/examples/asset-advanced/README.md +++ b/examples/asset-advanced/README.md @@ -38,6 +38,8 @@ function createImageElement(title, src) { # webpack.config.js ```javascript +"use strict"; + const svgToMiniDataURI = require("mini-svg-data-uri"); module.exports = { diff --git a/examples/asset-simple/README.md b/examples/asset-simple/README.md index 527218ad84d..d6938aa4875 100644 --- a/examples/asset-simple/README.md +++ b/examples/asset-simple/README.md @@ -40,6 +40,8 @@ function createImageElement(title, src) { # webpack.config.js ```javascript +"use strict"; + module.exports = { output: { assetModuleFilename: "images/[hash][ext]" diff --git a/examples/build-http/README.md b/examples/build-http/README.md index c3c27026d94..edb0bfc3d7a 100644 --- a/examples/build-http/README.md +++ b/examples/build-http/README.md @@ -14,6 +14,8 @@ console.log(pMap4); # webpack.config.js ```javascript +"use strict"; + module.exports = { // enable debug logging to see network requests! // stats: { diff --git a/examples/chunkhash/README.md b/examples/chunkhash/README.md index e4ac3316ec8..576efa241e3 100644 --- a/examples/chunkhash/README.md +++ b/examples/chunkhash/README.md @@ -18,6 +18,8 @@ import("./async2"); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/code-splitting-depend-on-advanced/README.md b/examples/code-splitting-depend-on-advanced/README.md index 02b267a07fe..a3c2c1e05d5 100644 --- a/examples/code-splitting-depend-on-advanced/README.md +++ b/examples/code-splitting-depend-on-advanced/README.md @@ -3,6 +3,8 @@ This example shows how to use Code Splitting with entrypoint dependOn # webpack.config.js ```javascript +"use strict"; + module.exports = { entry: { app: { import: "./app.js", dependOn: ["other-vendors"] }, diff --git a/examples/code-splitting-depend-on-simple/README.md b/examples/code-splitting-depend-on-simple/README.md index f1e53d3e8cc..d990b929071 100644 --- a/examples/code-splitting-depend-on-simple/README.md +++ b/examples/code-splitting-depend-on-simple/README.md @@ -3,6 +3,8 @@ This example shows how to use Code Splitting with entrypoint dependOn # webpack.config.js ```javascript +"use strict"; + module.exports = { entry: { app: { import: "./app.js", dependOn: ["react-vendors"] }, diff --git a/examples/common-chunk-and-vendor-chunk/README.md b/examples/common-chunk-and-vendor-chunk/README.md index 546405907d3..1601bb51c85 100644 --- a/examples/common-chunk-and-vendor-chunk/README.md +++ b/examples/common-chunk-and-vendor-chunk/README.md @@ -34,6 +34,8 @@ With this bundle configuration, you would load your third party libraries, then # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/common-chunk-grandchildren/README.md b/examples/common-chunk-grandchildren/README.md index 4e26fc1d676..0f1ab21193f 100644 --- a/examples/common-chunk-grandchildren/README.md +++ b/examples/common-chunk-grandchildren/README.md @@ -83,6 +83,7 @@ module.exports = function() { ```javascript "use strict"; + const path = require("path"); module.exports = { diff --git a/examples/custom-json-modules/README.md b/examples/custom-json-modules/README.md index 98eddf55da7..a1d27c469be 100644 --- a/examples/custom-json-modules/README.md +++ b/examples/custom-json-modules/README.md @@ -62,8 +62,10 @@ document.querySelector('#app').innerHTML = [toml, yaml, json].map(data => ` # webpack.config.js ```javascript -const toml = require("toml"); +"use strict"; + const json5 = require("json5"); +const toml = require("toml"); const yaml = require("yamljs"); module.exports = { diff --git a/examples/dll-entry-only/README.md b/examples/dll-entry-only/README.md index 90d1499f19b..7b73d0cf1a0 100644 --- a/examples/dll-entry-only/README.md +++ b/examples/dll-entry-only/README.md @@ -34,6 +34,8 @@ export { c } from "./cjs"; # webpack.config.js ```javascript +"use strict"; + const path = require("path"); const webpack = require("../../"); diff --git a/examples/dll-user/README.md b/examples/dll-user/README.md index e0007dd0677..bcb37afce9e 100644 --- a/examples/dll-user/README.md +++ b/examples/dll-user/README.md @@ -7,6 +7,8 @@ This is the _user_ bundle, which uses the manifest from [dll-reference example]( # webpack.config.js ```javascript +"use strict"; + const path = require("path"); const webpack = require("../../"); @@ -47,18 +49,18 @@ console.log(require("module")); /* 0 */, /* 1 */ /*!**************************************************************************!*\ - !*** delegated ./alpha.js from dll-reference alpha_2239422b902ff2ef1cc1 ***! + !*** delegated ./alpha.js from dll-reference alpha_a1d5c7116e082d77ec3e ***! \**************************************************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -module.exports = (__webpack_require__(/*! dll-reference alpha_2239422b902ff2ef1cc1 */ 2))(1); +module.exports = (__webpack_require__(/*! dll-reference alpha_a1d5c7116e082d77ec3e */ 2))(1); /***/ }), /* 2 */ /*!*********************************************!*\ - !*** external "alpha_2239422b902ff2ef1cc1" ***! + !*** external "alpha_a1d5c7116e082d77ec3e" ***! \*********************************************/ /*! dynamic exports */ /*! exports [maybe provided (runtime-defined)] [no usage info] */ @@ -66,34 +68,34 @@ module.exports = (__webpack_require__(/*! dll-reference alpha_2239422b902ff2ef1c /***/ ((module) => { "use strict"; -module.exports = alpha_2239422b902ff2ef1cc1; +module.exports = alpha_a1d5c7116e082d77ec3e; /***/ }), /* 3 */ /*!**********************************************************************!*\ - !*** delegated ./a.js from dll-reference alpha_2239422b902ff2ef1cc1 ***! + !*** delegated ./a.js from dll-reference alpha_a1d5c7116e082d77ec3e ***! \**********************************************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -module.exports = (__webpack_require__(/*! dll-reference alpha_2239422b902ff2ef1cc1 */ 2))(2); +module.exports = (__webpack_require__(/*! dll-reference alpha_a1d5c7116e082d77ec3e */ 2))(2); /***/ }), /* 4 */ /*!************************************************************************!*\ - !*** delegated ./beta.js from dll-reference beta_2239422b902ff2ef1cc1 ***! + !*** delegated ./beta.js from dll-reference beta_a1d5c7116e082d77ec3e ***! \************************************************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -module.exports = (__webpack_require__(/*! dll-reference beta_2239422b902ff2ef1cc1 */ 5))(5); +module.exports = (__webpack_require__(/*! dll-reference beta_a1d5c7116e082d77ec3e */ 5))(5); /***/ }), /* 5 */ /*!********************************************!*\ - !*** external "beta_2239422b902ff2ef1cc1" ***! + !*** external "beta_a1d5c7116e082d77ec3e" ***! \********************************************/ /*! dynamic exports */ /*! exports [maybe provided (runtime-defined)] [no usage info] */ @@ -101,40 +103,40 @@ module.exports = (__webpack_require__(/*! dll-reference beta_2239422b902ff2ef1cc /***/ ((module) => { "use strict"; -module.exports = beta_2239422b902ff2ef1cc1; +module.exports = beta_a1d5c7116e082d77ec3e; /***/ }), /* 6 */ /*!*********************************************************************!*\ - !*** delegated ./b.js from dll-reference beta_2239422b902ff2ef1cc1 ***! + !*** delegated ./b.js from dll-reference beta_a1d5c7116e082d77ec3e ***! \*********************************************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -module.exports = (__webpack_require__(/*! dll-reference beta_2239422b902ff2ef1cc1 */ 5))(6); +module.exports = (__webpack_require__(/*! dll-reference beta_a1d5c7116e082d77ec3e */ 5))(6); /***/ }), /* 7 */ /*!**********************************************************************!*\ - !*** delegated ./c.jsx from dll-reference beta_2239422b902ff2ef1cc1 ***! + !*** delegated ./c.jsx from dll-reference beta_a1d5c7116e082d77ec3e ***! \**********************************************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -module.exports = (__webpack_require__(/*! dll-reference beta_2239422b902ff2ef1cc1 */ 5))(7); +module.exports = (__webpack_require__(/*! dll-reference beta_a1d5c7116e082d77ec3e */ 5))(7); /***/ }), /* 8 */ /*!*****************************************************************************************!*\ - !*** delegated ../node_modules/module.js from dll-reference alpha_2239422b902ff2ef1cc1 ***! + !*** delegated ../node_modules/module.js from dll-reference alpha_a1d5c7116e082d77ec3e ***! \*****************************************************************************************/ /*! unknown exports (runtime-defined) */ /*! runtime requirements: module, __webpack_require__ */ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -module.exports = (__webpack_require__(/*! dll-reference alpha_2239422b902ff2ef1cc1 */ 2))(3); +module.exports = (__webpack_require__(/*! dll-reference alpha_a1d5c7116e082d77ec3e */ 2))(3); /***/ }) /******/ ]); diff --git a/examples/dll/README.md b/examples/dll/README.md index cc6a9f40ba0..267f3d1c0a7 100644 --- a/examples/dll/README.md +++ b/examples/dll/README.md @@ -7,6 +7,8 @@ This is the _reference_ bundle (with the manifests) for [dll user example](https # webpack.config.js ```javascript +"use strict"; + const path = require("path"); const webpack = require("../../"); @@ -36,7 +38,7 @@ module.exports = { # dist/MyDll.alpha.js ```javascript -var alpha_2239422b902ff2ef1cc1; +var alpha_a1d5c7116e082d77ec3e; /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ([ /* 0 */ @@ -129,7 +131,7 @@ module.exports = "module"; /******/ // Load entry module and return exports /******/ // This entry module doesn't tell about it's top-level declarations so it can't be inlined /******/ var __webpack_exports__ = __webpack_require__(0); -/******/ alpha_2239422b902ff2ef1cc1 = __webpack_exports__; +/******/ alpha_a1d5c7116e082d77ec3e = __webpack_exports__; /******/ /******/ })() ; @@ -138,7 +140,7 @@ module.exports = "module"; # dist/alpha-manifest.json ```javascript -{"name":"alpha_2239422b902ff2ef1cc1","content":{"./alpha.js":{"id":1,"buildMeta":{}},"./a.js":{"id":2,"buildMeta":{}},"../node_modules/module.js":{"id":3,"buildMeta":{}}}} +{"name":"alpha_a1d5c7116e082d77ec3e","content":{"./alpha.js":{"id":1,"buildMeta":{}},"./a.js":{"id":2,"buildMeta":{}},"../node_modules/module.js":{"id":3,"buildMeta":{}}}} ``` # Info @@ -155,9 +157,9 @@ chunk (runtime: alpha) MyDll.alpha.js (alpha) 85 bytes [entry] [rendered] [used exports unknown] dll entry used as library export -chunk (runtime: beta) MyDll.beta.js (beta) 80 bytes [entry] [rendered] +chunk (runtime: beta) MyDll.beta.js (beta) 81 bytes [entry] [rendered] > beta - dependent modules 68 bytes [dependent] 3 modules + dependent modules 69 bytes [dependent] 3 modules dll beta 12 bytes [built] [code generated] [used exports unknown] dll entry @@ -170,9 +172,9 @@ webpack X.X.X compiled successfully ``` asset MyDll.alpha.js 313 bytes [emitted] [minimized] (name: alpha) asset MyDll.beta.js 307 bytes [emitted] [minimized] (name: beta) -chunk (runtime: beta) MyDll.beta.js (beta) 80 bytes [entry] [rendered] +chunk (runtime: beta) MyDll.beta.js (beta) 81 bytes [entry] [rendered] > beta - dependent modules 68 bytes [dependent] 3 modules + dependent modules 69 bytes [dependent] 3 modules dll beta 12 bytes [built] [code generated] dll entry used as library export diff --git a/examples/explicit-vendor-chunk/README.md b/examples/explicit-vendor-chunk/README.md index 03c8fa9fc68..0d08945de26 100644 --- a/examples/explicit-vendor-chunk/README.md +++ b/examples/explicit-vendor-chunk/README.md @@ -1,6 +1,8 @@ # webpack.config.js ```javascript +"use strict"; + const path = require("path"); const webpack = require("../../"); diff --git a/examples/externals/README.md b/examples/externals/README.md index 569df4f238c..2a5be588b60 100644 --- a/examples/externals/README.md +++ b/examples/externals/README.md @@ -27,6 +27,8 @@ exports.exampleValue = subtract(add(42, 2), 2); # webpack.config.js ```javascript +"use strict"; + module.exports = { // mode: "development" || "production", output: { diff --git a/examples/extra-async-chunk-advanced/README.md b/examples/extra-async-chunk-advanced/README.md index ee9287596af..56e4732f6d8 100644 --- a/examples/extra-async-chunk-advanced/README.md +++ b/examples/extra-async-chunk-advanced/README.md @@ -22,6 +22,8 @@ require.ensure(["./a", "./e"], function(require) { # webpack.config.js ```javascript +"use strict"; + module.exports = { // mode: "development" || "production", optimization: { diff --git a/examples/harmony-library/README.md b/examples/harmony-library/README.md index a41425e863d..36fd3307a83 100644 --- a/examples/harmony-library/README.md +++ b/examples/harmony-library/README.md @@ -1,6 +1,8 @@ # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/http2-aggressive-splitting/README.md b/examples/http2-aggressive-splitting/README.md index 6fed1ed226b..14cc702eac2 100644 --- a/examples/http2-aggressive-splitting/README.md +++ b/examples/http2-aggressive-splitting/README.md @@ -17,6 +17,8 @@ The compression improves with bigger `maxSize`, as gzip works better for bigger The backward compatibility (non-HTTP2 client) improves with bigger `maxSize`, as the number of requests decreases. ```js +"use strict"; + const path = require("path"); const webpack = require("../../"); diff --git a/examples/hybrid-routing/README.md b/examples/hybrid-routing/README.md index 03716192585..dd9df38182a 100644 --- a/examples/hybrid-routing/README.md +++ b/examples/hybrid-routing/README.md @@ -1,6 +1,8 @@ # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/lazy-compilation/README.md b/examples/lazy-compilation/README.md index dc8ccb3c7b2..9cc712d5b2b 100644 --- a/examples/lazy-compilation/README.md +++ b/examples/lazy-compilation/README.md @@ -42,6 +42,8 @@ document.body.appendChild(pre); # webpack.config.js ```javascript +"use strict"; + const { HotModuleReplacementPlugin } = require("../../"); module.exports = { diff --git a/examples/many-pages/README.md b/examples/many-pages/README.md index 13bc49b5a33..fcf683b3dc7 100644 --- a/examples/many-pages/README.md +++ b/examples/many-pages/README.md @@ -25,6 +25,8 @@ Note: decreasing `maxInitial/AsyncRequest` will increase duplication further to ## webpack.config.js ``` +"use strict"; + module.exports = { // mode: "development" || "production", entry: { diff --git a/examples/module-federation/README.md b/examples/module-federation/README.md index 2226be34e5a..9b9f6d404ee 100644 --- a/examples/module-federation/README.md +++ b/examples/module-federation/README.md @@ -1,8 +1,11 @@ # webpack.config.js ```javascript +"use strict"; + const path = require("path"); const { ModuleFederationPlugin } = require("../../").container; + const rules = [ { test: /\.js$/, @@ -25,6 +28,7 @@ const stats = { chunkModules: true, chunkOrigins: true }; + module.exports = (env = "development") => [ // For this example we have 3 configs in a single file // In practice you probably would have separate config diff --git a/examples/multi-compiler/README.md b/examples/multi-compiler/README.md index d6a27c8d571..86b20f94630 100644 --- a/examples/multi-compiler/README.md +++ b/examples/multi-compiler/README.md @@ -10,6 +10,8 @@ console.log("Running " + ENV + " build"); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); const webpack = require("../../"); diff --git a/examples/multi-part-library/README.md b/examples/multi-part-library/README.md index 465c6bf5bb9..f2dfd7742f4 100644 --- a/examples/multi-part-library/README.md +++ b/examples/multi-part-library/README.md @@ -15,6 +15,8 @@ Note: When your library has dependencies that should not be included in the comp # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/multiple-entry-points/README.md b/examples/multiple-entry-points/README.md index 33bba7c01b8..151e2a702f0 100644 --- a/examples/multiple-entry-points/README.md +++ b/examples/multiple-entry-points/README.md @@ -50,6 +50,8 @@ require.ensure(["./shared"], function(require) { # webpack.config.js ```javascript +"use strict"; + module.exports = { // mode: "development" || "production", entry: { diff --git a/examples/nodejs-addons/README.md b/examples/nodejs-addons/README.md index e117c9c66f1..12792394eba 100644 --- a/examples/nodejs-addons/README.md +++ b/examples/nodejs-addons/README.md @@ -23,6 +23,8 @@ console.log(myModule.exports.hello()); # webpack.config.js ```javascript +"use strict"; + module.exports = { // mode: "development" || "production", target: "node", diff --git a/examples/persistent-caching/README.md b/examples/persistent-caching/README.md index 84ef2840489..40621534468 100644 --- a/examples/persistent-caching/README.md +++ b/examples/persistent-caching/README.md @@ -17,7 +17,10 @@ console.log(_); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); + module.exports = (env = "development") => ({ mode: env, infrastructureLogging: { diff --git a/examples/scope-hoisting/README.md b/examples/scope-hoisting/README.md index 9f111ad36ae..4498a9fd39b 100644 --- a/examples/scope-hoisting/README.md +++ b/examples/scope-hoisting/README.md @@ -99,6 +99,8 @@ export var y = "y"; # webpack.config.js ```javascript +"use strict"; + module.exports = { // mode: "development" || "production", optimization: { diff --git a/examples/source-map/README.md b/examples/source-map/README.md index db4b008e8c4..87ac473e90e 100644 --- a/examples/source-map/README.md +++ b/examples/source-map/README.md @@ -19,6 +19,8 @@ race = (winner, runners...) -> # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = [ diff --git a/examples/stats-detailed/README.md b/examples/stats-detailed/README.md index 042e47d7a59..54fd2862398 100644 --- a/examples/stats-detailed/README.md +++ b/examples/stats-detailed/README.md @@ -11,6 +11,8 @@ console.log("Hello World!"); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/stats-minimal/README.md b/examples/stats-minimal/README.md index 79d8f475a77..fd12fec106b 100644 --- a/examples/stats-minimal/README.md +++ b/examples/stats-minimal/README.md @@ -11,6 +11,8 @@ console.log("Hello World!"); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/stats-none/README.md b/examples/stats-none/README.md index d9fb8490193..9c20e6b3b8c 100644 --- a/examples/stats-none/README.md +++ b/examples/stats-none/README.md @@ -11,6 +11,8 @@ console.log("Hello World!"); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/stats-normal/README.md b/examples/stats-normal/README.md index b4481ca8a27..b2269e85c35 100644 --- a/examples/stats-normal/README.md +++ b/examples/stats-normal/README.md @@ -11,6 +11,8 @@ console.log("Hello World!"); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/stats-summary/README.md b/examples/stats-summary/README.md index 0518d541bfb..08be1b192de 100644 --- a/examples/stats-summary/README.md +++ b/examples/stats-summary/README.md @@ -11,6 +11,8 @@ console.log("Hello World!"); # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/top-level-await/README.md b/examples/top-level-await/README.md index f74492e242a..825c8a714bb 100644 --- a/examples/top-level-await/README.md +++ b/examples/top-level-await/README.md @@ -203,9 +203,12 @@ const AlternativeCreateUserAction = async name => { /************************************************************************/ /******/ /* webpack/runtime/async module */ /******/ (() => { -/******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__"; -/******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__"; -/******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__"; +/******/ var hasSymbol = typeof Symbol === "function"; +/******/ var webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__"; +/******/ var webpackExports = hasSymbol ? Symbol("webpack exports") : "__webpack_exports__"; +/******/ var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__"; +/******/ +/******/ /******/ var resolveQueue = (queue) => { /******/ if(queue && queue.d < 1) { /******/ queue.d = 1; @@ -215,6 +218,7 @@ const AlternativeCreateUserAction = async name => { /******/ } /******/ var wrapDeps = (deps) => (deps.map((dep) => { /******/ if(dep !== null && typeof dep === "object") { +/******/ /******/ if(dep[webpackQueues]) return dep; /******/ if(dep.then) { /******/ var queue = []; @@ -227,6 +231,7 @@ const AlternativeCreateUserAction = async name => { /******/ resolveQueue(queue); /******/ }); /******/ var obj = {}; +/******/ /******/ obj[webpackQueues] = (fn) => (fn(queue)); /******/ return obj; /******/ } @@ -251,10 +256,11 @@ const AlternativeCreateUserAction = async name => { /******/ promise[webpackExports] = exports; /******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {})); /******/ module.exports = promise; -/******/ body((deps) => { +/******/ var handle = (deps) => { /******/ currentDeps = wrapDeps(deps); /******/ var fn; /******/ var getResult = () => (currentDeps.map((d) => { +/******/ /******/ if(d[webpackError]) throw d[webpackError]; /******/ return d[webpackExports]; /******/ })) @@ -265,7 +271,9 @@ const AlternativeCreateUserAction = async name => { /******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue))); /******/ }); /******/ return fn.r ? promise : getResult(); -/******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue))); +/******/ } +/******/ var done = (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)) +/******/ body(handle, done); /******/ queue && queue.d < 0 && (queue.d = 0); /******/ }; /******/ })(); @@ -579,7 +587,7 @@ __webpack_async_result__(); ## Unoptimized ``` -asset output.js 15 KiB [emitted] (name: main) +asset output.js 15.1 KiB [emitted] (name: main) asset UserApi_js.output.js 2.97 KiB [emitted] chunk (runtime: main) UserApi_js.output.js 617 bytes [rendered] > ./UserApi.js ./Actions.js 22:30-52 @@ -590,9 +598,9 @@ chunk (runtime: main) UserApi_js.output.js 617 bytes [rendered] [used exports unknown] import() ./UserApi.js ./Actions.js 2:16-38 import() ./UserApi.js ./Actions.js 22:30-52 -chunk (runtime: main) output.js (main) 1.19 KiB (javascript) 7.56 KiB (runtime) [entry] [rendered] +chunk (runtime: main) output.js (main) 1.19 KiB (javascript) 7.59 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 7.56 KiB 9 modules + runtime modules 7.59 KiB 9 modules dependent modules 1.09 KiB [dependent] 1 module ./example.js 103 bytes [built] [code generated] [no exports] @@ -604,7 +612,7 @@ webpack X.X.X compiled successfully ## Production mode ``` -asset output.js 2.93 KiB [emitted] [minimized] (name: main) +asset output.js 2.89 KiB [emitted] [minimized] (name: main) asset UserApi_js.output.js 532 bytes [emitted] [minimized] chunk (runtime: main) UserApi_js.output.js 617 bytes [rendered] > ./UserApi.js ./Actions.js 22:30-52 @@ -614,9 +622,9 @@ chunk (runtime: main) UserApi_js.output.js 617 bytes [rendered] [exports: createUser] import() ./UserApi.js ./example.js + 1 modules ./Actions.js 2:16-38 import() ./UserApi.js ./example.js + 1 modules ./Actions.js 22:30-52 -chunk (runtime: main) output.js (main) 1.19 KiB (javascript) 7.56 KiB (runtime) [entry] [rendered] +chunk (runtime: main) output.js (main) 1.19 KiB (javascript) 7.59 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 7.56 KiB 9 modules + runtime modules 7.59 KiB 9 modules ./example.js + 1 modules 1.19 KiB [built] [code generated] [no exports] [no exports used] diff --git a/examples/two-explicit-vendor-chunks/README.md b/examples/two-explicit-vendor-chunks/README.md index 0654abeba0f..ea683484067 100644 --- a/examples/two-explicit-vendor-chunks/README.md +++ b/examples/two-explicit-vendor-chunks/README.md @@ -1,6 +1,8 @@ # webpack.config.js ```javascript +"use strict"; + const path = require("path"); module.exports = { diff --git a/examples/typescript/README.md b/examples/typescript/README.md index 1161b7a8e8c..218b0031f12 100644 --- a/examples/typescript/README.md +++ b/examples/typescript/README.md @@ -21,6 +21,8 @@ console.log(getArray(1, 2, 3)); # webpack.config.js ```javascript +"use strict"; + const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); module.exports = (env = "development") => ({ diff --git a/examples/wasm-bindgen-esm/README.md b/examples/wasm-bindgen-esm/README.md index 1852cab0ca9..86d82e811ba 100644 --- a/examples/wasm-bindgen-esm/README.md +++ b/examples/wasm-bindgen-esm/README.md @@ -218,9 +218,12 @@ module.exports = __webpack_require__.v(exports, module.id, "ffe21e855d11d22ab54f /************************************************************************/ /******/ /* webpack/runtime/async module */ /******/ (() => { -/******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__"; -/******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__"; -/******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__"; +/******/ var hasSymbol = typeof Symbol === "function"; +/******/ var webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__"; +/******/ var webpackExports = hasSymbol ? Symbol("webpack exports") : "__webpack_exports__"; +/******/ var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__"; +/******/ +/******/ /******/ var resolveQueue = (queue) => { /******/ if(queue && queue.d < 1) { /******/ queue.d = 1; @@ -230,6 +233,7 @@ module.exports = __webpack_require__.v(exports, module.id, "ffe21e855d11d22ab54f /******/ } /******/ var wrapDeps = (deps) => (deps.map((dep) => { /******/ if(dep !== null && typeof dep === "object") { +/******/ /******/ if(dep[webpackQueues]) return dep; /******/ if(dep.then) { /******/ var queue = []; @@ -242,6 +246,7 @@ module.exports = __webpack_require__.v(exports, module.id, "ffe21e855d11d22ab54f /******/ resolveQueue(queue); /******/ }); /******/ var obj = {}; +/******/ /******/ obj[webpackQueues] = (fn) => (fn(queue)); /******/ return obj; /******/ } @@ -266,10 +271,11 @@ module.exports = __webpack_require__.v(exports, module.id, "ffe21e855d11d22ab54f /******/ promise[webpackExports] = exports; /******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {})); /******/ module.exports = promise; -/******/ body((deps) => { +/******/ var handle = (deps) => { /******/ currentDeps = wrapDeps(deps); /******/ var fn; /******/ var getResult = () => (currentDeps.map((d) => { +/******/ /******/ if(d[webpackError]) throw d[webpackError]; /******/ return d[webpackExports]; /******/ })) @@ -280,7 +286,9 @@ module.exports = __webpack_require__.v(exports, module.id, "ffe21e855d11d22ab54f /******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue))); /******/ }); /******/ return fn.r ? promise : getResult(); -/******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue))); +/******/ } +/******/ var done = (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)) +/******/ body(handle, done); /******/ queue && queue.d < 0 && (queue.d = 0); /******/ }; /******/ })(); @@ -369,10 +377,10 @@ module.exports = __webpack_require__.v(exports, module.id, "ffe21e855d11d22ab54f ``` asset ffe21e855d11d22ab54f.wasm 14.8 KiB [emitted] [immutable] (auxiliary name: main) -asset output.js 13.4 KiB [emitted] (name: main) -chunk (runtime: main) output.js (main) 3.03 KiB (javascript) 14.8 KiB (webassembly) 3.68 KiB (runtime) [entry] [rendered] +asset output.js 13.6 KiB [emitted] (name: main) +chunk (runtime: main) output.js (main) 3.03 KiB (javascript) 14.8 KiB (webassembly) 3.72 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 3.68 KiB 6 modules + runtime modules 3.72 KiB 6 modules dependent modules 2.97 KiB (javascript) 14.8 KiB (webassembly) [dependent] 2 modules ./example.js 69 bytes [built] [code generated] [no exports] @@ -385,10 +393,10 @@ webpack X.X.X compiled successfully ``` asset 78eeb14b9b5e2c77fb0a.wasm 14.8 KiB [emitted] [immutable] (auxiliary name: main) -asset output.js 3.37 KiB [emitted] [minimized] (name: main) -chunk (runtime: main) output.js (main) 3.03 KiB (javascript) 14.8 KiB (webassembly) 3.42 KiB (runtime) [entry] [rendered] +asset output.js 3.33 KiB [emitted] [minimized] (name: main) +chunk (runtime: main) output.js (main) 3.03 KiB (javascript) 14.8 KiB (webassembly) 3.45 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 3.42 KiB 5 modules + runtime modules 3.45 KiB 5 modules dependent modules 2.97 KiB (javascript) 14.8 KiB (webassembly) [dependent] 2 modules ./example.js 69 bytes [built] [code generated] [no exports] diff --git a/examples/wasm-complex/README.md b/examples/wasm-complex/README.md index b358aeb18c0..03de92299d3 100644 --- a/examples/wasm-complex/README.md +++ b/examples/wasm-complex/README.md @@ -262,9 +262,12 @@ function getRandomNumber() { /************************************************************************/ /******/ /* webpack/runtime/async module */ /******/ (() => { -/******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__"; -/******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__"; -/******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__"; +/******/ var hasSymbol = typeof Symbol === "function"; +/******/ var webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__"; +/******/ var webpackExports = hasSymbol ? Symbol("webpack exports") : "__webpack_exports__"; +/******/ var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__"; +/******/ +/******/ /******/ var resolveQueue = (queue) => { /******/ if(queue && queue.d < 1) { /******/ queue.d = 1; @@ -274,6 +277,7 @@ function getRandomNumber() { /******/ } /******/ var wrapDeps = (deps) => (deps.map((dep) => { /******/ if(dep !== null && typeof dep === "object") { +/******/ /******/ if(dep[webpackQueues]) return dep; /******/ if(dep.then) { /******/ var queue = []; @@ -286,6 +290,7 @@ function getRandomNumber() { /******/ resolveQueue(queue); /******/ }); /******/ var obj = {}; +/******/ /******/ obj[webpackQueues] = (fn) => (fn(queue)); /******/ return obj; /******/ } @@ -310,10 +315,11 @@ function getRandomNumber() { /******/ promise[webpackExports] = exports; /******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {})); /******/ module.exports = promise; -/******/ body((deps) => { +/******/ var handle = (deps) => { /******/ currentDeps = wrapDeps(deps); /******/ var fn; /******/ var getResult = () => (currentDeps.map((d) => { +/******/ /******/ if(d[webpackError]) throw d[webpackError]; /******/ return d[webpackExports]; /******/ })) @@ -324,7 +330,9 @@ function getRandomNumber() { /******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue))); /******/ }); /******/ return fn.r ? promise : getResult(); -/******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue))); +/******/ } +/******/ var done = (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)) +/******/ body(handle, done); /******/ queue && queue.d < 0 && (queue.d = 0); /******/ }; /******/ })(); @@ -412,11 +420,11 @@ function getRandomNumber() { ## Unoptimized ``` -asset output.js 13.8 KiB [emitted] (name: main) +asset output.js 14 KiB [emitted] (name: main) asset daa529a2a650ee3943a9.module.wasm 139 bytes [emitted] [immutable] (auxiliary name: main) -chunk (runtime: main) output.js (main) 696 bytes (javascript) 139 bytes (webassembly) 3.69 KiB (runtime) [entry] [rendered] +chunk (runtime: main) output.js (main) 696 bytes (javascript) 139 bytes (webassembly) 3.72 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 3.69 KiB 6 modules + runtime modules 3.72 KiB 6 modules dependent modules 449 bytes (javascript) 139 bytes (webassembly) [dependent] 4 modules ./example.js 247 bytes [built] [code generated] [no exports] @@ -428,11 +436,11 @@ webpack X.X.X compiled successfully ## Production mode ``` -asset output.js 2.76 KiB [emitted] [minimized] (name: main) +asset output.js 2.72 KiB [emitted] [minimized] (name: main) asset 03b5e050bc920dbbb73e.module.wasm 139 bytes [emitted] [immutable] (auxiliary name: main) -chunk (runtime: main) output.js (main) 696 bytes (javascript) 139 bytes (webassembly) 3.42 KiB (runtime) [entry] [rendered] +chunk (runtime: main) output.js (main) 696 bytes (javascript) 139 bytes (webassembly) 3.46 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 3.42 KiB 5 modules + runtime modules 3.46 KiB 5 modules dependent modules 449 bytes (javascript) 139 bytes (webassembly) [dependent] 4 modules ./example.js 247 bytes [built] [code generated] [no exports] diff --git a/examples/wasm-simple/README.md b/examples/wasm-simple/README.md index fbbe3813d21..e6d52ac8fb3 100644 --- a/examples/wasm-simple/README.md +++ b/examples/wasm-simple/README.md @@ -225,9 +225,12 @@ module.exports = __webpack_require__.v(exports, module.id, "5a6637e8d63cdf9c72da /************************************************************************/ /******/ /* webpack/runtime/async module */ /******/ (() => { -/******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__"; -/******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__"; -/******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__"; +/******/ var hasSymbol = typeof Symbol === "function"; +/******/ var webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__"; +/******/ var webpackExports = hasSymbol ? Symbol("webpack exports") : "__webpack_exports__"; +/******/ var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__"; +/******/ +/******/ /******/ var resolveQueue = (queue) => { /******/ if(queue && queue.d < 1) { /******/ queue.d = 1; @@ -237,6 +240,7 @@ module.exports = __webpack_require__.v(exports, module.id, "5a6637e8d63cdf9c72da /******/ } /******/ var wrapDeps = (deps) => (deps.map((dep) => { /******/ if(dep !== null && typeof dep === "object") { +/******/ /******/ if(dep[webpackQueues]) return dep; /******/ if(dep.then) { /******/ var queue = []; @@ -249,6 +253,7 @@ module.exports = __webpack_require__.v(exports, module.id, "5a6637e8d63cdf9c72da /******/ resolveQueue(queue); /******/ }); /******/ var obj = {}; +/******/ /******/ obj[webpackQueues] = (fn) => (fn(queue)); /******/ return obj; /******/ } @@ -273,10 +278,11 @@ module.exports = __webpack_require__.v(exports, module.id, "5a6637e8d63cdf9c72da /******/ promise[webpackExports] = exports; /******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {})); /******/ module.exports = promise; -/******/ body((deps) => { +/******/ var handle = (deps) => { /******/ currentDeps = wrapDeps(deps); /******/ var fn; /******/ var getResult = () => (currentDeps.map((d) => { +/******/ /******/ if(d[webpackError]) throw d[webpackError]; /******/ return d[webpackExports]; /******/ })) @@ -287,7 +293,9 @@ module.exports = __webpack_require__.v(exports, module.id, "5a6637e8d63cdf9c72da /******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue))); /******/ }); /******/ return fn.r ? promise : getResult(); -/******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue))); +/******/ } +/******/ var done = (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)) +/******/ body(handle, done); /******/ queue && queue.d < 0 && (queue.d = 0); /******/ }; /******/ })(); @@ -375,13 +383,13 @@ module.exports = __webpack_require__.v(exports, module.id, "5a6637e8d63cdf9c72da ## Unoptimized ``` -asset output.js 13.2 KiB [emitted] (name: main) +asset output.js 13.3 KiB [emitted] (name: main) asset 5a6637e8d63cdf9c72da.wasm 67 bytes [emitted] [immutable] (auxiliary name: main) asset 35a58b7c95860d720a3c.wasm 62 bytes [emitted] [immutable] (auxiliary name: main) asset 0eaeab8b9fa3cef100d1.wasm 41 bytes [emitted] [immutable] (auxiliary name: main) -chunk (runtime: main) output.js (main) 1.27 KiB (javascript) 170 bytes (webassembly) 3.68 KiB (runtime) [entry] [rendered] +chunk (runtime: main) output.js (main) 1.27 KiB (javascript) 170 bytes (webassembly) 3.72 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 3.68 KiB 6 modules + runtime modules 3.72 KiB 6 modules dependent modules 552 bytes (javascript) 170 bytes (webassembly) [dependent] 4 modules ./example.js 753 bytes [built] [code generated] [no exports] @@ -393,13 +401,13 @@ webpack X.X.X compiled successfully ## Production mode ``` -asset output.js 2.85 KiB [emitted] [minimized] (name: main) +asset output.js 2.8 KiB [emitted] [minimized] (name: main) asset 93de874acf2fa7def7d9.wasm 67 bytes [emitted] [immutable] (auxiliary name: main) asset 5055869d769f484de216.wasm 62 bytes [emitted] [immutable] (auxiliary name: main) asset db91ebd6538fd6985888.wasm 41 bytes [emitted] [immutable] (auxiliary name: main) -chunk (runtime: main) output.js (main) 1.27 KiB (javascript) 170 bytes (webassembly) 3.42 KiB (runtime) [entry] [rendered] +chunk (runtime: main) output.js (main) 1.27 KiB (javascript) 170 bytes (webassembly) 3.45 KiB (runtime) [entry] [rendered] > ./example.js main - runtime modules 3.42 KiB 5 modules + runtime modules 3.45 KiB 5 modules dependent modules 552 bytes (javascript) 170 bytes (webassembly) [dependent] 4 modules ./example.js 753 bytes [built] [code generated] [no exports] diff --git a/lib/APIPlugin.js b/lib/APIPlugin.js index d51fb7a1ef3..b8978e337e8 100644 --- a/lib/APIPlugin.js +++ b/lib/APIPlugin.js @@ -179,7 +179,7 @@ class APIPlugin { compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.getFullHash) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule(chunk, new GetFullHashRuntimeModule()); return true; }); diff --git a/lib/Compilation.js b/lib/Compilation.js index b8f83d59e94..20dca8e7184 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -683,7 +683,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si { name, /** @type {AsyncSeriesHook["intercept"]} */ - intercept(interceptor) { + intercept(_interceptor) { throw new Error(errorMessage("it's using 'intercept'")); }, /** @type {AsyncSeriesHook["tap"]} */ @@ -5279,7 +5279,7 @@ This prevents using hashes of each other and should be avoided.`); runtimeTemplate, errors, codeGenerationResults, - (err, codeGenerated) => { + (err, _codeGenerated) => { callback(err); } ); @@ -5654,9 +5654,9 @@ Object.defineProperty(compilationPrototype, "cache", { ), set: util.deprecate( /** - * @param {EXPECTED_ANY} v value + * @param {EXPECTED_ANY} _v value */ - v => {}, + _v => {}, "Compilation.cache was removed in favor of Compilation.getCache()", "DEP_WEBPACK_COMPILATION_CACHE" ) diff --git a/lib/Compiler.js b/lib/Compiler.js index 24a72571cd2..fb509a8dc61 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -1391,7 +1391,7 @@ ${other}`); close(callback) { if (this.watching) { // When there is still an active watching, close this first - this.watching.close(err => { + this.watching.close(_err => { this.close(callback); }); return; diff --git a/lib/ConstPlugin.js b/lib/ConstPlugin.js index d79fa0215eb..04cca9430a3 100644 --- a/lib/ConstPlugin.js +++ b/lib/ConstPlugin.js @@ -160,7 +160,7 @@ class ConstPlugin { * @param {JavascriptParser} parser the parser */ const handler = parser => { - parser.hooks.terminate.tap(PLUGIN_NAME, statement => true); + parser.hooks.terminate.tap(PLUGIN_NAME, _statement => true); parser.hooks.statementIf.tap(PLUGIN_NAME, statement => { if (parser.scope.isAsmJs) return; const param = parser.evaluateExpression(statement.test); diff --git a/lib/ContextModuleFactory.js b/lib/ContextModuleFactory.js index 00359846771..77a7bf5919c 100644 --- a/lib/ContextModuleFactory.js +++ b/lib/ContextModuleFactory.js @@ -352,7 +352,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory { (segment, callback) => { const subResource = join(fs, directory, segment); - if (!exclude || !subResource.match(exclude)) { + if (!exclude || !exclude.test(subResource)) { fs.stat(subResource, (err, _stat) => { if (err) { if (err.code === "ENOENT") { @@ -370,7 +370,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory { addSubDirectory(ctx, subResource, callback); } else if ( stat.isFile() && - (!include || subResource.match(include)) + (!include || include.test(subResource)) ) { /** @type {{ context: string, request: string }} */ const obj = { diff --git a/lib/DynamicEntryPlugin.js b/lib/DynamicEntryPlugin.js index eb2386dd2bd..79600542090 100644 --- a/lib/DynamicEntryPlugin.js +++ b/lib/DynamicEntryPlugin.js @@ -80,7 +80,7 @@ class DynamicEntryPlugin { } return Promise.all(promises); }) - .then(x => {}) + .then(() => {}) ); } } diff --git a/lib/EvalDevToolModulePlugin.js b/lib/EvalDevToolModulePlugin.js index b9b402a1f6f..bde4bb6466d 100644 --- a/lib/EvalDevToolModulePlugin.js +++ b/lib/EvalDevToolModulePlugin.js @@ -119,7 +119,7 @@ class EvalDevToolModulePlugin { if (compilation.outputOptions.trustedTypes) { compilation.hooks.additionalModuleRuntimeRequirements.tap( PLUGIN_NAME, - (module, set, context) => { + (module, set, _context) => { set.add(RuntimeGlobals.createScript); } ); diff --git a/lib/ExportsInfo.js b/lib/ExportsInfo.js index a7d7e9ce682..e8fb81d01d0 100644 --- a/lib/ExportsInfo.js +++ b/lib/ExportsInfo.js @@ -508,17 +508,15 @@ class ExportsInfo { * @returns {SortableSet | boolean | null} set of used exports, or true (when namespace object is used), or false (when unused), or null (when unknown) */ getUsedExports(runtime) { - // eslint-disable-next-line no-constant-binary-expression - if (!this._redirectTo !== undefined) { - switch (this._otherExportsInfo.getUsed(runtime)) { - case UsageState.NoInfo: - return null; - case UsageState.Unknown: - case UsageState.OnlyPropertiesUsed: - case UsageState.Used: - return true; - } + switch (this._otherExportsInfo.getUsed(runtime)) { + case UsageState.NoInfo: + return null; + case UsageState.Unknown: + case UsageState.OnlyPropertiesUsed: + case UsageState.Used: + return true; } + const array = []; if (!this._exportsAreOrdered) this._sortExports(); for (const exportInfo of this._exports.values()) { @@ -557,17 +555,15 @@ class ExportsInfo { * @returns {null | true | string[]} list of exports when known */ getProvidedExports() { - // eslint-disable-next-line no-constant-binary-expression - if (!this._redirectTo !== undefined) { - switch (this._otherExportsInfo.provided) { - case undefined: - return null; - case null: - return true; - case true: - return true; - } + switch (this._otherExportsInfo.provided) { + case undefined: + return null; + case null: + return true; + case true: + return true; } + /** @type {string[]} */ const array = []; if (!this._exportsAreOrdered) this._sortExports(); diff --git a/lib/ExternalModule.js b/lib/ExternalModule.js index 488fe187678..64f60eb7363 100644 --- a/lib/ExternalModule.js +++ b/lib/ExternalModule.js @@ -669,7 +669,7 @@ class ExternalModule extends Module { * @param {ConcatenationBailoutReasonContext} context context * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated */ - getConcatenationBailoutReason({ moduleGraph }) { + getConcatenationBailoutReason(context) { switch (this.externalType) { case "amd": case "amd-require": diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index 3cb447e316f..f295078b67b 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -1950,11 +1950,11 @@ class FileSystemInfo { if (imp.d === -1) { // import ... from "..." dependency = parseString( - source.substring(imp.s - 1, imp.e + 1) + source.slice(imp.s - 1, imp.e + 1) ); } else if (imp.d > -1) { // import() - const expr = source.substring(imp.s, imp.e).trim(); + const expr = source.slice(imp.s, imp.e).trim(); dependency = parseString(expr); } else { // e.g. import.meta @@ -1974,7 +1974,7 @@ class FileSystemInfo { }); } catch (err1) { logger.warn( - `Parsing of ${path} for build dependencies failed at 'import(${source.substring( + `Parsing of ${path} for build dependencies failed at 'import(${source.slice( imp.s, imp.e )})'.\n` + diff --git a/lib/MultiCompiler.js b/lib/MultiCompiler.js index 5b8a6597d84..effd4df6311 100644 --- a/lib/MultiCompiler.js +++ b/lib/MultiCompiler.js @@ -598,7 +598,7 @@ module.exports = class MultiCompiler { } return watching; }, - (compiler, watching, callback) => { + (compiler, watching, _callback) => { if (compiler.watching !== watching) return; if (!watching.running) watching.invalidate(); }, diff --git a/lib/ProgressPlugin.js b/lib/ProgressPlugin.js index 4b82f61a232..b5add53ebc1 100644 --- a/lib/ProgressPlugin.js +++ b/lib/ProgressPlugin.js @@ -415,7 +415,7 @@ class ProgressPlugin { } return data; }, - err => { + _err => { // Ignore error } ); diff --git a/lib/RuntimePlugin.js b/lib/RuntimePlugin.js index 462df520dd3..d4eeb5b86da 100644 --- a/lib/RuntimePlugin.js +++ b/lib/RuntimePlugin.js @@ -363,7 +363,7 @@ class RuntimePlugin { "javascript", "javascript update", RuntimeGlobals.getChunkUpdateScriptFilename, - c => + _chunk => /** @type {NonNullable} */ (compilation.outputOptions.hotUpdateChunkFilename), true @@ -465,13 +465,13 @@ class RuntimePlugin { }); compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.relativeUrl) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule(chunk, new RelativeUrlRuntimeModule()); return true; }); compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.onChunksLoaded) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule( chunk, new OnChunksLoadedRuntimeModule() @@ -495,7 +495,7 @@ class RuntimePlugin { // TODO webpack 6: remove CompatRuntimeModule compilation.hooks.additionalTreeRuntimeRequirements.tap( PLUGIN_NAME, - (chunk, set) => { + (chunk, _set) => { const { mainTemplate } = compilation; if ( mainTemplate.hooks.bootstrap.isUsed() || diff --git a/lib/cache/PackFileCacheStrategy.js b/lib/cache/PackFileCacheStrategy.js index 57f1375e0ef..29bcf18e55a 100644 --- a/lib/cache/PackFileCacheStrategy.js +++ b/lib/cache/PackFileCacheStrategy.js @@ -1209,7 +1209,7 @@ class PackFileCacheStrategy { } logger.time("check build dependencies"); return Promise.all([ - new Promise((resolve, reject) => { + new Promise((resolve, _reject) => { this.fileSystemInfo.checkSnapshotValid( packContainer.buildSnapshot, (err, valid) => { @@ -1231,7 +1231,7 @@ class PackFileCacheStrategy { } ); }), - new Promise((resolve, reject) => { + new Promise((resolve, _reject) => { this.fileSystemInfo.checkSnapshotValid( packContainer.resolveBuildDependenciesSnapshot, (err, valid) => { diff --git a/lib/container/HoistContainerReferencesPlugin.js b/lib/container/HoistContainerReferencesPlugin.js index 3435c98ef2f..669dcccddca 100644 --- a/lib/container/HoistContainerReferencesPlugin.js +++ b/lib/container/HoistContainerReferencesPlugin.js @@ -56,7 +56,7 @@ class HoistContainerReferences { // advanced stage is where SplitChunksPlugin runs. stage: STAGE_ADVANCED + 1 }, - chunks => { + _chunks => { this.hoistModulesInChunks( compilation, depsToTrace, diff --git a/lib/container/RemoteModule.js b/lib/container/RemoteModule.js index 9ff13fcfc0f..41b77701e6b 100644 --- a/lib/container/RemoteModule.js +++ b/lib/container/RemoteModule.js @@ -141,7 +141,7 @@ class RemoteModule extends Module { * @param {CodeGenerationContext} context context for code generation * @returns {CodeGenerationResult} result */ - codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) { + codeGeneration({ moduleGraph, chunkGraph }) { const module = moduleGraph.getModule(this.dependencies[0]); const id = module && chunkGraph.getModuleId(module); const sources = new Map(); diff --git a/lib/css/walkCssTokens.js b/lib/css/walkCssTokens.js index 4fb7808c349..f6b8b042bda 100644 --- a/lib/css/walkCssTokens.js +++ b/lib/css/walkCssTokens.js @@ -320,6 +320,7 @@ const consumeAStringToken = (input, pos, callbacks) => { const isNonASCIICodePoint = (cc, q) => // Simplify cc > 0x80; + /** * @param {number} cc char code * @returns {boolean} is letter @@ -716,12 +717,12 @@ const consumeRightParenthesis = (input, pos, callbacks) => { }; /** @type {CharHandler} */ -const consumeLeftSquareBracket = (input, pos, callbacks) => +const consumeLeftSquareBracket = (input, pos, _callbacks) => // Return a <]-token>. pos; /** @type {CharHandler} */ -const consumeRightSquareBracket = (input, pos, callbacks) => +const consumeRightSquareBracket = (input, pos, _callbacks) => // Return a <]-token>. pos; diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index c28d3bc1c80..7a0f648217b 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -378,7 +378,7 @@ const interceptAllParserHooks = (moduleFactory, tracer) => { for (const moduleType of moduleTypes) { moduleFactory.hooks.parser .for(moduleType) - .tap(PLUGIN_NAME, (parser, parserOpts) => { + .tap(PLUGIN_NAME, (parser, _parserOpts) => { interceptAllHooksFor(parser, tracer, "Parser"); }); } @@ -399,7 +399,7 @@ const interceptAllGeneratorHooks = (moduleFactory, tracer) => { for (const moduleType of moduleTypes) { moduleFactory.hooks.generator .for(moduleType) - .tap(PLUGIN_NAME, (parser, parserOpts) => { + .tap(PLUGIN_NAME, (parser, _parserOpts) => { interceptAllHooksFor(parser, tracer, "Generator"); }); } diff --git a/lib/dependencies/AMDPlugin.js b/lib/dependencies/AMDPlugin.js index 29ebc30edda..9c8a12f6a0a 100644 --- a/lib/dependencies/AMDPlugin.js +++ b/lib/dependencies/AMDPlugin.js @@ -119,13 +119,13 @@ class AMDPlugin { compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.amdDefine) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule(chunk, new AMDDefineRuntimeModule()); }); compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.amdOptions) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule( chunk, new AMDOptionsRuntimeModule(amdOptions) diff --git a/lib/dependencies/CachedConstDependency.js b/lib/dependencies/CachedConstDependency.js index 913904abc94..01c0371ed36 100644 --- a/lib/dependencies/CachedConstDependency.js +++ b/lib/dependencies/CachedConstDependency.js @@ -99,11 +99,7 @@ CachedConstDependency.Template = class CachedConstDependencyTemplate extends ( * @param {DependencyTemplateContext} templateContext the context object * @returns {void} */ - apply( - dependency, - source, - { runtimeTemplate, dependencyTemplates, initFragments } - ) { + apply(dependency, source, { initFragments }) { const dep = /** @type {CachedConstDependency} */ (dependency); initFragments.push( diff --git a/lib/dependencies/CommonJsFullRequireDependency.js b/lib/dependencies/CommonJsFullRequireDependency.js index 1164eee150e..98b3b4cb1fa 100644 --- a/lib/dependencies/CommonJsFullRequireDependency.js +++ b/lib/dependencies/CommonJsFullRequireDependency.js @@ -107,15 +107,7 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp apply( dependency, source, - { - module, - runtimeTemplate, - moduleGraph, - chunkGraph, - runtimeRequirements, - runtime, - initFragments - } + { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements, runtime } ) { const dep = /** @type {CommonJsFullRequireDependency} */ (dependency); if (!dep.range) return; diff --git a/lib/dependencies/CommonJsPlugin.js b/lib/dependencies/CommonJsPlugin.js index 1f5e2848411..97b8695872a 100644 --- a/lib/dependencies/CommonJsPlugin.js +++ b/lib/dependencies/CommonJsPlugin.js @@ -156,7 +156,7 @@ class CommonJsPlugin { compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.harmonyModuleDecorator) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule( chunk, new HarmonyModuleDecoratorRuntimeModule() @@ -165,7 +165,7 @@ class CommonJsPlugin { compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.nodeModuleDecorator) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule( chunk, new NodeModuleDecoratorRuntimeModule() diff --git a/lib/dependencies/HarmonyImportDependency.js b/lib/dependencies/HarmonyImportDependency.js index 170a2be42d3..4ac805c8031 100644 --- a/lib/dependencies/HarmonyImportDependency.js +++ b/lib/dependencies/HarmonyImportDependency.js @@ -92,15 +92,19 @@ class HarmonyImportDependency extends ModuleDependency { getImportVar(moduleGraph) { const module = /** @type {Module} */ (moduleGraph.getParentModule(this)); const meta = moduleGraph.getMeta(module); - let importVarMap = meta.importVarMap; - if (!importVarMap) meta.importVarMap = importVarMap = new Map(); + const defer = this.defer; + + const metaKey = defer ? "deferredImportVarMap" : "importVarMap"; + let importVarMap = meta[metaKey]; + if (!importVarMap) meta[metaKey] = importVarMap = new Map(); + let importVar = importVarMap.get( /** @type {Module} */ (moduleGraph.getModule(this)) ); if (importVar) return importVar; importVar = `${Template.toIdentifier( `${this.userRequest}` - )}__WEBPACK_IMPORTED_MODULE_${importVarMap.size}__`; + )}__WEBPACK_${this.defer ? "DEFERRED_" : ""}IMPORTED_MODULE_${importVarMap.size}__`; importVarMap.set( /** @type {Module} */ (moduleGraph.getModule(this)), importVar @@ -301,7 +305,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends const moduleKey = referencedModule ? referencedModule.identifier() : dep.request; - const key = `harmony import ${moduleKey}`; + const key = `${dep.defer ? "deferred " : ""}harmony import ${moduleKey}`; const runtimeCondition = dep.weak ? false diff --git a/lib/dependencies/ImportParserPlugin.js b/lib/dependencies/ImportParserPlugin.js index 7c28451edd1..b41e43dd683 100644 --- a/lib/dependencies/ImportParserPlugin.js +++ b/lib/dependencies/ImportParserPlugin.js @@ -346,11 +346,11 @@ class ImportParserPlugin { include, exclude, mode, - namespaceObject: /** @type {BuildMeta} */ ( - parser.state.module.buildMeta - ).strictHarmonyModule - ? "strict" - : true, + namespaceObject: + /** @type {BuildMeta} */ + (parser.state.module.buildMeta).strictHarmonyModule + ? "strict" + : true, typePrefix: "import()", category: "esm", referencedExports: exports, diff --git a/lib/dependencies/SystemPlugin.js b/lib/dependencies/SystemPlugin.js index 367020d64a9..b0e09fd1bc0 100644 --- a/lib/dependencies/SystemPlugin.js +++ b/lib/dependencies/SystemPlugin.js @@ -46,7 +46,7 @@ class SystemPlugin { compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.system) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, _set) => { compilation.addRuntimeModule(chunk, new SystemRuntimeModule()); }); diff --git a/lib/dependencies/WorkerPlugin.js b/lib/dependencies/WorkerPlugin.js index cd033354842..8aea2db264d 100644 --- a/lib/dependencies/WorkerPlugin.js +++ b/lib/dependencies/WorkerPlugin.js @@ -493,12 +493,18 @@ class WorkerPlugin { const pattern = item.slice(1, firstDot); const itemMembers = item.slice(firstDot + 1, -2); - parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, statement) => { - if (decl.id.type === "Identifier" && decl.id.name === pattern) { - parser.tagVariable(decl.id.name, WorkerSpecifierTag); - return true; + parser.hooks.preDeclarator.tap( + PLUGIN_NAME, + (decl, _statement) => { + if ( + decl.id.type === "Identifier" && + decl.id.name === pattern + ) { + parser.tagVariable(decl.id.name, WorkerSpecifierTag); + return true; + } } - }); + ); parser.hooks.pattern.for(pattern).tap(PLUGIN_NAME, pattern => { parser.tagVariable(pattern.name, WorkerSpecifierTag); return true; diff --git a/lib/esm/ModuleChunkFormatPlugin.js b/lib/esm/ModuleChunkFormatPlugin.js index 5915f20e281..61c18ed15eb 100644 --- a/lib/esm/ModuleChunkFormatPlugin.js +++ b/lib/esm/ModuleChunkFormatPlugin.js @@ -164,24 +164,33 @@ class ModuleChunkFormatPlugin { return source; } }; - hooks.renderMain.tap(PLUGIN_NAME, (modules, renderContext) => { - const { chunk, chunkGraph } = renderContext; - const entryDependentChunks = - chunkGraph.getChunkEntryDependentChunksIterable(chunk); - const sourceWithDependentChunks = withDependentChunks( - /** @type {Set} */ (entryDependentChunks), - chunkGraph, - chunk - ); - if (!sourceWithDependentChunks) { - return modules; + hooks.renderStartup.tap( + PLUGIN_NAME, + (modules, _lastModule, renderContext) => { + const { chunk, chunkGraph } = renderContext; + if (!chunk.hasRuntime()) { + return modules; + } + const entryDependentChunks = + chunkGraph.getChunkEntryDependentChunksIterable(chunk); + const sourceWithDependentChunks = withDependentChunks( + /** @type {Set} */ (entryDependentChunks), + chunkGraph, + chunk + ); + if (!sourceWithDependentChunks) { + return modules; + } + if (modules.size() === 0) { + return sourceWithDependentChunks; + } + const source = new ConcatSource(); + source.add(sourceWithDependentChunks); + source.add("\n"); + source.add(modules); + return source; } - const source = new ConcatSource(); - source.add(modules); - source.add("\n"); - source.add(sourceWithDependentChunks); - return source; - }); + ); hooks.renderChunk.tap(PLUGIN_NAME, (modules, renderContext) => { const { chunk, chunkGraph, runtimeTemplate } = renderContext; const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null; @@ -278,22 +287,19 @@ class ModuleChunkFormatPlugin { } return source; }); - hooks.chunkHash.tap( - PLUGIN_NAME, - (chunk, hash, { chunkGraph, runtimeTemplate }) => { - if (chunk.hasRuntime()) return; - const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph); - hash.update(PLUGIN_NAME); - hash.update("1"); - if (runtimeChunk && runtimeChunk.hash) { - // Any change to runtimeChunk should trigger a hash update, - // we shouldn't depend on or inspect its internal implementation. - // import __webpack_require__ from "./runtime-main.e9400aee33633a3973bd.js"; - hash.update(runtimeChunk.hash); - } - updateHashForEntryStartup(hash, chunkGraph, entries, chunk); + hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, { chunkGraph }) => { + if (chunk.hasRuntime()) return; + const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph); + hash.update(PLUGIN_NAME); + hash.update("1"); + if (runtimeChunk && runtimeChunk.hash) { + // Any change to runtimeChunk should trigger a hash update, + // we shouldn't depend on or inspect its internal implementation. + // import __webpack_require__ from "./runtime-main.e9400aee33633a3973bd.js"; + hash.update(runtimeChunk.hash); } - ); + updateHashForEntryStartup(hash, chunkGraph, entries, chunk); + }); }); } } diff --git a/lib/esm/ModuleChunkLoadingPlugin.js b/lib/esm/ModuleChunkLoadingPlugin.js index 3f86bc221cb..a34f990a290 100644 --- a/lib/esm/ModuleChunkLoadingPlugin.js +++ b/lib/esm/ModuleChunkLoadingPlugin.js @@ -71,8 +71,11 @@ class ModuleChunkLoadingPlugin { .tap(PLUGIN_NAME, handler); compilation.hooks.runtimeRequirementInTree .for(RuntimeGlobals.externalInstallChunk) - .tap(PLUGIN_NAME, (chunk, set) => { + .tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => { if (!isEnabledForChunk(chunk)) return; + // If a chunk contains an entryModule, all exports are determined by the entryModule. + // The ExportWebpackRequireRuntimeModule is for internal use only and not exposed to users. + if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return; compilation.addRuntimeModule( chunk, new ExportWebpackRequireRuntimeModule() diff --git a/lib/ids/NaturalModuleIdsPlugin.js b/lib/ids/NaturalModuleIdsPlugin.js index e12b69b61d6..8dc9ae473b7 100644 --- a/lib/ids/NaturalModuleIdsPlugin.js +++ b/lib/ids/NaturalModuleIdsPlugin.js @@ -26,7 +26,7 @@ class NaturalModuleIdsPlugin { */ apply(compiler) { compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { - compilation.hooks.moduleIds.tap(PLUGIN_NAME, modules => { + compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => { const [usedIds, modulesInNaturalOrder] = getUsedModuleIdsAndModules(compilation); modulesInNaturalOrder.sort( diff --git a/lib/javascript/JavascriptModulesPlugin.js b/lib/javascript/JavascriptModulesPlugin.js index d58f7003d09..81ce7b8cf4b 100644 --- a/lib/javascript/JavascriptModulesPlugin.js +++ b/lib/javascript/JavascriptModulesPlugin.js @@ -117,10 +117,10 @@ const printGeneratedCodeForStack = (module, code) => { /** * @param {string} line the line * @param {number} i the index - * @param {string[]} lines the lines + * @param {string[]} _lines the lines * @returns {string} the line with line number */ - (line, i, lines) => { + (line, i, _lines) => { const iStr = `${i + 1}`; return `${" ".repeat(n - iStr.length)}${iStr} | ${line}`; } diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index ede5fcf0558..98c00d34dcd 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -7,6 +7,7 @@ const vm = require("vm"); const { Parser: AcornParser, tokTypes } = require("acorn"); +const acornImportPhases = require("acorn-import-phases"); const { HookMap, SyncBailHook } = require("tapable"); const Parser = require("../Parser"); const StackedMap = require("../util/StackedMap"); @@ -180,147 +181,11 @@ const importAssertions = Parser => } }; -// follow https://www.npmjs.com/acorn-import-defer if possible -/** @type {(BaseParser: typeof AcornParser) => typeof AcornParser} */ -const importDefer = Parser => - class extends Parser { - /** - * @this {InstanceType} - * @param {ImportDeclaration} node import declaration - * @returns {ImportDeclaration} import declaration - */ - parseImport(node) { - this._defer = false; - // eslint-disable-next-line no-warning-comments - // @ts-ignore - const result = super.parseImport(node); - if (this._defer) { - node.phase = "defer"; - } - return result; - } - - /** - * @this {InstanceType} - * @returns {ImportSpecifier[]} import specifiers - */ - parseImportSpecifiers() { - // eslint-disable-next-line no-warning-comments - // @ts-ignore - if (!this.isContextual("defer")) return super.parseImportSpecifiers(); - - const deferId = this.parseIdent(); - if (this.isContextual("from") || this.type === tokTypes.comma) { - const defaultSpecifier = this.startNodeAt( - deferId.start, - deferId.loc.start - ); - defaultSpecifier.local = deferId; - this.checkLValSimple(deferId, /* BIND_LEXICAL */ 2); - - const nodes = [ - this.finishNode(defaultSpecifier, "ImportDefaultSpecifier") - ]; - if (this.eat(tokTypes.comma)) { - if (this.type !== tokTypes.star && this.type !== tokTypes.braceL) { - this.unexpected(); - } - // eslint-disable-next-line no-warning-comments - // @ts-ignore - nodes.push(...super.parseImportSpecifiers()); - } - return nodes; - } - - this._defer = true; - - if (this.type !== tokTypes.star) { - this.raiseRecoverable( - deferId.start, - "'import defer' can only be used with namespace imports." - ); - } - - // eslint-disable-next-line no-warning-comments - // @ts-ignore - return super.parseImportSpecifiers(); - } - - /** - * @this {InstanceType} - * @param {boolean} forNew forNew - * @returns {ImportExpression} import expression - */ - parseExprImport(forNew) { - // eslint-disable-next-line no-warning-comments - // @ts-ignore - const node = super.parseExprImport(forNew); - - if (node.type === "MetaProperty" && node.property.name === "defer") { - if (this.type === tokTypes.parenL) { - const dynImport = this.parseDynamicImport( - this.startNodeAt(node.start, node.loc.start) - ); - dynImport.phase = "defer"; - return dynImport; - } - this.raiseRecoverable( - node.start, - "'import.defer' can only be used in a dynamic import." - ); - } - - return node; - } - - /** - * @this {InstanceType} - * @param {MetaProperty} node node - * @returns {MetaProperty} import.meta - */ - parseImportMeta(node) { - this.next(); - - const containsEsc = this.containsEsc; - node.property = this.parseIdent(true); - - const { name } = node.property; - - if (name !== "meta" && name !== "defer") { - this.raiseRecoverable( - // eslint-disable-next-line no-warning-comments - // @ts-ignore - node.property.start, - "The only valid meta property for import is 'import.meta'" - ); - } - if (containsEsc) { - this.raiseRecoverable( - // eslint-disable-next-line no-warning-comments - // @ts-ignore - node.start, - `'import.${name}' must not contain escaped characters` - ); - } - if ( - name === "meta" && - this.options.sourceType !== "module" && - !this.options.allowImportExportEverywhere - ) { - this.raiseRecoverable( - // eslint-disable-next-line no-warning-comments - // @ts-ignore - node.start, - "Cannot use 'import.meta' outside a module" - ); - } - - return this.finishNode(node, "MetaProperty"); - } - }; - // Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API -const parser = AcornParser.extend(importAssertions, importDefer); +const parser = AcornParser.extend( + importAssertions, + acornImportPhases({ source: false }) +); /** @typedef {Record & { _isLegacyAssert?: boolean }} ImportAttributes */ @@ -1521,7 +1386,7 @@ class JavascriptParser extends Parser { return this.callHooksForInfoWithFallback( this.hooks.evaluateIdentifier, info.name, - name => { + _name => { cachedExpression = expression; cachedInfo = info; return undefined; @@ -1576,7 +1441,7 @@ class JavascriptParser extends Parser { }; } }); - tapEvaluateWithVariableInfo("ThisExpression", expr => { + tapEvaluateWithVariableInfo("ThisExpression", _expr => { const info = this.getVariableInfo("this"); if ( typeof info === "string" || @@ -3616,7 +3481,7 @@ class JavascriptParser extends Parser { return; } this.walkExpression(expression.right); - this.enterPattern(expression.left, (name, decl) => { + this.enterPattern(expression.left, (name, _decl) => { if (!this.callHooksForName(this.hooks.assign, name, expression)) { this.walkExpression( /** @type {MemberExpression} */ @@ -3626,7 +3491,7 @@ class JavascriptParser extends Parser { }); } else if (expression.left.type.endsWith("Pattern")) { this.walkExpression(expression.right); - this.enterPattern(expression.left, (name, decl) => { + this.enterPattern(expression.left, (name, _decl) => { if (!this.callHooksForName(this.hooks.assign, name, expression)) { this.defineVariable(name); } diff --git a/lib/library/AssignLibraryPlugin.js b/lib/library/AssignLibraryPlugin.js index f8c8856f620..80f75fa28f4 100644 --- a/lib/library/AssignLibraryPlugin.js +++ b/lib/library/AssignLibraryPlugin.js @@ -344,9 +344,14 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin { ); } result.add( - ` ${hasProvided ? " " : ""}${webpackExportTarget}[__webpack_i__] = ${exports}[__webpack_i__];\n` + ` ${ + hasProvided ? " " : "" + }${webpackExportTarget}[__webpack_i__] = ${exports}[__webpack_i__];\n` ); - result.add(hasProvided ? " }\n}\n" : "\n"); + if (hasProvided) { + result.add(" }\n"); + } + result.add("}\n"); result.add( `Object.defineProperty(${exportTarget}, "__esModule", { value: true });\n` ); diff --git a/lib/optimize/InnerGraphPlugin.js b/lib/optimize/InnerGraphPlugin.js index 168f5bf4d64..0b70503d9b6 100644 --- a/lib/optimize/InnerGraphPlugin.js +++ b/lib/optimize/InnerGraphPlugin.js @@ -195,7 +195,7 @@ class InnerGraphPlugin { } }); - parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, statement) => { + parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, _statement) => { if (!InnerGraph.isEnabled(parser.state)) return; if ( parser.scope.topLevelScope === true && @@ -363,7 +363,7 @@ class InnerGraphPlugin { } ); - parser.hooks.declarator.tap(PLUGIN_NAME, (decl, statement) => { + parser.hooks.declarator.tap(PLUGIN_NAME, (decl, _statement) => { if (!InnerGraph.isEnabled(parser.state)) return; const fn = declWithTopLevelSymbol.get(decl); diff --git a/lib/optimize/SplitChunksPlugin.js b/lib/optimize/SplitChunksPlugin.js index 321cb423df9..08512518c45 100644 --- a/lib/optimize/SplitChunksPlugin.js +++ b/lib/optimize/SplitChunksPlugin.js @@ -279,10 +279,10 @@ const INITIAL_CHUNK_FILTER = chunk => chunk.canBeInitial(); */ const ASYNC_CHUNK_FILTER = chunk => !chunk.canBeInitial(); /** - * @param {Chunk} chunk the chunk + * @param {Chunk} _chunk the chunk * @returns {boolean} always true */ -const ALL_CHUNK_FILTER = chunk => true; +const ALL_CHUNK_FILTER = _chunk => true; /** * @param {OptimizationSplitChunksSizes | undefined} value the sizes diff --git a/lib/rules/BasicEffectRulePlugin.js b/lib/rules/BasicEffectRulePlugin.js index 3e7ca5f87b2..c7ab48b578d 100644 --- a/lib/rules/BasicEffectRulePlugin.js +++ b/lib/rules/BasicEffectRulePlugin.js @@ -35,7 +35,7 @@ class BasicEffectRulePlugin { apply(ruleSetCompiler) { ruleSetCompiler.hooks.rule.tap( PLUGIN_NAME, - (path, rule, unhandledProperties, result, references) => { + (path, rule, unhandledProperties, result) => { if (unhandledProperties.has(this.ruleProperty)) { unhandledProperties.delete(this.ruleProperty); diff --git a/lib/schemes/FileUriPlugin.js b/lib/schemes/FileUriPlugin.js index 26758ac6e2b..e870e1b6b60 100644 --- a/lib/schemes/FileUriPlugin.js +++ b/lib/schemes/FileUriPlugin.js @@ -5,7 +5,7 @@ "use strict"; -const { URL, fileURLToPath } = require("url"); +const { fileURLToPath } = require("url"); const { NormalModule } = require(".."); /** @typedef {import("../Compiler")} Compiler */ diff --git a/lib/schemes/HttpUriPlugin.js b/lib/schemes/HttpUriPlugin.js index 01b0ed3373e..0dad3db3d0f 100644 --- a/lib/schemes/HttpUriPlugin.js +++ b/lib/schemes/HttpUriPlugin.js @@ -7,7 +7,6 @@ const EventEmitter = require("events"); const { basename, extname } = require("path"); -const { URL } = require("url"); const { // eslint-disable-next-line n/no-unsupported-features/node-builtins createBrotliDecompress, @@ -37,7 +36,7 @@ const getHttps = memoize(() => require("https")); /** * @param {typeof import("http") | typeof import("https")} request request - * @param {string | { toString: () => string } | undefined} proxy proxy + * @param {string | URL | undefined} proxy proxy * @returns {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} fn */ const proxyFetch = (request, proxy) => (url, options, callback) => { diff --git a/lib/serialization/FileMiddleware.js b/lib/serialization/FileMiddleware.js index 1b24bc99275..41b7da48391 100644 --- a/lib/serialization/FileMiddleware.js +++ b/lib/serialization/FileMiddleware.js @@ -554,7 +554,7 @@ class FileMiddleware extends SerializerMiddleware { * @param {(value?: undefined) => void} resolve resolve */ resolve => { - this.fs.rename(filename, `${filename}.old`, err => { + this.fs.rename(filename, `${filename}.old`, _err => { resolve(); }); } diff --git a/lib/sharing/ConsumeSharedModule.js b/lib/sharing/ConsumeSharedModule.js index 20f8fda1ed3..7e14b716bc9 100644 --- a/lib/sharing/ConsumeSharedModule.js +++ b/lib/sharing/ConsumeSharedModule.js @@ -177,7 +177,7 @@ class ConsumeSharedModule extends Module { * @param {CodeGenerationContext} context context for code generation * @returns {CodeGenerationResult} result */ - codeGeneration({ chunkGraph, moduleGraph, runtimeTemplate }) { + codeGeneration({ chunkGraph, runtimeTemplate }) { const runtimeRequirements = new Set([RuntimeGlobals.shareScopeMap]); const { shareScope, diff --git a/lib/sharing/ProvideSharedModule.js b/lib/sharing/ProvideSharedModule.js index 1e67f79f4e0..e4c83e6c99a 100644 --- a/lib/sharing/ProvideSharedModule.js +++ b/lib/sharing/ProvideSharedModule.js @@ -132,7 +132,7 @@ class ProvideSharedModule extends Module { * @param {CodeGenerationContext} context context for code generation * @returns {CodeGenerationResult} result */ - codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) { + codeGeneration({ runtimeTemplate, chunkGraph }) { const runtimeRequirements = new Set([RuntimeGlobals.initializeSharing]); const code = `register(${JSON.stringify(this._name)}, ${JSON.stringify( this._version || "0" diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index e51a1248fa9..dce67f1dae4 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -495,7 +495,7 @@ const EXTRACT_ERROR = { errorDetails: ( object, error, - { type, compilation, cachedGetErrors, cachedGetWarnings }, + { type, compilation, cachedGetErrors }, { errorDetails } ) => { if ( @@ -1037,7 +1037,7 @@ const SIMPLE_EXTRACTORS = { _: ( object, asset, - { compilation, compilationFileToChunks, compilationAuxiliaryFileToChunks } + { compilationFileToChunks, compilationAuxiliaryFileToChunks } ) => { const chunks = compilationFileToChunks.get(asset.name) || []; const auxiliaryChunks = @@ -1522,7 +1522,7 @@ const SIMPLE_EXTRACTORS = { ids: (object, chunk) => { object.id = /** @type {ChunkId} */ (chunk.id); }, - chunkRelations: (object, chunk, { compilation: { chunkGraph } }) => { + chunkRelations: (object, chunk, _context) => { /** @type {Set} */ const parents = new Set(); /** @type {Set} */ @@ -1703,7 +1703,7 @@ const SORTERS = { "chunk.modules": MODULES_SORTER, "module.modules": MODULES_SORTER, "module.reasons": { - _: (comparators, { compilation: { chunkGraph } }) => { + _: (comparators, _context) => { comparators.push( compareSelect(x => x.originModule, compareModulesByIdentifier) ); @@ -2147,7 +2147,7 @@ const ASSETS_GROUPERS = { }); } }, - groupAssetsByInfo: (groupConfigs, context, options) => { + groupAssetsByInfo: (groupConfigs, _context, _options) => { /** * @param {string} name name */ @@ -2168,7 +2168,7 @@ const ASSETS_GROUPERS = { groupByAssetInfoFlag("development"); groupByAssetInfoFlag("hotModuleReplacement"); }, - groupAssetsByChunk: (groupConfigs, context, options) => { + groupAssetsByChunk: (groupConfigs, _context, _options) => { /** * @param {keyof KnownStatsAsset} name name */ diff --git a/lib/stats/DefaultStatsPresetPlugin.js b/lib/stats/DefaultStatsPresetPlugin.js index 96b26d74ded..02e4c3dad66 100644 --- a/lib/stats/DefaultStatsPresetPlugin.js +++ b/lib/stats/DefaultStatsPresetPlugin.js @@ -384,7 +384,7 @@ class DefaultStatsPresetPlugin { const defaults = NAMED_PRESETS[/** @type {keyof NamedPresets} */ (key)]; compilation.hooks.statsPreset .for(key) - .tap(PLUGIN_NAME, (options, context) => { + .tap(PLUGIN_NAME, (options, _context) => { applyDefaults(options, defaults); }); } diff --git a/lib/stats/DefaultStatsPrinterPlugin.js b/lib/stats/DefaultStatsPrinterPlugin.js index 9ffbd6a1b20..accddc5d287 100644 --- a/lib/stats/DefaultStatsPrinterPlugin.js +++ b/lib/stats/DefaultStatsPrinterPlugin.js @@ -494,7 +494,7 @@ const MODULE_SIMPLE_PRINTERS = { const [prefix, resource] = getModuleName(name); return `${prefix || ""}${bold(resource || "")}`; }, - "module.identifier": identifier => undefined, + "module.identifier": _identifier => undefined, "module.layer": (layer, { formatLayer }) => layer ? formatLayer(layer) : undefined, "module.sizes": printSizes, @@ -571,7 +571,7 @@ const MODULE_SIMPLE_PRINTERS = { yellow(optimizationBailout), "module.issuerPath": (issuerPath, { module }) => module.profile ? undefined : "", - "module.profile": profile => undefined, + "module.profile": _profile => undefined, "module.filteredModules": (filteredModules, { module: { modules } }) => filteredModules > 0 ? `${moreCount(modules, filteredModules)} nested ${plural( @@ -831,7 +831,7 @@ const ERROR_PRINTERS = { " " ) : undefined, - "error.moduleTrace": moduleTrace => undefined, + "error.moduleTrace": _moduleTrace => undefined, "error.separator!": () => "\n" }; @@ -1856,7 +1856,7 @@ class DefaultStatsPrinterPlugin { const preferredOrder = PREFERRED_ORDERS[key]; stats.hooks.sortElements .for(key) - .tap(PLUGIN_NAME, (elements, context) => { + .tap(PLUGIN_NAME, (elements, _context) => { createOrder(elements, preferredOrder); }); } diff --git a/package.json b/package.json index 3471f673175..1c11d9bffe4 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "@webassemblyjs/wasm-edit": "^1.14.1", "@webassemblyjs/wasm-parser": "^1.14.1", "acorn": "^8.15.0", + "acorn-import-phases": "^1.0.3", "browserslist": "^4.24.0", "chrome-trace-event": "^1.0.2", "enhanced-resolve": "^5.17.2", @@ -136,7 +137,7 @@ "eslint-plugin-import": "^2.32.0", "eslint-plugin-jest": "^29.0.1", "eslint-plugin-jsdoc": "^51.2.3", - "eslint-plugin-n": "^17.20.0", + "eslint-plugin-n": "^17.21.0", "eslint-plugin-prettier": "^5.5.0", "eslint-plugin-unicorn": "^59.0.1", "file-loader": "^6.0.0", diff --git a/setup/setup.js b/setup/setup.js index d109aaf779b..83373e617d6 100644 --- a/setup/setup.js +++ b/setup/setup.js @@ -43,7 +43,7 @@ async function runSetupSymlinkAsync() { * @returns {Promise} result */ function checkSymlinkExistsAsync() { - return new Promise((resolve, reject) => { + return new Promise(resolve => { if ( fs.existsSync(nodeModulesFolder) && fs.existsSync(webpackDependencyFolder) && diff --git a/test/Compiler-caching.test.js b/test/Compiler-caching.test.js index e30346d8cee..69f0a99861f 100644 --- a/test/Compiler-caching.test.js +++ b/test/Compiler-caching.test.js @@ -133,12 +133,12 @@ describe("Compiler (caching)", () => { const options = {}; const tempFixture = createTempFixture(); - const helper = compile(tempFixture.cFilepath, options, (stats, files) => { + const helper = compile(tempFixture.cFilepath, options, (stats, _files) => { // Not cached the first time expect(stats.assets[0].name).toBe("bundle.js"); expect(stats.assets[0].emitted).toBe(true); - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, _files, _iteration) => { // Cached the second run expect(stats.assets[0].name).toBe("bundle.js"); expect(stats.assets[0].emitted).toBe(false); @@ -151,7 +151,7 @@ describe("Compiler (caching)", () => { setTimeout(() => { fs.writeFileSync(tempFixture.aFilepath, aContent); - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, _files, _iteration) => { // Cached the third run expect(stats.assets[0].name).toBe("bundle.js"); expect(stats.assets[0].emitted).toBe(true); @@ -167,12 +167,12 @@ describe("Compiler (caching)", () => { const options = {}; const tempFixture = createTempFixture(); - const helper = compile(tempFixture.cFilepath, options, (stats, files) => { + const helper = compile(tempFixture.cFilepath, options, (stats, _files) => { // Not cached the first time expect(stats.assets[0].name).toBe("bundle.js"); expect(stats.assets[0].emitted).toBe(true); - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, files, _iteration) => { // Cached the second run expect(stats.assets[0].name).toBe("bundle.js"); expect(stats.assets[0].emitted).toBe(false); @@ -186,7 +186,7 @@ describe("Compiler (caching)", () => { fs.writeFileSync(tempFixture.aFilepath, aContent); - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, files, _iteration) => { // Cached the third run expect(stats.assets[0].name).toBe("bundle.js"); expect(stats.assets[0].emitted).toBe(true); @@ -203,7 +203,7 @@ describe("Compiler (caching)", () => { const options = {}; const tempFixture = createTempFixture(); - const helper = compile(tempFixture.cFilepath, options, (stats, files) => { + const helper = compile(tempFixture.cFilepath, options, (stats, _files) => { // Built the first time expect(stats.modules[0].name).toMatch("c.js"); expect(stats.modules[0].built).toBe(true); @@ -212,7 +212,7 @@ describe("Compiler (caching)", () => { expect(stats.modules[1].built).toBe(true); setTimeout(() => { - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, _files, _iteration) => { // Not built when cached the second run expect(stats.modules[0].name).toMatch("c.js"); // expect(stats.modules[0].built).toBe(false); @@ -228,7 +228,7 @@ describe("Compiler (caching)", () => { setTimeout(() => { fs.writeFileSync(tempFixture.aFilepath, aContent); - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, _files, _iteration) => { // And only a.js built after it was modified expect(stats.modules[0].name).toMatch("c.js"); expect(stats.modules[0].built).toBe(false); @@ -248,7 +248,7 @@ describe("Compiler (caching)", () => { const options = {}; const tempFixture = createTempFixture(); - const helper = compile(tempFixture.cFilepath, options, (stats, files) => { + const helper = compile(tempFixture.cFilepath, options, (stats, _files) => { // Built the first time expect(stats.modules[0].name).toMatch("c.js"); expect(stats.modules[0].built).toBe(true); @@ -256,7 +256,7 @@ describe("Compiler (caching)", () => { expect(stats.modules[1].name).toMatch("a.js"); expect(stats.modules[1].built).toBe(true); - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, _files, _iteration) => { // Not built when cached the second run expect(stats.modules[0].name).toMatch("c.js"); // expect(stats.modules[0].built).toBe(false); @@ -271,7 +271,7 @@ describe("Compiler (caching)", () => { fs.writeFileSync(tempFixture.aFilepath, aContent); - helper.runAgain((stats, files, iteration) => { + helper.runAgain((stats, _files, _iteration) => { // And only a.js built after it was modified expect(stats.modules[0].name).toMatch("c.js"); // expect(stats.modules[0].built).toBe(false); diff --git a/test/Compiler.test.js b/test/Compiler.test.js index 161879602f5..7eabfa723b4 100644 --- a/test/Compiler.test.js +++ b/test/Compiler.test.js @@ -94,7 +94,7 @@ describe("Compiler", () => { filename: "the/hell.js" } }, - (stats, files) => { + (stats, _files) => { expect(stats.logs.mkdir).toEqual(["/what", "/what/the"]); done(); } @@ -340,7 +340,7 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); if (compiler.outputFileSystem.existsSync("/bundle.js")) { return done(new Error("Bundle should not be created on error")); @@ -430,7 +430,7 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { watching.close(); if (err) return done(err); if (compiler.outputFileSystem.existsSync("/bundle.js")) { @@ -453,10 +453,10 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); }); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(); }); }); @@ -474,10 +474,10 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); }); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(); }); }); @@ -495,10 +495,10 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); }); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(); }); }); @@ -516,10 +516,10 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); }); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(); }); }); @@ -540,7 +540,7 @@ describe("Compiler", () => { () => {} ); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(); }); }); @@ -561,7 +561,7 @@ describe("Compiler", () => { compiler.run((err, stats1) => { if (err) return done(err); - compiler.run((err, stats2) => { + compiler.run((err, _stats2) => { if (err) return done(err); expect(stats1.toString({ all: true })).toBeTypeOf("string"); done(); @@ -582,10 +582,10 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { if (err) return done(err); watching.close(done); }); @@ -605,11 +605,11 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { if (err) return done(err); }); watching.close(() => { - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); done(); }); @@ -629,7 +629,7 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { if (err) return done(err); watching.close(done); }); @@ -649,11 +649,11 @@ describe("Compiler", () => { } }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { if (err) return done(err); }); watching.close(() => { - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); done(); }); @@ -677,12 +677,12 @@ describe("Compiler", () => { compiler.hooks.afterDone.tap("RunAgainTest", () => { if (!once) return; once = false; - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); done(); }); }); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); }); }); @@ -708,7 +708,7 @@ describe("Compiler", () => { expect(doneHookCb).toHaveBeenCalled(); done(); }); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); runCb(); }); @@ -729,7 +729,7 @@ describe("Compiler", () => { filename: "bundle.js" } }, - (err, stats) => { + (err, _stats) => { if (err) return done(err); instanceCb(); } @@ -770,7 +770,7 @@ describe("Compiler", () => { expect(invalidateCb).toHaveBeenCalled(); watching.close(done); }); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { if (err) return done(err); watchCb(); }); @@ -805,7 +805,7 @@ describe("Compiler", () => { expect(invalidateCb).toHaveBeenCalled(); done(); }); - const watch = compiler.watch({}, (err, stats) => { + const watch = compiler.watch({}, (err, _stats) => { if (err) return done(err); watch.close(watchCloseCb); }); @@ -881,7 +881,7 @@ describe("Compiler", () => { }); compiler.hooks.failed.tap("CompilerTest", failedSpy); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { expect(err).toBeTruthy(); expect(failedSpy).toHaveBeenCalledTimes(1); expect(failedSpy).toHaveBeenCalledWith(err); @@ -956,7 +956,7 @@ describe("Compiler", () => { plugins: [new MyPlugin()] }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((_err, _stats) => { expect(capture.toString().replace(/[\d.]+ ms/, "X ms")) .toMatchInlineSnapshot(` "<-> [MyPlugin] Group @@ -990,7 +990,7 @@ describe("Compiler", () => { plugins: [new MyPlugin()] }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((_err, _stats) => { expect(capture.toString().replace(/[\d.]+ ms/, "X ms")) .toMatchInlineSnapshot(` "<-> [MyPlugin] Group @@ -1024,7 +1024,7 @@ describe("Compiler", () => { plugins: [new MyPlugin()] }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((_err, _stats) => { expect(capture.toString()).toMatchInlineSnapshot('""'); done(); }); @@ -1047,7 +1047,7 @@ describe("Compiler", () => { plugins: [new MyPlugin()] }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((_err, _stats) => { expect(escapeAnsi(capture.toStringRaw()).replace(/[\d.]+ ms/, "X ms")) .toMatchInlineSnapshot(` "<-> [MyPlugin] Group @@ -1082,7 +1082,7 @@ describe("Compiler", () => { plugins: [new MyPlugin()] }); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((_err, _stats) => { expect(escapeAnsi(capture.toStringRaw()).replace(/[\d.]+ ms/, "X ms")) .toMatchInlineSnapshot(` "<-> [MyPlugin] Group diff --git a/test/JavascriptParser.unittest.js b/test/JavascriptParser.unittest.js index 09d19918c27..c34c545cd17 100644 --- a/test/JavascriptParser.unittest.js +++ b/test/JavascriptParser.unittest.js @@ -270,10 +270,10 @@ describe("JavascriptParser", () => { const testParser = new JavascriptParser({}); testParser.hooks.canRename .for("abc") - .tap("JavascriptParserTest", expr => true); + .tap("JavascriptParserTest", _expr => true); testParser.hooks.canRename .for("ijk") - .tap("JavascriptParserTest", expr => true); + .tap("JavascriptParserTest", _expr => true); testParser.hooks.call.for("abc").tap("JavascriptParserTest", expr => { if (!testParser.state.abc) testParser.state.abc = []; testParser.state.abc.push(testParser.parseString(expr.arguments[0])); @@ -295,7 +295,7 @@ describe("JavascriptParser", () => { }); testParser.hooks.expression .for("fgh") - .tap("JavascriptParserTest", expr => { + .tap("JavascriptParserTest", _expr => { if (!testParser.state.fgh) testParser.state.fgh = []; testParser.state.fgh.push( [...testParser.scope.definitions.asSet()].join(" ") @@ -304,7 +304,7 @@ describe("JavascriptParser", () => { }); testParser.hooks.expression .for("fgh.sub") - .tap("JavascriptParserTest", expr => { + .tap("JavascriptParserTest", _expr => { if (!testParser.state.fghsub) testParser.state.fghsub = []; testParser.state.fghsub.push( testParser.scope.inTry ? "try" : "notry" @@ -313,7 +313,7 @@ describe("JavascriptParser", () => { }); testParser.hooks.expression .for("ijk.sub") - .tap("JavascriptParserTest", expr => { + .tap("JavascriptParserTest", _expr => { if (!testParser.state.ijksub) testParser.state.ijksub = []; testParser.state.ijksub.push("test"); return true; @@ -710,7 +710,7 @@ describe("JavascriptParser", () => { const parser = new JavascriptParser(); - parser.hooks.statement.tap("JavascriptParserTest", expr => { + parser.hooks.statement.tap("JavascriptParserTest", _expr => { definitions = parser.scope.definitions; return true; }); diff --git a/test/MultiCompiler.test.js b/test/MultiCompiler.test.js index 403d0dfc89d..3571d6cea80 100644 --- a/test/MultiCompiler.test.js +++ b/test/MultiCompiler.test.js @@ -26,7 +26,7 @@ const createMultiCompiler = options => { ); compiler.outputFileSystem = createFsFromVolume(new Volume()); compiler.watchFileSystem = { - watch(a, b, c, d, e, f, g) {} + watch(_a, _b, _c, _d, _e, _f, _g) {} }; return compiler; }; @@ -64,10 +64,10 @@ describe("MultiCompiler", () => { it("should not be running twice at a time (run)", done => { const compiler = createMultiCompiler(); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); }); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) { compiler.close(done); } @@ -76,10 +76,10 @@ describe("MultiCompiler", () => { it("should not be running twice at a time (watch)", done => { const compiler = createMultiCompiler(); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); }); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) { compiler.close(done); } @@ -88,10 +88,10 @@ describe("MultiCompiler", () => { it("should not be running twice at a time (run - watch)", done => { const compiler = createMultiCompiler(); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); }); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) { compiler.close(done); } @@ -100,10 +100,10 @@ describe("MultiCompiler", () => { it("should not be running twice at a time (watch - run)", done => { const compiler = createMultiCompiler(); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); }); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) { compiler.close(done); } @@ -124,7 +124,7 @@ describe("MultiCompiler", () => { () => {} ); compiler.outputFileSystem = createFsFromVolume(new Volume()); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) { compiler.close(done); } @@ -133,10 +133,10 @@ describe("MultiCompiler", () => { it("should run again correctly after first compilation", done => { const compiler = createMultiCompiler(); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); compiler.close(done); }); @@ -145,10 +145,10 @@ describe("MultiCompiler", () => { it("should watch again correctly after first compilation", done => { const compiler = createMultiCompiler(); - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); compiler.close(done); }); @@ -157,11 +157,11 @@ describe("MultiCompiler", () => { it("should run again correctly after first closed watch", done => { const compiler = createMultiCompiler(); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { if (err) return done(err); }); watching.close(() => { - compiler.run((err, stats) => { + compiler.run((err, _stats) => { if (err) return done(err); compiler.close(done); }); @@ -170,11 +170,11 @@ describe("MultiCompiler", () => { it("should watch again correctly after first closed watch", done => { const compiler = createMultiCompiler(); - const watching = compiler.watch({}, (err, stats) => { + const watching = compiler.watch({}, (err, _stats) => { if (err) return done(err); }); watching.close(() => { - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); compiler.close(done); }); @@ -210,7 +210,7 @@ describe("MultiCompiler", () => { events.push(`${c.name} done`); }); } - compiler.run((err, stats) => { + compiler.run((_err, _stats) => { expect(events.join(" ")).toBe( "a run a done b run b done d run d done e run e done c run c done" ); @@ -628,7 +628,7 @@ describe("MultiCompiler", () => { } } }; - compiler.watch({}, (err, stats) => { + compiler.watch({}, (err, _stats) => { if (err) return done(err); compiler.close(done); }); diff --git a/test/TestCases.template.js b/test/TestCases.template.js index dcb7d3ac9e2..f035711c55f 100644 --- a/test/TestCases.template.js +++ b/test/TestCases.template.js @@ -3,16 +3,14 @@ require("./helpers/warmup-webpack"); const path = require("path"); -const { URL, pathToFileURL } = require("url"); -const vm = require("vm"); const fs = require("graceful-fs"); const rimraf = require("rimraf"); const checkArrayExpectation = require("./checkArrayExpectation"); -const asModule = require("./helpers/asModule"); const captureStdio = require("./helpers/captureStdio"); const createLazyTestEnv = require("./helpers/createLazyTestEnv"); const deprecationTracking = require("./helpers/deprecationTracking"); const filterInfraStructureErrors = require("./helpers/infrastructureLogErrors"); +const { TestRunner } = require("./runner/index"); const casesPath = path.join(__dirname, "cases"); let categories = fs.readdirSync(casesPath); @@ -434,109 +432,33 @@ const describeCases = config => { ); it(`${testName} should load the compiled tests`, done => { - const esmContext = vm.createContext({ - it: _it, - expect, - process, - global, - URL, - Buffer, - setTimeout, - setImmediate, - nsObj(m) { - Object.defineProperty(m, Symbol.toStringTag, { - value: "Module" - }); - return m; - } + const runner = new TestRunner({ + target: options.target, + outputDirectory, + testMeta: { + category: category.name, + name: testName + }, + testConfig, + webpackOptions: options }); - cleanups.push(() => (esmContext.it = undefined)); - - /** - * @param {string} module a module - * @param {"evaluated" | "unlinked"=} esmMode esm mode - * @returns {EXPECTED_ANY} required module - * @private - */ - function _require(module, esmMode) { - if (module.startsWith("./")) { - const p = path.join(outputDirectory, module); - const content = fs.readFileSync(p, "utf8"); - if (p.endsWith(".mjs")) { - let esm; - try { - esm = new vm.SourceTextModule(content, { - identifier: p, - context: esmContext, - initializeImportMeta: (meta, module) => { - meta.url = pathToFileURL(p).href; - }, - importModuleDynamically: async (specifier, module) => { - const result = await _require(specifier, "evaluated"); - return await asModule(result, module.context); - } - }); - cleanups.push(() => (esmContext.it = undefined)); - } catch (err) { - console.log(err); - err.message += `\nwhile parsing ${p}`; - throw err; - } - if (esmMode === "unlinked") return esm; - return (async () => { - await esm.link( - async (specifier, module) => - await asModule( - await _require(specifier, "unlinked"), - module.context, - true - ) - ); - // node.js 10 needs instantiate - if (esm.instantiate) esm.instantiate(); - await esm.evaluate(); - if (esmMode === "evaluated") return esm; - const ns = esm.namespace; - return ns.default && ns.default instanceof Promise - ? ns.default - : ns; - })(); - } - const fn = vm.runInThisContext( - "(function(require, module, exports, __dirname, __filename, it, expect) {" + - "global.expect = expect;" + - `function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }${ - content - }\n})`, - p - ); - const m = { - exports: {}, - webpackTestSuiteModule: true - }; - fn.call( - m.exports, - _require, - m, - m.exports, - outputDirectory, - p, - _it, - expect - ); - return m.exports; - } - return require(module); + runner.mergeModuleScope({ + it: _it + }); + if (testConfig.moduleScope) { + testConfig.moduleScope(runner._moduleScope, options); } - _require.webpackTestSuiteRequire = true; - Promise.resolve() - .then(() => _require(`./${options.output.filename}`)) - .then(() => { - if (getNumberOfTests() === 0) { - return done(new Error("No tests exported by test case")); - } - done(); - }, done); + runner.require.webpackTestSuiteRequire = true; + const results = []; + results.push( + runner.require(outputDirectory, `./${options.output.filename}`) + ); + Promise.all(results).then(() => { + if (getNumberOfTests() === 0) { + return done(new Error("No tests exported by test case")); + } + done(); + }, done); }, 10000); const { it: _it, getNumberOfTests } = createLazyTestEnv( diff --git a/test/WatchTestCases.template.js b/test/WatchTestCases.template.js index 16736a9e454..e48843c6056 100644 --- a/test/WatchTestCases.template.js +++ b/test/WatchTestCases.template.js @@ -212,7 +212,7 @@ const describeCases = config => { const compiler = webpack(options); compiler.hooks.invalid.tap( "WatchTestCasesTest", - (filename, mtime) => { + (filename, _mtime) => { triggeringFilename = filename; } ); diff --git a/test/WatcherEvents.test.js b/test/WatcherEvents.test.js index 3d0230743ef..2db8e930bee 100644 --- a/test/WatcherEvents.test.js +++ b/test/WatcherEvents.test.js @@ -38,7 +38,7 @@ describe("WatcherEvents", () => { let called = false; const compiler = createSingleCompiler(); - const watcher = compiler.watch({}, (err, stats) => { + const watcher = compiler.watch({}, (err, _stats) => { expect(called).toBe(true); done(err); }); @@ -56,7 +56,7 @@ describe("WatcherEvents", () => { let called = false; const compiler = createMultiCompiler(); - const watcher = compiler.watch({}, (err, stats) => { + const watcher = compiler.watch({}, (err, _stats) => { expect(called).toBe(true); done(err); }); diff --git a/test/WebpackError.unittest.js b/test/WebpackError.unittest.js index 19e59b59378..7c38588f076 100644 --- a/test/WebpackError.unittest.js +++ b/test/WebpackError.unittest.js @@ -4,7 +4,7 @@ const WebpackError = require("../lib/WebpackError"); describe("WebpackError", () => { class CustomError extends WebpackError { - constructor(message) { + constructor() { super(); this.name = "CustomError"; diff --git a/test/cases/parsing/optional-chaining/test.filter.js b/test/cases/parsing/optional-chaining/test.filter.js index e54f5d848b4..9486c09cf37 100644 --- a/test/cases/parsing/optional-chaining/test.filter.js +++ b/test/cases/parsing/optional-chaining/test.filter.js @@ -1,3 +1,3 @@ const supportsOptionalChaining = require("../../../helpers/supportsOptionalChaining"); -module.exports = config => supportsOptionalChaining(); +module.exports = () => supportsOptionalChaining(); diff --git a/test/configCases/asset-modules/only-entry/test.config.js b/test/configCases/asset-modules/only-entry/test.config.js index 32f4be1d473..f48f8b79def 100644 --- a/test/configCases/asset-modules/only-entry/test.config.js +++ b/test/configCases/asset-modules/only-entry/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["test.js"]; } }; diff --git a/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js b/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js index a9a1dbbfb6b..96dfc3ba940 100644 --- a/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js +++ b/test/configCases/asset-modules/query-and-custom-condition/webpack.config.js @@ -10,7 +10,7 @@ module.exports = { type: "asset", /** @type {ParserOptionsByModuleTypeKnown['asset']} */ parser: { - dataUrlCondition: (source, { filename, module }) => + dataUrlCondition: (source, { filename }) => filename.includes("?foo=bar") } } diff --git a/test/configCases/chunk-graph/issue-17989/test.config.js b/test/configCases/chunk-graph/issue-17989/test.config.js index fa813148fb8..e03ba4e8401 100644 --- a/test/configCases/chunk-graph/issue-17989/test.config.js +++ b/test/configCases/chunk-graph/issue-17989/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["a.js", "b.js"]; } }; diff --git a/test/configCases/chunk-graph/issue-9634/test.config.js b/test/configCases/chunk-graph/issue-9634/test.config.js index fa813148fb8..e03ba4e8401 100644 --- a/test/configCases/chunk-graph/issue-9634/test.config.js +++ b/test/configCases/chunk-graph/issue-9634/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["a.js", "b.js"]; } }; diff --git a/test/configCases/chunk-graph/rewalk-chunk/test.config.js b/test/configCases/chunk-graph/rewalk-chunk/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/chunk-graph/rewalk-chunk/test.config.js +++ b/test/configCases/chunk-graph/rewalk-chunk/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/chunk-index/issue-18008/test.config.js b/test/configCases/chunk-index/issue-18008/test.config.js index 52779458946..4e1620b1056 100644 --- a/test/configCases/chunk-index/issue-18008/test.config.js +++ b/test/configCases/chunk-index/issue-18008/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js", "A.js", "shared.js", "B.js", "B-2.js"]; } }; diff --git a/test/configCases/chunk-index/order-multiple-entries/test.config.js b/test/configCases/chunk-index/order-multiple-entries/test.config.js index 76c7ddf80f5..e4c2d7d4b4a 100644 --- a/test/configCases/chunk-index/order-multiple-entries/test.config.js +++ b/test/configCases/chunk-index/order-multiple-entries/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["entry1.js", "entry2.js"]; } }; diff --git a/test/configCases/concatenate-modules/load-chunk-function/test.config.js b/test/configCases/concatenate-modules/load-chunk-function/test.config.js index 76c7ddf80f5..e4c2d7d4b4a 100644 --- a/test/configCases/concatenate-modules/load-chunk-function/test.config.js +++ b/test/configCases/concatenate-modules/load-chunk-function/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["entry1.js", "entry2.js"]; } }; diff --git a/test/configCases/concatenate-modules/split-chunk-entry-module/test.config.js b/test/configCases/concatenate-modules/split-chunk-entry-module/test.config.js index 6f8ffeaa317..ed54956ea13 100644 --- a/test/configCases/concatenate-modules/split-chunk-entry-module/test.config.js +++ b/test/configCases/concatenate-modules/split-chunk-entry-module/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["runtime.js", "common-index_js.js", "main.js"]; } }; diff --git a/test/configCases/container/0-container-full/test.config.js b/test/configCases/container/0-container-full/test.config.js index 0755f427ddc..acc7d2091c8 100644 --- a/test/configCases/container/0-container-full/test.config.js +++ b/test/configCases/container/0-container-full/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return i === 0 ? "./main.js" : "./module/main.mjs"; } }; diff --git a/test/configCases/container/1-container-full/test.config.js b/test/configCases/container/1-container-full/test.config.js index 0755f427ddc..acc7d2091c8 100644 --- a/test/configCases/container/1-container-full/test.config.js +++ b/test/configCases/container/1-container-full/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return i === 0 ? "./main.js" : "./module/main.mjs"; } }; diff --git a/test/configCases/container/module-federation-with-shareScope/test.config.js b/test/configCases/container/module-federation-with-shareScope/test.config.js index 0755f427ddc..acc7d2091c8 100644 --- a/test/configCases/container/module-federation-with-shareScope/test.config.js +++ b/test/configCases/container/module-federation-with-shareScope/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return i === 0 ? "./main.js" : "./module/main.mjs"; } }; diff --git a/test/configCases/container/reference-hoisting/test.config.js b/test/configCases/container/reference-hoisting/test.config.js index 0755f427ddc..acc7d2091c8 100644 --- a/test/configCases/container/reference-hoisting/test.config.js +++ b/test/configCases/container/reference-hoisting/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return i === 0 ? "./main.js" : "./module/main.mjs"; } }; diff --git a/test/configCases/container/track-initial-chunks/test.config.js b/test/configCases/container/track-initial-chunks/test.config.js index 0755f427ddc..acc7d2091c8 100644 --- a/test/configCases/container/track-initial-chunks/test.config.js +++ b/test/configCases/container/track-initial-chunks/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return i === 0 ? "./main.js" : "./module/main.mjs"; } }; diff --git a/test/configCases/context-modules/context-options/dir/module-a.js b/test/configCases/context-modules/context-options/dir/module-a.js new file mode 100644 index 00000000000..e94fef18587 --- /dev/null +++ b/test/configCases/context-modules/context-options/dir/module-a.js @@ -0,0 +1 @@ +export default "a"; diff --git a/test/configCases/context-modules/context-options/dir/module-b.js b/test/configCases/context-modules/context-options/dir/module-b.js new file mode 100644 index 00000000000..eff703ff465 --- /dev/null +++ b/test/configCases/context-modules/context-options/dir/module-b.js @@ -0,0 +1 @@ +export default "b"; diff --git a/test/configCases/context-modules/context-options/dir/module-c.js b/test/configCases/context-modules/context-options/dir/module-c.js new file mode 100644 index 00000000000..5d50db5bc15 --- /dev/null +++ b/test/configCases/context-modules/context-options/dir/module-c.js @@ -0,0 +1 @@ +export default "c"; diff --git a/test/configCases/context-modules/context-options/index.js b/test/configCases/context-modules/context-options/index.js new file mode 100644 index 00000000000..699ea3632ed --- /dev/null +++ b/test/configCases/context-modules/context-options/index.js @@ -0,0 +1,39 @@ +async function loadModule(name) { + return import("./dir/" + name); +} + +async function loadModuleWithExclude(name) { + return import(/* webpackExclude: /module-b\.js$/ */ "./dir/" + name); +} + +async function loadModuleWithInclude(name) { + return import(/* webpackInclude: /module-b\.js$/ */ "./dir/" + name); +} + +async function loadModuleWithMode(name) { + return import(/* webpackMode: "eager" */ "./dir/" + name); +} + +it("should work when no options", async () => { + expect((await loadModule("module-a.js")).default).toBe("a"); + expect((await loadModule("module-b.js")).default).toBe("b"); + expect((await loadModule("module-c.js")).default).toBe("c"); +}); + +it("should work with exclude", async () => { + expect((await loadModuleWithExclude("module-a.js")).default).toBe("a"); + await expect(loadModuleWithExclude("module-b.js")).rejects.toThrow("Cannot find module './module-b.js'"); + expect((await loadModuleWithExclude("module-c.js")).default).toBe("c"); +}); + +it("should work with include", async () => { + await expect(loadModuleWithInclude("module-a.js")).rejects.toThrow("Cannot find module './module-a.js'"); + expect((await loadModuleWithInclude("module-b.js")).default).toBe("b"); + await expect(loadModuleWithInclude("module-c.js")).rejects.toThrow("Cannot find module './module-c.js'"); +}); + +it("should work with mode", async () => { + expect((await loadModuleWithMode("module-a.js")).default).toBe("a"); + expect((await loadModuleWithMode("module-b.js")).default).toBe("b"); + expect((await loadModuleWithMode("module-c.js")).default).toBe("c"); +}); diff --git a/test/configCases/context-modules/context-options/webpack.config.js b/test/configCases/context-modules/context-options/webpack.config.js new file mode 100644 index 00000000000..3583b70a321 --- /dev/null +++ b/test/configCases/context-modules/context-options/webpack.config.js @@ -0,0 +1,2 @@ +/** @type {import("../../../../").Configuration} */ +module.exports = {}; diff --git a/test/configCases/context-exclusion/simple/index.js b/test/configCases/context-modules/exclusion/index.js similarity index 100% rename from test/configCases/context-exclusion/simple/index.js rename to test/configCases/context-modules/exclusion/index.js diff --git a/test/configCases/context-exclusion/simple/some-dir/check-here/check-here/file.js b/test/configCases/context-modules/exclusion/some-dir/check-here/check-here/file.js similarity index 100% rename from test/configCases/context-exclusion/simple/some-dir/check-here/check-here/file.js rename to test/configCases/context-modules/exclusion/some-dir/check-here/check-here/file.js diff --git a/test/configCases/context-exclusion/simple/some-dir/check-here/dont-check-here/file.js b/test/configCases/context-modules/exclusion/some-dir/check-here/dont-check-here/file.js similarity index 100% rename from test/configCases/context-exclusion/simple/some-dir/check-here/dont-check-here/file.js rename to test/configCases/context-modules/exclusion/some-dir/check-here/dont-check-here/file.js diff --git a/test/configCases/context-exclusion/simple/some-dir/check-here/file.js b/test/configCases/context-modules/exclusion/some-dir/check-here/file.js similarity index 100% rename from test/configCases/context-exclusion/simple/some-dir/check-here/file.js rename to test/configCases/context-modules/exclusion/some-dir/check-here/file.js diff --git a/test/configCases/context-exclusion/simple/some-dir/dont-check-here/file.js b/test/configCases/context-modules/exclusion/some-dir/dont-check-here/file.js similarity index 100% rename from test/configCases/context-exclusion/simple/some-dir/dont-check-here/file.js rename to test/configCases/context-modules/exclusion/some-dir/dont-check-here/file.js diff --git a/test/configCases/context-exclusion/simple/some-dir/dont.js b/test/configCases/context-modules/exclusion/some-dir/dont.js similarity index 100% rename from test/configCases/context-exclusion/simple/some-dir/dont.js rename to test/configCases/context-modules/exclusion/some-dir/dont.js diff --git a/test/configCases/context-exclusion/simple/some-dir/file.js b/test/configCases/context-modules/exclusion/some-dir/file.js similarity index 100% rename from test/configCases/context-exclusion/simple/some-dir/file.js rename to test/configCases/context-modules/exclusion/some-dir/file.js diff --git a/test/configCases/context-exclusion/simple/webpack.config.js b/test/configCases/context-modules/exclusion/webpack.config.js similarity index 100% rename from test/configCases/context-exclusion/simple/webpack.config.js rename to test/configCases/context-modules/exclusion/webpack.config.js diff --git a/test/configCases/context-replacement/System.import/index.js b/test/configCases/context-modules/replacement-System.import/index.js similarity index 100% rename from test/configCases/context-replacement/System.import/index.js rename to test/configCases/context-modules/replacement-System.import/index.js diff --git a/test/configCases/context-replacement/System.import/modules/module-b.js b/test/configCases/context-modules/replacement-System.import/modules/module-b.js similarity index 100% rename from test/configCases/context-replacement/System.import/modules/module-b.js rename to test/configCases/context-modules/replacement-System.import/modules/module-b.js diff --git a/test/configCases/context-replacement/System.import/webpack.config.js b/test/configCases/context-modules/replacement-System.import/webpack.config.js similarity index 91% rename from test/configCases/context-replacement/System.import/webpack.config.js rename to test/configCases/context-modules/replacement-System.import/webpack.config.js index 3b5569bcc74..102b3879caa 100644 --- a/test/configCases/context-replacement/System.import/webpack.config.js +++ b/test/configCases/context-modules/replacement-System.import/webpack.config.js @@ -5,7 +5,7 @@ var webpack = require("../../../../"); module.exports = { plugins: [ new webpack.ContextReplacementPlugin( - /context-replacement/, + /replacement/, path.resolve(__dirname, "modules"), { a: "./module-b" diff --git a/test/configCases/context-replacement/a/index.js b/test/configCases/context-modules/replacement-a/index.js similarity index 100% rename from test/configCases/context-replacement/a/index.js rename to test/configCases/context-modules/replacement-a/index.js diff --git a/test/configCases/context-replacement/a/new-context/node_modules/error.js b/test/configCases/context-modules/replacement-a/new-context/node_modules/error.js similarity index 100% rename from test/configCases/context-replacement/a/new-context/node_modules/error.js rename to test/configCases/context-modules/replacement-a/new-context/node_modules/error.js diff --git a/test/configCases/context-replacement/a/new-context/node_modules/replaced.js b/test/configCases/context-modules/replacement-a/new-context/node_modules/replaced.js similarity index 100% rename from test/configCases/context-replacement/a/new-context/node_modules/replaced.js rename to test/configCases/context-modules/replacement-a/new-context/node_modules/replaced.js diff --git a/test/configCases/context-replacement/a/webpack.config.js b/test/configCases/context-modules/replacement-a/webpack.config.js similarity index 88% rename from test/configCases/context-replacement/a/webpack.config.js rename to test/configCases/context-modules/replacement-a/webpack.config.js index 2b44d0ceb8f..8d86fa0a012 100644 --- a/test/configCases/context-replacement/a/webpack.config.js +++ b/test/configCases/context-modules/replacement-a/webpack.config.js @@ -4,7 +4,7 @@ const webpack = require("../../../../"); module.exports = { plugins: [ new webpack.ContextReplacementPlugin( - /context-replacement.a$/, + /replacement.a$/, "new-context", true, /^replaced$/ diff --git a/test/configCases/context-replacement/b/error.js b/test/configCases/context-modules/replacement-b/error.js similarity index 100% rename from test/configCases/context-replacement/b/error.js rename to test/configCases/context-modules/replacement-b/error.js diff --git a/test/configCases/context-replacement/b/index.js b/test/configCases/context-modules/replacement-b/index.js similarity index 100% rename from test/configCases/context-replacement/b/index.js rename to test/configCases/context-modules/replacement-b/index.js diff --git a/test/configCases/context-replacement/b/only-this.js b/test/configCases/context-modules/replacement-b/only-this.js similarity index 100% rename from test/configCases/context-replacement/b/only-this.js rename to test/configCases/context-modules/replacement-b/only-this.js diff --git a/test/configCases/context-replacement/b/webpack.config.js b/test/configCases/context-modules/replacement-b/webpack.config.js similarity index 55% rename from test/configCases/context-replacement/b/webpack.config.js rename to test/configCases/context-modules/replacement-b/webpack.config.js index 3a5a33b4df7..9fa2c022ff1 100644 --- a/test/configCases/context-replacement/b/webpack.config.js +++ b/test/configCases/context-modules/replacement-b/webpack.config.js @@ -2,7 +2,5 @@ const webpack = require("../../../../"); /** @type {import("../../../../").Configuration} */ module.exports = { - plugins: [ - new webpack.ContextReplacementPlugin(/context-replacement.b$/, /^\.\/only/) - ] + plugins: [new webpack.ContextReplacementPlugin(/replacement.b$/, /^\.\/only/)] }; diff --git a/test/configCases/context-replacement/c/index.js b/test/configCases/context-modules/replacement-c/index.js similarity index 100% rename from test/configCases/context-replacement/c/index.js rename to test/configCases/context-modules/replacement-c/index.js diff --git a/test/configCases/context-replacement/c/modules/a.js b/test/configCases/context-modules/replacement-c/modules/a.js similarity index 100% rename from test/configCases/context-replacement/c/modules/a.js rename to test/configCases/context-modules/replacement-c/modules/a.js diff --git a/test/configCases/context-replacement/c/modules/module-b.js b/test/configCases/context-modules/replacement-c/modules/module-b.js similarity index 100% rename from test/configCases/context-replacement/c/modules/module-b.js rename to test/configCases/context-modules/replacement-c/modules/module-b.js diff --git a/test/configCases/context-replacement/c/node_modules/d.js b/test/configCases/context-modules/replacement-c/node_modules/d.js similarity index 100% rename from test/configCases/context-replacement/c/node_modules/d.js rename to test/configCases/context-modules/replacement-c/node_modules/d.js diff --git a/test/configCases/context-replacement/c/webpack.config.js b/test/configCases/context-modules/replacement-c/webpack.config.js similarity index 92% rename from test/configCases/context-replacement/c/webpack.config.js rename to test/configCases/context-modules/replacement-c/webpack.config.js index 2602bce536a..6c00f0d0b04 100644 --- a/test/configCases/context-replacement/c/webpack.config.js +++ b/test/configCases/context-modules/replacement-c/webpack.config.js @@ -5,7 +5,7 @@ const webpack = require("../../../../"); module.exports = { plugins: [ new webpack.ContextReplacementPlugin( - /context-replacement.c$/, + /replacement.c$/, path.resolve(__dirname, "modules"), { a: "./a", diff --git a/test/configCases/context-replacement/d/index.js b/test/configCases/context-modules/replacement-d/index.js similarity index 100% rename from test/configCases/context-replacement/d/index.js rename to test/configCases/context-modules/replacement-d/index.js diff --git a/test/configCases/context-replacement/d/modules/a.js b/test/configCases/context-modules/replacement-d/modules/a.js similarity index 100% rename from test/configCases/context-replacement/d/modules/a.js rename to test/configCases/context-modules/replacement-d/modules/a.js diff --git a/test/configCases/context-replacement/d/queryloader.js b/test/configCases/context-modules/replacement-d/queryloader.js similarity index 100% rename from test/configCases/context-replacement/d/queryloader.js rename to test/configCases/context-modules/replacement-d/queryloader.js diff --git a/test/configCases/context-replacement/d/webpack.config.js b/test/configCases/context-modules/replacement-d/webpack.config.js similarity index 92% rename from test/configCases/context-replacement/d/webpack.config.js rename to test/configCases/context-modules/replacement-d/webpack.config.js index fb0177ae566..fdc797fc227 100644 --- a/test/configCases/context-replacement/d/webpack.config.js +++ b/test/configCases/context-modules/replacement-d/webpack.config.js @@ -13,7 +13,7 @@ module.exports = { }, plugins: [ new webpack.ContextReplacementPlugin( - /context-replacement.d$/, + /replacement.d$/, path.resolve(__dirname, "modules?cats=meow"), { a: "./a" diff --git a/test/configCases/context-replacement/e/index.js b/test/configCases/context-modules/replacement-e/index.js similarity index 100% rename from test/configCases/context-replacement/e/index.js rename to test/configCases/context-modules/replacement-e/index.js diff --git a/test/configCases/context-replacement/e/new-context/modules/error.js b/test/configCases/context-modules/replacement-e/new-context/modules/error.js similarity index 100% rename from test/configCases/context-replacement/e/new-context/modules/error.js rename to test/configCases/context-modules/replacement-e/new-context/modules/error.js diff --git a/test/configCases/context-replacement/e/new-context/modules/replaced.js b/test/configCases/context-modules/replacement-e/new-context/modules/replaced.js similarity index 100% rename from test/configCases/context-replacement/e/new-context/modules/replaced.js rename to test/configCases/context-modules/replacement-e/new-context/modules/replaced.js diff --git a/test/configCases/context-replacement/e/webpack.config.js b/test/configCases/context-modules/replacement-e/webpack.config.js similarity index 92% rename from test/configCases/context-replacement/e/webpack.config.js rename to test/configCases/context-modules/replacement-e/webpack.config.js index 302cc942356..291621800d8 100644 --- a/test/configCases/context-replacement/e/webpack.config.js +++ b/test/configCases/context-modules/replacement-e/webpack.config.js @@ -8,7 +8,7 @@ module.exports = { }, plugins: [ new webpack.ContextReplacementPlugin( - /context-replacement.e$/, + /replacement.e$/, "new-context", true, /^replaced$|^\.\/modules\/rep/ diff --git a/test/configCases/context-replacement/f/folder/a.js b/test/configCases/context-modules/replacement-f/folder/a.js similarity index 100% rename from test/configCases/context-replacement/f/folder/a.js rename to test/configCases/context-modules/replacement-f/folder/a.js diff --git a/test/configCases/context-replacement/f/folder/nested/error.js b/test/configCases/context-modules/replacement-f/folder/nested/error.js similarity index 100% rename from test/configCases/context-replacement/f/folder/nested/error.js rename to test/configCases/context-modules/replacement-f/folder/nested/error.js diff --git a/test/configCases/context-replacement/f/index.js b/test/configCases/context-modules/replacement-f/index.js similarity index 100% rename from test/configCases/context-replacement/f/index.js rename to test/configCases/context-modules/replacement-f/index.js diff --git a/test/configCases/context-replacement/f/webpack.config.js b/test/configCases/context-modules/replacement-f/webpack.config.js similarity index 100% rename from test/configCases/context-replacement/f/webpack.config.js rename to test/configCases/context-modules/replacement-f/webpack.config.js diff --git a/test/configCases/css/basic-dynamic-only/test.config.js b/test/configCases/css/basic-dynamic-only/test.config.js index c141c9959a1..5e4602a59e2 100644 --- a/test/configCases/css/basic-dynamic-only/test.config.js +++ b/test/configCases/css/basic-dynamic-only/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["style_css.bundle0.js", "bundle0.js"]; } }; diff --git a/test/configCases/css/basic-web-async/test.config.js b/test/configCases/css/basic-web-async/test.config.js index 2462953a0f2..41c0f0a0c7f 100644 --- a/test/configCases/css/basic-web-async/test.config.js +++ b/test/configCases/css/basic-web-async/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["style2_css.bundle0.js", "bundle0.js"]; }, moduleScope(scope) { diff --git a/test/configCases/css/basic/test.config.js b/test/configCases/css/basic/test.config.js index 2462953a0f2..41c0f0a0c7f 100644 --- a/test/configCases/css/basic/test.config.js +++ b/test/configCases/css/basic/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["style2_css.bundle0.js", "bundle0.js"]; }, moduleScope(scope) { diff --git a/test/configCases/css/conflicting-order/test.config.js b/test/configCases/css/conflicting-order/test.config.js index c53f3453533..457af618640 100644 --- a/test/configCases/css/conflicting-order/test.config.js +++ b/test/configCases/css/conflicting-order/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["css.bundle0.js", "lazy4_js.bundle0.js", "bundle0.js"]; } }; diff --git a/test/configCases/css/css-modules-no-space/webpack.config.js b/test/configCases/css/css-modules-no-space/webpack.config.js index b8e2164d1ba..31bf688dada 100644 --- a/test/configCases/css/css-modules-no-space/webpack.config.js +++ b/test/configCases/css/css-modules-no-space/webpack.config.js @@ -1,5 +1,5 @@ -/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration} */ -module.exports = (env, { testPath }) => ({ +/** @type {() => import("../../../../").Configuration} */ +module.exports = () => ({ target: "web", mode: "development", experiments: { diff --git a/test/configCases/css/css-modules/test.config.js b/test/configCases/css/css-modules/test.config.js index f8d4d18b3fe..002bd6add7f 100644 --- a/test/configCases/css/css-modules/test.config.js +++ b/test/configCases/css/css-modules/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return i === 0 ? ["./use-style_js.bundle0.js", "./bundle0.js"] : ["./142.bundle1.js", "./bundle1.js"]; diff --git a/test/configCases/css/escape-unescape/test.config.js b/test/configCases/css/escape-unescape/test.config.js index 523bd009639..937cd273f4b 100644 --- a/test/configCases/css/escape-unescape/test.config.js +++ b/test/configCases/css/escape-unescape/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["bundle0.js"]; }, moduleScope(scope) { diff --git a/test/configCases/css/exports-convention/test.config.js b/test/configCases/css/exports-convention/test.config.js index 1fcdcbd62d5..05db19fcc48 100644 --- a/test/configCases/css/exports-convention/test.config.js +++ b/test/configCases/css/exports-convention/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return [ `style_module_css_as-is.bundle${i}.js`, `style_module_css_camel-case.bundle${i}.js`, diff --git a/test/configCases/css/exports-only-generator-options/test.config.js b/test/configCases/css/exports-only-generator-options/test.config.js index ee33a038662..ce962330ea5 100644 --- a/test/configCases/css/exports-only-generator-options/test.config.js +++ b/test/configCases/css/exports-only-generator-options/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return [ "pseudo-export_style_module_css.bundle0.js", "pseudo-export_style_module_css_module.bundle0.js", diff --git a/test/configCases/css/external/test.config.js b/test/configCases/css/external/test.config.js index f543ee110ce..35c79b0662e 100644 --- a/test/configCases/css/external/test.config.js +++ b/test/configCases/css/external/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["125.bundle0.js", "bundle0.js"]; } }; diff --git a/test/configCases/css/local-ident-name/test.config.js b/test/configCases/css/local-ident-name/test.config.js index 621df3274ac..207224f512d 100644 --- a/test/configCases/css/local-ident-name/test.config.js +++ b/test/configCases/css/local-ident-name/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return [ `style_module_css.bundle${i}.js`, `style_module_css_hash.bundle${i}.js`, diff --git a/test/configCases/css/pseudo-import/test.config.js b/test/configCases/css/pseudo-import/test.config.js index 1d05d5addff..25a8b9f4dff 100644 --- a/test/configCases/css/pseudo-import/test.config.js +++ b/test/configCases/css/pseudo-import/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["reexport_modules_css.bundle0.js", "bundle0.js"]; }, moduleScope(scope) { diff --git a/test/configCases/css/runtime-issue/test.config.js b/test/configCases/css/runtime-issue/test.config.js index 6362048d5f5..b4dce758416 100644 --- a/test/configCases/css/runtime-issue/test.config.js +++ b/test/configCases/css/runtime-issue/test.config.js @@ -9,7 +9,7 @@ module.exports = { link2.href = "asyncChunk2_js.css"; scope.window.document.head.appendChild(link2); }, - findBundle(i, options) { + findBundle() { return [ "./common-share_js-img_png.js", "./asyncChunk_js.js", diff --git a/test/configCases/css/url-and-asset-module-filename/test.config.js b/test/configCases/css/url-and-asset-module-filename/test.config.js index d34e2224b44..f3049c55ad1 100644 --- a/test/configCases/css/url-and-asset-module-filename/test.config.js +++ b/test/configCases/css/url-and-asset-module-filename/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return [`index_css.bundle${i}.js`, `bundle${i}.js`]; } }; diff --git a/test/configCases/defer-import/harmony-import-mixed/index.js b/test/configCases/defer-import/harmony-import-mixed/index.js new file mode 100644 index 00000000000..3a9fa7f4512 --- /dev/null +++ b/test/configCases/defer-import/harmony-import-mixed/index.js @@ -0,0 +1,16 @@ +import { value as directValue } from "./shared.js"; // non-defer import +import * as deferredShared from /* webpackDefer: true */ "./shared.js"; // defer import + +it("should handle mixed defer/non-defer targets correctly", () => { + // Test direct non-defer access + expect(typeof directValue).toBe("string"); + expect(directValue).toBe("shared-value"); + + // Test deferred access + expect(typeof deferredShared).toBe("object"); + expect(deferredShared).not.toBe(null); + expect(deferredShared.value).toBe("shared-value"); + + // Both should access the same underlying value + expect(directValue).toBe(deferredShared.value); +}); \ No newline at end of file diff --git a/test/configCases/defer-import/harmony-import-mixed/shared.js b/test/configCases/defer-import/harmony-import-mixed/shared.js new file mode 100644 index 00000000000..fa1f624691f --- /dev/null +++ b/test/configCases/defer-import/harmony-import-mixed/shared.js @@ -0,0 +1,2 @@ +// This module will be imported both as defer and non-defer +export const value = "shared-value"; \ No newline at end of file diff --git a/test/configCases/defer-import/harmony-import-mixed/webpack.config.js b/test/configCases/defer-import/harmony-import-mixed/webpack.config.js new file mode 100644 index 00000000000..b9ffe036a9b --- /dev/null +++ b/test/configCases/defer-import/harmony-import-mixed/webpack.config.js @@ -0,0 +1,10 @@ +/** @type {import("../../../../types").Configuration} */ +module.exports = { + target: [`async-node${process.versions.node.split(".").map(Number)[0]}`], + optimization: { + concatenateModules: true + }, + experiments: { + deferImport: true + } +}; diff --git a/test/configCases/deprecations/chunk-and-module/webpack.config.js b/test/configCases/deprecations/chunk-and-module/webpack.config.js index c54ee01fe4c..f0519bd26a6 100644 --- a/test/configCases/deprecations/chunk-and-module/webpack.config.js +++ b/test/configCases/deprecations/chunk-and-module/webpack.config.js @@ -30,7 +30,7 @@ module.exports = { expect(chunk.isEmpty()).toBe(false); expect(chunk.modulesSize()).toBeTypeOf("number"); expect(chunk.size()).toBe(chunk.modulesSize() * 10 + 10000); - expect(chunk.getChunkModuleMaps(m => true)).toEqual({ + expect(chunk.getChunkModuleMaps(() => true)).toEqual({ id: {}, hash: {} }); diff --git a/test/configCases/entry/no-chunking/test.config.js b/test/configCases/entry/no-chunking/test.config.js index c8bd29f48c3..81a03d4c348 100644 --- a/test/configCases/entry/no-chunking/test.config.js +++ b/test/configCases/entry/no-chunking/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./a.js", "./b.js", "./c.js", "./runtime.js", "./d.js"]; } }; diff --git a/test/configCases/errors/generator-generate-error/test.config.js b/test/configCases/errors/generator-generate-error/test.config.js index 13e7530a887..ac2a9c3a4c3 100644 --- a/test/configCases/errors/generator-generate-error/test.config.js +++ b/test/configCases/errors/generator-generate-error/test.config.js @@ -4,6 +4,6 @@ module.exports = { findBundle(i, options) { const files = findOutputFiles(options, new RegExp(/\.js$/)); - return files.sort((a, b) => (a.startsWith("main") ? 1 : 0)); + return files.sort((a, _b) => (a.startsWith("main") ? 1 : 0)); } }; diff --git a/test/configCases/externals/externals-in-commons-chunk/test.config.js b/test/configCases/externals/externals-in-commons-chunk/test.config.js index 07adc696f51..33095374f40 100644 --- a/test/configCases/externals/externals-in-commons-chunk/test.config.js +++ b/test/configCases/externals/externals-in-commons-chunk/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./common.js", "./main.js"]; } }; diff --git a/test/configCases/externals/module-import/test.config.js b/test/configCases/externals/module-import/test.config.js index 93fd44fb16b..8280b4d308c 100644 --- a/test/configCases/externals/module-import/test.config.js +++ b/test/configCases/externals/module-import/test.config.js @@ -1,3 +1,3 @@ module.exports = { - findBundle: (i, options) => ["main.js"] + findBundle: () => ["main.js"] }; diff --git a/test/configCases/externals/module-import/webpack.config.js b/test/configCases/externals/module-import/webpack.config.js index 66c1a65ad6e..eee267f8904 100644 --- a/test/configCases/externals/module-import/webpack.config.js +++ b/test/configCases/externals/module-import/webpack.config.js @@ -21,10 +21,7 @@ module.exports = { }, externalsType: "module-import", externals: [ - function externals( - { context, request, contextInfo, getResolve, dependencyType }, - callback - ) { + function externals({ request }, callback) { if (request === "external2") { return callback(null, "node-commonjs external2"); } diff --git a/test/configCases/filename-template/filename-function/test.config.js b/test/configCases/filename-template/filename-function/test.config.js index 298cbe6d5d4..57cc4f4b284 100644 --- a/test/configCases/filename-template/filename-function/test.config.js +++ b/test/configCases/filename-template/filename-function/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["11.js", "22.js", "aa.js", "bbb.js"]; } }; diff --git a/test/configCases/graph/issue-11770/test.config.js b/test/configCases/graph/issue-11770/test.config.js index d6424e6f060..ee8eace4eef 100644 --- a/test/configCases/graph/issue-11770/test.config.js +++ b/test/configCases/graph/issue-11770/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return [ "shared.js", "a.js", diff --git a/test/configCases/graph/issue-11856/test.config.js b/test/configCases/graph/issue-11856/test.config.js index 4ff816dc9ab..5162706afa5 100644 --- a/test/configCases/graph/issue-11856/test.config.js +++ b/test/configCases/graph/issue-11856/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["shared.js", "a.js", "b.js"]; } }; diff --git a/test/configCases/graph/issue-11863/test.config.js b/test/configCases/graph/issue-11863/test.config.js index 3a3565765c5..5f56a3e6c5e 100644 --- a/test/configCases/graph/issue-11863/test.config.js +++ b/test/configCases/graph/issue-11863/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return [ "shared.js", "a.js", diff --git a/test/configCases/issues/issue-3596/webpack.config.js b/test/configCases/issues/issue-3596/webpack.config.js index 614835822ad..cd23171cf55 100644 --- a/test/configCases/issues/issue-3596/webpack.config.js +++ b/test/configCases/issues/issue-3596/webpack.config.js @@ -10,7 +10,7 @@ module.exports = { plugins: [ function apply() { this.hooks.compilation.tap("TestPlugin", compilation => { - compilation.hooks.processAssets.tap("TestPlugin", assets => { + compilation.hooks.processAssets.tap("TestPlugin", () => { delete compilation.assets["b.js"]; }); }); diff --git a/test/configCases/library/issue-18951/test.config.js b/test/configCases/library/issue-18951/test.config.js index ab693054953..bc434b87b0c 100644 --- a/test/configCases/library/issue-18951/test.config.js +++ b/test/configCases/library/issue-18951/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.mjs"]; } }; diff --git a/test/configCases/library/issue-19664/index.js b/test/configCases/library/issue-19664/index.js new file mode 100644 index 00000000000..b80e597cb32 --- /dev/null +++ b/test/configCases/library/issue-19664/index.js @@ -0,0 +1,10 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.main = main; +function main() {} + +// commonjs bailout +if(this){} + +it("Should work when exports are unprovided", function() { + expect(true).toBe(true); +}); diff --git a/test/configCases/library/issue-19664/webpack.config.js b/test/configCases/library/issue-19664/webpack.config.js new file mode 100644 index 00000000000..9150aa1751b --- /dev/null +++ b/test/configCases/library/issue-19664/webpack.config.js @@ -0,0 +1,8 @@ +/** @type {import("../../../../").Configuration} */ +module.exports = { + output: { + library: { + type: "commonjs-static" + } + } +}; diff --git a/test/configCases/module/duplicate-export/index.js b/test/configCases/module/duplicate-export/index.js new file mode 100644 index 00000000000..6c4b0d2e15d --- /dev/null +++ b/test/configCases/module/duplicate-export/index.js @@ -0,0 +1,7 @@ +import value from "./separate"; + +it("should compile", () => { + expect(value).toBeDefined(); +}); + +export default "main"; diff --git a/test/configCases/module/duplicate-export/separate.js b/test/configCases/module/duplicate-export/separate.js new file mode 100644 index 00000000000..7a4e8a723a4 --- /dev/null +++ b/test/configCases/module/duplicate-export/separate.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/configCases/module/duplicate-export/test.config.js b/test/configCases/module/duplicate-export/test.config.js new file mode 100644 index 00000000000..9d2aabb1e9b --- /dev/null +++ b/test/configCases/module/duplicate-export/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle() { + return ["./main.mjs"]; + } +}; diff --git a/test/configCases/module/duplicate-export/webpack.config.js b/test/configCases/module/duplicate-export/webpack.config.js new file mode 100644 index 00000000000..576a99ee237 --- /dev/null +++ b/test/configCases/module/duplicate-export/webpack.config.js @@ -0,0 +1,28 @@ +/** @type {import("../../../../").Configuration} */ +module.exports = { + mode: "development", + output: { + filename: "[name].mjs", + library: { + type: "module" + } + }, + target: ["web", "es2020"], + experiments: { + outputModule: true + }, + optimization: { + minimize: false, + runtimeChunk: true, + splitChunks: { + cacheGroups: { + separate: { + test: /separate/, + chunks: "all", + filename: "separate.mjs", + enforce: true + } + } + } + } +}; diff --git a/test/configCases/module/iife-entry-module-with-others/test.config.js b/test/configCases/module/iife-entry-module-with-others/test.config.js index b0ea3b44c52..53042d86fab 100644 --- a/test/configCases/module/iife-entry-module-with-others/test.config.js +++ b/test/configCases/module/iife-entry-module-with-others/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return [ "module-avoidEntryIife-false.mjs", "module-avoidEntryIife-true.mjs", diff --git a/test/configCases/module/iife-innter-strict/test.config.js b/test/configCases/module/iife-innter-strict/test.config.js index 32f4be1d473..f48f8b79def 100644 --- a/test/configCases/module/iife-innter-strict/test.config.js +++ b/test/configCases/module/iife-innter-strict/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["test.js"]; } }; diff --git a/test/configCases/module/iife-multiple-entry-modules/test.config.js b/test/configCases/module/iife-multiple-entry-modules/test.config.js index 5e7f742d6f5..bb3de309b02 100644 --- a/test/configCases/module/iife-multiple-entry-modules/test.config.js +++ b/test/configCases/module/iife-multiple-entry-modules/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["bundle0.mjs", "test.js"]; } }; diff --git a/test/configCases/module/issue-16040/test.config.js b/test/configCases/module/issue-16040/test.config.js index 15fd839d728..194e0522015 100644 --- a/test/configCases/module/issue-16040/test.config.js +++ b/test/configCases/module/issue-16040/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.mjs", "vendor.mjs", "runtime.mjs"]; } }; diff --git a/test/configCases/module/split-chunks-issue-19657/index.js b/test/configCases/module/split-chunks-issue-19657/index.js new file mode 100644 index 00000000000..ad1acea94ec --- /dev/null +++ b/test/configCases/module/split-chunks-issue-19657/index.js @@ -0,0 +1,8 @@ +import m2 from "./testModule2.js" + +it("should compile and evaluate fine", (done) => { + expect(m2()).toBe("m11111111"); + done() +}); + +export default "index"; \ No newline at end of file diff --git a/test/configCases/module/split-chunks-issue-19657/test.config.js b/test/configCases/module/split-chunks-issue-19657/test.config.js new file mode 100644 index 00000000000..ab693054953 --- /dev/null +++ b/test/configCases/module/split-chunks-issue-19657/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle(i, options) { + return ["main.mjs"]; + } +}; diff --git a/test/configCases/module/split-chunks-issue-19657/testModule1.js b/test/configCases/module/split-chunks-issue-19657/testModule1.js new file mode 100644 index 00000000000..78fbf447153 --- /dev/null +++ b/test/configCases/module/split-chunks-issue-19657/testModule1.js @@ -0,0 +1 @@ +export const m1 = "m11111111"; diff --git a/test/configCases/module/split-chunks-issue-19657/testModule2.js b/test/configCases/module/split-chunks-issue-19657/testModule2.js new file mode 100644 index 00000000000..e6091bba12b --- /dev/null +++ b/test/configCases/module/split-chunks-issue-19657/testModule2.js @@ -0,0 +1,5 @@ +import { m1 } from "./testModule1"; + +export default function m2() { + return m1; +} \ No newline at end of file diff --git a/test/configCases/module/split-chunks-issue-19657/webpack.config.js b/test/configCases/module/split-chunks-issue-19657/webpack.config.js new file mode 100644 index 00000000000..56d61cdf6c1 --- /dev/null +++ b/test/configCases/module/split-chunks-issue-19657/webpack.config.js @@ -0,0 +1,34 @@ +/** @type {import("../../../../types").Configuration} */ +module.exports = { + mode: "development", + experiments: { + outputModule: true + }, + output: { + module: true, + chunkFormat: "module", + filename: "[name].mjs", + chunkFilename: "[name].chunk.mjs" + }, + devtool: false, + optimization: { + minimize: false, + splitChunks: { + chunks: "all", + minSize: 0, + cacheGroups: { + testModule1: { + test: /testModule1/, + name: "testModule1", + priority: 10, + enforce: true + }, + testModule2: { + test: /testModule2/, + name: "testModule2", + priority: 20 + } + } + } + } +}; diff --git a/test/configCases/module/split-chunks-without-externals/test.config.js b/test/configCases/module/split-chunks-without-externals/test.config.js index 1dd2dfc6303..6dfa448614e 100644 --- a/test/configCases/module/split-chunks-without-externals/test.config.js +++ b/test/configCases/module/split-chunks-without-externals/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.mjs", "testModule1.mjs", "testModule2.mjs"]; } }; diff --git a/test/configCases/output/charset/test.config.js b/test/configCases/output/charset/test.config.js index ea656968b0e..d338a4c0200 100644 --- a/test/configCases/output/charset/test.config.js +++ b/test/configCases/output/charset/test.config.js @@ -1,5 +1,5 @@ module.exports = { - moduleScope(scope, options) { + moduleScope(scope) { const link = scope.window.document.createElement("link"); link.rel = "stylesheet"; link.href = "chunk1.css"; diff --git a/test/configCases/plugins/banner-plugin-hashing/test.config.js b/test/configCases/plugins/banner-plugin-hashing/test.config.js index 5d626611bc5..72f2bf28c22 100644 --- a/test/configCases/plugins/banner-plugin-hashing/test.config.js +++ b/test/configCases/plugins/banner-plugin-hashing/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return "./dist/banner.js"; } }; diff --git a/test/configCases/plugins/limit-chunk-count-plugin/test.config.js b/test/configCases/plugins/limit-chunk-count-plugin/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/plugins/limit-chunk-count-plugin/test.config.js +++ b/test/configCases/plugins/limit-chunk-count-plugin/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/plugins/mini-css-extract-plugin/test.config.js b/test/configCases/plugins/mini-css-extract-plugin/test.config.js index 393afd969c7..41eeb395b80 100644 --- a/test/configCases/plugins/mini-css-extract-plugin/test.config.js +++ b/test/configCases/plugins/mini-css-extract-plugin/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return [`${i}_a.js`, `${i}_b.js`, `${i}_c.js`]; } }; diff --git a/test/configCases/plugins/source-map-dev-tool-plugin-append-function/webpack.config.js b/test/configCases/plugins/source-map-dev-tool-plugin-append-function/webpack.config.js index 8abc9602236..316da3e8874 100644 --- a/test/configCases/plugins/source-map-dev-tool-plugin-append-function/webpack.config.js +++ b/test/configCases/plugins/source-map-dev-tool-plugin-append-function/webpack.config.js @@ -20,7 +20,7 @@ module.exports = { plugins: [ new webpack.SourceMapDevToolPlugin({ filename: "sourcemaps/[file].map", - append: data => "\n//# sourceMappingURL=http://localhost:50505/[file].map" + append: () => "\n//# sourceMappingURL=http://localhost:50505/[file].map" }) ] }; diff --git a/test/configCases/plugins/virtual-url-plugin/webpack.config.js b/test/configCases/plugins/virtual-url-plugin/webpack.config.js index c14c93fee40..a5081e27532 100644 --- a/test/configCases/plugins/virtual-url-plugin/webpack.config.js +++ b/test/configCases/plugins/virtual-url-plugin/webpack.config.js @@ -10,7 +10,7 @@ const watchDir = path.join(__dirname, "./routes"); const config = { plugins: [ new VirtualUrlPlugin({ - routes(loaderContext) { + routes() { const files = fs.readdirSync(watchDir); return ` export const routes = { diff --git a/test/configCases/resolving/prefer-absolute/webpack.config.js b/test/configCases/resolving/prefer-absolute/webpack.config.js index 9d5b634248a..21adc6f0fdc 100644 --- a/test/configCases/resolving/prefer-absolute/webpack.config.js +++ b/test/configCases/resolving/prefer-absolute/webpack.config.js @@ -18,7 +18,7 @@ module.exports = { * @param {Resolver & { hooks: { file: SyncBailHook<[ResolveRequest, ResolveContext], void> } }} resolver resolver */ apply(resolver) { - resolver.hooks.file.tap("Test", (request, resolverContext) => { + resolver.hooks.file.tap("Test", request => { if ( /test.configCases.*test.configCases/.test( /** @type {string} */ diff --git a/test/configCases/resolving/prefer-root/webpack.config.js b/test/configCases/resolving/prefer-root/webpack.config.js index 36a2fd09e35..9aecc535c92 100644 --- a/test/configCases/resolving/prefer-root/webpack.config.js +++ b/test/configCases/resolving/prefer-root/webpack.config.js @@ -16,7 +16,7 @@ module.exports = { * @param {Resolver & { hooks: { file: SyncBailHook<[ResolveRequest, ResolveContext], void> } }} resolver resolver */ apply(resolver) { - resolver.hooks.file.tap("Test", (request, resolverContext) => { + resolver.hooks.file.tap("Test", request => { if (request.path === "/index.js") { throw new Error("Trying to resolve as absolute path"); } diff --git a/test/configCases/source-map/devtool-namespace-with-eval-source-map/test.config.js b/test/configCases/source-map/devtool-namespace-with-eval-source-map/test.config.js index a773bb4ebed..be2150cc603 100644 --- a/test/configCases/source-map/devtool-namespace-with-eval-source-map/test.config.js +++ b/test/configCases/source-map/devtool-namespace-with-eval-source-map/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["entry-a-bundle.js", "entry-b-bundle.js"]; } }; diff --git a/test/configCases/source-map/devtool-namespace-with-eval/test.config.js b/test/configCases/source-map/devtool-namespace-with-eval/test.config.js index a773bb4ebed..be2150cc603 100644 --- a/test/configCases/source-map/devtool-namespace-with-eval/test.config.js +++ b/test/configCases/source-map/devtool-namespace-with-eval/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["entry-a-bundle.js", "entry-b-bundle.js"]; } }; diff --git a/test/configCases/source-map/devtool-namespace-with-source-map/test.config.js b/test/configCases/source-map/devtool-namespace-with-source-map/test.config.js index a773bb4ebed..be2150cc603 100644 --- a/test/configCases/source-map/devtool-namespace-with-source-map/test.config.js +++ b/test/configCases/source-map/devtool-namespace-with-source-map/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["entry-a-bundle.js", "entry-b-bundle.js"]; } }; diff --git a/test/configCases/split-chunks-common/correct-order/test.config.js b/test/configCases/split-chunks-common/correct-order/test.config.js index f8bc4b8473c..ac3afebfca3 100644 --- a/test/configCases/split-chunks-common/correct-order/test.config.js +++ b/test/configCases/split-chunks-common/correct-order/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./vendor.js", "./main.js"]; } }; diff --git a/test/configCases/split-chunks-common/extract-async-from-entry/test.config.js b/test/configCases/split-chunks-common/extract-async-from-entry/test.config.js index 74e4d94cce7..0e721ca1433 100644 --- a/test/configCases/split-chunks-common/extract-async-from-entry/test.config.js +++ b/test/configCases/split-chunks-common/extract-async-from-entry/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./main.js"]; } }; diff --git a/test/configCases/split-chunks-common/hot-multi/test.config.js b/test/configCases/split-chunks-common/hot-multi/test.config.js index c5249179a7c..64952711508 100644 --- a/test/configCases/split-chunks-common/hot-multi/test.config.js +++ b/test/configCases/split-chunks-common/hot-multi/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./vendor.js", "./first.js", "./second.js"]; } }; diff --git a/test/configCases/split-chunks-common/hot/test.config.js b/test/configCases/split-chunks-common/hot/test.config.js index f8bc4b8473c..ac3afebfca3 100644 --- a/test/configCases/split-chunks-common/hot/test.config.js +++ b/test/configCases/split-chunks-common/hot/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./vendor.js", "./main.js"]; } }; diff --git a/test/configCases/split-chunks-common/inverted-order/test.config.js b/test/configCases/split-chunks-common/inverted-order/test.config.js index fc22d3b5770..eed5873a9bf 100644 --- a/test/configCases/split-chunks-common/inverted-order/test.config.js +++ b/test/configCases/split-chunks-common/inverted-order/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./main.js", "./vendor.js"]; } }; diff --git a/test/configCases/split-chunks-common/issue-12128/test.config.js b/test/configCases/split-chunks-common/issue-12128/test.config.js index 8e220227b7b..69f19523ba2 100644 --- a/test/configCases/split-chunks-common/issue-12128/test.config.js +++ b/test/configCases/split-chunks-common/issue-12128/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./common.js", "./main.js", "./main2.js"]; } }; diff --git a/test/configCases/split-chunks-common/library/test.config.js b/test/configCases/split-chunks-common/library/test.config.js index 8ede468fd67..06e8b92c02a 100644 --- a/test/configCases/split-chunks-common/library/test.config.js +++ b/test/configCases/split-chunks-common/library/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./vendor.js", "./main.js"]; }, modules: { diff --git a/test/configCases/split-chunks-common/move-entry/test.config.js b/test/configCases/split-chunks-common/move-entry/test.config.js index 1aceaa7c1ba..40bcfbb6380 100644 --- a/test/configCases/split-chunks-common/move-entry/test.config.js +++ b/test/configCases/split-chunks-common/move-entry/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./commons.js", "./main.js"]; } }; diff --git a/test/configCases/split-chunks-common/move-to-grandparent/test.config.js b/test/configCases/split-chunks-common/move-to-grandparent/test.config.js index c29a7929db6..20f79312e29 100644 --- a/test/configCases/split-chunks-common/move-to-grandparent/test.config.js +++ b/test/configCases/split-chunks-common/move-to-grandparent/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./main.js", "./misc.js"]; } }; diff --git a/test/configCases/split-chunks-common/simple/test.config.js b/test/configCases/split-chunks-common/simple/test.config.js index f8bc4b8473c..ac3afebfca3 100644 --- a/test/configCases/split-chunks-common/simple/test.config.js +++ b/test/configCases/split-chunks-common/simple/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["./vendor.js", "./main.js"]; } }; diff --git a/test/configCases/split-chunks/asnyc-entries/test.config.js b/test/configCases/split-chunks/asnyc-entries/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/split-chunks/asnyc-entries/test.config.js +++ b/test/configCases/split-chunks/asnyc-entries/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/split-chunks/chunk-filename-delimiter-default/test.config.js b/test/configCases/split-chunks/chunk-filename-delimiter-default/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/split-chunks/chunk-filename-delimiter-default/test.config.js +++ b/test/configCases/split-chunks/chunk-filename-delimiter-default/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/split-chunks/chunk-filename-delimiter/test.config.js b/test/configCases/split-chunks/chunk-filename-delimiter/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/split-chunks/chunk-filename-delimiter/test.config.js +++ b/test/configCases/split-chunks/chunk-filename-delimiter/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/split-chunks/custom-filename-function/test.config.js b/test/configCases/split-chunks/custom-filename-function/test.config.js index af4691d7848..4ca1669700f 100644 --- a/test/configCases/split-chunks/custom-filename-function/test.config.js +++ b/test/configCases/split-chunks/custom-filename-function/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["a.js"]; } }; diff --git a/test/configCases/split-chunks/custom-filename-many-custom/test.config.js b/test/configCases/split-chunks/custom-filename-many-custom/test.config.js index af4691d7848..4ca1669700f 100644 --- a/test/configCases/split-chunks/custom-filename-many-custom/test.config.js +++ b/test/configCases/split-chunks/custom-filename-many-custom/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["a.js"]; } }; diff --git a/test/configCases/split-chunks/custom-filename/test.config.js b/test/configCases/split-chunks/custom-filename/test.config.js index af4691d7848..4ca1669700f 100644 --- a/test/configCases/split-chunks/custom-filename/test.config.js +++ b/test/configCases/split-chunks/custom-filename/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["a.js"]; } }; diff --git a/test/configCases/split-chunks/entry-point-error/test.config.js b/test/configCases/split-chunks/entry-point-error/test.config.js index 024c0caeda3..fa1cdb2fcb2 100644 --- a/test/configCases/split-chunks/entry-point-error/test.config.js +++ b/test/configCases/split-chunks/entry-point-error/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["vendors.js", "main.js"]; } }; diff --git a/test/configCases/split-chunks/issue-11513/test.config.js b/test/configCases/split-chunks/issue-11513/test.config.js index 24317dca740..aab02d48ec4 100644 --- a/test/configCases/split-chunks/issue-11513/test.config.js +++ b/test/configCases/split-chunks/issue-11513/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["test.js", "main.js"]; } }; diff --git a/test/configCases/split-chunks/issue-17332/test.config.js b/test/configCases/split-chunks/issue-17332/test.config.js index 33308d294a8..1a6234f5e0f 100644 --- a/test/configCases/split-chunks/issue-17332/test.config.js +++ b/test/configCases/split-chunks/issue-17332/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["split-foo.js", "foo.js", "main.js"]; } }; diff --git a/test/configCases/split-chunks/issue-8908/test.config.js b/test/configCases/split-chunks/issue-8908/test.config.js index 51e90d128bf..7948c3fe722 100644 --- a/test/configCases/split-chunks/issue-8908/test.config.js +++ b/test/configCases/split-chunks/issue-8908/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["runtime.js", "vendor-a.js", "a.js"]; } }; diff --git a/test/configCases/split-chunks/issue-9491/test.config.js b/test/configCases/split-chunks/issue-9491/test.config.js index 69c3d55b612..823968a3f38 100644 --- a/test/configCases/split-chunks/issue-9491/test.config.js +++ b/test/configCases/split-chunks/issue-9491/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["runtime.js", "constructor.js"]; } }; diff --git a/test/configCases/split-chunks/max-size-casing/test.config.js b/test/configCases/split-chunks/max-size-casing/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/split-chunks/max-size-casing/test.config.js +++ b/test/configCases/split-chunks/max-size-casing/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/split-chunks/module-type-filter/test.config.js b/test/configCases/split-chunks/module-type-filter/test.config.js index 23e1b263675..5e6f0eb36c3 100644 --- a/test/configCases/split-chunks/module-type-filter/test.config.js +++ b/test/configCases/split-chunks/module-type-filter/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["json.js", "main.js"]; } }; diff --git a/test/configCases/split-chunks/move-to-entrypoint/test.config.js b/test/configCases/split-chunks/move-to-entrypoint/test.config.js index 60ac768dc48..97e8d085f4d 100644 --- a/test/configCases/split-chunks/move-to-entrypoint/test.config.js +++ b/test/configCases/split-chunks/move-to-entrypoint/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["runtime.js", "a.js", "b.js"]; } }; diff --git a/test/configCases/split-chunks/no-name/test.config.js b/test/configCases/split-chunks/no-name/test.config.js index b29ba477372..859a3d0a5fe 100644 --- a/test/configCases/split-chunks/no-name/test.config.js +++ b/test/configCases/split-chunks/no-name/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["common-a_js.js", "main.js"]; } }; diff --git a/test/configCases/split-chunks/no-options/test.config.js b/test/configCases/split-chunks/no-options/test.config.js index 39c2883c718..5875983aa91 100644 --- a/test/configCases/split-chunks/no-options/test.config.js +++ b/test/configCases/split-chunks/no-options/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["vendor.js", "main.js"]; } }; diff --git a/test/configCases/split-chunks/reuse-chunk-name/test.config.js b/test/configCases/split-chunks/reuse-chunk-name/test.config.js index ad7cd7e18d1..dc9c0aae56c 100644 --- a/test/configCases/split-chunks/reuse-chunk-name/test.config.js +++ b/test/configCases/split-chunks/reuse-chunk-name/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["common.js", "main.js"]; } }; diff --git a/test/configCases/split-chunks/runtime-chunk-async-node/test.config.js b/test/configCases/split-chunks/runtime-chunk-async-node/test.config.js index fafd4ba626a..1b0256ddd2a 100644 --- a/test/configCases/split-chunks/runtime-chunk-async-node/test.config.js +++ b/test/configCases/split-chunks/runtime-chunk-async-node/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["b.js", "deep/path/a.js", "somewhere/c.js"]; } }; diff --git a/test/configCases/split-chunks/runtime-chunk-node-13130/test.config.js b/test/configCases/split-chunks/runtime-chunk-node-13130/test.config.js index fafd4ba626a..1b0256ddd2a 100644 --- a/test/configCases/split-chunks/runtime-chunk-node-13130/test.config.js +++ b/test/configCases/split-chunks/runtime-chunk-node-13130/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["b.js", "deep/path/a.js", "somewhere/c.js"]; } }; diff --git a/test/configCases/split-chunks/runtime-chunk-node/test.config.js b/test/configCases/split-chunks/runtime-chunk-node/test.config.js index fafd4ba626a..1b0256ddd2a 100644 --- a/test/configCases/split-chunks/runtime-chunk-node/test.config.js +++ b/test/configCases/split-chunks/runtime-chunk-node/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["b.js", "deep/path/a.js", "somewhere/c.js"]; } }; diff --git a/test/configCases/split-chunks/runtime-chunk/test.config.js b/test/configCases/split-chunks/runtime-chunk/test.config.js index b00df088b2b..cdc9dd1d401 100644 --- a/test/configCases/split-chunks/runtime-chunk/test.config.js +++ b/test/configCases/split-chunks/runtime-chunk/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["runtime.js", "a.js"]; } }; diff --git a/test/configCases/split-chunks/vendor-only-entrypoint/test.config.js b/test/configCases/split-chunks/vendor-only-entrypoint/test.config.js index d0803add753..f80a9c6f527 100644 --- a/test/configCases/split-chunks/vendor-only-entrypoint/test.config.js +++ b/test/configCases/split-chunks/vendor-only-entrypoint/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["runtime~vendor.js", "vendor.js"]; } }; diff --git a/test/configCases/target/chunk-loading-per-entry/test.config.js b/test/configCases/target/chunk-loading-per-entry/test.config.js index cb1a34c3347..643395505ab 100644 --- a/test/configCases/target/chunk-loading-per-entry/test.config.js +++ b/test/configCases/target/chunk-loading-per-entry/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { return i === 0 ? "./web-0.js" : "./webworker-1.js"; } }; diff --git a/test/configCases/trusted-types/web-worker/test.config.js b/test/configCases/trusted-types/web-worker/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/trusted-types/web-worker/test.config.js +++ b/test/configCases/trusted-types/web-worker/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/umd/issue-15545/test.config.js b/test/configCases/umd/issue-15545/test.config.js index 2b00586a46d..67874807764 100644 --- a/test/configCases/umd/issue-15545/test.config.js +++ b/test/configCases/umd/issue-15545/test.config.js @@ -1,7 +1,7 @@ const CONTEXT = {}; module.exports = { - nonEsmThis(module) { + nonEsmThis() { return CONTEXT; }, findBundle() { diff --git a/test/configCases/wasm/fetch/test.config.js b/test/configCases/wasm/fetch/test.config.js index 3e6e0925a33..68d0c25fcf0 100644 --- a/test/configCases/wasm/fetch/test.config.js +++ b/test/configCases/wasm/fetch/test.config.js @@ -3,7 +3,7 @@ const path = require("path"); const url = require("url"); module.exports = { - findBundle(i, options) { + findBundle(i) { switch (i) { case 0: return ["bundle0.mjs"]; diff --git a/test/configCases/web/non-js-chunks-entrypoint-runtime-chunk/test.config.js b/test/configCases/web/non-js-chunks-entrypoint-runtime-chunk/test.config.js index 7de30aabdd2..09896fb508d 100644 --- a/test/configCases/web/non-js-chunks-entrypoint-runtime-chunk/test.config.js +++ b/test/configCases/web/non-js-chunks-entrypoint-runtime-chunk/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return [ "runtime.js", "main.js", diff --git a/test/configCases/web/non-js-chunks-entrypoint/test.config.js b/test/configCases/web/non-js-chunks-entrypoint/test.config.js index 096ce4cd918..229a4f1a0da 100644 --- a/test/configCases/web/non-js-chunks-entrypoint/test.config.js +++ b/test/configCases/web/non-js-chunks-entrypoint/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return [ "main.js", "vendors-node_modules_other-package_index_js-node_modules_package_index_js.js" diff --git a/test/configCases/web/preexecuted-chunk/test.config.js b/test/configCases/web/preexecuted-chunk/test.config.js index 6ad8df89ee3..7aafb486102 100644 --- a/test/configCases/web/preexecuted-chunk/test.config.js +++ b/test/configCases/web/preexecuted-chunk/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["the-chunk.js", "bundle0.js"]; } }; diff --git a/test/configCases/web/prefetch-split-chunks/test.config.js b/test/configCases/web/prefetch-split-chunks/test.config.js index b9ed0f575c1..086baa60bb9 100644 --- a/test/configCases/web/prefetch-split-chunks/test.config.js +++ b/test/configCases/web/prefetch-split-chunks/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js", "runtime~main.js", "separate-public-path_js.js"]; } }; diff --git a/test/configCases/web/unique-jsonp/test.config.js b/test/configCases/web/unique-jsonp/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/web/unique-jsonp/test.config.js +++ b/test/configCases/web/unique-jsonp/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/worker/custom-worker/test.config.js b/test/configCases/worker/custom-worker/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/worker/custom-worker/test.config.js +++ b/test/configCases/worker/custom-worker/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/worker/node-worker-esm/test.config.js b/test/configCases/worker/node-worker-esm/test.config.js index aac7fff6c82..b048fb04eba 100644 --- a/test/configCases/worker/node-worker-esm/test.config.js +++ b/test/configCases/worker/node-worker-esm/test.config.js @@ -1,6 +1,5 @@ const fs = require("fs"); const path = require("path"); -const { URL } = require("url"); module.exports = { findBundle() { diff --git a/test/configCases/worker/node-worker-hmr/test.config.js b/test/configCases/worker/node-worker-hmr/test.config.js index 28532b86979..d0b177310f8 100644 --- a/test/configCases/worker/node-worker-hmr/test.config.js +++ b/test/configCases/worker/node-worker-hmr/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["a.js", "b.js", "c.js", "d.js"]; } }; diff --git a/test/configCases/worker/node-worker-named/test.config.js b/test/configCases/worker/node-worker-named/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/worker/node-worker-named/test.config.js +++ b/test/configCases/worker/node-worker-named/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/worker/node-worker/test.config.js b/test/configCases/worker/node-worker/test.config.js index 28532b86979..d0b177310f8 100644 --- a/test/configCases/worker/node-worker/test.config.js +++ b/test/configCases/worker/node-worker/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["a.js", "b.js", "c.js", "d.js"]; } }; diff --git a/test/configCases/worker/self-import/test.config.js b/test/configCases/worker/self-import/test.config.js index 86bc794f174..792e0848ff5 100644 --- a/test/configCases/worker/self-import/test.config.js +++ b/test/configCases/worker/self-import/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle(i) { switch (i) { case 0: return [`bundle${i}.js`]; diff --git a/test/configCases/worker/universal/test.config.js b/test/configCases/worker/universal/test.config.js index 4b0564c5df1..61de36bb639 100644 --- a/test/configCases/worker/universal/test.config.js +++ b/test/configCases/worker/universal/test.config.js @@ -4,7 +4,7 @@ module.exports = { delete scope.Worker; } }, - findBundle(i, options) { + findBundle() { return ["web-main.mjs"]; } }; diff --git a/test/configCases/worker/web-worker/test.config.js b/test/configCases/worker/web-worker/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/worker/web-worker/test.config.js +++ b/test/configCases/worker/web-worker/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/configCases/worker/worker-contenthash/test.config.js b/test/configCases/worker/worker-contenthash/test.config.js index 0c4cdb95323..78a59a58887 100644 --- a/test/configCases/worker/worker-contenthash/test.config.js +++ b/test/configCases/worker/worker-contenthash/test.config.js @@ -1,5 +1,5 @@ module.exports = { - findBundle(i, options) { + findBundle() { return ["main.js"]; } }; diff --git a/test/helpers/FakeDocument.js b/test/helpers/FakeDocument.js index c0e869d1c12..a50bd6187a4 100644 --- a/test/helpers/FakeDocument.js +++ b/test/helpers/FakeDocument.js @@ -91,7 +91,7 @@ class FakeElement { } } - insertBefore(node, before) { + insertBefore(node) { this._attach(node); this._load(node); } diff --git a/test/helpers/deprecationTracking.js b/test/helpers/deprecationTracking.js index 17c1c68d6ad..24bce22da88 100644 --- a/test/helpers/deprecationTracking.js +++ b/test/helpers/deprecationTracking.js @@ -40,10 +40,9 @@ util.deprecate = (fn, message, _code) => { }; /** - * @param {EXPECTED_ANY} handler handler * @returns {() => EXPECTED_ANY} result */ -module.exports.start = handler => { +module.exports.start = () => { interception = new Map(); return () => { @@ -55,6 +54,6 @@ module.exports.start = handler => { if (a > b) return 1; return 0; }) - .map(([key, data]) => data); + .map(([_key, data]) => data); }; }; diff --git a/test/hotCases/css/single-css-entry/webpack.config.js b/test/hotCases/css/single-css-entry/webpack.config.js index 26f2eae1e82..62cd01bf74c 100644 --- a/test/hotCases/css/single-css-entry/webpack.config.js +++ b/test/hotCases/css/single-css-entry/webpack.config.js @@ -14,7 +14,7 @@ module.exports = { compiler.hooks.compilation.tap("Test", compilation => { compilation.hooks.additionalTreeRuntimeRequirements.tap( "Test", - (module, set, context) => { + (module, set, _context) => { // To prevent the runtime error `ReferenceError: __webpack_exports__ is not defined`, // which occurs because the default `output.library` setting is `commonjs2`, // resulting in adding `module.exports = __webpack_exports__;`. diff --git a/test/hotCases/worker/move-between-runtime/test.filter.js b/test/hotCases/worker/move-between-runtime/test.filter.js index 23936757a41..d456e8870d2 100644 --- a/test/hotCases/worker/move-between-runtime/test.filter.js +++ b/test/hotCases/worker/move-between-runtime/test.filter.js @@ -1,3 +1,3 @@ const supportsWorker = require("../../../helpers/supportsWorker"); -module.exports = config => supportsWorker(); +module.exports = () => supportsWorker(); diff --git a/test/runner/index.js b/test/runner/index.js index e6bc9f73973..c298d649c8a 100644 --- a/test/runner/index.js +++ b/test/runner/index.js @@ -1,11 +1,11 @@ const fs = require("fs"); const path = require("path"); +const { fileURLToPath, pathToFileURL } = require("url"); const vm = require("vm"); -const { pathToFileURL, fileURLToPath } = require("url"); /** - * @param {string} path - * @returns {string} + * @param {string} path path + * @returns {string} subPath */ const getSubPath = path => { let subPath = ""; @@ -28,15 +28,15 @@ const getSubPath = path => { }; /** - * @param {string} path - * @returns {boolean} + * @param {string} path path + * @returns {boolean} whether path is a relative path */ const isRelativePath = path => /^\.\.?\//.test(path); /** - * @param {string} url - * @param {string} outputDirectory - * @returns {string} + * @param {string} url url + * @param {string} outputDirectory outputDirectory + * @returns {string} absolute path */ const urlToPath = (url, outputDirectory) => { if (url.startsWith("https://test.cases/path/")) url = url.slice(24); @@ -45,8 +45,8 @@ const urlToPath = (url, outputDirectory) => { }; /** - * @param {string} url - * @returns {string} + * @param {string} url url + * @returns {string} relative path */ const urlToRelativePath = url => { if (url.startsWith("https://test.cases/path/")) url = url.slice(24); @@ -55,23 +55,23 @@ const urlToRelativePath = url => { }; /** - * @typedef {Object} TestMeta + * @typedef {object} TestMeta * @property {string} category * @property {string} name - * @property {"jsdom"} [env] - * @property {number} [round] + * @property {"jsdom"=} env + * @property {number=} round */ /** - * @typedef {Object} TestConfig - * @property {Function} [resolveModule] - * @property {Function} [moduleScope] - * @property {Function} [nonEsmThis] - * @property {boolean} [evaluateScriptOnAttached] + * @typedef {object} TestConfig + * @property {EXPECTED_FUNCTION=} resolveModule + * @property {EXPECTED_FUNCTION=} moduleScope + * @property {EXPECTED_FUNCTION=} nonEsmThis + * @property {boolean=} evaluateScriptOnAttached */ /** - * @typedef {Object} TestRunnerOptions + * @typedef {object} TestRunnerOptions * @property {string|string[]} target * @property {string} outputDirectory * @property {TestMeta} testMeta @@ -80,19 +80,19 @@ const urlToRelativePath = url => { */ /** - * @typedef {Object} ModuleInfo + * @typedef {object} ModuleInfo * @property {string} subPath * @property {string} modulePath * @property {string} content */ /** - * @typedef {Object} RequireContext + * @typedef {object} RequireContext * @property {"unlinked"|"evaluated"} esmMode */ /** - * @typedef {Object} ModuleRunner + * @typedef {object} ModuleRunner * @property {(moduleInfo: ModuleInfo, context: RequireContext) => EXPECTED_ANY} cjs * @property {(moduleInfo: ModuleInfo, context: RequireContext) => Promise} esm * @property {(moduleInfo: ModuleInfo, context: RequireContext) => EXPECTED_ANY} json @@ -101,7 +101,7 @@ const urlToRelativePath = url => { class TestRunner { /** - * @param {TestRunnerOptions} options + * @param {TestRunnerOptions} options test runner options */ constructor({ target, @@ -119,10 +119,11 @@ class TestRunner { this._globalContext = this.createBaseGlobalContext(); this._moduleScope = this.createBaseModuleScope(); this._moduleRunners = this.createModuleRunners(); + this._esmContext = this.createBaseEsmContext(); } /** - * @returns {ModuleRunner} + * @returns {ModuleRunner} module runners */ createModuleRunners() { return { @@ -132,16 +133,26 @@ class TestRunner { raw: this.createRawRunner() }; } + /** * @returns {EXPECTED_ANY} globalContext */ createBaseGlobalContext() { - let base = { console, expect, setTimeout, clearTimeout }; + const base = { console, expect, setTimeout, clearTimeout }; Object.assign(base, this.setupEnv()); return base; } + + /** + * @param {EXPECTED_ANY} esmContext esm context + * @returns {EXPECTED_ANY} esm context + */ + mergeEsmContext(esmContext) { + return Object.assign(this._esmContext, esmContext); + } + /** - * @returns {boolean} + * @returns {boolean} whether target is web */ isTargetWeb() { return ( @@ -151,17 +162,19 @@ class TestRunner { (this.target.includes("web") || this.target.includes("webworker"))) ); } + /** - * @returns {boolean} + * @returns {boolean} whether env is jsdom */ jsDom() { return this.testMeta.env === "jsdom" || this.isTargetWeb(); } + /** * @returns {EXPECTED_ANY} moduleScope */ createBaseModuleScope() { - let base = { + const base = { console, expect, jest, @@ -179,24 +192,42 @@ class TestRunner { } return base; } + + /** + * @returns {EXPECTED_ANY} esm context + */ + createBaseEsmContext() { + const base = { + global, + process, + setTimeout, + setImmediate, + URL, + Buffer + }; + return base; + } + /** - * @param {EXPECTED_ANY} globalContext - * @returns {EXPECTED_ANY} + * @param {EXPECTED_ANY} globalContext global context + * @returns {EXPECTED_ANY} global context */ mergeGlobalContext(globalContext) { return Object.assign(this._globalContext, globalContext); } + /** - * @param {EXPECTED_ANY} moduleScope - * @returns {EXPECTED_ANY} + * @param {EXPECTED_ANY} moduleScope module scope + * @returns {EXPECTED_ANY} module scope */ mergeModuleScope(moduleScope) { return Object.assign(this._moduleScope, moduleScope); } + /** - * @param {string} currentDirectory - * @param {string|string[]} module - * @returns {ModuleInfo} + * @param {string} currentDirectory current directory + * @param {string|string[]} module module + * @returns {ModuleInfo} module info */ _resolveModule(currentDirectory, module) { if (Array.isArray(module)) { @@ -212,14 +243,14 @@ class TestRunner { return { subPath: getSubPath(module), modulePath: path.join(currentDirectory, module), - content: fs.readFileSync(path.join(currentDirectory, module), "utf-8") + content: fs.readFileSync(path.join(currentDirectory, module), "utf8") }; } if (path.isAbsolute(module)) { return { subPath: "", modulePath: module, - content: fs.readFileSync(module, "utf-8") + content: fs.readFileSync(module, "utf8") }; } if (module.startsWith("https://test.")) { @@ -227,16 +258,16 @@ class TestRunner { return { subPath: "", modulePath: realPath, - content: fs.readFileSync(realPath, "utf-8") + content: fs.readFileSync(realPath, "utf8") }; } } /** - * @param {string} currentDirectory - * @param {string|string[]} module - * @param {RequireContext} [context={}] - * @returns {EXPECTED_ANY} + * @param {string} currentDirectory current directory + * @param {string|string[]} module module + * @param {RequireContext=} context context + * @returns {EXPECTED_ANY} require result */ require(currentDirectory, module, context = {}) { if (this.testConfig.modules && module in this.testConfig.modules) { @@ -249,7 +280,7 @@ class TestRunner { this.webpackOptions ); } - let moduleInfo = this._resolveModule(currentDirectory, module); + const moduleInfo = this._resolveModule(currentDirectory, module); if (!moduleInfo) { return require(module.startsWith("node:") ? module.slice(5) : module); } @@ -269,24 +300,29 @@ class TestRunner { } return this._moduleRunners.cjs(moduleInfo, context); } + /** - * @returns {(moduleInfo: ModuleInfo, context: RequireContext) => EXPECTED_ANY} + * @returns {(moduleInfo: ModuleInfo, context: RequireContext) => EXPECTED_ANY} cjs runner */ createCjsRunner() { const requireCache = Object.create(null); - return (moduleInfo, context) => { + return (moduleInfo, _context) => { const { modulePath, subPath, content } = moduleInfo; let _content = content; if (modulePath in requireCache) { return requireCache[modulePath].exports; } const mod = { - exports: {} + exports: {}, + webpackTestSuiteModule: true }; requireCache[modulePath] = mod; const moduleScope = { ...this._moduleScope, - require: this.require.bind(this, path.dirname(modulePath)), + require: Object.assign( + this.require.bind(this, path.dirname(modulePath)), + this.require + ), importScripts: url => { expect(url).toMatch(/^https:\/\/test\.cases\/path\//); this.require(this.outputDirectory, urlToRelativePath(url)); @@ -301,8 +337,9 @@ class TestRunner { if (this.testConfig.moduleScope) { this.testConfig.moduleScope(moduleScope, this.webpackOptions); } - if (!this._runInNewContext) + if (!this._runInNewContext) { _content = `Object.assign(global, _globalAssign); ${content}`; + } const args = Object.keys(moduleScope); const argValues = args.map(arg => moduleScope[arg]); const code = `(function(${args.join(", ")}) {${_content}\n})`; @@ -320,6 +357,7 @@ class TestRunner { }; if (document) { const CurrentScript = require("../helpers/CurrentScript"); + const oldCurrentScript = document.currentScript; document.currentScript = new CurrentScript(subPath); try { @@ -333,28 +371,36 @@ class TestRunner { return mod.exports; }; } + /** - * @returns {(moduleInfo: ModuleInfo, context: RequireContext) => Promise} + * @returns {(moduleInfo: ModuleInfo, context: RequireContext) => Promise} esm runner */ createEsmRunner() { + const createEsmContext = () => + vm.createContext( + { ...this._moduleScope, ...this._esmContext }, + { + name: "context for esm" + } + ); const esmCache = new Map(); const { category, name, round } = this.testMeta; const esmIdentifier = `${category.name}-${name}-${round || 0}`; let esmContext = null; return (moduleInfo, context) => { const asModule = require("../helpers/asModule"); + // lazy bind esm context if (!esmContext) { - esmContext = vm.createContext(this._moduleScope, { - name: "context for esm" - }); + esmContext = createEsmContext(); } - const { modulePath, subPath, content } = moduleInfo; + const { modulePath, content } = moduleInfo; const { esmMode } = context; - if (!vm.SourceTextModule) + if (!vm.SourceTextModule) { throw new Error( "Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/jest-cli/bin/jest'." ); + } let esm = esmCache.get(modulePath); if (!esm) { esm = new vm.SourceTextModule(content, { @@ -416,22 +462,32 @@ class TestRunner { })(); }; } + + /** + * @returns {(moduleInfo: ModuleInfo, context: RequireContext) => EXPECTED_ANY} json runner + */ createJSONRunner() { - return moduleInfo => { - return JSON.parse(moduleInfo.content); - }; + return moduleInfo => JSON.parse(moduleInfo.content); } + + /** + * @returns {(moduleInfo: ModuleInfo, context: RequireContext) => EXPECTED_ANY} raw runner + */ createRawRunner() { - return moduleInfo => { - return moduleInfo.content; - }; + return moduleInfo => moduleInfo.content; } + + /** + * @returns {EXPECTED_ANY} env + */ setupEnv() { if (this.jsDom()) { const outputDirectory = this.outputDirectory; + const FakeDocument = require("../helpers/FakeDocument"); const createFakeWorker = require("../helpers/createFakeWorker"); const EventSource = require("../helpers/EventSourceForNode"); + const document = new FakeDocument(outputDirectory); if (this.testConfig.evaluateScriptOnAttached) { document.onScript = src => { @@ -448,7 +504,7 @@ class TestRunner { return { status: 200, ok: true, - json: async () => JSON.parse(buffer.toString("utf-8")) + json: async () => JSON.parse(buffer.toString("utf8")) }; } catch (err) { if (err.code === "ENOENT") { @@ -460,7 +516,7 @@ class TestRunner { throw err; } }; - let env = { + const env = { setTimeout, document, location: { diff --git a/test/watchCases/cache/unsafe-cache-duplicates/webpack.config.js b/test/watchCases/cache/unsafe-cache-duplicates/webpack.config.js index 790b968d827..a6974524b0b 100644 --- a/test/watchCases/cache/unsafe-cache-duplicates/webpack.config.js +++ b/test/watchCases/cache/unsafe-cache-duplicates/webpack.config.js @@ -21,7 +21,7 @@ module.exports = (env, { srcPath }) => ({ name: "webpack.config.js", stage: -1000 }, - (identifier, etag) => { + identifier => { if (identifier.includes(path.join(srcPath, "module.js"))) { return null; } diff --git a/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js b/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js index 510ec2e86d4..231f2371a9b 100644 --- a/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js +++ b/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js @@ -1,5 +1,5 @@ -/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration} */ -module.exports = (env, { srcPath }) => ({ +/** @type {() => import("../../../../").Configuration} */ +module.exports = () => ({ mode: "development", cache: { type: "memory" diff --git a/tooling/print-cache-file.js b/tooling/print-cache-file.js index df9b4386660..e0c6bbd38ce 100644 --- a/tooling/print-cache-file.js +++ b/tooling/print-cache-file.js @@ -152,7 +152,7 @@ const printData = async (data, indent) => { } } const refCounters = [...referencedValuesCounters]; - refCounters.sort(([a, A], [b, B]) => B - A); + refCounters.sort(([_a, A], [_b, B]) => B - A); printLine("SUMMARY: top references:"); for (const [ref, count] of refCounters.slice(10)) { const value = referencedValues.get(ref); diff --git a/tsconfig.types.test.json b/tsconfig.types.test.json index 52ab5c90461..b6f832bd086 100644 --- a/tsconfig.types.test.json +++ b/tsconfig.types.test.json @@ -12,5 +12,6 @@ "test/configCases/**/*loader*.js", "test/hotCases/**/*loader*.js", "declarations.test.d.ts" - ] + ], + "exclude": ["test/js/**/*"] } diff --git a/yarn.lock b/yarn.lock index e138b0d2aa9..92e3ee242a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1568,7 +1568,7 @@ semver "^7.6.0" ts-api-utils "^2.1.0" -"@typescript-eslint/utils@^8.0.0", "@typescript-eslint/utils@^8.26.1": +"@typescript-eslint/utils@^8.0.0": version "8.34.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.34.1.tgz#f98c9b0c5cae407e34f5131cac0f3a74347a398e" integrity sha512-mqOwUdZ3KjtGk7xJJnLbHxTuWVn3GO2WZZuM+Slhkun4+qthLdXx32C8xIXbO1kfCECb3jIs3eoxK3eryk7aoQ== @@ -1851,6 +1851,11 @@ abort-controller@^3.0.0: dependencies: event-target-shim "^5.0.0" +acorn-import-phases@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/acorn-import-phases/-/acorn-import-phases-1.0.3.tgz#30394a1dccee5f380aecb8205b8c69b4f7ae688e" + integrity sha512-jtKLnfoOzm28PazuQ4dVBcE9Jeo6ha1GAJvq3N0LlNOszmTfx+wSycBehn+FN0RnyeR77IBxN/qVYMw0Rlj0Xw== + acorn-jsx@^5.3.2: version "5.3.2" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" @@ -3375,13 +3380,12 @@ eslint-plugin-jsdoc@^51.2.3: semver "^7.7.2" spdx-expression-parse "^4.0.0" -eslint-plugin-n@^17.20.0: - version "17.20.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-n/-/eslint-plugin-n-17.20.0.tgz#000a7a39675d737824d704ae77b626c257b318ef" - integrity sha512-IRSoatgB/NQJZG5EeTbv/iAx1byOGdbbyhQrNvWdCfTnmPxUT0ao9/eGOeG7ljD8wJBsxwE8f6tES5Db0FRKEw== +eslint-plugin-n@^17.21.0: + version "17.21.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-n/-/eslint-plugin-n-17.21.0.tgz#6b1833e5e8fd07a69bbab2be429771ff2309db5e" + integrity sha512-1+iZ8We4ZlwVMtb/DcHG3y5/bZOdazIpa/4TySo22MLKdwrLcfrX0hbadnCvykSQCCmkAnWmIP8jZVb2AAq29A== dependencies: "@eslint-community/eslint-utils" "^4.5.0" - "@typescript-eslint/utils" "^8.26.1" enhanced-resolve "^5.17.1" eslint-plugin-es-x "^7.8.0" get-tsconfig "^4.8.1"