webpack 5.59.0 → 5.76.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 (236) hide show
  1. package/README.md +22 -24
  2. package/bin/webpack.js +0 -0
  3. package/hot/dev-server.js +17 -4
  4. package/hot/lazy-compilation-node.js +3 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +33 -0
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +1 -1
  10. package/lib/CacheFacade.js +4 -11
  11. package/lib/Chunk.js +6 -3
  12. package/lib/ChunkGraph.js +94 -8
  13. package/lib/ChunkGroup.js +1 -1
  14. package/lib/CleanPlugin.js +81 -20
  15. package/lib/Compilation.js +188 -93
  16. package/lib/Compiler.js +87 -18
  17. package/lib/ConstPlugin.js +2 -2
  18. package/lib/ContextModule.js +142 -51
  19. package/lib/ContextModuleFactory.js +65 -25
  20. package/lib/DelegatedModule.js +1 -1
  21. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  22. package/lib/Dependency.js +17 -0
  23. package/lib/DependencyTemplate.js +9 -0
  24. package/lib/DependencyTemplates.js +1 -1
  25. package/lib/DllModule.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/EntryOptionPlugin.js +2 -0
  28. package/lib/ErrorHelpers.js +2 -2
  29. package/lib/EvalDevToolModulePlugin.js +16 -1
  30. package/lib/EvalSourceMapDevToolPlugin.js +25 -4
  31. package/lib/ExportsInfo.js +5 -5
  32. package/lib/ExternalModule.js +94 -54
  33. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  34. package/lib/FileSystemInfo.js +124 -58
  35. package/lib/Generator.js +3 -0
  36. package/lib/HookWebpackError.js +1 -1
  37. package/lib/HotModuleReplacementPlugin.js +3 -1
  38. package/lib/LoaderOptionsPlugin.js +1 -1
  39. package/lib/Module.js +28 -4
  40. package/lib/ModuleFilenameHelpers.js +8 -4
  41. package/lib/ModuleHashingError.js +29 -0
  42. package/lib/MultiCompiler.js +1 -1
  43. package/lib/MultiWatching.js +1 -1
  44. package/lib/NodeStuffPlugin.js +13 -3
  45. package/lib/NormalModule.js +51 -33
  46. package/lib/NormalModuleFactory.js +42 -37
  47. package/lib/ProgressPlugin.js +4 -5
  48. package/lib/RawModule.js +1 -1
  49. package/lib/RuntimeGlobals.js +29 -1
  50. package/lib/RuntimeModule.js +1 -1
  51. package/lib/RuntimePlugin.js +84 -1
  52. package/lib/RuntimeTemplate.js +114 -2
  53. package/lib/Template.js +3 -2
  54. package/lib/TemplatedPathPlugin.js +48 -23
  55. package/lib/WatchIgnorePlugin.js +19 -7
  56. package/lib/Watching.js +33 -19
  57. package/lib/WebpackOptionsApply.js +79 -11
  58. package/lib/asset/AssetGenerator.js +228 -71
  59. package/lib/asset/AssetModulesPlugin.js +3 -0
  60. package/lib/asset/AssetParser.js +1 -0
  61. package/lib/asset/AssetSourceGenerator.js +31 -6
  62. package/lib/asset/AssetSourceParser.js +1 -0
  63. package/lib/asset/RawDataUrlModule.js +148 -0
  64. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  65. package/lib/buildChunkGraph.js +38 -7
  66. package/lib/cache/PackFileCacheStrategy.js +15 -8
  67. package/lib/cache/ResolverCachePlugin.js +90 -29
  68. package/lib/cli.js +44 -3
  69. package/lib/config/browserslistTargetHandler.js +41 -6
  70. package/lib/config/defaults.js +123 -19
  71. package/lib/config/normalization.js +10 -2
  72. package/lib/config/target.js +10 -0
  73. package/lib/container/ContainerEntryModule.js +8 -5
  74. package/lib/container/FallbackModule.js +4 -4
  75. package/lib/container/ModuleFederationPlugin.js +2 -0
  76. package/lib/container/RemoteModule.js +4 -2
  77. package/lib/container/RemoteRuntimeModule.js +8 -7
  78. package/lib/css/CssExportsGenerator.js +139 -0
  79. package/lib/css/CssGenerator.js +109 -0
  80. package/lib/css/CssLoadingRuntimeModule.js +442 -0
  81. package/lib/css/CssModulesPlugin.js +462 -0
  82. package/lib/css/CssParser.js +618 -0
  83. package/lib/css/walkCssTokens.js +659 -0
  84. package/lib/debug/ProfilingPlugin.js +24 -21
  85. package/lib/dependencies/AMDRequireDependency.js +6 -6
  86. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  87. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  88. package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
  89. package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
  90. package/lib/dependencies/CommonJsRequireDependency.js +2 -1
  91. package/lib/dependencies/ContextDependency.js +16 -2
  92. package/lib/dependencies/ContextDependencyHelpers.js +21 -8
  93. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  94. package/lib/dependencies/ContextElementDependency.js +25 -3
  95. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  96. package/lib/dependencies/CssExportDependency.js +85 -0
  97. package/lib/dependencies/CssImportDependency.js +75 -0
  98. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  99. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  100. package/lib/dependencies/CssUrlDependency.js +132 -0
  101. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  102. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  103. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  104. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
  105. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  106. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  107. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  108. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  109. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  110. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  111. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  112. package/lib/dependencies/ImportContextDependency.js +0 -2
  113. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  114. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  115. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  116. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  117. package/lib/dependencies/ImportParserPlugin.js +35 -29
  118. package/lib/dependencies/JsonExportsDependency.js +17 -21
  119. package/lib/dependencies/LoaderDependency.js +13 -0
  120. package/lib/dependencies/LoaderImportDependency.js +13 -0
  121. package/lib/dependencies/LoaderPlugin.js +4 -2
  122. package/lib/dependencies/ModuleDependency.js +11 -1
  123. package/lib/dependencies/ProvidedDependency.js +31 -8
  124. package/lib/dependencies/RequireContextDependency.js +0 -16
  125. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  126. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  127. package/lib/dependencies/RequireResolveDependency.js +2 -1
  128. package/lib/dependencies/URLDependency.js +3 -8
  129. package/lib/dependencies/URLPlugin.js +22 -1
  130. package/lib/dependencies/WorkerPlugin.js +2 -0
  131. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  132. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  134. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  136. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  137. package/lib/hmr/lazyCompilationBackend.js +51 -12
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  139. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  140. package/lib/ids/IdHelpers.js +26 -12
  141. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  142. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  143. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  144. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  145. package/lib/index.js +20 -0
  146. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  147. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  148. package/lib/javascript/ChunkHelpers.js +33 -0
  149. package/lib/javascript/JavascriptGenerator.js +1 -0
  150. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  151. package/lib/javascript/JavascriptParser.js +143 -73
  152. package/lib/javascript/StartupHelpers.js +7 -30
  153. package/lib/json/JsonData.js +8 -0
  154. package/lib/json/JsonParser.js +4 -6
  155. package/lib/library/AssignLibraryPlugin.js +39 -15
  156. package/lib/library/EnableLibraryPlugin.js +11 -0
  157. package/lib/library/UmdLibraryPlugin.js +5 -3
  158. package/lib/node/NodeTargetPlugin.js +3 -0
  159. package/lib/node/NodeWatchFileSystem.js +85 -31
  160. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  161. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  162. package/lib/optimize/ConcatenatedModule.js +62 -26
  163. package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
  164. package/lib/optimize/RealContentHashPlugin.js +45 -15
  165. package/lib/optimize/SplitChunksPlugin.js +8 -1
  166. package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
  167. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  168. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  169. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  170. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  171. package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
  172. package/lib/runtime/NonceRuntimeModule.js +24 -0
  173. package/lib/schemes/HttpUriPlugin.js +77 -14
  174. package/lib/serialization/FileMiddleware.js +44 -9
  175. package/lib/sharing/ConsumeSharedModule.js +8 -2
  176. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  177. package/lib/sharing/ProvideSharedModule.js +4 -2
  178. package/lib/sharing/ProvideSharedPlugin.js +1 -2
  179. package/lib/sharing/ShareRuntimeModule.js +1 -1
  180. package/lib/sharing/utils.js +1 -1
  181. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  182. package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
  183. package/lib/util/ArrayHelpers.js +30 -0
  184. package/lib/util/AsyncQueue.js +1 -1
  185. package/lib/util/compileBooleanMatcher.js +1 -1
  186. package/lib/util/create-schema-validation.js +9 -2
  187. package/lib/util/createHash.js +12 -0
  188. package/lib/util/deprecation.js +10 -2
  189. package/lib/util/deterministicGrouping.js +1 -1
  190. package/lib/util/extractUrlAndGlobal.js +3 -0
  191. package/lib/util/fs.js +11 -0
  192. package/lib/util/hash/BatchedHash.js +7 -4
  193. package/lib/util/hash/md4.js +20 -0
  194. package/lib/util/hash/wasm-hash.js +163 -0
  195. package/lib/util/hash/xxhash64.js +5 -139
  196. package/lib/util/identifier.js +65 -44
  197. package/lib/util/internalSerializables.js +15 -0
  198. package/lib/util/nonNumericOnlyHash.js +22 -0
  199. package/lib/util/semver.js +17 -10
  200. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  201. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  202. package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
  203. package/lib/webpack.js +10 -3
  204. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  205. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  206. package/module.d.ts +215 -0
  207. package/package.json +28 -32
  208. package/schemas/WebpackOptions.check.js +1 -1
  209. package/schemas/WebpackOptions.json +321 -30
  210. package/schemas/plugins/BannerPlugin.check.js +1 -1
  211. package/schemas/plugins/BannerPlugin.json +4 -0
  212. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  213. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  217. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  218. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  219. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  220. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  222. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  223. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  224. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  225. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  226. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  227. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  228. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  229. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  230. package/schemas/plugins/css/CssParserOptions.json +3 -0
  231. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  232. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  233. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  234. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  235. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  236. package/types.d.ts +869 -296
@@ -89,8 +89,8 @@ class ExternalModuleFactoryPlugin {
89
89
  UNSPECIFIED_EXTERNAL_TYPE_REGEXP.test(externalConfig)
90
90
  ) {
91
91
  const idx = externalConfig.indexOf(" ");
92
- type = externalConfig.substr(0, idx);
93
- externalConfig = externalConfig.substr(idx + 1);
92
+ type = externalConfig.slice(0, idx);
93
+ externalConfig = externalConfig.slice(idx + 1);
94
94
  } else if (
95
95
  Array.isArray(externalConfig) &&
96
96
  externalConfig.length > 0 &&
@@ -98,9 +98,9 @@ class ExternalModuleFactoryPlugin {
98
98
  ) {
99
99
  const firstItem = externalConfig[0];
100
100
  const idx = firstItem.indexOf(" ");
101
- type = firstItem.substr(0, idx);
101
+ type = firstItem.slice(0, idx);
102
102
  externalConfig = [
103
- firstItem.substr(idx + 1),
103
+ firstItem.slice(idx + 1),
104
104
  ...externalConfig.slice(1)
105
105
  ];
106
106
  }
@@ -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) => {
@@ -6,7 +6,9 @@
6
6
  "use strict";
7
7
 
8
8
  const { create: createResolver } = require("enhanced-resolve");
9
+ const nodeModule = require("module");
9
10
  const asyncLib = require("neo-async");
11
+ const { isAbsolute } = require("path");
10
12
  const AsyncQueue = require("./util/AsyncQueue");
11
13
  const StackedCacheMap = require("./util/StackedCacheMap");
12
14
  const createHash = require("./util/createHash");
@@ -22,6 +24,8 @@ const processAsyncTree = require("./util/processAsyncTree");
22
24
 
23
25
  const supportsEsm = +process.versions.modules >= 83;
24
26
 
27
+ const builtinModules = new Set(nodeModule.builtinModules);
28
+
25
29
  let FS_ACCURACY = 2000;
26
30
 
27
31
  const EMPTY_SET = new Set();
@@ -204,6 +208,12 @@ class SnapshotIterable {
204
208
  class Snapshot {
205
209
  constructor() {
206
210
  this._flags = 0;
211
+ /** @type {Iterable<string> | undefined} */
212
+ this._cachedFileIterable = undefined;
213
+ /** @type {Iterable<string> | undefined} */
214
+ this._cachedContextIterable = undefined;
215
+ /** @type {Iterable<string> | undefined} */
216
+ this._cachedMissingIterable = undefined;
207
217
  /** @type {number | undefined} */
208
218
  this.startTime = undefined;
209
219
  /** @type {Map<string, FileSystemInfoEntry | null> | undefined} */
@@ -414,31 +424,43 @@ class Snapshot {
414
424
  * @returns {Iterable<string>} iterable
415
425
  */
416
426
  getFileIterable() {
417
- return this._createIterable(s => [
418
- s.fileTimestamps,
419
- s.fileHashes,
420
- s.fileTshs,
421
- s.managedFiles
422
- ]);
427
+ if (this._cachedFileIterable === undefined) {
428
+ this._cachedFileIterable = this._createIterable(s => [
429
+ s.fileTimestamps,
430
+ s.fileHashes,
431
+ s.fileTshs,
432
+ s.managedFiles
433
+ ]);
434
+ }
435
+ return this._cachedFileIterable;
423
436
  }
424
437
 
425
438
  /**
426
439
  * @returns {Iterable<string>} iterable
427
440
  */
428
441
  getContextIterable() {
429
- return this._createIterable(s => [
430
- s.contextTimestamps,
431
- s.contextHashes,
432
- s.contextTshs,
433
- s.managedContexts
434
- ]);
442
+ if (this._cachedContextIterable === undefined) {
443
+ this._cachedContextIterable = this._createIterable(s => [
444
+ s.contextTimestamps,
445
+ s.contextHashes,
446
+ s.contextTshs,
447
+ s.managedContexts
448
+ ]);
449
+ }
450
+ return this._cachedContextIterable;
435
451
  }
436
452
 
437
453
  /**
438
454
  * @returns {Iterable<string>} iterable
439
455
  */
440
456
  getMissingIterable() {
441
- return this._createIterable(s => [s.missingExistence, s.managedMissing]);
457
+ if (this._cachedMissingIterable === undefined) {
458
+ this._cachedMissingIterable = this._createIterable(s => [
459
+ s.missingExistence,
460
+ s.managedMissing
461
+ ]);
462
+ }
463
+ return this._cachedMissingIterable;
442
464
  }
443
465
  }
444
466
 
@@ -692,6 +714,11 @@ class SnapshotOptimization {
692
714
  }
693
715
  }
694
716
 
717
+ const parseString = str => {
718
+ if (str[0] === "'") str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
719
+ return JSON.parse(str);
720
+ };
721
+
695
722
  /* istanbul ignore next */
696
723
  /**
697
724
  * @param {number} mtime mtime
@@ -1180,7 +1207,7 @@ class FileSystemInfo {
1180
1207
 
1181
1208
  /**
1182
1209
  * @param {string} path file path
1183
- * @param {function(WebpackError=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1210
+ * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1184
1211
  * @returns {void}
1185
1212
  */
1186
1213
  getFileTimestamp(path, callback) {
@@ -1191,7 +1218,7 @@ class FileSystemInfo {
1191
1218
 
1192
1219
  /**
1193
1220
  * @param {string} path context path
1194
- * @param {function(WebpackError=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1221
+ * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1195
1222
  * @returns {void}
1196
1223
  */
1197
1224
  getContextTimestamp(path, callback) {
@@ -1212,7 +1239,7 @@ class FileSystemInfo {
1212
1239
 
1213
1240
  /**
1214
1241
  * @param {string} path context path
1215
- * @param {function(WebpackError=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1242
+ * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1216
1243
  * @returns {void}
1217
1244
  */
1218
1245
  _getUnresolvedContextTimestamp(path, callback) {
@@ -1223,7 +1250,7 @@ class FileSystemInfo {
1223
1250
 
1224
1251
  /**
1225
1252
  * @param {string} path file path
1226
- * @param {function(WebpackError=, string=): void} callback callback function
1253
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1227
1254
  * @returns {void}
1228
1255
  */
1229
1256
  getFileHash(path, callback) {
@@ -1234,7 +1261,7 @@ class FileSystemInfo {
1234
1261
 
1235
1262
  /**
1236
1263
  * @param {string} path context path
1237
- * @param {function(WebpackError=, string=): void} callback callback function
1264
+ * @param {function((WebpackError | null)=, string=): void} callback callback function
1238
1265
  * @returns {void}
1239
1266
  */
1240
1267
  getContextHash(path, callback) {
@@ -1254,7 +1281,7 @@ class FileSystemInfo {
1254
1281
 
1255
1282
  /**
1256
1283
  * @param {string} path context path
1257
- * @param {function(WebpackError=, ContextHash=): void} callback callback function
1284
+ * @param {function((WebpackError | null)=, ContextHash=): void} callback callback function
1258
1285
  * @returns {void}
1259
1286
  */
1260
1287
  _getUnresolvedContextHash(path, callback) {
@@ -1265,7 +1292,7 @@ class FileSystemInfo {
1265
1292
 
1266
1293
  /**
1267
1294
  * @param {string} path context path
1268
- * @param {function(WebpackError=, ResolvedContextTimestampAndHash=): void} callback callback function
1295
+ * @param {function((WebpackError | null)=, ResolvedContextTimestampAndHash=): void} callback callback function
1269
1296
  * @returns {void}
1270
1297
  */
1271
1298
  getContextTsh(path, callback) {
@@ -1285,7 +1312,7 @@ class FileSystemInfo {
1285
1312
 
1286
1313
  /**
1287
1314
  * @param {string} path context path
1288
- * @param {function(WebpackError=, ContextTimestampAndHash=): void} callback callback function
1315
+ * @param {function((WebpackError | null)=, ContextTimestampAndHash=): void} callback callback function
1289
1316
  * @returns {void}
1290
1317
  */
1291
1318
  _getUnresolvedContextTsh(path, callback) {
@@ -1325,7 +1352,7 @@ class FileSystemInfo {
1325
1352
  /**
1326
1353
  * @param {string} context context directory
1327
1354
  * @param {Iterable<string>} deps dependencies
1328
- * @param {function(Error=, ResolveBuildDependenciesResult=): void} callback callback function
1355
+ * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function
1329
1356
  * @returns {void}
1330
1357
  */
1331
1358
  resolveBuildDependencies(context, deps, callback) {
@@ -1625,7 +1652,9 @@ class FileSystemInfo {
1625
1652
  let request = relative(this.fs, context, childPath);
1626
1653
  if (request.endsWith(".js")) request = request.slice(0, -3);
1627
1654
  request = request.replace(/\\/g, "/");
1628
- if (!request.startsWith("../")) request = `./${request}`;
1655
+ if (!request.startsWith("../") && !isAbsolute(request)) {
1656
+ request = `./${request}`;
1657
+ }
1629
1658
  push({
1630
1659
  type: RBDT_RESOLVE_CJS_FILE,
1631
1660
  context,
@@ -1657,21 +1686,22 @@ class FileSystemInfo {
1657
1686
  let dependency;
1658
1687
  if (imp.d === -1) {
1659
1688
  // import ... from "..."
1660
- dependency = JSON.parse(
1689
+ dependency = parseString(
1661
1690
  source.substring(imp.s - 1, imp.e + 1)
1662
1691
  );
1663
1692
  } else if (imp.d > -1) {
1664
1693
  // import()
1665
1694
  let expr = source.substring(imp.s, imp.e).trim();
1666
- if (expr[0] === "'")
1667
- expr = `"${expr
1668
- .slice(1, -1)
1669
- .replace(/"/g, '\\"')}"`;
1670
- dependency = JSON.parse(expr);
1695
+ dependency = parseString(expr);
1671
1696
  } else {
1672
1697
  // e.g. import.meta
1673
1698
  continue;
1674
1699
  }
1700
+
1701
+ // we should not track Node.js build dependencies
1702
+ if (dependency.startsWith("node:")) continue;
1703
+ if (builtinModules.has(dependency)) continue;
1704
+
1675
1705
  push({
1676
1706
  type: RBDT_RESOLVE_ESM_FILE,
1677
1707
  context,
@@ -1797,7 +1827,7 @@ class FileSystemInfo {
1797
1827
 
1798
1828
  /**
1799
1829
  * @param {Map<string, string | false>} resolveResults results from resolving
1800
- * @param {function(Error=, boolean=): void} callback callback with true when resolveResults resolve the same way
1830
+ * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way
1801
1831
  * @returns {void}
1802
1832
  */
1803
1833
  checkResolveResultsValid(resolveResults, callback) {
@@ -1879,7 +1909,7 @@ class FileSystemInfo {
1879
1909
  * @param {Object} options options object (for future extensions)
1880
1910
  * @param {boolean=} options.hash should use hash to snapshot
1881
1911
  * @param {boolean=} options.timestamp should use timestamp to snapshot
1882
- * @param {function(WebpackError=, Snapshot=): void} callback callback function
1912
+ * @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function
1883
1913
  * @returns {void}
1884
1914
  */
1885
1915
  createSnapshot(startTime, files, directories, missing, options, callback) {
@@ -1988,7 +2018,7 @@ class FileSystemInfo {
1988
2018
  for (const managedPath of this.managedPathsRegExps) {
1989
2019
  const match = managedPath.exec(path);
1990
2020
  if (match) {
1991
- const managedItem = getManagedItem(managedPath[1], path);
2021
+ const managedItem = getManagedItem(match[1], path);
1992
2022
  if (managedItem) {
1993
2023
  managedItems.add(managedItem);
1994
2024
  managedSet.add(path);
@@ -2015,8 +2045,7 @@ class FileSystemInfo {
2015
2045
  }
2016
2046
  return capturedItems;
2017
2047
  };
2018
- if (files) {
2019
- const capturedFiles = captureNonManaged(files, managedFiles);
2048
+ const processCapturedFiles = capturedFiles => {
2020
2049
  switch (mode) {
2021
2050
  case 3:
2022
2051
  this._fileTshsOptimization.optimize(snapshot, capturedFiles);
@@ -2093,12 +2122,11 @@ class FileSystemInfo {
2093
2122
  }
2094
2123
  break;
2095
2124
  }
2125
+ };
2126
+ if (files) {
2127
+ processCapturedFiles(captureNonManaged(files, managedFiles));
2096
2128
  }
2097
- if (directories) {
2098
- const capturedDirectories = captureNonManaged(
2099
- directories,
2100
- managedContexts
2101
- );
2129
+ const processCapturedDirectories = capturedDirectories => {
2102
2130
  switch (mode) {
2103
2131
  case 3:
2104
2132
  this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
@@ -2218,9 +2246,13 @@ class FileSystemInfo {
2218
2246
  }
2219
2247
  break;
2220
2248
  }
2249
+ };
2250
+ if (directories) {
2251
+ processCapturedDirectories(
2252
+ captureNonManaged(directories, managedContexts)
2253
+ );
2221
2254
  }
2222
- if (missing) {
2223
- const capturedMissing = captureNonManaged(missing, managedMissing);
2255
+ const processCapturedMissing = capturedMissing => {
2224
2256
  this._missingExistenceOptimization.optimize(snapshot, capturedMissing);
2225
2257
  for (const path of capturedMissing) {
2226
2258
  const cache = this._fileTimestamps.get(path);
@@ -2245,11 +2277,19 @@ class FileSystemInfo {
2245
2277
  });
2246
2278
  }
2247
2279
  }
2280
+ };
2281
+ if (missing) {
2282
+ processCapturedMissing(captureNonManaged(missing, managedMissing));
2248
2283
  }
2249
2284
  this._managedItemInfoOptimization.optimize(snapshot, managedItems);
2250
2285
  for (const path of managedItems) {
2251
2286
  const cache = this._managedItems.get(path);
2252
2287
  if (cache !== undefined) {
2288
+ if (!cache.startsWith("*")) {
2289
+ managedFiles.add(join(this.fs, path, "package.json"));
2290
+ } else if (cache === "*nested") {
2291
+ managedMissing.add(join(this.fs, path, "package.json"));
2292
+ }
2253
2293
  managedItemInfo.set(path, cache);
2254
2294
  } else {
2255
2295
  jobs++;
@@ -2261,9 +2301,28 @@ class FileSystemInfo {
2261
2301
  );
2262
2302
  }
2263
2303
  jobError();
2264
- } else {
2304
+ } else if (entry) {
2305
+ if (!entry.startsWith("*")) {
2306
+ managedFiles.add(join(this.fs, path, "package.json"));
2307
+ } else if (cache === "*nested") {
2308
+ managedMissing.add(join(this.fs, path, "package.json"));
2309
+ }
2265
2310
  managedItemInfo.set(path, entry);
2266
2311
  jobDone();
2312
+ } else {
2313
+ // Fallback to normal snapshotting
2314
+ const process = (set, fn) => {
2315
+ if (set.size === 0) return;
2316
+ const captured = new Set();
2317
+ for (const file of set) {
2318
+ if (file.startsWith(path)) captured.add(file);
2319
+ }
2320
+ if (captured.size > 0) fn(captured);
2321
+ };
2322
+ process(managedFiles, processCapturedFiles);
2323
+ process(managedContexts, processCapturedDirectories);
2324
+ process(managedMissing, processCapturedMissing);
2325
+ jobDone();
2267
2326
  }
2268
2327
  });
2269
2328
  }
@@ -2349,7 +2408,7 @@ class FileSystemInfo {
2349
2408
 
2350
2409
  /**
2351
2410
  * @param {Snapshot} snapshot the snapshot made
2352
- * @param {function(WebpackError=, boolean=): void} callback callback function
2411
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2353
2412
  * @returns {void}
2354
2413
  */
2355
2414
  checkSnapshotValid(snapshot, callback) {
@@ -2369,7 +2428,7 @@ class FileSystemInfo {
2369
2428
 
2370
2429
  /**
2371
2430
  * @param {Snapshot} snapshot the snapshot made
2372
- * @param {function(WebpackError=, boolean=): void} callback callback function
2431
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2373
2432
  * @returns {void}
2374
2433
  */
2375
2434
  _checkSnapshotValidNoCache(snapshot, callback) {
@@ -2918,7 +2977,7 @@ class FileSystemInfo {
2918
2977
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromFile called when context item is a file
2919
2978
  * @param {function(string, IStats, function(Error=, ItemType=): void): void} options.fromDirectory called when context item is a directory
2920
2979
  * @param {function(string[], ItemType[]): T} options.reduce called from all context items
2921
- * @param {function(Error=, (T)=): void} callback callback
2980
+ * @param {function((Error | null)=, (T)=): void} callback callback
2922
2981
  */
2923
2982
  _readContext(
2924
2983
  {
@@ -2962,7 +3021,7 @@ class FileSystemInfo {
2962
3021
  for (const managedPath of this.managedPathsRegExps) {
2963
3022
  const match = managedPath.exec(path);
2964
3023
  if (match) {
2965
- const managedItem = getManagedItem(managedPath[1], path);
3024
+ const managedItem = getManagedItem(match[1], path);
2966
3025
  if (managedItem) {
2967
3026
  // construct timestampHash from managed info
2968
3027
  return this.managedItemQueue.add(managedItem, (err, info) => {
@@ -3101,7 +3160,7 @@ class FileSystemInfo {
3101
3160
 
3102
3161
  /**
3103
3162
  * @param {ContextFileSystemInfoEntry} entry entry
3104
- * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3163
+ * @param {function((Error | null)=, ResolvedContextFileSystemInfoEntry=): void} callback callback
3105
3164
  * @returns {void}
3106
3165
  */
3107
3166
  _resolveContextTimestamp(entry, callback) {
@@ -3209,7 +3268,7 @@ class FileSystemInfo {
3209
3268
 
3210
3269
  /**
3211
3270
  * @param {ContextHash} entry context hash
3212
- * @param {function(Error=, string=): void} callback callback
3271
+ * @param {function((Error | null)=, string=): void} callback callback
3213
3272
  * @returns {void}
3214
3273
  */
3215
3274
  _resolveContextHash(entry, callback) {
@@ -3365,7 +3424,7 @@ class FileSystemInfo {
3365
3424
 
3366
3425
  /**
3367
3426
  * @param {ContextTimestampAndHash} entry entry
3368
- * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback
3427
+ * @param {function((Error | null)=, ResolvedContextTimestampAndHash=): void} callback callback
3369
3428
  * @returns {void}
3370
3429
  */
3371
3430
  _resolveContextTsh(entry, callback) {
@@ -3445,8 +3504,8 @@ class FileSystemInfo {
3445
3504
  }
3446
3505
  if (!elements.has(path)) {
3447
3506
  // file or directory doesn't exist
3448
- this._managedItems.set(path, "missing");
3449
- return callback(null, "missing");
3507
+ this._managedItems.set(path, "*missing");
3508
+ return callback(null, "*missing");
3450
3509
  }
3451
3510
  // something exists
3452
3511
  // it may be a file or directory
@@ -3455,8 +3514,8 @@ class FileSystemInfo {
3455
3514
  (path.endsWith("/node_modules") || path.endsWith("\\node_modules"))
3456
3515
  ) {
3457
3516
  // we are only interested in existence of this special directory
3458
- this._managedItems.set(path, "exists");
3459
- return callback(null, "exists");
3517
+ this._managedItems.set(path, "*node_modules");
3518
+ return callback(null, "*node_modules");
3460
3519
  }
3461
3520
 
3462
3521
  // we assume it's a directory, as files shouldn't occur in managed paths
@@ -3473,12 +3532,13 @@ class FileSystemInfo {
3473
3532
  ) {
3474
3533
  // This is only a grouping folder e. g. used by yarn
3475
3534
  // we are only interested in existence of this special directory
3476
- this._managedItems.set(path, "nested");
3477
- return callback(null, "nested");
3535
+ this._managedItems.set(path, "*nested");
3536
+ return callback(null, "*nested");
3478
3537
  }
3479
- const problem = `Managed item ${path} isn't a directory or doesn't contain a package.json`;
3480
- this.logger.warn(problem);
3481
- return callback(new Error(problem));
3538
+ this.logger.warn(
3539
+ `Managed item ${path} isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)`
3540
+ );
3541
+ return callback();
3482
3542
  });
3483
3543
  return;
3484
3544
  }
@@ -3490,6 +3550,12 @@ class FileSystemInfo {
3490
3550
  } catch (e) {
3491
3551
  return callback(e);
3492
3552
  }
3553
+ if (!data.name) {
3554
+ this.logger.warn(
3555
+ `${packageJsonPath} doesn't contain a "name" property (see snapshot.managedPaths option)`
3556
+ );
3557
+ return callback();
3558
+ }
3493
3559
  const info = `${data.name || ""}@${data.version || ""}`;
3494
3560
  this._managedItems.set(path, info);
3495
3561
  callback(null, info);
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
  */
@@ -36,6 +38,7 @@
36
38
  * @property {NormalModule} module the module
37
39
  * @property {ChunkGraph} chunkGraph
38
40
  * @property {RuntimeSpec} runtime
41
+ * @property {RuntimeTemplate=} runtimeTemplate
39
42
  */
40
43
 
41
44
  /**
@@ -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
  */
@@ -83,6 +83,7 @@ class HotModuleReplacementPlugin {
83
83
  * @returns {void}
84
84
  */
85
85
  apply(compiler) {
86
+ const { _backCompat: backCompat } = compiler;
86
87
  if (compiler.options.output.strictModuleErrorHandling === undefined)
87
88
  compiler.options.output.strictModuleErrorHandling = true;
88
89
  const runtimeRequirements = [RuntimeGlobals.module];
@@ -597,7 +598,8 @@ class HotModuleReplacementPlugin {
597
598
  (newRuntimeModules && newRuntimeModules.length > 0)
598
599
  ) {
599
600
  const hotUpdateChunk = new HotUpdateChunk();
600
- ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
601
+ if (backCompat)
602
+ ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
601
603
  hotUpdateChunk.id = chunkId;
602
604
  hotUpdateChunk.runtime = newRuntime;
603
605
  if (currentChunk) {
@@ -52,7 +52,7 @@ class LoaderOptionsPlugin {
52
52
  if (
53
53
  ModuleFilenameHelpers.matchObject(
54
54
  options,
55
- i < 0 ? resource : resource.substr(0, i)
55
+ i < 0 ? resource : resource.slice(0, i)
56
56
  )
57
57
  ) {
58
58
  for (const key of Object.keys(options)) {
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 */
@@ -48,6 +49,7 @@ const makeSerializable = require("./util/makeSerializable");
48
49
  * @property {string=} type the type of source that should be generated
49
50
  */
50
51
 
52
+ // TODO webpack 6: compilation will be required in CodeGenerationContext
51
53
  /**
52
54
  * @typedef {Object} CodeGenerationContext
53
55
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -56,6 +58,9 @@ const makeSerializable = require("./util/makeSerializable");
56
58
  * @property {ChunkGraph} chunkGraph the chunk graph
57
59
  * @property {RuntimeSpec} runtime the runtimes code should be generated for
58
60
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
61
+ * @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
62
+ * @property {Compilation=} compilation the compilation
63
+ * @property {ReadonlySet<string>=} sourceTypes source types
59
64
  */
60
65
 
61
66
  /**
@@ -165,6 +170,8 @@ class Module extends DependenciesBlock {
165
170
  this.buildInfo = undefined;
166
171
  /** @type {Dependency[] | undefined} */
167
172
  this.presentationalDependencies = undefined;
173
+ /** @type {Dependency[] | undefined} */
174
+ this.codeGenerationDependencies = undefined;
168
175
  }
169
176
 
170
177
  // TODO remove in webpack 6
@@ -396,7 +403,6 @@ class Module extends DependenciesBlock {
396
403
  // BACKWARD-COMPAT END
397
404
 
398
405
  /**
399
- * @deprecated moved to .buildInfo.exportsArgument
400
406
  * @returns {string} name of the exports argument
401
407
  */
402
408
  get exportsArgument() {
@@ -404,7 +410,6 @@ class Module extends DependenciesBlock {
404
410
  }
405
411
 
406
412
  /**
407
- * @deprecated moved to .buildInfo.moduleArgument
408
413
  * @returns {string} name of the module argument
409
414
  */
410
415
  get moduleArgument() {
@@ -493,6 +498,19 @@ class Module extends DependenciesBlock {
493
498
  this.presentationalDependencies.push(presentationalDependency);
494
499
  }
495
500
 
501
+ /**
502
+ * @param {Dependency} codeGenerationDependency dependency being tied to module.
503
+ * This is a Dependency where the code generation result of the referenced module is needed during code generation.
504
+ * The Dependency should also be added to normal dependencies via addDependency.
505
+ * @returns {void}
506
+ */
507
+ addCodeGenerationDependency(codeGenerationDependency) {
508
+ if (this.codeGenerationDependencies === undefined) {
509
+ this.codeGenerationDependencies = [];
510
+ }
511
+ this.codeGenerationDependencies.push(codeGenerationDependency);
512
+ }
513
+
496
514
  /**
497
515
  * Removes all dependencies and blocks
498
516
  * @returns {void}
@@ -501,6 +519,9 @@ class Module extends DependenciesBlock {
501
519
  if (this.presentationalDependencies !== undefined) {
502
520
  this.presentationalDependencies.length = 0;
503
521
  }
522
+ if (this.codeGenerationDependencies !== undefined) {
523
+ this.codeGenerationDependencies.length = 0;
524
+ }
504
525
  super.clearDependenciesAndBlocks();
505
526
  }
506
527
 
@@ -671,7 +692,7 @@ class Module extends DependenciesBlock {
671
692
 
672
693
  /**
673
694
  * @param {NeedBuildContext} context context info
674
- * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
695
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
675
696
  * @returns {void}
676
697
  */
677
698
  needBuild(context, callback) {
@@ -799,7 +820,8 @@ class Module extends DependenciesBlock {
799
820
  runtimeTemplate,
800
821
  moduleGraph: chunkGraph.moduleGraph,
801
822
  chunkGraph,
802
- runtime: undefined
823
+ runtime: undefined,
824
+ codeGenerationResults: undefined
803
825
  };
804
826
  const sources = this.codeGeneration(codeGenContext).sources;
805
827
  return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
@@ -976,6 +998,7 @@ class Module extends DependenciesBlock {
976
998
  write(this.buildMeta);
977
999
  write(this.buildInfo);
978
1000
  write(this.presentationalDependencies);
1001
+ write(this.codeGenerationDependencies);
979
1002
  super.serialize(context);
980
1003
  }
981
1004
 
@@ -993,6 +1016,7 @@ class Module extends DependenciesBlock {
993
1016
  this.buildMeta = read();
994
1017
  this.buildInfo = read();
995
1018
  this.presentationalDependencies = read();
1019
+ this.codeGenerationDependencies = read();
996
1020
  super.deserialize(context);
997
1021
  }
998
1022
  }