webpack 5.65.0 → 5.68.0

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

Potentially problematic release.


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

Files changed (117) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +33 -0
  3. package/lib/Cache.js +1 -1
  4. package/lib/CacheFacade.js +4 -11
  5. package/lib/Chunk.js +2 -0
  6. package/lib/CleanPlugin.js +1 -1
  7. package/lib/Compilation.js +91 -47
  8. package/lib/Compiler.js +57 -3
  9. package/lib/ContextModule.js +21 -17
  10. package/lib/DelegatedModule.js +1 -1
  11. package/lib/Dependency.js +10 -0
  12. package/lib/DependencyTemplate.js +9 -0
  13. package/lib/DependencyTemplates.js +1 -1
  14. package/lib/DllModule.js +1 -1
  15. package/lib/EvalDevToolModulePlugin.js +16 -1
  16. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  17. package/lib/ExternalModule.js +93 -53
  18. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  19. package/lib/FileSystemInfo.js +29 -25
  20. package/lib/Generator.js +2 -0
  21. package/lib/HookWebpackError.js +1 -1
  22. package/lib/Module.js +25 -4
  23. package/lib/ModuleFilenameHelpers.js +5 -1
  24. package/lib/MultiCompiler.js +1 -1
  25. package/lib/MultiWatching.js +1 -1
  26. package/lib/NormalModule.js +9 -5
  27. package/lib/RawModule.js +1 -1
  28. package/lib/RuntimeGlobals.js +29 -1
  29. package/lib/RuntimeModule.js +1 -1
  30. package/lib/RuntimePlugin.js +50 -0
  31. package/lib/RuntimeTemplate.js +21 -0
  32. package/lib/Template.js +2 -1
  33. package/lib/Watching.js +2 -2
  34. package/lib/WebpackOptionsApply.js +43 -2
  35. package/lib/asset/AssetGenerator.js +64 -24
  36. package/lib/asset/AssetModulesPlugin.js +3 -0
  37. package/lib/asset/RawDataUrlModule.js +148 -0
  38. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  39. package/lib/cache/ResolverCachePlugin.js +1 -1
  40. package/lib/cli.js +44 -3
  41. package/lib/config/defaults.js +79 -5
  42. package/lib/config/normalization.js +5 -0
  43. package/lib/container/ContainerEntryModule.js +4 -2
  44. package/lib/container/FallbackModule.js +4 -4
  45. package/lib/container/RemoteModule.js +4 -2
  46. package/lib/css/CssExportsGenerator.js +139 -0
  47. package/lib/css/CssGenerator.js +109 -0
  48. package/lib/css/CssLoadingRuntimeModule.js +447 -0
  49. package/lib/css/CssModulesPlugin.js +461 -0
  50. package/lib/css/CssParser.js +618 -0
  51. package/lib/css/walkCssTokens.js +659 -0
  52. package/lib/debug/ProfilingPlugin.js +12 -10
  53. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  54. package/lib/dependencies/CssExportDependency.js +85 -0
  55. package/lib/dependencies/CssImportDependency.js +75 -0
  56. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  57. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  58. package/lib/dependencies/CssUrlDependency.js +132 -0
  59. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  60. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  61. package/lib/dependencies/LoaderPlugin.js +2 -2
  62. package/lib/dependencies/URLDependency.js +3 -8
  63. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  64. package/lib/hmr/LazyCompilationPlugin.js +45 -21
  65. package/lib/hmr/lazyCompilationBackend.js +4 -2
  66. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  67. package/lib/ids/HashedModuleIdsPlugin.js +9 -12
  68. package/lib/ids/IdHelpers.js +24 -10
  69. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  70. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  71. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  72. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  73. package/lib/index.js +5 -0
  74. package/lib/javascript/JavascriptGenerator.js +1 -0
  75. package/lib/javascript/StartupHelpers.js +3 -3
  76. package/lib/library/AssignLibraryPlugin.js +26 -3
  77. package/lib/library/EnableLibraryPlugin.js +11 -0
  78. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
  79. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
  80. package/lib/optimize/ConcatenatedModule.js +11 -5
  81. package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
  82. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  83. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  84. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  85. package/lib/schemes/HttpUriPlugin.js +8 -8
  86. package/lib/sharing/ConsumeSharedModule.js +4 -2
  87. package/lib/sharing/ProvideSharedModule.js +4 -2
  88. package/lib/sharing/utils.js +1 -1
  89. package/lib/stats/DefaultStatsFactoryPlugin.js +112 -67
  90. package/lib/stats/DefaultStatsPrinterPlugin.js +88 -23
  91. package/lib/util/ArrayHelpers.js +18 -4
  92. package/lib/util/AsyncQueue.js +1 -1
  93. package/lib/util/hash/xxhash64.js +2 -2
  94. package/lib/util/internalSerializables.js +11 -0
  95. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  96. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -2
  97. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  98. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  99. package/package.json +4 -11
  100. package/schemas/WebpackOptions.check.js +1 -1
  101. package/schemas/WebpackOptions.json +96 -1
  102. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  103. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  104. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  105. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  106. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  107. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  108. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  109. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  110. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  111. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  112. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  113. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  114. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  115. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  116. package/schemas/plugins/css/CssParserOptions.json +3 -0
  117. package/types.d.ts +249 -39
@@ -53,6 +53,7 @@ const { register } = require("./util/serialization");
53
53
  */
54
54
 
55
55
  const TYPES = new Set(["javascript"]);
56
+ const CSS_TYPES = new Set(["css-import"]);
56
57
  const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
57
58
  const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
58
59
  const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
@@ -392,7 +393,7 @@ class ExternalModule extends Module {
392
393
  * @returns {Set<string>} types available (do not mutate)
393
394
  */
394
395
  getSourceTypes() {
395
- return TYPES;
396
+ return this.externalType === "css-import" ? CSS_TYPES : TYPES;
396
397
  }
397
398
 
398
399
  /**
@@ -409,7 +410,9 @@ class ExternalModule extends Module {
409
410
  * @returns {boolean} true, if the chunk is ok for the module
410
411
  */
411
412
  chunkCondition(chunk, { chunkGraph }) {
412
- return chunkGraph.getNumberOfEntryModules(chunk) > 0;
413
+ return this.externalType === "css-import"
414
+ ? true
415
+ : chunkGraph.getNumberOfEntryModules(chunk) > 0;
413
416
  }
414
417
 
415
418
  /**
@@ -429,7 +432,7 @@ class ExternalModule extends Module {
429
432
 
430
433
  /**
431
434
  * @param {NeedBuildContext} context context info
432
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
435
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
433
436
  * @returns {void}
434
437
  */
435
438
  needBuild(context, callback) {
@@ -526,8 +529,14 @@ class ExternalModule extends Module {
526
529
  return { request, externalType };
527
530
  }
528
531
 
529
- _getSourceData(runtimeTemplate, moduleGraph, chunkGraph, runtime) {
530
- const { request, externalType } = this._getRequestAndExternalType();
532
+ _getSourceData(
533
+ request,
534
+ externalType,
535
+ runtimeTemplate,
536
+ moduleGraph,
537
+ chunkGraph,
538
+ runtime
539
+ ) {
531
540
  switch (externalType) {
532
541
  case "this":
533
542
  case "window":
@@ -541,6 +550,7 @@ class ExternalModule extends Module {
541
550
  case "commonjs":
542
551
  case "commonjs2":
543
552
  case "commonjs-module":
553
+ case "commonjs-static":
544
554
  return getSourceForCommonJsExternal(request);
545
555
  case "node-commonjs":
546
556
  return this.buildInfo.module
@@ -613,60 +623,90 @@ class ExternalModule extends Module {
613
623
  runtime,
614
624
  concatenationScope
615
625
  }) {
616
- const sourceData = this._getSourceData(
617
- runtimeTemplate,
618
- moduleGraph,
619
- chunkGraph,
620
- runtime
621
- );
626
+ const { request, externalType } = this._getRequestAndExternalType();
627
+ switch (externalType) {
628
+ case "asset": {
629
+ const sources = new Map();
630
+ sources.set(
631
+ "javascript",
632
+ new RawSource(`module.exports = ${JSON.stringify(request)};`)
633
+ );
634
+ const data = new Map();
635
+ data.set("url", request);
636
+ return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
637
+ }
638
+ case "css-import": {
639
+ const sources = new Map();
640
+ sources.set(
641
+ "css-import",
642
+ new RawSource(`@import url(${JSON.stringify(request)});`)
643
+ );
644
+ return {
645
+ sources,
646
+ runtimeRequirements: EMPTY_RUNTIME_REQUIREMENTS
647
+ };
648
+ }
649
+ default: {
650
+ const sourceData = this._getSourceData(
651
+ request,
652
+ externalType,
653
+ runtimeTemplate,
654
+ moduleGraph,
655
+ chunkGraph,
656
+ runtime
657
+ );
622
658
 
623
- let sourceString = sourceData.expression;
624
- if (sourceData.iife)
625
- sourceString = `(function() { return ${sourceString}; }())`;
626
- if (concatenationScope) {
627
- sourceString = `${runtimeTemplate.supportsConst() ? "const" : "var"} ${
628
- ConcatenationScope.NAMESPACE_OBJECT_EXPORT
629
- } = ${sourceString};`;
630
- concatenationScope.registerNamespaceExport(
631
- ConcatenationScope.NAMESPACE_OBJECT_EXPORT
632
- );
633
- } else {
634
- sourceString = `module.exports = ${sourceString};`;
635
- }
636
- if (sourceData.init) sourceString = `${sourceData.init}\n${sourceString}`;
659
+ let sourceString = sourceData.expression;
660
+ if (sourceData.iife)
661
+ sourceString = `(function() { return ${sourceString}; }())`;
662
+ if (concatenationScope) {
663
+ sourceString = `${
664
+ runtimeTemplate.supportsConst() ? "const" : "var"
665
+ } ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
666
+ concatenationScope.registerNamespaceExport(
667
+ ConcatenationScope.NAMESPACE_OBJECT_EXPORT
668
+ );
669
+ } else {
670
+ sourceString = `module.exports = ${sourceString};`;
671
+ }
672
+ if (sourceData.init)
673
+ sourceString = `${sourceData.init}\n${sourceString}`;
637
674
 
638
- let data = undefined;
639
- if (sourceData.chunkInitFragments) {
640
- data = new Map();
641
- data.set("chunkInitFragments", sourceData.chunkInitFragments);
642
- }
675
+ let data = undefined;
676
+ if (sourceData.chunkInitFragments) {
677
+ data = new Map();
678
+ data.set("chunkInitFragments", sourceData.chunkInitFragments);
679
+ }
643
680
 
644
- const sources = new Map();
645
- if (this.useSourceMap || this.useSimpleSourceMap) {
646
- sources.set(
647
- "javascript",
648
- new OriginalSource(sourceString, this.identifier())
649
- );
650
- } else {
651
- sources.set("javascript", new RawSource(sourceString));
652
- }
681
+ const sources = new Map();
682
+ if (this.useSourceMap || this.useSimpleSourceMap) {
683
+ sources.set(
684
+ "javascript",
685
+ new OriginalSource(sourceString, this.identifier())
686
+ );
687
+ } else {
688
+ sources.set("javascript", new RawSource(sourceString));
689
+ }
690
+
691
+ let runtimeRequirements = sourceData.runtimeRequirements;
692
+ if (!concatenationScope) {
693
+ if (!runtimeRequirements) {
694
+ runtimeRequirements = RUNTIME_REQUIREMENTS;
695
+ } else {
696
+ const set = new Set(runtimeRequirements);
697
+ set.add(RuntimeGlobals.module);
698
+ runtimeRequirements = set;
699
+ }
700
+ }
653
701
 
654
- let runtimeRequirements = sourceData.runtimeRequirements;
655
- if (!concatenationScope) {
656
- if (!runtimeRequirements) {
657
- runtimeRequirements = RUNTIME_REQUIREMENTS;
658
- } else {
659
- const set = new Set(runtimeRequirements);
660
- set.add(RuntimeGlobals.module);
661
- runtimeRequirements = set;
702
+ return {
703
+ sources,
704
+ runtimeRequirements:
705
+ runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
706
+ data
707
+ };
662
708
  }
663
709
  }
664
-
665
- return {
666
- sources,
667
- runtimeRequirements: runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
668
- data
669
- };
670
710
  }
671
711
 
672
712
  /**
@@ -117,7 +117,7 @@ class ExternalModuleFactoryPlugin {
117
117
 
118
118
  /**
119
119
  * @param {Externals} externals externals config
120
- * @param {function(Error=, ExternalModule=): void} callback callback
120
+ * @param {function((Error | null)=, ExternalModule=): void} callback callback
121
121
  * @returns {void}
122
122
  */
123
123
  const handleExternals = (externals, callback) => {
@@ -1185,7 +1185,7 @@ class FileSystemInfo {
1185
1185
 
1186
1186
  /**
1187
1187
  * @param {string} path file path
1188
- * @param {function(WebpackError=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1188
+ * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1189
1189
  * @returns {void}
1190
1190
  */
1191
1191
  getFileTimestamp(path, callback) {
@@ -1196,7 +1196,7 @@ class FileSystemInfo {
1196
1196
 
1197
1197
  /**
1198
1198
  * @param {string} path context path
1199
- * @param {function(WebpackError=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1199
+ * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1200
1200
  * @returns {void}
1201
1201
  */
1202
1202
  getContextTimestamp(path, callback) {
@@ -1217,7 +1217,7 @@ class FileSystemInfo {
1217
1217
 
1218
1218
  /**
1219
1219
  * @param {string} path context path
1220
- * @param {function(WebpackError=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1220
+ * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1221
1221
  * @returns {void}
1222
1222
  */
1223
1223
  _getUnresolvedContextTimestamp(path, callback) {
@@ -1228,7 +1228,7 @@ class FileSystemInfo {
1228
1228
 
1229
1229
  /**
1230
1230
  * @param {string} path file path
1231
- * @param {function(WebpackError=, string=): void} callback callback function
1231
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1232
1232
  * @returns {void}
1233
1233
  */
1234
1234
  getFileHash(path, callback) {
@@ -1239,7 +1239,7 @@ class FileSystemInfo {
1239
1239
 
1240
1240
  /**
1241
1241
  * @param {string} path context path
1242
- * @param {function(WebpackError=, string=): void} callback callback function
1242
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1243
1243
  * @returns {void}
1244
1244
  */
1245
1245
  getContextHash(path, callback) {
@@ -1259,7 +1259,7 @@ class FileSystemInfo {
1259
1259
 
1260
1260
  /**
1261
1261
  * @param {string} path context path
1262
- * @param {function(WebpackError=, ContextHash=): void} callback callback function
1262
+ * @param {function((WebpackError | null)=, ContextHash=): void} callback callback function
1263
1263
  * @returns {void}
1264
1264
  */
1265
1265
  _getUnresolvedContextHash(path, callback) {
@@ -1270,7 +1270,7 @@ class FileSystemInfo {
1270
1270
 
1271
1271
  /**
1272
1272
  * @param {string} path context path
1273
- * @param {function(WebpackError=, ResolvedContextTimestampAndHash=): void} callback callback function
1273
+ * @param {function((WebpackError | null)=, ResolvedContextTimestampAndHash=): void} callback callback function
1274
1274
  * @returns {void}
1275
1275
  */
1276
1276
  getContextTsh(path, callback) {
@@ -1290,7 +1290,7 @@ class FileSystemInfo {
1290
1290
 
1291
1291
  /**
1292
1292
  * @param {string} path context path
1293
- * @param {function(WebpackError=, ContextTimestampAndHash=): void} callback callback function
1293
+ * @param {function((WebpackError | null)=, ContextTimestampAndHash=): void} callback callback function
1294
1294
  * @returns {void}
1295
1295
  */
1296
1296
  _getUnresolvedContextTsh(path, callback) {
@@ -1330,7 +1330,7 @@ class FileSystemInfo {
1330
1330
  /**
1331
1331
  * @param {string} context context directory
1332
1332
  * @param {Iterable<string>} deps dependencies
1333
- * @param {function(Error=, ResolveBuildDependenciesResult=): void} callback callback function
1333
+ * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function
1334
1334
  * @returns {void}
1335
1335
  */
1336
1336
  resolveBuildDependencies(context, deps, callback) {
@@ -1798,7 +1798,7 @@ class FileSystemInfo {
1798
1798
 
1799
1799
  /**
1800
1800
  * @param {Map<string, string | false>} resolveResults results from resolving
1801
- * @param {function(Error=, boolean=): void} callback callback with true when resolveResults resolve the same way
1801
+ * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way
1802
1802
  * @returns {void}
1803
1803
  */
1804
1804
  checkResolveResultsValid(resolveResults, callback) {
@@ -1880,7 +1880,7 @@ class FileSystemInfo {
1880
1880
  * @param {Object} options options object (for future extensions)
1881
1881
  * @param {boolean=} options.hash should use hash to snapshot
1882
1882
  * @param {boolean=} options.timestamp should use timestamp to snapshot
1883
- * @param {function(WebpackError=, Snapshot=): void} callback callback function
1883
+ * @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function
1884
1884
  * @returns {void}
1885
1885
  */
1886
1886
  createSnapshot(startTime, files, directories, missing, options, callback) {
@@ -2256,8 +2256,10 @@ class FileSystemInfo {
2256
2256
  for (const path of managedItems) {
2257
2257
  const cache = this._managedItems.get(path);
2258
2258
  if (cache !== undefined) {
2259
- if (cache !== "missing") {
2259
+ if (!cache.startsWith("*")) {
2260
2260
  managedFiles.add(join(this.fs, path, "package.json"));
2261
+ } else if (cache === "*nested") {
2262
+ managedMissing.add(join(this.fs, path, "package.json"));
2261
2263
  }
2262
2264
  managedItemInfo.set(path, cache);
2263
2265
  } else {
@@ -2271,8 +2273,10 @@ class FileSystemInfo {
2271
2273
  }
2272
2274
  jobError();
2273
2275
  } else if (entry) {
2274
- if (entry !== "missing") {
2276
+ if (!entry.startsWith("*")) {
2275
2277
  managedFiles.add(join(this.fs, path, "package.json"));
2278
+ } else if (cache === "*nested") {
2279
+ managedMissing.add(join(this.fs, path, "package.json"));
2276
2280
  }
2277
2281
  managedItemInfo.set(path, entry);
2278
2282
  jobDone();
@@ -2375,7 +2379,7 @@ class FileSystemInfo {
2375
2379
 
2376
2380
  /**
2377
2381
  * @param {Snapshot} snapshot the snapshot made
2378
- * @param {function(WebpackError=, boolean=): void} callback callback function
2382
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2379
2383
  * @returns {void}
2380
2384
  */
2381
2385
  checkSnapshotValid(snapshot, callback) {
@@ -2395,7 +2399,7 @@ class FileSystemInfo {
2395
2399
 
2396
2400
  /**
2397
2401
  * @param {Snapshot} snapshot the snapshot made
2398
- * @param {function(WebpackError=, boolean=): void} callback callback function
2402
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2399
2403
  * @returns {void}
2400
2404
  */
2401
2405
  _checkSnapshotValidNoCache(snapshot, callback) {
@@ -2944,7 +2948,7 @@ class FileSystemInfo {
2944
2948
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromFile called when context item is a file
2945
2949
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromDirectory called when context item is a directory
2946
2950
  * @param {function(string[], ItemType[]): T} options.reduce called from all context items
2947
- * @param {function(Error=, (T)=): void} callback callback
2951
+ * @param {function((Error | null)=, (T)=): void} callback callback
2948
2952
  */
2949
2953
  _readContext(
2950
2954
  {
@@ -3127,7 +3131,7 @@ class FileSystemInfo {
3127
3131
 
3128
3132
  /**
3129
3133
  * @param {ContextFileSystemInfoEntry} entry entry
3130
- * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3134
+ * @param {function((Error | null)=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3131
3135
  * @returns {void}
3132
3136
  */
3133
3137
  _resolveContextTimestamp(entry, callback) {
@@ -3235,7 +3239,7 @@ class FileSystemInfo {
3235
3239
 
3236
3240
  /**
3237
3241
  * @param {ContextHash} entry context hash
3238
- * @param {function(Error=, string=): void} callback callback
3242
+ * @param {function((Error | null)=, string=): void} callback callback
3239
3243
  * @returns {void}
3240
3244
  */
3241
3245
  _resolveContextHash(entry, callback) {
@@ -3391,7 +3395,7 @@ class FileSystemInfo {
3391
3395
 
3392
3396
  /**
3393
3397
  * @param {ContextTimestampAndHash} entry entry
3394
- * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
3398
+ * @param {function((Error | null)=, ResolvedContextTimestampAndHash=): void} callback callback
3395
3399
  * @returns {void}
3396
3400
  */
3397
3401
  _resolveContextTsh(entry, callback) {
@@ -3471,8 +3475,8 @@ class FileSystemInfo {
3471
3475
  }
3472
3476
  if (!elements.has(path)) {
3473
3477
  // file or directory doesn't exist
3474
- this._managedItems.set(path, "missing");
3475
- return callback(null, "missing");
3478
+ this._managedItems.set(path, "*missing");
3479
+ return callback(null, "*missing");
3476
3480
  }
3477
3481
  // something exists
3478
3482
  // it may be a file or directory
@@ -3481,8 +3485,8 @@ class FileSystemInfo {
3481
3485
  (path.endsWith("/node_modules") || path.endsWith("\\node_modules"))
3482
3486
  ) {
3483
3487
  // we are only interested in existence of this special directory
3484
- this._managedItems.set(path, "exists");
3485
- return callback(null, "exists");
3488
+ this._managedItems.set(path, "*node_modules");
3489
+ return callback(null, "*node_modules");
3486
3490
  }
3487
3491
 
3488
3492
  // we assume it's a directory, as files shouldn't occur in managed paths
@@ -3499,8 +3503,8 @@ class FileSystemInfo {
3499
3503
  ) {
3500
3504
  // This is only a grouping folder e. g. used by yarn
3501
3505
  // we are only interested in existence of this special directory
3502
- this._managedItems.set(path, "nested");
3503
- return callback(null, "nested");
3506
+ this._managedItems.set(path, "*nested");
3507
+ return callback(null, "*nested");
3504
3508
  }
3505
3509
  this.logger.warn(
3506
3510
  `Managed item ${path} isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)`
package/lib/Generator.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  /** @typedef {import("webpack-sources").Source} Source */
9
9
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
10
+ /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
10
11
  /** @typedef {import("./Compilation")} Compilation */
11
12
  /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
12
13
  /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
@@ -27,6 +28,7 @@
27
28
  * @property {Set<string>} runtimeRequirements the requirements for runtime
28
29
  * @property {RuntimeSpec} runtime the runtime
29
30
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
31
+ * @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
30
32
  * @property {string} type which kind of code should be generated
31
33
  * @property {function(): Map<string, any>=} getData get access to the code generation data
32
34
  */
@@ -51,7 +51,7 @@ module.exports.makeWebpackError = makeWebpackError;
51
51
 
52
52
  /**
53
53
  * @template T
54
- * @param {function(WebpackError=, T=): void} callback webpack error callback
54
+ * @param {function((WebpackError | null)=, T=): void} callback webpack error callback
55
55
  * @param {string} hook name of hook
56
56
  * @returns {Callback<T>} generic callback
57
57
  */
package/lib/Module.js CHANGED
@@ -19,6 +19,7 @@ const makeSerializable = require("./util/makeSerializable");
19
19
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
20
20
  /** @typedef {import("./Chunk")} Chunk */
21
21
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
22
+ /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
22
23
  /** @typedef {import("./Compilation")} Compilation */
23
24
  /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
24
25
  /** @typedef {import("./Dependency")} Dependency */
@@ -56,6 +57,7 @@ const makeSerializable = require("./util/makeSerializable");
56
57
  * @property {ChunkGraph} chunkGraph the chunk graph
57
58
  * @property {RuntimeSpec} runtime the runtimes code should be generated for
58
59
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
60
+ * @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
59
61
  */
60
62
 
61
63
  /**
@@ -165,6 +167,8 @@ class Module extends DependenciesBlock {
165
167
  this.buildInfo = undefined;
166
168
  /** @type {Dependency[] | undefined} */
167
169
  this.presentationalDependencies = undefined;
170
+ /** @type {Dependency[] | undefined} */
171
+ this.codeGenerationDependencies = undefined;
168
172
  }
169
173
 
170
174
  // TODO remove in webpack 6
@@ -396,7 +400,6 @@ class Module extends DependenciesBlock {
396
400
  // BACKWARD-COMPAT END
397
401
 
398
402
  /**
399
- * @deprecated moved to .buildInfo.exportsArgument
400
403
  * @returns {string} name of the exports argument
401
404
  */
402
405
  get exportsArgument() {
@@ -404,7 +407,6 @@ class Module extends DependenciesBlock {
404
407
  }
405
408
 
406
409
  /**
407
- * @deprecated moved to .buildInfo.moduleArgument
408
410
  * @returns {string} name of the module argument
409
411
  */
410
412
  get moduleArgument() {
@@ -493,6 +495,19 @@ class Module extends DependenciesBlock {
493
495
  this.presentationalDependencies.push(presentationalDependency);
494
496
  }
495
497
 
498
+ /**
499
+ * @param {Dependency} codeGenerationDependency dependency being tied to module.
500
+ * This is a Dependency where the code generation result of the referenced module is needed during code generation.
501
+ * The Dependency should also be added to normal dependencies via addDependency.
502
+ * @returns {void}
503
+ */
504
+ addCodeGenerationDependency(codeGenerationDependency) {
505
+ if (this.codeGenerationDependencies === undefined) {
506
+ this.codeGenerationDependencies = [];
507
+ }
508
+ this.codeGenerationDependencies.push(codeGenerationDependency);
509
+ }
510
+
496
511
  /**
497
512
  * Removes all dependencies and blocks
498
513
  * @returns {void}
@@ -501,6 +516,9 @@ class Module extends DependenciesBlock {
501
516
  if (this.presentationalDependencies !== undefined) {
502
517
  this.presentationalDependencies.length = 0;
503
518
  }
519
+ if (this.codeGenerationDependencies !== undefined) {
520
+ this.codeGenerationDependencies.length = 0;
521
+ }
504
522
  super.clearDependenciesAndBlocks();
505
523
  }
506
524
 
@@ -671,7 +689,7 @@ class Module extends DependenciesBlock {
671
689
 
672
690
  /**
673
691
  * @param {NeedBuildContext} context context info
674
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
692
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
675
693
  * @returns {void}
676
694
  */
677
695
  needBuild(context, callback) {
@@ -799,7 +817,8 @@ class Module extends DependenciesBlock {
799
817
  runtimeTemplate,
800
818
  moduleGraph: chunkGraph.moduleGraph,
801
819
  chunkGraph,
802
- runtime: undefined
820
+ runtime: undefined,
821
+ codeGenerationResults: undefined
803
822
  };
804
823
  const sources = this.codeGeneration(codeGenContext).sources;
805
824
  return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
@@ -976,6 +995,7 @@ class Module extends DependenciesBlock {
976
995
  write(this.buildMeta);
977
996
  write(this.buildInfo);
978
997
  write(this.presentationalDependencies);
998
+ write(this.codeGenerationDependencies);
979
999
  super.serialize(context);
980
1000
  }
981
1001
 
@@ -993,6 +1013,7 @@ class Module extends DependenciesBlock {
993
1013
  this.buildMeta = read();
994
1014
  this.buildInfo = read();
995
1015
  this.presentationalDependencies = read();
1016
+ this.codeGenerationDependencies = read();
996
1017
  super.deserialize(context);
997
1018
  }
998
1019
  }
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const NormalModule = require("./NormalModule");
8
9
  const createHash = require("./util/createHash");
9
10
  const memoize = require("./util/memoize");
10
11
 
@@ -138,7 +139,10 @@ ModuleFilenameHelpers.createFilename = (
138
139
  );
139
140
  identifier = memoize(() => requestShortener.shorten(module.identifier()));
140
141
  moduleId = () => chunkGraph.getModuleId(module);
141
- absoluteResourcePath = () => module.identifier().split("!").pop();
142
+ absoluteResourcePath = () =>
143
+ module instanceof NormalModule
144
+ ? module.resource
145
+ : module.identifier().split("!").pop();
142
146
  hash = getHash(identifier, hashFunction);
143
147
  }
144
148
  const resource = memoize(() => shortIdentifier().split("!").pop());
@@ -27,7 +27,7 @@ const ArrayQueue = require("./util/ArrayQueue");
27
27
  /**
28
28
  * @template T
29
29
  * @callback Callback
30
- * @param {Error=} err
30
+ * @param {(Error | null)=} err
31
31
  * @param {T=} result
32
32
  */
33
33
 
@@ -13,7 +13,7 @@ const asyncLib = require("neo-async");
13
13
  /**
14
14
  * @template T
15
15
  * @callback Callback
16
- * @param {Error=} err
16
+ * @param {(Error | null)=} err
17
17
  * @param {T=} result
18
18
  */
19
19
 
@@ -310,7 +310,7 @@ class NormalModule extends Module {
310
310
  }
311
311
 
312
312
  // Info from Build
313
- /** @type {WebpackError=} */
313
+ /** @type {(WebpackError | null)=} */
314
314
  this.error = null;
315
315
  /** @private @type {Source=} */
316
316
  this._source = null;
@@ -355,11 +355,13 @@ class NormalModule extends Module {
355
355
  * @returns {string | null} an identifier for library inclusion
356
356
  */
357
357
  libIdent(options) {
358
- return contextify(
358
+ let ident = contextify(
359
359
  options.context,
360
360
  this.userRequest,
361
361
  options.associatedObjectForCache
362
362
  );
363
+ if (this.layer) ident = `(${this.layer})/${ident}`;
364
+ return ident;
363
365
  }
364
366
 
365
367
  /**
@@ -730,7 +732,7 @@ class NormalModule extends Module {
730
732
  * @param {ResolverWithOptions} resolver the resolver
731
733
  * @param {InputFileSystem} fs the file system
732
734
  * @param {NormalModuleCompilationHooks} hooks the hooks
733
- * @param {function(WebpackError=): void} callback callback function
735
+ * @param {function((WebpackError | null)=): void} callback callback function
734
736
  * @returns {void}
735
737
  */
736
738
  _doBuild(options, compilation, resolver, fs, hooks, callback) {
@@ -1168,7 +1170,8 @@ class NormalModule extends Module {
1168
1170
  moduleGraph,
1169
1171
  chunkGraph,
1170
1172
  runtime,
1171
- concatenationScope
1173
+ concatenationScope,
1174
+ codeGenerationResults
1172
1175
  }) {
1173
1176
  /** @type {Set<string>} */
1174
1177
  const runtimeRequirements = new Set();
@@ -1200,6 +1203,7 @@ class NormalModule extends Module {
1200
1203
  runtimeRequirements,
1201
1204
  runtime,
1202
1205
  concatenationScope,
1206
+ codeGenerationResults,
1203
1207
  getData,
1204
1208
  type
1205
1209
  });
@@ -1234,7 +1238,7 @@ class NormalModule extends Module {
1234
1238
 
1235
1239
  /**
1236
1240
  * @param {NeedBuildContext} context context info
1237
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1241
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
1238
1242
  * @returns {void}
1239
1243
  */
1240
1244
  needBuild(context, callback) {
package/lib/RawModule.js CHANGED
@@ -74,7 +74,7 @@ class RawModule extends Module {
74
74
 
75
75
  /**
76
76
  * @param {NeedBuildContext} context context info
77
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
77
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
78
78
  * @returns {void}
79
79
  */
80
80
  needBuild(context, callback) {