webpack 5.89.0 → 5.90.1

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 (167) hide show
  1. package/README.md +3 -0
  2. package/bin/webpack.js +1 -3
  3. package/hot/log.js +0 -2
  4. package/lib/APIPlugin.js +17 -13
  5. package/lib/ChunkGraph.js +1 -1
  6. package/lib/CleanPlugin.js +12 -12
  7. package/lib/Compilation.js +26 -17
  8. package/lib/Compiler.js +13 -0
  9. package/lib/ConcatenationScope.js +2 -2
  10. package/lib/ConditionalInitFragment.js +3 -3
  11. package/lib/ContextModule.js +4 -4
  12. package/lib/ContextModuleFactory.js +1 -1
  13. package/lib/DefinePlugin.js +47 -26
  14. package/lib/DependencyTemplate.js +3 -1
  15. package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
  16. package/lib/EvalDevToolModulePlugin.js +1 -1
  17. package/lib/EvalSourceMapDevToolPlugin.js +2 -2
  18. package/lib/ExportsInfoApiPlugin.js +2 -2
  19. package/lib/ExternalModule.js +47 -12
  20. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  21. package/lib/FileSystemInfo.js +20 -3
  22. package/lib/FlagDependencyExportsPlugin.js +1 -1
  23. package/lib/Generator.js +1 -0
  24. package/lib/HotModuleReplacementPlugin.js +3 -3
  25. package/lib/InitFragment.js +7 -7
  26. package/lib/LibManifestPlugin.js +4 -1
  27. package/lib/Module.js +2 -1
  28. package/lib/ModuleFilenameHelpers.js +1 -1
  29. package/lib/ModuleInfoHeaderPlugin.js +1 -1
  30. package/lib/MultiStats.js +2 -2
  31. package/lib/NodeStuffPlugin.js +48 -0
  32. package/lib/NormalModule.js +13 -11
  33. package/lib/NormalModuleFactory.js +7 -7
  34. package/lib/RuntimeTemplate.js +15 -11
  35. package/lib/SourceMapDevToolPlugin.js +2 -2
  36. package/lib/Stats.js +4 -0
  37. package/lib/WebpackOptionsApply.js +4 -3
  38. package/lib/asset/AssetModulesPlugin.js +2 -3
  39. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  40. package/lib/buildChunkGraph.js +53 -0
  41. package/lib/cache/AddManagedPathsPlugin.js +6 -1
  42. package/lib/cache/IdleFileCachePlugin.js +12 -5
  43. package/lib/cache/PackFileCacheStrategy.js +3 -3
  44. package/lib/cache/ResolverCachePlugin.js +2 -2
  45. package/lib/config/browserslistTargetHandler.js +35 -14
  46. package/lib/config/defaults.js +88 -52
  47. package/lib/config/normalization.js +17 -18
  48. package/lib/config/target.js +5 -0
  49. package/lib/container/ContainerReferencePlugin.js +1 -1
  50. package/lib/css/CssExportsGenerator.js +14 -1
  51. package/lib/css/CssGenerator.js +14 -1
  52. package/lib/css/CssLoadingRuntimeModule.js +23 -23
  53. package/lib/css/CssModulesPlugin.js +68 -32
  54. package/lib/css/CssParser.js +8 -3
  55. package/lib/debug/ProfilingPlugin.js +2 -2
  56. package/lib/dependencies/AMDDefineDependency.js +4 -4
  57. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +126 -34
  58. package/lib/dependencies/AMDPlugin.js +11 -4
  59. package/lib/dependencies/AMDRequireArrayDependency.js +13 -1
  60. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +159 -43
  61. package/lib/dependencies/AMDRequireDependency.js +2 -2
  62. package/lib/dependencies/AMDRequireItemDependency.js +1 -1
  63. package/lib/dependencies/CachedConstDependency.js +8 -1
  64. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  65. package/lib/dependencies/ContextElementDependency.js +1 -1
  66. package/lib/dependencies/ExternalModuleDependency.js +107 -0
  67. package/lib/dependencies/ExternalModuleInitFragment.js +131 -0
  68. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  69. package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
  70. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
  71. package/lib/dependencies/HarmonyExportInitFragment.js +6 -6
  72. package/lib/dependencies/HarmonyImportDependency.js +4 -4
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
  74. package/lib/dependencies/ImportDependency.js +26 -6
  75. package/lib/dependencies/JsonExportsDependency.js +1 -1
  76. package/lib/dependencies/LoaderPlugin.js +2 -1
  77. package/lib/dependencies/LocalModuleDependency.js +1 -1
  78. package/lib/dependencies/PureExpressionDependency.js +12 -4
  79. package/lib/dependencies/RequireIncludeDependency.js +1 -1
  80. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
  81. package/lib/dependencies/WorkerPlugin.js +10 -3
  82. package/lib/dependencies/getFunctionExpression.js +2 -2
  83. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
  84. package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
  85. package/lib/hmr/lazyCompilationBackend.js +4 -4
  86. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  87. package/lib/index.js +4 -0
  88. package/lib/javascript/JavascriptGenerator.js +16 -1
  89. package/lib/javascript/JavascriptModulesPlugin.js +33 -33
  90. package/lib/javascript/JavascriptParser.js +220 -74
  91. package/lib/json/JsonGenerator.js +1 -1
  92. package/lib/library/AmdLibraryPlugin.js +5 -1
  93. package/lib/library/AssignLibraryPlugin.js +1 -1
  94. package/lib/library/SystemLibraryPlugin.js +1 -1
  95. package/lib/library/UmdLibraryPlugin.js +39 -39
  96. package/lib/logging/createConsoleLogger.js +1 -19
  97. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
  98. package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
  99. package/lib/node/nodeConsole.js +1 -5
  100. package/lib/optimize/ConcatenatedModule.js +7 -7
  101. package/lib/optimize/InnerGraphPlugin.js +9 -1
  102. package/lib/optimize/MangleExportsPlugin.js +5 -1
  103. package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
  104. package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
  105. package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
  106. package/lib/optimize/SplitChunksPlugin.js +16 -16
  107. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
  108. package/lib/rules/RuleSetCompiler.js +1 -1
  109. package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
  110. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
  111. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
  112. package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
  113. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
  114. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
  115. package/lib/schemes/HttpUriPlugin.js +1 -1
  116. package/lib/serialization/FileMiddleware.js +4 -4
  117. package/lib/serialization/ObjectMiddleware.js +4 -4
  118. package/lib/sharing/ConsumeSharedPlugin.js +5 -5
  119. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
  120. package/lib/sharing/ProvideSharedModule.js +2 -2
  121. package/lib/sharing/SharePlugin.js +2 -2
  122. package/lib/sharing/ShareRuntimeModule.js +1 -1
  123. package/lib/sharing/utils.js +24 -28
  124. package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
  125. package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
  126. package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
  127. package/lib/util/chainedImports.js +7 -6
  128. package/lib/util/cleverMerge.js +4 -4
  129. package/lib/util/comparators.js +59 -23
  130. package/lib/util/hash/xxhash64.js +2 -2
  131. package/lib/util/identifier.js +2 -2
  132. package/lib/util/internalSerializables.js +6 -0
  133. package/lib/util/numberHash.js +64 -52
  134. package/lib/util/runtime.js +18 -1
  135. package/lib/util/semver.js +19 -24
  136. package/lib/util/smartGrouping.js +1 -1
  137. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +53 -28
  138. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
  139. package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
  140. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  141. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
  142. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
  143. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
  144. package/package.json +25 -80
  145. package/schemas/WebpackOptions.check.js +1 -1
  146. package/schemas/WebpackOptions.json +140 -32
  147. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
  148. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
  149. package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
  150. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
  151. package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
  152. package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
  153. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  154. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
  155. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
  156. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
  157. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
  158. package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
  159. package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
  160. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  161. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  162. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  163. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  164. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  165. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  166. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  167. package/types.d.ts +273 -94
@@ -0,0 +1,52 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Gengkun He @ahabhgk
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const WebpackError = require("./WebpackError");
9
+ const makeSerializable = require("./util/makeSerializable");
10
+
11
+ /** @typedef {import("./Module")} Module */
12
+ /** @typedef {import("./Compilation")} Compilation */
13
+ /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
14
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
15
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
+ /** @typedef {"asyncWebAssembly" | "topLevelAwait" | "external promise" | "external script" | "external import" | "external module"} Feature */
17
+
18
+ class EnvironmentNotSupportAsyncWarning extends WebpackError {
19
+ /**
20
+ * Creates an instance of EnvironmentNotSupportAsyncWarning.
21
+ * @param {Module} module module
22
+ * @param {Feature} feature feature
23
+ */
24
+ constructor(module, feature) {
25
+ const message = `The generated code contains 'async/await' because this module is using "${feature}".
26
+ However, your target environment does not appear to support 'async/await'.
27
+ As a result, the code may not run as expected or may cause runtime errors.`;
28
+ super(message);
29
+
30
+ this.name = "EnvironmentNotSupportAsyncWarning";
31
+ this.module = module;
32
+ }
33
+
34
+ /**
35
+ * Creates an instance of EnvironmentNotSupportAsyncWarning.
36
+ * @param {Module} module module
37
+ * @param {RuntimeTemplate} runtimeTemplate compilation
38
+ * @param {Feature} feature feature
39
+ */
40
+ static check(module, runtimeTemplate, feature) {
41
+ if (!runtimeTemplate.supportsAsyncFunction()) {
42
+ module.addWarning(new EnvironmentNotSupportAsyncWarning(module, feature));
43
+ }
44
+ }
45
+ }
46
+
47
+ makeSerializable(
48
+ EnvironmentNotSupportAsyncWarning,
49
+ "webpack/lib/EnvironmentNotSupportAsyncWarning"
50
+ );
51
+
52
+ module.exports = EnvironmentNotSupportAsyncWarning;
@@ -82,7 +82,7 @@ class EvalDevToolModulePlugin {
82
82
  compilation.outputOptions.trustedTypes
83
83
  ? `${RuntimeGlobals.createScript}(${JSON.stringify(
84
84
  content + footer
85
- )})`
85
+ )})`
86
86
  : JSON.stringify(content + footer)
87
87
  });`
88
88
  );
@@ -129,7 +129,7 @@ class EvalSourceMapDevToolPlugin {
129
129
 
130
130
  // Clone (flat) the sourcemap to ensure that the mutations below do not persist.
131
131
  sourceMap = { ...sourceMap };
132
- const context = compiler.options.context;
132
+ const context = /** @type {string} */ (compiler.options.context);
133
133
  const root = compiler.root;
134
134
  const modules = sourceMap.sources.map(source => {
135
135
  if (!source.startsWith("webpack://")) return source;
@@ -182,7 +182,7 @@ class EvalSourceMapDevToolPlugin {
182
182
  compilation.outputOptions.trustedTypes
183
183
  ? `${RuntimeGlobals.createScript}(${JSON.stringify(
184
184
  content + footer
185
- )})`
185
+ )})`
186
186
  : JSON.stringify(content + footer)
187
187
  });`
188
188
  )
@@ -48,12 +48,12 @@ class ExportsInfoApiPlugin {
48
48
  /** @type {Range} */ (expr.range),
49
49
  members.slice(0, -1),
50
50
  members[members.length - 1]
51
- )
51
+ )
52
52
  : new ExportsInfoDependency(
53
53
  /** @type {Range} */ (expr.range),
54
54
  null,
55
55
  members[0]
56
- );
56
+ );
57
57
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
58
58
  parser.state.module.addDependency(dep);
59
59
  return true;
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("./ConcatenationScope");
10
+ const EnvironmentNotSupportAsyncWarning = require("./EnvironmentNotSupportAsyncWarning");
10
11
  const { UsageState } = require("./ExportsInfo");
11
12
  const InitFragment = require("./InitFragment");
12
13
  const Module = require("./Module");
@@ -217,7 +218,12 @@ register(
217
218
  }
218
219
  );
219
220
 
220
- const generateModuleRemapping = (input, exportsInfo, runtime) => {
221
+ const generateModuleRemapping = (
222
+ input,
223
+ exportsInfo,
224
+ runtime,
225
+ runtimeTemplate
226
+ ) => {
221
227
  if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) {
222
228
  const properties = [];
223
229
  for (const exportInfo of exportsInfo.orderedExports) {
@@ -235,9 +241,9 @@ const generateModuleRemapping = (input, exportsInfo, runtime) => {
235
241
  }
236
242
  }
237
243
  properties.push(
238
- `[${JSON.stringify(used)}]: () => ${input}${propertyAccess([
239
- exportInfo.name
240
- ])}`
244
+ `[${JSON.stringify(used)}]: ${runtimeTemplate.returningFunction(
245
+ `${input}${propertyAccess([exportInfo.name])}`
246
+ )}`
241
247
  );
242
248
  }
243
249
  return `x({ ${properties.join(", ")} })`;
@@ -248,21 +254,21 @@ const generateModuleRemapping = (input, exportsInfo, runtime) => {
248
254
  * @param {string|string[]} moduleAndSpecifiers the module request
249
255
  * @param {ExportsInfo} exportsInfo exports info of this module
250
256
  * @param {RuntimeSpec} runtime the runtime
251
- * @param {string | HashConstructor=} hashFunction the hash function to use
257
+ * @param {RuntimeTemplate} runtimeTemplate the runtime template
252
258
  * @returns {SourceData} the generated source
253
259
  */
254
260
  const getSourceForModuleExternal = (
255
261
  moduleAndSpecifiers,
256
262
  exportsInfo,
257
263
  runtime,
258
- hashFunction
264
+ runtimeTemplate
259
265
  ) => {
260
266
  if (!Array.isArray(moduleAndSpecifiers))
261
267
  moduleAndSpecifiers = [moduleAndSpecifiers];
262
268
  const initFragment = new ModuleExternalInitFragment(
263
269
  moduleAndSpecifiers[0],
264
270
  undefined,
265
- hashFunction
271
+ runtimeTemplate.outputOptions.hashFunction
266
272
  );
267
273
  const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
268
274
  moduleAndSpecifiers,
@@ -271,12 +277,19 @@ const getSourceForModuleExternal = (
271
277
  const moduleRemapping = generateModuleRemapping(
272
278
  baseAccess,
273
279
  exportsInfo,
274
- runtime
280
+ runtime,
281
+ runtimeTemplate
275
282
  );
276
283
  let expression = moduleRemapping || baseAccess;
277
284
  return {
278
285
  expression,
279
- init: `var x = y => { var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x; }\nvar y = x => () => x`,
286
+ init: `var x = ${runtimeTemplate.basicFunction(
287
+ "y",
288
+ `var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x`
289
+ )} \nvar y = ${runtimeTemplate.returningFunction(
290
+ runtimeTemplate.returningFunction("x"),
291
+ "x"
292
+ )}`,
280
293
  runtimeRequirements: moduleRemapping
281
294
  ? RUNTIME_REQUIREMENTS_FOR_MODULE
282
295
  : undefined,
@@ -355,7 +368,7 @@ const getSourceForAmdOrUmdExternal = (
355
368
  externalVariable,
356
369
  Array.isArray(request) ? request.join(".") : request,
357
370
  runtimeTemplate
358
- )
371
+ )
359
372
  : undefined,
360
373
  expression: externalVariable
361
374
  };
@@ -491,6 +504,11 @@ class ExternalModule extends Module {
491
504
  }
492
505
  } else {
493
506
  this.buildMeta.async = true;
507
+ EnvironmentNotSupportAsyncWarning.check(
508
+ this,
509
+ compilation.runtimeTemplate,
510
+ "external module"
511
+ );
494
512
  if (!Array.isArray(request) || request.length === 1) {
495
513
  this.buildMeta.exportsType = "namespace";
496
514
  canMangle = false;
@@ -498,11 +516,28 @@ class ExternalModule extends Module {
498
516
  }
499
517
  break;
500
518
  case "script":
519
+ this.buildMeta.async = true;
520
+ EnvironmentNotSupportAsyncWarning.check(
521
+ this,
522
+ compilation.runtimeTemplate,
523
+ "external script"
524
+ );
525
+ break;
501
526
  case "promise":
502
527
  this.buildMeta.async = true;
528
+ EnvironmentNotSupportAsyncWarning.check(
529
+ this,
530
+ compilation.runtimeTemplate,
531
+ "external promise"
532
+ );
503
533
  break;
504
534
  case "import":
505
535
  this.buildMeta.async = true;
536
+ EnvironmentNotSupportAsyncWarning.check(
537
+ this,
538
+ compilation.runtimeTemplate,
539
+ "external import"
540
+ );
506
541
  if (!Array.isArray(request) || request.length === 1) {
507
542
  this.buildMeta.exportsType = "namespace";
508
543
  canMangle = false;
@@ -569,7 +604,7 @@ class ExternalModule extends Module {
569
604
  ? getSourceForCommonJsExternalInNodeModule(
570
605
  request,
571
606
  runtimeTemplate.outputOptions.importMetaName
572
- )
607
+ )
573
608
  : getSourceForCommonJsExternal(request);
574
609
  case "amd":
575
610
  case "amd-require":
@@ -610,7 +645,7 @@ class ExternalModule extends Module {
610
645
  request,
611
646
  moduleGraph.getExportsInfo(this),
612
647
  runtime,
613
- runtimeTemplate.outputOptions.hashFunction
648
+ runtimeTemplate
614
649
  );
615
650
  }
616
651
  case "var":
@@ -192,7 +192,7 @@ class ExternalModuleFactoryPlugin {
192
192
  data.resolveOptions || EMPTY_RESOLVE_OPTIONS,
193
193
  "dependencyType",
194
194
  dependencyType
195
- )
195
+ )
196
196
  : data.resolveOptions
197
197
  );
198
198
  if (options) resolver = resolver.withOptions(options);
@@ -729,7 +729,8 @@ class SnapshotOptimization {
729
729
  }
730
730
 
731
731
  const parseString = str => {
732
- if (str[0] === "'") str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
732
+ if (str[0] === "'" || str[0] === "`")
733
+ str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
733
734
  return JSON.parse(str);
734
735
  };
735
736
 
@@ -898,6 +899,7 @@ class FileSystemInfo {
898
899
  /**
899
900
  * @param {InputFileSystem} fs file system
900
901
  * @param {Object} options options
902
+ * @param {Iterable<string | RegExp>=} options.unmanagedPaths paths that are not managed by a package manager and the contents are subject to change
901
903
  * @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
902
904
  * @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
903
905
  * @param {Logger=} options.logger logger used to log invalid snapshots
@@ -906,6 +908,7 @@ class FileSystemInfo {
906
908
  constructor(
907
909
  fs,
908
910
  {
911
+ unmanagedPaths = [],
909
912
  managedPaths = [],
910
913
  immutablePaths = [],
911
914
  logger,
@@ -1040,6 +1043,14 @@ class FileSystemInfo {
1040
1043
  parallelism: 10,
1041
1044
  processor: this._getManagedItemDirectoryInfo.bind(this)
1042
1045
  });
1046
+ const _unmanagedPaths = Array.from(unmanagedPaths);
1047
+ this.unmanagedPathsWithSlash = /** @type {string[]} */ (
1048
+ _unmanagedPaths.filter(p => typeof p === "string")
1049
+ ).map(p => join(fs, p, "_").slice(0, -1));
1050
+ this.unmanagedPathsRegExps = /** @type {RegExp[]} */ (
1051
+ _unmanagedPaths.filter(p => typeof p !== "string")
1052
+ );
1053
+
1043
1054
  this.managedPaths = Array.from(managedPaths);
1044
1055
  this.managedPathsWithSlash = /** @type {string[]} */ (
1045
1056
  this.managedPaths.filter(p => typeof p === "string")
@@ -1733,7 +1744,7 @@ class FileSystemInfo {
1733
1744
  type: RBDT_RESOLVE_ESM_FILE,
1734
1745
  context,
1735
1746
  path: dependency,
1736
- expected: undefined,
1747
+ expected: imp.d > -1 ? false : undefined,
1737
1748
  issuer: job
1738
1749
  });
1739
1750
  } catch (e) {
@@ -2028,6 +2039,12 @@ class FileSystemInfo {
2028
2039
  }
2029
2040
  };
2030
2041
  const checkManaged = (path, managedSet) => {
2042
+ for (const unmanagedPath of this.unmanagedPathsRegExps) {
2043
+ if (unmanagedPath.test(path)) return false;
2044
+ }
2045
+ for (const unmanagedPath of this.unmanagedPathsWithSlash) {
2046
+ if (path.startsWith(unmanagedPath)) return false;
2047
+ }
2031
2048
  for (const immutablePath of this.immutablePathsRegExps) {
2032
2049
  if (immutablePath.test(path)) {
2033
2050
  managedSet.add(path);
@@ -3346,7 +3363,7 @@ class FileSystemInfo {
3346
3363
  : {
3347
3364
  ...timestamp,
3348
3365
  ...hash
3349
- };
3366
+ };
3350
3367
  this._contextTshs.set(path, result);
3351
3368
  callback(null, result);
3352
3369
  };
@@ -246,7 +246,7 @@ class FlagDependencyExportsPlugin {
246
246
  from,
247
247
  fromExport === undefined ? [name] : fromExport,
248
248
  priority
249
- ))
249
+ ))
250
250
  ) {
251
251
  changed = true;
252
252
  }
package/lib/Generator.js CHANGED
@@ -27,6 +27,7 @@
27
27
  * @property {ChunkGraph} chunkGraph the chunk graph
28
28
  * @property {Set<string>} runtimeRequirements the requirements for runtime
29
29
  * @property {RuntimeSpec} runtime the runtime
30
+ * @property {RuntimeSpec[]} [runtimes] the runtimes
30
31
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
31
32
  * @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
32
33
  * @property {string} type which kind of code should be generated
@@ -447,7 +447,7 @@ class HotModuleReplacementPlugin {
447
447
  : compilation.codeGenerationResults.getHash(
448
448
  module,
449
449
  chunk.runtime
450
- );
450
+ );
451
451
  if (records.chunkModuleHashes[key] !== hash) {
452
452
  updatedModules.add(module, chunk);
453
453
  }
@@ -571,7 +571,7 @@ class HotModuleReplacementPlugin {
571
571
  : compilation.codeGenerationResults.getHash(
572
572
  module,
573
573
  newRuntime
574
- );
574
+ );
575
575
  if (hash !== oldHash) {
576
576
  if (module.type === WEBPACK_MODULE_TYPE_RUNTIME) {
577
577
  newRuntimeModules = newRuntimeModules || [];
@@ -735,7 +735,7 @@ To fix this, make sure to include [runtime] in the output.hotUpdateMainFilename
735
735
  Array.from(removedModules, m =>
736
736
  chunkGraph.getModuleId(m)
737
737
  )
738
- )
738
+ )
739
739
  };
740
740
 
741
741
  const source = new RawSource(JSON.stringify(hotUpdateMainJson));
@@ -36,15 +36,15 @@ const sortFragmentWithIndex = ([a, i], [b, j]) => {
36
36
  };
37
37
 
38
38
  /**
39
- * @template Context
39
+ * @template GenerateContext
40
40
  */
41
41
  class InitFragment {
42
42
  /**
43
- * @param {string|Source} content the source code that will be included as initialization code
43
+ * @param {string | Source} content the source code that will be included as initialization code
44
44
  * @param {number} stage category of initialization code (contribute to order)
45
45
  * @param {number} position position in the category (contribute to order)
46
46
  * @param {string=} key unique key to avoid emitting the same initialization code twice
47
- * @param {string|Source=} endContent the source code that will be included at the end of the module
47
+ * @param {string | Source=} endContent the source code that will be included at the end of the module
48
48
  */
49
49
  constructor(content, stage, position, key, endContent) {
50
50
  this.content = content;
@@ -55,15 +55,15 @@ class InitFragment {
55
55
  }
56
56
 
57
57
  /**
58
- * @param {Context} context context
59
- * @returns {string|Source} the source code that will be included as initialization code
58
+ * @param {GenerateContext} context context
59
+ * @returns {string | Source} the source code that will be included as initialization code
60
60
  */
61
61
  getContent(context) {
62
62
  return this.content;
63
63
  }
64
64
 
65
65
  /**
66
- * @param {Context} context context
66
+ * @param {GenerateContext} context context
67
67
  * @returns {string|Source=} the source code that will be included at the end of the module
68
68
  */
69
69
  getEndContent(context) {
@@ -91,7 +91,7 @@ class InitFragment {
91
91
  for (const [fragment] of sortedFragments) {
92
92
  if (
93
93
  typeof (
94
- /** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment[]) => InitFragment[] }} */
94
+ /** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment<Context>[]) => InitFragment<Context>[] }} */
95
95
  (fragment).mergeAll
96
96
  ) === "function"
97
97
  ) {
@@ -46,7 +46,10 @@ class LibManifestPlugin {
46
46
  */
47
47
  apply(compiler) {
48
48
  compiler.hooks.emit.tapAsync(
49
- "LibManifestPlugin",
49
+ {
50
+ name: "LibManifestPlugin",
51
+ stage: 110
52
+ },
50
53
  (compilation, callback) => {
51
54
  const moduleGraph = compilation.moduleGraph;
52
55
  asyncLib.forEach(
package/lib/Module.js CHANGED
@@ -59,7 +59,8 @@ const makeSerializable = require("./util/makeSerializable");
59
59
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
60
60
  * @property {ModuleGraph} moduleGraph the module graph
61
61
  * @property {ChunkGraph} chunkGraph the chunk graph
62
- * @property {RuntimeSpec} runtime the runtimes code should be generated for
62
+ * @property {RuntimeSpec} runtime the runtime code should be generated for
63
+ * @property {RuntimeSpec[]} [runtimes] the runtimes code should be generated for
63
64
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
64
65
  * @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
65
66
  * @property {Compilation=} compilation the compilation
@@ -162,7 +162,7 @@ ModuleFilenameHelpers.createFilename = (
162
162
  ? options
163
163
  : {
164
164
  moduleFilenameTemplate: options
165
- })
165
+ })
166
166
  };
167
167
 
168
168
  let absoluteResourcePath;
@@ -96,7 +96,7 @@ const printExportsInfoToSource = (
96
96
  .map(e => JSON.stringify(e).slice(1, -1))
97
97
  .join(".")}`
98
98
  : ""
99
- }`
99
+ }`
100
100
  : ""
101
101
  }`
102
102
  ) + "\n"
package/lib/MultiStats.js CHANGED
@@ -59,8 +59,8 @@ class MultiStats {
59
59
  ...(typeof childOptions === "string"
60
60
  ? { preset: childOptions }
61
61
  : childOptions && typeof childOptions === "object"
62
- ? childOptions
63
- : undefined)
62
+ ? childOptions
63
+ : undefined)
64
64
  },
65
65
  context
66
66
  );
@@ -13,6 +13,7 @@ const NodeStuffInWebError = require("./NodeStuffInWebError");
13
13
  const RuntimeGlobals = require("./RuntimeGlobals");
14
14
  const CachedConstDependency = require("./dependencies/CachedConstDependency");
15
15
  const ConstDependency = require("./dependencies/ConstDependency");
16
+ const ExternalModuleDependency = require("./dependencies/ExternalModuleDependency");
16
17
  const {
17
18
  evaluateToString,
18
19
  expressionIsUnsupported
@@ -52,6 +53,11 @@ class NodeStuffPlugin {
52
53
  compiler.hooks.compilation.tap(
53
54
  PLUGIN_NAME,
54
55
  (compilation, { normalModuleFactory }) => {
56
+ compilation.dependencyTemplates.set(
57
+ ExternalModuleDependency,
58
+ new ExternalModuleDependency.Template()
59
+ );
60
+
55
61
  /**
56
62
  * @param {JavascriptParser} parser the parser
57
63
  * @param {JavascriptParserOptions} parserOptions options
@@ -128,6 +134,35 @@ class NodeStuffPlugin {
128
134
  });
129
135
  };
130
136
 
137
+ /**
138
+ * @param {string} expressionName expression name
139
+ * @param {(value: string) => string} fn function
140
+ * @returns {void}
141
+ */
142
+ const setUrlModuleConstant = (expressionName, fn) => {
143
+ parser.hooks.expression
144
+ .for(expressionName)
145
+ .tap(PLUGIN_NAME, expr => {
146
+ const dep = new ExternalModuleDependency(
147
+ "url",
148
+ [
149
+ {
150
+ name: "fileURLToPath",
151
+ value: "__webpack_fileURLToPath__"
152
+ }
153
+ ],
154
+ undefined,
155
+ fn("__webpack_fileURLToPath__"),
156
+ /** @type {Range} */ (expr.range),
157
+ expressionName
158
+ );
159
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
160
+ parser.state.module.addPresentationalDependency(dep);
161
+
162
+ return true;
163
+ });
164
+ };
165
+
131
166
  /**
132
167
  * @param {string} expressionName expression name
133
168
  * @param {string} value value
@@ -150,6 +185,12 @@ class NodeStuffPlugin {
150
185
  "__filename is a Node.js feature and isn't available in browsers."
151
186
  );
152
187
  break;
188
+ case "node-module":
189
+ setUrlModuleConstant(
190
+ "__filename",
191
+ functionName => `${functionName}(import.meta.url)`
192
+ );
193
+ break;
153
194
  case true:
154
195
  setModuleConstant("__filename", module =>
155
196
  relative(compiler.inputFileSystem, context, module.resource)
@@ -177,6 +218,13 @@ class NodeStuffPlugin {
177
218
  "__dirname is a Node.js feature and isn't available in browsers."
178
219
  );
179
220
  break;
221
+ case "node-module":
222
+ setUrlModuleConstant(
223
+ "__dirname",
224
+ functionName =>
225
+ `${functionName}(import.meta.url + "/..").slice(0, -1)`
226
+ );
227
+ break;
180
228
  case true:
181
229
  setModuleConstant("__dirname", module =>
182
230
  relative(compiler.inputFileSystem, context, module.context)
@@ -132,14 +132,14 @@ const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => {
132
132
  const mapper = !sourceRoot
133
133
  ? source => source
134
134
  : sourceRoot.endsWith("/")
135
- ? source =>
136
- source.startsWith("/")
137
- ? `${sourceRoot.slice(0, -1)}${source}`
138
- : `${sourceRoot}${source}`
139
- : source =>
140
- source.startsWith("/")
141
- ? `${sourceRoot}${source}`
142
- : `${sourceRoot}/${source}`;
135
+ ? source =>
136
+ source.startsWith("/")
137
+ ? `${sourceRoot.slice(0, -1)}${source}`
138
+ : `${sourceRoot}${source}`
139
+ : source =>
140
+ source.startsWith("/")
141
+ ? `${sourceRoot}${source}`
142
+ : `${sourceRoot}/${source}`;
143
143
  const newSources = sourceMap.sources.map(source =>
144
144
  contextifySourceUrl(context, mapper(source), associatedObjectForCache)
145
145
  );
@@ -782,7 +782,7 @@ class NormalModule extends Module {
782
782
  currentLoader
783
783
  ? compilation.runtimeTemplate.requestShortener.shorten(
784
784
  currentLoader.loader
785
- )
785
+ )
786
786
  : "unknown"
787
787
  }) didn't return a Buffer or String`
788
788
  );
@@ -1181,6 +1181,7 @@ class NormalModule extends Module {
1181
1181
  moduleGraph,
1182
1182
  chunkGraph,
1183
1183
  runtime,
1184
+ runtimes,
1184
1185
  concatenationScope,
1185
1186
  codeGenerationResults,
1186
1187
  sourceTypes
@@ -1204,7 +1205,7 @@ class NormalModule extends Module {
1204
1205
  const source = this.error
1205
1206
  ? new RawSource(
1206
1207
  "throw new Error(" + JSON.stringify(this.error.message) + ");"
1207
- )
1208
+ )
1208
1209
  : this.generator.generate(this, {
1209
1210
  dependencyTemplates,
1210
1211
  runtimeTemplate,
@@ -1212,11 +1213,12 @@ class NormalModule extends Module {
1212
1213
  chunkGraph,
1213
1214
  runtimeRequirements,
1214
1215
  runtime,
1216
+ runtimes,
1215
1217
  concatenationScope,
1216
1218
  codeGenerationResults,
1217
1219
  getData,
1218
1220
  type
1219
- });
1221
+ });
1220
1222
 
1221
1223
  if (source) {
1222
1224
  sources.set(type, new CachedSource(source));
@@ -411,8 +411,8 @@ class NormalModuleFactory extends ModuleFactory {
411
411
  noPreAutoLoaders || noPrePostAutoLoaders
412
412
  ? 2
413
413
  : noAutoLoaders
414
- ? 1
415
- : 0
414
+ ? 1
415
+ : 0
416
416
  )
417
417
  .split(/!+/);
418
418
  unresolvedResource = rawElements.pop();
@@ -676,7 +676,7 @@ class NormalModuleFactory extends ModuleFactory {
676
676
  resolveOptions || EMPTY_RESOLVE_OPTIONS,
677
677
  "dependencyType",
678
678
  dependencyType
679
- )
679
+ )
680
680
  : resolveOptions
681
681
  );
682
682
  this.resolveResource(
@@ -1063,10 +1063,10 @@ If changing the source code is not an option there is also a resolve options cal
1063
1063
  const type = /\.mjs$/i.test(parsedResult.path)
1064
1064
  ? "module"
1065
1065
  : /\.cjs$/i.test(parsedResult.path)
1066
- ? "commonjs"
1067
- : resolveRequest.descriptionFileData === undefined
1068
- ? undefined
1069
- : resolveRequest.descriptionFileData.type;
1066
+ ? "commonjs"
1067
+ : resolveRequest.descriptionFileData === undefined
1068
+ ? undefined
1069
+ : resolveRequest.descriptionFileData.type;
1070
1070
 
1071
1071
  const resolved = {
1072
1072
  loader: parsedResult.path,