webpack 5.70.0 → 5.71.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 (42) hide show
  1. package/hot/poll.js +1 -1
  2. package/hot/signal.js +1 -1
  3. package/lib/Chunk.js +1 -1
  4. package/lib/ChunkGroup.js +1 -1
  5. package/lib/Compilation.js +10 -8
  6. package/lib/Compiler.js +16 -3
  7. package/lib/ConstPlugin.js +2 -2
  8. package/lib/ContextModule.js +31 -8
  9. package/lib/ContextModuleFactory.js +7 -11
  10. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  11. package/lib/Dependency.js +7 -0
  12. package/lib/ErrorHelpers.js +2 -2
  13. package/lib/ExternalModuleFactoryPlugin.js +4 -4
  14. package/lib/FileSystemInfo.js +8 -0
  15. package/lib/LoaderOptionsPlugin.js +1 -1
  16. package/lib/Module.js +2 -0
  17. package/lib/ModuleFilenameHelpers.js +3 -3
  18. package/lib/NormalModule.js +2 -2
  19. package/lib/NormalModuleFactory.js +2 -2
  20. package/lib/RuntimePlugin.js +18 -0
  21. package/lib/config/defaults.js +9 -1
  22. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  23. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  24. package/lib/dependencies/ContextElementDependency.js +33 -1
  25. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  26. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +127 -43
  27. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -8
  28. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  29. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  30. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  31. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  32. package/lib/ids/HashedModuleIdsPlugin.js +2 -2
  33. package/lib/ids/IdHelpers.js +1 -1
  34. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  35. package/lib/javascript/JavascriptParser.js +66 -40
  36. package/lib/library/UmdLibraryPlugin.js +5 -3
  37. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  38. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
  39. package/lib/util/internalSerializables.js +2 -0
  40. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  41. package/package.json +1 -1
  42. package/types.d.ts +21 -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",
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/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
 
@@ -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,7 @@ 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
61
63
  */
62
64
 
63
65
  /**
@@ -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
 
@@ -375,7 +375,7 @@ class NormalModule extends Module {
375
375
  nameForCondition() {
376
376
  const resource = this.matchResource || this.resource;
377
377
  const idx = resource.indexOf("?");
378
- if (idx >= 0) return resource.substr(0, idx);
378
+ if (idx >= 0) return resource.slice(0, idx);
379
379
  return resource;
380
380
  }
381
381
 
@@ -558,7 +558,7 @@ class NormalModule extends Module {
558
558
  let { options } = loader;
559
559
 
560
560
  if (typeof options === "string") {
561
- if (options.substr(0, 1) === "{" && options.substr(-1) === "}") {
561
+ if (options.startsWith("{") && options.endsWith("}")) {
562
562
  try {
563
563
  options = parseJson(options);
564
564
  } catch (e) {
@@ -379,7 +379,7 @@ class NormalModuleFactory extends ModuleFactory {
379
379
  resource: matchResource,
380
380
  ...cacheParseResource(matchResource)
381
381
  };
382
- requestWithoutMatchResource = request.substr(
382
+ requestWithoutMatchResource = request.slice(
383
383
  matchResourceMatch[0].length
384
384
  );
385
385
  }
@@ -437,7 +437,7 @@ class NormalModuleFactory extends ModuleFactory {
437
437
  try {
438
438
  for (const item of loaders) {
439
439
  if (typeof item.options === "string" && item.options[0] === "?") {
440
- const ident = item.options.substr(1);
440
+ const ident = item.options.slice(1);
441
441
  if (ident === "[[missing ident]]") {
442
442
  throw new Error(
443
443
  "No ident is provided by referenced loader. " +
@@ -11,6 +11,7 @@ const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirement
11
11
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
12
12
  const AsyncModuleRuntimeModule = require("./runtime/AsyncModuleRuntimeModule");
13
13
  const AutoPublicPathRuntimeModule = require("./runtime/AutoPublicPathRuntimeModule");
14
+ const BaseUriRuntimeModule = require("./runtime/BaseUriRuntimeModule");
14
15
  const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule");
15
16
  const CompatRuntimeModule = require("./runtime/CompatRuntimeModule");
16
17
  const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule");
@@ -96,6 +97,15 @@ class RuntimePlugin {
96
97
  */
97
98
  apply(compiler) {
98
99
  compiler.hooks.compilation.tap("RuntimePlugin", compilation => {
100
+ const globalChunkLoading = compilation.outputOptions.chunkLoading;
101
+ const isChunkLoadingDisabledForChunk = chunk => {
102
+ const options = chunk.getEntryOptions();
103
+ const chunkLoading =
104
+ options && options.chunkLoading !== undefined
105
+ ? options.chunkLoading
106
+ : globalChunkLoading;
107
+ return chunkLoading === false;
108
+ };
99
109
  compilation.dependencyTemplates.set(
100
110
  RuntimeRequirementsDependency,
101
111
  new RuntimeRequirementsDependency.Template()
@@ -413,6 +423,14 @@ class RuntimePlugin {
413
423
  );
414
424
  return true;
415
425
  });
426
+ compilation.hooks.runtimeRequirementInTree
427
+ .for(RuntimeGlobals.baseURI)
428
+ .tap("RuntimePlugin", chunk => {
429
+ if (isChunkLoadingDisabledForChunk(chunk)) {
430
+ compilation.addRuntimeModule(chunk, new BaseUriRuntimeModule());
431
+ return true;
432
+ }
433
+ });
416
434
  // TODO webpack 6: remove CompatRuntimeModule
417
435
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
418
436
  "RuntimePlugin",
@@ -715,7 +715,15 @@ const applyOutputDefaults = (
715
715
  };
716
716
 
717
717
  F(output, "uniqueName", () => {
718
- const libraryName = getLibraryName(output.library);
718
+ const libraryName = getLibraryName(output.library).replace(
719
+ /^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g,
720
+ (m, a, d1, d2, b, c) => {
721
+ const content = a || b || c;
722
+ return content.startsWith("\\") && content.endsWith("\\")
723
+ ? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}`
724
+ : "";
725
+ }
726
+ );
719
727
  if (libraryName) return libraryName;
720
728
  const pkgPath = path.resolve(context, "package.json");
721
729
  try {
@@ -201,7 +201,7 @@ class CommonJsExportsParserPlugin {
201
201
  if (expr.arguments[1].type === "SpreadElement") return;
202
202
  if (expr.arguments[2].type === "SpreadElement") return;
203
203
  const exportsArg = parser.evaluateExpression(expr.arguments[0]);
204
- if (!exportsArg || !exportsArg.isIdentifier()) return;
204
+ if (!exportsArg.isIdentifier()) return;
205
205
  if (
206
206
  exportsArg.identifier !== "exports" &&
207
207
  exportsArg.identifier !== "module.exports" &&
@@ -210,7 +210,6 @@ class CommonJsExportsParserPlugin {
210
210
  return;
211
211
  }
212
212
  const propertyArg = parser.evaluateExpression(expr.arguments[1]);
213
- if (!propertyArg) return;
214
213
  const property = propertyArg.asString();
215
214
  if (typeof property !== "string") return;
216
215
  enableStructuredExports();
@@ -28,8 +28,8 @@ const splitContextFromPrefix = prefix => {
28
28
  const idx = prefix.lastIndexOf("/");
29
29
  let context = ".";
30
30
  if (idx >= 0) {
31
- context = prefix.substr(0, idx);
32
- prefix = `.${prefix.substr(idx)}`;
31
+ context = prefix.slice(0, idx);
32
+ prefix = `.${prefix.slice(idx)}`;
33
33
  }
34
34
  return {
35
35
  context,
@@ -14,11 +14,27 @@ const ModuleDependency = require("./ModuleDependency");
14
14
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
15
15
 
16
16
  class ContextElementDependency extends ModuleDependency {
17
- constructor(request, userRequest, typePrefix, category, referencedExports) {
17
+ /**
18
+ * @param {string} request request
19
+ * @param {string|undefined} userRequest user request
20
+ * @param {string} typePrefix type prefix
21
+ * @param {string} category category
22
+ * @param {string[][]=} referencedExports referenced exports
23
+ * @param {string=} context context
24
+ */
25
+ constructor(
26
+ request,
27
+ userRequest,
28
+ typePrefix,
29
+ category,
30
+ referencedExports,
31
+ context
32
+ ) {
18
33
  super(request);
19
34
  this.referencedExports = referencedExports;
20
35
  this._typePrefix = typePrefix;
21
36
  this._category = category;
37
+ this._context = context || undefined;
22
38
 
23
39
  if (userRequest) {
24
40
  this.userRequest = userRequest;
@@ -33,6 +49,20 @@ class ContextElementDependency extends ModuleDependency {
33
49
  return "context element";
34
50
  }
35
51
 
52
+ /**
53
+ * @returns {string | undefined} a request context
54
+ */
55
+ getContext() {
56
+ return this._context;
57
+ }
58
+
59
+ /**
60
+ * @returns {string | null} an identifier to merge equal requests
61
+ */
62
+ getResourceIdentifier() {
63
+ return `context${this._context || ""}|${super.getResourceIdentifier()}`;
64
+ }
65
+
36
66
  get category() {
37
67
  return this._category;
38
68
  }
@@ -56,6 +86,7 @@ class ContextElementDependency extends ModuleDependency {
56
86
  const { write } = context;
57
87
  write(this._typePrefix);
58
88
  write(this._category);
89
+ write(this._context);
59
90
  write(this.referencedExports);
60
91
  super.serialize(context);
61
92
  }
@@ -64,6 +95,7 @@ class ContextElementDependency extends ModuleDependency {
64
95
  const { read } = context;
65
96
  this._typePrefix = read();
66
97
  this._category = read();
98
+ this._context = read();
67
99
  this.referencedExports = read();
68
100
  super.deserialize(context);
69
101
  }