webpack 5.36.2 → 5.38.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 (113) hide show
  1. package/README.md +5 -8
  2. package/bin/webpack.js +0 -0
  3. package/lib/CacheFacade.js +3 -3
  4. package/lib/Chunk.js +10 -5
  5. package/lib/Compilation.js +45 -57
  6. package/lib/Compiler.js +9 -6
  7. package/lib/ConcatenationScope.js +2 -1
  8. package/lib/ContextModule.js +3 -3
  9. package/lib/ContextReplacementPlugin.js +4 -3
  10. package/lib/DefinePlugin.js +16 -12
  11. package/lib/EntryPlugin.js +4 -4
  12. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  13. package/lib/ExportsInfo.js +20 -13
  14. package/lib/FileSystemInfo.js +25 -31
  15. package/lib/FlagDependencyExportsPlugin.js +8 -7
  16. package/lib/FlagDependencyUsagePlugin.js +2 -4
  17. package/lib/HotModuleReplacementPlugin.js +27 -32
  18. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  19. package/lib/MainTemplate.js +2 -3
  20. package/lib/ModuleFilenameHelpers.js +4 -2
  21. package/lib/ModuleGraphConnection.js +6 -2
  22. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  23. package/lib/MultiCompiler.js +31 -27
  24. package/lib/NormalModule.js +42 -8
  25. package/lib/NormalModuleFactory.js +2 -0
  26. package/lib/RecordIdsPlugin.js +5 -4
  27. package/lib/ResolverFactory.js +10 -7
  28. package/lib/RuntimeGlobals.js +7 -0
  29. package/lib/RuntimePlugin.js +19 -1
  30. package/lib/SourceMapDevToolPlugin.js +14 -15
  31. package/lib/Template.js +4 -2
  32. package/lib/Watching.js +91 -47
  33. package/lib/asset/AssetGenerator.js +46 -29
  34. package/lib/asset/AssetModulesPlugin.js +1 -1
  35. package/lib/buildChunkGraph.js +21 -21
  36. package/lib/cache/PackFileCacheStrategy.js +12 -9
  37. package/lib/config/defaults.js +31 -10
  38. package/lib/config/normalization.js +16 -7
  39. package/lib/config/target.js +7 -2
  40. package/lib/debug/ProfilingPlugin.js +4 -3
  41. package/lib/dependencies/AMDRequireDependency.js +3 -3
  42. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  43. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  44. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  45. package/lib/dependencies/CommonJsPlugin.js +8 -7
  46. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  47. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  48. package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
  49. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  50. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  51. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  52. package/lib/dependencies/ImportDependency.js +3 -3
  53. package/lib/dependencies/ImportParserPlugin.js +2 -4
  54. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  55. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  56. package/lib/dependencies/WorkerDependency.js +6 -6
  57. package/lib/dependencies/WorkerPlugin.js +32 -20
  58. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  59. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  60. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  61. package/lib/index.js +5 -3
  62. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  63. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  64. package/lib/javascript/JavascriptGenerator.js +3 -1
  65. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  66. package/lib/javascript/JavascriptParser.js +10 -8
  67. package/lib/library/AssignLibraryPlugin.js +4 -2
  68. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  69. package/lib/node/NodeWatchFileSystem.js +19 -4
  70. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  71. package/lib/optimize/ConcatenatedModule.js +31 -27
  72. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  73. package/lib/optimize/InnerGraph.js +9 -11
  74. package/lib/optimize/InnerGraphPlugin.js +3 -1
  75. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  76. package/lib/optimize/RealContentHashPlugin.js +14 -16
  77. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  78. package/lib/optimize/SplitChunksPlugin.js +13 -15
  79. package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
  80. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  81. package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
  82. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  83. package/lib/schemes/DataUriPlugin.js +21 -2
  84. package/lib/serialization/BinaryMiddleware.js +5 -3
  85. package/lib/serialization/FileMiddleware.js +3 -1
  86. package/lib/serialization/ObjectMiddleware.js +11 -7
  87. package/lib/stats/DefaultStatsFactoryPlugin.js +7 -7
  88. package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
  89. package/lib/stats/StatsFactory.js +2 -1
  90. package/lib/stats/StatsPrinter.js +3 -3
  91. package/lib/util/LazyBucketSortedSet.js +3 -3
  92. package/lib/util/cleverMerge.js +3 -1
  93. package/lib/util/comparators.js +13 -13
  94. package/lib/util/createHash.js +5 -4
  95. package/lib/util/fs.js +8 -8
  96. package/lib/util/identifier.js +2 -1
  97. package/lib/util/internalSerializables.js +2 -0
  98. package/lib/util/serialization.js +108 -59
  99. package/lib/validateSchema.js +5 -3
  100. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  101. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  102. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  103. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  104. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  105. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  106. package/lib/webpack.js +11 -7
  107. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
  108. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
  109. package/package.json +10 -7
  110. package/schemas/WebpackOptions.check.js +1 -1
  111. package/schemas/WebpackOptions.json +107 -60
  112. package/types.d.ts +480 -285
  113. 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
File without changes
@@ -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
 
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)}`);
@@ -568,9 +567,15 @@ class Chunk {
568
567
  Array.from(this.groupsIterable, g => new Set(g.chunks))
569
568
  );
570
569
 
571
- for (const chunkGroup of this.groupsIterable) {
570
+ const initialQueue = new Set(this.groupsIterable);
571
+
572
+ for (const chunkGroup of initialQueue) {
572
573
  for (const child of chunkGroup.childrenIterable) {
573
- queue.add(child);
574
+ if (child instanceof Entrypoint) {
575
+ initialQueue.add(child);
576
+ } else {
577
+ queue.add(child);
578
+ }
574
579
  }
575
580
  }
576
581
 
@@ -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);
@@ -3993,8 +3985,8 @@ This prevents using hashes of each other and should be avoided.`);
3993
3985
  * from parent (or top level compiler) and creates a child Compilation
3994
3986
  *
3995
3987
  * @param {string} name name of the child compiler
3996
- * @param {OutputOptions} outputOptions // Need to convert config schema to types for this
3997
- * @param {Array<WebpackPluginInstance | WebpackPluginFunction>} plugins webpack plugins that will be applied
3988
+ * @param {OutputOptions=} outputOptions // Need to convert config schema to types for this
3989
+ * @param {Array<WebpackPluginInstance | WebpackPluginFunction>=} plugins webpack plugins that will be applied
3998
3990
  * @returns {Compiler} creates a child Compiler instance
3999
3991
  */
4000
3992
  createChildCompiler(name, outputOptions, plugins) {
@@ -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}`);
@@ -931,8 +933,8 @@ ${other}`);
931
933
  * @param {Compilation} compilation the compilation
932
934
  * @param {string} compilerName the compiler's name
933
935
  * @param {number} compilerIndex the compiler's index
934
- * @param {OutputOptions} outputOptions the output options
935
- * @param {WebpackPluginInstance[]} plugins the plugins to apply
936
+ * @param {OutputOptions=} outputOptions the output options
937
+ * @param {WebpackPluginInstance[]=} plugins the plugins to apply
936
938
  * @returns {Compiler} a child compiler
937
939
  */
938
940
  createChildCompiler(
@@ -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__";
@@ -1016,9 +1016,9 @@ module.exports = webpackEmptyAsyncContext;`;
1016
1016
  this.getSource(this.getSourceString(this.options.mode, context))
1017
1017
  );
1018
1018
  const set = new Set();
1019
- const allDeps = /** @type {ContextElementDependency[]} */ (this.dependencies.concat(
1020
- this.blocks.map(b => b.dependencies[0])
1021
- ));
1019
+ const allDeps = /** @type {ContextElementDependency[]} */ (
1020
+ this.dependencies.concat(this.blocks.map(b => b.dependencies[0]))
1021
+ );
1022
1022
  set.add(RuntimeGlobals.module);
1023
1023
  set.add(RuntimeGlobals.hasOwnProperty);
1024
1024
  if (allDeps.length > 0) {
@@ -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
@@ -17,7 +17,7 @@ class EntryPlugin {
17
17
  *
18
18
  * @param {string} context context path
19
19
  * @param {string} entry entry path
20
- * @param {EntryOptions | string} options entry options (passing a string is deprecated)
20
+ * @param {EntryOptions | string=} options entry options (passing a string is deprecated)
21
21
  */
22
22
  constructor(context, entry, options) {
23
23
  this.context = context;
@@ -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
 
@@ -1160,12 +1160,8 @@ class FileSystemInfo {
1160
1160
  * @returns {void}
1161
1161
  */
1162
1162
  resolveBuildDependencies(context, deps, callback) {
1163
- const {
1164
- resolveContext,
1165
- resolveEsm,
1166
- resolveCjs,
1167
- resolveCjsAsChild
1168
- } = this._createBuildDependenciesResolvers();
1163
+ const { resolveContext, resolveEsm, resolveCjs, resolveCjsAsChild } =
1164
+ this._createBuildDependenciesResolvers();
1169
1165
 
1170
1166
  /** @type {Set<string>} */
1171
1167
  const files = new Set();
@@ -1472,7 +1468,7 @@ class FileSystemInfo {
1472
1468
  }
1473
1469
  } else if (supportsEsm && /\.m?js$/.test(path)) {
1474
1470
  if (!this._warnAboutExperimentalEsmTracking) {
1475
- this.logger.info(
1471
+ this.logger.log(
1476
1472
  "Node.js doesn't offer a (nice) way to introspect the ESM dependency graph yet.\n" +
1477
1473
  "Until a full solution is available webpack uses an experimental ESM tracking based on parsing.\n" +
1478
1474
  "As best effort webpack parses the ESM files to guess dependencies. But this can lead to expensive and incorrect tracking."
@@ -1547,9 +1543,8 @@ class FileSystemInfo {
1547
1543
  break;
1548
1544
  }
1549
1545
  case RBDT_DIRECTORY_DEPENDENCIES: {
1550
- const match = /(^.+[\\/]node_modules[\\/](?:@[^\\/]+[\\/])?[^\\/]+)/.exec(
1551
- path
1552
- );
1546
+ const match =
1547
+ /(^.+[\\/]node_modules[\\/](?:@[^\\/]+[\\/])?[^\\/]+)/.exec(path);
1553
1548
  const packagePath = match ? match[1] : path;
1554
1549
  const packageJson = join(this.fs, packagePath, "package.json");
1555
1550
  this.fs.readFile(packageJson, (err, content) => {
@@ -1637,12 +1632,8 @@ class FileSystemInfo {
1637
1632
  * @returns {void}
1638
1633
  */
1639
1634
  checkResolveResultsValid(resolveResults, callback) {
1640
- const {
1641
- resolveCjs,
1642
- resolveCjsAsChild,
1643
- resolveEsm,
1644
- resolveContext
1645
- } = this._createBuildDependenciesResolvers();
1635
+ const { resolveCjs, resolveCjsAsChild, resolveEsm, resolveContext } =
1636
+ this._createBuildDependenciesResolvers();
1646
1637
  asyncLib.eachLimit(
1647
1638
  resolveResults,
1648
1639
  20,
@@ -1844,11 +1835,12 @@ class FileSystemInfo {
1844
1835
  unsharedManagedFiles
1845
1836
  );
1846
1837
  }
1847
- const unsharedManagedContexts = this._managedContextsOptimization.optimize(
1848
- managedContexts,
1849
- undefined,
1850
- children
1851
- );
1838
+ const unsharedManagedContexts =
1839
+ this._managedContextsOptimization.optimize(
1840
+ managedContexts,
1841
+ undefined,
1842
+ children
1843
+ );
1852
1844
  if (managedContexts.size !== 0) {
1853
1845
  snapshot.setManagedContexts(managedContexts);
1854
1846
  this._managedContextsOptimization.storeUnsharedSnapshot(
@@ -1856,11 +1848,12 @@ class FileSystemInfo {
1856
1848
  unsharedManagedContexts
1857
1849
  );
1858
1850
  }
1859
- const unsharedManagedMissing = this._managedMissingOptimization.optimize(
1860
- managedMissing,
1861
- undefined,
1862
- children
1863
- );
1851
+ const unsharedManagedMissing =
1852
+ this._managedMissingOptimization.optimize(
1853
+ managedMissing,
1854
+ undefined,
1855
+ children
1856
+ );
1864
1857
  if (managedMissing.size !== 0) {
1865
1858
  snapshot.setManagedMissing(managedMissing);
1866
1859
  this._managedMissingOptimization.storeUnsharedSnapshot(
@@ -2064,11 +2057,12 @@ class FileSystemInfo {
2064
2057
  }
2065
2058
  break;
2066
2059
  case 1:
2067
- unsharedContextTimestamps = this._contextTimestampsOptimization.optimize(
2068
- capturedDirectories,
2069
- startTime,
2070
- children
2071
- );
2060
+ unsharedContextTimestamps =
2061
+ this._contextTimestampsOptimization.optimize(
2062
+ capturedDirectories,
2063
+ startTime,
2064
+ children
2065
+ );
2072
2066
  for (const path of capturedDirectories) {
2073
2067
  const cache = this._contextTimestamps.get(path);
2074
2068
  if (cache !== undefined) {