webpack 5.70.0 → 5.72.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 (55) hide show
  1. package/hot/poll.js +1 -1
  2. package/hot/signal.js +1 -1
  3. package/lib/BannerPlugin.js +3 -1
  4. package/lib/Chunk.js +1 -1
  5. package/lib/ChunkGraph.js +93 -6
  6. package/lib/ChunkGroup.js +1 -1
  7. package/lib/Compilation.js +10 -8
  8. package/lib/Compiler.js +16 -3
  9. package/lib/ConstPlugin.js +2 -2
  10. package/lib/ContextModule.js +31 -8
  11. package/lib/ContextModuleFactory.js +7 -11
  12. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  13. package/lib/Dependency.js +7 -0
  14. package/lib/ErrorHelpers.js +2 -2
  15. package/lib/ExportsInfo.js +1 -1
  16. package/lib/ExternalModuleFactoryPlugin.js +4 -4
  17. package/lib/FileSystemInfo.js +8 -0
  18. package/lib/LoaderOptionsPlugin.js +1 -1
  19. package/lib/Module.js +3 -0
  20. package/lib/ModuleFilenameHelpers.js +3 -3
  21. package/lib/NormalModule.js +5 -4
  22. package/lib/NormalModuleFactory.js +2 -2
  23. package/lib/RuntimePlugin.js +18 -0
  24. package/lib/asset/AssetGenerator.js +36 -9
  25. package/lib/asset/AssetParser.js +1 -0
  26. package/lib/asset/AssetSourceGenerator.js +31 -6
  27. package/lib/asset/AssetSourceParser.js +1 -0
  28. package/lib/cache/PackFileCacheStrategy.js +8 -4
  29. package/lib/config/defaults.js +9 -1
  30. package/lib/container/RemoteRuntimeModule.js +8 -7
  31. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  32. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  33. package/lib/dependencies/ContextElementDependency.js +33 -1
  34. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  35. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +127 -43
  36. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -8
  37. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  38. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  39. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  40. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  41. package/lib/ids/HashedModuleIdsPlugin.js +2 -2
  42. package/lib/ids/IdHelpers.js +1 -1
  43. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  44. package/lib/javascript/JavascriptParser.js +66 -40
  45. package/lib/library/UmdLibraryPlugin.js +5 -3
  46. package/lib/optimize/ConcatenatedModule.js +2 -1
  47. package/lib/optimize/ModuleConcatenationPlugin.js +20 -1
  48. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  49. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
  50. package/lib/util/internalSerializables.js +2 -0
  51. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  52. package/package.json +1 -1
  53. package/schemas/plugins/BannerPlugin.check.js +1 -1
  54. package/schemas/plugins/BannerPlugin.json +4 -0
  55. package/types.d.ts +38 -11
package/hot/poll.js CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
  /*globals __resourceQuery */
6
6
  if (module.hot) {
7
- var hotPollInterval = +__resourceQuery.substr(1) || 10 * 60 * 1000;
7
+ var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
8
8
  var log = require("./log");
9
9
 
10
10
  var checkForUpdate = function checkForUpdate(fromUpdate) {
package/hot/signal.js CHANGED
@@ -45,7 +45,7 @@ if (module.hot) {
45
45
  });
46
46
  };
47
47
 
48
- process.on(__resourceQuery.substr(1) || "SIGUSR2", function () {
48
+ process.on(__resourceQuery.slice(1) || "SIGUSR2", function () {
49
49
  if (module.hot.status() !== "idle") {
50
50
  log(
51
51
  "warning",
@@ -106,7 +106,9 @@ class BannerPlugin {
106
106
  compilation.updateAsset(file, old => {
107
107
  let cached = cache.get(old);
108
108
  if (!cached || cached.comment !== comment) {
109
- const source = new ConcatSource(comment, "\n", old);
109
+ const source = options.footer
110
+ ? new ConcatSource(old, "\n", comment)
111
+ : new ConcatSource(comment, "\n", old);
110
112
  cache.set(old, { source, comment });
111
113
  return source;
112
114
  }
package/lib/Chunk.js CHANGED
@@ -690,7 +690,7 @@ class Chunk {
690
690
  for (const childGroup of group.childrenIterable) {
691
691
  for (const key of Object.keys(childGroup.options)) {
692
692
  if (key.endsWith("Order")) {
693
- const name = key.substr(0, key.length - "Order".length);
693
+ const name = key.slice(0, key.length - "Order".length);
694
694
  let list = lists.get(name);
695
695
  if (list === undefined) {
696
696
  list = [];
package/lib/ChunkGraph.js CHANGED
@@ -85,14 +85,17 @@ const getModuleRuntimes = chunks => {
85
85
  };
86
86
 
87
87
  /**
88
- * @param {SortableSet<Module>} set the set
89
- * @returns {Map<string, SortableSet<Module>>} modules by source type
88
+ * @param {WeakMap<Module, Set<string>> | undefined} sourceTypesByModule sourceTypesByModule
89
+ * @returns {function (SortableSet<Module>): Map<string, SortableSet<Module>>} modules by source type
90
90
  */
91
- const modulesBySourceType = set => {
91
+ const modulesBySourceType = sourceTypesByModule => set => {
92
92
  /** @type {Map<string, SortableSet<Module>>} */
93
93
  const map = new Map();
94
94
  for (const module of set) {
95
- for (const sourceType of module.getSourceTypes()) {
95
+ const sourceTypes =
96
+ (sourceTypesByModule && sourceTypesByModule.get(module)) ||
97
+ module.getSourceTypes();
98
+ for (const sourceType of sourceTypes) {
96
99
  let innerSet = map.get(sourceType);
97
100
  if (innerSet === undefined) {
98
101
  innerSet = new SortableSet();
@@ -110,6 +113,7 @@ const modulesBySourceType = set => {
110
113
  }
111
114
  return map;
112
115
  };
116
+ const defaultModulesBySourceType = modulesBySourceType(undefined);
113
117
 
114
118
  /** @type {WeakMap<Function, any>} */
115
119
  const createOrderedArrayFunctionMap = new WeakMap();
@@ -201,6 +205,8 @@ class ChunkGraphChunk {
201
205
  constructor() {
202
206
  /** @type {SortableSet<Module>} */
203
207
  this.modules = new SortableSet();
208
+ /** @type {WeakMap<Module, Set<string>> | undefined} */
209
+ this.sourceTypesByModule = undefined;
204
210
  /** @type {Map<Module, Entrypoint>} */
205
211
  this.entryModules = new Map();
206
212
  /** @type {SortableSet<RuntimeModule>} */
@@ -213,6 +219,8 @@ class ChunkGraphChunk {
213
219
  this.runtimeRequirements = undefined;
214
220
  /** @type {Set<string>} */
215
221
  this.runtimeRequirementsInTree = new Set();
222
+
223
+ this._modulesBySourceType = defaultModulesBySourceType;
216
224
  }
217
225
  }
218
226
 
@@ -315,6 +323,8 @@ class ChunkGraph {
315
323
  const cgm = this._getChunkGraphModule(module);
316
324
  const cgc = this._getChunkGraphChunk(chunk);
317
325
  cgc.modules.delete(module);
326
+ // No need to invalidate cgc._modulesBySourceType because we modified cgc.modules anyway
327
+ if (cgc.sourceTypesByModule) cgc.sourceTypesByModule.delete(module);
318
328
  cgm.chunks.delete(chunk);
319
329
  }
320
330
 
@@ -568,11 +578,84 @@ class ChunkGraph {
568
578
  getChunkModulesIterableBySourceType(chunk, sourceType) {
569
579
  const cgc = this._getChunkGraphChunk(chunk);
570
580
  const modulesWithSourceType = cgc.modules
571
- .getFromUnorderedCache(modulesBySourceType)
581
+ .getFromUnorderedCache(cgc._modulesBySourceType)
572
582
  .get(sourceType);
573
583
  return modulesWithSourceType;
574
584
  }
575
585
 
586
+ /**
587
+ * @param {Chunk} chunk chunk
588
+ * @param {Module} module chunk module
589
+ * @param {Set<string>} sourceTypes source types
590
+ */
591
+ setChunkModuleSourceTypes(chunk, module, sourceTypes) {
592
+ const cgc = this._getChunkGraphChunk(chunk);
593
+ if (cgc.sourceTypesByModule === undefined) {
594
+ cgc.sourceTypesByModule = new WeakMap();
595
+ }
596
+ cgc.sourceTypesByModule.set(module, sourceTypes);
597
+ // Update cgc._modulesBySourceType to invalidate the cache
598
+ cgc._modulesBySourceType = modulesBySourceType(cgc.sourceTypesByModule);
599
+ }
600
+
601
+ /**
602
+ * @param {Chunk} chunk chunk
603
+ * @param {Module} module chunk module
604
+ * @returns {Set<string>} source types
605
+ */
606
+ getChunkModuleSourceTypes(chunk, module) {
607
+ const cgc = this._getChunkGraphChunk(chunk);
608
+ if (cgc.sourceTypesByModule === undefined) {
609
+ return module.getSourceTypes();
610
+ }
611
+ return cgc.sourceTypesByModule.get(module) || module.getSourceTypes();
612
+ }
613
+
614
+ /**
615
+ * @param {Module} module module
616
+ * @returns {Set<string>} source types
617
+ */
618
+ getModuleSourceTypes(module) {
619
+ return (
620
+ this._getOverwrittenModuleSourceTypes(module) || module.getSourceTypes()
621
+ );
622
+ }
623
+
624
+ /**
625
+ * @param {Module} module module
626
+ * @returns {Set<string> | undefined} source types
627
+ */
628
+ _getOverwrittenModuleSourceTypes(module) {
629
+ let newSet = false;
630
+ let sourceTypes;
631
+ for (const chunk of this.getModuleChunksIterable(module)) {
632
+ const cgc = this._getChunkGraphChunk(chunk);
633
+ if (cgc.sourceTypesByModule === undefined) return;
634
+ const st = cgc.sourceTypesByModule.get(module);
635
+ if (st === undefined) return;
636
+ if (!sourceTypes) {
637
+ sourceTypes = st;
638
+ continue;
639
+ } else if (!newSet) {
640
+ for (const type of st) {
641
+ if (!newSet) {
642
+ if (!sourceTypes.has(type)) {
643
+ newSet = true;
644
+ sourceTypes = new Set(sourceTypes);
645
+ sourceTypes.add(type);
646
+ }
647
+ } else {
648
+ sourceTypes.add(type);
649
+ }
650
+ }
651
+ } else {
652
+ for (const type of st) sourceTypes.add(type);
653
+ }
654
+ }
655
+
656
+ return sourceTypes;
657
+ }
658
+
576
659
  /**
577
660
  * @param {Chunk} chunk the chunk
578
661
  * @param {function(Module, Module): -1|0|1} comparator comparator function
@@ -593,7 +676,7 @@ class ChunkGraph {
593
676
  getOrderedChunkModulesIterableBySourceType(chunk, sourceType, comparator) {
594
677
  const cgc = this._getChunkGraphChunk(chunk);
595
678
  const modulesWithSourceType = cgc.modules
596
- .getFromUnorderedCache(modulesBySourceType)
679
+ .getFromUnorderedCache(cgc._modulesBySourceType)
597
680
  .get(sourceType);
598
681
  if (modulesWithSourceType === undefined) return undefined;
599
682
  modulesWithSourceType.sortWith(comparator);
@@ -1473,6 +1556,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1473
1556
  const graphHash = cgm.graphHashes.provide(runtime, () => {
1474
1557
  const hash = createHash(this._hashFunction);
1475
1558
  hash.update(`${cgm.id}${this.moduleGraph.isAsync(module)}`);
1559
+ const sourceTypes = this._getOverwrittenModuleSourceTypes(module);
1560
+ if (sourceTypes !== undefined) {
1561
+ for (const type of sourceTypes) hash.update(type);
1562
+ }
1476
1563
  this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime);
1477
1564
  return BigInt(`0x${/** @type {string} */ (hash.digest("hex"))}`);
1478
1565
  });
package/lib/ChunkGroup.js CHANGED
@@ -486,7 +486,7 @@ class ChunkGroup {
486
486
  for (const childGroup of this._children) {
487
487
  for (const key of Object.keys(childGroup.options)) {
488
488
  if (key.endsWith("Order")) {
489
- const name = key.substr(0, key.length - "Order".length);
489
+ const name = key.slice(0, key.length - "Order".length);
490
490
  let list = lists.get(name);
491
491
  if (list === undefined) {
492
492
  lists.set(name, (list = []));
@@ -1436,7 +1436,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1436
1436
  * @returns {void}
1437
1437
  */
1438
1438
  _processModuleDependencies(module, callback) {
1439
- /** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], originModule: Module|null}>} */
1439
+ /** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], context: string|undefined, originModule: Module|null}>} */
1440
1440
  const sortedDependencies = [];
1441
1441
 
1442
1442
  /** @type {DependenciesBlock} */
@@ -1668,6 +1668,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1668
1668
  sortedDependencies.push({
1669
1669
  factory: factoryCacheKey2,
1670
1670
  dependencies: list,
1671
+ context: dep.getContext(),
1671
1672
  originModule: module
1672
1673
  });
1673
1674
  }
@@ -3328,7 +3329,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3328
3329
  dependencyTemplates,
3329
3330
  runtimeTemplate,
3330
3331
  runtime,
3331
- codeGenerationResults: results
3332
+ codeGenerationResults: results,
3333
+ compilation: this
3332
3334
  });
3333
3335
  } catch (err) {
3334
3336
  errors.push(new CodeGenerationError(module, err));
@@ -3895,7 +3897,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3895
3897
  module,
3896
3898
  runtime,
3897
3899
  digest,
3898
- digest.substr(0, hashDigestLength)
3900
+ digest.slice(0, hashDigestLength)
3899
3901
  );
3900
3902
  statModulesFromCache++;
3901
3903
  continue;
@@ -3959,7 +3961,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3959
3961
  module,
3960
3962
  runtime,
3961
3963
  moduleHashDigest,
3962
- moduleHashDigest.substr(0, hashDigestLength)
3964
+ moduleHashDigest.slice(0, hashDigestLength)
3963
3965
  );
3964
3966
  return moduleHashDigest;
3965
3967
  }
@@ -4163,7 +4165,7 @@ This prevents using hashes of each other and should be avoided.`);
4163
4165
  );
4164
4166
  hash.update(chunkHashDigest);
4165
4167
  chunk.hash = chunkHashDigest;
4166
- chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4168
+ chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4167
4169
  const fullHashModules =
4168
4170
  chunkGraph.getChunkFullHashModulesIterable(chunk);
4169
4171
  if (fullHashModules) {
@@ -4190,7 +4192,7 @@ This prevents using hashes of each other and should be avoided.`);
4190
4192
  this.logger.time("hashing: hash digest");
4191
4193
  this.hooks.fullHash.call(hash);
4192
4194
  this.fullHash = /** @type {string} */ (hash.digest(hashDigest));
4193
- this.hash = this.fullHash.substr(0, hashDigestLength);
4195
+ this.hash = this.fullHash.slice(0, hashDigestLength);
4194
4196
  this.logger.timeEnd("hashing: hash digest");
4195
4197
 
4196
4198
  this.logger.time("hashing: process full hash modules");
@@ -4210,7 +4212,7 @@ This prevents using hashes of each other and should be avoided.`);
4210
4212
  module,
4211
4213
  chunk.runtime,
4212
4214
  moduleHashDigest,
4213
- moduleHashDigest.substr(0, hashDigestLength)
4215
+ moduleHashDigest.slice(0, hashDigestLength)
4214
4216
  );
4215
4217
  codeGenerationJobsMap.get(oldHash).get(module).hash = moduleHashDigest;
4216
4218
  }
@@ -4221,7 +4223,7 @@ This prevents using hashes of each other and should be avoided.`);
4221
4223
  chunkHash.digest(hashDigest)
4222
4224
  );
4223
4225
  chunk.hash = chunkHashDigest;
4224
- chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4226
+ chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4225
4227
  this.hooks.contentHash.call(chunk);
4226
4228
  }
4227
4229
  this.logger.timeEnd("hashing: process full hash modules");
package/lib/Compiler.js CHANGED
@@ -545,8 +545,21 @@ class Compiler {
545
545
  */
546
546
  runAsChild(callback) {
547
547
  const startTime = Date.now();
548
+
549
+ const finalCallback = (err, entries, compilation) => {
550
+ try {
551
+ callback(err, entries, compilation);
552
+ } catch (e) {
553
+ const err = new WebpackError(
554
+ `compiler.runAsChild callback error: ${e}`
555
+ );
556
+ err.details = e.stack;
557
+ this.parentCompilation.errors.push(err);
558
+ }
559
+ };
560
+
548
561
  this.compile((err, compilation) => {
549
- if (err) return callback(err);
562
+ if (err) return finalCallback(err);
550
563
 
551
564
  this.parentCompilation.children.push(compilation);
552
565
  for (const { name, source, info } of compilation.getAssets()) {
@@ -561,7 +574,7 @@ class Compiler {
561
574
  compilation.startTime = startTime;
562
575
  compilation.endTime = Date.now();
563
576
 
564
- return callback(null, entries, compilation);
577
+ return finalCallback(null, entries, compilation);
565
578
  });
566
579
  }
567
580
 
@@ -596,7 +609,7 @@ class Compiler {
596
609
  let immutable = info.immutable;
597
610
  const queryStringIdx = targetFile.indexOf("?");
598
611
  if (queryStringIdx >= 0) {
599
- targetFile = targetFile.substr(0, queryStringIdx);
612
+ targetFile = targetFile.slice(0, queryStringIdx);
600
613
  // We may remove the hash, which is in the query string
601
614
  // So we recheck if the file is immutable
602
615
  // This doesn't cover all cases, but immutable is only a performance optimization anyway
@@ -324,7 +324,7 @@ class ConstPlugin {
324
324
  }
325
325
  } else if (expression.operator === "??") {
326
326
  const param = parser.evaluateExpression(expression.left);
327
- const keepRight = param && param.asNullish();
327
+ const keepRight = param.asNullish();
328
328
  if (typeof keepRight === "boolean") {
329
329
  // ------------------------------------------
330
330
  //
@@ -407,7 +407,7 @@ class ConstPlugin {
407
407
  const expression = optionalExpressionsStack.pop();
408
408
  const evaluated = parser.evaluateExpression(expression);
409
409
 
410
- if (evaluated && evaluated.asNullish()) {
410
+ if (evaluated.asNullish()) {
411
411
  // ------------------------------------------
412
412
  //
413
413
  // Given the following code:
@@ -19,7 +19,11 @@ const {
19
19
  keepOriginalOrder,
20
20
  compareModulesById
21
21
  } = require("./util/comparators");
22
- const { contextify, parseResource } = require("./util/identifier");
22
+ const {
23
+ contextify,
24
+ parseResource,
25
+ makePathsRelative
26
+ } = require("./util/identifier");
23
27
  const makeSerializable = require("./util/makeSerializable");
24
28
 
25
29
  /** @typedef {import("webpack-sources").Source} Source */
@@ -1066,9 +1070,21 @@ module.exports = webpackEmptyAsyncContext;`;
1066
1070
  return this.getSourceForEmptyContext(id, runtimeTemplate);
1067
1071
  }
1068
1072
 
1069
- getSource(sourceString) {
1073
+ /**
1074
+ * @param {string} sourceString source content
1075
+ * @param {Compilation=} compilation the compilation
1076
+ * @returns {Source} generated source
1077
+ */
1078
+ getSource(sourceString, compilation) {
1070
1079
  if (this.useSourceMap || this.useSimpleSourceMap) {
1071
- return new OriginalSource(sourceString, this.identifier());
1080
+ return new OriginalSource(
1081
+ sourceString,
1082
+ `webpack://${makePathsRelative(
1083
+ (compilation && compilation.compiler.context) || "",
1084
+ this.identifier(),
1085
+ compilation && compilation.compiler.root
1086
+ )}`
1087
+ );
1072
1088
  }
1073
1089
  return new RawSource(sourceString);
1074
1090
  }
@@ -1078,16 +1094,23 @@ module.exports = webpackEmptyAsyncContext;`;
1078
1094
  * @returns {CodeGenerationResult} result
1079
1095
  */
1080
1096
  codeGeneration(context) {
1081
- const { chunkGraph } = context;
1097
+ const { chunkGraph, compilation } = context;
1082
1098
  const sources = new Map();
1083
1099
  sources.set(
1084
1100
  "javascript",
1085
- this.getSource(this.getSourceString(this.options.mode, context))
1101
+ this.getSource(
1102
+ this.getSourceString(this.options.mode, context),
1103
+ compilation
1104
+ )
1086
1105
  );
1087
1106
  const set = new Set();
1088
- const allDeps = /** @type {ContextElementDependency[]} */ (
1089
- this.dependencies.concat(this.blocks.map(b => b.dependencies[0]))
1090
- );
1107
+ const allDeps =
1108
+ this.dependencies.length > 0
1109
+ ? /** @type {ContextElementDependency[]} */ (this.dependencies).slice()
1110
+ : [];
1111
+ for (const block of this.blocks)
1112
+ for (const dep of block.dependencies)
1113
+ allDeps.push(/** @type {ContextElementDependency} */ (dep));
1091
1114
  set.add(RuntimeGlobals.module);
1092
1115
  set.add(RuntimeGlobals.hasOwnProperty);
1093
1116
  if (allDeps.length > 0) {
@@ -128,7 +128,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
128
128
  loadersPrefix = "";
129
129
  const idx = request.lastIndexOf("!");
130
130
  if (idx >= 0) {
131
- let loadersRequest = request.substr(0, idx + 1);
131
+ let loadersRequest = request.slice(0, idx + 1);
132
132
  let i;
133
133
  for (
134
134
  i = 0;
@@ -138,7 +138,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
138
138
  loadersPrefix += "!";
139
139
  }
140
140
  loadersRequest = loadersRequest
141
- .substr(i)
141
+ .slice(i)
142
142
  .replace(/!+$/, "")
143
143
  .replace(/!!+/g, "!");
144
144
  if (loadersRequest === "") {
@@ -146,7 +146,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
146
146
  } else {
147
147
  loaders = loadersRequest.split("!");
148
148
  }
149
- resource = request.substr(idx + 1);
149
+ resource = request.slice(idx + 1);
150
150
  } else {
151
151
  loaders = [];
152
152
  resource = request;
@@ -292,7 +292,6 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
292
292
  } = options;
293
293
  if (!regExp || !resource) return callback(null, []);
294
294
 
295
- let severalContexts = false;
296
295
  const addDirectoryChecked = (ctx, directory, visited, callback) => {
297
296
  fs.realpath(directory, (err, realPath) => {
298
297
  if (err) return callback(err);
@@ -348,7 +347,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
348
347
  const obj = {
349
348
  context: ctx,
350
349
  request:
351
- "." + subResource.substr(ctx.length).replace(/\\/g, "/")
350
+ "." + subResource.slice(ctx.length).replace(/\\/g, "/")
352
351
  };
353
352
 
354
353
  this.hooks.alternativeRequests.callAsync(
@@ -359,15 +358,13 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
359
358
  alternatives = alternatives
360
359
  .filter(obj => regExp.test(obj.request))
361
360
  .map(obj => {
362
- const request = severalContexts
363
- ? join(fs, obj.context, obj.request)
364
- : obj.request;
365
361
  const dep = new ContextElementDependency(
366
- request + resourceQuery + resourceFragment,
362
+ `${obj.request}${resourceQuery}${resourceFragment}`,
367
363
  obj.request,
368
364
  typePrefix,
369
365
  category,
370
- referencedExports
366
+ referencedExports,
367
+ obj.context
371
368
  );
372
369
  dep.optional = true;
373
370
  return dep;
@@ -414,7 +411,6 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
414
411
  if (typeof resource === "string") {
415
412
  visitResource(resource, callback);
416
413
  } else {
417
- severalContexts = true;
418
414
  asyncLib.map(resource, visitResource, (err, result) => {
419
415
  if (err) return callback(err);
420
416
 
@@ -29,7 +29,7 @@ class DelegatedModuleFactoryPlugin {
29
29
  const [dependency] = data.dependencies;
30
30
  const { request } = dependency;
31
31
  if (request && request.startsWith(`${scope}/`)) {
32
- const innerRequest = "." + request.substr(scope.length);
32
+ const innerRequest = "." + request.slice(scope.length);
33
33
  let resolved;
34
34
  if (innerRequest in this.options.content) {
35
35
  resolved = this.options.content[innerRequest];
package/lib/Dependency.js CHANGED
@@ -182,6 +182,13 @@ class Dependency {
182
182
  this._loc = undefined;
183
183
  }
184
184
 
185
+ /**
186
+ * @returns {string | undefined} a request context
187
+ */
188
+ getContext() {
189
+ return undefined;
190
+ }
191
+
185
192
  /**
186
193
  * @returns {string | null} an identifier to merge equal requests
187
194
  */
@@ -43,8 +43,8 @@ exports.cutOffMessage = (stack, message) => {
43
43
  if (nextLine === -1) {
44
44
  return stack === message ? "" : stack;
45
45
  } else {
46
- const firstLine = stack.substr(0, nextLine);
47
- return firstLine === message ? stack.substr(nextLine + 1) : stack;
46
+ const firstLine = stack.slice(0, nextLine);
47
+ return firstLine === message ? stack.slice(nextLine + 1) : stack;
48
48
  }
49
49
  };
50
50
 
@@ -584,7 +584,7 @@ class ExportsInfo {
584
584
  if (info.exportsInfo && name.length > 1) {
585
585
  return info.exportsInfo.isExportProvided(name.slice(1));
586
586
  }
587
- return info.provided;
587
+ return info.provided ? name.length === 1 || undefined : info.provided;
588
588
  }
589
589
  const info = this.getReadOnlyExportInfo(name);
590
590
  return info.provided;
@@ -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
  }
@@ -6,6 +6,7 @@
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");
10
11
  const AsyncQueue = require("./util/AsyncQueue");
11
12
  const StackedCacheMap = require("./util/StackedCacheMap");
@@ -22,6 +23,8 @@ const processAsyncTree = require("./util/processAsyncTree");
22
23
 
23
24
  const supportsEsm = +process.versions.modules >= 83;
24
25
 
26
+ const builtinModules = new Set(nodeModule.builtinModules);
27
+
25
28
  let FS_ACCURACY = 2000;
26
29
 
27
30
  const EMPTY_SET = new Set();
@@ -1673,6 +1676,11 @@ class FileSystemInfo {
1673
1676
  // e.g. import.meta
1674
1677
  continue;
1675
1678
  }
1679
+
1680
+ // we should not track Node.js build dependencies
1681
+ if (dependency.startsWith("node:")) continue;
1682
+ if (builtinModules.has(dependency)) continue;
1683
+
1676
1684
  push({
1677
1685
  type: RBDT_RESOLVE_ESM_FILE,
1678
1686
  context,
@@ -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
@@ -49,6 +49,7 @@ const makeSerializable = require("./util/makeSerializable");
49
49
  * @property {string=} type the type of source that should be generated
50
50
  */
51
51
 
52
+ // TODO webpack 6: compilation will be required in CodeGenerationContext
52
53
  /**
53
54
  * @typedef {Object} CodeGenerationContext
54
55
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -58,6 +59,8 @@ const makeSerializable = require("./util/makeSerializable");
58
59
  * @property {RuntimeSpec} runtime the runtimes code should be generated for
59
60
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
60
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
61
64
  */
62
65
 
63
66
  /**
@@ -47,7 +47,7 @@ const getAfter = (strFn, token) => {
47
47
  return () => {
48
48
  const str = strFn();
49
49
  const idx = str.indexOf(token);
50
- return idx < 0 ? "" : str.substr(idx);
50
+ return idx < 0 ? "" : str.slice(idx);
51
51
  };
52
52
  };
53
53
 
@@ -55,7 +55,7 @@ const getBefore = (strFn, token) => {
55
55
  return () => {
56
56
  const str = strFn();
57
57
  const idx = str.lastIndexOf(token);
58
- return idx < 0 ? "" : str.substr(0, idx);
58
+ return idx < 0 ? "" : str.slice(0, idx);
59
59
  };
60
60
  };
61
61
 
@@ -64,7 +64,7 @@ const getHash = (strFn, hashFunction) => {
64
64
  const hash = createHash(hashFunction);
65
65
  hash.update(strFn());
66
66
  const digest = /** @type {string} */ (hash.digest("hex"));
67
- return digest.substr(0, 4);
67
+ return digest.slice(0, 4);
68
68
  };
69
69
  };
70
70