webpack 5.110.2 → 5.111.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.
Files changed (226) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +23 -7
  3. package/lib/AutomaticPrefetchPlugin.js +1 -1
  4. package/lib/Cache.js +8 -3
  5. package/lib/CacheFacade.js +1 -1
  6. package/lib/ChunkGraph.js +20 -18
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/Compilation.js +321 -303
  10. package/lib/Compiler.js +209 -46
  11. package/lib/ConcatenationScope.js +25 -35
  12. package/lib/ContextModule.js +17 -81
  13. package/lib/ContextModuleFactory.js +1 -1
  14. package/lib/CopyPlugin.js +1054 -0
  15. package/lib/DefinePlugin.js +24 -8
  16. package/lib/DotenvPlugin.js +41 -13
  17. package/lib/ExternalModule.js +41 -14
  18. package/lib/FileSystemInfo.js +17 -14
  19. package/lib/FlagDependencyExportsPlugin.js +45 -21
  20. package/lib/FlagDependencyUsagePlugin.js +8 -2
  21. package/lib/HotModuleReplacementPlugin.js +53 -7
  22. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  23. package/lib/MainTemplate.js +5 -1
  24. package/lib/Module.js +16 -7
  25. package/lib/MultiCompiler.js +1 -1
  26. package/lib/MultiWatching.js +1 -1
  27. package/lib/NormalModule.js +58 -32
  28. package/lib/NormalModuleFactory.js +1 -1
  29. package/lib/RuntimeGlobals.js +21 -7
  30. package/lib/RuntimeModule.js +28 -12
  31. package/lib/RuntimePlugin.js +33 -3
  32. package/lib/RuntimeTemplate.js +794 -477
  33. package/lib/SourceMapDevToolPlugin.js +1 -1
  34. package/lib/Watching.js +9 -0
  35. package/lib/WebpackOptionsApply.js +84 -91
  36. package/lib/asset/AssetGenerator.js +25 -8
  37. package/lib/asset/AssetModule.js +3 -0
  38. package/lib/asset/WebManifestParser.js +7 -5
  39. package/lib/async-modules/AsyncModuleHelpers.js +10 -4
  40. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  41. package/lib/cache/IdleFileCachePlugin.js +2 -2
  42. package/lib/cache/PackFileCacheStrategy.js +14 -1
  43. package/lib/config/browserslistTargetHandler.js +19 -0
  44. package/lib/config/defaults.js +110 -64
  45. package/lib/config/normalization.js +100 -20
  46. package/lib/config/target.js +10 -0
  47. package/lib/container/ContainerReferencePlugin.js +6 -0
  48. package/lib/container/RemoteRuntimeModule.js +9 -0
  49. package/lib/container/declaredRemotes.js +39 -0
  50. package/lib/css/CssGenerator.js +8 -0
  51. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  52. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  53. package/lib/css/CssModule.js +1 -1
  54. package/lib/css/CssModulesPlugin.js +7 -6
  55. package/lib/css/CssParser.js +144 -11
  56. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  57. package/lib/css/cssMinify.js +11 -3
  58. package/lib/css/data.js +2814 -678
  59. package/lib/css/syntax.js +4082 -248
  60. package/lib/debug/ProfilingPlugin.js +4 -0
  61. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  62. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  63. package/lib/dependencies/CommonJsExportRequireDependency.js +3 -1
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -0
  66. package/lib/dependencies/CommonJsPlugin.js +19 -3
  67. package/lib/dependencies/CommonJsRequireDependency.js +32 -9
  68. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
  69. package/lib/dependencies/CssIcssExportDependency.js +7 -1
  70. package/lib/dependencies/HarmonyCompatibilityDependency.js +58 -4
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -3
  72. package/lib/dependencies/HarmonyExportExpressionDependency.js +44 -29
  73. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +171 -32
  74. package/lib/dependencies/HarmonyExportInitFragment.js +99 -19
  75. package/lib/dependencies/HarmonyExportSpecifierDependency.js +18 -30
  76. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  77. package/lib/dependencies/HarmonyImportDependency.js +99 -41
  78. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -3
  79. package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -1
  80. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  81. package/lib/dependencies/HtmlEntryDependency.js +62 -2
  82. package/lib/dependencies/ImportContextDependency.js +43 -3
  83. package/lib/dependencies/ImportDependency.js +8 -29
  84. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  85. package/lib/dependencies/ImportMetaPlugin.js +59 -15
  86. package/lib/dependencies/ImportParserPlugin.js +24 -14
  87. package/lib/dependencies/RequireHeaderDependency.js +20 -21
  88. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  89. package/lib/dependencies/WorkerDependency.js +1 -2
  90. package/lib/dependencies/WorkletDependency.js +1 -2
  91. package/lib/dependencies/importOptionsCheck.js +47 -0
  92. package/lib/dll/DelegatedModule.js +18 -1
  93. package/lib/dll/DllReferencePlugin.js +11 -8
  94. package/lib/dll/LibManifestPlugin.js +1 -1
  95. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  96. package/lib/errors/DotenvFileError.js +29 -0
  97. package/lib/errors/DuplicateModulesWarning.js +12 -7
  98. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  99. package/lib/errors/ExternalStarReexportError.js +44 -0
  100. package/lib/errors/ImportedBindingAssignmentError.js +30 -0
  101. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  102. package/lib/errors/ModuleParseError.js +2 -1
  103. package/lib/errors/UnusedAssetsWarning.js +36 -0
  104. package/lib/errors/UnusedFederationWarning.js +35 -0
  105. package/lib/errors/UnusedModulesWarning.js +38 -0
  106. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  107. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  108. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  109. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  110. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  111. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  112. package/lib/html/HtmlGenerator.js +11 -5
  113. package/lib/html/HtmlModulesPlugin.js +360 -84
  114. package/lib/html/HtmlParser.js +13 -6
  115. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  116. package/lib/html/data.js +121 -7
  117. package/lib/html/htmlMinify.js +84 -113
  118. package/lib/html/syntax.js +1067 -569
  119. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  120. package/lib/index.js +3 -0
  121. package/lib/javascript/JavascriptModule.js +1 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +52 -22
  123. package/lib/javascript/JavascriptParser.js +1255 -728
  124. package/lib/javascript/StartupHelpers.js +27 -3
  125. package/lib/javascript/data.js +172 -0
  126. package/lib/javascript/grammar.js +5546 -0
  127. package/lib/javascript/parser.js +1494 -0
  128. package/lib/javascript/regexp.js +1762 -0
  129. package/lib/javascript/regexpData.js +51 -0
  130. package/lib/javascript/syntax.js +8696 -5225
  131. package/lib/library/ModuleLibraryPlugin.js +116 -5
  132. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  133. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  134. package/lib/optimize/ConcatenatedModule.js +133 -25
  135. package/lib/optimize/ConstExportsPlugin.js +50 -39
  136. package/lib/optimize/InlineExports.js +20 -123
  137. package/lib/optimize/MangleExportsPlugin.js +10 -0
  138. package/lib/optimize/ModuleConcatenationPlugin.js +24 -1
  139. package/lib/optimize/RealContentHashPlugin.js +68 -9
  140. package/lib/optimize/SideEffectsFlagPlugin.js +17 -9
  141. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  142. package/lib/performance/CacheEffectivenessPlugin.js +4 -3
  143. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  144. package/lib/performance/EvalUsagePlugin.js +5 -2
  145. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  146. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  147. package/lib/performance/TopLevelThisPlugin.js +5 -4
  148. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  149. package/lib/performance/UnusedFederationPlugin.js +147 -0
  150. package/lib/performance/UnusedModulesPlugin.js +141 -0
  151. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  152. package/lib/performance/isOnlyReexported.js +65 -0
  153. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  154. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +2 -0
  155. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  156. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  157. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  158. package/lib/prefetch/ResourceHintPlugin.js +7 -3
  159. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  160. package/lib/prefetch/StartupAssetHintRuntimeModule.js +9 -0
  161. package/lib/rules/RuleSetCompiler.js +211 -4
  162. package/lib/runtime/AsyncModuleRuntimeModule.js +105 -67
  163. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  164. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  165. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  166. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  167. package/lib/runtime/GetChunkFilenameRuntimeModule.js +9 -0
  168. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  169. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  170. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  171. package/lib/runtime/GlobalRuntimeModule.js +9 -0
  172. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  173. package/lib/runtime/HelperRuntimeModule.js +10 -0
  174. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +338 -217
  175. package/lib/runtime/NonceRuntimeModule.js +9 -0
  176. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  177. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  178. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  179. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  180. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  181. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  182. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  183. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  184. package/lib/schemes/HttpUriPlugin.js +22 -5
  185. package/lib/serialization/FileMiddleware.js +15 -2
  186. package/lib/serialization/ObjectMiddleware.js +138 -106
  187. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  188. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  189. package/lib/sharing/ShareRuntimeModule.js +9 -0
  190. package/lib/sharing/declaredShared.js +47 -0
  191. package/lib/stats/DefaultStatsFactoryPlugin.js +3 -1
  192. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  193. package/lib/util/ArrayQueue.js +3 -3
  194. package/lib/util/SourceProcessor.js +76 -69
  195. package/lib/util/URLAbsoluteSpecifier.js +3 -1
  196. package/lib/util/async.js +292 -0
  197. package/lib/util/buildDiagnostics.js +69 -0
  198. package/lib/util/conventions.js +5 -1
  199. package/lib/util/fs.js +27 -1
  200. package/lib/util/handlerKeys.js +40 -0
  201. package/lib/util/identifier.js +20 -0
  202. package/lib/util/internalSerializables.js +6 -0
  203. package/lib/util/registerExternalSerializer.js +6 -45
  204. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  205. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  206. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +9 -0
  207. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  208. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  209. package/package.json +22 -16
  210. package/schemas/WebpackOptions.check.js +1 -1
  211. package/schemas/WebpackOptions.json +388 -76
  212. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  213. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  214. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  217. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  218. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  219. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  220. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  222. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  223. package/types.d.ts +1440 -331
  224. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  225. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  226. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -107,21 +107,6 @@ Technically any value can be used.
107
107
  * @property {(context: ObjectDeserializerContext<EXPECTED_ANY>) => EXPECTED_ANY} deserialize
108
108
  */
109
109
 
110
- /**
111
- * Updates set size using the provided set.
112
- * @template T
113
- * @param {Set<T>} set set
114
- * @param {number} size count of items to keep
115
- */
116
- const setSetSize = (set, size) => {
117
- let i = 0;
118
- for (const item of set) {
119
- if (i++ >= size) {
120
- set.delete(item);
121
- }
122
- }
123
- };
124
-
125
110
  /**
126
111
  * Updates map size using the provided map.
127
112
  * @template K, X
@@ -149,6 +134,9 @@ const toHash = (buffer, hashFunction) => {
149
134
  return hash.digest("latin1");
150
135
  };
151
136
 
137
+ /** Marks an object whose children are still being written; never a real position. */
138
+ const IN_PROGRESS = -1;
139
+
152
140
  const ESCAPE = null;
153
141
  const ESCAPE_ESCAPE_VALUE = null;
154
142
  const ESCAPE_END_OBJECT = true;
@@ -463,16 +451,22 @@ class ObjectMiddleware extends SerializerMiddleware {
463
451
  let currentPosTypeLookup = 0;
464
452
  /** @type {Map<SerializerConfigWithSerializer, number>} */
465
453
  let objectTypeLookup = new Map();
466
- /** @type {Set<ComplexSerializableType>} */
467
- const cycleStack = new Set();
454
+ /**
455
+ * One-entry cache in front of `objectTypeLookup`, since runs of one class are common.
456
+ * @type {SerializerConfigWithSerializer | undefined}
457
+ */
458
+ let lastConfig;
459
+ /** @type {number} */
460
+ let lastConfigIndex = 0;
461
+ /** @type {ComplexSerializableType[]} */
462
+ const cycleStack = [];
468
463
  /**
469
464
  * Returns stack.
470
465
  * @param {ComplexSerializableType} item item to stack
471
466
  * @returns {string} stack
472
467
  */
473
468
  const stackToString = (item) => {
474
- const arr = [...cycleStack];
475
- arr.push(item);
469
+ const arr = [...cycleStack, item];
476
470
  return arr
477
471
  .map((item) => {
478
472
  if (typeof item === "string") {
@@ -528,63 +522,35 @@ class ObjectMiddleware extends SerializerMiddleware {
528
522
  };
529
523
  /** @type {undefined | WeakSet<Error>} */
530
524
  let hasDebugInfoAttached;
531
- /** @type {ObjectSerializerContext<EXPECTED_ANY>} */
532
- let ctx = {
533
- write(value) {
534
- try {
535
- process(/** @type {ComplexSerializableType} */ (value));
536
- } catch (err) {
537
- if (err !== NOT_SERIALIZABLE) {
538
- if (hasDebugInfoAttached === undefined) {
539
- hasDebugInfoAttached = new WeakSet();
540
- }
541
- if (!hasDebugInfoAttached.has(/** @type {Error} */ (err))) {
542
- /** @type {Error} */
543
- (err).message +=
544
- `\nwhile serializing ${stackToString(/** @type {ComplexSerializableType} */ (value))}`;
545
- hasDebugInfoAttached.add(/** @type {Error} */ (err));
546
- }
547
- }
548
- throw err;
549
- }
550
- return ctx;
551
- },
552
- setCircularReference(ref) {
553
- addReferenceable(ref);
554
- },
555
- snapshot() {
556
- return {
557
- length: result.length,
558
- cycleStackSize: cycleStack.size,
559
- referenceableSize: referenceable.size,
560
- currentPos,
561
- objectTypeLookupSize: objectTypeLookup.size,
562
- currentPosTypeLookup
563
- };
564
- },
565
- rollback(snapshot) {
566
- result.length = snapshot.length;
567
- setSetSize(cycleStack, snapshot.cycleStackSize);
568
- setMapSize(referenceable, snapshot.referenceableSize);
569
- currentPos = snapshot.currentPos;
570
- setMapSize(objectTypeLookup, snapshot.objectTypeLookupSize);
571
- currentPosTypeLookup = snapshot.currentPosTypeLookup;
572
- },
573
- ...context
525
+ /**
526
+ * Appends the path from the root to `item`, once per error.
527
+ * @param {Error} err error thrown while writing `item`
528
+ * @param {ComplexSerializableType} item item being written
529
+ * @returns {Error} err
530
+ */
531
+ const attachSerializationPath = (err, item) => {
532
+ if (hasDebugInfoAttached === undefined) {
533
+ hasDebugInfoAttached = new WeakSet();
534
+ }
535
+ if (!hasDebugInfoAttached.has(err)) {
536
+ err.message += `\nwhile serializing ${stackToString(item)}`;
537
+ hasDebugInfoAttached.add(err);
538
+ }
539
+ return err;
574
540
  };
575
- this.extendContext(ctx);
576
541
  // Dispatched on `typeof` first: two thirds of the items are numbers,
577
542
  // booleans and `undefined`, and only 3% are buffers.
578
543
  /**
579
- * Processes the provided item.
544
+ * Writes one item into the output; the context is returned so writes chain.
580
545
  * @param {ComplexSerializableType} item item to serialize
546
+ * @returns {ObjectSerializerContext<EXPECTED_ANY>} context
581
547
  */
582
548
  const process = (item) => {
583
549
  switch (typeof item) {
584
550
  case "number":
585
551
  case "boolean":
586
552
  result.push(item);
587
- return;
553
+ return ctx;
588
554
  case "string": {
589
555
  if (item.length > 1) {
590
556
  // short strings are shorter when not emitting a reference (this saves 1 byte per empty string)
@@ -602,10 +568,10 @@ class ObjectMiddleware extends SerializerMiddleware {
602
568
  ) {
603
569
  // A back-reference is `null` + the offset.
604
570
  result.push(ESCAPE, offset);
605
- return;
571
+ return ctx;
606
572
  }
607
573
  }
608
- addReferenceable(item);
574
+ referenceable.set(item, currentPos++);
609
575
  }
610
576
 
611
577
  if (item.length > 102400 && context.logger) {
@@ -617,87 +583,115 @@ class ObjectMiddleware extends SerializerMiddleware {
617
583
  }
618
584
 
619
585
  result.push(item);
620
- return;
586
+ return ctx;
621
587
  }
622
588
  case "undefined":
623
589
  result.push(ESCAPE, ESCAPE_UNDEFINED);
624
- return;
590
+ return ctx;
625
591
  case "object": {
626
592
  // ESCAPE is null, so this covers null too
627
593
  if (item === ESCAPE) {
628
594
  result.push(ESCAPE, ESCAPE_ESCAPE_VALUE);
629
- return;
595
+ return ctx;
630
596
  }
631
597
 
632
- if (Buffer.isBuffer(item)) {
633
- // check if we can emit a reference
634
- const ref = referenceable.get(item);
635
- if (ref !== undefined) {
636
- result.push(ESCAPE, ref - currentPos);
637
- return;
598
+ // buffers and objects share one reference table, so a single
599
+ // lookup answers both before the costlier buffer test
600
+ const ref = referenceable.get(item);
601
+ if (ref !== undefined) {
602
+ if (ref === IN_PROGRESS) {
603
+ throw attachSerializationPath(
604
+ new Error(
605
+ "This is a circular references. To serialize circular references use 'setCircularReference' somewhere in the circle during serialize and deserialize."
606
+ ),
607
+ item
608
+ );
638
609
  }
610
+ result.push(ESCAPE, ref - currentPos);
611
+ return ctx;
612
+ }
613
+
614
+ if (Buffer.isBuffer(item)) {
639
615
  const alreadyUsedBuffer = dedupeBuffer(item);
640
616
  if (alreadyUsedBuffer !== item) {
641
617
  const ref = referenceable.get(alreadyUsedBuffer);
642
618
  if (ref !== undefined) {
643
619
  referenceable.set(item, ref);
644
620
  result.push(ESCAPE, ref - currentPos);
645
- return;
621
+ return ctx;
646
622
  }
647
623
  item = alreadyUsedBuffer;
648
624
  }
649
- addReferenceable(item);
625
+ referenceable.set(item, currentPos++);
650
626
 
651
627
  result.push(/** @type {Buffer} */ (item));
652
- return;
653
- }
654
-
655
- // check if we can emit a reference
656
- const ref = referenceable.get(item);
657
- if (ref !== undefined) {
658
- result.push(ESCAPE, ref - currentPos);
659
- return;
660
- }
661
-
662
- if (cycleStack.has(item)) {
663
- throw new Error(
664
- "This is a circular references. To serialize circular references use 'setCircularReference' somewhere in the circle during serialize and deserialize."
665
- );
628
+ return ctx;
666
629
  }
667
630
 
668
631
  // Keyed by the registration itself: one per class, so it stands in for
669
632
  // `${request}/${name}` without building that string per object.
670
- const config = ObjectMiddleware.getSerializerFor(
671
- /** @type {Constructor} */
672
- (item)
633
+ const proto = Object.getPrototypeOf(item);
634
+ const registered = serializers.get(
635
+ proto === null ? null : proto.constructor
673
636
  );
637
+ /** @type {SerializerConfigWithSerializer} */
638
+ let config;
639
+ if (registered !== undefined && registered.serializer !== undefined) {
640
+ config = /** @type {SerializerConfigWithSerializer} */ (registered);
641
+ } else {
642
+ try {
643
+ // re-resolved so the miss reports which class is unregistered
644
+ config = ObjectMiddleware.getSerializerFor(
645
+ /** @type {Constructor} */
646
+ (item)
647
+ );
648
+ } catch (err) {
649
+ if (err === NOT_SERIALIZABLE) throw err;
650
+ throw attachSerializationPath(/** @type {Error} */ (err), item);
651
+ }
652
+ }
674
653
  const { request, name, serializer } = config;
675
- const lastIndex = objectTypeLookup.get(config);
654
+ const lastIndex =
655
+ config === lastConfig
656
+ ? lastConfigIndex
657
+ : objectTypeLookup.get(config);
676
658
 
677
659
  if (lastIndex === undefined) {
678
- objectTypeLookup.set(config, currentPosTypeLookup++);
660
+ lastConfigIndex = currentPosTypeLookup++;
661
+ objectTypeLookup.set(config, lastConfigIndex);
679
662
 
680
663
  result.push(ESCAPE, request, name);
681
664
  } else {
665
+ lastConfigIndex = lastIndex;
682
666
  result.push(ESCAPE, currentPosTypeLookup - lastIndex);
683
667
  }
668
+ lastConfig = config;
684
669
 
685
- cycleStack.add(item);
670
+ referenceable.set(item, IN_PROGRESS);
671
+ cycleStack.push(item);
686
672
 
687
673
  try {
688
674
  serializer.serialize(item, ctx);
689
- } finally {
690
- cycleStack.delete(item);
675
+ } catch (err) {
676
+ cycleStack.pop();
677
+ if (err !== NOT_SERIALIZABLE) {
678
+ attachSerializationPath(/** @type {Error} */ (err), item);
679
+ }
680
+ throw err;
691
681
  }
682
+ cycleStack.pop();
692
683
 
693
684
  result.push(ESCAPE, ESCAPE_END_OBJECT);
694
685
 
695
- addReferenceable(item);
696
- return;
686
+ referenceable.set(item, currentPos++);
687
+ return ctx;
697
688
  }
698
689
  case "function": {
699
690
  if (!SerializerMiddleware.isLazy(item)) {
700
- throw new Error(`Unexpected function ${item}`);
691
+ throw attachSerializationPath(
692
+ new Error(`Unexpected function ${item}`),
693
+ item
694
+ );
701
695
  }
702
696
 
703
697
  /** @type {SerializedType | undefined} */
@@ -708,10 +702,10 @@ class ObjectMiddleware extends SerializerMiddleware {
708
702
  if (typeof serializedData === "function") {
709
703
  result.push(serializedData);
710
704
  } else {
711
- throw new Error("Not implemented");
705
+ throw attachSerializationPath(new Error("Not implemented"), item);
712
706
  }
713
707
  } else if (SerializerMiddleware.isLazy(item, this)) {
714
- throw new Error("Not implemented");
708
+ throw attachSerializationPath(new Error("Not implemented"), item);
715
709
  } else {
716
710
  const data =
717
711
  /** @type {() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>} */
@@ -723,12 +717,50 @@ class ObjectMiddleware extends SerializerMiddleware {
723
717
  SerializerMiddleware.setLazySerializedValue(item, data);
724
718
  result.push(data);
725
719
  }
726
- return;
720
+ return ctx;
727
721
  }
728
722
  default:
729
723
  result.push(item);
730
724
  }
725
+ return ctx;
731
726
  };
727
+ /** @type {ObjectSerializerContext<EXPECTED_ANY>} */
728
+ let ctx = {
729
+ write: process,
730
+ setCircularReference(ref) {
731
+ addReferenceable(ref);
732
+ },
733
+ snapshot() {
734
+ return {
735
+ length: result.length,
736
+ cycleStackSize: cycleStack.length,
737
+ referenceableSize: referenceable.size,
738
+ currentPos,
739
+ objectTypeLookupSize: objectTypeLookup.size,
740
+ currentPosTypeLookup
741
+ };
742
+ },
743
+ rollback(snapshot) {
744
+ result.length = snapshot.length;
745
+ cycleStack.length = snapshot.cycleStackSize;
746
+ // a `setCircularReference` since the snapshot replaced a marker on an
747
+ // item already keyed here, which `setMapSize` cannot undo
748
+ for (let i = 0; i < cycleStack.length; i++) {
749
+ const item = /** @type {ReferenceableItem} */ (cycleStack[i]);
750
+ const ref = referenceable.get(item);
751
+ if (ref !== undefined && ref >= snapshot.currentPos) {
752
+ referenceable.set(item, IN_PROGRESS);
753
+ }
754
+ }
755
+ setMapSize(referenceable, snapshot.referenceableSize);
756
+ currentPos = snapshot.currentPos;
757
+ setMapSize(objectTypeLookup, snapshot.objectTypeLookupSize);
758
+ lastConfig = undefined;
759
+ currentPosTypeLookup = snapshot.currentPosTypeLookup;
760
+ },
761
+ ...context
762
+ };
763
+ this.extendContext(ctx);
732
764
 
733
765
  try {
734
766
  for (const item of data) {
@@ -15,6 +15,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
15
15
  const ConsumeSharedModule = require("./ConsumeSharedModule");
16
16
  const ConsumeSharedRuntimeModule = require("./ConsumeSharedRuntimeModule");
17
17
  const ProvideForSharedDependency = require("./ProvideForSharedDependency");
18
+ const { addDeclaredShared } = require("./declaredShared");
18
19
  const { resolveMatchedConfigs } = require("./resolveMatchedConfigs");
19
20
  const {
20
21
  getDescriptionFile,
@@ -137,6 +138,17 @@ class ConsumeSharedPlugin {
137
138
  normalModuleFactory
138
139
  );
139
140
 
141
+ // A key ending in a slash shares everything under it, and the
142
+ // modules then carry the remainder appended to the share key.
143
+ addDeclaredShared(
144
+ compilation,
145
+ consumes.map(([key, config]) => ({
146
+ name: key,
147
+ shareKey: config.shareKey,
148
+ prefix: key.endsWith("/")
149
+ }))
150
+ );
151
+
140
152
  /** @typedef {Map<string, ConsumeOptions>} Consumes */
141
153
 
142
154
  /** @type {Consumes} */
@@ -33,6 +33,17 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
33
33
  this._runtimeRequirements = runtimeRequirements;
34
34
  }
35
35
 
36
+ /**
37
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
38
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
39
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
40
+ */
41
+ getInstalledChunkHandlers() {
42
+ return this._runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)
43
+ ? [[RuntimeGlobals.ensureChunkHandlers, "consumes"]]
44
+ : [];
45
+ }
46
+
36
47
  /**
37
48
  * Generates runtime code for this runtime module.
38
49
  * @returns {string | null} runtime code
@@ -23,6 +23,15 @@ class ShareRuntimeModule extends RuntimeModule {
23
23
  super("sharing");
24
24
  }
25
25
 
26
+ /**
27
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
28
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
29
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
30
+ */
31
+ getInstalledChunkHandlers() {
32
+ return RuntimeModule.NO_CHUNK_HANDLERS;
33
+ }
34
+
26
35
  /**
27
36
  * Generates runtime code for this runtime module.
28
37
  * @returns {string | null} runtime code
@@ -0,0 +1,47 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @import Compilation from "../Compilation" */
9
+
10
+ /**
11
+ * @typedef {object} SharedDeclaration
12
+ * @property {string} name the config key, as the config spells it
13
+ * @property {string} shareKey the key the modules created for it carry
14
+ * @property {boolean} prefix whether it shares everything under the key
15
+ */
16
+
17
+ /** @type {WeakMap<Compilation, SharedDeclaration[]>} */
18
+ const DECLARED_SHARED = new WeakMap();
19
+
20
+ /**
21
+ * What this build declared as shared, one entry per config key, since several
22
+ * may name one share key. `performance.unusedConfig` matches modules on the
23
+ * share key and reports the config key.
24
+ * @param {Compilation} compilation the compilation
25
+ * @returns {SharedDeclaration[] | undefined} the declarations, when any were made
26
+ */
27
+ const getDeclaredShared = (compilation) => DECLARED_SHARED.get(compilation);
28
+
29
+ /**
30
+ * Records declarations, appending when a build applies the plugin more than
31
+ * once, as `ModuleFederationPlugin` and `SharePlugin` do.
32
+ * @param {Compilation} compilation the compilation
33
+ * @param {SharedDeclaration[]} declarations what this application declared
34
+ * @returns {void}
35
+ */
36
+ const addDeclaredShared = (compilation, declarations) => {
37
+ const declared = DECLARED_SHARED.get(compilation);
38
+
39
+ if (declared === undefined) {
40
+ DECLARED_SHARED.set(compilation, [...declarations]);
41
+ } else {
42
+ for (const declaration of declarations) declared.push(declaration);
43
+ }
44
+ };
45
+
46
+ module.exports.addDeclaredShared = addDeclaredShared;
47
+ module.exports.getDeclaredShared = getDeclaredShared;
@@ -1340,9 +1340,11 @@ const SIMPLE_EXTRACTORS = {
1340
1340
  const warnings = module.getWarnings();
1341
1341
  const warningsCount =
1342
1342
  warnings !== undefined ? countIterable(warnings) : 0;
1343
- const { cacheable, notCacheableReasons } = /** @type {BuildInfo} */ (
1343
+ const { cacheable, diagnostics } = /** @type {BuildInfo} */ (
1344
1344
  module.buildInfo
1345
1345
  );
1346
+ const notCacheableReasons =
1347
+ diagnostics === undefined ? undefined : diagnostics.notCacheableReasons;
1346
1348
  const preOrderIndex = /** @type {number} */ (
1347
1349
  moduleGraph.getPreOrderIndex(module)
1348
1350
  );
@@ -460,6 +460,8 @@ const ASSET_SIMPLE_PRINTERS = {
460
460
  javascriptModule ? formatFlag("javascript module") : undefined,
461
461
  "asset.info.sourceFilename": (sourceFilename, { formatFlag }) =>
462
462
  sourceFilename ? formatFlag(`from: ${sourceFilename}`) : undefined,
463
+ "asset.info.copied": (copied, { green, formatFlag }) =>
464
+ copied ? green(formatFlag("copied")) : undefined,
463
465
  "asset.info.development": (development, { green, formatFlag }) =>
464
466
  development ? green(formatFlag("dev")) : undefined,
465
467
  "asset.info.hotModuleReplacement": (
@@ -1045,6 +1047,7 @@ const PREFERRED_ORDERS = {
1045
1047
  "asset.info": [
1046
1048
  "immutable",
1047
1049
  "sourceFilename",
1050
+ "copied",
1048
1051
  "javascriptModule",
1049
1052
  "development",
1050
1053
  "hotModuleReplacement"
@@ -90,11 +90,11 @@ class ArrayQueue {
90
90
  [Symbol.iterator]() {
91
91
  return {
92
92
  next: () => {
93
- const item = this.dequeue();
94
- if (item) {
93
+ // length, not truthiness: a queued `0`/`false`/`undefined` is a value
94
+ if (this.length > 0) {
95
95
  return {
96
96
  done: false,
97
- value: item
97
+ value: /** @type {T} */ (this.dequeue())
98
98
  };
99
99
  }
100
100
  return {