webpack 5.49.0 → 5.51.2

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 (41) hide show
  1. package/README.md +4 -16
  2. package/bin/webpack.js +0 -0
  3. package/lib/ChunkGraph.js +75 -1
  4. package/lib/CompatibilityPlugin.js +21 -4
  5. package/lib/Compilation.js +10 -1
  6. package/lib/Compiler.js +7 -0
  7. package/lib/EvalSourceMapDevToolPlugin.js +2 -2
  8. package/lib/FileSystemInfo.js +660 -191
  9. package/lib/HotModuleReplacementPlugin.js +14 -0
  10. package/lib/NormalModule.js +13 -3
  11. package/lib/Parser.js +1 -0
  12. package/lib/RuntimeGlobals.js +5 -0
  13. package/lib/RuntimeModule.js +2 -1
  14. package/lib/SourceMapDevToolPlugin.js +2 -2
  15. package/lib/Watching.js +8 -10
  16. package/lib/config/defaults.js +1 -1
  17. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -2
  18. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -1
  19. package/lib/javascript/JavascriptParser.js +2 -0
  20. package/lib/library/ModuleLibraryPlugin.js +4 -0
  21. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -1
  22. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  23. package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
  24. package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -1
  25. package/lib/optimize/ConcatenatedModule.js +3 -3
  26. package/lib/optimize/SplitChunksPlugin.js +1 -1
  27. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -0
  28. package/lib/serialization/BinaryMiddleware.js +293 -265
  29. package/lib/util/fs.js +40 -0
  30. package/lib/util/identifier.js +26 -8
  31. package/lib/util/propertyAccess.js +54 -1
  32. package/lib/wasm-async/{AsyncWasmChunkLoadingRuntimeModule.js → AsyncWasmLoadingRuntimeModule.js} +3 -3
  33. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -2
  34. package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -2
  35. package/lib/web/FetchCompileWasmPlugin.js +2 -1
  36. package/lib/web/JsonpChunkLoadingRuntimeModule.js +21 -8
  37. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +7 -1
  38. package/package.json +2 -1
  39. package/schemas/WebpackOptions.json +1 -1
  40. package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
  41. package/types.d.ts +63 -9
package/README.md CHANGED
@@ -138,25 +138,13 @@ or are automatically applied via regex from your webpack configuration.
138
138
 
139
139
  #### Files
140
140
 
141
- | Name | Status | Install Size | Description |
142
- | :-----------------: | :---------: | :----------: | :---------------------------------------------------------------------------------------- |
143
- | [raw-loader][raw] | ![raw-npm] | ![raw-size] | Loads raw content of a file (utf-8) |
144
- | [val-loader][val] | ![val-npm] | ![val-size] | Executes code as module and considers exports as JS code |
145
- | [url-loader][url] | ![url-npm] | ![url-size] | Works like the file loader, but can return a Data Url if the file is smaller than a limit |
146
- | [file-loader][file] | ![file-npm] | ![file-size] | Emits the file into the output folder and returns the (relative) url |
147
-
148
- [raw]: https://github.com/webpack-contrib/raw-loader
149
- [raw-npm]: https://img.shields.io/npm/v/raw-loader.svg
150
- [raw-size]: https://packagephobia.com/badge?p=raw-loader
141
+ | Name | Status | Install Size | Description |
142
+ | :---------------: | :--------: | :----------: | :------------------------------------------------------- |
143
+ | [val-loader][val] | ![val-npm] | ![val-size] | Executes code as module and considers exports as JS code |
144
+
151
145
  [val]: https://github.com/webpack-contrib/val-loader
152
146
  [val-npm]: https://img.shields.io/npm/v/val-loader.svg
153
147
  [val-size]: https://packagephobia.com/badge?p=val-loader
154
- [url]: https://github.com/webpack-contrib/url-loader
155
- [url-npm]: https://img.shields.io/npm/v/url-loader.svg
156
- [url-size]: https://packagephobia.com/badge?p=url-loader
157
- [file]: https://github.com/webpack-contrib/file-loader
158
- [file-npm]: https://img.shields.io/npm/v/file-loader.svg
159
- [file-size]: https://packagephobia.com/badge?p=file-loader
160
148
 
161
149
  #### JSON
162
150
 
package/bin/webpack.js CHANGED
File without changes
package/lib/ChunkGraph.js CHANGED
@@ -205,6 +205,8 @@ class ChunkGraphChunk {
205
205
  this.runtimeModules = new SortableSet();
206
206
  /** @type {Set<RuntimeModule> | undefined} */
207
207
  this.fullHashModules = undefined;
208
+ /** @type {Set<RuntimeModule> | undefined} */
209
+ this.dependentHashModules = undefined;
208
210
  /** @type {Set<string> | undefined} */
209
211
  this.runtimeRequirements = undefined;
210
212
  /** @type {Set<string>} */
@@ -389,6 +391,20 @@ class ChunkGraph {
389
391
  }
390
392
  }
391
393
 
394
+ /**
395
+ * @param {Chunk} chunk the chunk
396
+ * @param {Iterable<RuntimeModule>} modules the modules that require a full hash
397
+ * @returns {void}
398
+ */
399
+ attachDependentHashModules(chunk, modules) {
400
+ const cgc = this._getChunkGraphChunk(chunk);
401
+ if (cgc.dependentHashModules === undefined)
402
+ cgc.dependentHashModules = new Set();
403
+ for (const module of modules) {
404
+ cgc.dependentHashModules.add(module);
405
+ }
406
+ }
407
+
392
408
  /**
393
409
  * @param {Module} oldModule the replaced module
394
410
  * @param {Module} newModule the replacing module
@@ -444,6 +460,17 @@ class ChunkGraph {
444
460
  cgc.fullHashModules.delete(/** @type {RuntimeModule} */ (oldModule));
445
461
  cgc.fullHashModules.add(/** @type {RuntimeModule} */ (newModule));
446
462
  }
463
+ if (
464
+ cgc.dependentHashModules !== undefined &&
465
+ cgc.dependentHashModules.has(/** @type {RuntimeModule} */ (oldModule))
466
+ ) {
467
+ cgc.dependentHashModules.delete(
468
+ /** @type {RuntimeModule} */ (oldModule)
469
+ );
470
+ cgc.dependentHashModules.add(
471
+ /** @type {RuntimeModule} */ (newModule)
472
+ );
473
+ }
447
474
  }
448
475
  oldCgm.runtimeInChunks = undefined;
449
476
  }
@@ -529,13 +556,22 @@ class ChunkGraph {
529
556
 
530
557
  /**
531
558
  * @param {Chunk} chunk the chunk
532
- * @returns {number} the number of module which are contained in this chunk
559
+ * @returns {number} the number of modules which are contained in this chunk
533
560
  */
534
561
  getNumberOfChunkModules(chunk) {
535
562
  const cgc = this._getChunkGraphChunk(chunk);
536
563
  return cgc.modules.size;
537
564
  }
538
565
 
566
+ /**
567
+ * @param {Chunk} chunk the chunk
568
+ * @returns {number} the number of full hash modules which are contained in this chunk
569
+ */
570
+ getNumberOfChunkFullHashModules(chunk) {
571
+ const cgc = this._getChunkGraphChunk(chunk);
572
+ return cgc.fullHashModules === undefined ? 0 : cgc.fullHashModules.size;
573
+ }
574
+
539
575
  /**
540
576
  * @param {Chunk} chunk the chunk
541
577
  * @returns {Iterable<Module>} return the modules for this chunk
@@ -900,6 +936,23 @@ class ChunkGraph {
900
936
  ChunkGraph.clearChunkGraphForChunk(chunkB);
901
937
  }
902
938
 
939
+ /**
940
+ * @param {Chunk} chunk the chunk to upgrade
941
+ * @returns {void}
942
+ */
943
+ upgradeDependentToFullHashModules(chunk) {
944
+ const cgc = this._getChunkGraphChunk(chunk);
945
+ if (cgc.dependentHashModules === undefined) return;
946
+ if (cgc.fullHashModules === undefined) {
947
+ cgc.fullHashModules = cgc.dependentHashModules;
948
+ } else {
949
+ for (const m of cgc.dependentHashModules) {
950
+ cgc.fullHashModules.add(m);
951
+ }
952
+ cgc.dependentHashModules = undefined;
953
+ }
954
+ }
955
+
903
956
  /**
904
957
  * @param {Module} module the checked module
905
958
  * @param {Chunk} chunk the checked chunk
@@ -952,6 +1005,18 @@ class ChunkGraph {
952
1005
  cgc.fullHashModules.add(module);
953
1006
  }
954
1007
 
1008
+ /**
1009
+ * @param {Chunk} chunk the new chunk
1010
+ * @param {RuntimeModule} module the module that require a full hash
1011
+ * @returns {void}
1012
+ */
1013
+ addDependentHashModuleToChunk(chunk, module) {
1014
+ const cgc = this._getChunkGraphChunk(chunk);
1015
+ if (cgc.dependentHashModules === undefined)
1016
+ cgc.dependentHashModules = new Set();
1017
+ cgc.dependentHashModules.add(module);
1018
+ }
1019
+
955
1020
  /**
956
1021
  * @param {Chunk} chunk the new chunk
957
1022
  * @param {Module} module the entry module
@@ -1128,6 +1193,15 @@ class ChunkGraph {
1128
1193
  return cgc.fullHashModules;
1129
1194
  }
1130
1195
 
1196
+ /**
1197
+ * @param {Chunk} chunk the chunk
1198
+ * @returns {Iterable<RuntimeModule> | undefined} iterable of modules (do not modify)
1199
+ */
1200
+ getChunkDependentHashModulesIterable(chunk) {
1201
+ const cgc = this._getChunkGraphChunk(chunk);
1202
+ return cgc.dependentHashModules;
1203
+ }
1204
+
1131
1205
  /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
1132
1206
 
1133
1207
  /**
@@ -69,7 +69,8 @@ class CompatibilityPlugin {
69
69
  * @param {JavascriptParser} parser the parser
70
70
  * @returns {void}
71
71
  */
72
- const nestedWebpackRequireHandler = parser => {
72
+ const handler = parser => {
73
+ // Handle nested requires
73
74
  parser.hooks.preStatement.tap("CompatibilityPlugin", statement => {
74
75
  if (
75
76
  statement.type === "FunctionDeclaration" &&
@@ -117,17 +118,33 @@ class CompatibilityPlugin {
117
118
  parser.state.module.addPresentationalDependency(dep);
118
119
  return true;
119
120
  });
121
+
122
+ // Handle hashbang
123
+ parser.hooks.program.tap(
124
+ "CompatibilityPlugin",
125
+ (program, comments) => {
126
+ if (comments.length === 0) return;
127
+ const c = comments[0];
128
+ if (c.type === "Line" && c.range[0] === 0) {
129
+ if (parser.state.source.slice(0, 2).toString() !== "#!") return;
130
+ // this is a hashbang comment
131
+ const dep = new ConstDependency("//", 0);
132
+ dep.loc = c.loc;
133
+ parser.state.module.addPresentationalDependency(dep);
134
+ }
135
+ }
136
+ );
120
137
  };
121
138
 
122
139
  normalModuleFactory.hooks.parser
123
140
  .for("javascript/auto")
124
- .tap("CompatibilityPlugin", nestedWebpackRequireHandler);
141
+ .tap("CompatibilityPlugin", handler);
125
142
  normalModuleFactory.hooks.parser
126
143
  .for("javascript/dynamic")
127
- .tap("CompatibilityPlugin", nestedWebpackRequireHandler);
144
+ .tap("CompatibilityPlugin", handler);
128
145
  normalModuleFactory.hooks.parser
129
146
  .for("javascript/esm")
130
- .tap("CompatibilityPlugin", nestedWebpackRequireHandler);
147
+ .tap("CompatibilityPlugin", handler);
131
148
  }
132
149
  );
133
150
  }
@@ -1839,13 +1839,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1839
1839
  contextInfo,
1840
1840
  context
1841
1841
  },
1842
- err => {
1842
+ (err, result) => {
1843
1843
  if (err && this.bail) {
1844
1844
  callback(err);
1845
1845
  this.buildQueue.stop();
1846
1846
  this.rebuildQueue.stop();
1847
1847
  this.processDependenciesQueue.stop();
1848
1848
  this.factorizeQueue.stop();
1849
+ } else if (!err && result) {
1850
+ callback(null, result);
1849
1851
  } else {
1850
1852
  callback();
1851
1853
  }
@@ -2877,6 +2879,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2877
2879
  chunkGraph.connectChunkAndRuntimeModule(chunk, module);
2878
2880
  if (module.fullHash) {
2879
2881
  chunkGraph.addFullHashModuleToChunk(chunk, module);
2882
+ } else if (module.dependentHash) {
2883
+ chunkGraph.addDependentHashModuleToChunk(chunk, module);
2880
2884
  }
2881
2885
 
2882
2886
  // attach runtime module
@@ -3342,8 +3346,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3342
3346
  if (remaining > 0) {
3343
3347
  const readyChunks = [];
3344
3348
  for (const chunk of runtimeChunks) {
3349
+ const hasFullHashModules =
3350
+ chunkGraph.getNumberOfChunkFullHashModules(chunk) !== 0;
3345
3351
  const info = runtimeChunksMap.get(chunk);
3346
3352
  for (const otherInfo of info.referencedBy) {
3353
+ if (hasFullHashModules) {
3354
+ chunkGraph.upgradeDependentToFullHashModules(otherInfo.chunk);
3355
+ }
3347
3356
  remaining--;
3348
3357
  if (--otherInfo.remaining === 0) {
3349
3358
  readyChunks.push(otherInfo.chunk);
package/lib/Compiler.js CHANGED
@@ -1130,6 +1130,13 @@ ${other}`);
1130
1130
  * @returns {void}
1131
1131
  */
1132
1132
  close(callback) {
1133
+ if (this.watching) {
1134
+ // When there is still an active watching, close this first
1135
+ this.watching.close(err => {
1136
+ this.close(callback);
1137
+ });
1138
+ return;
1139
+ }
1133
1140
  this.hooks.shutdown.callAsync(err => {
1134
1141
  if (err) return callback(err);
1135
1142
  // Get rid of reference to last compilation to avoid leaking memory
@@ -11,7 +11,7 @@ const NormalModule = require("./NormalModule");
11
11
  const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
12
12
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
13
13
  const ConcatenatedModule = require("./optimize/ConcatenatedModule");
14
- const { absolutify } = require("./util/identifier");
14
+ const { makePathsAbsolute } = require("./util/identifier");
15
15
 
16
16
  /** @typedef {import("webpack-sources").Source} Source */
17
17
  /** @typedef {import("../declarations/WebpackOptions").DevTool} DevToolOptions */
@@ -125,7 +125,7 @@ class EvalSourceMapDevToolPlugin {
125
125
  const root = compiler.root;
126
126
  const modules = sourceMap.sources.map(source => {
127
127
  if (!source.startsWith("webpack://")) return source;
128
- source = absolutify(context, source.slice(10), root);
128
+ source = makePathsAbsolute(context, source.slice(10), root);
129
129
  const module = compilation.findModule(source);
130
130
  return module || source;
131
131
  });