webpack 5.105.3 → 5.106.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.
Files changed (131) hide show
  1. package/README.md +3 -6
  2. package/lib/BannerPlugin.js +13 -13
  3. package/lib/Chunk.js +25 -0
  4. package/lib/ChunkGraph.js +8 -4
  5. package/lib/CleanPlugin.js +23 -20
  6. package/lib/CompatibilityPlugin.js +1 -1
  7. package/lib/Compilation.js +36 -13
  8. package/lib/Compiler.js +59 -1
  9. package/lib/CssModule.js +17 -2
  10. package/lib/Dependency.js +1 -1
  11. package/lib/DllPlugin.js +17 -17
  12. package/lib/DllReferencePlugin.js +20 -18
  13. package/lib/DotenvPlugin.js +29 -27
  14. package/lib/ExternalModule.js +39 -6
  15. package/lib/FileSystemInfo.js +3 -1
  16. package/lib/IgnorePlugin.js +12 -11
  17. package/lib/LoaderOptionsPlugin.js +17 -15
  18. package/lib/ManifestPlugin.js +27 -25
  19. package/lib/Module.js +84 -4
  20. package/lib/ModuleGraph.js +3 -0
  21. package/lib/ModuleParseError.js +1 -1
  22. package/lib/ModuleTypeConstants.js +1 -1
  23. package/lib/MultiStats.js +5 -5
  24. package/lib/NormalModule.js +7 -3
  25. package/lib/NormalModuleFactory.js +20 -1
  26. package/lib/ProgressPlugin.js +39 -29
  27. package/lib/RuntimeGlobals.js +6 -0
  28. package/lib/RuntimeModule.js +18 -1
  29. package/lib/RuntimeTemplate.js +1 -1
  30. package/lib/SourceMapDevToolPlugin.js +13 -11
  31. package/lib/Stats.js +3 -2
  32. package/lib/TemplatedPathPlugin.js +4 -3
  33. package/lib/WatchIgnorePlugin.js +15 -13
  34. package/lib/WebpackOptionsApply.js +4 -4
  35. package/lib/asset/AssetModulesPlugin.js +50 -29
  36. package/lib/cli.js +3 -1
  37. package/lib/config/defaults.js +27 -13
  38. package/lib/config/normalization.js +3 -2
  39. package/lib/container/ContainerPlugin.js +46 -42
  40. package/lib/container/ContainerReferencePlugin.js +42 -26
  41. package/lib/container/FallbackModule.js +1 -1
  42. package/lib/container/ModuleFederationPlugin.js +17 -13
  43. package/lib/container/RemoteModule.js +18 -1
  44. package/lib/css/CssGenerator.js +315 -191
  45. package/lib/css/CssInjectStyleRuntimeModule.js +179 -0
  46. package/lib/css/CssLoadingRuntimeModule.js +1 -4
  47. package/lib/css/CssModulesPlugin.js +197 -98
  48. package/lib/css/CssParser.js +231 -134
  49. package/lib/css/walkCssTokens.js +115 -12
  50. package/lib/debug/ProfilingPlugin.js +16 -13
  51. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +20 -15
  52. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -3
  53. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -2
  54. package/lib/dependencies/CommonJsExportsDependency.js +1 -1
  55. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
  56. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  57. package/lib/dependencies/CommonJsImportsParserPlugin.js +63 -2
  58. package/lib/dependencies/CommonJsRequireContextDependency.js +21 -0
  59. package/lib/dependencies/CommonJsRequireDependency.js +42 -1
  60. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -1
  61. package/lib/dependencies/ContextElementDependency.js +1 -1
  62. package/lib/dependencies/CreateRequireParserPlugin.js +11 -0
  63. package/lib/dependencies/CssIcssExportDependency.js +210 -87
  64. package/lib/dependencies/CssIcssImportDependency.js +13 -70
  65. package/lib/dependencies/CssIcssSymbolDependency.js +19 -30
  66. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +13 -2
  67. package/lib/dependencies/HarmonyExportExpressionDependency.js +28 -2
  68. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -3
  69. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  70. package/lib/dependencies/HarmonyImportDependency.js +21 -8
  71. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +124 -205
  72. package/lib/dependencies/HarmonyImportSideEffectDependency.js +12 -6
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +13 -2
  74. package/lib/dependencies/ImportContextDependency.js +1 -1
  75. package/lib/dependencies/ImportDependency.js +16 -2
  76. package/lib/dependencies/ImportMetaPlugin.js +39 -29
  77. package/lib/dependencies/ImportParserPlugin.js +4 -5
  78. package/lib/dependencies/ImportPhase.js +65 -22
  79. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
  80. package/lib/esm/ModuleChunkFormatPlugin.js +1 -4
  81. package/lib/ids/HashedModuleIdsPlugin.js +21 -23
  82. package/lib/ids/OccurrenceChunkIdsPlugin.js +15 -11
  83. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -11
  84. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -4
  85. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -4
  86. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -2
  87. package/lib/javascript/JavascriptModulesPlugin.js +38 -12
  88. package/lib/javascript/JavascriptParser.js +5 -3
  89. package/lib/json/JsonModulesPlugin.js +28 -21
  90. package/lib/library/AssignLibraryPlugin.js +1 -1
  91. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  92. package/lib/library/ModuleLibraryPlugin.js +35 -13
  93. package/lib/library/SystemLibraryPlugin.js +1 -1
  94. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +22 -0
  95. package/lib/optimize/AggressiveSplittingPlugin.js +18 -31
  96. package/lib/optimize/ConcatenatedModule.js +6 -2
  97. package/lib/optimize/InnerGraphPlugin.js +11 -5
  98. package/lib/optimize/LimitChunkCountPlugin.js +22 -18
  99. package/lib/optimize/MergeDuplicateChunksPlugin.js +15 -12
  100. package/lib/optimize/MinChunkSizePlugin.js +20 -16
  101. package/lib/optimize/ModuleConcatenationPlugin.js +4 -1
  102. package/lib/optimize/RemoveEmptyChunksPlugin.js +0 -1
  103. package/lib/rules/RuleSetCompiler.js +1 -0
  104. package/lib/schemes/HttpUriPlugin.js +20 -11
  105. package/lib/schemes/VirtualUrlPlugin.js +77 -30
  106. package/lib/serialization/FileMiddleware.js +7 -7
  107. package/lib/sharing/ConsumeSharedModule.js +18 -1
  108. package/lib/sharing/ConsumeSharedPlugin.js +32 -25
  109. package/lib/sharing/ProvideSharedPlugin.js +29 -25
  110. package/lib/util/AppendOnlyStackedSet.js +22 -1
  111. package/lib/util/{propertyName.js → property.js} +26 -1
  112. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +148 -0
  113. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +54 -0
  114. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +105 -0
  115. package/lib/wasm-async/AsyncWebAssemblyParser.js +30 -6
  116. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +26 -2
  117. package/lib/web/FetchCompileAsyncWasmPlugin.js +23 -0
  118. package/lib/web/JsonpTemplatePlugin.js +1 -0
  119. package/lib/webpack.js +34 -4
  120. package/package.json +20 -18
  121. package/schemas/WebpackOptions.check.js +1 -1
  122. package/schemas/WebpackOptions.json +82 -22
  123. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  124. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  125. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  126. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +1 -1
  127. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -1
  128. package/schemas/plugins/schemes/VirtualUrlPlugin.json +8 -0
  129. package/types.d.ts +606 -150
  130. package/lib/util/create-schema-validation.js +0 -41
  131. package/lib/util/propertyAccess.js +0 -30
package/lib/Module.js CHANGED
@@ -41,12 +41,11 @@ const makeSerializable = require("./util/makeSerializable");
41
41
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
42
42
  /** @typedef {import("./ModuleTypeConstants").ModuleTypes} ModuleTypes */
43
43
  /** @typedef {import("./ModuleGraph").OptimizationBailouts} OptimizationBailouts */
44
+ /** @typedef {import("./ModuleProfile")} ModuleProfile */
44
45
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
45
46
  /** @typedef {import("./RequestShortener")} RequestShortener */
46
47
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
47
48
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
48
- /** @typedef {import("../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
49
-
50
49
  /**
51
50
  * @template T
52
51
  * @typedef {import("./InitFragment")<T>} InitFragment
@@ -59,6 +58,10 @@ const makeSerializable = require("./util/makeSerializable");
59
58
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
60
59
  /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
61
60
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
61
+ /**
62
+ * @template T
63
+ * @typedef {import("./util/SortableSet")<T>} SortableSet
64
+ */
62
65
  /** @typedef {"namespace" | "default-only" | "default-with-named" | "dynamic"} ExportsType */
63
66
 
64
67
  /**
@@ -80,6 +83,8 @@ const makeSerializable = require("./util/makeSerializable");
80
83
  /** @typedef {KnownSourceType | string} SourceType */
81
84
  /** @typedef {ReadonlySet<SourceType>} SourceTypes */
82
85
 
86
+ /** @typedef {ReadonlySet<typeof JAVASCRIPT_TYPE | string>} BasicSourceTypes */
87
+
83
88
  // TODO webpack 6: compilation will be required in CodeGenerationContext
84
89
  /**
85
90
  * @typedef {object} CodeGenerationContext
@@ -154,7 +159,6 @@ const makeSerializable = require("./util/makeSerializable");
154
159
  /**
155
160
  * @typedef {object} KnownBuildMeta
156
161
  * @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
157
- * @property {CssParserExportType=} exportType
158
162
  * @property {(false | "redirect" | "redirect-warn")=} defaultObject
159
163
  * @property {boolean=} strictHarmonyModule
160
164
  * @property {boolean=} treatAsCommonJs
@@ -301,6 +305,7 @@ class Module extends DependenciesBlock {
301
305
  // TODO remove in webpack 6
302
306
  // BACKWARD-COMPAT START
303
307
  /**
308
+ * @deprecated
304
309
  * @returns {ModuleId | null} module id
305
310
  */
306
311
  get id() {
@@ -312,6 +317,7 @@ class Module extends DependenciesBlock {
312
317
  }
313
318
 
314
319
  /**
320
+ * @deprecated
315
321
  * @param {ModuleId} value value
316
322
  */
317
323
  set id(value) {
@@ -327,6 +333,7 @@ class Module extends DependenciesBlock {
327
333
  }
328
334
 
329
335
  /**
336
+ * @deprecated
330
337
  * @returns {string} the hash of the module
331
338
  */
332
339
  get hash() {
@@ -338,6 +345,7 @@ class Module extends DependenciesBlock {
338
345
  }
339
346
 
340
347
  /**
348
+ * @deprecated
341
349
  * @returns {string} the shortened hash of the module
342
350
  */
343
351
  get renderedHash() {
@@ -348,6 +356,10 @@ class Module extends DependenciesBlock {
348
356
  ).getRenderedModuleHash(this, undefined);
349
357
  }
350
358
 
359
+ /**
360
+ * @deprecated
361
+ * @returns {ModuleProfile | undefined} module profile
362
+ */
351
363
  get profile() {
352
364
  return ModuleGraph.getModuleGraphForModule(
353
365
  this,
@@ -356,6 +368,10 @@ class Module extends DependenciesBlock {
356
368
  ).getProfile(this);
357
369
  }
358
370
 
371
+ /**
372
+ * @deprecated
373
+ * @param {ModuleProfile | undefined} value module profile
374
+ */
359
375
  set profile(value) {
360
376
  ModuleGraph.getModuleGraphForModule(
361
377
  this,
@@ -365,6 +381,7 @@ class Module extends DependenciesBlock {
365
381
  }
366
382
 
367
383
  /**
384
+ * @deprecated
368
385
  * @returns {number | null} the pre order index
369
386
  */
370
387
  get index() {
@@ -376,6 +393,7 @@ class Module extends DependenciesBlock {
376
393
  }
377
394
 
378
395
  /**
396
+ * @deprecated
379
397
  * @param {number} value the pre order index
380
398
  */
381
399
  set index(value) {
@@ -387,6 +405,7 @@ class Module extends DependenciesBlock {
387
405
  }
388
406
 
389
407
  /**
408
+ * @deprecated
390
409
  * @returns {number | null} the post order index
391
410
  */
392
411
  get index2() {
@@ -398,6 +417,7 @@ class Module extends DependenciesBlock {
398
417
  }
399
418
 
400
419
  /**
420
+ * @deprecated
401
421
  * @param {number} value the post order index
402
422
  */
403
423
  set index2(value) {
@@ -409,6 +429,7 @@ class Module extends DependenciesBlock {
409
429
  }
410
430
 
411
431
  /**
432
+ * @deprecated
412
433
  * @returns {number | null} the depth
413
434
  */
414
435
  get depth() {
@@ -420,6 +441,7 @@ class Module extends DependenciesBlock {
420
441
  }
421
442
 
422
443
  /**
444
+ * @deprecated
423
445
  * @param {number} value the depth
424
446
  */
425
447
  set depth(value) {
@@ -431,6 +453,7 @@ class Module extends DependenciesBlock {
431
453
  }
432
454
 
433
455
  /**
456
+ * @deprecated
434
457
  * @returns {Module | null | undefined} issuer
435
458
  */
436
459
  get issuer() {
@@ -442,6 +465,7 @@ class Module extends DependenciesBlock {
442
465
  }
443
466
 
444
467
  /**
468
+ * @deprecated
445
469
  * @param {Module | null} value issuer
446
470
  */
447
471
  set issuer(value) {
@@ -452,6 +476,10 @@ class Module extends DependenciesBlock {
452
476
  ).setIssuer(this, value);
453
477
  }
454
478
 
479
+ /**
480
+ * @deprecated
481
+ * @returns {boolean | SortableSet<string> | null} used exports
482
+ */
455
483
  get usedExports() {
456
484
  return ModuleGraph.getModuleGraphForModule(
457
485
  this,
@@ -472,6 +500,10 @@ class Module extends DependenciesBlock {
472
500
  ).getOptimizationBailout(this);
473
501
  }
474
502
 
503
+ /**
504
+ * @deprecated
505
+ * @returns {boolean} true when optional, otherwise false
506
+ */
475
507
  get optional() {
476
508
  return this.isOptional(
477
509
  ModuleGraph.getModuleGraphForModule(
@@ -483,6 +515,7 @@ class Module extends DependenciesBlock {
483
515
  }
484
516
 
485
517
  /**
518
+ * @deprecated
486
519
  * @param {Chunk} chunk the chunk
487
520
  * @returns {boolean} true, when the module was added
488
521
  */
@@ -498,6 +531,7 @@ class Module extends DependenciesBlock {
498
531
  }
499
532
 
500
533
  /**
534
+ * @deprecated
501
535
  * @param {Chunk} chunk the chunk
502
536
  * @returns {void}
503
537
  */
@@ -510,6 +544,7 @@ class Module extends DependenciesBlock {
510
544
  }
511
545
 
512
546
  /**
547
+ * @deprecated
513
548
  * @param {Chunk} chunk the chunk
514
549
  * @returns {boolean} true, when the module is in the chunk
515
550
  */
@@ -521,6 +556,10 @@ class Module extends DependenciesBlock {
521
556
  ).isModuleInChunk(this, chunk);
522
557
  }
523
558
 
559
+ /**
560
+ * @deprecated
561
+ * @returns {boolean} true when is entry module, otherwise false
562
+ */
524
563
  isEntryModule() {
525
564
  return ChunkGraph.getChunkGraphForModule(
526
565
  this,
@@ -529,6 +568,10 @@ class Module extends DependenciesBlock {
529
568
  ).isEntryModule(this);
530
569
  }
531
570
 
571
+ /**
572
+ * @deprecated
573
+ * @returns {Chunk[]} chunks
574
+ */
532
575
  getChunks() {
533
576
  return ChunkGraph.getChunkGraphForModule(
534
577
  this,
@@ -537,6 +580,10 @@ class Module extends DependenciesBlock {
537
580
  ).getModuleChunks(this);
538
581
  }
539
582
 
583
+ /**
584
+ * @deprecated
585
+ * @returns {number} number of chunks
586
+ */
540
587
  getNumberOfChunks() {
541
588
  return ChunkGraph.getChunkGraphForModule(
542
589
  this,
@@ -545,6 +592,10 @@ class Module extends DependenciesBlock {
545
592
  ).getNumberOfModuleChunks(this);
546
593
  }
547
594
 
595
+ /**
596
+ * @deprecated
597
+ * @returns {Iterable<Chunk>} chunks
598
+ */
548
599
  get chunksIterable() {
549
600
  return ChunkGraph.getChunkGraphForModule(
550
601
  this,
@@ -554,6 +605,7 @@ class Module extends DependenciesBlock {
554
605
  }
555
606
 
556
607
  /**
608
+ * @deprecated
557
609
  * @param {string} exportName a name of an export
558
610
  * @returns {boolean | null} true, if the export is provided why the module.
559
611
  * null, if it's unknown.
@@ -966,6 +1018,19 @@ class Module extends DependenciesBlock {
966
1018
  return JAVASCRIPT_TYPES;
967
1019
  }
968
1020
 
1021
+ /**
1022
+ * Basic source types are high-level categories like javascript, css, webassembly, etc.
1023
+ * We only have built-in knowledge about the javascript basic type here; other basic types may be
1024
+ * added or changed over time by generators and do not need to be handled or detected here.
1025
+ *
1026
+ * Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
1027
+ * from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
1028
+ * @returns {BasicSourceTypes} types available (do not mutate)
1029
+ */
1030
+ getSourceBasicTypes() {
1031
+ return this.getSourceTypes();
1032
+ }
1033
+
969
1034
  /**
970
1035
  * @abstract
971
1036
  * @deprecated Use codeGeneration() instead
@@ -1080,7 +1145,7 @@ class Module extends DependenciesBlock {
1080
1145
  /**
1081
1146
  * @param {Chunk} chunk the chunk which condition should be checked
1082
1147
  * @param {Compilation} compilation the compilation
1083
- * @returns {boolean} true, if the chunk is ok for the module
1148
+ * @returns {boolean} true if the module can be placed in the chunk
1084
1149
  */
1085
1150
  chunkCondition(chunk, compilation) {
1086
1151
  return true;
@@ -1206,6 +1271,21 @@ class Module extends DependenciesBlock {
1206
1271
  this.codeGenerationDependencies = read();
1207
1272
  super.deserialize(context);
1208
1273
  }
1274
+
1275
+ // TODO remove in webpack 6
1276
+ /**
1277
+ * @deprecated In webpack 6, call getSourceBasicTypes() directly on the module instance instead of using this static method.
1278
+ * @param {Module} module the module
1279
+ * @returns {ReturnType<Module["getSourceBasicTypes"]>} the source types of the module
1280
+ */
1281
+ static getSourceBasicTypes(module) {
1282
+ if (!(module instanceof Module)) {
1283
+ // https://github.com/webpack/webpack/issues/20597
1284
+ // fallback to javascript
1285
+ return JAVASCRIPT_TYPES;
1286
+ }
1287
+ return module.getSourceBasicTypes();
1288
+ }
1209
1289
  }
1210
1290
 
1211
1291
  makeSerializable(Module, "webpack/lib/Module");
@@ -961,6 +961,7 @@ class ModuleGraph {
961
961
 
962
962
  // TODO remove in webpack 6
963
963
  /**
964
+ * @deprecated
964
965
  * @param {Module} module the module
965
966
  * @param {string} deprecateMessage message for the deprecation message
966
967
  * @param {string} deprecationCode code for the deprecation
@@ -994,6 +995,7 @@ class ModuleGraph {
994
995
 
995
996
  // TODO remove in webpack 6
996
997
  /**
998
+ * @deprecated
997
999
  * @param {Module} module the module
998
1000
  * @param {ModuleGraph} moduleGraph the module graph
999
1001
  * @returns {void}
@@ -1004,6 +1006,7 @@ class ModuleGraph {
1004
1006
 
1005
1007
  // TODO remove in webpack 6
1006
1008
  /**
1009
+ * @deprecated
1007
1010
  * @param {Module} module the module
1008
1011
  * @returns {void}
1009
1012
  */
@@ -28,7 +28,7 @@ class ModuleParseError extends WebpackError {
28
28
  let loc;
29
29
 
30
30
  if (
31
- ((Buffer.isBuffer(source) && source.slice(0, 4).equals(WASM_HEADER)) ||
31
+ ((Buffer.isBuffer(source) && source.subarray(0, 4).equals(WASM_HEADER)) ||
32
32
  (typeof source === "string" && /^\0asm/.test(source))) &&
33
33
  !type.startsWith("webassembly")
34
34
  ) {
@@ -175,7 +175,7 @@ module.exports.JAVASCRIPT_MODULE_TYPE_ESM = JAVASCRIPT_MODULE_TYPE_ESM;
175
175
  module.exports.JSON_MODULE_TYPE = JSON_MODULE_TYPE;
176
176
  /** @type {WebAssemblyModuleTypes[]} */
177
177
  module.exports.WEBASSEMBLY_MODULES = [
178
- WEBASSEMBLY_MODULE_TYPE_SYNC,
178
+ WEBASSEMBLY_MODULE_TYPE_ASYNC,
179
179
  WEBASSEMBLY_MODULE_TYPE_SYNC
180
180
  ];
181
181
  module.exports.WEBASSEMBLY_MODULE_TYPE_ASYNC = WEBASSEMBLY_MODULE_TYPE_ASYNC;
package/lib/MultiStats.js CHANGED
@@ -8,6 +8,7 @@
8
8
  const identifierUtils = require("./util/identifier");
9
9
 
10
10
  /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
11
+ /** @typedef {import("../declarations/WebpackOptions").StatsValue} StatsValue */
11
12
  /** @typedef {import("./Compilation").CreateStatsOptionsContext} CreateStatsOptionsContext */
12
13
  /** @typedef {import("./Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
13
14
  /** @typedef {import("./Stats")} Stats */
@@ -25,8 +26,7 @@ const indent = (str, prefix) => {
25
26
  return prefix + rem;
26
27
  };
27
28
 
28
- /** @typedef {undefined | string | boolean | StatsOptions} ChildrenStatsOptions */
29
- /** @typedef {Omit<StatsOptions, "children"> & { children?: ChildrenStatsOptions | ChildrenStatsOptions[] }} MultiStatsOptions */
29
+ /** @typedef {StatsOptions} MultiStatsOptions */
30
30
  /** @typedef {{ version: boolean, hash: boolean, errorsCount: boolean, warningsCount: boolean, errors: boolean, warnings: boolean, children: NormalizedStatsOptions[] }} ChildOptions */
31
31
 
32
32
  class MultiStats {
@@ -56,7 +56,7 @@ class MultiStats {
56
56
  }
57
57
 
58
58
  /**
59
- * @param {undefined | string | boolean | MultiStatsOptions} options stats options
59
+ * @param {undefined | StatsValue} options stats options
60
60
  * @param {CreateStatsOptionsContext} context context
61
61
  * @returns {ChildOptions} context context
62
62
  */
@@ -109,7 +109,7 @@ class MultiStats {
109
109
  }
110
110
 
111
111
  /**
112
- * @param {(string | boolean | MultiStatsOptions)=} options stats options
112
+ * @param {StatsValue=} options stats options
113
113
  * @returns {StatsCompilation} json output
114
114
  */
115
115
  toJson(options) {
@@ -184,7 +184,7 @@ class MultiStats {
184
184
  }
185
185
 
186
186
  /**
187
- * @param {(string | boolean | MultiStatsOptions)=} options stats options
187
+ * @param {StatsValue=} options stats options
188
188
  * @returns {string} string output
189
189
  */
190
190
  toString(options) {
@@ -229,13 +229,18 @@ makeSerializable(
229
229
 
230
230
  /** @typedef {LoaderContext<EXPECTED_ANY>} AnyLoaderContext */
231
231
 
232
+ /**
233
+ * @deprecated Use the `readResource` hook instead.
234
+ * @typedef {HookMap<FakeHook<AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>>>} DeprecatedReadResourceForScheme
235
+ */
236
+
232
237
  /**
233
238
  * @typedef {object} NormalModuleCompilationHooks
234
239
  * @property {SyncHook<[AnyLoaderContext, NormalModule]>} loader
235
240
  * @property {SyncHook<[LoaderItem[], NormalModule, AnyLoaderContext]>} beforeLoaders
236
241
  * @property {SyncHook<[NormalModule]>} beforeParse
237
242
  * @property {SyncHook<[NormalModule]>} beforeSnapshot
238
- * @property {HookMap<FakeHook<AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>>>} readResourceForScheme
243
+ * @property {DeprecatedReadResourceForScheme} readResourceForScheme
239
244
  * @property {HookMap<AsyncSeriesBailHook<[AnyLoaderContext], string | Buffer | null>>} readResource
240
245
  * @property {SyncWaterfallHook<[Result, NormalModule]>} processResult
241
246
  * @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
@@ -735,7 +740,7 @@ class NormalModule extends Module {
735
740
  options = {};
736
741
  }
737
742
 
738
- if (schema) {
743
+ if (schema && compilation.options.validate) {
739
744
  let name = "Loader";
740
745
  let baseDataPath = "options";
741
746
  /** @type {RegExpExecArray | null} */
@@ -872,7 +877,6 @@ class NormalModule extends Module {
872
877
  return /** @type {AnyLoaderContext} */ (loaderContext);
873
878
  }
874
879
 
875
- // TODO remove `loaderContext` in webpack@6
876
880
  /**
877
881
  * @param {AnyLoaderContext} loaderContext loader context
878
882
  * @param {number} index index
@@ -20,6 +20,7 @@ const ModuleFactory = require("./ModuleFactory");
20
20
  const ModuleGraph = require("./ModuleGraph");
21
21
  const { JAVASCRIPT_MODULE_TYPE_AUTO } = require("./ModuleTypeConstants");
22
22
  const NormalModule = require("./NormalModule");
23
+ const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
23
24
  const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin");
24
25
  const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
25
26
  const ObjectMatcherRulePlugin = require("./rules/ObjectMatcherRulePlugin");
@@ -52,6 +53,8 @@ const {
52
53
  /** @typedef {import("./ResolverFactory")} ResolverFactory */
53
54
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
54
55
  /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
56
+ /** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
57
+ /** @typedef {import("./dependencies/ImportPhase").ImportPhaseName} ImportPhaseName */
55
58
  /** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
56
59
  /** @typedef {import("./rules/RuleSetCompiler").RuleSetRules} RuleSetRules */
57
60
  /** @typedef {import("./rules/RuleSetCompiler").RuleSet} RuleSet */
@@ -72,7 +75,8 @@ const {
72
75
  * @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions
73
76
  * @property {string} context
74
77
  * @property {string} request
75
- * @property {ImportAttributes | undefined} attributes
78
+ * @property {ImportPhaseName=} phase
79
+ * @property {ImportAttributes=} attributes
76
80
  * @property {ModuleDependency[]} dependencies
77
81
  * @property {string} dependencyType
78
82
  * @property {CreateData} createData
@@ -246,6 +250,7 @@ const ruleSetCompiler = new RuleSetCompiler([
246
250
  new BasicMatcherRulePlugin("issuer"),
247
251
  new BasicMatcherRulePlugin("compiler"),
248
252
  new BasicMatcherRulePlugin("issuerLayer"),
253
+ new BasicMatcherRulePlugin("phase"),
249
254
  new ObjectMatcherRulePlugin("assert", "attributes", (value) => {
250
255
  if (value) {
251
256
  return (
@@ -520,6 +525,7 @@ class NormalModuleFactory extends ModuleFactory {
520
525
  dependencies,
521
526
  dependencyType,
522
527
  request,
528
+ phase,
523
529
  attributes,
524
530
  resolveOptions,
525
531
  fileDependencies,
@@ -687,12 +693,14 @@ class NormalModuleFactory extends ModuleFactory {
687
693
  } else {
688
694
  settings.type = JAVASCRIPT_MODULE_TYPE_AUTO;
689
695
  const resourceDataForRules = matchResourceData || resourceData;
696
+
690
697
  const result = this.ruleSet.exec({
691
698
  resource: resourceDataForRules.path,
692
699
  realResource: resourceData.path,
693
700
  resourceQuery: resourceDataForRules.query,
694
701
  resourceFragment: resourceDataForRules.fragment,
695
702
  scheme,
703
+ phase,
696
704
  attributes,
697
705
  mimetype: matchResourceData
698
706
  ? ""
@@ -977,6 +985,16 @@ class NormalModuleFactory extends ModuleFactory {
977
985
  const attributes =
978
986
  /** @type {ModuleDependency & { attributes: ImportAttributes }} */
979
987
  (dependency).attributes;
988
+ const phase =
989
+ typeof (
990
+ /** @type {ModuleDependency & { phase?: ImportPhaseType }} */
991
+ (dependency).phase
992
+ ) === "number"
993
+ ? ImportPhaseUtils.stringify(
994
+ /** @type {ModuleDependency & { phase?: ImportPhaseType }} */
995
+ (dependency).phase
996
+ )
997
+ : "evaluation";
980
998
  const dependencyType = dependency.category || "";
981
999
  const contextInfo = data.contextInfo;
982
1000
  /** @type {FileSystemDependencies} */
@@ -991,6 +1009,7 @@ class NormalModuleFactory extends ModuleFactory {
991
1009
  resolveOptions,
992
1010
  context,
993
1011
  request,
1012
+ phase,
994
1013
  attributes,
995
1014
  dependencies,
996
1015
  dependencyType,
@@ -8,7 +8,6 @@
8
8
  const Compiler = require("./Compiler");
9
9
  const MultiCompiler = require("./MultiCompiler");
10
10
  const NormalModule = require("./NormalModule");
11
- const createSchemaValidation = require("./util/create-schema-validation");
12
11
  const { contextify } = require("./util/identifier");
13
12
 
14
13
  /** @typedef {import("tapable").Tap} Tap */
@@ -17,6 +16,7 @@ const { contextify } = require("./util/identifier");
17
16
  * @typedef {import("tapable").Hook<T, R, AdditionalOptions>} Hook
18
17
  */
19
18
  /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
19
+ /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
20
20
  /** @typedef {import("./Compilation").FactorizeModuleOptions} FactorizeModuleOptions */
21
21
  /** @typedef {import("./Dependency")} Dependency */
22
22
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
@@ -35,15 +35,6 @@ const { contextify } = require("./util/identifier");
35
35
  * @property {number} dependenciesCount dependencies count
36
36
  */
37
37
 
38
- const validate = createSchemaValidation(
39
- require("../schemas/plugins/ProgressPlugin.check"),
40
- () => require("../schemas/plugins/ProgressPlugin.json"),
41
- {
42
- name: "Progress Plugin",
43
- baseDataPath: "options"
44
- }
45
- );
46
-
47
38
  /**
48
39
  * @param {number} a a
49
40
  * @param {number} b b
@@ -142,6 +133,18 @@ const progressReporters = new WeakMap();
142
133
 
143
134
  const PLUGIN_NAME = "ProgressPlugin";
144
135
 
136
+ /** @type {Required<Omit<ProgressPluginOptions, "handler">>} */
137
+ const DEFAULT_OPTIONS = {
138
+ profile: false,
139
+ modulesCount: 5000,
140
+ dependenciesCount: 10000,
141
+ modules: true,
142
+ dependencies: true,
143
+ activeModules: false,
144
+ entries: true,
145
+ percentBy: null
146
+ };
147
+
145
148
  class ProgressPlugin {
146
149
  /**
147
150
  * @param {Compiler} compiler the current compiler
@@ -161,18 +164,21 @@ class ProgressPlugin {
161
164
  };
162
165
  }
163
166
 
164
- validate(options);
165
- options = { ...ProgressPlugin.defaultOptions, ...options };
167
+ /** @type {ProgressPluginOptions} */
168
+ this.options = options;
166
169
 
167
- this.profile = options.profile;
170
+ this.profile = options.profile || DEFAULT_OPTIONS.profile;
168
171
  this.handler = options.handler;
169
- this.modulesCount = options.modulesCount;
170
- this.dependenciesCount = options.dependenciesCount;
171
- this.showEntries = options.entries;
172
- this.showModules = options.modules;
173
- this.showDependencies = options.dependencies;
174
- this.showActiveModules = options.activeModules;
175
- this.percentBy = options.percentBy;
172
+ this.modulesCount = options.modulesCount || DEFAULT_OPTIONS.modulesCount;
173
+ this.dependenciesCount =
174
+ options.dependenciesCount || DEFAULT_OPTIONS.dependenciesCount;
175
+ this.showEntries = options.entries || DEFAULT_OPTIONS.entries;
176
+ this.showModules = options.modules || DEFAULT_OPTIONS.modules;
177
+ this.showDependencies =
178
+ options.dependencies || DEFAULT_OPTIONS.dependencies;
179
+ this.showActiveModules =
180
+ options.activeModules || DEFAULT_OPTIONS.activeModules;
181
+ this.percentBy = options.percentBy || DEFAULT_OPTIONS.percentBy;
176
182
  }
177
183
 
178
184
  /**
@@ -218,6 +224,18 @@ class ProgressPlugin {
218
224
  * @returns {void}
219
225
  */
220
226
  _applyOnCompiler(compiler, handler) {
227
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
228
+ compiler.validate(
229
+ () => require("../schemas/plugins/ProgressPlugin.json"),
230
+ this.options,
231
+ {
232
+ name: "Progress Plugin",
233
+ baseDataPath: "options"
234
+ },
235
+ (options) => require("../schemas/plugins/ProgressPlugin.check")(options)
236
+ );
237
+ });
238
+
221
239
  const showEntries = this.showEntries;
222
240
  const showModules = this.showModules;
223
241
  const showDependencies = this.showDependencies;
@@ -697,15 +715,7 @@ class ProgressPlugin {
697
715
  }
698
716
  }
699
717
 
700
- ProgressPlugin.defaultOptions = {
701
- profile: false,
702
- modulesCount: 5000,
703
- dependenciesCount: 10000,
704
- modules: true,
705
- dependencies: true,
706
- activeModules: false,
707
- entries: true
708
- };
718
+ ProgressPlugin.defaultOptions = DEFAULT_OPTIONS;
709
719
 
710
720
  ProgressPlugin.createDefaultHandler = createDefaultHandler;
711
721
 
@@ -59,6 +59,11 @@ module.exports.chunkName = "__webpack_require__.cn";
59
59
  */
60
60
  module.exports.compatGetDefaultExport = "__webpack_require__.n";
61
61
 
62
+ /**
63
+ * compile a wasm module from id and hash, returning WebAssembly.Module
64
+ */
65
+ module.exports.compileWasm = "__webpack_require__.vs";
66
+
62
67
  /**
63
68
  * create a fake namespace object
64
69
  */
@@ -82,6 +87,7 @@ module.exports.createScriptUrl = "__webpack_require__.tu";
82
87
  * merge multiple CSS stylesheets (CSSStyleSheet or string) into one CSS text string
83
88
  * Arguments: (sheets: Array<CSSStyleSheet | string> | CSSStyleSheet | string) => string
84
89
  */
90
+ module.exports.cssInjectStyle = "__webpack_require__.is";
85
91
  module.exports.cssMergeStyleSheets = "__webpack_require__.mcs";
86
92
 
87
93
  /**
@@ -8,7 +8,10 @@
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("./ModuleSourceTypeConstants");
11
+ const {
12
+ JAVASCRIPT_TYPES,
13
+ RUNTIME_TYPES
14
+ } = require("./ModuleSourceTypeConstants");
12
15
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
13
16
 
14
17
  /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
@@ -29,6 +32,7 @@ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
29
32
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
30
33
  /** @typedef {import("./util/Hash")} Hash */
31
34
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
35
+ /** @typedef {import("./Module").BasicSourceTypes} BasicSourceTypes */
32
36
 
33
37
  class RuntimeModule extends Module {
34
38
  /**
@@ -138,6 +142,19 @@ class RuntimeModule extends Module {
138
142
  return RUNTIME_TYPES;
139
143
  }
140
144
 
145
+ /**
146
+ * Basic source types are high-level categories like javascript, css, webassembly, etc.
147
+ * We only have built-in knowledge about the javascript basic type here; other basic types may be
148
+ * added or changed over time by generators and do not need to be handled or detected here.
149
+ *
150
+ * Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
151
+ * from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
152
+ * @returns {BasicSourceTypes} types available (do not mutate)
153
+ */
154
+ getSourceBasicTypes() {
155
+ return JAVASCRIPT_TYPES;
156
+ }
157
+
141
158
  /**
142
159
  * @param {CodeGenerationContext} context context for code generation
143
160
  * @returns {CodeGenerationResult} result
@@ -19,7 +19,7 @@ const {
19
19
  const { equals } = require("./util/ArrayHelpers");
20
20
  const compileBooleanMatcher = require("./util/compileBooleanMatcher");
21
21
  const memoize = require("./util/memoize");
22
- const propertyAccess = require("./util/propertyAccess");
22
+ const { propertyAccess } = require("./util/property");
23
23
  const { forEachRuntime, subtractRuntime } = require("./util/runtime");
24
24
 
25
25
  const getHarmonyImportDependency = memoize(() =>