webpack 5.89.0 → 5.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (148) hide show
  1. package/README.md +3 -0
  2. package/bin/webpack.js +1 -3
  3. package/hot/log.js +0 -2
  4. package/lib/APIPlugin.js +1 -1
  5. package/lib/ChunkGraph.js +1 -1
  6. package/lib/CleanPlugin.js +12 -12
  7. package/lib/Compilation.js +25 -16
  8. package/lib/Compiler.js +13 -0
  9. package/lib/ConcatenationScope.js +2 -2
  10. package/lib/ContextModule.js +4 -4
  11. package/lib/ContextModuleFactory.js +1 -1
  12. package/lib/DependencyTemplate.js +3 -1
  13. package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
  14. package/lib/EvalDevToolModulePlugin.js +1 -1
  15. package/lib/EvalSourceMapDevToolPlugin.js +1 -1
  16. package/lib/ExportsInfoApiPlugin.js +2 -2
  17. package/lib/ExternalModule.js +47 -12
  18. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  19. package/lib/FileSystemInfo.js +20 -3
  20. package/lib/FlagDependencyExportsPlugin.js +1 -1
  21. package/lib/Generator.js +1 -0
  22. package/lib/HotModuleReplacementPlugin.js +3 -3
  23. package/lib/LibManifestPlugin.js +4 -1
  24. package/lib/Module.js +2 -1
  25. package/lib/ModuleFilenameHelpers.js +1 -1
  26. package/lib/ModuleInfoHeaderPlugin.js +1 -1
  27. package/lib/MultiStats.js +2 -2
  28. package/lib/NodeStuffPlugin.js +48 -0
  29. package/lib/NormalModule.js +13 -11
  30. package/lib/NormalModuleFactory.js +7 -7
  31. package/lib/RuntimeTemplate.js +15 -11
  32. package/lib/SourceMapDevToolPlugin.js +2 -2
  33. package/lib/WebpackOptionsApply.js +4 -3
  34. package/lib/asset/AssetModulesPlugin.js +2 -3
  35. package/lib/cache/AddManagedPathsPlugin.js +6 -1
  36. package/lib/cache/IdleFileCachePlugin.js +12 -5
  37. package/lib/cache/PackFileCacheStrategy.js +3 -3
  38. package/lib/cache/ResolverCachePlugin.js +2 -2
  39. package/lib/config/browserslistTargetHandler.js +24 -5
  40. package/lib/config/defaults.js +87 -52
  41. package/lib/config/normalization.js +17 -18
  42. package/lib/config/target.js +5 -0
  43. package/lib/container/ContainerReferencePlugin.js +1 -1
  44. package/lib/css/CssExportsGenerator.js +14 -1
  45. package/lib/css/CssGenerator.js +14 -1
  46. package/lib/css/CssLoadingRuntimeModule.js +23 -23
  47. package/lib/css/CssModulesPlugin.js +68 -32
  48. package/lib/css/CssParser.js +8 -3
  49. package/lib/debug/ProfilingPlugin.js +2 -2
  50. package/lib/dependencies/CachedConstDependency.js +8 -1
  51. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  52. package/lib/dependencies/ContextElementDependency.js +1 -1
  53. package/lib/dependencies/ExternalModuleDependency.js +98 -0
  54. package/lib/dependencies/ExternalModuleInitFragment.js +124 -0
  55. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  56. package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
  57. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
  58. package/lib/dependencies/HarmonyExportInitFragment.js +4 -4
  59. package/lib/dependencies/HarmonyImportDependency.js +4 -4
  60. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
  61. package/lib/dependencies/ImportDependency.js +26 -6
  62. package/lib/dependencies/JsonExportsDependency.js +1 -1
  63. package/lib/dependencies/LoaderPlugin.js +2 -1
  64. package/lib/dependencies/PureExpressionDependency.js +12 -4
  65. package/lib/dependencies/RequireIncludeDependency.js +1 -1
  66. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
  67. package/lib/dependencies/WorkerPlugin.js +7 -1
  68. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
  69. package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
  70. package/lib/hmr/lazyCompilationBackend.js +4 -4
  71. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  72. package/lib/index.js +4 -0
  73. package/lib/javascript/JavascriptGenerator.js +16 -1
  74. package/lib/javascript/JavascriptModulesPlugin.js +33 -33
  75. package/lib/javascript/JavascriptParser.js +8 -0
  76. package/lib/json/JsonGenerator.js +1 -1
  77. package/lib/library/AmdLibraryPlugin.js +5 -1
  78. package/lib/library/AssignLibraryPlugin.js +1 -1
  79. package/lib/library/SystemLibraryPlugin.js +1 -1
  80. package/lib/library/UmdLibraryPlugin.js +39 -39
  81. package/lib/logging/createConsoleLogger.js +1 -19
  82. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
  83. package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
  84. package/lib/node/nodeConsole.js +1 -5
  85. package/lib/optimize/ConcatenatedModule.js +7 -7
  86. package/lib/optimize/InnerGraphPlugin.js +9 -1
  87. package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
  88. package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
  89. package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
  90. package/lib/optimize/SplitChunksPlugin.js +16 -16
  91. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
  92. package/lib/rules/RuleSetCompiler.js +1 -1
  93. package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
  94. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
  95. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
  96. package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
  97. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
  98. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
  99. package/lib/schemes/HttpUriPlugin.js +1 -1
  100. package/lib/serialization/FileMiddleware.js +4 -4
  101. package/lib/serialization/ObjectMiddleware.js +4 -4
  102. package/lib/sharing/ConsumeSharedPlugin.js +5 -5
  103. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
  104. package/lib/sharing/ProvideSharedModule.js +2 -2
  105. package/lib/sharing/SharePlugin.js +2 -2
  106. package/lib/sharing/ShareRuntimeModule.js +1 -1
  107. package/lib/sharing/utils.js +24 -28
  108. package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
  109. package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
  110. package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
  111. package/lib/util/cleverMerge.js +4 -4
  112. package/lib/util/hash/xxhash64.js +2 -2
  113. package/lib/util/identifier.js +2 -2
  114. package/lib/util/internalSerializables.js +6 -0
  115. package/lib/util/runtime.js +18 -1
  116. package/lib/util/semver.js +19 -24
  117. package/lib/util/smartGrouping.js +1 -1
  118. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
  119. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
  120. package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
  121. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  122. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
  123. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
  124. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
  125. package/package.json +23 -23
  126. package/schemas/WebpackOptions.check.js +1 -1
  127. package/schemas/WebpackOptions.json +140 -32
  128. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
  129. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
  130. package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
  131. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
  132. package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
  133. package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
  134. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  135. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
  136. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
  137. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
  138. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
  139. package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
  140. package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
  141. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  142. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  143. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  144. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  145. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  146. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  147. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  148. package/types.d.ts +172 -20
@@ -113,10 +113,10 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
113
113
  withOnChunkLoad
114
114
  ? `${
115
115
  RuntimeGlobals.onChunksLoaded
116
- }.readFileVm = ${runtimeTemplate.returningFunction(
116
+ }.readFileVm = ${runtimeTemplate.returningFunction(
117
117
  "installedChunks[chunkId] === 0",
118
118
  "chunkId"
119
- )};`
119
+ )};`
120
120
  : "// no on chunks loaded",
121
121
  "",
122
122
  withLoading || withExternalInstallChunk
@@ -141,7 +141,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
141
141
  ]),
142
142
  "}",
143
143
  withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : ""
144
- ])};`
144
+ ])};`
145
145
  : "// no chunk install function needed",
146
146
  "",
147
147
  withLoading
@@ -192,17 +192,17 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
192
192
  "}"
193
193
  ]),
194
194
  "}"
195
- ])
195
+ ])
196
196
  : Template.indent(["installedChunks[chunkId] = 0;"]),
197
197
  "};"
198
- ])
198
+ ])
199
199
  : "// no chunk loading",
200
200
  "",
201
201
  withExternalInstallChunk
202
202
  ? Template.asString([
203
203
  `module.exports = ${RuntimeGlobals.require};`,
204
204
  `${RuntimeGlobals.externalInstallChunk} = installChunk;`
205
- ])
205
+ ])
206
206
  : "// no external install chunk",
207
207
  "",
208
208
  withHmr
@@ -263,7 +263,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
263
263
  /\$hmrInvalidateModuleHandlers\$/g,
264
264
  RuntimeGlobals.hmrInvalidateModuleHandlers
265
265
  )
266
- ])
266
+ ])
267
267
  : "// no HMR",
268
268
  "",
269
269
  withHmrManifest
@@ -291,7 +291,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
291
291
  "});"
292
292
  ]),
293
293
  "}"
294
- ])
294
+ ])
295
295
  : "// no HMR manifest"
296
296
  ]);
297
297
  }
@@ -113,10 +113,10 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
113
113
  withOnChunkLoad
114
114
  ? `${
115
115
  RuntimeGlobals.onChunksLoaded
116
- }.require = ${runtimeTemplate.returningFunction(
116
+ }.require = ${runtimeTemplate.returningFunction(
117
117
  "installedChunks[chunkId]",
118
118
  "chunkId"
119
- )};`
119
+ )};`
120
120
  : "// no on chunks loaded",
121
121
  "",
122
122
  withLoading || withExternalInstallChunk
@@ -135,7 +135,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
135
135
  "for(var i = 0; i < chunkIds.length; i++)",
136
136
  Template.indent("installedChunks[chunkIds[i]] = 1;"),
137
137
  withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : ""
138
- ])};`
138
+ ])};`
139
139
  : "// no chunk install function needed",
140
140
  "",
141
141
  withLoading
@@ -162,17 +162,17 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
162
162
  ""
163
163
  ]),
164
164
  "}"
165
- ]
165
+ ]
166
166
  : "installedChunks[chunkId] = 1;"
167
167
  )};`
168
- ])
168
+ ])
169
169
  : "// no chunk loading",
170
170
  "",
171
171
  withExternalInstallChunk
172
172
  ? Template.asString([
173
173
  `module.exports = ${RuntimeGlobals.require};`,
174
174
  `${RuntimeGlobals.externalInstallChunk} = installChunk;`
175
- ])
175
+ ])
176
176
  : "// no external install chunk",
177
177
  "",
178
178
  withHmr
@@ -220,7 +220,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
220
220
  /\$hmrInvalidateModuleHandlers\$/g,
221
221
  RuntimeGlobals.hmrInvalidateModuleHandlers
222
222
  )
223
- ])
223
+ ])
224
224
  : "// no HMR",
225
225
  "",
226
226
  withHmrManifest
@@ -236,7 +236,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
236
236
  "})['catch'](function(err) { if(err.code !== 'MODULE_NOT_FOUND') throw err; });"
237
237
  ]),
238
238
  "}"
239
- ])
239
+ ])
240
240
  : "// no HMR manifest"
241
241
  ]);
242
242
  }
@@ -102,17 +102,13 @@ module.exports = ({ colors, appendOnly, stream }) => {
102
102
  else if (currentIndent.length >= 2)
103
103
  currentIndent = currentIndent.slice(0, currentIndent.length - 2);
104
104
  },
105
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
106
105
  profile: console.profile && (name => console.profile(name)),
107
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
108
106
  profileEnd: console.profileEnd && (name => console.profileEnd(name)),
109
107
  clear:
110
108
  !appendOnly &&
111
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
112
109
  console.clear &&
113
110
  (() => {
114
111
  clearStatusMessage();
115
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
116
112
  console.clear();
117
113
  writeStatusMessage();
118
114
  }),
@@ -136,6 +132,6 @@ module.exports = ({ colors, appendOnly, stream }) => {
136
132
  currentStatusMessage = [name, ...args];
137
133
  writeStatusMessage();
138
134
  }
139
- }
135
+ }
140
136
  };
141
137
  };
@@ -335,10 +335,10 @@ const getFinalBinding = (
335
335
  const defaultExport = asCall
336
336
  ? `${info.interopDefaultAccessName}()`
337
337
  : asiSafe
338
- ? `(${info.interopDefaultAccessName}())`
339
- : asiSafe === false
340
- ? `;(${info.interopDefaultAccessName}())`
341
- : `${info.interopDefaultAccessName}.a`;
338
+ ? `(${info.interopDefaultAccessName}())`
339
+ : asiSafe === false
340
+ ? `;(${info.interopDefaultAccessName}())`
341
+ : `${info.interopDefaultAccessName}.a`;
342
342
  return {
343
343
  info,
344
344
  rawName: defaultExport,
@@ -568,8 +568,8 @@ const getFinalName = (
568
568
  return asiSafe
569
569
  ? `(0,${reference})`
570
570
  : asiSafe === false
571
- ? `;(0,${reference})`
572
- : `/*#__PURE__*/Object(${reference})`;
571
+ ? `;(0,${reference})`
572
+ : `/*#__PURE__*/Object(${reference})`;
573
573
  }
574
574
  return reference;
575
575
  }
@@ -1541,7 +1541,7 @@ class ConcatenatedModule extends Module {
1541
1541
  nsObj.length > 0
1542
1542
  ? `${RuntimeGlobals.definePropertyGetters}(${name}, {${nsObj.join(
1543
1543
  ","
1544
- )}\n});\n`
1544
+ )}\n});\n`
1545
1545
  : "";
1546
1546
  if (nsObj.length > 0)
1547
1547
  runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
@@ -177,7 +177,6 @@ class InnerGraphPlugin {
177
177
  ) {
178
178
  pureDeclarators.add(decl);
179
179
  }
180
- return true;
181
180
  }
182
181
  }
183
182
  });
@@ -336,6 +335,15 @@ class InnerGraphPlugin {
336
335
  parser.walkExpression(decl.init);
337
336
  InnerGraph.setTopLevelSymbol(parser.state, undefined);
338
337
  return true;
338
+ } else if (
339
+ decl.id.type === "Identifier" &&
340
+ decl.init &&
341
+ decl.init.type === "ClassExpression" &&
342
+ classWithTopLevelSymbol.has(decl.init)
343
+ ) {
344
+ parser.walkExpression(decl.init);
345
+ InnerGraph.setTopLevelSymbol(parser.state, undefined);
346
+ return true;
339
347
  }
340
348
  });
341
349
 
@@ -284,8 +284,8 @@ class ModuleConcatenationPlugin {
284
284
  filteredRuntime === true
285
285
  ? chunkRuntime
286
286
  : filteredRuntime === false
287
- ? undefined
288
- : filteredRuntime;
287
+ ? undefined
288
+ : filteredRuntime;
289
289
 
290
290
  // create a configuration with the root
291
291
  const currentConfiguration = new ConcatConfiguration(
@@ -6,12 +6,58 @@
6
6
  "use strict";
7
7
 
8
8
  const { STAGE_BASIC } = require("../OptimizationStages");
9
- const Queue = require("../util/Queue");
10
- const { intersect } = require("../util/SetHelpers");
11
9
 
12
10
  /** @typedef {import("../Chunk")} Chunk */
13
11
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
14
12
  /** @typedef {import("../Compiler")} Compiler */
13
+ /** @typedef {import("../Module")} Module */
14
+
15
+ /**
16
+ * Intersects multiple masks represented as bigints
17
+ * @param {bigint[]} masks The module masks to intersect
18
+ * @returns {bigint} The intersection of all masks
19
+ */
20
+ function intersectMasks(masks) {
21
+ let result = masks[0];
22
+ for (let i = masks.length - 1; i >= 1; i--) {
23
+ result &= masks[i];
24
+ }
25
+ return result;
26
+ }
27
+
28
+ const ZERO_BIGINT = BigInt(0);
29
+ const ONE_BIGINT = BigInt(1);
30
+ const THIRTY_TWO_BIGINT = BigInt(32);
31
+
32
+ /**
33
+ * Parses the module mask and returns the modules represented by it
34
+ * @param {bigint} mask the module mask
35
+ * @param {Module[]} ordinalModules the modules in the order they were added to the mask (LSB is index 0)
36
+ * @returns {Generator<Module>} the modules represented by the mask
37
+ */
38
+ function* getModulesFromMask(mask, ordinalModules) {
39
+ let offset = 31;
40
+ while (mask !== ZERO_BIGINT) {
41
+ // Consider the last 32 bits, since that's what Math.clz32 can handle
42
+ let last32 = Number(BigInt.asUintN(32, mask));
43
+ while (last32 > 0) {
44
+ let last = Math.clz32(last32);
45
+ // The number of trailing zeros is the number trimmed off the input mask + 31 - the number of leading zeros
46
+ // The 32 is baked into the initial value of offset
47
+ const moduleIndex = offset - last;
48
+ // The number of trailing zeros is the index into the array generated by getOrCreateModuleMask
49
+ const module = ordinalModules[moduleIndex];
50
+ yield module;
51
+ // Remove the matched module from the mask
52
+ // Since we can only count leading zeros, not trailing, we can't just downshift the mask
53
+ last32 &= ~(1 << (31 - last));
54
+ }
55
+
56
+ // Remove the processed chunk from the mask
57
+ mask >>= THIRTY_TWO_BIGINT;
58
+ offset += 32;
59
+ }
60
+ }
15
61
 
16
62
  class RemoveParentModulesPlugin {
17
63
  /**
@@ -26,92 +72,122 @@ class RemoveParentModulesPlugin {
26
72
  */
27
73
  const handler = (chunks, chunkGroups) => {
28
74
  const chunkGraph = compilation.chunkGraph;
29
- const queue = new Queue();
75
+ const queue = new Set();
30
76
  const availableModulesMap = new WeakMap();
31
77
 
78
+ let nextModuleMask = ONE_BIGINT;
79
+ const maskByModule = new WeakMap();
80
+ const ordinalModules = [];
81
+
82
+ /**
83
+ * Gets or creates a unique mask for a module
84
+ * @param {Module} mod the module to get the mask for
85
+ * @returns {bigint} the module mask to uniquely identify the module
86
+ */
87
+ const getOrCreateModuleMask = mod => {
88
+ let id = maskByModule.get(mod);
89
+ if (id === undefined) {
90
+ id = nextModuleMask;
91
+ ordinalModules.push(mod);
92
+ maskByModule.set(mod, id);
93
+ nextModuleMask <<= ONE_BIGINT;
94
+ }
95
+ return id;
96
+ };
97
+
98
+ // Initialize masks by chunk and by chunk group for quicker comparisons
99
+ const chunkMasks = new WeakMap();
100
+ for (const chunk of chunks) {
101
+ let mask = ZERO_BIGINT;
102
+ for (const m of chunkGraph.getChunkModulesIterable(chunk)) {
103
+ const id = getOrCreateModuleMask(m);
104
+ mask |= id;
105
+ }
106
+ chunkMasks.set(chunk, mask);
107
+ }
108
+
109
+ const chunkGroupMasks = new WeakMap();
110
+ for (const chunkGroup of chunkGroups) {
111
+ let mask = ZERO_BIGINT;
112
+ for (const chunk of chunkGroup.chunks) {
113
+ const chunkMask = chunkMasks.get(chunk);
114
+ if (chunkMask !== undefined) {
115
+ mask |= chunkMask;
116
+ }
117
+ }
118
+ chunkGroupMasks.set(chunkGroup, mask);
119
+ }
120
+
32
121
  for (const chunkGroup of compilation.entrypoints.values()) {
33
122
  // initialize available modules for chunks without parents
34
- availableModulesMap.set(chunkGroup, new Set());
123
+ availableModulesMap.set(chunkGroup, ZERO_BIGINT);
35
124
  for (const child of chunkGroup.childrenIterable) {
36
- queue.enqueue(child);
125
+ queue.add(child);
37
126
  }
38
127
  }
39
128
  for (const chunkGroup of compilation.asyncEntrypoints) {
40
129
  // initialize available modules for chunks without parents
41
- availableModulesMap.set(chunkGroup, new Set());
130
+ availableModulesMap.set(chunkGroup, ZERO_BIGINT);
42
131
  for (const child of chunkGroup.childrenIterable) {
43
- queue.enqueue(child);
132
+ queue.add(child);
44
133
  }
45
134
  }
46
135
 
47
- while (queue.length > 0) {
48
- const chunkGroup = queue.dequeue();
49
- let availableModules = availableModulesMap.get(chunkGroup);
136
+ for (const chunkGroup of queue) {
137
+ let availableModulesMask = availableModulesMap.get(chunkGroup);
50
138
  let changed = false;
51
139
  for (const parent of chunkGroup.parentsIterable) {
52
140
  const availableModulesInParent = availableModulesMap.get(parent);
53
141
  if (availableModulesInParent !== undefined) {
142
+ const parentMask =
143
+ availableModulesInParent | chunkGroupMasks.get(parent);
54
144
  // If we know the available modules in parent: process these
55
- if (availableModules === undefined) {
145
+ if (availableModulesMask === undefined) {
56
146
  // if we have not own info yet: create new entry
57
- availableModules = new Set(availableModulesInParent);
58
- for (const chunk of parent.chunks) {
59
- for (const m of chunkGraph.getChunkModulesIterable(chunk)) {
60
- availableModules.add(m);
61
- }
62
- }
63
- availableModulesMap.set(chunkGroup, availableModules);
147
+ availableModulesMask = parentMask;
64
148
  changed = true;
65
149
  } else {
66
- for (const m of availableModules) {
67
- if (
68
- !chunkGraph.isModuleInChunkGroup(m, parent) &&
69
- !availableModulesInParent.has(m)
70
- ) {
71
- availableModules.delete(m);
72
- changed = true;
73
- }
150
+ let newMask = availableModulesMask & parentMask;
151
+ if (newMask !== availableModulesMask) {
152
+ changed = true;
153
+ availableModulesMask = newMask;
74
154
  }
75
155
  }
76
156
  }
77
157
  }
158
+
78
159
  if (changed) {
160
+ availableModulesMap.set(chunkGroup, availableModulesMask);
79
161
  // if something changed: enqueue our children
80
162
  for (const child of chunkGroup.childrenIterable) {
81
- queue.enqueue(child);
163
+ // Push the child to the end of the queue
164
+ queue.delete(child);
165
+ queue.add(child);
82
166
  }
83
167
  }
84
168
  }
85
169
 
86
170
  // now we have available modules for every chunk
87
171
  for (const chunk of chunks) {
172
+ const chunkMask = chunkMasks.get(chunk);
173
+ if (chunkMask === undefined) continue; // No info about this chunk
174
+
88
175
  const availableModulesSets = Array.from(
89
176
  chunk.groupsIterable,
90
177
  chunkGroup => availableModulesMap.get(chunkGroup)
91
178
  );
92
179
  if (availableModulesSets.some(s => s === undefined)) continue; // No info about this chunk group
93
- const availableModules =
94
- availableModulesSets.length === 1
95
- ? availableModulesSets[0]
96
- : intersect(availableModulesSets);
97
- const numberOfModules = chunkGraph.getNumberOfChunkModules(chunk);
98
- const toRemove = new Set();
99
- if (numberOfModules < availableModules.size) {
100
- for (const m of chunkGraph.getChunkModulesIterable(chunk)) {
101
- if (availableModules.has(m)) {
102
- toRemove.add(m);
103
- }
104
- }
105
- } else {
106
- for (const m of availableModules) {
107
- if (chunkGraph.isModuleInChunk(m, chunk)) {
108
- toRemove.add(m);
109
- }
180
+
181
+ const availableModulesMask = intersectMasks(availableModulesSets);
182
+ const toRemoveMask = chunkMask & availableModulesMask;
183
+ if (toRemoveMask !== ZERO_BIGINT) {
184
+ for (const module of getModulesFromMask(
185
+ toRemoveMask,
186
+ ordinalModules
187
+ )) {
188
+ chunkGraph.disconnectChunkAndModule(chunk, module);
110
189
  }
111
190
  }
112
- for (const module of toRemove) {
113
- chunkGraph.disconnectChunkAndModule(chunk, module);
114
- }
115
191
  }
116
192
  };
117
193
  compilation.hooks.optimizeChunks.tap(
@@ -159,8 +159,8 @@ class SideEffectsFlagPlugin {
159
159
  statement.test
160
160
  ? statement.test.range[1]
161
161
  : statement.init
162
- ? statement.init.range[1]
163
- : statement.range[0]
162
+ ? statement.init.range[1]
163
+ : statement.range[0]
164
164
  )
165
165
  ) {
166
166
  sideEffectsStatement = statement;
@@ -243,7 +243,12 @@ class SideEffectsFlagPlugin {
243
243
  );
244
244
 
245
245
  logger.time("update dependencies");
246
- for (const module of modules) {
246
+
247
+ const optimizedModules = new Set();
248
+
249
+ const optimizeIncomingConnections = module => {
250
+ if (optimizedModules.has(module)) return;
251
+ optimizedModules.add(module);
247
252
  if (module.getSideEffectsConnectionState(moduleGraph) === false) {
248
253
  const exportsInfo = moduleGraph.getExportsInfo(module);
249
254
  for (const connection of moduleGraph.getIncomingConnections(
@@ -258,6 +263,9 @@ class SideEffectsFlagPlugin {
258
263
  (dep instanceof HarmonyImportSpecifierDependency &&
259
264
  !dep.namespaceObjectAsContext)
260
265
  ) {
266
+ if (connection.originModule !== null) {
267
+ optimizeIncomingConnections(connection.originModule);
268
+ }
261
269
  // TODO improve for export *
262
270
  if (isReexport && dep.name) {
263
271
  const exportInfo = moduleGraph.getExportInfo(
@@ -314,6 +322,10 @@ class SideEffectsFlagPlugin {
314
322
  }
315
323
  }
316
324
  }
325
+ };
326
+
327
+ for (const module of modules) {
328
+ optimizeIncomingConnections(module);
317
329
  }
318
330
  logger.timeEnd("update dependencies");
319
331
  }
@@ -749,20 +749,20 @@ module.exports = class SplitChunksPlugin {
749
749
  cacheGroupSource.minChunks !== undefined
750
750
  ? cacheGroupSource.minChunks
751
751
  : cacheGroupSource.enforce
752
- ? 1
753
- : this.options.minChunks,
752
+ ? 1
753
+ : this.options.minChunks,
754
754
  maxAsyncRequests:
755
755
  cacheGroupSource.maxAsyncRequests !== undefined
756
756
  ? cacheGroupSource.maxAsyncRequests
757
757
  : cacheGroupSource.enforce
758
- ? Infinity
759
- : this.options.maxAsyncRequests,
758
+ ? Infinity
759
+ : this.options.maxAsyncRequests,
760
760
  maxInitialRequests:
761
761
  cacheGroupSource.maxInitialRequests !== undefined
762
762
  ? cacheGroupSource.maxInitialRequests
763
763
  : cacheGroupSource.enforce
764
- ? Infinity
765
- : this.options.maxInitialRequests,
764
+ ? Infinity
765
+ : this.options.maxInitialRequests,
766
766
  getName:
767
767
  cacheGroupSource.getName !== undefined
768
768
  ? cacheGroupSource.getName
@@ -1428,13 +1428,13 @@ module.exports = class SplitChunksPlugin {
1428
1428
  chunk.isOnlyInitial()
1429
1429
  ? item.cacheGroup.maxInitialRequests
1430
1430
  : chunk.canBeInitial()
1431
- ? Math.min(
1432
- /** @type {number} */
1433
- (item.cacheGroup.maxInitialRequests),
1434
- /** @type {number} */
1435
- (item.cacheGroup.maxAsyncRequests)
1436
- )
1437
- : item.cacheGroup.maxAsyncRequests
1431
+ ? Math.min(
1432
+ /** @type {number} */
1433
+ (item.cacheGroup.maxInitialRequests),
1434
+ /** @type {number} */
1435
+ (item.cacheGroup.maxAsyncRequests)
1436
+ )
1437
+ : item.cacheGroup.maxAsyncRequests
1438
1438
  );
1439
1439
  if (
1440
1440
  isFinite(maxRequests) &&
@@ -1569,21 +1569,21 @@ module.exports = class SplitChunksPlugin {
1569
1569
  oldMaxSizeSettings.minSize,
1570
1570
  item.cacheGroup._minSizeForMaxSize,
1571
1571
  Math.max
1572
- )
1572
+ )
1573
1573
  : item.cacheGroup.minSize,
1574
1574
  maxAsyncSize: oldMaxSizeSettings
1575
1575
  ? combineSizes(
1576
1576
  oldMaxSizeSettings.maxAsyncSize,
1577
1577
  item.cacheGroup.maxAsyncSize,
1578
1578
  Math.min
1579
- )
1579
+ )
1580
1580
  : item.cacheGroup.maxAsyncSize,
1581
1581
  maxInitialSize: oldMaxSizeSettings
1582
1582
  ? combineSizes(
1583
1583
  oldMaxSizeSettings.maxInitialSize,
1584
1584
  item.cacheGroup.maxInitialSize,
1585
1585
  Math.min
1586
- )
1586
+ )
1587
1587
  : item.cacheGroup.maxInitialSize,
1588
1588
  automaticNameDelimiter: item.cacheGroup.automaticNameDelimiter,
1589
1589
  keys: oldMaxSizeSettings
@@ -42,10 +42,10 @@ class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
42
42
  chunks,
43
43
  c =>
44
44
  `${RuntimeGlobals.prefetchChunk}(${JSON.stringify(c.id)});`
45
- )
45
+ )
46
46
  : `${JSON.stringify(Array.from(chunks, c => c.id))}.map(${
47
47
  RuntimeGlobals.prefetchChunk
48
- });`
48
+ });`
49
49
  )}, 5);`
50
50
  )
51
51
  );
@@ -272,7 +272,7 @@ class RuleSetCompiler {
272
272
  if (!Array.isArray(value)) {
273
273
  throw this.error(
274
274
  `${path}.or`,
275
- condition.and,
275
+ condition.or,
276
276
  "Expected array of conditions"
277
277
  );
278
278
  }
@@ -63,7 +63,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
63
63
  "}"
64
64
  ]),
65
65
  "}"
66
- ]),
66
+ ]),
67
67
  "// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration",
68
68
  '// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.',
69
69
  'if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");',
@@ -72,7 +72,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
72
72
  ? `${RuntimeGlobals.publicPath} = scriptUrl;`
73
73
  : `${RuntimeGlobals.publicPath} = scriptUrl + ${JSON.stringify(
74
74
  undoPath
75
- )};`
75
+ )};`
76
76
  ]);
77
77
  }
78
78
  }
@@ -152,7 +152,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
152
152
  chunk: c,
153
153
  contentHashType: contentType
154
154
  })
155
- )
155
+ )
156
156
  : JSON.stringify(chunkFilename);
157
157
  const staticChunkFilename = compilation.getPath(chunkFilenameValue, {
158
158
  hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
@@ -219,7 +219,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
219
219
  return useId
220
220
  ? `(chunkId === ${JSON.stringify(lastKey)} ? ${JSON.stringify(
221
221
  obj[/** @type {number | string} */ (lastKey)]
222
- )} : chunkId)`
222
+ )} : chunkId)`
223
223
  : JSON.stringify(obj[/** @type {number | string} */ (lastKey)]);
224
224
  }
225
225
  return useId
@@ -285,13 +285,13 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
285
285
  : `{${Array.from(
286
286
  ids,
287
287
  id => `${JSON.stringify(id)}:1`
288
- ).join(",")}}[chunkId]`;
288
+ ).join(",")}}[chunkId]`;
289
289
  return `if (${condition}) return ${url};`;
290
290
  })
291
291
  ),
292
292
  "// return url for filenames based on template",
293
293
  `return ${url};`
294
- ]
294
+ ]
295
295
  : ["// return url for filenames based on template", `return ${url};`]
296
296
  )};`
297
297
  ]);
@@ -46,7 +46,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
46
46
  "script",
47
47
  "script"
48
48
  )}`
49
- ]
49
+ ]
50
50
  : []),
51
51
  ...(this.runtimeRequirements.has(RuntimeGlobals.createScriptUrl)
52
52
  ? [
@@ -54,7 +54,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
54
54
  "url",
55
55
  "url"
56
56
  )}`
57
- ]
57
+ ]
58
58
  : [])
59
59
  ].join(",\n")
60
60
  ),
@@ -80,11 +80,11 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
80
80
  )}');`
81
81
  ]),
82
82
  "}"
83
- ]
83
+ ]
84
84
  : [])
85
85
  ]),
86
86
  "}"
87
- ]
87
+ ]
88
88
  : [])
89
89
  ]),
90
90
  "}",