webpack 5.37.0 → 5.39.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 (139) hide show
  1. package/README.md +5 -8
  2. package/bin/webpack.js +20 -5
  3. package/lib/AsyncDependencyToInitialChunkError.js +0 -2
  4. package/lib/CacheFacade.js +3 -3
  5. package/lib/CaseSensitiveModulesWarning.js +0 -2
  6. package/lib/Chunk.js +8 -5
  7. package/lib/ChunkRenderError.js +0 -2
  8. package/lib/CodeGenerationError.js +0 -2
  9. package/lib/CommentCompilationWarning.js +0 -2
  10. package/lib/Compilation.js +43 -55
  11. package/lib/Compiler.js +7 -4
  12. package/lib/ConcatenationScope.js +2 -1
  13. package/lib/ConcurrentCompilationError.js +0 -2
  14. package/lib/ContextModule.js +5 -4
  15. package/lib/ContextModuleFactory.js +3 -1
  16. package/lib/ContextReplacementPlugin.js +4 -3
  17. package/lib/DefinePlugin.js +16 -12
  18. package/lib/DllReferencePlugin.js +0 -2
  19. package/lib/EntryPlugin.js +3 -3
  20. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  21. package/lib/ExportsInfo.js +20 -13
  22. package/lib/FileSystemInfo.js +24 -30
  23. package/lib/FlagDependencyExportsPlugin.js +8 -7
  24. package/lib/FlagDependencyUsagePlugin.js +2 -4
  25. package/lib/HarmonyLinkingError.js +0 -2
  26. package/lib/HookWebpackError.js +0 -1
  27. package/lib/HotModuleReplacementPlugin.js +27 -32
  28. package/lib/InvalidDependenciesModuleWarning.js +0 -2
  29. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  30. package/lib/MainTemplate.js +2 -3
  31. package/lib/ModuleBuildError.js +0 -2
  32. package/lib/ModuleDependencyError.js +0 -2
  33. package/lib/ModuleDependencyWarning.js +0 -2
  34. package/lib/ModuleError.js +0 -2
  35. package/lib/ModuleFilenameHelpers.js +4 -2
  36. package/lib/ModuleGraphConnection.js +6 -2
  37. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  38. package/lib/ModuleNotFoundError.js +0 -2
  39. package/lib/ModuleParseError.js +0 -2
  40. package/lib/ModuleRestoreError.js +0 -2
  41. package/lib/ModuleStoreError.js +0 -2
  42. package/lib/ModuleWarning.js +0 -2
  43. package/lib/MultiCompiler.js +31 -27
  44. package/lib/NoModeWarning.js +0 -2
  45. package/lib/NormalModule.js +26 -8
  46. package/lib/NormalModuleFactory.js +2 -0
  47. package/lib/RecordIdsPlugin.js +5 -4
  48. package/lib/ResolverFactory.js +10 -7
  49. package/lib/SourceMapDevToolPlugin.js +13 -14
  50. package/lib/Template.js +4 -2
  51. package/lib/UnsupportedFeatureWarning.js +0 -2
  52. package/lib/WarnDeprecatedOptionPlugin.js +0 -2
  53. package/lib/Watching.js +91 -47
  54. package/lib/WebpackError.js +0 -2
  55. package/lib/asset/AssetGenerator.js +46 -29
  56. package/lib/asset/AssetModulesPlugin.js +1 -1
  57. package/lib/buildChunkGraph.js +21 -21
  58. package/lib/cache/PackFileCacheStrategy.js +12 -9
  59. package/lib/config/defaults.js +21 -10
  60. package/lib/config/normalization.js +8 -7
  61. package/lib/config/target.js +7 -2
  62. package/lib/debug/ProfilingPlugin.js +4 -3
  63. package/lib/dependencies/AMDRequireDependency.js +3 -3
  64. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  65. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  66. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  67. package/lib/dependencies/CommonJsPlugin.js +8 -7
  68. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  69. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  70. package/lib/dependencies/ContextElementDependency.js +6 -1
  71. package/lib/dependencies/CriticalDependencyWarning.js +0 -2
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  75. package/lib/dependencies/ImportDependency.js +3 -3
  76. package/lib/dependencies/ImportParserPlugin.js +3 -4
  77. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  78. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  79. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +0 -2
  80. package/lib/dependencies/SystemPlugin.js +0 -2
  81. package/lib/dependencies/WorkerDependency.js +6 -6
  82. package/lib/dependencies/WorkerPlugin.js +18 -19
  83. package/lib/errors/BuildCycleError.js +0 -1
  84. package/lib/hmr/LazyCompilationPlugin.js +9 -5
  85. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  86. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  87. package/lib/index.js +5 -3
  88. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  89. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  90. package/lib/javascript/JavascriptGenerator.js +3 -1
  91. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  92. package/lib/javascript/JavascriptParser.js +10 -8
  93. package/lib/library/AssignLibraryPlugin.js +4 -2
  94. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  95. package/lib/node/NodeWatchFileSystem.js +19 -4
  96. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  97. package/lib/optimize/ConcatenatedModule.js +31 -27
  98. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  99. package/lib/optimize/InnerGraph.js +9 -11
  100. package/lib/optimize/InnerGraphPlugin.js +3 -1
  101. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  102. package/lib/optimize/RealContentHashPlugin.js +14 -16
  103. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  104. package/lib/optimize/SplitChunksPlugin.js +13 -15
  105. package/lib/performance/AssetsOverSizeLimitWarning.js +0 -2
  106. package/lib/performance/EntrypointsOverSizeLimitWarning.js +0 -2
  107. package/lib/performance/NoAsyncChunksWarning.js +0 -2
  108. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  109. package/lib/runtime/LoadScriptRuntimeModule.js +2 -3
  110. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  111. package/lib/schemes/DataUriPlugin.js +21 -2
  112. package/lib/serialization/BinaryMiddleware.js +5 -3
  113. package/lib/serialization/FileMiddleware.js +3 -1
  114. package/lib/serialization/ObjectMiddleware.js +11 -7
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +7 -7
  116. package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
  117. package/lib/stats/StatsFactory.js +2 -1
  118. package/lib/stats/StatsPrinter.js +3 -3
  119. package/lib/util/LazyBucketSortedSet.js +3 -3
  120. package/lib/util/cleverMerge.js +3 -1
  121. package/lib/util/comparators.js +13 -13
  122. package/lib/util/createHash.js +5 -4
  123. package/lib/util/identifier.js +2 -1
  124. package/lib/util/serialization.js +108 -59
  125. package/lib/validateSchema.js +5 -3
  126. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  127. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +0 -2
  128. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  129. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  130. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +0 -2
  131. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  132. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  133. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  134. package/lib/webpack.js +11 -7
  135. package/package.json +9 -6
  136. package/schemas/WebpackOptions.check.js +1 -1
  137. package/schemas/WebpackOptions.json +76 -60
  138. package/types.d.ts +112 -262
  139. package/lib/util/DataURI.js +0 -32
@@ -519,7 +519,8 @@ const visitModules = (
519
519
  if (skipConnectionBuffer.length > 0) {
520
520
  let { skippedModuleConnections } = chunkGroupInfo;
521
521
  if (skippedModuleConnections === undefined) {
522
- chunkGroupInfo.skippedModuleConnections = skippedModuleConnections = new Set();
522
+ chunkGroupInfo.skippedModuleConnections = skippedModuleConnections =
523
+ new Set();
523
524
  }
524
525
  for (let i = skipConnectionBuffer.length - 1; i >= 0; i--) {
525
526
  skippedModuleConnections.add(skipConnectionBuffer[i]);
@@ -695,7 +696,8 @@ const visitModules = (
695
696
  let resultingAvailableModules;
696
697
  if (minAvailableModules.size > minAvailableModules.plus.size) {
697
698
  // resultingAvailableModules = (modules of chunk) + (minAvailableModules + minAvailableModules.plus)
698
- resultingAvailableModules = /** @type {Set<Module> & {plus: Set<Module>}} */ (new Set());
699
+ resultingAvailableModules =
700
+ /** @type {Set<Module> & {plus: Set<Module>}} */ (new Set());
699
701
  for (const module of minAvailableModules.plus)
700
702
  minAvailableModules.add(module);
701
703
  minAvailableModules.plus = EMPTY_SET;
@@ -703,9 +705,10 @@ const visitModules = (
703
705
  chunkGroupInfo.minAvailableModulesOwned = false;
704
706
  } else {
705
707
  // resultingAvailableModules = (minAvailableModules + modules of chunk) + (minAvailableModules.plus)
706
- resultingAvailableModules = /** @type {Set<Module> & {plus: Set<Module>}} */ (new Set(
707
- minAvailableModules
708
- ));
708
+ resultingAvailableModules =
709
+ /** @type {Set<Module> & {plus: Set<Module>}} */ (
710
+ new Set(minAvailableModules)
711
+ );
709
712
  resultingAvailableModules.plus = minAvailableModules.plus;
710
713
  }
711
714
 
@@ -715,7 +718,8 @@ const visitModules = (
715
718
  resultingAvailableModules.add(m);
716
719
  }
717
720
  }
718
- return (chunkGroupInfo.resultingAvailableModules = resultingAvailableModules);
721
+ return (chunkGroupInfo.resultingAvailableModules =
722
+ resultingAvailableModules);
719
723
  };
720
724
 
721
725
  const processConnectQueue = () => {
@@ -732,9 +736,8 @@ const visitModules = (
732
736
  }
733
737
 
734
738
  // 2. Calculate resulting available modules
735
- const resultingAvailableModules = calculateResultingAvailableModules(
736
- chunkGroupInfo
737
- );
739
+ const resultingAvailableModules =
740
+ calculateResultingAvailableModules(chunkGroupInfo);
738
741
 
739
742
  const runtime = chunkGroupInfo.runtime;
740
743
 
@@ -800,9 +803,8 @@ const visitModules = (
800
803
  if (!availableModules.has(m) && !availableModules.plus.has(m)) {
801
804
  // We can't remove modules from the plus part
802
805
  // so we need to merge plus into the normal part to allow modifying it
803
- const iterator = cachedMinAvailableModules.plus[
804
- Symbol.iterator
805
- ]();
806
+ const iterator =
807
+ cachedMinAvailableModules.plus[Symbol.iterator]();
806
808
  // fast forward add all modules until m
807
809
  /** @type {IteratorResult<Module>} */
808
810
  let it;
@@ -951,13 +953,12 @@ const visitModules = (
951
953
  statForkedMergedModulesCountPlus += availableModules.plus.size;
952
954
  // construct a new Set as intersection of cachedMinAvailableModules and availableModules
953
955
  // we already know that all modules directly from cachedMinAvailableModules are in availableModules too
954
- const newSet = /** @type {ModuleSetPlus} */ (new Set(
955
- cachedMinAvailableModules
956
- ));
956
+ const newSet = /** @type {ModuleSetPlus} */ (
957
+ new Set(cachedMinAvailableModules)
958
+ );
957
959
  newSet.plus = EMPTY_SET;
958
- const iterator = cachedMinAvailableModules.plus[
959
- Symbol.iterator
960
- ]();
960
+ const iterator =
961
+ cachedMinAvailableModules.plus[Symbol.iterator]();
961
962
  // fast forward add all modules until m
962
963
  /** @type {IteratorResult<Module>} */
963
964
  let it;
@@ -1018,9 +1019,8 @@ const visitModules = (
1018
1019
  };
1019
1020
  // combine minAvailableModules from all resultingAvailableModules
1020
1021
  for (const source of info.availableSources) {
1021
- const resultingAvailableModules = calculateResultingAvailableModules(
1022
- source
1023
- );
1022
+ const resultingAvailableModules =
1023
+ calculateResultingAvailableModules(source);
1024
1024
  mergeSet(resultingAvailableModules);
1025
1025
  mergeSet(resultingAvailableModules.plus);
1026
1026
  }
@@ -1041,7 +1041,8 @@ class PackFileCacheStrategy {
1041
1041
  if (newBuildDependencies)
1042
1042
  this.newBuildDependencies.addAll(newBuildDependencies);
1043
1043
  this.resolveResults = resolveResults;
1044
- this.resolveBuildDependenciesSnapshot = resolveBuildDependenciesSnapshot;
1044
+ this.resolveBuildDependenciesSnapshot =
1045
+ resolveBuildDependenciesSnapshot;
1045
1046
  return pack;
1046
1047
  }
1047
1048
  return new Pack(logger, this.maxAge);
@@ -1163,10 +1164,11 @@ class PackFileCacheStrategy {
1163
1164
  );
1164
1165
  }
1165
1166
  if (this.resolveBuildDependenciesSnapshot) {
1166
- this.resolveBuildDependenciesSnapshot = this.fileSystemInfo.mergeSnapshots(
1167
- this.resolveBuildDependenciesSnapshot,
1168
- snapshot
1169
- );
1167
+ this.resolveBuildDependenciesSnapshot =
1168
+ this.fileSystemInfo.mergeSnapshots(
1169
+ this.resolveBuildDependenciesSnapshot,
1170
+ snapshot
1171
+ );
1170
1172
  } else {
1171
1173
  this.resolveBuildDependenciesSnapshot = snapshot;
1172
1174
  }
@@ -1194,10 +1196,11 @@ class PackFileCacheStrategy {
1194
1196
  this.logger.debug("Captured build dependencies");
1195
1197
 
1196
1198
  if (this.buildSnapshot) {
1197
- this.buildSnapshot = this.fileSystemInfo.mergeSnapshots(
1198
- this.buildSnapshot,
1199
- snapshot
1200
- );
1199
+ this.buildSnapshot =
1200
+ this.fileSystemInfo.mergeSnapshots(
1201
+ this.buildSnapshot,
1202
+ snapshot
1203
+ );
1201
1204
  } else {
1202
1205
  this.buildSnapshot = snapshot;
1203
1206
  }
@@ -318,9 +318,10 @@ const applyCacheDefaults = (cache, { name, mode, development }) => {
318
318
  const applySnapshotDefaults = (snapshot, { production }) => {
319
319
  A(snapshot, "managedPaths", () => {
320
320
  if (process.versions.pnp === "3") {
321
- const match = /^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
322
- require.resolve("watchpack")
323
- );
321
+ const match =
322
+ /^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
323
+ require.resolve("watchpack")
324
+ );
324
325
  if (match) {
325
326
  return [path.resolve(match[1], "unplugged")];
326
327
  }
@@ -337,16 +338,18 @@ const applySnapshotDefaults = (snapshot, { production }) => {
337
338
  });
338
339
  A(snapshot, "immutablePaths", () => {
339
340
  if (process.versions.pnp === "1") {
340
- const match = /^(.+?[\\/]v4)[\\/]npm-watchpack-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec(
341
- require.resolve("watchpack")
342
- );
341
+ const match =
342
+ /^(.+?[\\/]v4)[\\/]npm-watchpack-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec(
343
+ require.resolve("watchpack")
344
+ );
343
345
  if (match) {
344
346
  return [match[1]];
345
347
  }
346
348
  } else if (process.versions.pnp === "3") {
347
- const match = /^(.+?)[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
348
- require.resolve("watchpack")
349
- );
349
+ const match =
350
+ /^(.+?)[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
351
+ require.resolve("watchpack")
352
+ );
350
353
  if (match) {
351
354
  return [match[1]];
352
355
  }
@@ -475,7 +478,15 @@ const applyModuleDefaults = (
475
478
  },
476
479
  {
477
480
  dependency: "url",
478
- type: "asset/resource"
481
+ oneOf: [
482
+ {
483
+ scheme: /^data$/,
484
+ type: "asset/inline"
485
+ },
486
+ {
487
+ type: "asset/resource"
488
+ }
489
+ ]
479
490
  }
480
491
  ];
481
492
  if (asyncWebAssembly) {
@@ -92,9 +92,9 @@ const keyedNestedConfig = (value, fn, customKeys) => {
92
92
  ? {}
93
93
  : Object.keys(value).reduce(
94
94
  (obj, key) => (
95
- (obj[key] = (customKeys && key in customKeys
96
- ? customKeys[key]
97
- : fn)(value[key])),
95
+ (obj[key] = (
96
+ customKeys && key in customKeys ? customKeys[key] : fn
97
+ )(value[key])),
98
98
  obj
99
99
  ),
100
100
  /** @type {Record<string, R>} */ ({})
@@ -129,6 +129,7 @@ const getNormalizedWebpackOptions = config => {
129
129
  case "filesystem":
130
130
  return {
131
131
  type: "filesystem",
132
+ allowCollectingMemory: cache.allowCollectingMemory,
132
133
  maxMemoryGenerations: cache.maxMemoryGenerations,
133
134
  maxAge: cache.maxAge,
134
135
  profile: cache.profile,
@@ -163,10 +164,10 @@ const getNormalizedWebpackOptions = config => {
163
164
  config.entry === undefined
164
165
  ? { main: {} }
165
166
  : typeof config.entry === "function"
166
- ? (fn => () =>
167
- Promise.resolve().then(fn).then(getNormalizedEntryStatic))(
168
- config.entry
169
- )
167
+ ? (
168
+ fn => () =>
169
+ Promise.resolve().then(fn).then(getNormalizedEntryStatic)
170
+ )(config.entry)
170
171
  : getNormalizedEntryStatic(config.entry),
171
172
  experiments: cloneObject(config.experiments),
172
173
  externals: config.externals,
@@ -5,14 +5,18 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const browserslistTargetHandler = require("./browserslistTargetHandler");
8
+ const memoize = require("../util/memoize");
9
+
10
+ const getBrowserslistTargetHandler = memoize(() =>
11
+ require("./browserslistTargetHandler")
12
+ );
9
13
 
10
14
  /**
11
15
  * @param {string} context the context directory
12
16
  * @returns {string} default target
13
17
  */
14
18
  const getDefaultTarget = context => {
15
- const browsers = browserslistTargetHandler.load(null, context);
19
+ const browsers = getBrowserslistTargetHandler().load(null, context);
16
20
  return browsers ? "browserslist" : "web";
17
21
  };
18
22
 
@@ -78,6 +82,7 @@ const TARGETS = [
78
82
  "Resolve features from browserslist. Will resolve browserslist config automatically. Only browser or node queries are supported (electron is not supported). Examples: 'browserslist:modern' to use 'modern' environment from browserslist config",
79
83
  /^browserslist(?::(.+))?$/,
80
84
  (rest, context) => {
85
+ const browserslistTargetHandler = getBrowserslistTargetHandler();
81
86
  const browsers = browserslistTargetHandler.load(
82
87
  rest ? rest.trim() : null,
83
88
  context
@@ -332,9 +332,10 @@ const interceptAllParserHooks = (moduleFactory, tracer) => {
332
332
  const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
333
333
  interceptAllHooksFor(
334
334
  {
335
- hooks: require("../javascript/JavascriptModulesPlugin").getCompilationHooks(
336
- compilation
337
- )
335
+ hooks:
336
+ require("../javascript/JavascriptModulesPlugin").getCompilationHooks(
337
+ compilation
338
+ )
338
339
  },
339
340
  tracer,
340
341
  "JavascriptModulesPlugin"
@@ -77,9 +77,9 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
77
77
  { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
78
78
  ) {
79
79
  const dep = /** @type {AMDRequireDependency} */ (dependency);
80
- const depBlock = /** @type {AsyncDependenciesBlock} */ (moduleGraph.getParentBlock(
81
- dep
82
- ));
80
+ const depBlock = /** @type {AsyncDependenciesBlock} */ (
81
+ moduleGraph.getParentBlock(dep)
82
+ );
83
83
  const promise = runtimeTemplate.blockPromise({
84
84
  chunkGraph,
85
85
  block: depBlock,
@@ -230,9 +230,8 @@ class CommonJsExportRequireDependency extends ModuleDependency {
230
230
  if (name === "__esModule" && isNamespaceImport) {
231
231
  exports.add(name);
232
232
  } else if (importedExportsInfo) {
233
- const importedExportInfo = importedExportsInfo.getReadOnlyExportInfo(
234
- name
235
- );
233
+ const importedExportInfo =
234
+ importedExportsInfo.getReadOnlyExportInfo(name);
236
235
  if (importedExportInfo.provided === false) continue;
237
236
  exports.add(name);
238
237
  if (importedExportInfo.provided === true) continue;
@@ -192,7 +192,9 @@ class CommonJsExportsParserPlugin {
192
192
  parser.hooks.call
193
193
  .for("Object.defineProperty")
194
194
  .tap("CommonJsExportsParserPlugin", expression => {
195
- const expr = /** @type {import("estree").CallExpression} */ (expression);
195
+ const expr = /** @type {import("estree").CallExpression} */ (
196
+ expression
197
+ );
196
198
  if (!parser.isStatementLevelExpression(expr)) return;
197
199
  if (expr.arguments.length !== 3) return;
198
200
  if (expr.arguments[0].type === "SpreadElement") return;
@@ -182,10 +182,8 @@ class CommonJsImportsParserPlugin {
182
182
  };
183
183
  const createRequireHandler = callNew => expr => {
184
184
  if (options.commonjsMagicComments) {
185
- const {
186
- options: requireOptions,
187
- errors: commentErrors
188
- } = parser.parseCommentOptions(expr.range);
185
+ const { options: requireOptions, errors: commentErrors } =
186
+ parser.parseCommentOptions(expr.range);
189
187
 
190
188
  if (commentErrors) {
191
189
  for (const e of commentErrors) {
@@ -265,13 +265,14 @@ class NodeModuleDecoratorRuntimeModule extends RuntimeModule {
265
265
  generate() {
266
266
  const { runtimeTemplate } = this.compilation;
267
267
  return Template.asString([
268
- `${
269
- RuntimeGlobals.nodeModuleDecorator
270
- } = ${runtimeTemplate.basicFunction("module", [
271
- "module.paths = [];",
272
- "if (!module.children) module.children = [];",
273
- "return module;"
274
- ])};`
268
+ `${RuntimeGlobals.nodeModuleDecorator} = ${runtimeTemplate.basicFunction(
269
+ "module",
270
+ [
271
+ "module.paths = [];",
272
+ "if (!module.children) module.children = [];",
273
+ "return module;"
274
+ ]
275
+ )};`
275
276
  ]);
276
277
  }
277
278
  }
@@ -45,6 +45,7 @@ makeSerializable(
45
45
  "webpack/lib/dependencies/CommonJsRequireContextDependency"
46
46
  );
47
47
 
48
- CommonJsRequireContextDependency.Template = ContextDependencyTemplateAsRequireCall;
48
+ CommonJsRequireContextDependency.Template =
49
+ ContextDependencyTemplateAsRequireCall;
49
50
 
50
51
  module.exports = CommonJsRequireContextDependency;
@@ -61,10 +61,11 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
61
61
 
62
62
  const valueRange = param.range;
63
63
  const { context, prefix } = splitContextFromPrefix(prefixRaw);
64
- const { path: postfix, query, fragment } = parseResource(
65
- postfixRaw,
66
- parser
67
- );
64
+ const {
65
+ path: postfix,
66
+ query,
67
+ fragment
68
+ } = parseResource(postfixRaw, parser);
68
69
 
69
70
  // When there are more than two quasis, the generated RegExp can be more precise
70
71
  // We join the quasis with the expression regexp
@@ -160,10 +161,11 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
160
161
  param.postfix && param.postfix.isString() ? param.postfix.range : null;
161
162
  const valueRange = param.range;
162
163
  const { context, prefix } = splitContextFromPrefix(prefixRaw);
163
- const { path: postfix, query, fragment } = parseResource(
164
- postfixRaw,
165
- parser
166
- );
164
+ const {
165
+ path: postfix,
166
+ query,
167
+ fragment
168
+ } = parseResource(postfixRaw, parser);
167
169
  const regExp = new RegExp(
168
170
  `^${quoteMeta(prefix)}${options.wrappedContextRegExp.source}${quoteMeta(
169
171
  postfix
@@ -14,9 +14,10 @@ const ModuleDependency = require("./ModuleDependency");
14
14
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
15
15
 
16
16
  class ContextElementDependency extends ModuleDependency {
17
- constructor(request, userRequest, category, referencedExports) {
17
+ constructor(request, userRequest, typePrefix, category, referencedExports) {
18
18
  super(request);
19
19
  this.referencedExports = referencedExports;
20
+ this._typePrefix = typePrefix;
20
21
  this._category = category;
21
22
 
22
23
  if (userRequest) {
@@ -25,6 +26,10 @@ class ContextElementDependency extends ModuleDependency {
25
26
  }
26
27
 
27
28
  get type() {
29
+ if (this._typePrefix) {
30
+ return `${this._typePrefix} context element`;
31
+ }
32
+
28
33
  return "context element";
29
34
  }
30
35
 
@@ -14,8 +14,6 @@ class CriticalDependencyWarning extends WebpackError {
14
14
 
15
15
  this.name = "CriticalDependencyWarning";
16
16
  this.message = "Critical dependency: " + message;
17
-
18
- Error.captureStackTrace(this, this.constructor);
19
17
  }
20
18
  }
21
19
 
@@ -411,9 +411,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
411
411
  const ignoredExports = new Set(["default", ...this.activeExports]);
412
412
 
413
413
  let hiddenExports = undefined;
414
- const otherStarExports = this._discoverActiveExportsFromOtherStarExports(
415
- moduleGraph
416
- );
414
+ const otherStarExports =
415
+ this._discoverActiveExportsFromOtherStarExports(moduleGraph);
417
416
  if (otherStarExports !== undefined) {
418
417
  hiddenExports = new Set();
419
418
  for (let i = 0; i < otherStarExports.namesSlice; i++) {
@@ -441,9 +440,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
441
440
  const name = exportInfo.name;
442
441
  if (ignoredExports.has(name)) continue;
443
442
  if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
444
- const importedExportInfo = importedExportsInfo.getReadOnlyExportInfo(
445
- name
446
- );
443
+ const importedExportInfo =
444
+ importedExportsInfo.getReadOnlyExportInfo(name);
447
445
  if (importedExportInfo.provided === false) continue;
448
446
  if (hiddenExports !== undefined && hiddenExports.has(name)) {
449
447
  hidden.add(name);
@@ -763,9 +761,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
763
761
  `(reexported as '${this.name}')`
764
762
  );
765
763
  if (ids.length === 0 && this.name === null) {
766
- const potentialConflicts = this._discoverActiveExportsFromOtherStarExports(
767
- moduleGraph
768
- );
764
+ const potentialConflicts =
765
+ this._discoverActiveExportsFromOtherStarExports(moduleGraph);
769
766
  if (potentialConflicts && potentialConflicts.namesSlice > 0) {
770
767
  const ownNames = new Set(
771
768
  potentialConflicts.names.slice(
@@ -802,9 +799,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
802
799
  conflictingModule,
803
800
  exportInfo.name
804
801
  );
805
- const conflictingTarget = conflictingExportInfo.getTerminalBinding(
806
- moduleGraph
807
- );
802
+ const conflictingTarget =
803
+ conflictingExportInfo.getTerminalBinding(moduleGraph);
808
804
  if (!conflictingTarget) continue;
809
805
  if (target === conflictingTarget) continue;
810
806
  const list = conflicts.get(conflictingDependency.request);
@@ -882,7 +878,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
882
878
  apply(dependency, source, templateContext) {
883
879
  const { moduleGraph, runtime, concatenationScope } = templateContext;
884
880
 
885
- const dep = /** @type {HarmonyExportImportedSpecifierDependency} */ (dependency);
881
+ const dep = /** @type {HarmonyExportImportedSpecifierDependency} */ (
882
+ dependency
883
+ );
886
884
 
887
885
  const mode = dep.getMode(moduleGraph, runtime);
888
886
 
@@ -152,10 +152,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
152
152
  InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
153
153
  return true;
154
154
  });
155
- const {
156
- hotAcceptCallback,
157
- hotAcceptWithoutCallback
158
- } = HotModuleReplacementPlugin.getParserHooks(parser);
155
+ const { hotAcceptCallback, hotAcceptWithoutCallback } =
156
+ HotModuleReplacementPlugin.getParserHooks(parser);
159
157
  hotAcceptCallback.tap(
160
158
  "HarmonyImportDependencyParserPlugin",
161
159
  (expr, requests) => {
@@ -243,12 +243,8 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
243
243
  */
244
244
  apply(dependency, source, templateContext) {
245
245
  const dep = /** @type {HarmonyImportSpecifierDependency} */ (dependency);
246
- const {
247
- moduleGraph,
248
- module,
249
- runtime,
250
- concatenationScope
251
- } = templateContext;
246
+ const { moduleGraph, module, runtime, concatenationScope } =
247
+ templateContext;
252
248
  const connection = moduleGraph.getConnection(dep);
253
249
  // Skip rendering depending when dependency is conditional
254
250
  if (connection && !connection.isTargetActive(runtime)) return;
@@ -287,11 +283,8 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
287
283
  } else {
288
284
  super.apply(dependency, source, templateContext);
289
285
 
290
- const {
291
- runtimeTemplate,
292
- initFragments,
293
- runtimeRequirements
294
- } = templateContext;
286
+ const { runtimeTemplate, initFragments, runtimeRequirements } =
287
+ templateContext;
295
288
 
296
289
  exportExpr = runtimeTemplate.exportFromImport({
297
290
  moduleGraph,
@@ -81,9 +81,9 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
81
81
  { runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
82
82
  ) {
83
83
  const dep = /** @type {ImportDependency} */ (dependency);
84
- const block = /** @type {AsyncDependenciesBlock} */ (moduleGraph.getParentBlock(
85
- dep
86
- ));
84
+ const block = /** @type {AsyncDependenciesBlock} */ (
85
+ moduleGraph.getParentBlock(dep)
86
+ );
87
87
  const content = runtimeTemplate.moduleNamespacePromise({
88
88
  chunkGraph,
89
89
  block: block,
@@ -36,10 +36,8 @@ class ImportParserPlugin {
36
36
  /** @type {RawChunkGroupOptions} */
37
37
  const groupOptions = {};
38
38
 
39
- const {
40
- options: importOptions,
41
- errors: commentErrors
42
- } = parser.parseCommentOptions(expr.range);
39
+ const { options: importOptions, errors: commentErrors } =
40
+ parser.parseCommentOptions(expr.range);
43
41
 
44
42
  if (commentErrors) {
45
43
  for (const e of commentErrors) {
@@ -250,6 +248,7 @@ class ImportParserPlugin {
250
248
  namespaceObject: parser.state.module.buildMeta.strictHarmonyModule
251
249
  ? "strict"
252
250
  : true,
251
+ typePrefix: "import()",
253
252
  category: "esm",
254
253
  referencedExports: exports
255
254
  },
@@ -46,9 +46,8 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
46
46
  ? dependenciesExpr.items
47
47
  : [dependenciesExpr];
48
48
  const successExpressionArg = expr.arguments[1];
49
- const successExpression = getFunctionExpression(
50
- successExpressionArg
51
- );
49
+ const successExpression =
50
+ getFunctionExpression(successExpressionArg);
52
51
 
53
52
  if (successExpression) {
54
53
  parser.walkExpressions(successExpression.expressions);
@@ -68,9 +68,9 @@ RequireEnsureDependency.Template = class RequireEnsureDependencyTemplate extends
68
68
  { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
69
69
  ) {
70
70
  const dep = /** @type {RequireEnsureDependency} */ (dependency);
71
- const depBlock = /** @type {AsyncDependenciesBlock} */ (moduleGraph.getParentBlock(
72
- dep
73
- ));
71
+ const depBlock = /** @type {AsyncDependenciesBlock} */ (
72
+ moduleGraph.getParentBlock(dep)
73
+ );
74
74
  const promise = runtimeTemplate.blockPromise({
75
75
  chunkGraph,
76
76
  block: depBlock,
@@ -67,8 +67,6 @@ class RequireIncludeDeprecationWarning extends WebpackError {
67
67
  this.name = "RequireIncludeDeprecationWarning";
68
68
 
69
69
  this.loc = loc;
70
-
71
- Error.captureStackTrace(this, this.constructor);
72
70
  }
73
71
  }
74
72
 
@@ -127,8 +127,6 @@ class SystemImportDeprecationWarning extends WebpackError {
127
127
  this.name = "SystemImportDeprecationWarning";
128
128
 
129
129
  this.loc = loc;
130
-
131
- Error.captureStackTrace(this, this.constructor);
132
130
  }
133
131
  }
134
132
 
@@ -62,12 +62,12 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
62
62
  apply(dependency, source, templateContext) {
63
63
  const { chunkGraph, moduleGraph, runtimeRequirements } = templateContext;
64
64
  const dep = /** @type {WorkerDependency} */ (dependency);
65
- const block = /** @type {AsyncDependenciesBlock} */ (moduleGraph.getParentBlock(
66
- dependency
67
- ));
68
- const entrypoint = /** @type {Entrypoint} */ (chunkGraph.getBlockChunkGroup(
69
- block
70
- ));
65
+ const block = /** @type {AsyncDependenciesBlock} */ (
66
+ moduleGraph.getParentBlock(dependency)
67
+ );
68
+ const entrypoint = /** @type {Entrypoint} */ (
69
+ chunkGraph.getBlockChunkGroup(block)
70
+ );
71
71
  const chunk = entrypoint.getEntrypointChunk();
72
72
 
73
73
  runtimeRequirements.add(RuntimeGlobals.publicPath);