webpack 5.36.0 → 5.37.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 (110) 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/ChunkGraph.js +58 -35
  6. package/lib/Compilation.js +116 -98
  7. package/lib/Compiler.js +31 -17
  8. package/lib/ConcatenationScope.js +2 -1
  9. package/lib/ContextModule.js +3 -3
  10. package/lib/ContextReplacementPlugin.js +4 -3
  11. package/lib/DefinePlugin.js +16 -12
  12. package/lib/EntryPlugin.js +1 -1
  13. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  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 +20 -30
  18. package/lib/InitFragment.js +21 -6
  19. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  20. package/lib/MainTemplate.js +2 -3
  21. package/lib/ModuleFilenameHelpers.js +4 -2
  22. package/lib/ModuleGraph.js +2 -2
  23. package/lib/ModuleGraphConnection.js +6 -2
  24. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  25. package/lib/MultiCompiler.js +31 -27
  26. package/lib/NormalModule.js +38 -7
  27. package/lib/NormalModuleFactory.js +27 -23
  28. package/lib/RecordIdsPlugin.js +5 -4
  29. package/lib/ResolverFactory.js +10 -7
  30. package/lib/RuntimeGlobals.js +7 -0
  31. package/lib/RuntimePlugin.js +19 -1
  32. package/lib/SourceMapDevToolPlugin.js +14 -15
  33. package/lib/Template.js +4 -2
  34. package/lib/Watching.js +83 -46
  35. package/lib/WebpackOptionsApply.js +1 -0
  36. package/lib/asset/AssetGenerator.js +19 -23
  37. package/lib/buildChunkGraph.js +28 -23
  38. package/lib/cache/PackFileCacheStrategy.js +77 -13
  39. package/lib/config/defaults.js +24 -10
  40. package/lib/config/normalization.js +17 -7
  41. package/lib/debug/ProfilingPlugin.js +4 -3
  42. package/lib/dependencies/AMDRequireDependency.js +3 -3
  43. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  44. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  45. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  46. package/lib/dependencies/CommonJsPlugin.js +8 -7
  47. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  48. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  49. package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
  50. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  51. package/lib/dependencies/HarmonyExportInitFragment.js +47 -0
  52. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  53. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  54. package/lib/dependencies/ImportDependency.js +3 -3
  55. package/lib/dependencies/ImportParserPlugin.js +2 -4
  56. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  57. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  58. package/lib/dependencies/WorkerDependency.js +6 -6
  59. package/lib/dependencies/WorkerPlugin.js +47 -20
  60. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  61. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  62. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  63. package/lib/index.js +5 -3
  64. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  65. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  66. package/lib/javascript/JavascriptGenerator.js +3 -1
  67. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  68. package/lib/javascript/JavascriptParser.js +10 -8
  69. package/lib/library/AssignLibraryPlugin.js +4 -2
  70. package/lib/node/NodeWatchFileSystem.js +19 -4
  71. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  72. package/lib/optimize/ConcatenatedModule.js +22 -27
  73. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  74. package/lib/optimize/InnerGraph.js +9 -11
  75. package/lib/optimize/InnerGraphPlugin.js +3 -1
  76. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  77. package/lib/optimize/RealContentHashPlugin.js +14 -16
  78. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  79. package/lib/optimize/SplitChunksPlugin.js +13 -15
  80. package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
  81. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  82. package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
  83. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  84. package/lib/serialization/BinaryMiddleware.js +2 -3
  85. package/lib/serialization/FileMiddleware.js +3 -1
  86. package/lib/serialization/ObjectMiddleware.js +11 -7
  87. package/lib/stats/DefaultStatsFactoryPlugin.js +2 -3
  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/fs.js +8 -8
  95. package/lib/util/identifier.js +2 -1
  96. package/lib/util/internalSerializables.js +2 -0
  97. package/lib/validateSchema.js +5 -3
  98. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  99. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  100. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  101. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  102. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  103. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  104. package/lib/webpack.js +11 -7
  105. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
  106. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
  107. package/package.json +9 -6
  108. package/schemas/WebpackOptions.check.js +1 -1
  109. package/schemas/WebpackOptions.json +103 -60
  110. package/types.d.ts +463 -280
@@ -519,7 +519,8 @@ const visitModules = (
519
519
  if (skipConnectionBuffer.length > 0) {
520
520
  let { skippedModuleConnections } = chunkGroupInfo;
521
521
  if (skippedModuleConnections === undefined) {
522
- chunkGroupInfo.skippedModuleConnections = skippedModuleConnections = new Set();
522
+ chunkGroupInfo.skippedModuleConnections = skippedModuleConnections =
523
+ new Set();
523
524
  }
524
525
  for (let i = skipConnectionBuffer.length - 1; i >= 0; i--) {
525
526
  skippedModuleConnections.add(skipConnectionBuffer[i]);
@@ -695,7 +696,8 @@ const visitModules = (
695
696
  let resultingAvailableModules;
696
697
  if (minAvailableModules.size > minAvailableModules.plus.size) {
697
698
  // resultingAvailableModules = (modules of chunk) + (minAvailableModules + minAvailableModules.plus)
698
- resultingAvailableModules = /** @type {Set<Module> & {plus: Set<Module>}} */ (new Set());
699
+ resultingAvailableModules =
700
+ /** @type {Set<Module> & {plus: Set<Module>}} */ (new Set());
699
701
  for (const module of minAvailableModules.plus)
700
702
  minAvailableModules.add(module);
701
703
  minAvailableModules.plus = EMPTY_SET;
@@ -703,9 +705,10 @@ const visitModules = (
703
705
  chunkGroupInfo.minAvailableModulesOwned = false;
704
706
  } else {
705
707
  // resultingAvailableModules = (minAvailableModules + modules of chunk) + (minAvailableModules.plus)
706
- resultingAvailableModules = /** @type {Set<Module> & {plus: Set<Module>}} */ (new Set(
707
- minAvailableModules
708
- ));
708
+ resultingAvailableModules =
709
+ /** @type {Set<Module> & {plus: Set<Module>}} */ (
710
+ new Set(minAvailableModules)
711
+ );
709
712
  resultingAvailableModules.plus = minAvailableModules.plus;
710
713
  }
711
714
 
@@ -715,7 +718,8 @@ const visitModules = (
715
718
  resultingAvailableModules.add(m);
716
719
  }
717
720
  }
718
- return (chunkGroupInfo.resultingAvailableModules = resultingAvailableModules);
721
+ return (chunkGroupInfo.resultingAvailableModules =
722
+ resultingAvailableModules);
719
723
  };
720
724
 
721
725
  const processConnectQueue = () => {
@@ -732,9 +736,8 @@ const visitModules = (
732
736
  }
733
737
 
734
738
  // 2. Calculate resulting available modules
735
- const resultingAvailableModules = calculateResultingAvailableModules(
736
- chunkGroupInfo
737
- );
739
+ const resultingAvailableModules =
740
+ calculateResultingAvailableModules(chunkGroupInfo);
738
741
 
739
742
  const runtime = chunkGroupInfo.runtime;
740
743
 
@@ -800,9 +803,8 @@ const visitModules = (
800
803
  if (!availableModules.has(m) && !availableModules.plus.has(m)) {
801
804
  // We can't remove modules from the plus part
802
805
  // so we need to merge plus into the normal part to allow modifying it
803
- const iterator = cachedMinAvailableModules.plus[
804
- Symbol.iterator
805
- ]();
806
+ const iterator =
807
+ cachedMinAvailableModules.plus[Symbol.iterator]();
806
808
  // fast forward add all modules until m
807
809
  /** @type {IteratorResult<Module>} */
808
810
  let it;
@@ -951,13 +953,12 @@ const visitModules = (
951
953
  statForkedMergedModulesCountPlus += availableModules.plus.size;
952
954
  // construct a new Set as intersection of cachedMinAvailableModules and availableModules
953
955
  // we already know that all modules directly from cachedMinAvailableModules are in availableModules too
954
- const newSet = /** @type {ModuleSetPlus} */ (new Set(
955
- cachedMinAvailableModules
956
- ));
956
+ const newSet = /** @type {ModuleSetPlus} */ (
957
+ new Set(cachedMinAvailableModules)
958
+ );
957
959
  newSet.plus = EMPTY_SET;
958
- const iterator = cachedMinAvailableModules.plus[
959
- Symbol.iterator
960
- ]();
960
+ const iterator =
961
+ cachedMinAvailableModules.plus[Symbol.iterator]();
961
962
  // fast forward add all modules until m
962
963
  /** @type {IteratorResult<Module>} */
963
964
  let it;
@@ -997,10 +998,15 @@ const visitModules = (
997
998
  };
998
999
 
999
1000
  const processChunkGroupsForCombining = () => {
1000
- loop: for (const info of chunkGroupsForCombining) {
1001
+ for (const info of chunkGroupsForCombining) {
1001
1002
  for (const source of info.availableSources) {
1002
- if (!source.minAvailableModules) continue loop;
1003
+ if (!source.minAvailableModules) {
1004
+ chunkGroupsForCombining.delete(info);
1005
+ break;
1006
+ }
1003
1007
  }
1008
+ }
1009
+ for (const info of chunkGroupsForCombining) {
1004
1010
  const availableModules = /** @type {ModuleSetPlus} */ (new Set());
1005
1011
  availableModules.plus = EMPTY_SET;
1006
1012
  const mergeSet = set => {
@@ -1013,9 +1019,8 @@ const visitModules = (
1013
1019
  };
1014
1020
  // combine minAvailableModules from all resultingAvailableModules
1015
1021
  for (const source of info.availableSources) {
1016
- const resultingAvailableModules = calculateResultingAvailableModules(
1017
- source
1018
- );
1022
+ const resultingAvailableModules =
1023
+ calculateResultingAvailableModules(source);
1019
1024
  mergeSet(resultingAvailableModules);
1020
1025
  mergeSet(resultingAvailableModules.plus);
1021
1026
  }
@@ -561,7 +561,40 @@ class PackContentItems {
561
561
  this.map = map;
562
562
  }
563
563
 
564
- serialize({ write, snapshot, rollback, logger }) {
564
+ serialize({ write, snapshot, rollback, logger, profile }) {
565
+ if (profile) {
566
+ write(false);
567
+ for (const [key, value] of this.map) {
568
+ const s = snapshot();
569
+ try {
570
+ write(key);
571
+ const start = process.hrtime();
572
+ write(value);
573
+ const durationHr = process.hrtime(start);
574
+ const duration = durationHr[0] * 1000 + durationHr[1] / 1e6;
575
+ if (duration > 1) {
576
+ if (duration > 500)
577
+ logger.error(`Serialization of '${key}': ${duration} ms`);
578
+ else if (duration > 50)
579
+ logger.warn(`Serialization of '${key}': ${duration} ms`);
580
+ else if (duration > 10)
581
+ logger.info(`Serialization of '${key}': ${duration} ms`);
582
+ else if (duration > 5)
583
+ logger.log(`Serialization of '${key}': ${duration} ms`);
584
+ else logger.debug(`Serialization of '${key}': ${duration} ms`);
585
+ }
586
+ } catch (e) {
587
+ rollback(s);
588
+ if (e === NOT_SERIALIZABLE) continue;
589
+ logger.warn(
590
+ `Skipped not serializable cache item '${key}': ${e.message}`
591
+ );
592
+ logger.debug(e.stack);
593
+ }
594
+ }
595
+ write(null);
596
+ return;
597
+ }
565
598
  // Try to serialize all at once
566
599
  const s = snapshot();
567
600
  try {
@@ -590,9 +623,32 @@ class PackContentItems {
590
623
  }
591
624
  }
592
625
 
593
- deserialize({ read }) {
626
+ deserialize({ read, logger, profile }) {
594
627
  if (read()) {
595
628
  this.map = read();
629
+ } else if (profile) {
630
+ const map = new Map();
631
+ let key = read();
632
+ while (key !== null) {
633
+ const start = process.hrtime();
634
+ const value = read();
635
+ const durationHr = process.hrtime(start);
636
+ const duration = durationHr[0] * 1000 + durationHr[1] / 1e6;
637
+ if (duration > 1) {
638
+ if (duration > 100)
639
+ logger.error(`Deserialization of '${key}': ${duration} ms`);
640
+ else if (duration > 20)
641
+ logger.warn(`Deserialization of '${key}': ${duration} ms`);
642
+ else if (duration > 5)
643
+ logger.info(`Deserialization of '${key}': ${duration} ms`);
644
+ else if (duration > 2)
645
+ logger.log(`Deserialization of '${key}': ${duration} ms`);
646
+ else logger.debug(`Deserialization of '${key}': ${duration} ms`);
647
+ }
648
+ map.set(key, value);
649
+ key = read();
650
+ }
651
+ this.map = map;
596
652
  } else {
597
653
  const map = new Map();
598
654
  let key = read();
@@ -787,6 +843,7 @@ class PackFileCacheStrategy {
787
843
  * @param {Logger} options.logger a logger
788
844
  * @param {SnapshotOptions} options.snapshot options regarding snapshotting
789
845
  * @param {number} options.maxAge max age of cache items
846
+ * @param {boolean} options.profile track and log detailed timing information for individual cache items
790
847
  * @param {boolean} options.allowCollectingMemory allow to collect unused memory created during deserialization
791
848
  */
792
849
  constructor({
@@ -798,6 +855,7 @@ class PackFileCacheStrategy {
798
855
  logger,
799
856
  snapshot,
800
857
  maxAge,
858
+ profile,
801
859
  allowCollectingMemory
802
860
  }) {
803
861
  this.fileSerializer = createFileSerializer(fs);
@@ -812,6 +870,7 @@ class PackFileCacheStrategy {
812
870
  this.version = version;
813
871
  this.logger = logger;
814
872
  this.maxAge = maxAge;
873
+ this.profile = profile;
815
874
  this.allowCollectingMemory = allowCollectingMemory;
816
875
  this.snapshot = snapshot;
817
876
  /** @type {Set<string>} */
@@ -840,7 +899,7 @@ class PackFileCacheStrategy {
840
899
  * @returns {Promise<Pack>} the pack
841
900
  */
842
901
  _openPack() {
843
- const { logger, cacheLocation, version } = this;
902
+ const { logger, profile, cacheLocation, version } = this;
844
903
  /** @type {Snapshot} */
845
904
  let buildSnapshot;
846
905
  /** @type {Set<string>} */
@@ -857,6 +916,7 @@ class PackFileCacheStrategy {
857
916
  filename: `${cacheLocation}/index.pack`,
858
917
  extension: ".pack",
859
918
  logger,
919
+ profile,
860
920
  retainedBuffer: this.allowCollectingMemory
861
921
  ? allowCollectingMemory
862
922
  : undefined
@@ -981,7 +1041,8 @@ class PackFileCacheStrategy {
981
1041
  if (newBuildDependencies)
982
1042
  this.newBuildDependencies.addAll(newBuildDependencies);
983
1043
  this.resolveResults = resolveResults;
984
- this.resolveBuildDependenciesSnapshot = resolveBuildDependenciesSnapshot;
1044
+ this.resolveBuildDependenciesSnapshot =
1045
+ resolveBuildDependenciesSnapshot;
985
1046
  return pack;
986
1047
  }
987
1048
  return new Pack(logger, this.maxAge);
@@ -1103,10 +1164,11 @@ class PackFileCacheStrategy {
1103
1164
  );
1104
1165
  }
1105
1166
  if (this.resolveBuildDependenciesSnapshot) {
1106
- this.resolveBuildDependenciesSnapshot = this.fileSystemInfo.mergeSnapshots(
1107
- this.resolveBuildDependenciesSnapshot,
1108
- snapshot
1109
- );
1167
+ this.resolveBuildDependenciesSnapshot =
1168
+ this.fileSystemInfo.mergeSnapshots(
1169
+ this.resolveBuildDependenciesSnapshot,
1170
+ snapshot
1171
+ );
1110
1172
  } else {
1111
1173
  this.resolveBuildDependenciesSnapshot = snapshot;
1112
1174
  }
@@ -1134,10 +1196,11 @@ class PackFileCacheStrategy {
1134
1196
  this.logger.debug("Captured build dependencies");
1135
1197
 
1136
1198
  if (this.buildSnapshot) {
1137
- this.buildSnapshot = this.fileSystemInfo.mergeSnapshots(
1138
- this.buildSnapshot,
1139
- snapshot
1140
- );
1199
+ this.buildSnapshot =
1200
+ this.fileSystemInfo.mergeSnapshots(
1201
+ this.buildSnapshot,
1202
+ snapshot
1203
+ );
1141
1204
  } else {
1142
1205
  this.buildSnapshot = snapshot;
1143
1206
  }
@@ -1172,7 +1235,8 @@ class PackFileCacheStrategy {
1172
1235
  .serialize(content, {
1173
1236
  filename: `${this.cacheLocation}/index.pack`,
1174
1237
  extension: ".pack",
1175
- logger: this.logger
1238
+ logger: this.logger,
1239
+ profile: this.profile
1176
1240
  })
1177
1241
  .then(() => {
1178
1242
  for (const dep of newBuildDependencies) {
@@ -293,6 +293,7 @@ const applyCacheDefaults = (cache, { name, mode, development }) => {
293
293
  );
294
294
  D(cache, "hashAlgorithm", "md4");
295
295
  D(cache, "store", "pack");
296
+ D(cache, "profile", false);
296
297
  D(cache, "idleTimeout", 60000);
297
298
  D(cache, "idleTimeoutForInitialStore", 0);
298
299
  D(cache, "maxMemoryGenerations", development ? 5 : Infinity);
@@ -317,9 +318,10 @@ const applyCacheDefaults = (cache, { name, mode, development }) => {
317
318
  const applySnapshotDefaults = (snapshot, { production }) => {
318
319
  A(snapshot, "managedPaths", () => {
319
320
  if (process.versions.pnp === "3") {
320
- const match = /^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
321
- require.resolve("watchpack")
322
- );
321
+ const match =
322
+ /^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
323
+ require.resolve("watchpack")
324
+ );
323
325
  if (match) {
324
326
  return [path.resolve(match[1], "unplugged")];
325
327
  }
@@ -336,16 +338,18 @@ const applySnapshotDefaults = (snapshot, { production }) => {
336
338
  });
337
339
  A(snapshot, "immutablePaths", () => {
338
340
  if (process.versions.pnp === "1") {
339
- const match = /^(.+?[\\/]v4)[\\/]npm-watchpack-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec(
340
- require.resolve("watchpack")
341
- );
341
+ const match =
342
+ /^(.+?[\\/]v4)[\\/]npm-watchpack-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec(
343
+ require.resolve("watchpack")
344
+ );
342
345
  if (match) {
343
346
  return [match[1]];
344
347
  }
345
348
  } else if (process.versions.pnp === "3") {
346
- const match = /^(.+?)[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
347
- require.resolve("watchpack")
348
- );
349
+ const match =
350
+ /^(.+?)[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
351
+ require.resolve("watchpack")
352
+ );
349
353
  if (match) {
350
354
  return [match[1]];
351
355
  }
@@ -731,6 +735,16 @@ const applyOutputDefaults = (
731
735
  F(output.environment, "dynamicImport", () => tp && tp.dynamicImport);
732
736
  F(output.environment, "module", () => tp && tp.module);
733
737
 
738
+ const { trustedTypes } = output;
739
+ if (trustedTypes) {
740
+ F(
741
+ trustedTypes,
742
+ "policyName",
743
+ () =>
744
+ output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
745
+ );
746
+ }
747
+
734
748
  /**
735
749
  * @param {function(EntryDescription): void} fn iterator
736
750
  * @returns {void}
@@ -948,7 +962,7 @@ const applyOptimizationDefaults = (
948
962
  A(splitChunks, "defaultSizeTypes", () => ["javascript", "unknown"]);
949
963
  D(splitChunks, "hidePathInfo", production);
950
964
  D(splitChunks, "chunks", "async");
951
- D(splitChunks, "usedExports", true);
965
+ D(splitChunks, "usedExports", optimization.usedExports === true);
952
966
  D(splitChunks, "minChunks", 1);
953
967
  F(splitChunks, "minSize", () => (production ? 20000 : 10000));
954
968
  F(splitChunks, "minRemainingSize", () => (development ? 0 : undefined));
@@ -92,9 +92,9 @@ const keyedNestedConfig = (value, fn, customKeys) => {
92
92
  ? {}
93
93
  : Object.keys(value).reduce(
94
94
  (obj, key) => (
95
- (obj[key] = (customKeys && key in customKeys
96
- ? customKeys[key]
97
- : fn)(value[key])),
95
+ (obj[key] = (
96
+ customKeys && key in customKeys ? customKeys[key] : fn
97
+ )(value[key])),
98
98
  obj
99
99
  ),
100
100
  /** @type {Record<string, R>} */ ({})
@@ -131,6 +131,7 @@ const getNormalizedWebpackOptions = config => {
131
131
  type: "filesystem",
132
132
  maxMemoryGenerations: cache.maxMemoryGenerations,
133
133
  maxAge: cache.maxAge,
134
+ profile: cache.profile,
134
135
  buildDependencies: cloneObject(cache.buildDependencies),
135
136
  cacheDirectory: cache.cacheDirectory,
136
137
  cacheLocation: cache.cacheLocation,
@@ -162,10 +163,10 @@ const getNormalizedWebpackOptions = config => {
162
163
  config.entry === undefined
163
164
  ? { main: {} }
164
165
  : typeof config.entry === "function"
165
- ? (fn => () =>
166
- Promise.resolve().then(fn).then(getNormalizedEntryStatic))(
167
- config.entry
168
- )
166
+ ? (
167
+ fn => () =>
168
+ Promise.resolve().then(fn).then(getNormalizedEntryStatic)
169
+ )(config.entry)
169
170
  : getNormalizedEntryStatic(config.entry),
170
171
  experiments: cloneObject(config.experiments),
171
172
  externals: config.externals,
@@ -337,6 +338,15 @@ const getNormalizedWebpackOptions = config => {
337
338
  sourceMapFilename: output.sourceMapFilename,
338
339
  sourcePrefix: output.sourcePrefix,
339
340
  strictModuleExceptionHandling: output.strictModuleExceptionHandling,
341
+ trustedTypes: optionalNestedConfig(
342
+ output.trustedTypes,
343
+ trustedTypes => {
344
+ if (trustedTypes === true) return {};
345
+ if (typeof trustedTypes === "string")
346
+ return { policyName: trustedTypes };
347
+ return { ...trustedTypes };
348
+ }
349
+ ),
340
350
  uniqueName: output.uniqueName,
341
351
  wasmLoading: output.wasmLoading,
342
352
  webassemblyModuleFilename: output.webassemblyModuleFilename,
@@ -332,9 +332,10 @@ const interceptAllParserHooks = (moduleFactory, tracer) => {
332
332
  const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
333
333
  interceptAllHooksFor(
334
334
  {
335
- hooks: require("../javascript/JavascriptModulesPlugin").getCompilationHooks(
336
- compilation
337
- )
335
+ hooks:
336
+ require("../javascript/JavascriptModulesPlugin").getCompilationHooks(
337
+ compilation
338
+ )
338
339
  },
339
340
  tracer,
340
341
  "JavascriptModulesPlugin"
@@ -77,9 +77,9 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
77
77
  { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
78
78
  ) {
79
79
  const dep = /** @type {AMDRequireDependency} */ (dependency);
80
- const depBlock = /** @type {AsyncDependenciesBlock} */ (moduleGraph.getParentBlock(
81
- dep
82
- ));
80
+ const depBlock = /** @type {AsyncDependenciesBlock} */ (
81
+ moduleGraph.getParentBlock(dep)
82
+ );
83
83
  const promise = runtimeTemplate.blockPromise({
84
84
  chunkGraph,
85
85
  block: depBlock,
@@ -230,9 +230,8 @@ class CommonJsExportRequireDependency extends ModuleDependency {
230
230
  if (name === "__esModule" && isNamespaceImport) {
231
231
  exports.add(name);
232
232
  } else if (importedExportsInfo) {
233
- const importedExportInfo = importedExportsInfo.getReadOnlyExportInfo(
234
- name
235
- );
233
+ const importedExportInfo =
234
+ importedExportsInfo.getReadOnlyExportInfo(name);
236
235
  if (importedExportInfo.provided === false) continue;
237
236
  exports.add(name);
238
237
  if (importedExportInfo.provided === true) continue;
@@ -192,7 +192,9 @@ class CommonJsExportsParserPlugin {
192
192
  parser.hooks.call
193
193
  .for("Object.defineProperty")
194
194
  .tap("CommonJsExportsParserPlugin", expression => {
195
- const expr = /** @type {import("estree").CallExpression} */ (expression);
195
+ const expr = /** @type {import("estree").CallExpression} */ (
196
+ expression
197
+ );
196
198
  if (!parser.isStatementLevelExpression(expr)) return;
197
199
  if (expr.arguments.length !== 3) return;
198
200
  if (expr.arguments[0].type === "SpreadElement") return;
@@ -182,10 +182,8 @@ class CommonJsImportsParserPlugin {
182
182
  };
183
183
  const createRequireHandler = callNew => expr => {
184
184
  if (options.commonjsMagicComments) {
185
- const {
186
- options: requireOptions,
187
- errors: commentErrors
188
- } = parser.parseCommentOptions(expr.range);
185
+ const { options: requireOptions, errors: commentErrors } =
186
+ parser.parseCommentOptions(expr.range);
189
187
 
190
188
  if (commentErrors) {
191
189
  for (const e of commentErrors) {
@@ -265,13 +265,14 @@ class NodeModuleDecoratorRuntimeModule extends RuntimeModule {
265
265
  generate() {
266
266
  const { runtimeTemplate } = this.compilation;
267
267
  return Template.asString([
268
- `${
269
- RuntimeGlobals.nodeModuleDecorator
270
- } = ${runtimeTemplate.basicFunction("module", [
271
- "module.paths = [];",
272
- "if (!module.children) module.children = [];",
273
- "return module;"
274
- ])};`
268
+ `${RuntimeGlobals.nodeModuleDecorator} = ${runtimeTemplate.basicFunction(
269
+ "module",
270
+ [
271
+ "module.paths = [];",
272
+ "if (!module.children) module.children = [];",
273
+ "return module;"
274
+ ]
275
+ )};`
275
276
  ]);
276
277
  }
277
278
  }
@@ -45,6 +45,7 @@ makeSerializable(
45
45
  "webpack/lib/dependencies/CommonJsRequireContextDependency"
46
46
  );
47
47
 
48
- CommonJsRequireContextDependency.Template = ContextDependencyTemplateAsRequireCall;
48
+ CommonJsRequireContextDependency.Template =
49
+ ContextDependencyTemplateAsRequireCall;
49
50
 
50
51
  module.exports = CommonJsRequireContextDependency;
@@ -61,10 +61,11 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
61
61
 
62
62
  const valueRange = param.range;
63
63
  const { context, prefix } = splitContextFromPrefix(prefixRaw);
64
- const { path: postfix, query, fragment } = parseResource(
65
- postfixRaw,
66
- parser
67
- );
64
+ const {
65
+ path: postfix,
66
+ query,
67
+ fragment
68
+ } = parseResource(postfixRaw, parser);
68
69
 
69
70
  // When there are more than two quasis, the generated RegExp can be more precise
70
71
  // We join the quasis with the expression regexp
@@ -160,10 +161,11 @@ exports.create = (Dep, range, param, expr, options, contextOptions, parser) => {
160
161
  param.postfix && param.postfix.isString() ? param.postfix.range : null;
161
162
  const valueRange = param.range;
162
163
  const { context, prefix } = splitContextFromPrefix(prefixRaw);
163
- const { path: postfix, query, fragment } = parseResource(
164
- postfixRaw,
165
- parser
166
- );
164
+ const {
165
+ path: postfix,
166
+ query,
167
+ fragment
168
+ } = parseResource(postfixRaw, parser);
167
169
  const regExp = new RegExp(
168
170
  `^${quoteMeta(prefix)}${options.wrappedContextRegExp.source}${quoteMeta(
169
171
  postfix
@@ -0,0 +1,54 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const RuntimeGlobals = require("../RuntimeGlobals");
9
+ const makeSerializable = require("../util/makeSerializable");
10
+ const NullDependency = require("./NullDependency");
11
+
12
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
+ /** @typedef {import("../Dependency")} Dependency */
14
+ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
+
16
+ class CreateScriptUrlDependency extends NullDependency {
17
+ /**
18
+ * @param {[number, number]} range range
19
+ */
20
+ constructor(range) {
21
+ super();
22
+ this.range = range;
23
+ }
24
+
25
+ get type() {
26
+ return "create script url";
27
+ }
28
+ }
29
+
30
+ CreateScriptUrlDependency.Template = class CreateScriptUrlDependencyTemplate extends (
31
+ NullDependency.Template
32
+ ) {
33
+ /**
34
+ * @param {Dependency} dependency the dependency for which the template should be applied
35
+ * @param {ReplaceSource} source the current replace source which can be modified
36
+ * @param {DependencyTemplateContext} templateContext the context object
37
+ * @returns {void}
38
+ */
39
+ apply(dependency, source, { runtimeRequirements }) {
40
+ const dep = /** @type {CreateScriptUrlDependency} */ (dependency);
41
+
42
+ runtimeRequirements.add(RuntimeGlobals.createScriptUrl);
43
+
44
+ source.insert(dep.range[0], `${RuntimeGlobals.createScriptUrl}(`);
45
+ source.insert(dep.range[1], ")");
46
+ }
47
+ };
48
+
49
+ makeSerializable(
50
+ CreateScriptUrlDependency,
51
+ "webpack/lib/dependencies/CreateScriptUrlDependency"
52
+ );
53
+
54
+ module.exports = CreateScriptUrlDependency;
@@ -411,9 +411,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
411
411
  const ignoredExports = new Set(["default", ...this.activeExports]);
412
412
 
413
413
  let hiddenExports = undefined;
414
- const otherStarExports = this._discoverActiveExportsFromOtherStarExports(
415
- moduleGraph
416
- );
414
+ const otherStarExports =
415
+ this._discoverActiveExportsFromOtherStarExports(moduleGraph);
417
416
  if (otherStarExports !== undefined) {
418
417
  hiddenExports = new Set();
419
418
  for (let i = 0; i < otherStarExports.namesSlice; i++) {
@@ -441,9 +440,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
441
440
  const name = exportInfo.name;
442
441
  if (ignoredExports.has(name)) continue;
443
442
  if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
444
- const importedExportInfo = importedExportsInfo.getReadOnlyExportInfo(
445
- name
446
- );
443
+ const importedExportInfo =
444
+ importedExportsInfo.getReadOnlyExportInfo(name);
447
445
  if (importedExportInfo.provided === false) continue;
448
446
  if (hiddenExports !== undefined && hiddenExports.has(name)) {
449
447
  hidden.add(name);
@@ -763,9 +761,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
763
761
  `(reexported as '${this.name}')`
764
762
  );
765
763
  if (ids.length === 0 && this.name === null) {
766
- const potentialConflicts = this._discoverActiveExportsFromOtherStarExports(
767
- moduleGraph
768
- );
764
+ const potentialConflicts =
765
+ this._discoverActiveExportsFromOtherStarExports(moduleGraph);
769
766
  if (potentialConflicts && potentialConflicts.namesSlice > 0) {
770
767
  const ownNames = new Set(
771
768
  potentialConflicts.names.slice(
@@ -802,9 +799,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
802
799
  conflictingModule,
803
800
  exportInfo.name
804
801
  );
805
- const conflictingTarget = conflictingExportInfo.getTerminalBinding(
806
- moduleGraph
807
- );
802
+ const conflictingTarget =
803
+ conflictingExportInfo.getTerminalBinding(moduleGraph);
808
804
  if (!conflictingTarget) continue;
809
805
  if (target === conflictingTarget) continue;
810
806
  const list = conflicts.get(conflictingDependency.request);
@@ -882,7 +878,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
882
878
  apply(dependency, source, templateContext) {
883
879
  const { moduleGraph, runtime, concatenationScope } = templateContext;
884
880
 
885
- const dep = /** @type {HarmonyExportImportedSpecifierDependency} */ (dependency);
881
+ const dep = /** @type {HarmonyExportImportedSpecifierDependency} */ (
882
+ dependency
883
+ );
886
884
 
887
885
  const mode = dep.getMode(moduleGraph, runtime);
888
886