webpack 5.12.3 → 5.16.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 (39) hide show
  1. package/lib/AutomaticPrefetchPlugin.js +1 -1
  2. package/lib/ChunkGraph.js +14 -4
  3. package/lib/Compilation.js +20 -15
  4. package/lib/Compiler.js +6 -3
  5. package/lib/ContextModule.js +2 -2
  6. package/lib/ContextModuleFactory.js +6 -4
  7. package/lib/ExportsInfo.js +0 -1
  8. package/lib/ExternalModuleFactoryPlugin.js +46 -3
  9. package/lib/FileSystemInfo.js +288 -157
  10. package/lib/IgnoreErrorModuleFactory.js +39 -0
  11. package/lib/MultiCompiler.js +2 -0
  12. package/lib/NormalModuleFactory.js +26 -7
  13. package/lib/WatchIgnorePlugin.js +6 -1
  14. package/lib/WebpackIsIncludedPlugin.js +85 -0
  15. package/lib/WebpackOptionsApply.js +2 -0
  16. package/lib/cache/PackFileCacheStrategy.js +5 -5
  17. package/lib/dependencies/AMDDefineDependency.js +1 -1
  18. package/lib/dependencies/HarmonyImportSpecifierDependency.js +2 -17
  19. package/lib/dependencies/URLDependency.js +45 -3
  20. package/lib/dependencies/URLPlugin.js +33 -7
  21. package/lib/dependencies/WebpackIsIncludedDependency.js +80 -0
  22. package/lib/ids/IdHelpers.js +8 -3
  23. package/lib/javascript/JavascriptModulesPlugin.js +4 -3
  24. package/lib/library/AssignLibraryPlugin.js +13 -4
  25. package/lib/library/EnableLibraryPlugin.js +12 -0
  26. package/lib/optimize/InnerGraph.js +32 -0
  27. package/lib/optimize/SplitChunksPlugin.js +4 -1
  28. package/lib/serialization/FileMiddleware.js +1 -1
  29. package/lib/sharing/ProvideSharedModule.js +1 -1
  30. package/lib/sharing/ShareRuntimeModule.js +2 -2
  31. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -0
  32. package/lib/util/fs.js +51 -11
  33. package/lib/util/internalSerializables.js +2 -0
  34. package/lib/util/processAsyncTree.js +61 -0
  35. package/package.json +9 -7
  36. package/schemas/WebpackOptions.json +62 -25
  37. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  38. package/schemas/plugins/container/ModuleFederationPlugin.json +2 -1
  39. package/types.d.ts +339 -236
@@ -45,7 +45,7 @@ class AutomaticPrefetchPlugin {
45
45
  (m, callback) => {
46
46
  compilation.addModuleChain(
47
47
  m.context || compiler.context,
48
- new PrefetchDependency(m.request),
48
+ new PrefetchDependency(`!!${m.request}`),
49
49
  callback
50
50
  );
51
51
  },
package/lib/ChunkGraph.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const util = require("util");
9
+ const ModuleGraphConnection = require("./ModuleGraphConnection");
9
10
  const SortableSet = require("./util/SortableSet");
10
11
  const {
11
12
  compareModulesById,
@@ -272,10 +273,19 @@ class ChunkGraph {
272
273
  findGraphRoots(set, module => {
273
274
  /** @type {Set<Module>} */
274
275
  const set = new Set();
275
- for (const connection of moduleGraph.getOutgoingConnections(module)) {
276
- if (!connection.module) continue;
277
- set.add(connection.module);
278
- }
276
+ const addDependencies = module => {
277
+ for (const connection of moduleGraph.getOutgoingConnections(module)) {
278
+ if (!connection.module) continue;
279
+ const activeState = connection.getActiveState(undefined);
280
+ if (activeState === false) continue;
281
+ if (activeState === ModuleGraphConnection.TRANSITIVE_ONLY) {
282
+ addDependencies(connection.module);
283
+ continue;
284
+ }
285
+ set.add(connection.module);
286
+ }
287
+ };
288
+ addDependencies(module);
279
289
  return set;
280
290
  })
281
291
  ).sort(compareModulesByIdentifier);
@@ -2683,18 +2683,6 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2683
2683
  * @returns {void}
2684
2684
  */
2685
2685
  removeReasonsOfDependencyBlock(module, block) {
2686
- const chunkGraph = this.chunkGraph;
2687
- const iteratorDependency = d => {
2688
- if (!d.module) {
2689
- return;
2690
- }
2691
- if (d.module.removeReason(module, d)) {
2692
- for (const chunk of chunkGraph.getModuleChunksIterable(d.module)) {
2693
- this.patchChunksAfterReasonRemoval(d.module, chunk);
2694
- }
2695
- }
2696
- };
2697
-
2698
2686
  if (block.blocks) {
2699
2687
  for (const b of block.blocks) {
2700
2688
  this.removeReasonsOfDependencyBlock(module, b);
@@ -2702,7 +2690,20 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2702
2690
  }
2703
2691
 
2704
2692
  if (block.dependencies) {
2705
- for (const dep of block.dependencies) iteratorDependency(dep);
2693
+ for (const dep of block.dependencies) {
2694
+ const originalModule = this.moduleGraph.getModule(dep);
2695
+ if (originalModule) {
2696
+ this.moduleGraph.removeConnection(dep);
2697
+
2698
+ if (this.chunkGraph) {
2699
+ for (const chunk of this.chunkGraph.getModuleChunks(
2700
+ originalModule
2701
+ )) {
2702
+ this.patchChunksAfterReasonRemoval(originalModule, chunk);
2703
+ }
2704
+ }
2705
+ }
2706
+ }
2706
2707
  }
2707
2708
  }
2708
2709
 
@@ -2730,11 +2731,15 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2730
2731
  * @returns {void}
2731
2732
  */
2732
2733
  removeChunkFromDependencies(block, chunk) {
2734
+ /**
2735
+ * @param {Dependency} d dependency to (maybe) patch up
2736
+ */
2733
2737
  const iteratorDependency = d => {
2734
- if (!d.module) {
2738
+ const depModule = this.moduleGraph.getModule(d);
2739
+ if (!depModule) {
2735
2740
  return;
2736
2741
  }
2737
- this.patchChunksAfterReasonRemoval(d.module, chunk);
2742
+ this.patchChunksAfterReasonRemoval(depModule, chunk);
2738
2743
  };
2739
2744
 
2740
2745
  const blocks = block.blocks;
package/lib/Compiler.js CHANGED
@@ -222,9 +222,9 @@ class Compiler {
222
222
  this.modifiedFiles = undefined;
223
223
  /** @type {Set<string>} */
224
224
  this.removedFiles = undefined;
225
- /** @type {Map<string, FileSystemInfoEntry | null>} */
225
+ /** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
226
226
  this.fileTimestamps = undefined;
227
- /** @type {Map<string, FileSystemInfoEntry | null>} */
227
+ /** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
228
228
  this.contextTimestamps = undefined;
229
229
 
230
230
  /** @type {ResolverFactory} */
@@ -724,7 +724,10 @@ ${other}`);
724
724
  return this.outputFileSystem.readFile(
725
725
  targetPath,
726
726
  (err, existingContent) => {
727
- if (err || !content.equals(existingContent)) {
727
+ if (
728
+ err ||
729
+ !content.equals(/** @type {Buffer} */ (existingContent))
730
+ ) {
728
731
  return doWrite(content);
729
732
  } else {
730
733
  return alreadyWritten();
@@ -16,9 +16,9 @@ const {
16
16
  compareLocations,
17
17
  concatComparators,
18
18
  compareSelect,
19
- keepOriginalOrder
19
+ keepOriginalOrder,
20
+ compareModulesById
20
21
  } = require("./util/comparators");
21
- const { compareModulesById } = require("./util/comparators");
22
22
  const { contextify, parseResource } = require("./util/identifier");
23
23
  const makeSerializable = require("./util/makeSerializable");
24
24
 
@@ -298,11 +298,13 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
298
298
  const addDirectory = (directory, addSubDirectory, callback) => {
299
299
  fs.readdir(directory, (err, files) => {
300
300
  if (err) return callback(err);
301
- files = files.map(file => file.normalize("NFC"));
302
- files = cmf.hooks.contextModuleFiles.call(files);
303
- if (!files || files.length === 0) return callback(null, []);
301
+ const processedFiles = cmf.hooks.contextModuleFiles.call(
302
+ /** @type {string[]} */ (files).map(file => file.normalize("NFC"))
303
+ );
304
+ if (!processedFiles || processedFiles.length === 0)
305
+ return callback(null, []);
304
306
  asyncLib.map(
305
- files.filter(p => p.indexOf(".") !== 0),
307
+ processedFiles.filter(p => p.indexOf(".") !== 0),
306
308
  (segment, callback) => {
307
309
  const subResource = join(fs, directory, segment);
308
310
 
@@ -457,7 +457,6 @@ class ExportsInfo {
457
457
  case UsageState.NoInfo:
458
458
  return null;
459
459
  case UsageState.Unknown:
460
- return true;
461
460
  case UsageState.OnlyPropertiesUsed:
462
461
  case UsageState.Used:
463
462
  return true;
@@ -7,12 +7,13 @@
7
7
 
8
8
  const util = require("util");
9
9
  const ExternalModule = require("./ExternalModule");
10
- const { resolveByProperty } = require("./util/cleverMerge");
10
+ const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
11
11
 
12
12
  /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
13
13
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
14
14
 
15
15
  const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9]+ /;
16
+ const EMPTY_RESOLVE_OPTIONS = {};
16
17
 
17
18
  // TODO webpack 6 remove this
18
19
  const callDeprecatedExternals = util.deprecate(
@@ -171,14 +172,56 @@ class ExternalModuleFactoryPlugin {
171
172
  cb
172
173
  );
173
174
  } else {
174
- externals(
175
+ const promise = externals(
175
176
  {
176
177
  context,
177
178
  request: dependency.request,
178
- contextInfo
179
+ contextInfo,
180
+ getResolve: options => (context, request, callback) => {
181
+ const dependencyType = dependency.category || "";
182
+ const resolveContext = {
183
+ fileDependencies: data.fileDependencies,
184
+ missingDependencies: data.missingDependencies,
185
+ contextDependencies: data.contextDependencies
186
+ };
187
+ let resolver = normalModuleFactory.getResolver(
188
+ "normal",
189
+ dependencyType
190
+ ? cachedSetProperty(
191
+ data.resolveOptions || EMPTY_RESOLVE_OPTIONS,
192
+ "dependencyType",
193
+ dependencyType
194
+ )
195
+ : data.resolveOptions
196
+ );
197
+ if (options) resolver = resolver.withOptions(options);
198
+ if (callback) {
199
+ resolver.resolve(
200
+ {},
201
+ context,
202
+ request,
203
+ resolveContext,
204
+ callback
205
+ );
206
+ } else {
207
+ return new Promise((resolve, reject) => {
208
+ resolver.resolve(
209
+ {},
210
+ context,
211
+ request,
212
+ resolveContext,
213
+ (err, result) => {
214
+ if (err) reject(err);
215
+ else resolve(result);
216
+ }
217
+ );
218
+ });
219
+ }
220
+ }
179
221
  },
180
222
  cb
181
223
  );
224
+ if (promise && promise.then) promise.then(r => cb(null, r), cb);
182
225
  }
183
226
  return;
184
227
  } else if (typeof externals === "object") {