From 1a504483b82e2e80ed1f0442af105cb14106d435 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Thu, 2 Dec 2021 18:47:49 +0300 Subject: [PATCH 01/32] fix/refactor spaceLimited - optimize - respect max arg when there is no groups and max > items.length --- lib/stats/DefaultStatsFactoryPlugin.js | 152 +++++++++++------- .../StatsTestCases.basictest.js.snap | 84 ++++++++-- 2 files changed, 162 insertions(+), 74 deletions(-) diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 1adc8dc1471..447daa9a8f7 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -1658,84 +1658,114 @@ const collapse = children => { return newChildren; }; -const spaceLimited = (itemsAndGroups, max) => { +const spaceLimited = (itemsAndGroups, max, innerSpace = false) => { + if (max < 1) { + return { + children: undefined, + filteredChildren: getTotalItems(itemsAndGroups) + }; + } /** @type {any[] | undefined} */ let children = undefined; /** @type {number | undefined} */ let filteredChildren = undefined; // This are the groups, which take 1+ lines each - const groups = itemsAndGroups.filter(c => c.children || c.filteredChildren); + const groups = []; // The sizes of the groups are stored in groupSizes - const groupSizes = groups.map(g => getItemSize(g)); + const groupSizes = []; // This are the items, which take 1 line each - const items = itemsAndGroups.filter(c => !c.children && !c.filteredChildren); + const items = []; // The total of group sizes - let groupsSize = groupSizes.reduce((a, b) => a + b, 0); + let groupsSize = 0; + + for (const itemOrGroup of itemsAndGroups) { + // is item + if (!itemOrGroup.children && !itemOrGroup.filteredChildren) { + items.push(itemOrGroup); + } else { + groups.push(itemOrGroup); + const size = getItemSize(itemOrGroup); + groupSizes.push(size); + groupsSize += size; + } + } + if (groupsSize + items.length <= max) { // The total size in the current state fits into the max // keep all - children = groups.concat(items); - } else if ( - groups.length > 0 && - groups.length + Math.min(1, items.length) < max - ) { - // If each group would take 1 line the total would be below the maximum - // collapse some groups, keep items - while (groupsSize + items.length + (filteredChildren ? 1 : 0) > max) { + children = groups.length > 0 ? groups.concat(items) : items; + } else if (groups.length === 0) { + // slice items to max + // inner space marks that lines for filteredChildren already reserved + const limit = max - (innerSpace ? 0 : 1); + filteredChildren = items.length - limit; + items.length = limit; + children = items; + } else { + const limit = groups.length + (innerSpace ? 0 : Math.min(1, items.length)); + if (limit < max) { // calculate how much we are over the size limit // this allows to approach the limit faster - // it's always > 1 - const oversize = - items.length + groupsSize + (filteredChildren ? 1 : 0) - max; - // Find the maximum group and process only this one - const maxGroupSize = Math.max(...groupSizes); - if (maxGroupSize < items.length) { - filteredChildren = items.length; - items.length = 0; - continue; - } - for (let i = 0; i < groups.length; i++) { - if (groupSizes[i] === maxGroupSize) { - const group = groups[i]; - // run this algorithm recursively and limit the size of the children to - // current size - oversize / number of groups - // So it should always end up being smaller - const headerSize = !group.children - ? 0 - : group.filteredChildren - ? 2 - : 1; - const limited = spaceLimited( - group.children, - groupSizes[i] - headerSize - oversize / groups.length - ); - groups[i] = { - ...group, - children: limited.children, - filteredChildren: - (group.filteredChildren || 0) + limited.filteredChildren - }; - const newSize = getItemSize(groups[i]); - groupsSize -= groupSizes[i] - newSize; - groupSizes[i] = newSize; - break; + let oversize; + // If each group would take 1 line the total would be below the maximum + // collapse some groups, keep items + while ( + (oversize = + groupsSize + + items.length + + (filteredChildren && !innerSpace ? 1 : 0) - + max) > 0 + ) { + // Find the maximum group and process only this one + const maxGroupSize = Math.max(...groupSizes); + if (maxGroupSize < items.length) { + filteredChildren = items.length; + items.length = 0; + continue; + } + for (let i = 0; i < groups.length; i++) { + if (groupSizes[i] === maxGroupSize) { + const group = groups[i]; + // run this algorithm recursively and limit the size of the children to + // current size - oversize / number of groups + // So it should always end up being smaller + const headerSize = group.filteredChildren ? 2 : 1; + const limited = spaceLimited( + group.children, + maxGroupSize - + // we should use ceil to always feet in max + Math.ceil(oversize / groups.length) - + // we substitute size of group head + headerSize, + true + ); + groups[i] = { + ...group, + children: limited.children, + filteredChildren: limited.filteredChildren + ? (group.filteredChildren || 0) + limited.filteredChildren + : group.filteredChildren + }; + const newSize = getItemSize(groups[i]); + groupsSize -= maxGroupSize - newSize; + groupSizes[i] = newSize; + break; + } } } + children = groups.concat(items); + } else if (limit === max) { + // If we have only enough space to show one line per group and one line for the filtered items + // collapse all groups and items + children = collapse(groups); + filteredChildren = items.length; + } else { + // If we have no space + // collapse complete group + filteredChildren = getTotalItems(itemsAndGroups); } - children = groups.concat(items); - } else if ( - groups.length > 0 && - groups.length + Math.min(1, items.length) <= max - ) { - // If we have only enough space to show one line per group and one line for the filtered items - // collapse all groups and items - children = groups.length ? collapse(groups) : undefined; - filteredChildren = items.length; - } else { - // If we have no space - // collapse complete group - filteredChildren = getTotalItems(itemsAndGroups); } + return { children, filteredChildren diff --git a/test/__snapshots__/StatsTestCases.basictest.js.snap b/test/__snapshots__/StatsTestCases.basictest.js.snap index 6cfe46048b7..aa8f8b5f9a4 100644 --- a/test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/test/__snapshots__/StatsTestCases.basictest.js.snap @@ -1326,13 +1326,46 @@ webpack x.x.x compiled successfully in X ms" exports[`StatsTestCases should print correct stats for max-modules 1`] = ` "asset main.js 5.47 KiB [emitted] (name: main) -31 modules +./index.js 181 bytes [built] [code generated] +./a.js?1 33 bytes [built] [code generated] +./a.js?2 33 bytes [built] [code generated] +./a.js?3 33 bytes [built] [code generated] +./a.js?4 33 bytes [built] [code generated] +./a.js?5 33 bytes [built] [code generated] +./a.js?6 33 bytes [built] [code generated] +./a.js?7 33 bytes [built] [code generated] +./a.js?8 33 bytes [built] [code generated] +./a.js?9 33 bytes [built] [code generated] +./a.js?10 33 bytes [built] [code generated] +./c.js?1 33 bytes [built] [code generated] +./c.js?2 33 bytes [built] [code generated] +./c.js?3 33 bytes [built] [code generated] +./c.js?4 33 bytes [built] [code generated] +./c.js?5 33 bytes [built] [code generated] +./c.js?6 33 bytes [built] [code generated] +./c.js?7 33 bytes [built] [code generated] +./c.js?8 33 bytes [built] [code generated] +12 modules webpack x.x.x compiled successfully in X ms" `; exports[`StatsTestCases should print correct stats for max-modules-default 1`] = ` "asset main.js 5.47 KiB [emitted] (name: main) -31 modules +./index.js 181 bytes [built] [code generated] +./a.js?1 33 bytes [built] [code generated] +./a.js?2 33 bytes [built] [code generated] +./a.js?3 33 bytes [built] [code generated] +./a.js?4 33 bytes [built] [code generated] +./a.js?5 33 bytes [built] [code generated] +./a.js?6 33 bytes [built] [code generated] +./a.js?7 33 bytes [built] [code generated] +./a.js?8 33 bytes [built] [code generated] +./a.js?9 33 bytes [built] [code generated] +./a.js?10 33 bytes [built] [code generated] +./c.js?1 33 bytes [built] [code generated] +./c.js?2 33 bytes [built] [code generated] +./c.js?3 33 bytes [built] [code generated] +17 modules webpack x.x.x compiled successfully in X ms" `; @@ -3052,7 +3085,23 @@ exports[`StatsTestCases should print correct stats for scope-hoisting-bailouts 1 "runtime modules 6.83 KiB 10 modules built modules 615 bytes [built] code generated modules 530 bytes [code generated] - modules by path ./*.js 377 bytes 7 modules + modules by path ./*.js 377 bytes + ./index.js 150 bytes [built] [code generated] + Statement (ExpressionStatement) with side effects in source code at 7:0-25 + ModuleConcatenation bailout: Cannot concat with ./cjs.js: Module is not an ECMAScript module + ModuleConcatenation bailout: Cannot concat with ./eval.js: Module uses eval() + ModuleConcatenation bailout: Cannot concat with ./module-id.js: Module uses module.id + ModuleConcatenation bailout: Cannot concat with ./module-loaded.js: Module uses module.loaded + ./entry.js 32 bytes [built] [code generated] + ./cjs.js 59 bytes [built] [code generated] + CommonJS bailout: module.exports is used directly at 3:0-14 + Statement (ExpressionStatement) with side effects in source code at 1:0-26 + ModuleConcatenation bailout: Module is not an ECMAScript module + ./ref-from-cjs.js 45 bytes [built] [code generated] + ./eval.js 35 bytes [built] [code generated] + Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-34 + ModuleConcatenation bailout: Module uses eval() + 2 modules ./concatenated.js + 2 modules 111 bytes [built] [code generated] ModuleConcatenation bailout: Cannot concat with external \\"external\\": Module external \\"external\\" is not in the same chunk(s) (expected in chunk(s) unnamed chunk(s), module is in chunk(s) index) external \\"external\\" 42 bytes [built] [code generated] @@ -3087,12 +3136,13 @@ Entrypoint second 13.5 KiB = b-vendor.js 419 bytes b-second.js 13.1 KiB runtime modules 15.1 KiB 20 modules cacheable modules 975 bytes code generated modules 857 bytes [code generated] - modules by path ./*.js + 1 modules 459 bytes 3 modules + modules by path ./*.js + 1 modules 459 bytes + ./second.js + 1 modules 227 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./vendor.js: Module ./vendor.js is not in the same chunk(s) (expected in chunk(s) second, module is in chunk(s) vendor) + 2 modules modules by path ./*.js 106 bytes ./vendor.js 25 bytes [built] [code generated] - ./lazy_shared.js 56 bytes [built] [code generated] - ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_first.js, ./lazy_second.js - ./common_lazy_shared.js 25 bytes [built] [code generated] + 2 modules ./first.js + 2 modules 292 bytes [built] [code generated] ModuleConcatenation bailout: Cannot concat with ./vendor.js: Module ./vendor.js is not in the same chunk(s) (expected in chunk(s) first, module is in chunk(s) vendor) orphan modules 118 bytes [orphan] @@ -4073,8 +4123,16 @@ switched: ./index.js 1.19 KiB [built] [code generated] chunk (runtime: main) switched-main-879072e3.js (main-879072e3) 1.68 KiB ={1}= ={59}= ={318}= ={410}= ={520}= ={663}= ={869}= ={997}= [initial] [rendered] > ./ main - modules by path ./subfolder/*.js 1.1 KiB 11 modules - modules by path ./*.js 594 bytes 9 modules + modules by path ./subfolder/*.js 1.1 KiB + ./subfolder/big.js?1 267 bytes [built] [code generated] + ./subfolder/big.js?2 267 bytes [built] [code generated] + ./subfolder/small.js?1 66 bytes [built] [code generated] + 8 modules + modules by path ./*.js 594 bytes + ./small.js?1 66 bytes [built] [code generated] + ./small.js?2 66 bytes [built] [code generated] + ./small.js?3 66 bytes [built] [code generated] + 6 modules chunk (runtime: main) switched-main-12217e1d.js (main-12217e1d) 1.57 KiB (javascript) 3.02 KiB (runtime) ={1}= ={59}= ={318}= ={410}= ={520}= ={581}= ={869}= ={997}= [entry] [rendered] > ./ main runtime modules 3.02 KiB 5 modules @@ -4086,13 +4144,13 @@ switched: ./node_modules/small.js?2 66 bytes [built] [code generated] chunk (runtime: main) switched-main-7aeafcb2.js (main-7aeafcb2) 1.62 KiB ={1}= ={59}= ={318}= ={410}= ={520}= ={581}= ={663}= ={869}= [initial] [rendered] > ./ main - modules by path ./inner-module/*.js 594 bytes 9 modules + modules by path ./inner-module/*.js 594 bytes + ./inner-module/small.js?1 66 bytes [built] [code generated] + 8 modules modules by path ./in-some-directory/*.js 531 bytes ./in-some-directory/big.js?1 267 bytes [built] [code generated] ./in-some-directory/small.js?1 66 bytes [built] [code generated] - ./in-some-directory/small.js?2 66 bytes [built] [code generated] - ./in-some-directory/small.js?3 66 bytes [built] [code generated] - ./in-some-directory/small.js?4 66 bytes [built] [code generated] + 3 modules modules by path ./*.js 534 bytes ./big.js?1 267 bytes [built] [code generated] ./big.js?2 267 bytes [built] [code generated] From eae11dd27ed31119e6bd3568a4a4ec563c57b7a9 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Thu, 2 Dec 2021 19:30:28 +0300 Subject: [PATCH 02/32] renaming --- lib/stats/DefaultStatsFactoryPlugin.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 447daa9a8f7..81eb2a1123d 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -1658,7 +1658,11 @@ const collapse = children => { return newChildren; }; -const spaceLimited = (itemsAndGroups, max, innerSpace = false) => { +const spaceLimited = ( + itemsAndGroups, + max, + filteredChildrenLineReserved = false +) => { if (max < 1) { return { children: undefined, @@ -1697,12 +1701,14 @@ const spaceLimited = (itemsAndGroups, max, innerSpace = false) => { } else if (groups.length === 0) { // slice items to max // inner space marks that lines for filteredChildren already reserved - const limit = max - (innerSpace ? 0 : 1); + const limit = max - (filteredChildrenLineReserved ? 0 : 1); filteredChildren = items.length - limit; items.length = limit; children = items; } else { - const limit = groups.length + (innerSpace ? 0 : Math.min(1, items.length)); + const limit = + groups.length + + (filteredChildrenLineReserved ? 0 : Math.min(1, items.length)); if (limit < max) { // calculate how much we are over the size limit // this allows to approach the limit faster @@ -1713,7 +1719,7 @@ const spaceLimited = (itemsAndGroups, max, innerSpace = false) => { (oversize = groupsSize + items.length + - (filteredChildren && !innerSpace ? 1 : 0) - + (filteredChildren && !filteredChildrenLineReserved ? 1 : 0) - max) > 0 ) { // Find the maximum group and process only this one @@ -1737,7 +1743,7 @@ const spaceLimited = (itemsAndGroups, max, innerSpace = false) => { Math.ceil(oversize / groups.length) - // we substitute size of group head headerSize, - true + headerSize === 2 ); groups[i] = { ...group, From 5c76d8d39df20abd039293429a1e33d175261df0 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sun, 12 Dec 2021 14:47:45 +0530 Subject: [PATCH 03/32] feat: allow specific description for cli options --- lib/cli.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cli.js b/lib/cli.js index 5488a7d47ac..f8b13d961d8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -97,6 +97,7 @@ const getArguments = (schema = webpackSchema) => { const getDescription = path => { for (const { schema } of path) { if (schema.cli && schema.cli.helper) continue; + if (schema.cliDescription) return schema.cliDescription; if (schema.description) return schema.description; } }; From b86cfd7df920a5261d31435bfa95431c51bea8e3 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sun, 12 Dec 2021 14:51:18 +0530 Subject: [PATCH 04/32] feat: add `negatedDescription` property for negative flags --- lib/cli.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/cli.js b/lib/cli.js index f8b13d961d8..984b1539a17 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -37,6 +37,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json"); /** * @typedef {Object} ArgumentConfig * @property {string} description + * @property {string} [negatedDescription] * @property {string} path * @property {boolean} multiple * @property {"enum"|"string"|"path"|"number"|"boolean"|"RegExp"|"reset"} type @@ -102,6 +103,18 @@ const getArguments = (schema = webpackSchema) => { } }; + /** + * + * @param {PathItem[]} path path in the schema + * @returns {string | undefined} negative description + */ + const getNegatedDescription = path => { + for (const { schema } of path) { + if (schema.cli && schema.cli.helper) continue; + if (schema.negatedDescription) return schema.negatedDescription; + } + }; + /** * * @param {any} schemaPart schema @@ -168,6 +181,7 @@ const getArguments = (schema = webpackSchema) => { const argConfigBase = schemaToArgumentConfig(path[0].schema); if (!argConfigBase) return 0; + const negatedDescription = getNegatedDescription(path); const name = pathToArgumentName(path[0].path); /** @type {ArgumentConfig} */ const argConfig = { @@ -177,6 +191,10 @@ const getArguments = (schema = webpackSchema) => { path: path[0].path }; + if (negatedDescription) { + argConfig.negatedDescription = negatedDescription; + } + if (!flags[name]) { flags[name] = { configs: [], From 34471196f3bad8a4118a2ae31f6cf61eac425b15 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sun, 12 Dec 2021 14:56:38 +0530 Subject: [PATCH 05/32] chore: update types --- types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types.d.ts b/types.d.ts index 05d308f1e3c..a9d9b4d2d46 100644 --- a/types.d.ts +++ b/types.d.ts @@ -215,6 +215,7 @@ declare interface Argument { } declare interface ArgumentConfig { description: string; + negatedDescription?: string; path: string; multiple: boolean; type: "string" | "number" | "boolean" | "path" | "enum" | "RegExp" | "reset"; From ddb0c74da8576e697194076e9144d58b9d850269 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sun, 12 Dec 2021 15:06:44 +0530 Subject: [PATCH 06/32] test: add more tests for CLI --- test/Cli.basictest.js | 28 +++++++++++++++ test/__snapshots__/Cli.basictest.js.snap | 46 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/test/Cli.basictest.js b/test/Cli.basictest.js index 7a82fd1bc76..0223db56c62 100644 --- a/test/Cli.basictest.js +++ b/test/Cli.basictest.js @@ -5,6 +5,34 @@ describe("Cli", () => { expect(getArguments()).toMatchSnapshot(); }); + it("should generate the correct cli flags with custom schema", () => { + const schema = { + title: "custom CLI options", + type: "object", + additionalProperties: false, + properties: { + "with-cli-description": { + type: "string", + description: "original description", + cliDescription: "description for CLI option" + }, + "with-negative-description": { + type: "boolean", + description: "original description", + negatedDescription: "custom negative description" + }, + "with-both-cli-and-negative-description": { + type: "boolean", + description: "original description", + cliDescription: "description for CLI option", + negatedDescription: "custom negative description" + } + } + }; + + expect(getArguments(schema)).toMatchSnapshot(); + }); + const test = (name, values, config, fn) => { it(`should correctly process arguments for ${name}`, () => { const args = getArguments(); diff --git a/test/__snapshots__/Cli.basictest.js.snap b/test/__snapshots__/Cli.basictest.js.snap index 7dfe3d84ef0..bde140f6fb6 100644 --- a/test/__snapshots__/Cli.basictest.js.snap +++ b/test/__snapshots__/Cli.basictest.js.snap @@ -8931,3 +8931,49 @@ Object { }, } `; + +exports[`Cli should generate the correct cli flags with custom schema 1`] = ` +Object { + "with-both-cli-and-negative-description": Object { + "configs": Array [ + Object { + "description": "description for CLI option", + "multiple": false, + "negatedDescription": "custom negative description", + "path": "with-both-cli-and-negative-description", + "type": "boolean", + }, + ], + "description": "description for CLI option", + "multiple": false, + "simpleType": "boolean", + }, + "with-cli-description": Object { + "configs": Array [ + Object { + "description": "description for CLI option", + "multiple": false, + "path": "with-cli-description", + "type": "string", + }, + ], + "description": "description for CLI option", + "multiple": false, + "simpleType": "string", + }, + "with-negative-description": Object { + "configs": Array [ + Object { + "description": "original description", + "multiple": false, + "negatedDescription": "custom negative description", + "path": "with-negative-description", + "type": "boolean", + }, + ], + "description": "original description", + "multiple": false, + "simpleType": "boolean", + }, +} +`; From af4150d0641db82b9a776f92b4f11e908c297bf2 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Thu, 9 Dec 2021 23:14:14 -0500 Subject: [PATCH 07/32] chore: remove old Travis-CI config --- .travis.yml | 74 -------------------------------------------------- package.json | 4 --- test/README.md | 2 +- 3 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b2f09b31b78..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,74 +0,0 @@ -dist: trusty -language: node_js - -branches: - only: - - webpack-4 - - main - - next - - dev-1 - -cache: - yarn: true - directories: - - ".jest-cache" - - ".eslintcache" - -stages: - - basic - - advanced - -matrix: - include: - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=basic - stage: basic - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=lintunit - stage: advanced - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration - stage: advanced - - os: linux - node_js: "12" - env: NO_WATCH_TESTS=1 ALTERNATIVE_SORT=1 JEST="--maxWorkers=2 --cacheDirectory .jest-cache" JOB_PART=integration - stage: advanced - - os: linux - node_js: "10" - env: - - NODEJS_VERSION=v15.0.0-nightly2020082003293aa3a1 - - YARN_EXTRA_ARGS="--ignore-engines" - - NO_WATCH_TESTS=1 - - JEST="--maxWorkers=2 --cacheDirectory .jest-cache" - - JOB_PART=integration - stage: advanced - fast_finish: true - -before_install: - - | - if [ "$NODEJS_VERSION" != "" ]; - then - mkdir /opt/node - curl --silent "https://nodejs.org/download/nightly/$NODEJS_VERSION/node-$NODEJS_VERSION-linux-x64.tar.gz" | tar -zxf - --directory /opt/node - export PATH="/opt/node/node-$NODEJS_VERSION-linux-x64/bin:$PATH" - node --version - fi - -install: - - yarn --frozen-lockfile $YARN_EXTRA_ARGS - - yarn link --frozen-lockfile $YARN_EXTRA_ARGS || true - - yarn link webpack --frozen-lockfile $YARN_EXTRA_ARGS - -script: yarn travis:$JOB_PART - -after_success: - - cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose - - bash <(curl -s https://codecov.io/bash) -F $JOB_PART -X gcov - - rm -f .jest-cache/haste-map* .jest-cache/perf-cache* - -notifications: - slack: - secure: JduSdKWwbnLCwo7Z4E59SGE+Uw832UwnXzQiKEpg1BV45MYDPRiGltly1tRHmPh9OGjvGx3XSkC2tNGOBLtL4UL2SCkf012x0t7jDutKRfcv/njynl8jk8l+UhPmaWiHXDQAgGiiKdL4RfzPLW3HeVHCOWm0LKMzcarTa8tw+rE= diff --git a/package.json b/package.json index d4d2b84c219..abb3f169375 100644 --- a/package.json +++ b/package.json @@ -143,10 +143,6 @@ "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\"", - "travis:integration": "yarn cover:integration --ci $JEST", - "travis:basic": "yarn cover:basic --ci $JEST", - "travis:lintunit": "yarn lint && yarn cover:unit --ci $JEST", - "travis:benchmark": "yarn benchmark --ci", "appveyor:integration": "yarn cover:integration --ci %JEST%", "appveyor:unit": "yarn cover:unit --ci %JEST%", "appveyor:benchmark": "yarn benchmark --ci", diff --git a/test/README.md b/test/README.md index 240d58b9009..11dd2dcb7e3 100644 --- a/test/README.md +++ b/test/README.md @@ -69,4 +69,4 @@ If you are still nervous or don't quite understand, please submit an issue and t ## Footnotes -1 webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow NodeJS's timeline for dropping older versions of node. Because of this we expect your tests on Travis to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions. +1 webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow NodeJS's timeline for dropping older versions of node. Because of this we expect your tests on GitHub Actions to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions. From 7164747a2c3d3deb8296e9c50f8589d0d3336fb0 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Tue, 14 Dec 2021 10:15:27 -0500 Subject: [PATCH 08/32] chore: remove old AppVeyor config --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index abb3f169375..2f72efa35dd 100644 --- a/package.json +++ b/package.json @@ -143,9 +143,6 @@ "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\"", - "appveyor:integration": "yarn cover:integration --ci %JEST%", - "appveyor:unit": "yarn cover:unit --ci %JEST%", - "appveyor:benchmark": "yarn benchmark --ci", "build:examples": "cd examples && node buildAll.js", "type-report": "rimraf coverage && yarn cover:types && yarn cover:report && open-cli coverage/lcov-report/index.html", "pretest": "yarn lint", From 6dff128a9700cce6c8821f40090f6a93f7af2c20 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Dec 2021 03:02:26 +0000 Subject: [PATCH 09/32] chore(deps): bump browserslist from 4.18.1 to 4.19.1 Bumps [browserslist](https://github.com/browserslist/browserslist) from 4.18.1 to 4.19.1. - [Release notes](https://github.com/browserslist/browserslist/releases) - [Changelog](https://github.com/browserslist/browserslist/blob/main/CHANGELOG.md) - [Commits](https://github.com/browserslist/browserslist/compare/4.18.1...4.19.1) --- updated-dependencies: - dependency-name: browserslist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- yarn.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/yarn.lock b/yarn.lock index 444dc549a7c..da2ad23c96d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1560,12 +1560,12 @@ browser-process-hrtime@^1.0.0: integrity sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow== browserslist@^4.14.5, browserslist@^4.16.6: - version "4.18.1" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.18.1.tgz#60d3920f25b6860eb917c6c7b185576f4d8b017f" - integrity sha512-8ScCzdpPwR2wQh8IT82CA2VgDwjHyqMovPBZSNH54+tm4Jk2pCuv90gmAdH6J84OCRWi0b4gMe6O6XPXuJnjgQ== + version "4.19.1" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.19.1.tgz#4ac0435b35ab655896c31d53018b6dd5e9e4c9a3" + integrity sha512-u2tbbG5PdKRTUoctO3NBD8FQ5HdPh1ZXPHzp1rwaa5jTc+RV9/+RlWiAIKmjRPQF+xbGM9Kklj5bZQFa2s/38A== dependencies: - caniuse-lite "^1.0.30001280" - electron-to-chromium "^1.3.896" + caniuse-lite "^1.0.30001286" + electron-to-chromium "^1.4.17" escalade "^3.1.1" node-releases "^2.0.1" picocolors "^1.0.0" @@ -1628,10 +1628,10 @@ camelcase@^6.2.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809" integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== -caniuse-lite@^1.0.30001280: - version "1.0.30001280" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001280.tgz#066a506046ba4be34cde5f74a08db7a396718fb7" - integrity sha512-kFXwYvHe5rix25uwueBxC569o53J6TpnGu0BEEn+6Lhl2vsnAumRFWEBhDft1fwyo6m1r4i+RqA4+163FpeFcA== +caniuse-lite@^1.0.30001286: + version "1.0.30001286" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001286.tgz#3e9debad420419618cfdf52dc9b6572b28a8fff6" + integrity sha512-zaEMRH6xg8ESMi2eQ3R4eZ5qw/hJiVsO/HlLwniIwErij0JDr9P+8V4dtx1l+kLq6j3yy8l8W4fst1lBnat5wQ== caseless@~0.12.0: version "0.12.0" @@ -2227,10 +2227,10 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" safer-buffer "^2.1.0" -electron-to-chromium@^1.3.896: - version "1.3.896" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.896.tgz#4a94efe4870b1687eafd5c378198a49da06e8a1b" - integrity sha512-NcGkBVXePiuUrPLV8IxP43n1EOtdg+dudVjrfVEUd/bOqpQUFZ2diL5PPYzbgEhZFEltdXV3AcyKwGnEQ5lhMA== +electron-to-chromium@^1.4.17: + version "1.4.18" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.18.tgz#2fb282213937986a20a653315963070e8321b3f3" + integrity sha512-i7nKjGGBE1+YUIbfLObA1EZPmN7J1ITEllbhusDk+KIk6V6gUxN9PFe36v+Sd+8Cg0k3cgUv9lQhQZalr8rggw== emittery@^0.8.1: version "0.8.1" From 136b723023f8f26d71eabdd16badf04c1c8554e4 Mon Sep 17 00:00:00 2001 From: Asriel Yu Date: Fri, 24 Dec 2021 20:27:31 +0800 Subject: [PATCH 10/32] fix callback err type should include null --- lib/Cache.js | 2 +- lib/CacheFacade.js | 4 +- lib/CleanPlugin.js | 2 +- lib/Compilation.js | 10 +-- lib/Compiler.js | 4 +- lib/ContextModule.js | 4 +- lib/DelegatedModule.js | 2 +- lib/DllModule.js | 2 +- lib/ExternalModule.js | 2 +- lib/ExternalModuleFactoryPlugin.js | 2 +- lib/FileSystemInfo.js | 34 ++++---- lib/HookWebpackError.js | 2 +- lib/Module.js | 2 +- lib/MultiCompiler.js | 2 +- lib/NormalModule.js | 6 +- lib/RawModule.js | 2 +- lib/RuntimeModule.js | 2 +- lib/asset/RawDataUrlModule.js | 2 +- lib/cache/ResolverCachePlugin.js | 2 +- lib/container/ContainerEntryModule.js | 2 +- lib/container/FallbackModule.js | 2 +- lib/container/RemoteModule.js | 2 +- lib/dependencies/LoaderPlugin.js | 4 +- lib/hmr/LazyCompilationPlugin.js | 2 +- lib/hmr/lazyCompilationBackend.js | 2 +- lib/schemes/HttpUriPlugin.js | 16 ++-- lib/sharing/ConsumeSharedModule.js | 2 +- lib/sharing/ProvideSharedModule.js | 2 +- lib/sharing/utils.js | 2 +- types.d.ts | 121 +++++++++++++++----------- 30 files changed, 134 insertions(+), 111 deletions(-) diff --git a/lib/Cache.js b/lib/Cache.js index 2f553bef93c..e76f8b63b5f 100644 --- a/lib/Cache.js +++ b/lib/Cache.js @@ -21,7 +21,7 @@ const { /** * @template T * @callback CallbackCache - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {T=} result * @returns {void} */ diff --git a/lib/CacheFacade.js b/lib/CacheFacade.js index acd22c7405e..912c9d45927 100644 --- a/lib/CacheFacade.js +++ b/lib/CacheFacade.js @@ -18,7 +18,7 @@ const mergeEtags = require("./cache/mergeEtags"); /** * @template T * @callback CallbackCache - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {T=} result * @returns {void} */ @@ -26,7 +26,7 @@ const mergeEtags = require("./cache/mergeEtags"); /** * @template T * @callback CallbackNormalErrorCache - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result * @returns {void} */ diff --git a/lib/CleanPlugin.js b/lib/CleanPlugin.js index e6fbf1d6016..074b90bf450 100644 --- a/lib/CleanPlugin.js +++ b/lib/CleanPlugin.js @@ -45,7 +45,7 @@ const validate = createSchemaValidation( * @param {OutputFileSystem} fs filesystem * @param {string} outputPath output path * @param {Set} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator) - * @param {function(Error=, Set=): void} callback returns the filenames of the assets that shouldn't be there + * @param {function((Error | null)=, Set=): void} callback returns the filenames of the assets that shouldn't be there * @returns {void} */ const getDiffToFs = (fs, outputPath, currentAssets, callback) => { diff --git a/lib/Compilation.js b/lib/Compilation.js index 0e3ed08aa81..a094b5bebe4 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -116,34 +116,34 @@ const { isSourceEqual } = require("./util/source"); /** * @callback Callback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @returns {void} */ /** * @callback ModuleCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {Module=} result * @returns {void} */ /** * @callback ModuleFactoryResultCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {ModuleFactoryResult=} result * @returns {void} */ /** * @callback ModuleOrFactoryResultCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {Module | ModuleFactoryResult=} result * @returns {void} */ /** * @callback ExecuteModuleCallback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {ExecuteModuleResult=} result * @returns {void} */ diff --git a/lib/Compiler.js b/lib/Compiler.js index 2d7ccc1e5a6..f232d8cf4d6 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -58,13 +58,13 @@ const { isSourceEqual } = require("./util/source"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ /** * @callback RunAsChildCallback - * @param {Error=} err + * @param {(Error | null)=} err * @param {Chunk[]=} entries * @param {Compilation=} compilation */ diff --git a/lib/ContextModule.js b/lib/ContextModule.js index a1aca892184..4ffe4822b42 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -71,7 +71,7 @@ const makeSerializable = require("./util/makeSerializable"); /** * @callback ResolveDependenciesCallback - * @param {Error=} err + * @param {(Error | null)=} err * @param {ContextElementDependency[]=} dependencies */ @@ -312,7 +312,7 @@ class ContextModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild({ fileSystemInfo }, callback) { diff --git a/lib/DelegatedModule.js b/lib/DelegatedModule.js index 98e0ca8f46d..76cb0a48db9 100644 --- a/lib/DelegatedModule.js +++ b/lib/DelegatedModule.js @@ -91,7 +91,7 @@ class DelegatedModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/DllModule.js b/lib/DllModule.js index a4321d0d6f1..83b2d95a99a 100644 --- a/lib/DllModule.js +++ b/lib/DllModule.js @@ -96,7 +96,7 @@ class DllModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/ExternalModule.js b/lib/ExternalModule.js index 607a3a9ef3d..bed0bbbe23e 100644 --- a/lib/ExternalModule.js +++ b/lib/ExternalModule.js @@ -432,7 +432,7 @@ class ExternalModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/ExternalModuleFactoryPlugin.js b/lib/ExternalModuleFactoryPlugin.js index 171720dcfa4..92d56470025 100644 --- a/lib/ExternalModuleFactoryPlugin.js +++ b/lib/ExternalModuleFactoryPlugin.js @@ -117,7 +117,7 @@ class ExternalModuleFactoryPlugin { /** * @param {Externals} externals externals config - * @param {function(Error=, ExternalModule=): void} callback callback + * @param {function((Error | null)=, ExternalModule=): void} callback callback * @returns {void} */ const handleExternals = (externals, callback) => { diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index d76ac8b961c..5bc90497616 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -1185,7 +1185,7 @@ class FileSystemInfo { /** * @param {string} path file path - * @param {function(WebpackError=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function * @returns {void} */ getFileTimestamp(path, callback) { @@ -1196,7 +1196,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function * @returns {void} */ getContextTimestamp(path, callback) { @@ -1217,7 +1217,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function * @returns {void} */ _getUnresolvedContextTimestamp(path, callback) { @@ -1228,7 +1228,7 @@ class FileSystemInfo { /** * @param {string} path file path - * @param {function(WebpackError=, string=): void} callback callback function + * @param {function((WebpackError | null)=, string=): void} callback callback function * @returns {void} */ getFileHash(path, callback) { @@ -1239,7 +1239,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, string=): void} callback callback function + * @param {function((WebpackError | null)=, string=): void} callback callback function * @returns {void} */ getContextHash(path, callback) { @@ -1259,7 +1259,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, ContextHash=): void} callback callback function + * @param {function((WebpackError | null)=, ContextHash=): void} callback callback function * @returns {void} */ _getUnresolvedContextHash(path, callback) { @@ -1270,7 +1270,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, ResolvedContextTimestampAndHash=): void} callback callback function + * @param {function((WebpackError | null)=, ResolvedContextTimestampAndHash=): void} callback callback function * @returns {void} */ getContextTsh(path, callback) { @@ -1290,7 +1290,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function(WebpackError=, ContextTimestampAndHash=): void} callback callback function + * @param {function((WebpackError | null)=, ContextTimestampAndHash=): void} callback callback function * @returns {void} */ _getUnresolvedContextTsh(path, callback) { @@ -1330,7 +1330,7 @@ class FileSystemInfo { /** * @param {string} context context directory * @param {Iterable} deps dependencies - * @param {function(Error=, ResolveBuildDependenciesResult=): void} callback callback function + * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function * @returns {void} */ resolveBuildDependencies(context, deps, callback) { @@ -1798,7 +1798,7 @@ class FileSystemInfo { /** * @param {Map} resolveResults results from resolving - * @param {function(Error=, boolean=): void} callback callback with true when resolveResults resolve the same way + * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way * @returns {void} */ checkResolveResultsValid(resolveResults, callback) { @@ -1880,7 +1880,7 @@ class FileSystemInfo { * @param {Object} options options object (for future extensions) * @param {boolean=} options.hash should use hash to snapshot * @param {boolean=} options.timestamp should use timestamp to snapshot - * @param {function(WebpackError=, Snapshot=): void} callback callback function + * @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function * @returns {void} */ createSnapshot(startTime, files, directories, missing, options, callback) { @@ -2375,7 +2375,7 @@ class FileSystemInfo { /** * @param {Snapshot} snapshot the snapshot made - * @param {function(WebpackError=, boolean=): void} callback callback function + * @param {function((WebpackError | null)=, boolean=): void} callback callback function * @returns {void} */ checkSnapshotValid(snapshot, callback) { @@ -2395,7 +2395,7 @@ class FileSystemInfo { /** * @param {Snapshot} snapshot the snapshot made - * @param {function(WebpackError=, boolean=): void} callback callback function + * @param {function((WebpackError | null)=, boolean=): void} callback callback function * @returns {void} */ _checkSnapshotValidNoCache(snapshot, callback) { @@ -2944,7 +2944,7 @@ class FileSystemInfo { * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromFile called when context item is a file * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromDirectory called when context item is a directory * @param {function(string[], ItemType[]): T} options.reduce called from all context items - * @param {function(Error=, (T)=): void} callback callback + * @param {function((Error | null)=, (T)=): void} callback callback */ _readContext( { @@ -3127,7 +3127,7 @@ class FileSystemInfo { /** * @param {ContextFileSystemInfoEntry} entry entry - * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback + * @param {function((Error | null)=, ResolvedContextFileSystemInfoEntry=): void} callback callback * @returns {void} */ _resolveContextTimestamp(entry, callback) { @@ -3235,7 +3235,7 @@ class FileSystemInfo { /** * @param {ContextHash} entry context hash - * @param {function(Error=, string=): void} callback callback + * @param {function((Error | null)=, string=): void} callback callback * @returns {void} */ _resolveContextHash(entry, callback) { @@ -3391,7 +3391,7 @@ class FileSystemInfo { /** * @param {ContextTimestampAndHash} entry entry - * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback + * @param {function((Error | null)=, ResolvedContextTimestampAndHash=): void} callback callback * @returns {void} */ _resolveContextTsh(entry, callback) { diff --git a/lib/HookWebpackError.js b/lib/HookWebpackError.js index e813d1eac87..dfb5e935899 100644 --- a/lib/HookWebpackError.js +++ b/lib/HookWebpackError.js @@ -51,7 +51,7 @@ module.exports.makeWebpackError = makeWebpackError; /** * @template T - * @param {function(WebpackError=, T=): void} callback webpack error callback + * @param {function((WebpackError | null)=, T=): void} callback webpack error callback * @param {string} hook name of hook * @returns {Callback} generic callback */ diff --git a/lib/Module.js b/lib/Module.js index e311e58a4bf..a79e620393e 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -691,7 +691,7 @@ class Module extends DependenciesBlock { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/MultiCompiler.js b/lib/MultiCompiler.js index b28cb110dc8..80468380171 100644 --- a/lib/MultiCompiler.js +++ b/lib/MultiCompiler.js @@ -27,7 +27,7 @@ const ArrayQueue = require("./util/ArrayQueue"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 2d8b3736673..0032d41e290 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -310,7 +310,7 @@ class NormalModule extends Module { } // Info from Build - /** @type {WebpackError=} */ + /** @type {(WebpackError | null)=} */ this.error = null; /** @private @type {Source=} */ this._source = null; @@ -730,7 +730,7 @@ class NormalModule extends Module { * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system * @param {NormalModuleCompilationHooks} hooks the hooks - * @param {function(WebpackError=): void} callback callback function + * @param {function((WebpackError | null)=): void} callback callback function * @returns {void} */ _doBuild(options, compilation, resolver, fs, hooks, callback) { @@ -1236,7 +1236,7 @@ class NormalModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/RawModule.js b/lib/RawModule.js index dc923ce17b2..91342babc31 100644 --- a/lib/RawModule.js +++ b/lib/RawModule.js @@ -74,7 +74,7 @@ class RawModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/RuntimeModule.js b/lib/RuntimeModule.js index c1bd8a9d1d6..9c955d95d09 100644 --- a/lib/RuntimeModule.js +++ b/lib/RuntimeModule.js @@ -78,7 +78,7 @@ class RuntimeModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/asset/RawDataUrlModule.js b/lib/asset/RawDataUrlModule.js index 87f5e40ecf8..5d3ab32cecc 100644 --- a/lib/asset/RawDataUrlModule.js +++ b/lib/asset/RawDataUrlModule.js @@ -69,7 +69,7 @@ class RawDataUrlModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/cache/ResolverCachePlugin.js b/lib/cache/ResolverCachePlugin.js index 78d68ed7ad2..a0c0bbccbdb 100644 --- a/lib/cache/ResolverCachePlugin.js +++ b/lib/cache/ResolverCachePlugin.js @@ -106,7 +106,7 @@ class ResolverCachePlugin { * @param {Resolver} resolver the resolver * @param {Object} resolveContext context for resolving meta info * @param {Object} request the request info object - * @param {function(Error=, Object=): void} callback callback function + * @param {function((Error | null)=, Object=): void} callback callback function * @returns {void} */ const doRealResolve = ( diff --git a/lib/container/ContainerEntryModule.js b/lib/container/ContainerEntryModule.js index d27b767751a..555defe1260 100644 --- a/lib/container/ContainerEntryModule.js +++ b/lib/container/ContainerEntryModule.js @@ -84,7 +84,7 @@ class ContainerEntryModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/container/FallbackModule.js b/lib/container/FallbackModule.js index cc51cae27fa..2a918e75f40 100644 --- a/lib/container/FallbackModule.js +++ b/lib/container/FallbackModule.js @@ -76,7 +76,7 @@ class FallbackModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/container/RemoteModule.js b/lib/container/RemoteModule.js index b2bea8e33af..b1dfe1eca53 100644 --- a/lib/container/RemoteModule.js +++ b/lib/container/RemoteModule.js @@ -72,7 +72,7 @@ class RemoteModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/dependencies/LoaderPlugin.js b/lib/dependencies/LoaderPlugin.js index e22fef9fca1..cba0f59ebf2 100644 --- a/lib/dependencies/LoaderPlugin.js +++ b/lib/dependencies/LoaderPlugin.js @@ -16,7 +16,7 @@ const LoaderImportDependency = require("./LoaderImportDependency"); /** * @callback LoadModuleCallback - * @param {Error=} err error object + * @param {(Error | null)=} err error object * @param {string | Buffer=} source source code * @param {object=} map source map * @param {Module=} module loaded module if successful @@ -24,7 +24,7 @@ const LoaderImportDependency = require("./LoaderImportDependency"); /** * @callback ImportModuleCallback - * @param {Error=} err error object + * @param {(Error | null)=} err error object * @param {any=} exports exports of the evaluated module */ diff --git a/lib/hmr/LazyCompilationPlugin.js b/lib/hmr/LazyCompilationPlugin.js index 25b12c3c541..692f30af0d5 100644 --- a/lib/hmr/LazyCompilationPlugin.js +++ b/lib/hmr/LazyCompilationPlugin.js @@ -146,7 +146,7 @@ class LazyCompilationProxyModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/hmr/lazyCompilationBackend.js b/lib/hmr/lazyCompilationBackend.js index fce04238a9e..10c175aeca0 100644 --- a/lib/hmr/lazyCompilationBackend.js +++ b/lib/hmr/lazyCompilationBackend.js @@ -13,7 +13,7 @@ /** * @callback BackendHandler * @param {Compiler} compiler compiler - * @param {function(Error?, any?): void} callback callback + * @param {function((Error | null)=, any=): void} callback callback * @returns {void} */ diff --git a/lib/schemes/HttpUriPlugin.js b/lib/schemes/HttpUriPlugin.js index 36c35a3fbe0..e2c3aa9c27f 100644 --- a/lib/schemes/HttpUriPlugin.js +++ b/lib/schemes/HttpUriPlugin.js @@ -166,7 +166,7 @@ class Lockfile { /** * @template R * @param {function(function(Error=, R=): void): void} fn function - * @returns {function(function(Error=, R=): void): void} cached function + * @returns {function(function((Error | null)=, R=): void): void} cached function */ const cachedWithoutKey = fn => { let inFlight = false; @@ -201,10 +201,10 @@ const cachedWithoutKey = fn => { * @template R * @param {function(T, function(Error=, R=): void): void} fn function * @param {function(T, function(Error=, R=): void): void=} forceFn function for the second try - * @returns {(function(T, function(Error=, R=): void): void) & { force: function(T, function(Error=, R=): void): void }} cached function + * @returns {(function(T, function((Error | null)=, R=): void): void) & { force: function(T, function((Error | null)=, R=): void): void }} cached function */ const cachedWithKey = (fn, forceFn = fn) => { - /** @typedef {{ result?: R, error?: Error, callbacks?: (function(Error=, R=): void)[], force?: true }} CacheEntry */ + /** @typedef {{ result?: R, error?: Error, callbacks?: (function((Error | null)=, R=): void)[], force?: true }} CacheEntry */ /** @type {Map} */ const cache = new Map(); const resultFn = (arg, callback) => { @@ -358,7 +358,7 @@ class HttpUriPlugin { const getLockfile = cachedWithoutKey( /** - * @param {function(Error=, Lockfile=): void} callback callback + * @param {function((Error | null)=, Lockfile=): void} callback callback * @returns {void} */ callback => { @@ -465,7 +465,7 @@ class HttpUriPlugin { * * @param {string} url URL * @param {string} integrity integrity - * @param {function(Error=, { entry: LockfileEntry, content: Buffer, storeLock: boolean }=): void} callback callback + * @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer, storeLock: boolean }=): void} callback callback */ const resolveContent = (url, integrity, callback) => { const handleResult = (err, result) => { @@ -510,7 +510,7 @@ class HttpUriPlugin { /** * @param {string} url URL * @param {FetchResult} cachedResult result from cache - * @param {function(Error=, FetchResult=): void} callback callback + * @param {function((Error | null)=, FetchResult=): void} callback callback * @returns {void} */ const fetchContentRaw = (url, cachedResult, callback) => { @@ -662,7 +662,7 @@ class HttpUriPlugin { const fetchContent = cachedWithKey( /** * @param {string} url URL - * @param {function(Error=, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback + * @param {function((Error | null)=, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback * @returns {void} */ (url, callback) => { cache.get(url, null, (err, cachedResult) => { @@ -693,7 +693,7 @@ class HttpUriPlugin { const getInfo = cachedWithKey( /** * @param {string} url the url - * @param {function(Error=, { entry: LockfileEntry, content: Buffer }=): void} callback callback + * @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer }=): void} callback callback * @returns {void} */ (url, callback) => { diff --git a/lib/sharing/ConsumeSharedModule.js b/lib/sharing/ConsumeSharedModule.js index 675fa6cf4eb..b0c8f3cf6a6 100644 --- a/lib/sharing/ConsumeSharedModule.js +++ b/lib/sharing/ConsumeSharedModule.js @@ -108,7 +108,7 @@ class ConsumeSharedModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/sharing/ProvideSharedModule.js b/lib/sharing/ProvideSharedModule.js index bbb71ce39e9..eded5809774 100644 --- a/lib/sharing/ProvideSharedModule.js +++ b/lib/sharing/ProvideSharedModule.js @@ -72,7 +72,7 @@ class ProvideSharedModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/sharing/utils.js b/lib/sharing/utils.js index 6f89da05385..aefe6f02409 100644 --- a/lib/sharing/utils.js +++ b/lib/sharing/utils.js @@ -22,7 +22,7 @@ exports.isRequiredVersion = str => { * @param {InputFileSystem} fs file system * @param {string} directory directory to start looking into * @param {string[]} descriptionFiles possible description filenames - * @param {function(Error=, {data: object, path: string}=): void} callback callback + * @param {function((Error | null)=, {data: object, path: string}=): void} callback callback */ const getDescriptionFile = (fs, directory, descriptionFiles, callback) => { let i = 0; diff --git a/types.d.ts b/types.d.ts index d438d5edaf6..51ee4ab3d91 100644 --- a/types.d.ts +++ b/types.d.ts @@ -678,13 +678,16 @@ declare interface CallbackAsyncQueue { (err?: WebpackError, result?: T): any; } declare interface CallbackCache { - (err?: WebpackError, result?: T): void; + (err?: null | WebpackError, result?: T): void; } -declare interface CallbackFunction { +declare interface CallbackFunction_1 { (err?: Error, result?: T): any; } +declare interface CallbackFunction_2 { + (err?: null | Error, result?: T): any; +} declare interface CallbackNormalErrorCache { - (err?: Error, result?: T): void; + (err?: null | Error, result?: T): void; } declare interface CallbackWebpack { (err?: Error, stats?: T): void; @@ -1541,7 +1544,7 @@ declare class Compilation { getLogger(name: string | (() => string)): WebpackLogger; addModule( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; /** @@ -1559,21 +1562,21 @@ declare class Compilation { */ buildModule( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; processModuleDependencies( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; processModuleDependenciesNonRecursive(module: Module): void; handleModuleCreation( __0: HandleModuleCreationOptions, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addModuleChain( context: string, dependency: Dependency, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addModuleTree( __0: { @@ -1590,27 +1593,27 @@ declare class Compilation { */ contextInfo?: Partial; }, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addEntry( context: string, entry: Dependency, optionsOrName: string | EntryOptions, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; addInclude( context: string, dependency: Dependency, options: EntryOptions, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; rebuildModule( module: Module, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; finish(callback?: any): void; unseal(): void; - seal(callback: (err?: WebpackError) => void): void; + seal(callback: (err?: null | WebpackError) => void): void; reportDependencyErrorsAndWarnings( module: Module, blocks: DependenciesBlock[] @@ -1698,7 +1701,7 @@ declare class Compilation { clearAssets(): void; createModuleAssets(): void; getRenderManifest(options: RenderManifestOptions): RenderManifestEntry[]; - createChunkAssets(callback: (err?: WebpackError) => void): void; + createChunkAssets(callback: (err?: null | WebpackError) => void): void; getPath( filename: string | ((arg0: PathData, arg1?: AssetInfo) => string), data?: PathData @@ -1734,17 +1737,20 @@ declare class Compilation { executeModule( module: Module, options: ExecuteModuleOptions, - callback: (err?: WebpackError, result?: ExecuteModuleResult) => void + callback: (err?: null | WebpackError, result?: ExecuteModuleResult) => void ): void; checkConstraints(): void; factorizeModule: { ( options: FactorizeModuleOptions & { factoryResult?: false }, - callback: (err?: WebpackError, result?: Module) => void + callback: (err?: null | WebpackError, result?: Module) => void ): void; ( options: FactorizeModuleOptions & { factoryResult: true }, - callback: (err?: WebpackError, result?: ModuleFactoryResult) => void + callback: ( + err?: null | WebpackError, + result?: ModuleFactoryResult + ) => void ): void; }; @@ -1939,15 +1945,25 @@ declare class Compiler { watchMode: boolean; getCache(name: string): CacheFacade; getInfrastructureLogger(name: string | (() => string)): WebpackLogger; - watch(watchOptions: WatchOptions, handler: CallbackFunction): Watching; - run(callback: CallbackFunction): void; + watch( + watchOptions: WatchOptions, + handler: CallbackFunction_2 + ): Watching; + run(callback: CallbackFunction_2): void; runAsChild( - callback: (err?: Error, entries?: Chunk[], compilation?: Compilation) => any + callback: ( + err?: null | Error, + entries?: Chunk[], + compilation?: Compilation + ) => any ): void; purgeInputFileSystem(): void; - emitAssets(compilation: Compilation, callback: CallbackFunction): void; - emitRecords(callback: CallbackFunction): void; - readRecords(callback: CallbackFunction): void; + emitAssets( + compilation: Compilation, + callback: CallbackFunction_2 + ): void; + emitRecords(callback: CallbackFunction_2): void; + readRecords(callback: CallbackFunction_2): void; createChildCompiler( compilation: Compilation, compilerName: string, @@ -1964,8 +1980,8 @@ declare class Compiler { normalModuleFactory: NormalModuleFactory; contextModuleFactory: ContextModuleFactory; }; - compile(callback: CallbackFunction): void; - close(callback: CallbackFunction): void; + compile(callback: CallbackFunction_2): void; + close(callback: CallbackFunction_2): void; } declare class ConcatSource extends Source { constructor(...args: (string | Source)[]); @@ -2475,7 +2491,10 @@ declare abstract class ContextModuleFactory extends ModuleFactory { resolveDependencies( fs: InputFileSystem, options: ContextModuleOptions, - callback: (err?: Error, dependencies?: ContextElementDependency[]) => any + callback: ( + err?: null | Error, + dependencies?: ContextElementDependency[] + ) => any ): void; } @@ -4117,40 +4136,43 @@ declare abstract class FileSystemInfo { getFileTimestamp( path: string, callback: ( - arg0?: WebpackError, + arg0?: null | WebpackError, arg1?: null | FileSystemInfoEntry | "ignore" ) => void ): void; getContextTimestamp( path: string, callback: ( - arg0?: WebpackError, + arg0?: null | WebpackError, arg1?: null | "ignore" | ResolvedContextFileSystemInfoEntry ) => void ): void; getFileHash( path: string, - callback: (arg0?: WebpackError, arg1?: string) => void + callback: (arg0?: null | WebpackError, arg1?: string) => void ): void; getContextHash( path: string, - callback: (arg0?: WebpackError, arg1?: string) => void + callback: (arg0?: null | WebpackError, arg1?: string) => void ): void; getContextTsh( path: string, callback: ( - arg0?: WebpackError, + arg0?: null | WebpackError, arg1?: ResolvedContextTimestampAndHash ) => void ): void; resolveBuildDependencies( context: string, deps: Iterable, - callback: (arg0?: Error, arg1?: ResolveBuildDependenciesResult) => void + callback: ( + arg0?: null | Error, + arg1?: ResolveBuildDependenciesResult + ) => void ): void; checkResolveResultsValid( resolveResults: Map, - callback: (arg0?: Error, arg1?: boolean) => void + callback: (arg0?: null | Error, arg1?: boolean) => void ): void; createSnapshot( startTime: number, @@ -4167,12 +4189,12 @@ declare abstract class FileSystemInfo { */ timestamp?: boolean; }, - callback: (arg0?: WebpackError, arg1?: Snapshot) => void + callback: (arg0?: null | WebpackError, arg1?: null | Snapshot) => void ): void; mergeSnapshots(snapshot1: Snapshot, snapshot2: Snapshot): Snapshot; checkSnapshotValid( snapshot: Snapshot, - callback: (arg0?: WebpackError, arg1?: boolean) => void + callback: (arg0?: null | WebpackError, arg1?: boolean) => void ): void; getDeprecatedFileTimestamps(): Map; getDeprecatedContextTimestamps(): Map; @@ -6217,7 +6239,7 @@ declare interface LoaderPluginLoaderContext { importModule( request: string, options: ImportModuleOptions, - callback: (err?: Error, exports?: any) => any + callback: (err?: null | Error, exports?: any) => any ): void; importModule(request: string, options?: ImportModuleOptions): Promise; } @@ -6300,6 +6322,7 @@ declare interface LoaderRunnerLoaderContext { /** * An array of all the loaders. It is writeable in the pitch phase. * loaders = [{request: string, path: string, query: string, module: function}] + * * In the example: * [ * { request: "/abc/loader1.js?xyz", @@ -6583,7 +6606,7 @@ declare class Module extends DependenciesBlock { hasReasons(moduleGraph: ModuleGraph, runtime: RuntimeSpec): boolean; needBuild( context: NeedBuildContext, - callback: (arg0?: WebpackError, arg1?: boolean) => void + callback: (arg0?: null | WebpackError, arg1?: boolean) => void ): void; needRebuild( fileTimestamps: Map, @@ -7163,19 +7186,19 @@ declare class MultiCompiler { intermediateFileSystem: IntermediateFileSystem; getInfrastructureLogger(name?: any): WebpackLogger; setDependencies(compiler: Compiler, dependencies: string[]): void; - validateDependencies(callback: CallbackFunction): boolean; + validateDependencies(callback: CallbackFunction_2): boolean; runWithDependencies( compilers: Compiler[], - fn: (compiler: Compiler, callback: CallbackFunction) => any, - callback: CallbackFunction + fn: (compiler: Compiler, callback: CallbackFunction_2) => any, + callback: CallbackFunction_2 ): void; watch( watchOptions: WatchOptions | WatchOptions[], - handler: CallbackFunction + handler: CallbackFunction_2 ): MultiWatching; - run(callback: CallbackFunction): void; + run(callback: CallbackFunction_2): void; purgeInputFileSystem(): void; - close(callback: CallbackFunction): void; + close(callback: CallbackFunction_2): void; } declare interface MultiCompilerOptions { /** @@ -7197,7 +7220,7 @@ declare abstract class MultiWatching { invalidate(callback?: any): void; suspend(): void; resume(): void; - close(callback: CallbackFunction): void; + close(callback: CallbackFunction_1): void; } declare class NamedChunkIdsPlugin { constructor(options?: any); @@ -7452,7 +7475,7 @@ declare class NormalModule extends Module { resourceResolveData?: Record; matchResource?: string; loaders: LoaderItem[]; - error?: WebpackError; + error?: null | WebpackError; restoreFromUnsafeCache( unsafeCacheData?: any, normalModuleFactory?: any @@ -11862,8 +11885,8 @@ declare interface WatcherInfo { declare abstract class Watching { startTime: null | number; invalid: boolean; - handler: CallbackFunction; - callbacks: CallbackFunction[]; + handler: CallbackFunction_1; + callbacks: CallbackFunction_1[]; closed: boolean; suspended: boolean; blocked: boolean; @@ -11899,10 +11922,10 @@ declare abstract class Watching { dirs: Iterable, missing: Iterable ): void; - invalidate(callback?: CallbackFunction): void; + invalidate(callback?: CallbackFunction_1): void; suspend(): void; resume(): void; - close(callback: CallbackFunction): void; + close(callback: CallbackFunction_1): void; } declare abstract class WeakTupleMap { set(...args: [T, ...V[]]): void; From 49e9caeb8277ab6bf902c974916210005d3ddc0b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Dec 2021 03:04:50 +0000 Subject: [PATCH 11/32] chore(deps): bump acorn from 8.6.0 to 8.7.0 Bumps [acorn](https://github.com/acornjs/acorn) from 8.6.0 to 8.7.0. - [Release notes](https://github.com/acornjs/acorn/releases) - [Commits](https://github.com/acornjs/acorn/compare/8.6.0...8.7.0) --- updated-dependencies: - dependency-name: acorn dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 691917fccbb..0411ede51a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1228,9 +1228,9 @@ acorn@^7.1.1, acorn@^7.4.0: integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== acorn@^8.2.4, acorn@^8.4.1: - version "8.6.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.6.0.tgz#e3692ba0eb1a0c83eaa4f37f5fa7368dd7142895" - integrity sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw== + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== agent-base@6: version "6.0.2" From 759851cb4500ac29fdef4a69c65f99602a72900c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 31 Dec 2021 03:02:51 +0000 Subject: [PATCH 12/32] chore(deps-dev): bump @types/jest from 27.0.2 to 27.4.0 Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 27.0.2 to 27.4.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) --- updated-dependencies: - dependency-name: "@types/jest" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 691917fccbb..c1943d2eb56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -925,9 +925,9 @@ "@types/istanbul-lib-report" "*" "@types/jest@^27.0.2": - version "27.0.2" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.0.2.tgz#ac383c4d4aaddd29bbf2b916d8d105c304a5fcd7" - integrity sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA== + version "27.4.0" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.4.0.tgz#037ab8b872067cae842a320841693080f9cb84ed" + integrity sha512-gHl8XuC1RZ8H2j5sHv/JqsaxXkDDM9iDOgu0Wp8sjs4u/snb2PVehyWXJPr+ORA0RPpgw231mnutWI1+0hgjIQ== dependencies: jest-diff "^27.0.0" pretty-format "^27.0.0" From 964fb971ddb26aaab6a0e8f88f0434f43d4935d2 Mon Sep 17 00:00:00 2001 From: Mark Molinaro Date: Mon, 10 Jan 2022 15:15:21 -0800 Subject: [PATCH 13/32] fix: context regex non-deterministic with | --- lib/ContextModule.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/ContextModule.js b/lib/ContextModule.js index a1aca892184..aa28f116c13 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -149,12 +149,9 @@ class ContextModule extends Module { this.resolveDependencies = undefined; } - prettyRegExp(regexString) { - // remove the "/" at the front and the beginning - // "/foo/" -> "foo" - return regexString - .substring(1, regexString.length - 1) - .replace(/!/g, "%21"); + prettyRegExp(regexString, stripSlash = true) { + const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C"); + return stripSlash ? str.substring(1, str.length - 1) : str; } _createIdentifier() { @@ -175,13 +172,19 @@ class ContextModule extends Module { identifier += `|${this.options.addon}`; } if (this.options.regExp) { - identifier += `|${this.options.regExp}`; + identifier += `|${this.prettyRegExp(this.options.regExp, false)}`; } if (this.options.include) { - identifier += `|include: ${this.options.include}`; + identifier += `|include: ${this.prettyRegExp( + this.options.include, + false + )}`; } if (this.options.exclude) { - identifier += `|exclude: ${this.options.exclude}`; + identifier += `|exclude: ${this.prettyRegExp( + this.options.exclude, + false + )}`; } if (this.options.referencedExports) { identifier += `|referencedExports: ${JSON.stringify( @@ -231,13 +234,13 @@ class ContextModule extends Module { identifier += ` ${requestShortener.shorten(this.options.addon)}`; } if (this.options.regExp) { - identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`; + identifier += ` ${this.prettyRegExp(this.options.regExp)}`; } if (this.options.include) { - identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`; + identifier += ` include: ${this.prettyRegExp(this.options.include)}`; } if (this.options.exclude) { - identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`; + identifier += ` exclude: ${this.prettyRegExp(this.options.exclude)}`; } if (this.options.referencedExports) { identifier += ` referencedExports: ${this.options.referencedExports @@ -286,13 +289,13 @@ class ContextModule extends Module { )}`; } if (this.options.regExp) { - identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`; + identifier += ` ${this.prettyRegExp(this.options.regExp)}`; } if (this.options.include) { - identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`; + identifier += ` include: ${this.prettyRegExp(this.options.include)}`; } if (this.options.exclude) { - identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`; + identifier += ` exclude: ${this.prettyRegExp(this.options.exclude)}`; } if (this.options.referencedExports) { identifier += ` referencedExports: ${this.options.referencedExports From 4faa5c7203d0381abb83fdda4de456d937cb09a5 Mon Sep 17 00:00:00 2001 From: Mark Molinaro Date: Mon, 10 Jan 2022 15:27:42 -0800 Subject: [PATCH 14/32] add test --- lib/ContextModule.js | 20 ++++++++++---------- test/ContextModule.unittest.js | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 test/ContextModule.unittest.js diff --git a/lib/ContextModule.js b/lib/ContextModule.js index aa28f116c13..1af04c7d3ea 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -149,7 +149,7 @@ class ContextModule extends Module { this.resolveDependencies = undefined; } - prettyRegExp(regexString, stripSlash = true) { + _prettyRegExp(regexString, stripSlash = true) { const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C"); return stripSlash ? str.substring(1, str.length - 1) : str; } @@ -172,16 +172,16 @@ class ContextModule extends Module { identifier += `|${this.options.addon}`; } if (this.options.regExp) { - identifier += `|${this.prettyRegExp(this.options.regExp, false)}`; + identifier += `|${this._prettyRegExp(this.options.regExp, false)}`; } if (this.options.include) { - identifier += `|include: ${this.prettyRegExp( + identifier += `|include: ${this._prettyRegExp( this.options.include, false )}`; } if (this.options.exclude) { - identifier += `|exclude: ${this.prettyRegExp( + identifier += `|exclude: ${this._prettyRegExp( this.options.exclude, false )}`; @@ -234,13 +234,13 @@ class ContextModule extends Module { identifier += ` ${requestShortener.shorten(this.options.addon)}`; } if (this.options.regExp) { - identifier += ` ${this.prettyRegExp(this.options.regExp)}`; + identifier += ` ${this._prettyRegExp(this.options.regExp)}`; } if (this.options.include) { - identifier += ` include: ${this.prettyRegExp(this.options.include)}`; + identifier += ` include: ${this._prettyRegExp(this.options.include)}`; } if (this.options.exclude) { - identifier += ` exclude: ${this.prettyRegExp(this.options.exclude)}`; + identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`; } if (this.options.referencedExports) { identifier += ` referencedExports: ${this.options.referencedExports @@ -289,13 +289,13 @@ class ContextModule extends Module { )}`; } if (this.options.regExp) { - identifier += ` ${this.prettyRegExp(this.options.regExp)}`; + identifier += ` ${this._prettyRegExp(this.options.regExp)}`; } if (this.options.include) { - identifier += ` include: ${this.prettyRegExp(this.options.include)}`; + identifier += ` include: ${this._prettyRegExp(this.options.include)}`; } if (this.options.exclude) { - identifier += ` exclude: ${this.prettyRegExp(this.options.exclude)}`; + identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`; } if (this.options.referencedExports) { identifier += ` referencedExports: ${this.options.referencedExports diff --git a/test/ContextModule.unittest.js b/test/ContextModule.unittest.js new file mode 100644 index 00000000000..4d3e691b111 --- /dev/null +++ b/test/ContextModule.unittest.js @@ -0,0 +1,22 @@ +"use strict"; + +const ContextModule = require("../lib/ContextModule"); + +describe("contextModule", () => { + let contextModule; + let request; + beforeEach(() => { + request = "/some/request"; + }); + describe("#identifier", () => { + it("returns an safe identifier for this module", () => { + contextModule = new ContextModule(() => {}, { + type: "javascript/auto", + request, + mode: "lazy", + regExp: /a|b/ + }); + expect(contextModule.identifier()).toContain("/a%7Cb/"); + }); + }); +}); From 0105d7d3e6a2d1a0bb18b7cd9fdf83ec78121cc7 Mon Sep 17 00:00:00 2001 From: Asriel Yu Date: Tue, 11 Jan 2022 19:41:14 +0800 Subject: [PATCH 15/32] add omitted types should include null --- lib/MultiWatching.js | 2 +- lib/Watching.js | 2 +- lib/util/AsyncQueue.js | 2 +- types.d.ts | 49 +++++++++++++++++------------------------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/lib/MultiWatching.js b/lib/MultiWatching.js index 5314569c2c3..2bbd5365a1c 100644 --- a/lib/MultiWatching.js +++ b/lib/MultiWatching.js @@ -13,7 +13,7 @@ const asyncLib = require("neo-async"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ diff --git a/lib/Watching.js b/lib/Watching.js index f92b55119e7..ca6039ad27a 100644 --- a/lib/Watching.js +++ b/lib/Watching.js @@ -15,7 +15,7 @@ const Stats = require("./Stats"); /** * @template T * @callback Callback - * @param {Error=} err + * @param {(Error | null)=} err * @param {T=} result */ diff --git a/lib/util/AsyncQueue.js b/lib/util/AsyncQueue.js index 9191b2e6c2b..604337d1cec 100644 --- a/lib/util/AsyncQueue.js +++ b/lib/util/AsyncQueue.js @@ -19,7 +19,7 @@ let inHandleResult = 0; /** * @template T * @callback Callback - * @param {WebpackError=} err + * @param {(WebpackError | null)=} err * @param {T=} result */ diff --git a/types.d.ts b/types.d.ts index 51ee4ab3d91..16f4e414db6 100644 --- a/types.d.ts +++ b/types.d.ts @@ -675,15 +675,12 @@ declare interface CallExpressionInfo { getMembers: () => string[]; } declare interface CallbackAsyncQueue { - (err?: WebpackError, result?: T): any; + (err?: null | WebpackError, result?: T): any; } declare interface CallbackCache { (err?: null | WebpackError, result?: T): void; } -declare interface CallbackFunction_1 { - (err?: Error, result?: T): any; -} -declare interface CallbackFunction_2 { +declare interface CallbackFunction { (err?: null | Error, result?: T): any; } declare interface CallbackNormalErrorCache { @@ -1945,11 +1942,8 @@ declare class Compiler { watchMode: boolean; getCache(name: string): CacheFacade; getInfrastructureLogger(name: string | (() => string)): WebpackLogger; - watch( - watchOptions: WatchOptions, - handler: CallbackFunction_2 - ): Watching; - run(callback: CallbackFunction_2): void; + watch(watchOptions: WatchOptions, handler: CallbackFunction): Watching; + run(callback: CallbackFunction): void; runAsChild( callback: ( err?: null | Error, @@ -1958,12 +1952,9 @@ declare class Compiler { ) => any ): void; purgeInputFileSystem(): void; - emitAssets( - compilation: Compilation, - callback: CallbackFunction_2 - ): void; - emitRecords(callback: CallbackFunction_2): void; - readRecords(callback: CallbackFunction_2): void; + emitAssets(compilation: Compilation, callback: CallbackFunction): void; + emitRecords(callback: CallbackFunction): void; + readRecords(callback: CallbackFunction): void; createChildCompiler( compilation: Compilation, compilerName: string, @@ -1980,8 +1971,8 @@ declare class Compiler { normalModuleFactory: NormalModuleFactory; contextModuleFactory: ContextModuleFactory; }; - compile(callback: CallbackFunction_2): void; - close(callback: CallbackFunction_2): void; + compile(callback: CallbackFunction): void; + close(callback: CallbackFunction): void; } declare class ConcatSource extends Source { constructor(...args: (string | Source)[]); @@ -7186,19 +7177,19 @@ declare class MultiCompiler { intermediateFileSystem: IntermediateFileSystem; getInfrastructureLogger(name?: any): WebpackLogger; setDependencies(compiler: Compiler, dependencies: string[]): void; - validateDependencies(callback: CallbackFunction_2): boolean; + validateDependencies(callback: CallbackFunction): boolean; runWithDependencies( compilers: Compiler[], - fn: (compiler: Compiler, callback: CallbackFunction_2) => any, - callback: CallbackFunction_2 + fn: (compiler: Compiler, callback: CallbackFunction) => any, + callback: CallbackFunction ): void; watch( watchOptions: WatchOptions | WatchOptions[], - handler: CallbackFunction_2 + handler: CallbackFunction ): MultiWatching; - run(callback: CallbackFunction_2): void; + run(callback: CallbackFunction): void; purgeInputFileSystem(): void; - close(callback: CallbackFunction_2): void; + close(callback: CallbackFunction): void; } declare interface MultiCompilerOptions { /** @@ -7220,7 +7211,7 @@ declare abstract class MultiWatching { invalidate(callback?: any): void; suspend(): void; resume(): void; - close(callback: CallbackFunction_1): void; + close(callback: CallbackFunction): void; } declare class NamedChunkIdsPlugin { constructor(options?: any); @@ -11885,8 +11876,8 @@ declare interface WatcherInfo { declare abstract class Watching { startTime: null | number; invalid: boolean; - handler: CallbackFunction_1; - callbacks: CallbackFunction_1[]; + handler: CallbackFunction; + callbacks: CallbackFunction[]; closed: boolean; suspended: boolean; blocked: boolean; @@ -11922,10 +11913,10 @@ declare abstract class Watching { dirs: Iterable, missing: Iterable ): void; - invalidate(callback?: CallbackFunction_1): void; + invalidate(callback?: CallbackFunction): void; suspend(): void; resume(): void; - close(callback: CallbackFunction_1): void; + close(callback: CallbackFunction): void; } declare abstract class WeakTupleMap { set(...args: [T, ...V[]]): void; From 01ce7411adf0edb422bc21caa981282a966b5eed Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 12 Jan 2022 17:42:22 +0300 Subject: [PATCH 16/32] fix: cache for CreateScriptUrlDependency --- lib/dependencies/CreateScriptUrlDependency.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/dependencies/CreateScriptUrlDependency.js b/lib/dependencies/CreateScriptUrlDependency.js index 08890144a60..30b39b76d52 100644 --- a/lib/dependencies/CreateScriptUrlDependency.js +++ b/lib/dependencies/CreateScriptUrlDependency.js @@ -25,6 +25,18 @@ class CreateScriptUrlDependency extends NullDependency { get type() { return "create script url"; } + + serialize(context) { + const { write } = context; + write(this.range); + super.serialize(context); + } + + deserialize(context) { + const { read } = context; + this.range = read(); + super.deserialize(context); + } } CreateScriptUrlDependency.Template = class CreateScriptUrlDependencyTemplate extends ( From f21930b588db5e7a5200439bcb41e7bb8f432106 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 12 Jan 2022 19:23:16 +0300 Subject: [PATCH 17/32] fix: handle content from loaders --- lib/asset/AssetGenerator.js | 58 +++++++++---------- .../asset-modules/data-url/index.js | 2 + .../asset-modules/data-url/loader.js | 4 ++ .../asset-modules/data-url/webpack.config.js | 5 ++ .../input-data-url-encoding/index.js | 2 +- 5 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 test/configCases/asset-modules/data-url/loader.js diff --git a/lib/asset/AssetGenerator.js b/lib/asset/AssetGenerator.js index 16132e2af8a..777eb49ddf7 100644 --- a/lib/asset/AssetGenerator.js +++ b/lib/asset/AssetGenerator.js @@ -74,6 +74,34 @@ const mergeRelatedInfo = (a, b) => { return result; }; +const encodeDataUri = (encoding, source) => { + let encodedContent; + + switch (encoding) { + case "base64": { + encodedContent = source.buffer().toString("base64"); + break; + } + case false: { + const content = source.source(); + + if (typeof content !== "string") { + encodedContent = content.toString("utf-8"); + } + + encodedContent = encodeURIComponent(encodedContent).replace( + /[!'()*]/g, + character => "%" + character.codePointAt(0).toString(16) + ); + break; + } + default: + throw new Error(`Unsupported encoding '${encoding}'`); + } + + return encodedContent; +}; + const JS_TYPES = new Set(["javascript"]); const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]); @@ -157,35 +185,7 @@ class AssetGenerator extends Generator { ); } - let encodedContent; - if ( - module.resourceResolveData && - module.resourceResolveData.encoding === encoding - ) { - encodedContent = module.resourceResolveData.encodedContent; - } else { - switch (encoding) { - case "base64": { - encodedContent = originalSource.buffer().toString("base64"); - break; - } - case false: { - const content = originalSource.source(); - - if (typeof content !== "string") { - encodedContent = content.toString("utf-8"); - } - - encodedContent = encodeURIComponent(encodedContent).replace( - /[!'()*]/g, - character => "%" + character.codePointAt(0).toString(16) - ); - break; - } - default: - throw new Error(`Unsupported encoding '${encoding}'`); - } - } + const encodedContent = encodeDataUri(encoding, originalSource); encodedSource = `data:${mimeType}${ encoding ? `;${encoding}` : "" diff --git a/test/configCases/asset-modules/data-url/index.js b/test/configCases/asset-modules/data-url/index.js index 2011c18894f..c45262a35f7 100644 --- a/test/configCases/asset-modules/data-url/index.js +++ b/test/configCases/asset-modules/data-url/index.js @@ -5,6 +5,7 @@ import dataSvg from "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53M const urlSvg = new URL( "data:image/svg;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPgo=" ); +const helloWorld = new URL("data:text/plain,Hello", import.meta.url); it("should generate various data-url types", () => { expect(png).toContain("data:image/png;base64,"); @@ -12,4 +13,5 @@ it("should generate various data-url types", () => { expect(jpg).toContain("data:image/jpeg;base64,"); expect(dataSvg).toContain("data:image/svg+xml;base64,"); expect(urlSvg.href).toContain("data:image/svg;base64,"); + expect(helloWorld.href).toContain("data:text/plain,Hello%2C%20World%21"); }); diff --git a/test/configCases/asset-modules/data-url/loader.js b/test/configCases/asset-modules/data-url/loader.js new file mode 100644 index 00000000000..c5048a9c3df --- /dev/null +++ b/test/configCases/asset-modules/data-url/loader.js @@ -0,0 +1,4 @@ +/** @type {import("../../../../").LoaderDefinition<{ f(): any }>} */ +module.exports = function (source) { + return `${source}, World!`; +}; diff --git a/test/configCases/asset-modules/data-url/webpack.config.js b/test/configCases/asset-modules/data-url/webpack.config.js index 19be170b1e7..ab9e619ce2f 100644 --- a/test/configCases/asset-modules/data-url/webpack.config.js +++ b/test/configCases/asset-modules/data-url/webpack.config.js @@ -19,6 +19,11 @@ module.exports = { maxSize: Infinity } } + }, + { + mimetype: "text/plain", + type: "asset/inline", + loader: "./loader" } ] } diff --git a/test/configCases/asset-modules/input-data-url-encoding/index.js b/test/configCases/asset-modules/input-data-url-encoding/index.js index 561c29d9516..3393e4c7f26 100644 --- a/test/configCases/asset-modules/input-data-url-encoding/index.js +++ b/test/configCases/asset-modules/input-data-url-encoding/index.js @@ -4,7 +4,7 @@ it("should keep original encoding", () => { import.meta.url ); expect(url.href).toBe( - "data:image/svg+xml;p=1;q=2,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke=\"%23343a40\" stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e" + "data:image/svg+xml;p=1;q=2,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2016%2016%27%3E%3Cpath%20fill%3D%27none%27%20stroke%3D%22%23343a40%22%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%20stroke-width%3D%272%27%20d%3D%27M2%205l6%206%206-6%27%2F%3E%3C%2Fsvg%3E" ); }); From 718bd9bc1e8621146f7466e99cbab90b75a95b14 Mon Sep 17 00:00:00 2001 From: Mark Molinaro Date: Thu, 13 Jan 2022 01:18:17 -0800 Subject: [PATCH 18/32] Fix ProfilingPlugin for watch scenarios --- lib/debug/ProfilingPlugin.js | 8 +++----- test/WatchTestCases.template.js | 2 +- test/watchCases/plugins/profiling-plugin/0/index.js | 3 +++ test/watchCases/plugins/profiling-plugin/1/index.js | 3 +++ test/watchCases/plugins/profiling-plugin/deprecations.js | 3 +++ .../watchCases/plugins/profiling-plugin/webpack.config.js | 6 ++++++ 6 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 test/watchCases/plugins/profiling-plugin/0/index.js create mode 100644 test/watchCases/plugins/profiling-plugin/1/index.js create mode 100644 test/watchCases/plugins/profiling-plugin/deprecations.js create mode 100644 test/watchCases/plugins/profiling-plugin/webpack.config.js diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index 8f8dcaac814..a61bd5b05e1 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -123,9 +123,7 @@ class Profiler { * @returns {Trace} The trace object */ const createTrace = (fs, outputPath) => { - const trace = new Tracer({ - noStream: true - }); + const trace = new Tracer(); const profiler = new Profiler(inspector); if (/\/|\\/.test(outputPath)) { const dirPath = dirname(fs, outputPath); @@ -173,6 +171,7 @@ const createTrace = (fs, outputPath) => { counter, profiler, end: callback => { + trace.push("]"); // Wait until the write stream finishes. fsStream.on("close", () => { callback(); @@ -242,10 +241,10 @@ class ProfilingPlugin { stage: Infinity }, (stats, callback) => { + if (compiler.watchMode) return callback(); tracer.profiler.stopProfiling().then(parsedResults => { if (parsedResults === undefined) { tracer.profiler.destroy(); - tracer.trace.flush(); tracer.end(callback); return; } @@ -293,7 +292,6 @@ class ProfilingPlugin { }); tracer.profiler.destroy(); - tracer.trace.flush(); tracer.end(callback); }); } diff --git a/test/WatchTestCases.template.js b/test/WatchTestCases.template.js index a971f3657fd..68dbce53a75 100644 --- a/test/WatchTestCases.template.js +++ b/test/WatchTestCases.template.js @@ -396,7 +396,7 @@ const describeCases = config => { done ) ) { - compiler.close(); + compiler.close(() => {}); return; } compiler.close(done); diff --git a/test/watchCases/plugins/profiling-plugin/0/index.js b/test/watchCases/plugins/profiling-plugin/0/index.js new file mode 100644 index 00000000000..cecdb3b9c59 --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/0/index.js @@ -0,0 +1,3 @@ +it("compiles", function() { + expect(WATCH_STEP).toBe("0"); +}) \ No newline at end of file diff --git a/test/watchCases/plugins/profiling-plugin/1/index.js b/test/watchCases/plugins/profiling-plugin/1/index.js new file mode 100644 index 00000000000..5e1eb9ebdba --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/1/index.js @@ -0,0 +1,3 @@ +it("should not crash on recompile", function() { + expect(WATCH_STEP).toBe("1"); +}) diff --git a/test/watchCases/plugins/profiling-plugin/deprecations.js b/test/watchCases/plugins/profiling-plugin/deprecations.js new file mode 100644 index 00000000000..dee16addc3f --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/deprecations.js @@ -0,0 +1,3 @@ +module.exports = [ + { code: /DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK/ } +]; diff --git a/test/watchCases/plugins/profiling-plugin/webpack.config.js b/test/watchCases/plugins/profiling-plugin/webpack.config.js new file mode 100644 index 00000000000..3d258a435b9 --- /dev/null +++ b/test/watchCases/plugins/profiling-plugin/webpack.config.js @@ -0,0 +1,6 @@ +var webpack = require("../../../../"); + +/** @type {import("../../../../").Configuration} */ +module.exports = { + plugins: [new webpack.debug.ProfilingPlugin()] +}; From 3edda4d5f9edf0ed6450856c5546bfc341c39119 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 14 Jan 2022 11:11:06 +0100 Subject: [PATCH 19/32] fix css hmr edge cases insert css into old location only look for rel="stylesheet" tags --- examples/css/README.md | 15 ++++++++------- lib/css/CssLoadingRuntimeModule.js | 7 ++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/css/README.md b/examples/css/README.md index fb3b35f3464..08b76f663b4 100644 --- a/examples/css/README.md +++ b/examples/css/README.md @@ -208,7 +208,7 @@ module.exports = __webpack_require__.p + "89a353e9c515885abd8e.png"; /******/ var links = document.getElementsByTagName("link"); /******/ for(var i = 0; i < links.length; i++) { /******/ var l = links[i]; -/******/ if(l.href == url || l.getAttribute("href") == url || l.getAttribute("data-webpack") == uniqueName + ":" + key) { link = l; break; } +/******/ if(l.rel == "stylesheet" && (l.href == url || l.getAttribute("href") == url || l.getAttribute("data-webpack") == uniqueName + ":" + key)) { link = l; break; } /******/ } /******/ if(!done) return link; /******/ @@ -233,6 +233,7 @@ module.exports = __webpack_require__.p + "89a353e9c515885abd8e.png"; /******/ link.onerror = onLinkComplete.bind(null, link.onerror); /******/ link.onload = onLinkComplete.bind(null, link.onload); /******/ } else onLinkComplete(undefined, { type: 'load', target: link }); +/******/ /******/ needAttach && document.head.appendChild(link); /******/ return link; /******/ }; @@ -486,12 +487,12 @@ head{--webpack-app-1:_7;} ## Unoptimized ``` -assets by chunk 16.8 KiB (name: main) - asset output.js 16.4 KiB [emitted] (name: main) +assets by chunk 16.9 KiB (name: main) + asset output.js 16.5 KiB [emitted] (name: main) asset output.css 385 bytes [emitted] (name: main) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: images/file.png] (auxiliary name: main) asset 1.output.css 49 bytes [emitted] -Entrypoint main 16.8 KiB (14.6 KiB) = output.js 16.4 KiB output.css 385 bytes 1 auxiliary asset +Entrypoint main 16.9 KiB (14.6 KiB) = output.js 16.5 KiB output.css 385 bytes 1 auxiliary asset chunk (runtime: main) output.js, output.css (main) 218 bytes (javascript) 335 bytes (css) 14.6 KiB (asset) 42 bytes (css-import) 10 KiB (runtime) [entry] [rendered] > ./example.js main runtime modules 10 KiB 9 modules @@ -512,12 +513,12 @@ webpack 5.66.0 compiled successfully ## Production mode ``` -assets by chunk 4.23 KiB (name: main) - asset output.js 3.85 KiB [emitted] [minimized] (name: main) +assets by chunk 4.25 KiB (name: main) + asset output.js 3.87 KiB [emitted] [minimized] (name: main) asset output.css 385 bytes [emitted] (name: main) asset 89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: images/file.png] (auxiliary name: main) asset 159.output.css 53 bytes [emitted] -Entrypoint main 4.23 KiB (14.6 KiB) = output.js 3.85 KiB output.css 385 bytes 1 auxiliary asset +Entrypoint main 4.25 KiB (14.6 KiB) = output.js 3.87 KiB output.css 385 bytes 1 auxiliary asset chunk (runtime: main) 159.output.css 23 bytes > ./lazy-style.css ./example.js 4:0-26 ./lazy-style.css 23 bytes [built] [code generated] diff --git a/lib/css/CssLoadingRuntimeModule.js b/lib/css/CssLoadingRuntimeModule.js index a36b0321ff4..a9d52b00a77 100644 --- a/lib/css/CssLoadingRuntimeModule.js +++ b/lib/css/CssLoadingRuntimeModule.js @@ -216,7 +216,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { "for(var i = 0; i < links.length; i++) {", Template.indent([ "var l = links[i];", - `if(${ + `if(l.rel == "stylesheet" && (${ withHmr ? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)' : 'l.href == url || l.getAttribute("href") == url' @@ -224,7 +224,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { uniqueName ? ' || l.getAttribute("data-webpack") == uniqueName + ":" + key' : "" - }) { link = l; break; }` + })) { link = l; break; }` ]), "}", "if(!done) return link;", @@ -253,6 +253,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { "link.onload = onLinkComplete.bind(null, link.onload);" ]), "} else onLinkComplete(undefined, { type: 'load', target: link });", // We assume any existing stylesheet is render blocking + withHmr ? "hmr ? document.head.insertBefore(link, hmr) :" : "", "needAttach && document.head.appendChild(link);", "return link;" ] @@ -433,7 +434,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { ]), "}" ] - )}, true);` + )}, oldTag);` ] )}));` ])});` From 6b83f85141336bc75cff20391238ee4455be0658 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 14 Jan 2022 12:05:28 +0100 Subject: [PATCH 20/32] Module.libIdent is scoped by the module layer if there is one --- lib/ContextModule.js | 1 + lib/NormalModule.js | 4 +++- lib/container/ContainerEntryModule.js | 4 +++- lib/container/FallbackModule.js | 6 +++--- lib/container/RemoteModule.js | 4 +++- lib/sharing/ConsumeSharedModule.js | 4 +++- lib/sharing/ProvideSharedModule.js | 4 +++- 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/ContextModule.js b/lib/ContextModule.js index a1aca892184..bcb00b4b634 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -272,6 +272,7 @@ class ContextModule extends Module { this.context, options.associatedObjectForCache ); + if (this.layer) identifier = `(${this.layer})/${identifier}`; if (this.options.mode) { identifier += ` ${this.options.mode}`; } diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 2d8b3736673..039b1b01144 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -355,11 +355,13 @@ class NormalModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return contextify( + let ident = contextify( options.context, this.userRequest, options.associatedObjectForCache ); + if (this.layer) ident = `(${this.layer})/${ident}`; + return ident; } /** diff --git a/lib/container/ContainerEntryModule.js b/lib/container/ContainerEntryModule.js index d27b767751a..9eff540bee4 100644 --- a/lib/container/ContainerEntryModule.js +++ b/lib/container/ContainerEntryModule.js @@ -79,7 +79,9 @@ class ContainerEntryModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/container/entry/${this._name}`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/container/entry/${ + this._name + }`; } /** diff --git a/lib/container/FallbackModule.js b/lib/container/FallbackModule.js index cc51cae27fa..1d052d411bd 100644 --- a/lib/container/FallbackModule.js +++ b/lib/container/FallbackModule.js @@ -60,9 +60,9 @@ class FallbackModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/container/fallback/${this.requests[0]}/and ${ - this.requests.length - 1 - } more`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/container/fallback/${ + this.requests[0] + }/and ${this.requests.length - 1} more`; } /** diff --git a/lib/container/RemoteModule.js b/lib/container/RemoteModule.js index b2bea8e33af..eb250e6f9ad 100644 --- a/lib/container/RemoteModule.js +++ b/lib/container/RemoteModule.js @@ -67,7 +67,9 @@ class RemoteModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/container/remote/${this.request}`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/container/remote/${ + this.request + }`; } /** diff --git a/lib/sharing/ConsumeSharedModule.js b/lib/sharing/ConsumeSharedModule.js index 675fa6cf4eb..dbc27a01aab 100644 --- a/lib/sharing/ConsumeSharedModule.js +++ b/lib/sharing/ConsumeSharedModule.js @@ -101,7 +101,9 @@ class ConsumeSharedModule extends Module { */ libIdent(options) { const { shareKey, shareScope, import: request } = this.options; - return `webpack/sharing/consume/${shareScope}/${shareKey}${ + return `${ + this.layer ? `(${this.layer})/` : "" + }webpack/sharing/consume/${shareScope}/${shareKey}${ request ? `/${request}` : "" }`; } diff --git a/lib/sharing/ProvideSharedModule.js b/lib/sharing/ProvideSharedModule.js index bbb71ce39e9..86487018695 100644 --- a/lib/sharing/ProvideSharedModule.js +++ b/lib/sharing/ProvideSharedModule.js @@ -67,7 +67,9 @@ class ProvideSharedModule extends Module { * @returns {string | null} an identifier for library inclusion */ libIdent(options) { - return `webpack/sharing/provide/${this._shareScope}/${this._name}`; + return `${this.layer ? `(${this.layer})/` : ""}webpack/sharing/provide/${ + this._shareScope + }/${this._name}`; } /** From 04ddb71e06b0d898eb70f3b42a9e11e0799f5cd2 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 14 Jan 2022 12:06:05 +0100 Subject: [PATCH 21/32] fix normalization of css filename --- lib/config/normalization.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/config/normalization.js b/lib/config/normalization.js index 507b5460e93..cba7d6b6e54 100644 --- a/lib/config/normalization.js +++ b/lib/config/normalization.js @@ -297,6 +297,8 @@ const getNormalizedWebpackOptions = config => { chunkLoading: output.chunkLoading, chunkLoadingGlobal: output.chunkLoadingGlobal, chunkLoadTimeout: output.chunkLoadTimeout, + cssFilename: output.cssFilename, + cssChunkFilename: output.cssChunkFilename, clean: output.clean, compareBeforeEmit: output.compareBeforeEmit, crossOriginLoading: output.crossOriginLoading, From 8c6077c246062ea29f8678751c2f0eaa965bea60 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 14 Jan 2022 13:19:48 +0100 Subject: [PATCH 22/32] move to cli add resetDescription --- lib/cli.js | 34 +++++++++++++++++++----- test/Cli.basictest.js | 24 ++++++++++++++--- test/__snapshots__/Cli.basictest.js.snap | 26 ++++++++++++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 984b1539a17..7165b3ccc28 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -97,8 +97,10 @@ const getArguments = (schema = webpackSchema) => { */ const getDescription = path => { for (const { schema } of path) { - if (schema.cli && schema.cli.helper) continue; - if (schema.cliDescription) return schema.cliDescription; + if (schema.cli) { + if (schema.cli.helper) continue; + if (schema.cli.description) return schema.cli.description; + } if (schema.description) return schema.description; } }; @@ -110,8 +112,24 @@ const getArguments = (schema = webpackSchema) => { */ const getNegatedDescription = path => { for (const { schema } of path) { - if (schema.cli && schema.cli.helper) continue; - if (schema.negatedDescription) return schema.negatedDescription; + if (schema.cli) { + if (schema.cli.helper) continue; + if (schema.cli.negatedDescription) return schema.cli.negatedDescription; + } + } + }; + + /** + * + * @param {PathItem[]} path path in the schema + * @returns {string | undefined} reset description + */ + const getResetDescription = path => { + for (const { schema } of path) { + if (schema.cli) { + if (schema.cli.helper) continue; + if (schema.cli.resetDescription) return schema.cli.resetDescription; + } } }; @@ -156,13 +174,17 @@ const getArguments = (schema = webpackSchema) => { const addResetFlag = path => { const schemaPath = path[0].path; const name = pathToArgumentName(`${schemaPath}.reset`); - const description = getDescription(path); + const description = + getResetDescription(path) || + `Clear all items provided in '${schemaPath}' configuration. ${getDescription( + path + )}`; flags[name] = { configs: [ { type: "reset", multiple: false, - description: `Clear all items provided in '${schemaPath}' configuration. ${description}`, + description, path: schemaPath } ], diff --git a/test/Cli.basictest.js b/test/Cli.basictest.js index 0223db56c62..b3ae20301a6 100644 --- a/test/Cli.basictest.js +++ b/test/Cli.basictest.js @@ -11,21 +11,37 @@ describe("Cli", () => { type: "object", additionalProperties: false, properties: { + "with-reset-description": { + type: "array", + items: { + type: "string" + }, + description: "original description", + cli: { + resetDescription: "custom reset" + } + }, "with-cli-description": { type: "string", description: "original description", - cliDescription: "description for CLI option" + cli: { + description: "description for CLI option" + } }, "with-negative-description": { type: "boolean", description: "original description", - negatedDescription: "custom negative description" + cli: { + negatedDescription: "custom negative description" + } }, "with-both-cli-and-negative-description": { type: "boolean", description: "original description", - cliDescription: "description for CLI option", - negatedDescription: "custom negative description" + cli: { + description: "description for CLI option", + negatedDescription: "custom negative description" + } } } }; diff --git a/test/__snapshots__/Cli.basictest.js.snap b/test/__snapshots__/Cli.basictest.js.snap index bde140f6fb6..95cc00b8f27 100644 --- a/test/__snapshots__/Cli.basictest.js.snap +++ b/test/__snapshots__/Cli.basictest.js.snap @@ -8975,5 +8975,31 @@ Object { "multiple": false, "simpleType": "boolean", }, + "with-reset-description": Object { + "configs": Array [ + Object { + "description": "original description", + "multiple": true, + "path": "with-reset-description[]", + "type": "string", + }, + ], + "description": "original description", + "multiple": true, + "simpleType": "string", + }, + "with-reset-description-reset": Object { + "configs": Array [ + Object { + "description": "custom reset", + "multiple": false, + "path": "with-reset-description", + "type": "reset", + }, + ], + "description": "custom reset", + "multiple": false, + "simpleType": "boolean", + }, } `; From 616251c0699c814c01c2a3ed7b614fdc510e6c62 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 14 Jan 2022 15:27:30 +0100 Subject: [PATCH 23/32] add a plus before count handle extension extraction for concatenated modules correctly --- lib/stats/DefaultStatsFactoryPlugin.js | 14 +- lib/stats/DefaultStatsPrinterPlugin.js | 85 +++++++++--- .../StatsTestCases.basictest.js.snap | 123 +++++++++--------- 3 files changed, 135 insertions(+), 87 deletions(-) diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 81eb2a1123d..20c89962787 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -1706,9 +1706,10 @@ const spaceLimited = ( items.length = limit; children = items; } else { + // limit is the size when all groups are collapsed const limit = groups.length + - (filteredChildrenLineReserved ? 0 : Math.min(1, items.length)); + (filteredChildrenLineReserved || items.length === 0 ? 0 : 1); if (limit < max) { // calculate how much we are over the size limit // this allows to approach the limit faster @@ -1813,6 +1814,9 @@ const reasonGroup = (children, reasons) => { }; }; +const GROUP_EXTENSION_REGEXP = /(\.[^.]+?)(?:\?|(?: \+ \d+ modules?)?$)/; +const GROUP_PATH_REGEXP = /(.+)[/\\][^/\\]+?(?:\?|(?: \+ \d+ modules?)?$)/; + /** @type {Record void>} */ const ASSETS_GROUPERS = { _: (groupConfigs, context, options) => { @@ -1861,10 +1865,10 @@ const ASSETS_GROUPERS = { groupConfigs.push({ getKeys: asset => { const extensionMatch = - groupAssetsByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(asset.name); + groupAssetsByExtension && GROUP_EXTENSION_REGEXP.exec(asset.name); const extension = extensionMatch ? extensionMatch[1] : ""; const pathMatch = - groupAssetsByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(asset.name); + groupAssetsByPath && GROUP_PATH_REGEXP.exec(asset.name); const path = pathMatch ? pathMatch[1].split(/[/\\]/) : []; const keys = []; if (groupAssetsByPath) { @@ -2059,10 +2063,10 @@ const MODULES_GROUPERS = type => ({ if (!module.name) return; const resource = parseResource(module.name.split("!").pop()).path; const extensionMatch = - groupModulesByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(resource); + groupModulesByExtension && GROUP_EXTENSION_REGEXP.exec(resource); const extension = extensionMatch ? extensionMatch[1] : ""; const pathMatch = - groupModulesByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(resource); + groupModulesByPath && GROUP_PATH_REGEXP.exec(resource); const path = pathMatch ? pathMatch[1].split(/[/\\]/) : []; const keys = []; if (groupModulesByPath) { diff --git a/lib/stats/DefaultStatsPrinterPlugin.js b/lib/stats/DefaultStatsPrinterPlugin.js index ec917faafa1..1ab78dd52e1 100644 --- a/lib/stats/DefaultStatsPrinterPlugin.js +++ b/lib/stats/DefaultStatsPrinterPlugin.js @@ -38,6 +38,10 @@ const isValidId = id => { return typeof id === "number" || id; }; +const moreCount = (list, count) => { + return list && list.length > 0 ? `+ ${count}` : `${count}`; +}; + /** @type {Record string | void>} */ const SIMPLE_PRINTERS = { "compilation.summary!": ( @@ -163,13 +167,24 @@ const SIMPLE_PRINTERS = { }, "compilation.assetsByChunkName": () => "", - "compilation.filteredModules": filteredModules => + "compilation.filteredModules": ( + filteredModules, + { compilation: { modules } } + ) => filteredModules > 0 - ? `${filteredModules} ${plural(filteredModules, "module", "modules")}` + ? `${moreCount(modules, filteredModules)} ${plural( + filteredModules, + "module", + "modules" + )}` : undefined, "compilation.filteredAssets": (filteredAssets, { compilation: { assets } }) => filteredAssets > 0 - ? `${filteredAssets} ${plural(filteredAssets, "asset", "assets")}` + ? `${moreCount(assets, filteredAssets)} ${plural( + filteredAssets, + "asset", + "assets" + )}` : undefined, "compilation.logging": (logging, context, printer) => Array.isArray(logging) @@ -262,15 +277,19 @@ const SIMPLE_PRINTERS = { "asset.separator!": () => "\n", "asset.filteredRelated": (filteredRelated, { asset: { related } }) => filteredRelated > 0 - ? `${filteredRelated} related ${plural( + ? `${moreCount(related, filteredRelated)} related ${plural( filteredRelated, "asset", "assets" )}` : undefined, - "asset.filteredChildren": filteredChildren => + "asset.filteredChildren": (filteredChildren, { asset: { children } }) => filteredChildren > 0 - ? `${filteredChildren} ${plural(filteredChildren, "asset", "assets")}` + ? `${moreCount(children, filteredChildren)} ${plural( + filteredChildren, + "asset", + "assets" + )}` : undefined, assetChunk: (id, { formatChunkId }) => formatChunkId(id), @@ -366,21 +385,29 @@ const SIMPLE_PRINTERS = { "module.issuerPath": (issuerPath, { module }) => module.profile ? undefined : "", "module.profile": profile => undefined, - "module.filteredModules": filteredModules => + "module.filteredModules": (filteredModules, { module: { modules } }) => filteredModules > 0 - ? `${filteredModules} nested ${plural( + ? `${moreCount(modules, filteredModules)} nested ${plural( filteredModules, "module", "modules" )}` : undefined, - "module.filteredReasons": filteredReasons => + "module.filteredReasons": (filteredReasons, { module: { reasons } }) => filteredReasons > 0 - ? `${filteredReasons} ${plural(filteredReasons, "reason", "reasons")}` + ? `${moreCount(reasons, filteredReasons)} ${plural( + filteredReasons, + "reason", + "reasons" + )}` : undefined, - "module.filteredChildren": filteredChildren => + "module.filteredChildren": (filteredChildren, { module: { children } }) => filteredChildren > 0 - ? `${filteredChildren} ${plural(filteredChildren, "module", "modules")}` + ? `${moreCount(children, filteredChildren)} ${plural( + filteredChildren, + "module", + "modules" + )}` : undefined, "module.separator!": () => "\n", @@ -397,9 +424,16 @@ const SIMPLE_PRINTERS = { "moduleReason.active": (active, { formatFlag }) => active ? undefined : formatFlag("inactive"), "moduleReason.resolvedModule": (module, { magenta }) => magenta(module), - "moduleReason.filteredChildren": filteredChildren => + "moduleReason.filteredChildren": ( + filteredChildren, + { moduleReason: { children } } + ) => filteredChildren > 0 - ? `${filteredChildren} ${plural(filteredChildren, "reason", "reasons")}` + ? `${moreCount(children, filteredChildren)} ${plural( + filteredChildren, + "reason", + "reasons" + )}` : undefined, "module.profile.total": (value, { formatTime }) => formatTime(value), @@ -427,10 +461,21 @@ const SIMPLE_PRINTERS = { size ? formatSize(size) : undefined, "chunkGroup.auxiliaryAssetsSize": (size, { formatSize }) => size ? `(${formatSize(size)})` : undefined, - "chunkGroup.filteredAssets": n => - n > 0 ? `${n} ${plural(n, "asset", "assets")}` : undefined, - "chunkGroup.filteredAuxiliaryAssets": n => - n > 0 ? `${n} auxiliary ${plural(n, "asset", "assets")}` : undefined, + "chunkGroup.filteredAssets": (n, { chunkGroup: { assets } }) => + n > 0 + ? `${moreCount(assets, n)} ${plural(n, "asset", "assets")}` + : undefined, + "chunkGroup.filteredAuxiliaryAssets": ( + n, + { chunkGroup: { auxiliaryAssets } } + ) => + n > 0 + ? `${moreCount(auxiliaryAssets, n)} auxiliary ${plural( + n, + "asset", + "assets" + )}` + : undefined, "chunkGroup.is!": () => "=", "chunkGroupAsset.name": (asset, { green }) => green(asset), "chunkGroupAsset.size": (size, { formatSize, chunkGroup }) => @@ -490,9 +535,9 @@ const SIMPLE_PRINTERS = { "chunk.recorded": (recorded, { formatFlag, green }) => recorded ? green(formatFlag("recorded")) : undefined, "chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined), - "chunk.filteredModules": filteredModules => + "chunk.filteredModules": (filteredModules, { chunk: { modules } }) => filteredModules > 0 - ? `${filteredModules} chunk ${plural( + ? `${moreCount(modules, filteredModules)} chunk ${plural( filteredModules, "module", "modules" diff --git a/test/__snapshots__/StatsTestCases.basictest.js.snap b/test/__snapshots__/StatsTestCases.basictest.js.snap index aa8f8b5f9a4..3a1cac7484a 100644 --- a/test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/test/__snapshots__/StatsTestCases.basictest.js.snap @@ -1345,7 +1345,7 @@ exports[`StatsTestCases should print correct stats for max-modules 1`] = ` ./c.js?6 33 bytes [built] [code generated] ./c.js?7 33 bytes [built] [code generated] ./c.js?8 33 bytes [built] [code generated] -12 modules ++ 12 modules webpack x.x.x compiled successfully in X ms" `; @@ -1365,7 +1365,7 @@ exports[`StatsTestCases should print correct stats for max-modules-default 1`] = ./c.js?1 33 bytes [built] [code generated] ./c.js?2 33 bytes [built] [code generated] ./c.js?3 33 bytes [built] [code generated] -17 modules ++ 17 modules webpack x.x.x compiled successfully in X ms" `; @@ -2657,27 +2657,27 @@ exclude1: hidden assets 28.9 KiB 2 assets sourceMap exclude1-main.js.map 12.5 KiB [emitted] [dev] (auxiliary name: main) hidden assets 25 KiB 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset asset exclude1-chunk_js.js 804 bytes [emitted] hidden assets 1.57 KiB 2 assets sourceMap exclude1-chunk_js.js.map 295 bytes [emitted] [dev] hidden assets 590 bytes 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset assets by path *.css 144 bytes asset exclude1-chunk_js.css 74 bytes [emitted] hidden assets 148 bytes 2 assets sourceMap exclude1-chunk_js.css.map 197 bytes [emitted] [dev] hidden assets 394 bytes 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset asset exclude1-main.css 70 bytes [emitted] (name: main) hidden assets 140 bytes 2 assets sourceMap exclude1-main.css.map 187 bytes [emitted] [dev] (auxiliary name: main) hidden assets 374 bytes 2 assets - 1 related asset - 1 related asset + + 1 related asset + + 1 related asset exclude2: assets by path *.js 15.2 KiB @@ -3085,23 +3085,27 @@ exports[`StatsTestCases should print correct stats for scope-hoisting-bailouts 1 "runtime modules 6.83 KiB 10 modules built modules 615 bytes [built] code generated modules 530 bytes [code generated] - modules by path ./*.js 377 bytes - ./index.js 150 bytes [built] [code generated] - Statement (ExpressionStatement) with side effects in source code at 7:0-25 - ModuleConcatenation bailout: Cannot concat with ./cjs.js: Module is not an ECMAScript module - ModuleConcatenation bailout: Cannot concat with ./eval.js: Module uses eval() - ModuleConcatenation bailout: Cannot concat with ./module-id.js: Module uses module.id - ModuleConcatenation bailout: Cannot concat with ./module-loaded.js: Module uses module.loaded - ./entry.js 32 bytes [built] [code generated] - ./cjs.js 59 bytes [built] [code generated] - CommonJS bailout: module.exports is used directly at 3:0-14 - Statement (ExpressionStatement) with side effects in source code at 1:0-26 - ModuleConcatenation bailout: Module is not an ECMAScript module - ./ref-from-cjs.js 45 bytes [built] [code generated] - ./eval.js 35 bytes [built] [code generated] - Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-34 - ModuleConcatenation bailout: Module uses eval() - 2 modules + ./index.js 150 bytes [built] [code generated] + Statement (ExpressionStatement) with side effects in source code at 7:0-25 + ModuleConcatenation bailout: Cannot concat with ./cjs.js: Module is not an ECMAScript module + ModuleConcatenation bailout: Cannot concat with ./eval.js: Module uses eval() + ModuleConcatenation bailout: Cannot concat with ./module-id.js: Module uses module.id + ModuleConcatenation bailout: Cannot concat with ./module-loaded.js: Module uses module.loaded + ./entry.js 32 bytes [built] [code generated] + ./cjs.js 59 bytes [built] [code generated] + CommonJS bailout: module.exports is used directly at 3:0-14 + Statement (ExpressionStatement) with side effects in source code at 1:0-26 + ModuleConcatenation bailout: Module is not an ECMAScript module + ./ref-from-cjs.js 45 bytes [built] [code generated] + ./eval.js 35 bytes [built] [code generated] + Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-34 + ModuleConcatenation bailout: Module uses eval() + ./module-id.js 26 bytes [built] [code generated] + Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-25 + ModuleConcatenation bailout: Module uses module.id + ./module-loaded.js 30 bytes [built] [code generated] + Statement (ExportDefaultDeclaration) with side effects in source code at 1:0-29 + ModuleConcatenation bailout: Module uses module.loaded ./concatenated.js + 2 modules 111 bytes [built] [code generated] ModuleConcatenation bailout: Cannot concat with external \\"external\\": Module external \\"external\\" is not in the same chunk(s) (expected in chunk(s) unnamed chunk(s), module is in chunk(s) index) external \\"external\\" 42 bytes [built] [code generated] @@ -3136,15 +3140,18 @@ Entrypoint second 13.5 KiB = b-vendor.js 419 bytes b-second.js 13.1 KiB runtime modules 15.1 KiB 20 modules cacheable modules 975 bytes code generated modules 857 bytes [code generated] - modules by path ./*.js + 1 modules 459 bytes - ./second.js + 1 modules 227 bytes [built] [code generated] - ModuleConcatenation bailout: Cannot concat with ./vendor.js: Module ./vendor.js is not in the same chunk(s) (expected in chunk(s) second, module is in chunk(s) vendor) - 2 modules - modules by path ./*.js 106 bytes - ./vendor.js 25 bytes [built] [code generated] - 2 modules ./first.js + 2 modules 292 bytes [built] [code generated] ModuleConcatenation bailout: Cannot concat with ./vendor.js: Module ./vendor.js is not in the same chunk(s) (expected in chunk(s) first, module is in chunk(s) vendor) + ./second.js + 1 modules 227 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./vendor.js: Module ./vendor.js is not in the same chunk(s) (expected in chunk(s) second, module is in chunk(s) vendor) + ./vendor.js 25 bytes [built] [code generated] + ./lazy_first.js + 1 modules 116 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_shared.js + ./lazy_shared.js 56 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_first.js, ./lazy_second.js + ./lazy_second.js + 1 modules 116 bytes [built] [code generated] + ModuleConcatenation bailout: Cannot concat with ./common_lazy_shared.js: Module ./common_lazy_shared.js is referenced from different chunks by these modules: ./lazy_shared.js + ./common_lazy_shared.js 25 bytes [built] [code generated] orphan modules 118 bytes [orphan] ./common2.js 25 bytes [orphan] [built] ./module_first.js 31 bytes [orphan] [built] @@ -3162,16 +3169,7 @@ cacheable modules 823 bytes modules by path ./components/src/ 501 bytes orphan modules 315 bytes [orphan] modules by path ./components/src/CompAB/*.js 164 bytes 2 modules - modules by path ./components/src/CompC/*.js 67 bytes - ./components/src/CompC/CompC.js 33 bytes [orphan] [built] - [module unused] - [inactive] harmony side effect evaluation ./CompC ./components/src/CompC/index.js 1:0-34 - [inactive] harmony export imported specifier ./CompC ./components/src/CompC/index.js 1:0-34 - [inactive] harmony export imported specifier ./CompC ./components/src/index.js 2:0-43 (skipped side-effect-free modules) - ./components/src/CompC/index.js 34 bytes [orphan] [built] - [module unused] - [inactive] harmony side effect evaluation ./CompC ./components/src/index.js 2:0-43 - [inactive] harmony export imported specifier ./CompC ./components/src/index.js 2:0-43 + modules by path ./components/src/CompC/*.js 67 bytes 2 modules ./components/src/index.js 84 bytes [orphan] [built] [module unused] [inactive] from origin ./main.js + 1 modules @@ -3200,20 +3198,21 @@ cacheable modules 823 bytes from origin ./main.js + 1 modules [inactive] harmony side effect evaluation ./utils ./main.js + 1 modules ./components/src/CompAB/CompB.js 1:0-30 harmony import specifier ./utils ./main.js + 1 modules ./components/src/CompAB/CompB.js 5:2-5 - ./main.js + 1 modules 221 bytes [built] [code generated] - [no exports used] - entry ./main.js main - | ./main.js 144 bytes [built] - | [no exports used] - | ./components/src/CompAB/CompB.js 77 bytes [built] - | [only some exports used: default] - | [inactive] from origin ./components/src/CompAB/index.js - | [inactive] harmony side effect evaluation ./CompB ./components/src/CompAB/index.js 2:0-43 - | [inactive] harmony export imported specifier ./CompB ./components/src/CompAB/index.js 2:0-43 - | [inactive] harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40 (skipped side-effect-free modules) - | harmony import specifier ./components ./main.js 4:15-20 (skipped side-effect-free modules) - ./foo.js 101 bytes [built] [code generated] - import() ./foo ./main.js + 1 modules ./main.js 6:0-15 + modules by path ./*.js 322 bytes + ./main.js + 1 modules 221 bytes [built] [code generated] + [no exports used] + entry ./main.js main + | ./main.js 144 bytes [built] + | [no exports used] + | ./components/src/CompAB/CompB.js 77 bytes [built] + | [only some exports used: default] + | [inactive] from origin ./components/src/CompAB/index.js + | [inactive] harmony side effect evaluation ./CompB ./components/src/CompAB/index.js 2:0-43 + | [inactive] harmony export imported specifier ./CompB ./components/src/CompAB/index.js 2:0-43 + | [inactive] harmony export imported specifier ./CompAB ./components/src/index.js 1:0-40 (skipped side-effect-free modules) + | harmony import specifier ./components ./main.js 4:15-20 (skipped side-effect-free modules) + ./foo.js 101 bytes [built] [code generated] + import() ./foo ./main.js + 1 modules ./main.js 6:0-15 webpack x.x.x compiled successfully in X ms" `; @@ -4127,12 +4126,12 @@ switched: ./subfolder/big.js?1 267 bytes [built] [code generated] ./subfolder/big.js?2 267 bytes [built] [code generated] ./subfolder/small.js?1 66 bytes [built] [code generated] - 8 modules + + 8 modules modules by path ./*.js 594 bytes ./small.js?1 66 bytes [built] [code generated] ./small.js?2 66 bytes [built] [code generated] ./small.js?3 66 bytes [built] [code generated] - 6 modules + + 6 modules chunk (runtime: main) switched-main-12217e1d.js (main-12217e1d) 1.57 KiB (javascript) 3.02 KiB (runtime) ={1}= ={59}= ={318}= ={410}= ={520}= ={581}= ={869}= ={997}= [entry] [rendered] > ./ main runtime modules 3.02 KiB 5 modules @@ -4146,11 +4145,11 @@ switched: > ./ main modules by path ./inner-module/*.js 594 bytes ./inner-module/small.js?1 66 bytes [built] [code generated] - 8 modules + + 8 modules modules by path ./in-some-directory/*.js 531 bytes ./in-some-directory/big.js?1 267 bytes [built] [code generated] ./in-some-directory/small.js?1 66 bytes [built] [code generated] - 3 modules + + 3 modules modules by path ./*.js 534 bytes ./big.js?1 267 bytes [built] [code generated] ./big.js?2 267 bytes [built] [code generated] From 8e6fcfa0facd1d1457fc984ba8fd30f87227a667 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jan 2022 03:03:10 +0000 Subject: [PATCH 24/32] chore(deps-dev): bump core-js from 3.19.1 to 3.20.3 Bumps [core-js](https://github.com/zloirock/core-js) from 3.19.1 to 3.20.3. - [Release notes](https://github.com/zloirock/core-js/releases) - [Changelog](https://github.com/zloirock/core-js/blob/master/CHANGELOG.md) - [Commits](https://github.com/zloirock/core-js/compare/v3.19.1...v3.20.3) --- updated-dependencies: - dependency-name: core-js dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index f43f46453c0..b07424e28fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1896,9 +1896,9 @@ copy-anything@^2.0.1: is-what "^3.7.1" core-js@^3.6.5: - version "3.19.1" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.19.1.tgz#f6f173cae23e73a7d88fa23b6e9da329276c6641" - integrity sha512-Tnc7E9iKd/b/ff7GFbhwPVzJzPztGrChB8X8GLqoYGdEOG8IpLnK1xPyo3ZoO3HsK6TodJS58VGPOxA+hLHQMg== + version "3.20.3" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.20.3.tgz#c710d0a676e684522f3db4ee84e5e18a9d11d69a" + integrity sha512-vVl8j8ph6tRS3B8qir40H7yw7voy17xL0piAjlbBUsH7WIfzoedL/ZOr1OV9FyZQLWXsayOJyV4tnRyXR85/ag== core-util-is@1.0.2, core-util-is@^1.0.2, core-util-is@~1.0.0: version "1.0.2" From f0a8664895746ebcd7a35e5947c54fe0314210e5 Mon Sep 17 00:00:00 2001 From: Asriel Yu Date: Mon, 17 Jan 2022 14:06:13 +0800 Subject: [PATCH 25/32] update type.d.ts by special-lint-fix --- types.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types.d.ts b/types.d.ts index 946b48fc72f..7dfee522143 100644 --- a/types.d.ts +++ b/types.d.ts @@ -6315,7 +6315,6 @@ declare interface LoaderRunnerLoaderContext { /** * An array of all the loaders. It is writeable in the pitch phase. * loaders = [{request: string, path: string, query: string, module: function}] - * * In the example: * [ * { request: "/abc/loader1.js?xyz", From 420e8b68151e2a3befac5b3550e2ac8c9ceb3d53 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 17 Jan 2022 18:47:49 +0300 Subject: [PATCH 26/32] fix: logic --- lib/asset/AssetGenerator.js | 33 ++++++++++++++++++- .../asset-modules/data-url/index.js | 14 ++++++++ .../input-data-url-encoding/index.js | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/asset/AssetGenerator.js b/lib/asset/AssetGenerator.js index 777eb49ddf7..bb72f010740 100644 --- a/lib/asset/AssetGenerator.js +++ b/lib/asset/AssetGenerator.js @@ -185,7 +185,38 @@ class AssetGenerator extends Generator { ); } - const encodedContent = encodeDataUri(encoding, originalSource); + let encodedContent; + + const decodeDataURI = uri => { + const match = URIRegEx.exec(uri); + if (!match) return null; + + const isBase64 = match[3]; + const body = match[4]; + return isBase64 + ? Buffer.from(body, "base64") + : Buffer.from(decodeURIComponent(body), "ascii"); + }; + + const decodeDataUriContent = (encoding, content) => { + const isBase64 = encoding === "base64"; + return isBase64 + ? Buffer.from(content, "base64") + : Buffer.from(decodeURIComponent(content), "ascii"); + }; + + if ( + module.resourceResolveData && + module.resourceResolveData.encoding === encoding && + decodeDataUriContent( + module.resourceResolveData.encoding, + module.resourceResolveData.encodedContent, + ).equals(originalSource.buffer()) + ) { + encodedContent = module.resourceResolveData.encodedContent; + } else { + encodedContent = encodeDataUri(encoding, originalSource); + } encodedSource = `data:${mimeType}${ encoding ? `;${encoding}` : "" diff --git a/test/configCases/asset-modules/data-url/index.js b/test/configCases/asset-modules/data-url/index.js index c45262a35f7..ee46bb5c044 100644 --- a/test/configCases/asset-modules/data-url/index.js +++ b/test/configCases/asset-modules/data-url/index.js @@ -5,7 +5,15 @@ import dataSvg from "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53M const urlSvg = new URL( "data:image/svg;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPgo=" ); +const urlSvg2 = new URL( + "data:image/svg+xml;p=1;q=2,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke=\"%23343a40\" stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e", + import.meta.url +); const helloWorld = new URL("data:text/plain,Hello", import.meta.url); +const helloWorldBase64 = new URL( + "data:text/plain;base64,SGVsbG8=", + import.meta.url +); it("should generate various data-url types", () => { expect(png).toContain("data:image/png;base64,"); @@ -13,5 +21,11 @@ it("should generate various data-url types", () => { expect(jpg).toContain("data:image/jpeg;base64,"); expect(dataSvg).toContain("data:image/svg+xml;base64,"); expect(urlSvg.href).toContain("data:image/svg;base64,"); + expect(urlSvg2.href).toContain( + "data:image/svg+xml;p=1;q=2,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke=\"%23343a40\" stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e" + ); expect(helloWorld.href).toContain("data:text/plain,Hello%2C%20World%21"); + expect(helloWorldBase64.href).toContain( + "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" + ); }); diff --git a/test/configCases/asset-modules/input-data-url-encoding/index.js b/test/configCases/asset-modules/input-data-url-encoding/index.js index 3393e4c7f26..561c29d9516 100644 --- a/test/configCases/asset-modules/input-data-url-encoding/index.js +++ b/test/configCases/asset-modules/input-data-url-encoding/index.js @@ -4,7 +4,7 @@ it("should keep original encoding", () => { import.meta.url ); expect(url.href).toBe( - "data:image/svg+xml;p=1;q=2,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2016%2016%27%3E%3Cpath%20fill%3D%27none%27%20stroke%3D%22%23343a40%22%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%20stroke-width%3D%272%27%20d%3D%27M2%205l6%206%206-6%27%2F%3E%3C%2Fsvg%3E" + "data:image/svg+xml;p=1;q=2,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke=\"%23343a40\" stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e" ); }); From eaaccf9d6c17db39830ab65d73213b03a4861a18 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 17 Jan 2022 18:52:55 +0300 Subject: [PATCH 27/32] fix: handle content from loaders --- lib/asset/AssetGenerator.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/asset/AssetGenerator.js b/lib/asset/AssetGenerator.js index bb72f010740..c1967e9e7a4 100644 --- a/lib/asset/AssetGenerator.js +++ b/lib/asset/AssetGenerator.js @@ -102,6 +102,13 @@ const encodeDataUri = (encoding, source) => { return encodedContent; }; +const decodeDataUriContent = (encoding, content) => { + const isBase64 = encoding === "base64"; + return isBase64 + ? Buffer.from(content, "base64") + : Buffer.from(decodeURIComponent(content), "ascii"); +}; + const JS_TYPES = new Set(["javascript"]); const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]); @@ -187,30 +194,12 @@ class AssetGenerator extends Generator { let encodedContent; - const decodeDataURI = uri => { - const match = URIRegEx.exec(uri); - if (!match) return null; - - const isBase64 = match[3]; - const body = match[4]; - return isBase64 - ? Buffer.from(body, "base64") - : Buffer.from(decodeURIComponent(body), "ascii"); - }; - - const decodeDataUriContent = (encoding, content) => { - const isBase64 = encoding === "base64"; - return isBase64 - ? Buffer.from(content, "base64") - : Buffer.from(decodeURIComponent(content), "ascii"); - }; - if ( module.resourceResolveData && module.resourceResolveData.encoding === encoding && decodeDataUriContent( module.resourceResolveData.encoding, - module.resourceResolveData.encodedContent, + module.resourceResolveData.encodedContent ).equals(originalSource.buffer()) ) { encodedContent = module.resourceResolveData.encodedContent; From 822c3b33cfd211ec7e579c7169625ffa655deb01 Mon Sep 17 00:00:00 2001 From: Mark Molinaro Date: Mon, 17 Jan 2022 20:45:42 -0800 Subject: [PATCH 28/32] fix for older node verisons --- lib/debug/ProfilingPlugin.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index a61bd5b05e1..6d6af9d39c4 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -344,11 +344,15 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => { const makeInterceptorFor = (instance, tracer) => hookName => ({ register: ({ name, type, context, fn }) => { - const newFn = makeNewProfiledTapFn(hookName, tracer, { - name, - type, - fn - }); + const newFn = + // Don't tap our own hooks to ensure stream can close cleanly + name === pluginName + ? fn + : makeNewProfiledTapFn(hookName, tracer, { + name, + type, + fn + }); return { name, type, From 8f224a54e2b4b9c9cd91ae8e1e663e29573b7c64 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jan 2022 09:03:11 +0000 Subject: [PATCH 29/32] chore(deps): bump @types/eslint-scope from 3.7.2 to 3.7.3 Bumps [@types/eslint-scope](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/eslint-scope) from 3.7.2 to 3.7.3. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/eslint-scope) --- updated-dependencies: - dependency-name: "@types/eslint-scope" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- yarn.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index f43f46453c0..ef8140a65c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -878,9 +878,9 @@ es-module-lexer "*" "@types/eslint-scope@^3.7.0": - version "3.7.2" - resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.2.tgz#11e96a868c67acf65bf6f11d10bb89ea71d5e473" - integrity sha512-TzgYCWoPiTeRg6RQYgtuW7iODtVoKu3RVL72k3WohqhjfaOLK5Mg2T4Tg1o2bSfu0vPkoI48wdQFv5b/Xe04wQ== + version "3.7.3" + resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224" + integrity sha512-PB3ldyrcnAicT35TWPs5IcwKD8S333HMaa2VVv4+wdvebJkjWuW/xESoB8IwRcog8HYVYamb1g/R31Qv5Bx03g== dependencies: "@types/eslint" "*" "@types/estree" "*" @@ -1228,9 +1228,9 @@ acorn@^7.1.1, acorn@^7.4.0: integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== acorn@^8.2.4, acorn@^8.4.1: - version "8.6.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.6.0.tgz#e3692ba0eb1a0c83eaa4f37f5fa7368dd7142895" - integrity sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw== + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== agent-base@6: version "6.0.2" From 73280a4ce54e63df23cd8e1ada4ece7143afa780 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jan 2022 09:03:28 +0000 Subject: [PATCH 30/32] chore(deps-dev): bump date-fns from 2.27.0 to 2.28.0 Bumps [date-fns](https://github.com/date-fns/date-fns) from 2.27.0 to 2.28.0. - [Release notes](https://github.com/date-fns/date-fns/releases) - [Changelog](https://github.com/date-fns/date-fns/blob/master/CHANGELOG.md) - [Commits](https://github.com/date-fns/date-fns/compare/v2.27.0...v2.28.0) --- updated-dependencies: - dependency-name: date-fns dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- yarn.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index f43f46453c0..e5f0be1d233 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1228,9 +1228,9 @@ acorn@^7.1.1, acorn@^7.4.0: integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== acorn@^8.2.4, acorn@^8.4.1: - version "8.6.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.6.0.tgz#e3692ba0eb1a0c83eaa4f37f5fa7368dd7142895" - integrity sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw== + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== agent-base@6: version "6.0.2" @@ -2113,9 +2113,9 @@ data-urls@^2.0.0: whatwg-url "^8.0.0" date-fns@^2.15.0: - version "2.27.0" - resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.27.0.tgz#e1ff3c3ddbbab8a2eaadbb6106be2929a5a2d92b" - integrity sha512-sj+J0Mo2p2X1e306MHq282WS4/A8Pz/95GIFcsPNMPMZVI3EUrAdSv90al1k+p74WGLCruMXk23bfEDZa71X9Q== + version "2.28.0" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.28.0.tgz#9570d656f5fc13143e50c975a3b6bbeb46cd08b2" + integrity sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw== debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2: version "4.3.2" From 453643af6db2df4be1d8ac743ea4b46e96d61ae1 Mon Sep 17 00:00:00 2001 From: Ivan Kopeykin Date: Tue, 18 Jan 2022 13:42:13 +0300 Subject: [PATCH 31/32] provide hashFunction parameter to DependencyTemplates --- lib/Compilation.js | 4 +++- lib/DependencyTemplates.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Compilation.js b/lib/Compilation.js index a094b5bebe4..b949ce134c2 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -1020,7 +1020,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** @type {Map} */ this.dependencyFactories = new Map(); /** @type {DependencyTemplates} */ - this.dependencyTemplates = new DependencyTemplates(); + this.dependencyTemplates = new DependencyTemplates( + this.outputOptions.hashFunction + ); this.childrenCounters = {}; /** @type {Set} */ this.usedChunkIds = null; diff --git a/lib/DependencyTemplates.js b/lib/DependencyTemplates.js index 45268e13adb..5f7f30e0273 100644 --- a/lib/DependencyTemplates.js +++ b/lib/DependencyTemplates.js @@ -57,7 +57,7 @@ class DependencyTemplates { } clone() { - const newInstance = new DependencyTemplates(); + const newInstance = new DependencyTemplates(this._hashFunction); newInstance._map = new Map(this._map); newInstance._hash = this._hash; return newInstance; From a9477c2409ede0843a0715045b31a6d424a4f592 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 18 Jan 2022 12:26:43 +0100 Subject: [PATCH 32/32] fix HMR when experiments.lazyCompilation is enabled --- lib/hmr/LazyCompilationPlugin.js | 64 +++++++++++++------ .../hotCases/lazy-compilation/simple/index.js | 18 +++++- .../lazy-compilation/simple/module.js | 2 + .../lazy-compilation/unrelated/index.js | 25 ++++++++ .../lazy-compilation/unrelated/lazy.js | 1 + .../lazy-compilation/unrelated/module.js | 5 ++ .../unrelated/webpack.config.js | 10 +++ 7 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 test/hotCases/lazy-compilation/unrelated/index.js create mode 100644 test/hotCases/lazy-compilation/unrelated/lazy.js create mode 100644 test/hotCases/lazy-compilation/unrelated/module.js create mode 100644 test/hotCases/lazy-compilation/unrelated/webpack.config.js diff --git a/lib/hmr/LazyCompilationPlugin.js b/lib/hmr/LazyCompilationPlugin.js index 692f30af0d5..3e73d8c6459 100644 --- a/lib/hmr/LazyCompilationPlugin.js +++ b/lib/hmr/LazyCompilationPlugin.js @@ -29,6 +29,7 @@ const { registerNotSerializable } = require("../util/serialization"); /** @typedef {import("../RequestShortener")} RequestShortener */ /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */ /** @typedef {import("../WebpackError")} WebpackError */ +/** @typedef {import("../dependencies/HarmonyImportDependency")} HarmonyImportDependency */ /** @typedef {import("../util/Hash")} Hash */ /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */ @@ -38,7 +39,7 @@ const { registerNotSerializable } = require("../util/serialization"); * @property {function(Module): { client: string, data: string, active: boolean }} module */ -const IGNORED_DEPENDENCY_TYPES = new Set([ +const HMR_DEPENDENCY_TYPES = new Set([ "import.meta.webpackHot.accept", "import.meta.webpackHot.decline", "module.hot.accept", @@ -351,32 +352,55 @@ class LazyCompilationPlugin { "LazyCompilationPlugin", (originalModule, createData, resolveData) => { if ( - resolveData.dependencies.every( + resolveData.dependencies.every(dep => + HMR_DEPENDENCY_TYPES.has(dep.type) + ) + ) { + // for HMR only resolving, try to determine if the HMR accept/decline refers to + // an import() or not + const hmrDep = resolveData.dependencies[0]; + const originModule = + compilation.moduleGraph.getParentModule(hmrDep); + const isReferringToDynamicImport = originModule.blocks.some( + block => + block.dependencies.some( + dep => + dep.type === "import()" && + /** @type {HarmonyImportDependency} */ (dep).request === + hmrDep.request + ) + ); + if (!isReferringToDynamicImport) return; + } else if ( + !resolveData.dependencies.every( dep => - IGNORED_DEPENDENCY_TYPES.has(dep.type) || + HMR_DEPENDENCY_TYPES.has(dep.type) || (this.imports && (dep.type === "import()" || dep.type === "import() context element")) || (this.entries && dep.type === "entry") - ) && - !/webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client/.test( + ) + ) + return; + if ( + /webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client/.test( resolveData.request - ) && - checkTest(this.test, originalModule) - ) { - const moduleInfo = backend.module(originalModule); - if (!moduleInfo) return; - const { client, data, active } = moduleInfo; + ) || + !checkTest(this.test, originalModule) + ) + return; + const moduleInfo = backend.module(originalModule); + if (!moduleInfo) return; + const { client, data, active } = moduleInfo; - return new LazyCompilationProxyModule( - compiler.context, - originalModule, - resolveData.request, - client, - data, - active - ); - } + return new LazyCompilationProxyModule( + compiler.context, + originalModule, + resolveData.request, + client, + data, + active + ); } ); compilation.dependencyFactories.set( diff --git a/test/hotCases/lazy-compilation/simple/index.js b/test/hotCases/lazy-compilation/simple/index.js index 1c17e850915..187b2bb4181 100644 --- a/test/hotCases/lazy-compilation/simple/index.js +++ b/test/hotCases/lazy-compilation/simple/index.js @@ -20,9 +20,21 @@ it("should compile to lazy imported module", done => { expect(generation).toBe(1); import("./module").then(result => { expect(result).toHaveProperty("default", 43); - setTimeout(() => { - done(); - }, 1000); + expect(generation).toBe(1); + module.hot.accept("./module", () => { + generation += 10; + }); + NEXT( + require("../../update")(done, true, () => { + import("./module").then(result => { + expect(result).toHaveProperty("default", 44); + expect(generation).toBe(11); + setTimeout(() => { + done(); + }, 1000); + }, done); + }) + ); }, done); }) ); diff --git a/test/hotCases/lazy-compilation/simple/module.js b/test/hotCases/lazy-compilation/simple/module.js index 48e48492637..84c81da2983 100644 --- a/test/hotCases/lazy-compilation/simple/module.js +++ b/test/hotCases/lazy-compilation/simple/module.js @@ -3,3 +3,5 @@ export default 42; export default 42; --- export default 43; +--- +export default 44; diff --git a/test/hotCases/lazy-compilation/unrelated/index.js b/test/hotCases/lazy-compilation/unrelated/index.js new file mode 100644 index 00000000000..9481047251f --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/index.js @@ -0,0 +1,25 @@ +import value from "./module"; + +const neverCalled = () => import("./lazy"); + +it("should compile to lazy imported module", done => { + let generation = 0; + module.hot.accept("./module", () => { + generation++; + }); + expect(value).toBe(42); + expect(generation).toBe(0); + NEXT( + require("../../update")(done, true, () => { + expect(value).toBe(43); + expect(generation).toBe(1); + NEXT( + require("../../update")(done, true, () => { + expect(value).toBe(44); + expect(generation).toBe(2); + done(); + }) + ); + }) + ); +}); diff --git a/test/hotCases/lazy-compilation/unrelated/lazy.js b/test/hotCases/lazy-compilation/unrelated/lazy.js new file mode 100644 index 00000000000..05e08712040 --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/lazy.js @@ -0,0 +1 @@ +export default 123; diff --git a/test/hotCases/lazy-compilation/unrelated/module.js b/test/hotCases/lazy-compilation/unrelated/module.js new file mode 100644 index 00000000000..d099aaa344e --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/module.js @@ -0,0 +1,5 @@ +export default 42; +--- +export default 43; +--- +export default 44; diff --git a/test/hotCases/lazy-compilation/unrelated/webpack.config.js b/test/hotCases/lazy-compilation/unrelated/webpack.config.js new file mode 100644 index 00000000000..aef58ef1aaf --- /dev/null +++ b/test/hotCases/lazy-compilation/unrelated/webpack.config.js @@ -0,0 +1,10 @@ +"use strict"; + +/** @type {import("../../../../").Configuration} */ +module.exports = { + experiments: { + lazyCompilation: { + entries: false + } + } +};