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
package/README.md CHANGED
@@ -169,17 +169,14 @@ or are automatically applied via regex from your webpack configuration.
169
169
 
170
170
  #### Transpiling
171
171
 
172
- | Name | Status | Install Size | Description |
173
- | :--------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------: | :-------------: | :--------------------------------------------------------------------------------------------------- |
174
- | <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
175
- | <a href="https://github.com/jupl/traceur-loader"><img width="48" height="48" src="https://google.github.com/traceur-compiler/logo/tc.svg"></a> | ![traceur-npm] | ![traceur-size] | Loads ES2015+ code and transpiles to ES5 using [Traceur](https://github.com/google/traceur-compiler) |
176
- | <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://cdn.rawgit.com/Microsoft/TypeScript/master/doc/logo.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
177
- | <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |
172
+ | Name | Status | Install Size | Description |
173
+ | :--------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: | :------------: | :------------------------------------------------------------------------------------------------ |
174
+ | <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
175
+ | <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://cdn.rawgit.com/Microsoft/TypeScript/master/doc/logo.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
176
+ | <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |
178
177
 
179
178
  [babel-npm]: https://img.shields.io/npm/v/babel-loader.svg
180
179
  [babel-size]: https://packagephobia.com/badge?p=babel-loader
181
- [traceur-npm]: https://img.shields.io/npm/v/traceur-loader.svg
182
- [traceur-size]: https://packagephobia.com/badge?p=traceur-loader
183
180
  [coffee-npm]: https://img.shields.io/npm/v/coffee-loader.svg
184
181
  [coffee-size]: https://packagephobia.com/badge?p=coffee-loader
185
182
  [type-npm]: https://img.shields.io/npm/v/ts-loader.svg
package/bin/webpack.js CHANGED
@@ -32,13 +32,28 @@ const runCommand = (command, args) => {
32
32
  * @returns {boolean} is the package installed?
33
33
  */
34
34
  const isInstalled = packageName => {
35
- try {
36
- require.resolve(packageName);
37
-
35
+ if (process.versions.pnp) {
38
36
  return true;
39
- } catch (err) {
40
- return false;
41
37
  }
38
+
39
+ const path = require("path");
40
+ const fs = require("graceful-fs");
41
+
42
+ let dir = __dirname;
43
+
44
+ do {
45
+ try {
46
+ if (
47
+ fs.statSync(path.join(dir, "node_modules", packageName)).isDirectory()
48
+ ) {
49
+ return true;
50
+ }
51
+ } catch (_error) {
52
+ // Nothing
53
+ }
54
+ } while (dir !== (dir = path.dirname(dir)));
55
+
56
+ return false;
42
57
  };
43
58
 
44
59
  /**
@@ -25,8 +25,6 @@ class AsyncDependencyToInitialChunkError extends WebpackError {
25
25
  this.name = "AsyncDependencyToInitialChunkError";
26
26
  this.module = module;
27
27
  this.loc = loc;
28
-
29
- Error.captureStackTrace(this, this.constructor);
30
28
  }
31
29
  }
32
30
 
@@ -90,9 +90,9 @@ class MultiItemCache {
90
90
  * @returns {Promise<void>} promise signals when the value is stored
91
91
  */
92
92
  storePromise(data) {
93
- return Promise.all(
94
- this._items.map(item => item.storePromise(data))
95
- ).then(() => {});
93
+ return Promise.all(this._items.map(item => item.storePromise(data))).then(
94
+ () => {}
95
+ );
96
96
  }
97
97
  }
98
98
 
@@ -65,8 +65,6 @@ ${modulesList}`);
65
65
 
66
66
  this.name = "CaseSensitiveModulesWarning";
67
67
  this.module = sortedModules[0];
68
-
69
- Error.captureStackTrace(this, this.constructor);
70
68
  }
71
69
  }
72
70
 
package/lib/Chunk.js CHANGED
@@ -547,9 +547,8 @@ class Chunk {
547
547
  xor.add(chunkGraph.getModuleHash(m, this.runtime));
548
548
  }
549
549
  xor.updateHash(hash);
550
- const entryModules = chunkGraph.getChunkEntryModulesWithChunkGroupIterable(
551
- this
552
- );
550
+ const entryModules =
551
+ chunkGraph.getChunkEntryModulesWithChunkGroupIterable(this);
553
552
  for (const [m, chunkGroup] of entryModules) {
554
553
  hash.update("entry");
555
554
  hash.update(`${chunkGraph.getModuleId(m)}`);
@@ -599,8 +598,12 @@ class Chunk {
599
598
  */
600
599
  getAllInitialChunks() {
601
600
  const chunks = new Set();
602
- for (const group of this.groupsIterable) {
603
- for (const c of group.chunks) chunks.add(c);
601
+ const queue = new Set(this.groupsIterable);
602
+ for (const group of queue) {
603
+ if (group.isInitial()) {
604
+ for (const c of group.chunks) chunks.add(c);
605
+ for (const g of group.childrenIterable) queue.add(g);
606
+ }
604
607
  }
605
608
  return chunks;
606
609
  }
@@ -25,8 +25,6 @@ class ChunkRenderError extends WebpackError {
25
25
  this.details = error.stack;
26
26
  this.file = file;
27
27
  this.chunk = chunk;
28
-
29
- Error.captureStackTrace(this, this.constructor);
30
28
  }
31
29
  }
32
30
 
@@ -23,8 +23,6 @@ class CodeGenerationError extends WebpackError {
23
23
  this.message = error.message;
24
24
  this.details = error.stack;
25
25
  this.module = module;
26
-
27
- Error.captureStackTrace(this, this.constructor);
28
26
  }
29
27
  }
30
28
 
@@ -22,8 +22,6 @@ class CommentCompilationWarning extends WebpackError {
22
22
  this.name = "CommentCompilationWarning";
23
23
 
24
24
  this.loc = loc;
25
-
26
- Error.captureStackTrace(this, this.constructor);
27
25
  }
28
26
  }
29
27
 
@@ -510,7 +510,8 @@ class Compilation {
510
510
  * @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
511
511
  */
512
512
  const createProcessAssetsHook = (name, stage, getArgs, code) => {
513
- const errorMessage = reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
513
+ const errorMessage =
514
+ reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
514
515
  BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
515
516
  const getOptions = options => {
516
517
  if (typeof options === "string") options = { name: options };
@@ -1615,9 +1616,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1615
1616
  let creatingModuleDuringBuildSet = undefined;
1616
1617
  if (!recursive && this.buildQueue.isProcessing(originModule)) {
1617
1618
  // Track build dependency
1618
- creatingModuleDuringBuildSet = this.creatingModuleDuringBuild.get(
1619
- originModule
1620
- );
1619
+ creatingModuleDuringBuildSet =
1620
+ this.creatingModuleDuringBuild.get(originModule);
1621
1621
  if (creatingModuleDuringBuildSet === undefined) {
1622
1622
  creatingModuleDuringBuildSet = new Set();
1623
1623
  this.creatingModuleDuringBuild.set(
@@ -1746,11 +1746,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1746
1746
  module: result
1747
1747
  };
1748
1748
  }
1749
- const {
1750
- fileDependencies,
1751
- contextDependencies,
1752
- missingDependencies
1753
- } = result;
1749
+ const { fileDependencies, contextDependencies, missingDependencies } =
1750
+ result;
1754
1751
  if (fileDependencies) {
1755
1752
  this.fileDependencies.addAll(fileDependencies);
1756
1753
  }
@@ -2316,7 +2313,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2316
2313
  }
2317
2314
  ] of this.entries) {
2318
2315
  if (dependOn && runtime) {
2319
- const err = new WebpackError(`Entrypoint '${name}' has 'dependOn' and 'runtime' specified. This is not valid.
2316
+ const err =
2317
+ new WebpackError(`Entrypoint '${name}' has 'dependOn' and 'runtime' specified. This is not valid.
2320
2318
  Entrypoints that depend on other entrypoints do not have their own runtime.
2321
2319
  They will use the runtime(s) from referenced entrypoints instead.
2322
2320
  Remove the 'runtime' option from the entrypoint.`);
@@ -2357,11 +2355,12 @@ Remove the 'runtime' option from the entrypoint.`);
2357
2355
  let chunk = this.namedChunks.get(runtime);
2358
2356
  if (chunk) {
2359
2357
  if (!runtimeChunks.has(chunk)) {
2360
- const err = new WebpackError(`Entrypoint '${name}' has a 'runtime' option which points to another entrypoint named '${runtime}'.
2358
+ const err =
2359
+ new WebpackError(`Entrypoint '${name}' has a 'runtime' option which points to another entrypoint named '${runtime}'.
2361
2360
  It's not valid to use other entrypoints as runtime chunk.
2362
2361
  Did you mean to use 'dependOn: ${JSON.stringify(
2363
- runtime
2364
- )}' instead to allow using entrypoint '${name}' within the runtime of entrypoint '${runtime}'? For this '${runtime}' must always be loaded when '${name}' is used.
2362
+ runtime
2363
+ )}' instead to allow using entrypoint '${name}' within the runtime of entrypoint '${runtime}'? For this '${runtime}' must always be loaded when '${name}' is used.
2365
2364
  Or do you want to use the entrypoints '${name}' and '${runtime}' independently on the same page with a shared runtime? In this case give them both the same value for the 'runtime' option. It must be a name not already used by an entrypoint.`);
2366
2365
  const entryChunk = entry.getEntrypointChunk();
2367
2366
  err.chunk = entryChunk;
@@ -2621,12 +2620,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2621
2620
  _runCodeGenerationJobs(jobs, callback) {
2622
2621
  let statModulesFromCache = 0;
2623
2622
  let statModulesGenerated = 0;
2624
- const {
2625
- chunkGraph,
2626
- moduleGraph,
2627
- dependencyTemplates,
2628
- runtimeTemplate
2629
- } = this;
2623
+ const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
2624
+ this;
2630
2625
  const results = this.codeGenerationResults;
2631
2626
  const errors = [];
2632
2627
  asyncLib.eachLimit(
@@ -2773,17 +2768,15 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2773
2768
  chunkGraphEntries = this._getChunkGraphEntries()
2774
2769
  } = {}) {
2775
2770
  const context = { chunkGraph, codeGenerationResults };
2776
- const additionalModuleRuntimeRequirements = this.hooks
2777
- .additionalModuleRuntimeRequirements;
2771
+ const additionalModuleRuntimeRequirements =
2772
+ this.hooks.additionalModuleRuntimeRequirements;
2778
2773
  const runtimeRequirementInModule = this.hooks.runtimeRequirementInModule;
2779
2774
  for (const module of modules) {
2780
2775
  if (chunkGraph.getNumberOfModuleChunks(module) > 0) {
2781
2776
  for (const runtime of chunkGraph.getModuleRuntimes(module)) {
2782
2777
  let set;
2783
- const runtimeRequirements = codeGenerationResults.getRuntimeRequirements(
2784
- module,
2785
- runtime
2786
- );
2778
+ const runtimeRequirements =
2779
+ codeGenerationResults.getRuntimeRequirements(module, runtime);
2787
2780
  if (runtimeRequirements && runtimeRequirements.size > 0) {
2788
2781
  set = new Set(runtimeRequirements);
2789
2782
  } else if (additionalModuleRuntimeRequirements.isUsed()) {
@@ -2823,9 +2816,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2823
2816
  for (const treeEntry of chunkGraphEntries) {
2824
2817
  const set = new Set();
2825
2818
  for (const chunk of treeEntry.getAllReferencedChunks()) {
2826
- const runtimeRequirements = chunkGraph.getChunkRuntimeRequirements(
2827
- chunk
2828
- );
2819
+ const runtimeRequirements =
2820
+ chunkGraph.getChunkRuntimeRequirements(chunk);
2829
2821
  for (const r of runtimeRequirements) set.add(r);
2830
2822
  }
2831
2823
 
@@ -3223,9 +3215,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3223
3215
  runtime,
3224
3216
  runtimeTemplate
3225
3217
  });
3226
- const moduleHashDigest = /** @type {string} */ (moduleHash.digest(
3227
- hashDigest
3228
- ));
3218
+ const moduleHashDigest = /** @type {string} */ (
3219
+ moduleHash.digest(hashDigest)
3220
+ );
3229
3221
  chunkGraph.setModuleHashes(
3230
3222
  module,
3231
3223
  runtime,
@@ -3354,10 +3346,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3354
3346
  }
3355
3347
  }
3356
3348
  circularRuntimeChunkInfo.sort(compareSelect(i => i.chunk, byId));
3357
- const err = new WebpackError(`Circular dependency between chunks with runtime (${Array.from(
3358
- circularRuntimeChunkInfo,
3359
- c => c.chunk.name || c.chunk.id
3360
- ).join(", ")})
3349
+ const err =
3350
+ new WebpackError(`Circular dependency between chunks with runtime (${Array.from(
3351
+ circularRuntimeChunkInfo,
3352
+ c => c.chunk.name || c.chunk.id
3353
+ ).join(", ")})
3361
3354
  This prevents using hashes of each other and should be avoided.`);
3362
3355
  err.chunk = circularRuntimeChunkInfo[0].chunk;
3363
3356
  this.warnings.push(err);
@@ -3420,15 +3413,14 @@ This prevents using hashes of each other and should be avoided.`);
3420
3413
  moduleGraph: this.moduleGraph,
3421
3414
  runtimeTemplate: this.runtimeTemplate
3422
3415
  });
3423
- const chunkHashDigest = /** @type {string} */ (chunkHash.digest(
3424
- hashDigest
3425
- ));
3416
+ const chunkHashDigest = /** @type {string} */ (
3417
+ chunkHash.digest(hashDigest)
3418
+ );
3426
3419
  hash.update(chunkHashDigest);
3427
3420
  chunk.hash = chunkHashDigest;
3428
3421
  chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
3429
- const fullHashModules = chunkGraph.getChunkFullHashModulesIterable(
3430
- chunk
3431
- );
3422
+ const fullHashModules =
3423
+ chunkGraph.getChunkFullHashModulesIterable(chunk);
3432
3424
  if (fullHashModules) {
3433
3425
  fullHashChunks.add(chunk);
3434
3426
  } else {
@@ -3459,9 +3451,9 @@ This prevents using hashes of each other and should be avoided.`);
3459
3451
  runtime: chunk.runtime,
3460
3452
  runtimeTemplate
3461
3453
  });
3462
- const moduleHashDigest = /** @type {string} */ (moduleHash.digest(
3463
- hashDigest
3464
- ));
3454
+ const moduleHashDigest = /** @type {string} */ (
3455
+ moduleHash.digest(hashDigest)
3456
+ );
3465
3457
  const oldHash = chunkGraph.getModuleHash(module, chunk.runtime);
3466
3458
  chunkGraph.setModuleHashes(
3467
3459
  module,
@@ -3474,9 +3466,9 @@ This prevents using hashes of each other and should be avoided.`);
3474
3466
  const chunkHash = createHash(hashFunction);
3475
3467
  chunkHash.update(chunk.hash);
3476
3468
  chunkHash.update(this.hash);
3477
- const chunkHashDigest = /** @type {string} */ (chunkHash.digest(
3478
- hashDigest
3479
- ));
3469
+ const chunkHashDigest = /** @type {string} */ (
3470
+ chunkHash.digest(hashDigest)
3471
+ );
3480
3472
  chunk.hash = chunkHashDigest;
3481
3473
  chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
3482
3474
  this.hooks.contentHash.call(chunk);
@@ -4051,11 +4043,8 @@ This prevents using hashes of each other and should be avoided.`);
4051
4043
  // Create new chunk graph, chunk and entrypoint for the build time execution
4052
4044
  const chunkGraph = new ChunkGraph(this.moduleGraph);
4053
4045
  const runtime = "build time";
4054
- const {
4055
- hashFunction,
4056
- hashDigest,
4057
- hashDigestLength
4058
- } = this.outputOptions;
4046
+ const { hashFunction, hashDigest, hashDigestLength } =
4047
+ this.outputOptions;
4059
4048
  const runtimeTemplate = this.runtimeTemplate;
4060
4049
 
4061
4050
  const chunk = new Chunk("build time chunk");
@@ -4151,9 +4140,8 @@ This prevents using hashes of each other and should be avoided.`);
4151
4140
  });
4152
4141
  this.chunkGraph = old;
4153
4142
 
4154
- const runtimeModules = chunkGraph.getChunkRuntimeModulesIterable(
4155
- chunk
4156
- );
4143
+ const runtimeModules =
4144
+ chunkGraph.getChunkRuntimeModulesIterable(chunk);
4157
4145
 
4158
4146
  // Hash runtime modules
4159
4147
  for (const module of runtimeModules) {
package/lib/Compiler.js CHANGED
@@ -230,6 +230,8 @@ class Compiler {
230
230
  this.fileTimestamps = undefined;
231
231
  /** @type {Map<string, FileSystemInfoEntry | "ignore" | null>} */
232
232
  this.contextTimestamps = undefined;
233
+ /** @type {number} */
234
+ this.fsStartTime = undefined;
233
235
 
234
236
  /** @type {ResolverFactory} */
235
237
  this.resolverFactory = new ResolverFactory();
@@ -590,9 +592,8 @@ class Compiler {
590
592
  allTargetPaths.add(targetPath);
591
593
 
592
594
  // check if the target file has already been written by this Compiler
593
- const targetFileGeneration = this._assetEmittingWrittenFiles.get(
594
- targetPath
595
- );
595
+ const targetFileGeneration =
596
+ this._assetEmittingWrittenFiles.get(targetPath);
596
597
 
597
598
  // create an cache entry for this Source if not already existing
598
599
  let cacheEntry = this._assetEmittingSourceCache.get(source);
@@ -622,7 +623,8 @@ class Compiler {
622
623
  }
623
624
  alreadyWritten();
624
625
  } else {
625
- const err = new WebpackError(`Prevent writing to file that only differs in casing or query string from already written file.
626
+ const err =
627
+ new WebpackError(`Prevent writing to file that only differs in casing or query string from already written file.
626
628
  This will lead to a race-condition and corrupted files on case-insensitive file systems.
627
629
  ${targetPath}
628
630
  ${other}`);
@@ -952,6 +954,7 @@ ${other}`);
952
954
  childCompiler.removedFiles = this.removedFiles;
953
955
  childCompiler.fileTimestamps = this.fileTimestamps;
954
956
  childCompiler.contextTimestamps = this.contextTimestamps;
957
+ childCompiler.fsStartTime = this.fsStartTime;
955
958
  childCompiler.cache = this.cache;
956
959
  childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`;
957
960
 
@@ -7,7 +7,8 @@
7
7
 
8
8
  /** @typedef {import("./Module")} Module */
9
9
 
10
- const MODULE_REFERENCE_REGEXP = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
10
+ const MODULE_REFERENCE_REGEXP =
11
+ /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
11
12
 
12
13
  const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
13
14
  const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
@@ -14,7 +14,5 @@ module.exports = class ConcurrentCompilationError extends WebpackError {
14
14
  this.name = "ConcurrentCompilationError";
15
15
  this.message =
16
16
  "You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.";
17
-
18
- Error.captureStackTrace(this, this.constructor);
19
17
  }
20
18
  };
@@ -54,6 +54,7 @@ const makeSerializable = require("./util/makeSerializable");
54
54
  * @property {RegExp=} include
55
55
  * @property {RegExp=} exclude
56
56
  * @property {RawChunkGroupOptions=} groupOptions
57
+ * @property {string=} typePrefix
57
58
  * @property {string=} category
58
59
  * @property {string[][]=} referencedExports exports referenced from modules (won't be mangled)
59
60
  */
@@ -577,7 +578,7 @@ class ContextModule extends Module {
577
578
  fakeMapDataExpression = "fakeMap[id]"
578
579
  ) {
579
580
  if (typeof fakeMap === "number") {
580
- return `return ${this.getReturn(fakeMap)};`;
581
+ return `return ${this.getReturn(fakeMap, asyncModule)};`;
581
582
  }
582
583
  return `return ${
583
584
  RuntimeGlobals.createFakeNamespaceObject
@@ -1016,9 +1017,9 @@ module.exports = webpackEmptyAsyncContext;`;
1016
1017
  this.getSource(this.getSourceString(this.options.mode, context))
1017
1018
  );
1018
1019
  const set = new Set();
1019
- const allDeps = /** @type {ContextElementDependency[]} */ (this.dependencies.concat(
1020
- this.blocks.map(b => b.dependencies[0])
1021
- ));
1020
+ const allDeps = /** @type {ContextElementDependency[]} */ (
1021
+ this.dependencies.concat(this.blocks.map(b => b.dependencies[0]))
1022
+ );
1022
1023
  set.add(RuntimeGlobals.module);
1023
1024
  set.add(RuntimeGlobals.hasOwnProperty);
1024
1025
  if (allDeps.length > 0) {
@@ -273,7 +273,8 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
273
273
  include,
274
274
  exclude,
275
275
  referencedExports,
276
- category
276
+ category,
277
+ typePrefix
277
278
  } = options;
278
279
  if (!regExp || !resource) return callback(null, []);
279
280
 
@@ -346,6 +347,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
346
347
  const dep = new ContextElementDependency(
347
348
  obj.request + resourceQuery + resourceFragment,
348
349
  obj.request,
350
+ typePrefix,
349
351
  category,
350
352
  referencedExports
351
353
  );
@@ -104,9 +104,10 @@ class ContextReplacementPlugin {
104
104
  result.regExp = newContentRegExp;
105
105
  }
106
106
  if (typeof newContentCreateContextMap === "function") {
107
- result.resolveDependencies = createResolveDependenciesFromContextMap(
108
- newContentCreateContextMap
109
- );
107
+ result.resolveDependencies =
108
+ createResolveDependenciesFromContextMap(
109
+ newContentCreateContextMap
110
+ );
110
111
  }
111
112
  if (typeof newContentCallback === "function") {
112
113
  const origResource = result.resource;
@@ -89,9 +89,9 @@ class RuntimeValue {
89
89
  module: parser.state.module,
90
90
  key,
91
91
  get version() {
92
- return /** @type {string} */ (valueCacheVersions.get(
93
- VALUE_DEP_PREFIX + key
94
- ));
92
+ return /** @type {string} */ (
93
+ valueCacheVersions.get(VALUE_DEP_PREFIX + key)
94
+ );
95
95
  }
96
96
  });
97
97
  }
@@ -286,11 +286,13 @@ class DefinePlugin {
286
286
  );
287
287
  const { runtimeTemplate } = compilation;
288
288
 
289
- const mainValue = /** @type {Set<string>} */ (provide(
290
- compilation.valueCacheVersions,
291
- VALUE_DEP_MAIN,
292
- () => new Set()
293
- ));
289
+ const mainValue = /** @type {Set<string>} */ (
290
+ provide(
291
+ compilation.valueCacheVersions,
292
+ VALUE_DEP_MAIN,
293
+ () => new Set()
294
+ )
295
+ );
294
296
 
295
297
  /**
296
298
  * Handler
@@ -313,10 +315,12 @@ class DefinePlugin {
313
315
  );
314
316
  };
315
317
 
316
- const withValueDependency = (key, fn) => (...args) => {
317
- addValueDependency(key);
318
- return fn(...args);
319
- };
318
+ const withValueDependency =
319
+ (key, fn) =>
320
+ (...args) => {
321
+ addValueDependency(key);
322
+ return fn(...args);
323
+ };
320
324
 
321
325
  /**
322
326
  * Walk definitions
@@ -156,8 +156,6 @@ class DllManifestError extends WebpackError {
156
156
 
157
157
  this.name = "DllManifestError";
158
158
  this.message = `Dll manifest ${filename}\n${message}`;
159
-
160
- Error.captureStackTrace(this, this.constructor);
161
159
  }
162
160
  }
163
161
 
@@ -41,10 +41,10 @@ class EntryPlugin {
41
41
  }
42
42
  );
43
43
 
44
- compiler.hooks.make.tapAsync("EntryPlugin", (compilation, callback) => {
45
- const { entry, options, context } = this;
44
+ const { entry, options, context } = this;
45
+ const dep = EntryPlugin.createDependency(entry, options);
46
46
 
47
- const dep = EntryPlugin.createDependency(entry, options);
47
+ compiler.hooks.make.tapAsync("EntryPlugin", (compilation, callback) => {
48
48
  compilation.addEntry(context, dep, options, err => {
49
49
  callback(err);
50
50
  });
@@ -91,7 +91,9 @@ class EvalSourceMapDevToolPlugin {
91
91
  } else if (m instanceof ConcatenatedModule) {
92
92
  const concatModule = /** @type {ConcatenatedModule} */ (m);
93
93
  if (concatModule.rootModule instanceof NormalModule) {
94
- const module = /** @type {NormalModule} */ (concatModule.rootModule);
94
+ const module = /** @type {NormalModule} */ (
95
+ concatModule.rootModule
96
+ );
95
97
  if (!matchModule(module.resource)) {
96
98
  return result(source);
97
99
  }
@@ -137,18 +137,22 @@ class ExportsInfo {
137
137
 
138
138
  _sortExportsMap(exports) {
139
139
  if (exports.size > 1) {
140
- const entriesInOrder = Array.from(exports.values());
141
- if (
142
- entriesInOrder.length !== 2 ||
143
- entriesInOrder[0].name > entriesInOrder[1].name
144
- ) {
145
- entriesInOrder.sort((a, b) => {
146
- return a.name < b.name ? -1 : 1;
147
- });
148
- exports.clear();
149
- for (const entry of entriesInOrder) {
150
- exports.set(entry.name, entry);
151
- }
140
+ const namesInOrder = [];
141
+ for (const entry of exports.values()) {
142
+ namesInOrder.push(entry.name);
143
+ }
144
+ namesInOrder.sort();
145
+ let i = 0;
146
+ for (const entry of exports.values()) {
147
+ const name = namesInOrder[i];
148
+ if (entry.name !== name) break;
149
+ i++;
150
+ }
151
+ for (; i < namesInOrder.length; i++) {
152
+ const name = namesInOrder[i];
153
+ const correctEntry = exports.get(name);
154
+ exports.delete(name);
155
+ exports.set(name, correctEntry);
152
156
  }
153
157
  }
154
158
  }
@@ -722,7 +726,7 @@ class ExportsInfo {
722
726
  const otherCanMangleProvide = this._otherExportsInfo.canMangleProvide;
723
727
  const otherTerminalBinding = this._otherExportsInfo.terminalBinding;
724
728
  const exports = [];
725
- for (const exportInfo of this._exports.values()) {
729
+ for (const exportInfo of this.orderedExports) {
726
730
  if (
727
731
  exportInfo.provided !== otherProvided ||
728
732
  exportInfo.canMangleProvide !== otherCanMangleProvide ||
@@ -754,7 +758,9 @@ class ExportsInfo {
754
758
  otherTerminalBinding,
755
759
  exports
756
760
  }) {
761
+ let wasEmpty = true;
757
762
  for (const exportInfo of this._exports.values()) {
763
+ wasEmpty = false;
758
764
  exportInfo.provided = otherProvided;
759
765
  exportInfo.canMangleProvide = otherCanMangleProvide;
760
766
  exportInfo.terminalBinding = otherTerminalBinding;
@@ -772,6 +778,7 @@ class ExportsInfo {
772
778
  exportsInfo.restoreProvided(exp.exportsInfo);
773
779
  }
774
780
  }
781
+ if (wasEmpty) this._exportsAreOrdered = true;
775
782
  }
776
783
  }
777
784