webpack 5.99.6 → 5.99.8

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 (219) hide show
  1. package/lib/AutomaticPrefetchPlugin.js +21 -22
  2. package/lib/BannerPlugin.js +31 -35
  3. package/lib/CleanPlugin.js +5 -3
  4. package/lib/Compilation.js +21 -15
  5. package/lib/Compiler.js +2 -1
  6. package/lib/ContextExclusionPlugin.js +4 -2
  7. package/lib/ContextModule.js +1 -1
  8. package/lib/ContextModuleFactory.js +1 -2
  9. package/lib/ContextReplacementPlugin.js +7 -4
  10. package/lib/DefinePlugin.js +2 -2
  11. package/lib/DelegatedModule.js +18 -8
  12. package/lib/DelegatedModuleFactoryPlugin.js +9 -7
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +138 -139
  23. package/lib/ExportsInfo.js +35 -16
  24. package/lib/ExternalModule.js +6 -5
  25. package/lib/ExternalsPlugin.js +3 -1
  26. package/lib/FileSystemInfo.js +2 -2
  27. package/lib/FlagDependencyExportsPlugin.js +2 -1
  28. package/lib/IgnorePlugin.js +6 -4
  29. package/lib/IgnoreWarningsPlugin.js +4 -2
  30. package/lib/LibManifestPlugin.js +5 -6
  31. package/lib/LoaderOptionsPlugin.js +4 -2
  32. package/lib/LoaderTargetPlugin.js +4 -2
  33. package/lib/Module.js +19 -12
  34. package/lib/ModuleFilenameHelpers.js +8 -4
  35. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  36. package/lib/MultiCompiler.js +5 -3
  37. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  38. package/lib/NormalModule.js +13 -8
  39. package/lib/NormalModuleReplacementPlugin.js +33 -36
  40. package/lib/PlatformPlugin.js +3 -1
  41. package/lib/PrefetchPlugin.js +4 -2
  42. package/lib/ProgressPlugin.js +23 -26
  43. package/lib/RecordIdsPlugin.js +72 -102
  44. package/lib/RuntimePlugin.js +34 -32
  45. package/lib/SourceMapDevToolPlugin.js +9 -8
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +6 -7
  51. package/lib/asset/AssetGenerator.js +2 -2
  52. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  53. package/lib/cache/IdleFileCachePlugin.js +11 -12
  54. package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
  55. package/lib/cache/ResolverCachePlugin.js +8 -6
  56. package/lib/cli.js +5 -1
  57. package/lib/config/defaults.js +10 -6
  58. package/lib/config/normalization.js +14 -8
  59. package/lib/container/ContainerReferencePlugin.js +24 -26
  60. package/lib/container/ModuleFederationPlugin.js +2 -1
  61. package/lib/css/CssGenerator.js +1 -1
  62. package/lib/css/CssModulesPlugin.js +8 -6
  63. package/lib/debug/ProfilingPlugin.js +18 -21
  64. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  65. package/lib/dependencies/ContextElementDependency.js +1 -1
  66. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  68. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  69. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  70. package/lib/dependencies/LoaderPlugin.js +5 -3
  71. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  72. package/lib/dependencies/RequireContextPlugin.js +2 -1
  73. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  74. package/lib/dependencies/WorkerPlugin.js +2 -2
  75. package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
  76. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  77. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
  78. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  79. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  80. package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
  81. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  82. package/lib/ids/NamedChunkIdsPlugin.js +4 -2
  83. package/lib/ids/NamedModuleIdsPlugin.js +4 -2
  84. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  85. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  86. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  87. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  88. package/lib/index.js +11 -0
  89. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  90. package/lib/javascript/JavascriptParser.js +634 -656
  91. package/lib/json/JsonModulesPlugin.js +4 -4
  92. package/lib/library/AbstractLibraryPlugin.js +1 -1
  93. package/lib/library/ModuleLibraryPlugin.js +60 -42
  94. package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
  95. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  96. package/lib/node/nodeConsole.js +3 -2
  97. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  98. package/lib/optimize/ConcatenatedModule.js +15 -16
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  100. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  101. package/lib/optimize/MangleExportsPlugin.js +15 -16
  102. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  103. package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
  104. package/lib/optimize/RealContentHashPlugin.js +4 -2
  105. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  106. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  107. package/lib/optimize/RuntimeChunkPlugin.js +21 -23
  108. package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
  109. package/lib/optimize/SplitChunksPlugin.js +9 -7
  110. package/lib/performance/SizeLimitsPlugin.js +3 -1
  111. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  112. package/lib/rules/BasicEffectRulePlugin.js +1 -2
  113. package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
  114. package/lib/rules/RuleSetCompiler.js +19 -5
  115. package/lib/rules/UseEffectRulePlugin.js +4 -6
  116. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  117. package/lib/schemes/DataUriPlugin.js +5 -3
  118. package/lib/schemes/FileUriPlugin.js +5 -3
  119. package/lib/schemes/HttpUriPlugin.js +186 -188
  120. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  121. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  122. package/lib/serialization/ObjectMiddleware.js +13 -0
  123. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  124. package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
  125. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  126. package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
  127. package/lib/util/concatenate.js +4 -2
  128. package/lib/util/createHash.js +3 -3
  129. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  130. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  131. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  132. package/package.json +35 -30
  133. package/schemas/WebpackOptions.check.d.ts +1 -1
  134. package/schemas/WebpackOptions.check.js +2 -2
  135. package/schemas/WebpackOptions.json +267 -26
  136. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  137. package/schemas/plugins/BannerPlugin.check.js +1 -1
  138. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  139. package/schemas/plugins/DllPlugin.check.js +1 -1
  140. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  141. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  142. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
  143. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  144. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  145. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  146. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  147. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  148. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  149. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  150. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  151. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  152. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  153. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  154. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  155. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  156. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  157. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  158. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  159. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  160. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  161. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  162. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  163. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  164. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  165. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  166. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  167. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  168. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  169. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  170. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  171. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
  172. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
  174. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  175. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  176. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  177. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
  178. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
  180. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  182. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  183. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  184. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  185. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  186. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  187. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  188. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  189. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  190. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  191. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  192. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  193. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  194. package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
  195. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  196. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  197. package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
  198. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  199. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  200. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  201. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  202. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  203. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  204. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  209. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  210. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  211. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  212. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  213. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  214. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  215. package/types.d.ts +587 -207
  216. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
  217. package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
  218. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  219. package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -16,6 +16,7 @@ const { mkdirp, dirname, join } = require("../util/fs");
16
16
  const memoize = require("../util/memoize");
17
17
 
18
18
  /** @typedef {import("http").IncomingMessage} IncomingMessage */
19
+ /** @typedef {import("http").OutgoingHttpHeaders} OutgoingHttpHeaders */
19
20
  /** @typedef {import("http").RequestOptions} RequestOptions */
20
21
  /** @typedef {import("net").Socket} Socket */
21
22
  /** @typedef {import("stream").Readable} Readable */
@@ -147,7 +148,7 @@ const parseKeyValuePairs = str => {
147
148
  /**
148
149
  * @param {string | undefined} cacheControl Cache-Control header
149
150
  * @param {number} requestTime timestamp of request
150
- * @returns {{storeCache: boolean, storeLock: boolean, validUntil: number}} Logic for storing in cache and lockfile cache
151
+ * @returns {{ storeCache: boolean, storeLock: boolean, validUntil: number }} Logic for storing in cache and lockfile cache
151
152
  */
152
153
  const parseCacheControl = (cacheControl, requestTime) => {
153
154
  // When false resource is not stored in cache
@@ -190,7 +191,7 @@ const areLockfileEntriesEqual = (a, b) =>
190
191
 
191
192
  /**
192
193
  * @param {LockfileEntry} entry lockfile entry
193
- * @returns {`resolved: ${string}, integrity: ${string}, contentType: ${*}`} stringified entry
194
+ * @returns {`resolved: ${string}, integrity: ${string}, contentType: ${string}`} stringified entry
194
195
  */
195
196
  const entryToString = entry =>
196
197
  `resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
@@ -405,6 +406,8 @@ const cachedWithKey = (fn, forceFn = fn) => {
405
406
  /** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
406
407
  /** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
407
408
 
409
+ const PLUGIN_NAME = "HttpUriPlugin";
410
+
408
411
  class HttpUriPlugin {
409
412
  /**
410
413
  * @param {HttpUriPluginOptions} options options
@@ -440,14 +443,14 @@ class HttpUriPlugin {
440
443
  /** @type {LockfileCache} */
441
444
  let lockfileCache;
442
445
  compiler.hooks.compilation.tap(
443
- "HttpUriPlugin",
446
+ PLUGIN_NAME,
444
447
  (compilation, { normalModuleFactory }) => {
445
448
  const intermediateFs =
446
449
  /** @type {IntermediateFileSystem} */
447
450
  (compiler.intermediateFileSystem);
448
451
  const fs = compilation.inputFileSystem;
449
- const cache = compilation.getCache("webpack.HttpUriPlugin");
450
- const logger = compilation.getLogger("webpack.HttpUriPlugin");
452
+ const cache = compilation.getCache(`webpack.${PLUGIN_NAME}`);
453
+ const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
451
454
  /** @type {string} */
452
455
  const lockfileLocation =
453
456
  this._lockfileLocation ||
@@ -634,11 +637,14 @@ class HttpUriPlugin {
634
637
  const resolveContent = (url, integrity, callback) => {
635
638
  /**
636
639
  * @param {Error | null} err error
637
- * @param {TODO} result result result
640
+ * @param {FetchResult=} _result fetch result
638
641
  * @returns {void}
639
642
  */
640
- const handleResult = (err, result) => {
643
+ const handleResult = (err, _result) => {
641
644
  if (err) return callback(err);
645
+
646
+ const result = /** @type {FetchResult} */ (_result);
647
+
642
648
  if ("location" in result) {
643
649
  return resolveContent(
644
650
  result.location,
@@ -655,6 +661,7 @@ class HttpUriPlugin {
655
661
  }
656
662
  );
657
663
  }
664
+
658
665
  if (
659
666
  !result.fresh &&
660
667
  integrity &&
@@ -663,12 +670,14 @@ class HttpUriPlugin {
663
670
  ) {
664
671
  return fetchContent.force(url, handleResult);
665
672
  }
673
+
666
674
  return callback(null, {
667
675
  entry: result.entry,
668
676
  content: result.content,
669
677
  storeLock: result.storeLock
670
678
  });
671
679
  };
680
+
672
681
  fetchContent(url, handleResult);
673
682
  };
674
683
 
@@ -680,164 +689,162 @@ class HttpUriPlugin {
680
689
  */
681
690
  const fetchContentRaw = (url, cachedResult, callback) => {
682
691
  const requestTime = Date.now();
683
- fetch(
684
- new URL(url),
685
- {
686
- headers: {
687
- "accept-encoding": "gzip, deflate, br",
688
- "user-agent": "webpack",
689
- "if-none-match": /** @type {TODO} */ (
690
- cachedResult ? cachedResult.etag || null : null
691
- )
692
- }
693
- },
694
- res => {
695
- const etag = res.headers.etag;
696
- const location = res.headers.location;
697
- const cacheControl = res.headers["cache-control"];
698
- const { storeLock, storeCache, validUntil } = parseCacheControl(
699
- cacheControl,
700
- requestTime
701
- );
702
- /**
703
- * @param {Partial<Pick<FetchResultMeta, "fresh">> & (Pick<RedirectFetchResult, "location"> | Pick<ContentFetchResult, "content" | "entry">)} partialResult result
704
- * @returns {void}
705
- */
706
- const finishWith = partialResult => {
707
- if ("location" in partialResult) {
708
- logger.debug(
709
- `GET ${url} [${res.statusCode}] -> ${partialResult.location}`
710
- );
711
- } else {
712
- logger.debug(
713
- `GET ${url} [${res.statusCode}] ${Math.ceil(
714
- partialResult.content.length / 1024
715
- )} kB${!storeLock ? " no-cache" : ""}`
716
- );
717
- }
718
- const result = {
719
- ...partialResult,
720
- fresh: true,
721
- storeLock,
722
- storeCache,
723
- validUntil,
724
- etag
725
- };
726
- if (!storeCache) {
727
- logger.log(
728
- `${url} can't be stored in cache, due to Cache-Control header: ${cacheControl}`
729
- );
730
- return callback(null, result);
731
- }
732
- cache.store(
733
- url,
734
- null,
735
- {
736
- ...result,
737
- fresh: false
738
- },
739
- err => {
740
- if (err) {
741
- logger.warn(
742
- `${url} can't be stored in cache: ${err.message}`
743
- );
744
- logger.debug(err.stack);
745
- }
746
- callback(null, result);
747
- }
692
+ /** @type {OutgoingHttpHeaders} */
693
+ const headers = {
694
+ "accept-encoding": "gzip, deflate, br",
695
+ "user-agent": "webpack"
696
+ };
697
+
698
+ if (cachedResult && cachedResult.etag) {
699
+ headers["if-none-match"] = cachedResult.etag;
700
+ }
701
+
702
+ fetch(new URL(url), { headers }, res => {
703
+ const etag = res.headers.etag;
704
+ const location = res.headers.location;
705
+ const cacheControl = res.headers["cache-control"];
706
+ const { storeLock, storeCache, validUntil } = parseCacheControl(
707
+ cacheControl,
708
+ requestTime
709
+ );
710
+ /**
711
+ * @param {Partial<Pick<FetchResultMeta, "fresh">> & (Pick<RedirectFetchResult, "location"> | Pick<ContentFetchResult, "content" | "entry">)} partialResult result
712
+ * @returns {void}
713
+ */
714
+ const finishWith = partialResult => {
715
+ if ("location" in partialResult) {
716
+ logger.debug(
717
+ `GET ${url} [${res.statusCode}] -> ${partialResult.location}`
718
+ );
719
+ } else {
720
+ logger.debug(
721
+ `GET ${url} [${res.statusCode}] ${Math.ceil(
722
+ partialResult.content.length / 1024
723
+ )} kB${!storeLock ? " no-cache" : ""}`
748
724
  );
725
+ }
726
+ const result = {
727
+ ...partialResult,
728
+ fresh: true,
729
+ storeLock,
730
+ storeCache,
731
+ validUntil,
732
+ etag
749
733
  };
750
- if (res.statusCode === 304) {
751
- const result = /** @type {FetchResult} */ (cachedResult);
752
- if (
753
- result.validUntil < validUntil ||
754
- result.storeLock !== storeLock ||
755
- result.storeCache !== storeCache ||
756
- result.etag !== etag
757
- ) {
758
- return finishWith(result);
759
- }
760
- logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
761
- return callback(null, { ...result, fresh: true });
734
+ if (!storeCache) {
735
+ logger.log(
736
+ `${url} can't be stored in cache, due to Cache-Control header: ${cacheControl}`
737
+ );
738
+ return callback(null, result);
762
739
  }
740
+ cache.store(
741
+ url,
742
+ null,
743
+ {
744
+ ...result,
745
+ fresh: false
746
+ },
747
+ err => {
748
+ if (err) {
749
+ logger.warn(
750
+ `${url} can't be stored in cache: ${err.message}`
751
+ );
752
+ logger.debug(err.stack);
753
+ }
754
+ callback(null, result);
755
+ }
756
+ );
757
+ };
758
+ if (res.statusCode === 304) {
759
+ const result = /** @type {FetchResult} */ (cachedResult);
763
760
  if (
764
- location &&
765
- res.statusCode &&
766
- res.statusCode >= 301 &&
767
- res.statusCode <= 308
761
+ result.validUntil < validUntil ||
762
+ result.storeLock !== storeLock ||
763
+ result.storeCache !== storeCache ||
764
+ result.etag !== etag
768
765
  ) {
769
- const result = {
770
- location: new URL(location, url).href
771
- };
772
- if (
773
- !cachedResult ||
774
- !("location" in cachedResult) ||
775
- cachedResult.location !== result.location ||
776
- cachedResult.validUntil < validUntil ||
777
- cachedResult.storeLock !== storeLock ||
778
- cachedResult.storeCache !== storeCache ||
779
- cachedResult.etag !== etag
780
- ) {
781
- return finishWith(result);
782
- }
783
- logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
784
- return callback(null, {
785
- ...result,
786
- fresh: true,
787
- storeLock,
788
- storeCache,
789
- validUntil,
790
- etag
791
- });
766
+ return finishWith(result);
792
767
  }
793
- const contentType = res.headers["content-type"] || "";
794
- /** @type {Buffer[]} */
795
- const bufferArr = [];
796
-
797
- const contentEncoding = res.headers["content-encoding"];
798
- /** @type {Readable} */
799
- let stream = res;
800
- if (contentEncoding === "gzip") {
801
- stream = stream.pipe(createGunzip());
802
- } else if (contentEncoding === "br") {
803
- stream = stream.pipe(createBrotliDecompress());
804
- } else if (contentEncoding === "deflate") {
805
- stream = stream.pipe(createInflate());
768
+ logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
769
+ return callback(null, { ...result, fresh: true });
770
+ }
771
+ if (
772
+ location &&
773
+ res.statusCode &&
774
+ res.statusCode >= 301 &&
775
+ res.statusCode <= 308
776
+ ) {
777
+ const result = {
778
+ location: new URL(location, url).href
779
+ };
780
+ if (
781
+ !cachedResult ||
782
+ !("location" in cachedResult) ||
783
+ cachedResult.location !== result.location ||
784
+ cachedResult.validUntil < validUntil ||
785
+ cachedResult.storeLock !== storeLock ||
786
+ cachedResult.storeCache !== storeCache ||
787
+ cachedResult.etag !== etag
788
+ ) {
789
+ return finishWith(result);
806
790
  }
807
-
808
- stream.on("data", chunk => {
809
- bufferArr.push(chunk);
791
+ logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
792
+ return callback(null, {
793
+ ...result,
794
+ fresh: true,
795
+ storeLock,
796
+ storeCache,
797
+ validUntil,
798
+ etag
810
799
  });
800
+ }
801
+ const contentType = res.headers["content-type"] || "";
802
+ /** @type {Buffer[]} */
803
+ const bufferArr = [];
811
804
 
812
- stream.on("end", () => {
813
- if (!res.complete) {
814
- logger.log(`GET ${url} [${res.statusCode}] (terminated)`);
815
- return callback(new Error(`${url} request was terminated`));
816
- }
805
+ const contentEncoding = res.headers["content-encoding"];
806
+ /** @type {Readable} */
807
+ let stream = res;
808
+ if (contentEncoding === "gzip") {
809
+ stream = stream.pipe(createGunzip());
810
+ } else if (contentEncoding === "br") {
811
+ stream = stream.pipe(createBrotliDecompress());
812
+ } else if (contentEncoding === "deflate") {
813
+ stream = stream.pipe(createInflate());
814
+ }
817
815
 
818
- const content = Buffer.concat(bufferArr);
816
+ stream.on("data", chunk => {
817
+ bufferArr.push(chunk);
818
+ });
819
819
 
820
- if (res.statusCode !== 200) {
821
- logger.log(`GET ${url} [${res.statusCode}]`);
822
- return callback(
823
- new Error(
824
- `${url} request status code = ${
825
- res.statusCode
826
- }\n${content.toString("utf-8")}`
827
- )
828
- );
829
- }
820
+ stream.on("end", () => {
821
+ if (!res.complete) {
822
+ logger.log(`GET ${url} [${res.statusCode}] (terminated)`);
823
+ return callback(new Error(`${url} request was terminated`));
824
+ }
830
825
 
831
- const integrity = computeIntegrity(content);
832
- const entry = { resolved: url, integrity, contentType };
826
+ const content = Buffer.concat(bufferArr);
833
827
 
834
- finishWith({
835
- entry,
836
- content
837
- });
828
+ if (res.statusCode !== 200) {
829
+ logger.log(`GET ${url} [${res.statusCode}]`);
830
+ return callback(
831
+ new Error(
832
+ `${url} request status code = ${
833
+ res.statusCode
834
+ }\n${content.toString("utf-8")}`
835
+ )
836
+ );
837
+ }
838
+
839
+ const integrity = computeIntegrity(content);
840
+ const entry = { resolved: url, integrity, contentType };
841
+
842
+ finishWith({
843
+ entry,
844
+ content
838
845
  });
839
- }
840
- ).on("error", err => {
846
+ });
847
+ }).on("error", err => {
841
848
  logger.log(`GET ${url} (error)`);
842
849
  err.message += `\nwhile fetching ${url}`;
843
850
  callback(err);
@@ -847,7 +854,7 @@ class HttpUriPlugin {
847
854
  const fetchContent = cachedWithKey(
848
855
  /**
849
856
  * @param {string} url URL
850
- * @param {(err: Error | null, result?: { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }) => void} callback callback
857
+ * @param {(err: Error | null, result?: FetchResult) => void} callback callback
851
858
  * @returns {void}
852
859
  */
853
860
  (url, callback) => {
@@ -1154,19 +1161,16 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1154
1161
  };
1155
1162
  normalModuleFactory.hooks.resolveForScheme
1156
1163
  .for(scheme)
1157
- .tapAsync(
1158
- "HttpUriPlugin",
1159
- (resourceData, resolveData, callback) => {
1160
- respondWithUrlModule(
1161
- new URL(resourceData.resource),
1162
- resourceData,
1163
- callback
1164
- );
1165
- }
1166
- );
1164
+ .tapAsync(PLUGIN_NAME, (resourceData, resolveData, callback) => {
1165
+ respondWithUrlModule(
1166
+ new URL(resourceData.resource),
1167
+ resourceData,
1168
+ callback
1169
+ );
1170
+ });
1167
1171
  normalModuleFactory.hooks.resolveInScheme
1168
1172
  .for(scheme)
1169
- .tapAsync("HttpUriPlugin", (resourceData, data, callback) => {
1173
+ .tapAsync(PLUGIN_NAME, (resourceData, data, callback) => {
1170
1174
  // Only handle relative urls (./xxx, ../xxx, /xxx, //xxx)
1171
1175
  if (
1172
1176
  data.dependencyType !== "url" &&
@@ -1183,7 +1187,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1183
1187
  const hooks = NormalModule.getCompilationHooks(compilation);
1184
1188
  hooks.readResourceForScheme
1185
1189
  .for(scheme)
1186
- .tapAsync("HttpUriPlugin", (resource, module, callback) =>
1190
+ .tapAsync(PLUGIN_NAME, (resource, module, callback) =>
1187
1191
  getInfo(resource, (err, _result) => {
1188
1192
  if (err) return callback(err);
1189
1193
  const result = /** @type {Info} */ (_result);
@@ -1192,33 +1196,27 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1192
1196
  callback(null, result.content);
1193
1197
  })
1194
1198
  );
1195
- hooks.needBuild.tapAsync(
1196
- "HttpUriPlugin",
1197
- (module, context, callback) => {
1198
- if (
1199
- module.resource &&
1200
- module.resource.startsWith(`${scheme}://`)
1201
- ) {
1202
- getInfo(module.resource, (err, _result) => {
1203
- if (err) return callback(err);
1204
- const result = /** @type {Info} */ (_result);
1205
- if (
1206
- result.entry.integrity !==
1207
- /** @type {BuildInfo} */
1208
- (module.buildInfo).resourceIntegrity
1209
- ) {
1210
- return callback(null, true);
1211
- }
1212
- callback();
1213
- });
1214
- } else {
1215
- return callback();
1216
- }
1199
+ hooks.needBuild.tapAsync(PLUGIN_NAME, (module, context, callback) => {
1200
+ if (module.resource && module.resource.startsWith(`${scheme}://`)) {
1201
+ getInfo(module.resource, (err, _result) => {
1202
+ if (err) return callback(err);
1203
+ const result = /** @type {Info} */ (_result);
1204
+ if (
1205
+ result.entry.integrity !==
1206
+ /** @type {BuildInfo} */
1207
+ (module.buildInfo).resourceIntegrity
1208
+ ) {
1209
+ return callback(null, true);
1210
+ }
1211
+ callback();
1212
+ });
1213
+ } else {
1214
+ return callback();
1217
1215
  }
1218
- );
1216
+ });
1219
1217
  }
1220
1218
  compilation.hooks.finishModules.tapAsync(
1221
- "HttpUriPlugin",
1219
+ PLUGIN_NAME,
1222
1220
  (modules, callback) => {
1223
1221
  if (!lockfileUpdates) return callback();
1224
1222
  const ext = extname(lockfileLocation);
@@ -0,0 +1,42 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ */
4
+
5
+ "use strict";
6
+
7
+ /** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
8
+ /** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
9
+
10
+ /** @typedef {Error & { cause: unknown, errors: EXPECTED_ANY[] }} AggregateError */
11
+
12
+ class AggregateErrorSerializer {
13
+ /**
14
+ * @param {AggregateError} obj error
15
+ * @param {ObjectSerializerContext} context context
16
+ */
17
+ serialize(obj, context) {
18
+ context.write(obj.errors);
19
+ context.write(obj.message);
20
+ context.write(obj.stack);
21
+ context.write(obj.cause);
22
+ }
23
+
24
+ /**
25
+ * @param {ObjectDeserializerContext} context context
26
+ * @returns {AggregateError} error
27
+ */
28
+ deserialize(context) {
29
+ const errors = context.read();
30
+ // @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers
31
+ // eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
32
+ const err = new AggregateError(errors);
33
+
34
+ err.message = context.read();
35
+ err.stack = context.read();
36
+ err.cause = context.read();
37
+
38
+ return err;
39
+ }
40
+ }
41
+
42
+ module.exports = AggregateErrorSerializer;
@@ -7,6 +7,8 @@
7
7
  /** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
8
8
  /** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
9
9
 
10
+ /** @typedef {Error & { cause?: unknown }} ErrorWithCause */
11
+
10
12
  class ErrorObjectSerializer {
11
13
  /**
12
14
  * @param {ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor} Type error type
@@ -22,7 +24,10 @@ class ErrorObjectSerializer {
22
24
  serialize(obj, context) {
23
25
  context.write(obj.message);
24
26
  context.write(obj.stack);
25
- context.write(/** @type {Error & { cause: "unknown" }} */ (obj).cause);
27
+ context.write(
28
+ /** @type {ErrorWithCause} */
29
+ (obj).cause
30
+ );
26
31
  }
27
32
 
28
33
  /**
@@ -34,7 +39,7 @@ class ErrorObjectSerializer {
34
39
 
35
40
  err.message = context.read();
36
41
  err.stack = context.read();
37
- /** @type {Error & { cause: "unknown" }} */
42
+ /** @type {ErrorWithCause} */
38
43
  (err).cause = context.read();
39
44
 
40
45
  return err;
@@ -6,6 +6,7 @@
6
6
 
7
7
  const { DEFAULTS } = require("../config/defaults");
8
8
  const createHash = require("../util/createHash");
9
+ const AggregateErrorSerializer = require("./AggregateErrorSerializer");
9
10
  const ArraySerializer = require("./ArraySerializer");
10
11
  const DateObjectSerializer = require("./DateObjectSerializer");
11
12
  const ErrorObjectSerializer = require("./ErrorObjectSerializer");
@@ -140,6 +141,7 @@ const loadedRequests = new Set();
140
141
  const NOT_SERIALIZABLE = {};
141
142
 
142
143
  const jsTypes = new Map();
144
+
143
145
  jsTypes.set(Object, new PlainObjectSerializer());
144
146
  jsTypes.set(Array, new ArraySerializer());
145
147
  jsTypes.set(null, new NullPrototypeObjectSerializer());
@@ -154,6 +156,17 @@ jsTypes.set(ReferenceError, new ErrorObjectSerializer(ReferenceError));
154
156
  jsTypes.set(SyntaxError, new ErrorObjectSerializer(SyntaxError));
155
157
  jsTypes.set(TypeError, new ErrorObjectSerializer(TypeError));
156
158
 
159
+ // @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers
160
+ // eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
161
+ if (typeof AggregateError !== "undefined") {
162
+ jsTypes.set(
163
+ // @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers
164
+ // eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
165
+ AggregateError,
166
+ new AggregateErrorSerializer()
167
+ );
168
+ }
169
+
157
170
  // If in a sandboxed environment (e.g. jest), this escapes the sandbox and registers
158
171
  // real Object and Array types to. These types may occur in the wild too, e.g. when
159
172
  // using Structured Clone in postMessage.
@@ -36,6 +36,8 @@ const validate = createSchemaValidation(
36
36
 
37
37
  /** @typedef {Map<string, { config: ProvideOptions, version: string | undefined | false }>} ResolvedProvideMap */
38
38
 
39
+ const PLUGIN_NAME = "ProvideSharedPlugin";
40
+
39
41
  class ProvideSharedPlugin {
40
42
  /**
41
43
  * @param {ProvideSharedPluginOptions} options options
@@ -83,7 +85,7 @@ class ProvideSharedPlugin {
83
85
  const compilationData = new WeakMap();
84
86
 
85
87
  compiler.hooks.compilation.tap(
86
- "ProvideSharedPlugin",
88
+ PLUGIN_NAME,
87
89
  (compilation, { normalModuleFactory }) => {
88
90
  /** @type {ResolvedProvideMap} */
89
91
  const resolvedProvideMap = new Map();
@@ -156,7 +158,7 @@ class ProvideSharedPlugin {
156
158
  });
157
159
  };
158
160
  normalModuleFactory.hooks.module.tap(
159
- "ProvideSharedPlugin",
161
+ PLUGIN_NAME,
160
162
  (module, { resource, resourceResolveData }, resolveData) => {
161
163
  if (resolvedProvideMap.has(/** @type {string} */ (resource))) {
162
164
  return module;
@@ -194,7 +196,7 @@ class ProvideSharedPlugin {
194
196
  );
195
197
  }
196
198
  );
197
- compiler.hooks.finishMake.tapPromise("ProvideSharedPlugin", compilation => {
199
+ compiler.hooks.finishMake.tapPromise(PLUGIN_NAME, compilation => {
198
200
  const resolvedProvideMap = compilationData.get(compilation);
199
201
  if (!resolvedProvideMap) return Promise.resolve();
200
202
  return Promise.all(
@@ -225,7 +227,7 @@ class ProvideSharedPlugin {
225
227
  });
226
228
 
227
229
  compiler.hooks.compilation.tap(
228
- "ProvideSharedPlugin",
230
+ PLUGIN_NAME,
229
231
  (compilation, { normalModuleFactory }) => {
230
232
  compilation.dependencyFactories.set(
231
233
  ProvideForSharedDependency,