webpack 5.95.0 → 5.96.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 (145) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EvalDevToolModulePlugin.js +5 -2
  19. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  20. package/lib/ExternalModule.js +40 -7
  21. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  22. package/lib/FileSystemInfo.js +12 -8
  23. package/lib/Generator.js +5 -4
  24. package/lib/HotModuleReplacementPlugin.js +8 -6
  25. package/lib/IgnorePlugin.js +19 -1
  26. package/lib/LoaderOptionsPlugin.js +3 -1
  27. package/lib/Module.js +9 -8
  28. package/lib/ModuleSourceTypesConstants.js +100 -0
  29. package/lib/NormalModule.js +27 -17
  30. package/lib/NormalModuleFactory.js +38 -22
  31. package/lib/OptionsApply.js +12 -1
  32. package/lib/ProgressPlugin.js +50 -10
  33. package/lib/RawModule.js +3 -4
  34. package/lib/RuntimeModule.js +3 -4
  35. package/lib/RuntimePlugin.js +11 -4
  36. package/lib/RuntimeTemplate.js +13 -42
  37. package/lib/SourceMapDevToolPlugin.js +10 -7
  38. package/lib/Watching.js +2 -2
  39. package/lib/WebpackOptionsApply.js +42 -21
  40. package/lib/asset/AssetGenerator.js +347 -194
  41. package/lib/asset/AssetModulesPlugin.js +2 -1
  42. package/lib/asset/AssetSourceGenerator.js +82 -27
  43. package/lib/asset/RawDataUrlModule.js +5 -4
  44. package/lib/buildChunkGraph.js +2 -2
  45. package/lib/cache/PackFileCacheStrategy.js +69 -31
  46. package/lib/cache/ResolverCachePlugin.js +248 -173
  47. package/lib/config/defaults.js +134 -126
  48. package/lib/container/ContainerEntryModule.js +3 -4
  49. package/lib/container/ContainerPlugin.js +8 -0
  50. package/lib/container/FallbackModule.js +2 -2
  51. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  52. package/lib/container/ModuleFederationPlugin.js +38 -1
  53. package/lib/container/RemoteModule.js +4 -2
  54. package/lib/container/RemoteRuntimeModule.js +4 -2
  55. package/lib/css/CssExportsGenerator.js +16 -12
  56. package/lib/css/CssGenerator.js +22 -16
  57. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  58. package/lib/css/CssModulesPlugin.js +122 -77
  59. package/lib/css/CssParser.js +655 -526
  60. package/lib/css/walkCssTokens.js +1168 -338
  61. package/lib/debug/ProfilingPlugin.js +5 -0
  62. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  63. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  64. package/lib/dependencies/CssExportDependency.js +3 -3
  65. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  66. package/lib/dependencies/CssUrlDependency.js +33 -3
  67. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  68. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  69. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  71. package/lib/dependencies/ImportParserPlugin.js +9 -7
  72. package/lib/dependencies/LoaderPlugin.js +19 -0
  73. package/lib/dependencies/SystemPlugin.js +2 -1
  74. package/lib/dependencies/URLPlugin.js +7 -1
  75. package/lib/dependencies/WorkerPlugin.js +1 -1
  76. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  77. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  78. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  79. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  80. package/lib/hmr/lazyCompilationBackend.js +1 -7
  81. package/lib/index.js +37 -7
  82. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  83. package/lib/javascript/JavascriptGenerator.js +8 -8
  84. package/lib/javascript/JavascriptModulesPlugin.js +126 -73
  85. package/lib/javascript/JavascriptParser.js +338 -117
  86. package/lib/json/JsonGenerator.js +5 -5
  87. package/lib/library/EnableLibraryPlugin.js +2 -2
  88. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  89. package/lib/library/UmdLibraryPlugin.js +16 -8
  90. package/lib/logging/Logger.js +11 -11
  91. package/lib/logging/createConsoleLogger.js +14 -14
  92. package/lib/logging/truncateArgs.js +1 -1
  93. package/lib/node/NodeWatchFileSystem.js +3 -1
  94. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  95. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  96. package/lib/node/nodeConsole.js +11 -8
  97. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  98. package/lib/optimize/ConcatenatedModule.js +43 -145
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  100. package/lib/optimize/InnerGraphPlugin.js +57 -16
  101. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  102. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  103. package/lib/optimize/RealContentHashPlugin.js +1 -1
  104. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  105. package/lib/rules/RuleSetCompiler.js +2 -2
  106. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  107. package/lib/schemes/DataUriPlugin.js +1 -1
  108. package/lib/serialization/BinaryMiddleware.js +32 -19
  109. package/lib/serialization/ObjectMiddleware.js +23 -9
  110. package/lib/serialization/SerializerMiddleware.js +3 -2
  111. package/lib/serialization/types.js +2 -2
  112. package/lib/sharing/ConsumeSharedModule.js +2 -3
  113. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  114. package/lib/sharing/ProvideSharedModule.js +2 -3
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  116. package/lib/stats/StatsFactory.js +12 -12
  117. package/lib/stats/StatsPrinter.js +7 -7
  118. package/lib/util/AsyncQueue.js +17 -1
  119. package/lib/util/IterableHelpers.js +1 -1
  120. package/lib/util/SetHelpers.js +1 -1
  121. package/lib/util/cleverMerge.js +48 -24
  122. package/lib/util/concatenate.js +227 -0
  123. package/lib/util/create-schema-validation.js +22 -9
  124. package/lib/util/deprecation.js +86 -28
  125. package/lib/util/fs.js +9 -9
  126. package/lib/util/hash/wasm-hash.js +12 -1
  127. package/lib/util/magicComment.js +21 -0
  128. package/lib/util/makeSerializable.js +24 -1
  129. package/lib/util/memoize.js +2 -1
  130. package/lib/util/runtime.js +4 -1
  131. package/lib/util/semver.js +130 -23
  132. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  133. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  134. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  135. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  136. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  137. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  138. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  139. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  140. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  141. package/package.json +18 -19
  142. package/schemas/WebpackOptions.check.js +1 -1
  143. package/schemas/WebpackOptions.json +8 -2
  144. package/types.d.ts +801 -259
  145. package/lib/util/mergeScope.js +0 -76
@@ -52,8 +52,8 @@ const {
52
52
  /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
53
53
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
54
54
 
55
- /** @typedef {Pick<RuleSetRule, 'type'|'sideEffects'|'parser'|'generator'|'resolve'|'layer'>} ModuleSettings */
56
- /** @typedef {Partial<NormalModuleCreateData & {settings: ModuleSettings}>} CreateData */
55
+ /** @typedef {Pick<RuleSetRule, 'type' | 'sideEffects' | 'parser' | 'generator' | 'resolve' | 'layer'>} ModuleSettings */
56
+ /** @typedef {Partial<NormalModuleCreateData & { settings: ModuleSettings }>} CreateData */
57
57
 
58
58
  /**
59
59
  * @typedef {object} ResolveData
@@ -68,6 +68,7 @@ const {
68
68
  * @property {LazySet<string>} fileDependencies
69
69
  * @property {LazySet<string>} missingDependencies
70
70
  * @property {LazySet<string>} contextDependencies
71
+ * @property {Module=} ignoredModule
71
72
  * @property {boolean} cacheable allow to use the unsafe cache
72
73
  */
73
74
 
@@ -169,7 +170,9 @@ const mergeGlobalOptions = (globalOptions, type, localOptions) => {
169
170
  let current = "";
170
171
  for (const part of parts) {
171
172
  current = current ? `${current}/${part}` : part;
172
- const options = globalOptions[current];
173
+ const options =
174
+ /** @type {T} */
175
+ (globalOptions[/** @type {keyof T} */ (current)]);
173
176
  if (typeof options === "object") {
174
177
  result =
175
178
  result === undefined ? options : cachedCleverMerge(result, options);
@@ -219,16 +222,19 @@ const ruleSetCompiler = new RuleSetCompiler([
219
222
  new BasicMatcherRulePlugin("issuer"),
220
223
  new BasicMatcherRulePlugin("compiler"),
221
224
  new BasicMatcherRulePlugin("issuerLayer"),
222
- new ObjectMatcherRulePlugin(
223
- "assert",
224
- "assertions",
225
- value => value && /** @type {any} */ (value)._isLegacyAssert !== undefined
226
- ),
227
- new ObjectMatcherRulePlugin(
228
- "with",
229
- "assertions",
230
- value => value && !(/** @type {any} */ (value)._isLegacyAssert)
231
- ),
225
+ new ObjectMatcherRulePlugin("assert", "assertions", value => {
226
+ if (value) {
227
+ return /** @type {any} */ (value)._isLegacyAssert !== undefined;
228
+ }
229
+
230
+ return false;
231
+ }),
232
+ new ObjectMatcherRulePlugin("with", "assertions", value => {
233
+ if (value) {
234
+ return !(/** @type {any} */ (value)._isLegacyAssert);
235
+ }
236
+ return false;
237
+ }),
232
238
  new ObjectMatcherRulePlugin("descriptionData"),
233
239
  new BasicEffectRulePlugin("type"),
234
240
  new BasicEffectRulePlugin("sideEffects"),
@@ -246,7 +252,7 @@ class NormalModuleFactory extends ModuleFactory {
246
252
  * @param {InputFileSystem} param.fs file system
247
253
  * @param {ResolverFactory} param.resolverFactory resolverFactory
248
254
  * @param {ModuleOptions} param.options options
249
- * @param {object=} param.associatedObjectForCache an object to which the cache will be attached
255
+ * @param {object} param.associatedObjectForCache an object to which the cache will be attached
250
256
  * @param {boolean=} param.layers enable layers
251
257
  */
252
258
  constructor({
@@ -277,13 +283,13 @@ class NormalModuleFactory extends ModuleFactory {
277
283
  afterResolve: new AsyncSeriesBailHook(["resolveData"]),
278
284
  /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
279
285
  createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
280
- /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
286
+ /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData]>} */
281
287
  module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
282
- /** @type {HookMap<SyncBailHook<[ParserOptions], Parser>>} */
288
+ /** @type {HookMap<SyncBailHook<[ParserOptions], Parser | void>>} */
283
289
  createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
284
290
  /** @type {HookMap<SyncBailHook<[TODO, ParserOptions], void>>} */
285
291
  parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
286
- /** @type {HookMap<SyncBailHook<[GeneratorOptions], Generator>>} */
292
+ /** @type {HookMap<SyncBailHook<[GeneratorOptions], Generator | void>>} */
287
293
  createGenerator: new HookMap(
288
294
  () => new SyncBailHook(["generatorOptions"])
289
295
  ),
@@ -291,7 +297,7 @@ class NormalModuleFactory extends ModuleFactory {
291
297
  generator: new HookMap(
292
298
  () => new SyncHook(["generator", "generatorOptions"])
293
299
  ),
294
- /** @type {HookMap<SyncBailHook<[TODO, ResolveData], Module>>} */
300
+ /** @type {HookMap<SyncBailHook<[TODO, ResolveData], Module | void>>} */
295
301
  createModuleClass: new HookMap(
296
302
  () => new SyncBailHook(["createData", "resolveData"])
297
303
  )
@@ -374,14 +380,16 @@ class NormalModuleFactory extends ModuleFactory {
374
380
  // TODO webpack 6 make it required and move javascript/wasm/asset properties to own module
375
381
  createdModule = this.hooks.createModuleClass
376
382
  .for(
377
- /** @type {ModuleSettings} */ (createData.settings).type
383
+ /** @type {ModuleSettings} */
384
+ (createData.settings).type
378
385
  )
379
386
  .call(createData, resolveData);
380
387
 
381
388
  if (!createdModule) {
382
389
  createdModule = /** @type {Module} */ (
383
390
  new NormalModule(
384
- /** @type {NormalModuleCreateData} */ (createData)
391
+ /** @type {NormalModuleCreateData} */
392
+ (createData)
385
393
  )
386
394
  );
387
395
  }
@@ -887,12 +895,19 @@ class NormalModuleFactory extends ModuleFactory {
887
895
 
888
896
  // Ignored
889
897
  if (result === false) {
890
- return callback(null, {
898
+ /** @type {ModuleFactoryResult} * */
899
+ const factoryResult = {
891
900
  fileDependencies,
892
901
  missingDependencies,
893
902
  contextDependencies,
894
903
  cacheable: resolveData.cacheable
895
- });
904
+ };
905
+
906
+ if (resolveData.ignoredModule) {
907
+ factoryResult.module = resolveData.ignoredModule;
908
+ }
909
+
910
+ return callback(null, factoryResult);
896
911
  }
897
912
 
898
913
  if (typeof result === "object")
@@ -913,6 +928,7 @@ class NormalModuleFactory extends ModuleFactory {
913
928
  });
914
929
  }
915
930
 
931
+ /** @type {ModuleFactoryResult} * */
916
932
  const factoryResult = {
917
933
  module,
918
934
  fileDependencies,
@@ -5,7 +5,18 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
9
+ /** @typedef {import("./Compiler")} Compiler */
10
+
8
11
  class OptionsApply {
9
- process(options, compiler) {}
12
+ /**
13
+ * @param {WebpackOptions} options options object
14
+ * @param {Compiler} compiler compiler object
15
+ * @returns {WebpackOptions} options object
16
+ */
17
+ process(options, compiler) {
18
+ return options;
19
+ }
10
20
  }
21
+
11
22
  module.exports = OptionsApply;
@@ -15,11 +15,18 @@ const { contextify } = require("./util/identifier");
15
15
  /** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */
16
16
  /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
17
17
  /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
18
+ /** @typedef {import("./Compilation").FactorizeModuleOptions} FactorizeModuleOptions */
18
19
  /** @typedef {import("./Dependency")} Dependency */
19
20
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
20
21
  /** @typedef {import("./Module")} Module */
22
+ /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
21
23
  /** @typedef {import("./logging/Logger").Logger} Logger */
22
24
 
25
+ /**
26
+ * @template T, K, R
27
+ * @typedef {import("./util/AsyncQueue")<T, K, R>} AsyncQueue
28
+ */
29
+
23
30
  /**
24
31
  * @typedef {object} CountsData
25
32
  * @property {number} modulesCount modules count
@@ -121,6 +128,8 @@ const createDefaultHandler = (profile, logger) => {
121
128
  return defaultHandler;
122
129
  };
123
130
 
131
+ const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"];
132
+
124
133
  /**
125
134
  * @callback ReportProgress
126
135
  * @param {number} p percentage
@@ -217,7 +226,9 @@ class ProgressPlugin {
217
226
  let lastDependenciesCount = 0;
218
227
  let lastEntriesCount = 0;
219
228
  let modulesCount = 0;
229
+ let skippedModulesCount = 0;
220
230
  let dependenciesCount = 0;
231
+ let skippedDependenciesCount = 0;
221
232
  let entriesCount = 1;
222
233
  let doneModules = 0;
223
234
  let doneDependencies = 0;
@@ -298,7 +309,15 @@ class ProgressPlugin {
298
309
  lastUpdate = Date.now();
299
310
  };
300
311
 
301
- const factorizeAdd = () => {
312
+ /**
313
+ * @template T
314
+ * @param {AsyncQueue<FactorizeModuleOptions, string, Module | ModuleFactoryResult>} factorizeQueue async queue
315
+ * @param {T} _item item
316
+ */
317
+ const factorizeAdd = (factorizeQueue, _item) => {
318
+ if (SKIPPED_QUEUE_CONTEXTS.includes(factorizeQueue.getContext())) {
319
+ skippedDependenciesCount++;
320
+ }
302
321
  dependenciesCount++;
303
322
  if (dependenciesCount < 50 || dependenciesCount % 100 === 0)
304
323
  updateThrottled();
@@ -310,7 +329,15 @@ class ProgressPlugin {
310
329
  updateThrottled();
311
330
  };
312
331
 
313
- const moduleAdd = () => {
332
+ /**
333
+ * @template T
334
+ * @param {AsyncQueue<Module, string, Module>} addModuleQueue async queue
335
+ * @param {T} _item item
336
+ */
337
+ const moduleAdd = (addModuleQueue, _item) => {
338
+ if (SKIPPED_QUEUE_CONTEXTS.includes(addModuleQueue.getContext())) {
339
+ skippedModulesCount++;
340
+ }
314
341
  modulesCount++;
315
342
  if (modulesCount < 50 || modulesCount % 100 === 0) updateThrottled();
316
343
  };
@@ -397,12 +424,19 @@ class ProgressPlugin {
397
424
  if (compilation.compiler.isChild()) return Promise.resolve();
398
425
  return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
399
426
  async oldData => {
427
+ const realModulesCount = modulesCount - skippedModulesCount;
428
+ const realDependenciesCount =
429
+ dependenciesCount - skippedDependenciesCount;
430
+
400
431
  if (
401
432
  !oldData ||
402
- oldData.modulesCount !== modulesCount ||
403
- oldData.dependenciesCount !== dependenciesCount
433
+ oldData.modulesCount !== realModulesCount ||
434
+ oldData.dependenciesCount !== realDependenciesCount
404
435
  ) {
405
- await cache.storePromise({ modulesCount, dependenciesCount });
436
+ await cache.storePromise({
437
+ modulesCount: realModulesCount,
438
+ dependenciesCount: realDependenciesCount
439
+ });
406
440
  }
407
441
  }
408
442
  );
@@ -413,19 +447,25 @@ class ProgressPlugin {
413
447
  lastModulesCount = modulesCount;
414
448
  lastEntriesCount = entriesCount;
415
449
  lastDependenciesCount = dependenciesCount;
416
- modulesCount = dependenciesCount = entriesCount = 0;
450
+ modulesCount =
451
+ skippedModulesCount =
452
+ dependenciesCount =
453
+ skippedDependenciesCount =
454
+ entriesCount =
455
+ 0;
417
456
  doneModules = doneDependencies = doneEntries = 0;
418
457
 
419
- compilation.factorizeQueue.hooks.added.tap(
420
- "ProgressPlugin",
421
- factorizeAdd
458
+ compilation.factorizeQueue.hooks.added.tap("ProgressPlugin", item =>
459
+ factorizeAdd(compilation.factorizeQueue, item)
422
460
  );
423
461
  compilation.factorizeQueue.hooks.result.tap(
424
462
  "ProgressPlugin",
425
463
  factorizeDone
426
464
  );
427
465
 
428
- compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", moduleAdd);
466
+ compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", item =>
467
+ moduleAdd(compilation.addModuleQueue, item)
468
+ );
429
469
  compilation.processDependenciesQueue.hooks.result.tap(
430
470
  "ProgressPlugin",
431
471
  moduleDone
package/lib/RawModule.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JS_TYPES } = require("./ModuleSourceTypesConstants");
10
11
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
11
12
  const makeSerializable = require("./util/makeSerializable");
12
13
 
@@ -16,11 +17,11 @@ const makeSerializable = require("./util/makeSerializable");
16
17
  /** @typedef {import("./Compilation")} Compilation */
17
18
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
18
19
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
20
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
19
21
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
20
22
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
21
23
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
22
24
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
23
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
24
25
  /** @typedef {import("./RequestShortener")} RequestShortener */
25
26
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
26
27
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
@@ -30,8 +31,6 @@ const makeSerializable = require("./util/makeSerializable");
30
31
  /** @typedef {import("./util/Hash")} Hash */
31
32
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
32
33
 
33
- const TYPES = new Set(["javascript"]);
34
-
35
34
  class RawModule extends Module {
36
35
  /**
37
36
  * @param {string} source source code
@@ -51,7 +50,7 @@ class RawModule extends Module {
51
50
  * @returns {SourceTypes} types available (do not mutate)
52
51
  */
53
52
  getSourceTypes() {
54
- return TYPES;
53
+ return JS_TYPES;
55
54
  }
56
55
 
57
56
  /**
@@ -8,6 +8,7 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const OriginalSource = require("webpack-sources").OriginalSource;
10
10
  const Module = require("./Module");
11
+ const { RUNTIME_TYPES } = require("./ModuleSourceTypesConstants");
11
12
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
12
13
 
13
14
  /** @typedef {import("webpack-sources").Source} Source */
@@ -16,18 +17,16 @@ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
16
17
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
17
18
  /** @typedef {import("./Compilation")} Compilation */
18
19
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
20
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
19
21
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
20
22
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
21
23
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
22
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
23
24
  /** @typedef {import("./RequestShortener")} RequestShortener */
24
25
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
25
26
  /** @typedef {import("./WebpackError")} WebpackError */
26
27
  /** @typedef {import("./util/Hash")} Hash */
27
28
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
28
29
 
29
- const TYPES = new Set([WEBPACK_MODULE_TYPE_RUNTIME]);
30
-
31
30
  class RuntimeModule extends Module {
32
31
  /**
33
32
  * @param {string} name a readable name
@@ -127,7 +126,7 @@ class RuntimeModule extends Module {
127
126
  * @returns {SourceTypes} types available (do not mutate)
128
127
  */
129
128
  getSourceTypes() {
130
- return TYPES;
129
+ return RUNTIME_TYPES;
131
130
  }
132
131
 
133
132
  /**
@@ -34,6 +34,7 @@ const RuntimeIdRuntimeModule = require("./runtime/RuntimeIdRuntimeModule");
34
34
  const SystemContextRuntimeModule = require("./runtime/SystemContextRuntimeModule");
35
35
  const ShareRuntimeModule = require("./sharing/ShareRuntimeModule");
36
36
  const StringXor = require("./util/StringXor");
37
+ const memoize = require("./util/memoize");
37
38
 
38
39
  /** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
39
40
  /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
@@ -42,6 +43,11 @@ const StringXor = require("./util/StringXor");
42
43
  /** @typedef {import("./Module")} Module */
43
44
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
44
45
 
46
+ const getJavascriptModulesPlugin = memoize(() =>
47
+ require("./javascript/JavascriptModulesPlugin")
48
+ );
49
+ const getCssModulesPlugin = memoize(() => require("./css/CssModulesPlugin"));
50
+
45
51
  const GLOBALS_ON_REQUIRE = [
46
52
  RuntimeGlobals.chunkName,
47
53
  RuntimeGlobals.runtimeId,
@@ -261,7 +267,7 @@ class RuntimePlugin {
261
267
  });
262
268
  compilation.hooks.runtimeRequirementInTree
263
269
  .for(RuntimeGlobals.getChunkScriptFilename)
264
- .tap("RuntimePlugin", (chunk, set) => {
270
+ .tap("RuntimePlugin", (chunk, set, { chunkGraph }) => {
265
271
  if (
266
272
  typeof compilation.outputOptions.chunkFilename === "string" &&
267
273
  /\[(full)?hash(:\d+)?\]/.test(
@@ -277,8 +283,8 @@ class RuntimePlugin {
277
283
  "javascript",
278
284
  RuntimeGlobals.getChunkScriptFilename,
279
285
  chunk =>
280
- /** @type {TemplatePath} */
281
- (
286
+ getJavascriptModulesPlugin().chunkHasJs(chunk, chunkGraph) &&
287
+ /** @type {TemplatePath} */ (
282
288
  chunk.filenameTemplate ||
283
289
  (chunk.canBeInitial()
284
290
  ? compilation.outputOptions.filename
@@ -291,7 +297,7 @@ class RuntimePlugin {
291
297
  });
292
298
  compilation.hooks.runtimeRequirementInTree
293
299
  .for(RuntimeGlobals.getChunkCssFilename)
294
- .tap("RuntimePlugin", (chunk, set) => {
300
+ .tap("RuntimePlugin", (chunk, set, { chunkGraph }) => {
295
301
  if (
296
302
  typeof compilation.outputOptions.cssChunkFilename === "string" &&
297
303
  /\[(full)?hash(:\d+)?\]/.test(
@@ -307,6 +313,7 @@ class RuntimePlugin {
307
313
  "css",
308
314
  RuntimeGlobals.getChunkCssFilename,
309
315
  chunk =>
316
+ getCssModulesPlugin().chunkHasCss(chunk, chunkGraph) &&
310
317
  getChunkFilenameTemplate(chunk, compilation.outputOptions),
311
318
  set.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
312
319
  )
@@ -86,7 +86,7 @@ class RuntimeTemplate {
86
86
  */
87
87
  constructor(compilation, outputOptions, requestShortener) {
88
88
  this.compilation = compilation;
89
- this.outputOptions = outputOptions || {};
89
+ this.outputOptions = /** @type {OutputOptions} */ (outputOptions || {});
90
90
  this.requestShortener = requestShortener;
91
91
  this.globalObject =
92
92
  /** @type {string} */
@@ -106,55 +106,47 @@ class RuntimeTemplate {
106
106
  }
107
107
 
108
108
  supportsConst() {
109
- return /** @type {Environment} */ (this.outputOptions.environment).const;
109
+ return this.outputOptions.environment.const;
110
110
  }
111
111
 
112
112
  supportsArrowFunction() {
113
- return /** @type {Environment} */ (this.outputOptions.environment)
114
- .arrowFunction;
113
+ return this.outputOptions.environment.arrowFunction;
115
114
  }
116
115
 
117
116
  supportsAsyncFunction() {
118
- return /** @type {Environment} */ (this.outputOptions.environment)
119
- .asyncFunction;
117
+ return this.outputOptions.environment.asyncFunction;
120
118
  }
121
119
 
122
120
  supportsOptionalChaining() {
123
- return /** @type {Environment} */ (this.outputOptions.environment)
124
- .optionalChaining;
121
+ return this.outputOptions.environment.optionalChaining;
125
122
  }
126
123
 
127
124
  supportsForOf() {
128
- return /** @type {Environment} */ (this.outputOptions.environment).forOf;
125
+ return this.outputOptions.environment.forOf;
129
126
  }
130
127
 
131
128
  supportsDestructuring() {
132
- return /** @type {Environment} */ (this.outputOptions.environment)
133
- .destructuring;
129
+ return this.outputOptions.environment.destructuring;
134
130
  }
135
131
 
136
132
  supportsBigIntLiteral() {
137
- return /** @type {Environment} */ (this.outputOptions.environment)
138
- .bigIntLiteral;
133
+ return this.outputOptions.environment.bigIntLiteral;
139
134
  }
140
135
 
141
136
  supportsDynamicImport() {
142
- return /** @type {Environment} */ (this.outputOptions.environment)
143
- .dynamicImport;
137
+ return this.outputOptions.environment.dynamicImport;
144
138
  }
145
139
 
146
140
  supportsEcmaScriptModuleSyntax() {
147
- return /** @type {Environment} */ (this.outputOptions.environment).module;
141
+ return this.outputOptions.environment.module;
148
142
  }
149
143
 
150
144
  supportTemplateLiteral() {
151
- return /** @type {Environment} */ (this.outputOptions.environment)
152
- .templateLiteral;
145
+ return this.outputOptions.environment.templateLiteral;
153
146
  }
154
147
 
155
148
  supportNodePrefixForCoreModules() {
156
- return /** @type {Environment} */ (this.outputOptions.environment)
157
- .nodePrefixForCoreModules;
149
+ return this.outputOptions.environment.nodePrefixForCoreModules;
158
150
  }
159
151
 
160
152
  /**
@@ -315,7 +307,7 @@ class RuntimeTemplate {
315
307
  * Add a comment
316
308
  * @param {object} options Information content of the comment
317
309
  * @param {string=} options.request request string used originally
318
- * @param {string=} options.chunkName name of the chunk referenced
310
+ * @param {(string | null)=} options.chunkName name of the chunk referenced
319
311
  * @param {string=} options.chunkReason reason information of the chunk
320
312
  * @param {string=} options.message additional message
321
313
  * @param {string=} options.exportName name of the export
@@ -1105,27 +1097,6 @@ class RuntimeTemplate {
1105
1097
  runtimeRequirements.add(RuntimeGlobals.exports);
1106
1098
  return `${RuntimeGlobals.makeNamespaceObject}(${exportsArgument});\n`;
1107
1099
  }
1108
-
1109
- /**
1110
- * @param {object} options options object
1111
- * @param {Module} options.module the module
1112
- * @param {RuntimeSpec=} options.runtime runtime
1113
- * @param {CodeGenerationResults} options.codeGenerationResults the code generation results
1114
- * @returns {string} the url of the asset
1115
- */
1116
- assetUrl({ runtime, module, codeGenerationResults }) {
1117
- if (!module) {
1118
- return "data:,";
1119
- }
1120
- const codeGen = codeGenerationResults.get(module, runtime);
1121
- const data = /** @type {NonNullable<CodeGenerationResult["data"]>} */ (
1122
- codeGen.data
1123
- );
1124
- const url = data.get("url");
1125
- if (url) return url.toString();
1126
- const assetPath = data.get("assetPathForCss");
1127
- return assetPath;
1128
- }
1129
1100
  }
1130
1101
 
1131
1102
  module.exports = RuntimeTemplate;
@@ -236,11 +236,17 @@ class SourceMapDevToolPlugin {
236
236
  fileIndex++;
237
237
  return callback();
238
238
  }
239
+
240
+ const chunk = fileToChunk.get(file);
241
+ const sourceMapNamespace = compilation.getPath(this.namespace, {
242
+ chunk
243
+ });
244
+
239
245
  const cacheItem = cache.getItemCache(
240
246
  file,
241
247
  cache.mergeEtags(
242
248
  cache.getLazyHashedEtag(asset.source),
243
- namespace
249
+ sourceMapNamespace
244
250
  )
245
251
  );
246
252
 
@@ -270,11 +276,8 @@ class SourceMapDevToolPlugin {
270
276
  /**
271
277
  * Add file to chunk, if not presented there
272
278
  */
273
- if (cachedFile !== file) {
274
- const chunk = fileToChunk.get(file);
275
- if (chunk !== undefined)
276
- chunk.auxiliaryFiles.add(cachedFile);
277
- }
279
+ if (cachedFile !== file && chunk !== undefined)
280
+ chunk.auxiliaryFiles.add(cachedFile);
278
281
  }
279
282
 
280
283
  reportProgress(
@@ -326,7 +329,7 @@ class SourceMapDevToolPlugin {
326
329
  module,
327
330
  {
328
331
  moduleFilenameTemplate,
329
- namespace
332
+ namespace: sourceMapNamespace
330
333
  },
331
334
  {
332
335
  requestShortener,
package/lib/Watching.js CHANGED
@@ -77,8 +77,8 @@ class Watching {
77
77
  }
78
78
 
79
79
  /**
80
- * @param {ReadonlySet<string>=} changedFiles changed files
81
- * @param {ReadonlySet<string>=} removedFiles removed files
80
+ * @param {ReadonlySet<string> | undefined | null} changedFiles changed files
81
+ * @param {ReadonlySet<string> | undefined | null} removedFiles removed files
82
82
  */
83
83
  _mergeWithCollected(changedFiles, removedFiles) {
84
84
  if (!changedFiles) return;