diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af1f302757f..f3ca0ed4754 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -190,7 +190,7 @@ jobs: yarn --frozen-lockfile if: matrix.node-version == '18.x' # Install main version of our deps - - run: yarn upgrade enhanced-resolve@webpack/enhanced-resolve#main loader-runner@webpack/loader-runner#main webpack-sources@webpack/webpack-sources#main watchpack@webpack/watchpack#main tapable@webpack/tapable#master + - run: yarn upgrade enhanced-resolve@webpack/enhanced-resolve#main loader-runner@webpack/loader-runner#main webpack-sources@webpack/webpack-sources#main watchpack@webpack/watchpack#main tapable@webpack/tapable#main if: matrix.use_main_branches == '1' # Install dependencies for LTS node versions - run: yarn --frozen-lockfile diff --git a/lib/esm/ModuleChunkLoadingRuntimeModule.js b/lib/esm/ModuleChunkLoadingRuntimeModule.js index 347e49c5a2c..727c918fa97 100644 --- a/lib/esm/ModuleChunkLoadingRuntimeModule.js +++ b/lib/esm/ModuleChunkLoadingRuntimeModule.js @@ -216,9 +216,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule { "// setup Promise in chunk cache", `var promise = ${importFunctionName}(${ compilation.outputOptions.publicPath === "auto" - ? "" - : `${RuntimeGlobals.publicPath} + ` - }${JSON.stringify(rootOutputDir)} + ${ + ? JSON.stringify(rootOutputDir) + : RuntimeGlobals.publicPath + } + ${ RuntimeGlobals.getChunkScriptFilename }(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction( "e", diff --git a/package.json b/package.json index 455ecb628cc..380457d8dde 100644 --- a/package.json +++ b/package.json @@ -170,17 +170,18 @@ "pretest": "yarn lint", "test": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage", "test:update-snapshots": "yarn test -u", - "test:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.{basictest,longtest,test}.js\"", - "test:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.basictest.js\"", - "test:unit": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.unittest.js\"", + "test:basic": "yarn test --testMatch \"/test/*.basictest.js\"", + "test:unit": "yarn test --testMatch \"/test/*.unittest.js\"", + "test:integration": "yarn test --testMatch \"/test/*.{basictest,longtest,test}.js\"", "cover": "yarn cover:all && yarn cover:report", "cover:clean": "rimraf .nyc_output coverage", - "cover:all": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --coverage", - "cover:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.basictest.js\" --coverage", - "cover:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.{basictest,longtest,test}.js\" --coverage", - "cover:integration:a": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.{basictest,test}.js\" --coverage", - "cover:integration:b": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"/test/*.longtest.js\" --coverage", - "cover:unit": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --testMatch \"/test/*.unittest.js\" --coverage", + "cover:all": "yarn cover:base --coverage", + "cover:unit": "yarn cover:base --testMatch \"/test/*.unittest.js\" --coverage", + "cover:basic": "yarn cover:base --testMatch \"/test/*.basictest.js\" --coverage", + "cover:integration": "yarn cover:base --testMatch \"/test/*.{basictest,longtest,test}.js\" --coverage", + "cover:integration:a": "yarn cover:base --testMatch \"/test/*.{basictest,test}.js\" --coverage", + "cover:integration:b": "yarn cover:base --testMatch \"/test/*.longtest.js\" --coverage", + "cover:base": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage", "cover:types": "node node_modules/tooling/type-coverage", "cover:merge": "yarn mkdirp .nyc_output && nyc merge .nyc_output coverage/coverage-nyc.json && rimraf .nyc_output", "cover:report": "nyc report --reporter=lcov --reporter=text -t coverage" diff --git a/test/ConfigTestCases.template.js b/test/ConfigTestCases.template.js index 6f2e05aa662..b9193d7e803 100644 --- a/test/ConfigTestCases.template.js +++ b/test/ConfigTestCases.template.js @@ -498,11 +498,15 @@ const describeCases = config => { esmMode, parentModule ) => { + if (testConfig.resolveModule) { + module = testConfig.resolveModule(module, i, options); + } if (testConfig === undefined) { throw new Error( `_require(${module}) called after all tests from ${category.name} ${testName} have completed` ); } + if (Array.isArray(module) || /^\.\.?\//.test(module)) { let content; let p; diff --git a/test/configCases/output-module/public-path/test.config.js b/test/configCases/output-module/public-path/test.config.js index 3157eb15cff..83d80a64a1d 100644 --- a/test/configCases/output-module/public-path/test.config.js +++ b/test/configCases/output-module/public-path/test.config.js @@ -1,4 +1,29 @@ +const path = require("path"); + module.exports = { + resolveModule(module, i) { + if (/^\.\/bundle/.test(module)) { + return module; + } + + if (i === 4 || i === 5) { + return `./${module}`; + } + + if (i === 6 || i === 7 || i === 10 || i === 11) { + if (/async/.test(module)) { + return `../${module}`; + } + + return `./${module}`; + } + + if (i === 15) { + return `./${path.basename(module)}`; + } + + return module; + }, findBundle(i, options) { switch (i) { case 2: @@ -9,8 +34,10 @@ module.exports = { case 3: case 7: case 11: + case 12: case 13: - case 12: { + case 14: + case 15: { return `./bundle${i}/${options.output.filename}`; } default: { diff --git a/test/configCases/output-module/public-path/webpack.config.js b/test/configCases/output-module/public-path/webpack.config.js index c4efcbe9817..92c2cfd0e96 100644 --- a/test/configCases/output-module/public-path/webpack.config.js +++ b/test/configCases/output-module/public-path/webpack.config.js @@ -179,5 +179,32 @@ module.exports = (env, { testPath }) => [ experiments: { outputModule: true } + }, + { + devtool: false, + target: "web", + output: { + path: path.resolve(testPath, "./bundle14"), + module: true, + filename: "js/bundle14.mjs", + chunkFilename: "js/[id].bundle14.mjs" + }, + experiments: { + outputModule: true + } + }, + { + devtool: false, + target: "web", + output: { + publicPath: "https://example.com/public/path/", + path: path.resolve(testPath, "./bundle15"), + module: true, + filename: "js/bundle15.mjs", + chunkFilename: "js/[id].bundle15.mjs" + }, + experiments: { + outputModule: true + } } ];