webpack 5.108.4 → 5.109.1

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.
Files changed (200) hide show
  1. package/bin/webpack.js +12 -0
  2. package/lib/APIPlugin.js +48 -29
  3. package/lib/CacheFacade.js +8 -0
  4. package/lib/ChunkGraph.js +17 -15
  5. package/lib/ChunkGroup.js +1 -0
  6. package/lib/CompatibilityPlugin.js +62 -29
  7. package/lib/Compilation.js +58 -6
  8. package/lib/ConstPlugin.js +11 -11
  9. package/lib/ContextModule.js +239 -6
  10. package/lib/ContextModuleFactory.js +139 -14
  11. package/lib/DefinePlugin.js +433 -112
  12. package/lib/Entrypoint.js +1 -1
  13. package/lib/ExportsInfo.js +22 -5
  14. package/lib/ExportsInfoApiPlugin.js +2 -2
  15. package/lib/ExternalModule.js +107 -5
  16. package/lib/ExternalModuleFactoryPlugin.js +20 -1
  17. package/lib/FileSystemInfo.js +256 -100
  18. package/lib/FlagDependencyUsagePlugin.js +33 -12
  19. package/lib/HotModuleReplacementPlugin.js +18 -15
  20. package/lib/InitFragment.js +20 -32
  21. package/lib/Module.js +3 -0
  22. package/lib/ModuleFilenameHelpers.js +2 -2
  23. package/lib/ModuleTypeConstants.js +8 -1
  24. package/lib/MultiCompiler.js +13 -2
  25. package/lib/MultiWatching.js +1 -0
  26. package/lib/NodeStuffPlugin.js +51 -33
  27. package/lib/NormalModule.js +175 -401
  28. package/lib/NormalModuleFactory.js +76 -2
  29. package/lib/ProgressPlugin.js +211 -119
  30. package/lib/ProvidePlugin.js +2 -2
  31. package/lib/RuntimeGlobals.js +47 -0
  32. package/lib/RuntimePlugin.js +67 -107
  33. package/lib/RuntimeTemplate.js +304 -16
  34. package/lib/Template.js +23 -3
  35. package/lib/UseStrictPlugin.js +1 -1
  36. package/lib/WebpackIsIncludedPlugin.js +1 -1
  37. package/lib/WebpackOptionsApply.js +24 -19
  38. package/lib/asset/AssetGenerator.js +110 -28
  39. package/lib/asset/AssetModulesPlugin.js +92 -2
  40. package/lib/asset/WebManifestGenerator.js +164 -0
  41. package/lib/asset/WebManifestParser.js +130 -0
  42. package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
  43. package/lib/async-modules/isGeneratorLowered.js +26 -0
  44. package/lib/cache/PackFileCacheStrategy.js +9 -3
  45. package/lib/config/browserslistTargetHandler.js +40 -0
  46. package/lib/config/defaults.js +219 -29
  47. package/lib/config/normalization.js +26 -0
  48. package/lib/config/target.js +9 -1
  49. package/lib/container/HoistContainerReferencesPlugin.js +47 -55
  50. package/lib/css/CssGenerator.js +40 -31
  51. package/lib/css/CssLoadingRuntimeModule.js +5 -1
  52. package/lib/css/CssModulesPlugin.js +13 -0
  53. package/lib/css/CssParser.js +729 -313
  54. package/lib/css/syntax.js +1371 -861
  55. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
  56. package/lib/dependencies/AMDPlugin.js +2 -2
  57. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
  58. package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
  59. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
  60. package/lib/dependencies/CommonJsExportsDependency.js +47 -2
  61. package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
  62. package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
  63. package/lib/dependencies/CommonJsPlugin.js +2 -2
  64. package/lib/dependencies/CommonJsRequireDependency.js +26 -1
  65. package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
  66. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  67. package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
  68. package/lib/dependencies/CssIcssExportDependency.js +162 -71
  69. package/lib/dependencies/CssUrlDependency.js +35 -4
  70. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
  71. package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
  72. package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
  73. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -1
  74. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
  75. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +17 -9
  76. package/lib/dependencies/HarmonyImportDependency.js +13 -2
  77. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
  78. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -7
  79. package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
  80. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
  81. package/lib/dependencies/HtmlEntryDependency.js +797 -172
  82. package/lib/dependencies/HtmlSourceDependency.js +26 -0
  83. package/lib/dependencies/ImportDependency.js +43 -1
  84. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
  85. package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
  86. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  87. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  88. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  89. package/lib/dependencies/ImportMetaPlugin.js +532 -180
  90. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  91. package/lib/dependencies/ImportParserPlugin.js +80 -17
  92. package/lib/dependencies/ImportPhase.js +10 -8
  93. package/lib/dependencies/LoaderPlugin.js +5 -1
  94. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  95. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
  96. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
  97. package/lib/dependencies/SystemPlugin.js +2 -4
  98. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  99. package/lib/dependencies/URLDependency.js +141 -21
  100. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
  101. package/lib/dependencies/WorkerDependency.js +86 -18
  102. package/lib/dependencies/WorkletDependency.js +278 -0
  103. package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
  104. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
  105. package/lib/errors/LoaderLoadingError.js +20 -0
  106. package/lib/errors/ModuleParseError.js +39 -22
  107. package/lib/errors/NodeStuffInWebError.js +1 -1
  108. package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
  109. package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
  110. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
  111. package/lib/hmr/lazyCompilationBackend.js +51 -12
  112. package/lib/html/HtmlGenerator.js +907 -15
  113. package/lib/html/HtmlModule.js +2 -2
  114. package/lib/html/HtmlModulesPlugin.js +610 -166
  115. package/lib/html/HtmlParser.js +603 -247
  116. package/lib/html/favicon.svg +1 -0
  117. package/lib/html/syntax.js +3451 -2762
  118. package/lib/ids/IdHelpers.js +25 -11
  119. package/lib/index.js +6 -0
  120. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
  121. package/lib/javascript/BasicEvaluatedExpression.js +366 -48
  122. package/lib/javascript/JavascriptGenerator.js +197 -49
  123. package/lib/javascript/JavascriptModulesPlugin.js +178 -24
  124. package/lib/javascript/JavascriptParser.js +704 -355
  125. package/lib/javascript/JavascriptParserHelpers.js +3 -6
  126. package/lib/javascript/syntax.js +5037 -0
  127. package/lib/library/ModuleLibraryPlugin.js +38 -1
  128. package/lib/loaders/LoaderRunner.js +714 -0
  129. package/lib/loaders/loadLoader.js +100 -0
  130. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +29 -2
  131. package/lib/node/ReadFileCompileWasmPlugin.js +24 -2
  132. package/lib/optimize/AggressiveMergingPlugin.js +19 -15
  133. package/lib/optimize/ConcatenatedModule.js +139 -31
  134. package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
  135. package/lib/optimize/InnerGraphPlugin.js +50 -30
  136. package/lib/optimize/ModuleConcatenationPlugin.js +139 -24
  137. package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
  138. package/lib/optimize/SplitChunksPlugin.js +146 -44
  139. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
  140. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
  141. package/lib/prefetch/ResourceHintPlugin.js +687 -0
  142. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  143. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  144. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  145. package/lib/rules/RuleSetCompiler.js +114 -0
  146. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  147. package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
  148. package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
  149. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  150. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  151. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
  152. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
  153. package/lib/schemes/HttpUriPlugin.js +40 -1
  154. package/lib/schemes/VirtualUrlPlugin.js +1 -2
  155. package/lib/serialization/BinaryMiddleware.js +270 -938
  156. package/lib/serialization/FileMiddleware.js +29 -3
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +229 -194
  158. package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
  159. package/lib/stats/DefaultStatsPrinterPlugin.js +36 -168
  160. package/lib/stats/StatsFactory.js +46 -17
  161. package/lib/url/URLParserPlugin.js +66 -13
  162. package/lib/util/AsyncQueue.js +122 -72
  163. package/lib/util/SetHelpers.js +1 -1
  164. package/lib/util/StackedMap.js +122 -48
  165. package/lib/util/binarySearchBounds.js +2 -2
  166. package/lib/util/concatenate.js +40 -14
  167. package/lib/util/createHooksRegistry.js +13 -5
  168. package/lib/util/dataURL.js +2 -2
  169. package/lib/util/deterministicGrouping.js +7 -5
  170. package/lib/util/formatSize.js +6 -2
  171. package/lib/util/globUtils.js +710 -0
  172. package/lib/util/identifier.js +23 -6
  173. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  174. package/lib/util/internalSerializables.js +88 -71
  175. package/lib/util/magicComment.js +121 -25
  176. package/lib/util/numberHash.js +2 -2
  177. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
  178. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
  179. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
  180. package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
  181. package/lib/web/FetchCompileWasmPlugin.js +14 -0
  182. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
  183. package/lib/webpack.js +65 -0
  184. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
  185. package/module.d.ts +21 -0
  186. package/package.json +12 -11
  187. package/schemas/WebpackOptions.check.js +1 -1
  188. package/schemas/WebpackOptions.json +759 -36
  189. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  190. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  191. package/schemas/plugins/ProgressPlugin.json +17 -1
  192. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  194. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  195. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  197. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  198. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  199. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  200. package/types.d.ts +1212 -99
@@ -30,6 +30,19 @@ const {
30
30
  const PLUGIN_NAME = "FlagDependencyUsagePlugin";
31
31
  const PLUGIN_LOGGER_NAME = `webpack.${PLUGIN_NAME}`;
32
32
 
33
+ // Hoisted stateless predicates for setUsedConditionally on the innermost
34
+ // used-export loop, so they aren't re-allocated per export.
35
+ /**
36
+ * @param {import("./ExportsInfo").UsageStateType} used usage state
37
+ * @returns {boolean} whether unused
38
+ */
39
+ const IS_UNUSED = (used) => used === UsageState.Unused;
40
+ /**
41
+ * @param {import("./ExportsInfo").UsageStateType} used usage state
42
+ * @returns {boolean} whether not used
43
+ */
44
+ const IS_NOT_USED = (used) => used !== UsageState.Used;
45
+
33
46
  class FlagDependencyUsagePlugin {
34
47
  /**
35
48
  * Creates an instance of FlagDependencyUsagePlugin.
@@ -162,7 +175,7 @@ class FlagDependencyUsagePlugin {
162
175
  if (nestedInfo) {
163
176
  if (
164
177
  exportInfo.setUsedConditionally(
165
- (used) => used === UsageState.Unused,
178
+ IS_UNUSED,
166
179
  UsageState.OnlyPropertiesUsed,
167
180
  runtime
168
181
  )
@@ -181,7 +194,7 @@ class FlagDependencyUsagePlugin {
181
194
  }
182
195
  if (
183
196
  exportInfo.setUsedConditionally(
184
- (v) => v !== UsageState.Used,
197
+ IS_NOT_USED,
185
198
  UsageState.Used,
186
199
  runtime
187
200
  )
@@ -229,8 +242,9 @@ class FlagDependencyUsagePlugin {
229
242
  // Modules whose whole namespace object escapes in a mangleable way.
230
243
  // Tracked separately so specific member references are still merged
231
244
  // (and marked used) instead of being dropped by the escape marker.
232
- /** @type {Set<Module>} */
233
- const mangleableEscapeModules = new Set();
245
+ // Lazily allocated — usually empty.
246
+ /** @type {Set<Module> | undefined} */
247
+ let mangleableEscapeModules;
234
248
 
235
249
  /** @type {ArrayQueue<DependenciesBlock>} */
236
250
  const queue = new ArrayQueue();
@@ -273,7 +287,9 @@ class FlagDependencyUsagePlugin {
273
287
  // conservative result and always wins.
274
288
  if (referencedExports === EXPORTS_OBJECT_REFERENCED) {
275
289
  map.set(module, EXPORTS_OBJECT_REFERENCED);
276
- mangleableEscapeModules.delete(module);
290
+ if (mangleableEscapeModules) {
291
+ mangleableEscapeModules.delete(module);
292
+ }
277
293
  continue;
278
294
  }
279
295
  // A mangleable whole-object escape keeps the module's exports
@@ -284,6 +300,9 @@ class FlagDependencyUsagePlugin {
284
300
  if (
285
301
  referencedExports === EXPORTS_OBJECT_REFERENCED_MANGLEABLE
286
302
  ) {
303
+ if (mangleableEscapeModules === undefined) {
304
+ mangleableEscapeModules = new Set();
305
+ }
287
306
  mangleableEscapeModules.add(module);
288
307
  continue;
289
308
  }
@@ -358,13 +377,15 @@ class FlagDependencyUsagePlugin {
358
377
  );
359
378
  }
360
379
  }
361
- for (const module of mangleableEscapeModules) {
362
- processReferencedModule(
363
- module,
364
- EXPORTS_OBJECT_REFERENCED_MANGLEABLE,
365
- runtime,
366
- forceSideEffects
367
- );
380
+ if (mangleableEscapeModules) {
381
+ for (const module of mangleableEscapeModules) {
382
+ processReferencedModule(
383
+ module,
384
+ EXPORTS_OBJECT_REFERENCED_MANGLEABLE,
385
+ runtime,
386
+ forceSideEffects
387
+ );
388
+ }
368
389
  }
369
390
  };
370
391
 
@@ -22,6 +22,7 @@ const { chunkHasCss } = require("./css/CssModulesPlugin");
22
22
  const ConstDependency = require("./dependencies/ConstDependency");
23
23
  const ImportMetaHotAcceptDependency = require("./dependencies/ImportMetaHotAcceptDependency");
24
24
  const ImportMetaHotDeclineDependency = require("./dependencies/ImportMetaHotDeclineDependency");
25
+ const { isImportMetaFieldEnabled } = require("./dependencies/ImportMetaPlugin");
25
26
  const ModuleHotAcceptDependency = require("./dependencies/ModuleHotAcceptDependency");
26
27
  const ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDependency");
27
28
  const WebpackError = require("./errors/WebpackError");
@@ -141,7 +142,7 @@ class HotModuleReplacementPlugin {
141
142
  /** @type {Range} */ (expr.callee.range),
142
143
  runtimeRequirements
143
144
  );
144
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
145
+ dep.loc = parser.getLocation(expr);
145
146
  module.addPresentationalDependency(dep);
146
147
  /** @type {BuildInfo} */
147
148
  (module.buildInfo).moduleConcatenationBailout =
@@ -168,10 +169,7 @@ class HotModuleReplacementPlugin {
168
169
  /** @type {Range} */ (param.range)
169
170
  );
170
171
  dep.optional = true;
171
- dep.setLocWithIndex(
172
- /** @type {DependencyLocation} */ (expr.loc),
173
- idx
174
- );
172
+ dep.setLocWithIndex(parser.getLocation(expr), idx);
175
173
  module.addDependency(dep);
176
174
  requests.push(request);
177
175
  }
@@ -204,7 +202,7 @@ class HotModuleReplacementPlugin {
204
202
  /** @type {Range} */ (expr.callee.range),
205
203
  runtimeRequirements
206
204
  );
207
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
205
+ dep.loc = parser.getLocation(expr);
208
206
  module.addPresentationalDependency(dep);
209
207
  /** @type {BuildInfo} */
210
208
  (module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
@@ -225,10 +223,7 @@ class HotModuleReplacementPlugin {
225
223
  /** @type {Range} */ (param.range)
226
224
  );
227
225
  dep.optional = true;
228
- dep.setLocWithIndex(
229
- /** @type {DependencyLocation} */ (expr.loc),
230
- idx
231
- );
226
+ dep.setLocWithIndex(parser.getLocation(expr), idx);
232
227
  module.addDependency(dep);
233
228
  }
234
229
  }
@@ -247,7 +242,7 @@ class HotModuleReplacementPlugin {
247
242
  /** @type {Range} */ (expr.range),
248
243
  runtimeRequirements
249
244
  );
250
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
245
+ dep.loc = parser.getLocation(expr);
251
246
  module.addPresentationalDependency(dep);
252
247
  /** @type {BuildInfo} */
253
248
  (module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
@@ -960,9 +955,13 @@ To fix this, make sure to include [runtime] in the output.hotUpdateMainFilename
960
955
 
961
956
  normalModuleFactory.hooks.parser
962
957
  .for(JAVASCRIPT_MODULE_TYPE_AUTO)
963
- .tap(PLUGIN_NAME, (parser) => {
958
+ .tap(PLUGIN_NAME, (parser, parserOptions) => {
964
959
  applyModuleHot(parser);
965
- applyImportMetaHot(parser);
960
+ if (
961
+ isImportMetaFieldEnabled(parserOptions.importMeta, "webpackHot")
962
+ ) {
963
+ applyImportMetaHot(parser);
964
+ }
966
965
  });
967
966
  normalModuleFactory.hooks.parser
968
967
  .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
@@ -971,8 +970,12 @@ To fix this, make sure to include [runtime] in the output.hotUpdateMainFilename
971
970
  });
972
971
  normalModuleFactory.hooks.parser
973
972
  .for(JAVASCRIPT_MODULE_TYPE_ESM)
974
- .tap(PLUGIN_NAME, (parser) => {
975
- applyImportMetaHot(parser);
973
+ .tap(PLUGIN_NAME, (parser, parserOptions) => {
974
+ if (
975
+ isImportMetaFieldEnabled(parserOptions.importMeta, "webpackHot")
976
+ ) {
977
+ applyImportMetaHot(parser);
978
+ }
976
979
  });
977
980
  normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (module) => {
978
981
  if (module instanceof NormalModule) module.hot = true;
@@ -28,30 +28,6 @@ const makeSerializable = require("./util/makeSerializable");
28
28
  * @property {(fragments: MaybeMergeableInitFragment<GenerateContext>[]) => MaybeMergeableInitFragment<GenerateContext>[]=} mergeAll
29
29
  */
30
30
 
31
- /**
32
- * Extract fragment index.
33
- * @template T
34
- * @param {T} fragment the init fragment
35
- * @param {number} index index
36
- * @returns {[T, number]} tuple with both
37
- */
38
- const extractFragmentIndex = (fragment, index) => [fragment, index];
39
-
40
- /**
41
- * Sorts fragment with index.
42
- * @template T
43
- * @param {[MaybeMergeableInitFragment<T>, number]} a first pair
44
- * @param {[MaybeMergeableInitFragment<T>, number]} b second pair
45
- * @returns {number} sort value
46
- */
47
- const sortFragmentWithIndex = ([a, i], [b, j]) => {
48
- const stageCmp = a.stage - b.stage;
49
- if (stageCmp !== 0) return stageCmp;
50
- const positionCmp = a.position - b.position;
51
- if (positionCmp !== 0) return positionCmp;
52
- return i - j;
53
- };
54
-
55
31
  /**
56
32
  * Represents InitFragment.
57
33
  * @template GenerateContext
@@ -107,16 +83,28 @@ class InitFragment {
107
83
  */
108
84
  static addToSource(source, initFragments, context) {
109
85
  if (initFragments.length > 0) {
110
- // Sort fragments by position. If 2 fragments have the same position,
111
- // use their index.
112
- const sortedFragments = initFragments
113
- .map(extractFragmentIndex)
114
- .sort(sortFragmentWithIndex);
86
+ // Sort fragment indices by (stage, position), falling back to the
87
+ // original index — one flat number array instead of N [fragment, index]
88
+ // tuples for a stable-by-index order.
89
+ const sortedIndices = initFragments.map((_, index) => index);
90
+ sortedIndices.sort((a, b) => {
91
+ const fragmentA = initFragments[a];
92
+ const fragmentB = initFragments[b];
93
+ const stageCmp = fragmentA.stage - fragmentB.stage;
94
+ if (stageCmp !== 0) return stageCmp;
95
+ const positionCmp = fragmentA.position - fragmentB.position;
96
+ if (positionCmp !== 0) return positionCmp;
97
+ return a - b;
98
+ });
115
99
 
116
100
  // Deduplicate fragments. If a fragment has no key, it is always included.
117
- /** @type {Map<InitFragmentKey | symbol, MaybeMergeableInitFragment<Context> | MaybeMergeableInitFragment<Context>[]>} */
101
+ // Keyless fragments get a unique numeric key; number keys never collide
102
+ // with the string `InitFragmentKey`s used for keyed fragments.
103
+ /** @type {Map<InitFragmentKey | number, MaybeMergeableInitFragment<Context> | MaybeMergeableInitFragment<Context>[]>} */
118
104
  const keyedFragments = new Map();
119
- for (const [fragment] of sortedFragments) {
105
+ let keylessKey = 0;
106
+ for (const index of sortedIndices) {
107
+ const fragment = initFragments[index];
120
108
  if (typeof fragment.mergeAll === "function") {
121
109
  if (!fragment.key) {
122
110
  throw new Error(
@@ -142,7 +130,7 @@ class InitFragment {
142
130
  continue;
143
131
  }
144
132
  }
145
- keyedFragments.set(fragment.key || Symbol("fragment key"), fragment);
133
+ keyedFragments.set(fragment.key || keylessKey++, fragment);
146
134
  }
147
135
 
148
136
  const concatSource = new ConcatSource();
package/lib/Module.js CHANGED
@@ -106,6 +106,7 @@ const makeSerializable = require("./util/makeSerializable");
106
106
  * @typedef {object} ConcatenationBailoutReasonContext
107
107
  * @property {ModuleGraph} moduleGraph the module graph
108
108
  * @property {ChunkGraph} chunkGraph the chunk graph
109
+ * @property {boolean=} concatenateCommonJsModules whether eligible CommonJS modules may be concatenated
109
110
  */
110
111
 
111
112
  /** @typedef {Set<string>} RuntimeRequirements */
@@ -179,6 +180,7 @@ const makeSerializable = require("./util/makeSerializable");
179
180
  * Module type specific properties live in the `Known*BuildInfo` typedef of the dedicated module class.
180
181
  * @typedef {object} KnownBuildInfo
181
182
  * @property {boolean=} cacheable
183
+ * @property {string[]=} notCacheableReasons reasons why the module is not cacheable (e.g. paths of loaders that marked it)
182
184
  * @property {boolean=} strict
183
185
  * @property {string=} moduleArgument
184
186
  * @property {string=} exportsArgument
@@ -186,6 +188,7 @@ const makeSerializable = require("./util/makeSerializable");
186
188
  * @property {Map<string, AssetInfo | undefined>=} assetsInfo
187
189
  * @property {Set<string>=} topLevelDeclarations top level declaration names
188
190
  * @property {boolean=} isCircular true when the module is part of a circular dependency chain
191
+ * @property {boolean=} usesTopLevelAwaitForOf module uses top-level `for await…of`, which can't be lowered to a generator
189
192
  */
190
193
 
191
194
  /** @typedef {string | Set<string>} ValueCacheVersion */
@@ -327,9 +327,9 @@ ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
327
327
  * ```js
328
328
  * ModuleFilenameHelpers.matchPart("foo.js", "foo"); // true
329
329
  * ModuleFilenameHelpers.matchPart("foo.js", "foo.js"); // true
330
- * ModuleFilenameHelpers.matchPart("foo.js", "foo."); // false
330
+ * ModuleFilenameHelpers.matchPart("foo.js", "foo."); // true
331
331
  * ModuleFilenameHelpers.matchPart("foo.js", "foo*"); // false
332
- * ModuleFilenameHelpers.matchPart("foo.js", "foo.*"); // true
332
+ * ModuleFilenameHelpers.matchPart("foo.js", "foo.*"); // false
333
333
  * ModuleFilenameHelpers.matchPart("foo.js", /^foo/); // true
334
334
  * ModuleFilenameHelpers.matchPart("foo.js", [/^foo/, "bar"]); // true
335
335
  * ModuleFilenameHelpers.matchPart("foo.js", [/^foo/, "bar"]); // true
@@ -108,6 +108,12 @@ const ASSET_MODULE_TYPE_BYTES = "asset/bytes";
108
108
  */
109
109
  const ASSET_MODULE_TYPE_RAW_DATA_URL = "asset/raw-data-url";
110
110
 
111
+ /**
112
+ * @type {Readonly<"asset/webmanifest">}
113
+ * This is the module type used for a Web App Manifest whose icon URLs are bundled as assets.
114
+ */
115
+ const ASSET_MODULE_TYPE_WEBMANIFEST = "asset/webmanifest";
116
+
111
117
  /**
112
118
  * @type {Readonly<"runtime">}
113
119
  * This is the module type used for the webpack runtime abstractions.
@@ -149,7 +155,7 @@ const WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY = "lazy-compilation-proxy";
149
155
  /** @typedef {"webassembly/async" | "webassembly/sync"} WebAssemblyModuleTypes */
150
156
  /** @typedef {"css" | "css/global" | "css/module" | "css/auto"} CssModuleTypes */
151
157
  /** @typedef {"html"} HTMLModuleType */
152
- /** @typedef {"asset" | "asset/inline" | "asset/resource" | "asset/source" | "asset/raw-data-url"} AssetModuleTypes */
158
+ /** @typedef {"asset" | "asset/inline" | "asset/resource" | "asset/source" | "asset/raw-data-url" | "asset/webmanifest"} AssetModuleTypes */
153
159
  /** @typedef {"runtime" | "fallback-module" | "remote-module" | "provide-module" | "consume-shared-module" | "lazy-compilation-proxy"} WebpackModuleTypes */
154
160
  /** @typedef {string} UnknownModuleTypes */
155
161
  /** @typedef {JavaScriptModuleTypes | JSONModuleType | WebAssemblyModuleTypes | CssModuleTypes | HTMLModuleType | AssetModuleTypes | WebpackModuleTypes | UnknownModuleTypes} ModuleTypes */
@@ -160,6 +166,7 @@ module.exports.ASSET_MODULE_TYPE_INLINE = ASSET_MODULE_TYPE_INLINE;
160
166
  module.exports.ASSET_MODULE_TYPE_RAW_DATA_URL = ASSET_MODULE_TYPE_RAW_DATA_URL;
161
167
  module.exports.ASSET_MODULE_TYPE_RESOURCE = ASSET_MODULE_TYPE_RESOURCE;
162
168
  module.exports.ASSET_MODULE_TYPE_SOURCE = ASSET_MODULE_TYPE_SOURCE;
169
+ module.exports.ASSET_MODULE_TYPE_WEBMANIFEST = ASSET_MODULE_TYPE_WEBMANIFEST;
163
170
  /** @type {CssModuleTypes[]} */
164
171
  module.exports.CSS_MODULES = [
165
172
  CSS_MODULE_TYPE,
@@ -102,6 +102,8 @@ module.exports = class MultiCompiler {
102
102
  this.dependencies = new WeakMap();
103
103
  /** @type {boolean} */
104
104
  this.running = false;
105
+ /** @type {MultiWatching | undefined} */
106
+ this.watching = undefined;
105
107
 
106
108
  /** @type {(Stats | null)[]} */
107
109
  const compilerStats = this.compilers.map(() => null);
@@ -662,10 +664,12 @@ module.exports = class MultiCompiler {
662
664
  },
663
665
  handler
664
666
  );
665
- return new MultiWatching(watchings, this);
667
+ this.watching = new MultiWatching(watchings, this);
668
+ return this.watching;
666
669
  }
667
670
 
668
- return new MultiWatching([], this);
671
+ this.watching = new MultiWatching([], this);
672
+ return this.watching;
669
673
  }
670
674
 
671
675
  /**
@@ -709,6 +713,13 @@ module.exports = class MultiCompiler {
709
713
  * @returns {void}
710
714
  */
711
715
  close(callback) {
716
+ if (this.watching) {
717
+ // When there is still an active watching, close this first
718
+ this.watching.close((_err) => {
719
+ this.close(callback);
720
+ });
721
+ return;
722
+ }
712
723
  asyncLib.each(
713
724
  this.compilers,
714
725
  (compiler, callback) => {
@@ -69,6 +69,7 @@ class MultiWatching {
69
69
  watching.close(finishedCallback);
70
70
  },
71
71
  (err) => {
72
+ if (this.compiler.watching === this) this.compiler.watching = undefined;
72
73
  this.compiler.hooks.watchClose.call();
73
74
  if (typeof callback === "function") {
74
75
  this.compiler.running = false;
@@ -34,7 +34,8 @@ const { parseResource } = require("./util/identifier");
34
34
  const PLUGIN_NAME = "NodeStuffPlugin";
35
35
  const URL_MODULE_CONSTANT_FUNCTION_NAME = "__webpack_fileURLToPath__";
36
36
 
37
- const { IMPORT_META_DIRNAME, IMPORT_META_FILENAME } = ImportMetaPlugin;
37
+ const { IMPORT_META_DIRNAME, IMPORT_META_FILENAME, isImportMetaFieldEnabled } =
38
+ ImportMetaPlugin;
38
39
 
39
40
  class NodeStuffPlugin {
40
41
  /**
@@ -97,7 +98,7 @@ class NodeStuffPlugin {
97
98
 
98
99
  parser.hooks.expression.for("global").tap(PLUGIN_NAME, (expr) => {
99
100
  const dep = getGlobalDep(expr);
100
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
101
+ dep.loc = parser.getLocation(expr);
101
102
  parser.state.module.addPresentationalDependency(dep);
102
103
 
103
104
  if (withWarning) {
@@ -113,7 +114,7 @@ class NodeStuffPlugin {
113
114
 
114
115
  parser.hooks.rename.for("global").tap(PLUGIN_NAME, (expr) => {
115
116
  const dep = getGlobalDep(expr);
116
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
117
+ dep.loc = parser.getLocation(expr);
117
118
  parser.state.module.addPresentationalDependency(dep);
118
119
  return false;
119
120
  });
@@ -138,7 +139,7 @@ class NodeStuffPlugin {
138
139
  /** @type {Range} */
139
140
  (expr.range)
140
141
  );
141
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
142
+ dep.loc = parser.getLocation(expr);
142
143
  parser.state.module.addPresentationalDependency(dep);
143
144
  return true;
144
145
  });
@@ -180,7 +181,7 @@ class NodeStuffPlugin {
180
181
  (expr.range),
181
182
  `__webpack_${property}__`
182
183
  );
183
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
184
+ dep.loc = parser.getLocation(expr);
184
185
  parser.state.module.addPresentationalDependency(dep);
185
186
 
186
187
  if (warning) {
@@ -201,7 +202,7 @@ class NodeStuffPlugin {
201
202
  if (warning) {
202
203
  parser.state.module.addWarning(
203
204
  new NodeStuffInWebError(
204
- usingProperty.loc,
205
+ parser.getLocation(usingProperty),
205
206
  expressionName,
206
207
  warning
207
208
  )
@@ -278,7 +279,7 @@ class NodeStuffPlugin {
278
279
  CachedConstDependency.PLACE_CHUNK
279
280
  );
280
281
 
281
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
282
+ dep.loc = parser.getLocation(expr);
282
283
  parser.state.module.addPresentationalDependency(dep);
283
284
  return;
284
285
  }
@@ -297,7 +298,7 @@ class NodeStuffPlugin {
297
298
  `__webpack_${property}__`,
298
299
  ExternalModuleDependency.PLACE_CHUNK
299
300
  );
300
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
301
+ dep.loc = parser.getLocation(expr);
301
302
  parser.state.module.addPresentationalDependency(dep);
302
303
 
303
304
  return true;
@@ -324,9 +325,7 @@ class NodeStuffPlugin {
324
325
  `__webpack_${property}__`,
325
326
  CachedConstDependency.PLACE_CHUNK
326
327
  );
327
- dep.loc = /** @type {DependencyLocation} */ (
328
- usingProperty.loc
329
- );
328
+ dep.loc = parser.getLocation(usingProperty);
330
329
  parser.state.module.addPresentationalDependency(dep);
331
330
  return `${property}: __webpack_${property}__,`;
332
331
  }
@@ -346,7 +345,7 @@ class NodeStuffPlugin {
346
345
  ExternalModuleDependency.PLACE_CHUNK
347
346
  );
348
347
 
349
- dep.loc = /** @type {DependencyLocation} */ (usingProperty.loc);
348
+ dep.loc = parser.getLocation(usingProperty);
350
349
  parser.state.module.addPresentationalDependency(dep);
351
350
 
352
351
  return `${property}: __webpack_${property}__,`;
@@ -359,23 +358,24 @@ class NodeStuffPlugin {
359
358
  * Dirname and filename handler.
360
359
  * @param {JavascriptParser} parser the parser
361
360
  * @param {NodeOptions} nodeOptions options
362
- * @param {{ dirname: "__dirname" | "import.meta.dirname", filename: "__filename" | "import.meta.filename" }} identifiers options
361
+ * @param {{ dirname: "__dirname" | "import.meta.dirname", filename: "__filename" | "import.meta.filename", dirnameEnabled?: boolean, filenameEnabled?: boolean }} identifiers options
363
362
  * @returns {void}
364
363
  */
365
364
  const dirnameAndFilenameHandler = (
366
365
  parser,
367
366
  nodeOptions,
368
- { dirname, filename }
367
+ { dirname, filename, dirnameEnabled = true, filenameEnabled = true }
369
368
  ) => {
370
- // Keep `import.meta.filename` in code
369
+ // Keep `import.meta.filename` in code.
371
370
  if (
371
+ filenameEnabled &&
372
372
  nodeOptions.__filename === false &&
373
373
  filename === IMPORT_META_FILENAME
374
374
  ) {
375
375
  setModuleConstant(parser, filename, () => filename, "filename");
376
376
  }
377
377
 
378
- if (nodeOptions.__filename) {
378
+ if (filenameEnabled && nodeOptions.__filename) {
379
379
  switch (nodeOptions.__filename) {
380
380
  case "mock":
381
381
  setConstant(parser, filename, "/index.js", "filename");
@@ -446,15 +446,16 @@ class NodeStuffPlugin {
446
446
  });
447
447
  }
448
448
 
449
- // Keep `import.meta.dirname` in code
449
+ // Keep `import.meta.dirname` in code.
450
450
  if (
451
+ dirnameEnabled &&
451
452
  nodeOptions.__dirname === false &&
452
453
  dirname === IMPORT_META_DIRNAME
453
454
  ) {
454
455
  setModuleConstant(parser, dirname, () => dirname, "dirname");
455
456
  }
456
457
 
457
- if (nodeOptions.__dirname) {
458
+ if (dirnameEnabled && nodeOptions.__dirname) {
458
459
  switch (nodeOptions.__dirname) {
459
460
  case "mock":
460
461
  setConstant(parser, dirname, "/", "dirname");
@@ -537,19 +538,24 @@ class NodeStuffPlugin {
537
538
  */
538
539
  const handler = (parser, parserOptions, a, b) => {
539
540
  if (b && parserOptions.node === false) {
540
- // Keep `import.meta.dirname` and `import.meta.filename` in code
541
- setModuleConstant(
542
- parser,
543
- IMPORT_META_DIRNAME,
544
- () => IMPORT_META_DIRNAME,
545
- "dirname"
546
- );
547
- setModuleConstant(
548
- parser,
549
- IMPORT_META_FILENAME,
550
- () => IMPORT_META_FILENAME,
551
- "filename"
552
- );
541
+ if (isImportMetaFieldEnabled(parserOptions.importMeta, "dirname")) {
542
+ setModuleConstant(
543
+ parser,
544
+ IMPORT_META_DIRNAME,
545
+ () => IMPORT_META_DIRNAME,
546
+ "dirname"
547
+ );
548
+ }
549
+ if (
550
+ isImportMetaFieldEnabled(parserOptions.importMeta, "filename")
551
+ ) {
552
+ setModuleConstant(
553
+ parser,
554
+ IMPORT_META_FILENAME,
555
+ () => IMPORT_META_FILENAME,
556
+ "filename"
557
+ );
558
+ }
553
559
  return;
554
560
  }
555
561
 
@@ -570,10 +576,22 @@ class NodeStuffPlugin {
570
576
  });
571
577
  }
572
578
 
573
- if (b && parserOptions.importMeta !== false) {
579
+ if (
580
+ b &&
581
+ (isImportMetaFieldEnabled(parserOptions.importMeta, "dirname") ||
582
+ isImportMetaFieldEnabled(parserOptions.importMeta, "filename"))
583
+ ) {
574
584
  dirnameAndFilenameHandler(parser, localOptions, {
575
585
  dirname: IMPORT_META_DIRNAME,
576
- filename: IMPORT_META_FILENAME
586
+ filename: IMPORT_META_FILENAME,
587
+ dirnameEnabled: isImportMetaFieldEnabled(
588
+ parserOptions.importMeta,
589
+ "dirname"
590
+ ),
591
+ filenameEnabled: isImportMetaFieldEnabled(
592
+ parserOptions.importMeta,
593
+ "filename"
594
+ )
577
595
  });
578
596
  }
579
597
  };