webpack 5.105.4 → 5.106.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 (123) 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 +34 -11
  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 +69 -7
  20. package/lib/ModuleGraph.js +3 -0
  21. package/lib/ModuleParseError.js +1 -1
  22. package/lib/ModuleTypeConstants.js +1 -1
  23. package/lib/NormalModule.js +7 -3
  24. package/lib/NormalModuleFactory.js +20 -1
  25. package/lib/ProgressPlugin.js +39 -29
  26. package/lib/RuntimeGlobals.js +6 -0
  27. package/lib/RuntimeTemplate.js +1 -1
  28. package/lib/SourceMapDevToolPlugin.js +13 -11
  29. package/lib/TemplatedPathPlugin.js +4 -3
  30. package/lib/WatchIgnorePlugin.js +15 -13
  31. package/lib/WebpackOptionsApply.js +4 -4
  32. package/lib/asset/AssetModulesPlugin.js +50 -29
  33. package/lib/cli.js +3 -1
  34. package/lib/config/defaults.js +27 -13
  35. package/lib/config/normalization.js +3 -2
  36. package/lib/container/ContainerPlugin.js +46 -42
  37. package/lib/container/ContainerReferencePlugin.js +42 -26
  38. package/lib/container/FallbackModule.js +1 -1
  39. package/lib/container/ModuleFederationPlugin.js +17 -13
  40. package/lib/css/CssGenerator.js +306 -192
  41. package/lib/css/CssInjectStyleRuntimeModule.js +179 -0
  42. package/lib/css/CssLoadingRuntimeModule.js +1 -4
  43. package/lib/css/CssModulesPlugin.js +197 -98
  44. package/lib/css/CssParser.js +243 -134
  45. package/lib/css/walkCssTokens.js +115 -12
  46. package/lib/debug/ProfilingPlugin.js +16 -13
  47. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +20 -15
  48. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -3
  49. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -2
  50. package/lib/dependencies/CommonJsExportsDependency.js +1 -1
  51. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
  52. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  53. package/lib/dependencies/CommonJsImportsParserPlugin.js +63 -2
  54. package/lib/dependencies/CommonJsRequireContextDependency.js +21 -0
  55. package/lib/dependencies/CommonJsRequireDependency.js +42 -1
  56. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -1
  57. package/lib/dependencies/ContextElementDependency.js +1 -1
  58. package/lib/dependencies/CssIcssExportDependency.js +211 -88
  59. package/lib/dependencies/CssIcssImportDependency.js +13 -70
  60. package/lib/dependencies/CssIcssSymbolDependency.js +19 -30
  61. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +13 -2
  62. package/lib/dependencies/HarmonyExportExpressionDependency.js +35 -5
  63. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -3
  64. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  65. package/lib/dependencies/HarmonyImportDependency.js +21 -8
  66. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +4 -1
  67. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportSpecifierDependency.js +13 -2
  69. package/lib/dependencies/ImportContextDependency.js +1 -1
  70. package/lib/dependencies/ImportDependency.js +16 -2
  71. package/lib/dependencies/ImportMetaPlugin.js +39 -29
  72. package/lib/dependencies/ImportParserPlugin.js +4 -5
  73. package/lib/dependencies/ImportPhase.js +65 -22
  74. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
  75. package/lib/esm/ModuleChunkFormatPlugin.js +1 -4
  76. package/lib/ids/HashedModuleIdsPlugin.js +21 -23
  77. package/lib/ids/OccurrenceChunkIdsPlugin.js +15 -11
  78. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -11
  79. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -4
  80. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -4
  81. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -2
  82. package/lib/javascript/JavascriptModulesPlugin.js +38 -12
  83. package/lib/javascript/JavascriptParser.js +5 -3
  84. package/lib/json/JsonModulesPlugin.js +28 -21
  85. package/lib/library/AssignLibraryPlugin.js +1 -1
  86. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  87. package/lib/library/ModuleLibraryPlugin.js +35 -13
  88. package/lib/library/SystemLibraryPlugin.js +1 -1
  89. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +22 -0
  90. package/lib/optimize/AggressiveSplittingPlugin.js +18 -31
  91. package/lib/optimize/ConcatenatedModule.js +4 -3
  92. package/lib/optimize/InnerGraphPlugin.js +11 -5
  93. package/lib/optimize/LimitChunkCountPlugin.js +22 -18
  94. package/lib/optimize/MergeDuplicateChunksPlugin.js +15 -12
  95. package/lib/optimize/MinChunkSizePlugin.js +20 -16
  96. package/lib/optimize/RemoveEmptyChunksPlugin.js +0 -1
  97. package/lib/rules/RuleSetCompiler.js +1 -0
  98. package/lib/schemes/HttpUriPlugin.js +20 -11
  99. package/lib/schemes/VirtualUrlPlugin.js +77 -30
  100. package/lib/serialization/FileMiddleware.js +7 -7
  101. package/lib/sharing/ConsumeSharedPlugin.js +32 -25
  102. package/lib/sharing/ProvideSharedPlugin.js +29 -25
  103. package/lib/util/{propertyName.js → property.js} +26 -1
  104. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +148 -0
  105. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +54 -0
  106. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +105 -0
  107. package/lib/wasm-async/AsyncWebAssemblyParser.js +30 -6
  108. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +26 -2
  109. package/lib/web/FetchCompileAsyncWasmPlugin.js +23 -0
  110. package/lib/web/JsonpTemplatePlugin.js +1 -0
  111. package/lib/webpack.js +34 -4
  112. package/package.json +18 -16
  113. package/schemas/WebpackOptions.check.js +1 -1
  114. package/schemas/WebpackOptions.json +82 -22
  115. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  116. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  117. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  118. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +1 -1
  119. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -1
  120. package/schemas/plugins/schemes/VirtualUrlPlugin.json +8 -0
  121. package/types.d.ts +511 -114
  122. package/lib/util/create-schema-validation.js +0 -41
  123. 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
  /**
@@ -117,14 +120,11 @@ const makeSerializable = require("./util/makeSerializable");
117
120
  * @property {[{ shareScope: string, initStage: number, init: string }]} share-init share-init for modules federation
118
121
  */
119
122
 
120
- /* eslint-disable jsdoc/type-formatting */
121
123
  /**
122
124
  * @template {string} K
123
125
  * @typedef {K extends keyof AllCodeGenerationSchemas ? AllCodeGenerationSchemas[K] : EXPECTED_ANY} CodeGenValue
124
126
  */
125
- /* eslint-enable jsdoc/type-formatting */
126
127
 
127
- /* eslint-disable jsdoc/require-template */
128
128
  /**
129
129
  * @typedef {object} CodeGenMapOverloads
130
130
  * @property {<K extends string>(key: K) => CodeGenValue<K> | undefined} get
@@ -156,7 +156,6 @@ const makeSerializable = require("./util/makeSerializable");
156
156
  /**
157
157
  * @typedef {object} KnownBuildMeta
158
158
  * @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
159
- * @property {CssParserExportType=} exportType
160
159
  * @property {(false | "redirect" | "redirect-warn")=} defaultObject
161
160
  * @property {boolean=} strictHarmonyModule
162
161
  * @property {boolean=} treatAsCommonJs
@@ -303,6 +302,7 @@ class Module extends DependenciesBlock {
303
302
  // TODO remove in webpack 6
304
303
  // BACKWARD-COMPAT START
305
304
  /**
305
+ * @deprecated
306
306
  * @returns {ModuleId | null} module id
307
307
  */
308
308
  get id() {
@@ -314,6 +314,7 @@ class Module extends DependenciesBlock {
314
314
  }
315
315
 
316
316
  /**
317
+ * @deprecated
317
318
  * @param {ModuleId} value value
318
319
  */
319
320
  set id(value) {
@@ -329,6 +330,7 @@ class Module extends DependenciesBlock {
329
330
  }
330
331
 
331
332
  /**
333
+ * @deprecated
332
334
  * @returns {string} the hash of the module
333
335
  */
334
336
  get hash() {
@@ -340,6 +342,7 @@ class Module extends DependenciesBlock {
340
342
  }
341
343
 
342
344
  /**
345
+ * @deprecated
343
346
  * @returns {string} the shortened hash of the module
344
347
  */
345
348
  get renderedHash() {
@@ -350,6 +353,10 @@ class Module extends DependenciesBlock {
350
353
  ).getRenderedModuleHash(this, undefined);
351
354
  }
352
355
 
356
+ /**
357
+ * @deprecated
358
+ * @returns {ModuleProfile | undefined} module profile
359
+ */
353
360
  get profile() {
354
361
  return ModuleGraph.getModuleGraphForModule(
355
362
  this,
@@ -358,6 +365,10 @@ class Module extends DependenciesBlock {
358
365
  ).getProfile(this);
359
366
  }
360
367
 
368
+ /**
369
+ * @deprecated
370
+ * @param {ModuleProfile | undefined} value module profile
371
+ */
361
372
  set profile(value) {
362
373
  ModuleGraph.getModuleGraphForModule(
363
374
  this,
@@ -367,6 +378,7 @@ class Module extends DependenciesBlock {
367
378
  }
368
379
 
369
380
  /**
381
+ * @deprecated
370
382
  * @returns {number | null} the pre order index
371
383
  */
372
384
  get index() {
@@ -378,6 +390,7 @@ class Module extends DependenciesBlock {
378
390
  }
379
391
 
380
392
  /**
393
+ * @deprecated
381
394
  * @param {number} value the pre order index
382
395
  */
383
396
  set index(value) {
@@ -389,6 +402,7 @@ class Module extends DependenciesBlock {
389
402
  }
390
403
 
391
404
  /**
405
+ * @deprecated
392
406
  * @returns {number | null} the post order index
393
407
  */
394
408
  get index2() {
@@ -400,6 +414,7 @@ class Module extends DependenciesBlock {
400
414
  }
401
415
 
402
416
  /**
417
+ * @deprecated
403
418
  * @param {number} value the post order index
404
419
  */
405
420
  set index2(value) {
@@ -411,6 +426,7 @@ class Module extends DependenciesBlock {
411
426
  }
412
427
 
413
428
  /**
429
+ * @deprecated
414
430
  * @returns {number | null} the depth
415
431
  */
416
432
  get depth() {
@@ -422,6 +438,7 @@ class Module extends DependenciesBlock {
422
438
  }
423
439
 
424
440
  /**
441
+ * @deprecated
425
442
  * @param {number} value the depth
426
443
  */
427
444
  set depth(value) {
@@ -433,6 +450,7 @@ class Module extends DependenciesBlock {
433
450
  }
434
451
 
435
452
  /**
453
+ * @deprecated
436
454
  * @returns {Module | null | undefined} issuer
437
455
  */
438
456
  get issuer() {
@@ -444,6 +462,7 @@ class Module extends DependenciesBlock {
444
462
  }
445
463
 
446
464
  /**
465
+ * @deprecated
447
466
  * @param {Module | null} value issuer
448
467
  */
449
468
  set issuer(value) {
@@ -454,6 +473,10 @@ class Module extends DependenciesBlock {
454
473
  ).setIssuer(this, value);
455
474
  }
456
475
 
476
+ /**
477
+ * @deprecated
478
+ * @returns {boolean | SortableSet<string> | null} used exports
479
+ */
457
480
  get usedExports() {
458
481
  return ModuleGraph.getModuleGraphForModule(
459
482
  this,
@@ -474,6 +497,10 @@ class Module extends DependenciesBlock {
474
497
  ).getOptimizationBailout(this);
475
498
  }
476
499
 
500
+ /**
501
+ * @deprecated
502
+ * @returns {boolean} true when optional, otherwise false
503
+ */
477
504
  get optional() {
478
505
  return this.isOptional(
479
506
  ModuleGraph.getModuleGraphForModule(
@@ -485,6 +512,7 @@ class Module extends DependenciesBlock {
485
512
  }
486
513
 
487
514
  /**
515
+ * @deprecated
488
516
  * @param {Chunk} chunk the chunk
489
517
  * @returns {boolean} true, when the module was added
490
518
  */
@@ -500,6 +528,7 @@ class Module extends DependenciesBlock {
500
528
  }
501
529
 
502
530
  /**
531
+ * @deprecated
503
532
  * @param {Chunk} chunk the chunk
504
533
  * @returns {void}
505
534
  */
@@ -512,6 +541,7 @@ class Module extends DependenciesBlock {
512
541
  }
513
542
 
514
543
  /**
544
+ * @deprecated
515
545
  * @param {Chunk} chunk the chunk
516
546
  * @returns {boolean} true, when the module is in the chunk
517
547
  */
@@ -523,6 +553,10 @@ class Module extends DependenciesBlock {
523
553
  ).isModuleInChunk(this, chunk);
524
554
  }
525
555
 
556
+ /**
557
+ * @deprecated
558
+ * @returns {boolean} true when is entry module, otherwise false
559
+ */
526
560
  isEntryModule() {
527
561
  return ChunkGraph.getChunkGraphForModule(
528
562
  this,
@@ -531,6 +565,10 @@ class Module extends DependenciesBlock {
531
565
  ).isEntryModule(this);
532
566
  }
533
567
 
568
+ /**
569
+ * @deprecated
570
+ * @returns {Chunk[]} chunks
571
+ */
534
572
  getChunks() {
535
573
  return ChunkGraph.getChunkGraphForModule(
536
574
  this,
@@ -539,6 +577,10 @@ class Module extends DependenciesBlock {
539
577
  ).getModuleChunks(this);
540
578
  }
541
579
 
580
+ /**
581
+ * @deprecated
582
+ * @returns {number} number of chunks
583
+ */
542
584
  getNumberOfChunks() {
543
585
  return ChunkGraph.getChunkGraphForModule(
544
586
  this,
@@ -547,6 +589,10 @@ class Module extends DependenciesBlock {
547
589
  ).getNumberOfModuleChunks(this);
548
590
  }
549
591
 
592
+ /**
593
+ * @deprecated
594
+ * @returns {Iterable<Chunk>} chunks
595
+ */
550
596
  get chunksIterable() {
551
597
  return ChunkGraph.getChunkGraphForModule(
552
598
  this,
@@ -556,6 +602,7 @@ class Module extends DependenciesBlock {
556
602
  }
557
603
 
558
604
  /**
605
+ * @deprecated
559
606
  * @param {string} exportName a name of an export
560
607
  * @returns {boolean | null} true, if the export is provided why the module.
561
608
  * null, if it's unknown.
@@ -1095,7 +1142,7 @@ class Module extends DependenciesBlock {
1095
1142
  /**
1096
1143
  * @param {Chunk} chunk the chunk which condition should be checked
1097
1144
  * @param {Compilation} compilation the compilation
1098
- * @returns {boolean} true, if the chunk is ok for the module
1145
+ * @returns {boolean} true if the module can be placed in the chunk
1099
1146
  */
1100
1147
  chunkCondition(chunk, compilation) {
1101
1148
  return true;
@@ -1221,6 +1268,21 @@ class Module extends DependenciesBlock {
1221
1268
  this.codeGenerationDependencies = read();
1222
1269
  super.deserialize(context);
1223
1270
  }
1271
+
1272
+ // TODO remove in webpack 6
1273
+ /**
1274
+ * @deprecated In webpack 6, call getSourceBasicTypes() directly on the module instance instead of using this static method.
1275
+ * @param {Module} module the module
1276
+ * @returns {ReturnType<Module["getSourceBasicTypes"]>} the source types of the module
1277
+ */
1278
+ static getSourceBasicTypes(module) {
1279
+ if (!(module instanceof Module)) {
1280
+ // https://github.com/webpack/webpack/issues/20597
1281
+ // fallback to javascript
1282
+ return JAVASCRIPT_TYPES;
1283
+ }
1284
+ return module.getSourceBasicTypes();
1285
+ }
1224
1286
  }
1225
1287
 
1226
1288
  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;
@@ -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
  /**
@@ -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(() =>
@@ -11,7 +11,6 @@ const Compilation = require("./Compilation");
11
11
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
12
12
  const ProgressPlugin = require("./ProgressPlugin");
13
13
  const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
14
- const createSchemaValidation = require("./util/create-schema-validation");
15
14
  const createHash = require("./util/createHash");
16
15
  const { dirname, relative } = require("./util/fs");
17
16
  const generateDebugId = require("./util/generateDebugId");
@@ -34,14 +33,6 @@ const { makePathsAbsolute } = require("./util/identifier");
34
33
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
35
34
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
36
35
 
37
- const validate = createSchemaValidation(
38
- require("../schemas/plugins/SourceMapDevToolPlugin.check"),
39
- () => require("../schemas/plugins/SourceMapDevToolPlugin.json"),
40
- {
41
- name: "SourceMap DevTool Plugin",
42
- baseDataPath: "options"
43
- }
44
- );
45
36
  /**
46
37
  * @typedef {object} SourceMapTask
47
38
  * @property {Source} asset
@@ -141,8 +132,6 @@ class SourceMapDevToolPlugin {
141
132
  * @throws {Error} throws error, if got more than 1 arguments
142
133
  */
143
134
  constructor(options = {}) {
144
- validate(options);
145
-
146
135
  /** @type {undefined | null | false | string} */
147
136
  this.sourceMapFilename = options.filename;
148
137
  /** @type {false | TemplatePath} */
@@ -170,6 +159,19 @@ class SourceMapDevToolPlugin {
170
159
  * @returns {void}
171
160
  */
172
161
  apply(compiler) {
162
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
163
+ compiler.validate(
164
+ () => require("../schemas/plugins/SourceMapDevToolPlugin.json"),
165
+ this.options,
166
+ {
167
+ name: "SourceMap DevTool Plugin",
168
+ baseDataPath: "options"
169
+ },
170
+ (options) =>
171
+ require("../schemas/plugins/SourceMapDevToolPlugin.check")(options)
172
+ );
173
+ });
174
+
173
175
  const outputFs =
174
176
  /** @type {OutputFileSystem} */
175
177
  (compiler.outputFileSystem);
@@ -138,10 +138,10 @@ const deprecated = (fn, message, code) => {
138
138
  /**
139
139
  * @param {TemplatePath} path the raw path
140
140
  * @param {PathData} data context data
141
- * @param {AssetInfo | undefined} assetInfo extra info about the asset (will be written to)
141
+ * @param {AssetInfo=} assetInfo extra info about the asset (will be written to)
142
142
  * @returns {string} the interpolated path
143
143
  */
144
- const replacePathVariables = (path, data, assetInfo) => {
144
+ const interpolate = (path, data, assetInfo) => {
145
145
  const chunkGraph = data.chunkGraph;
146
146
 
147
147
  /** @type {Map<string, Replacer>} */
@@ -392,9 +392,10 @@ class TemplatedPathPlugin {
392
392
  */
393
393
  apply(compiler) {
394
394
  compiler.hooks.compilation.tap(plugin, (compilation) => {
395
- compilation.hooks.assetPath.tap(plugin, replacePathVariables);
395
+ compilation.hooks.assetPath.tap(plugin, interpolate);
396
396
  });
397
397
  }
398
398
  }
399
399
 
400
400
  module.exports = TemplatedPathPlugin;
401
+ module.exports.interpolate = interpolate;