@depup/webpack 5.110.3-depup.0 → 5.111.1-depup.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 (283) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/CompatibilityPlugin.js +3 -4
  10. package/lib/Compilation.js +336 -337
  11. package/lib/Compiler.js +213 -51
  12. package/lib/ConstPlugin.js +16 -132
  13. package/lib/CopyPlugin.js +1054 -0
  14. package/lib/DefinePlugin.js +24 -8
  15. package/lib/DependencyTemplate.js +2 -1
  16. package/lib/DotenvPlugin.js +24 -28
  17. package/lib/ErrorHelpers.js +113 -0
  18. package/lib/ExportsInfo.js +20 -16
  19. package/lib/ExternalModule.js +47 -22
  20. package/lib/FileSystemInfo.js +17 -14
  21. package/lib/FlagDependencyExportsPlugin.js +53 -34
  22. package/lib/FlagDependencyUsagePlugin.js +9 -13
  23. package/lib/Generator.js +24 -2
  24. package/lib/HotModuleReplacementPlugin.js +55 -7
  25. package/lib/IgnorePlugin.js +1 -1
  26. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  27. package/lib/LoaderOptionsPlugin.js +1 -1
  28. package/lib/MainTemplate.js +5 -1
  29. package/lib/Module.js +19 -10
  30. package/lib/ModuleGraph.js +6 -9
  31. package/lib/MultiCompiler.js +7 -17
  32. package/lib/MultiWatching.js +1 -1
  33. package/lib/NormalModule.js +135 -50
  34. package/lib/NormalModuleFactory.js +1 -1
  35. package/lib/RuntimeGlobals.js +21 -7
  36. package/lib/RuntimeModule.js +28 -12
  37. package/lib/RuntimePlugin.js +30 -3
  38. package/lib/RuntimeTemplate.js +813 -518
  39. package/lib/SourceMapDevToolPlugin.js +54 -104
  40. package/lib/TemplatedPathPlugin.js +16 -59
  41. package/lib/Watching.js +9 -0
  42. package/lib/WebpackOptionsApply.js +84 -91
  43. package/lib/asset/AssetBytesGenerator.js +7 -1
  44. package/lib/asset/AssetGenerator.js +50 -24
  45. package/lib/asset/AssetModule.js +3 -0
  46. package/lib/asset/AssetSourceGenerator.js +7 -1
  47. package/lib/asset/WebManifestParser.js +7 -5
  48. package/lib/buildChunkGraph.js +11 -15
  49. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  50. package/lib/cache/IdleFileCachePlugin.js +2 -2
  51. package/lib/cache/MemoryCachePlugin.js +4 -4
  52. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  53. package/lib/cache/PackFileCacheStrategy.js +17 -19
  54. package/lib/cache/getLazyHashedEtag.js +3 -5
  55. package/lib/config/browserslistTargetHandler.js +17 -4
  56. package/lib/config/defaults.js +138 -128
  57. package/lib/config/getClaimedAssetTypes.js +10 -11
  58. package/lib/config/normalization.js +82 -12
  59. package/lib/config/target.js +13 -4
  60. package/lib/container/ContainerReferencePlugin.js +6 -0
  61. package/lib/container/RemoteRuntimeModule.js +9 -0
  62. package/lib/container/declaredRemotes.js +39 -0
  63. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  64. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  65. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  66. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  67. package/lib/css/CssGenerator.js +27 -11
  68. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  69. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  70. package/lib/css/CssModule.js +1 -1
  71. package/lib/css/CssModulesPlugin.js +7 -6
  72. package/lib/css/CssParser.js +162 -31
  73. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  74. package/lib/css/cssMinify.js +43 -32
  75. package/lib/css/data.js +3514 -869
  76. package/lib/css/syntax.js +6370 -1220
  77. package/lib/debug/ProfilingPlugin.js +7 -4
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  79. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  80. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  81. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  82. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  83. package/lib/dependencies/CommonJsPlugin.js +19 -3
  84. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  85. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  86. package/lib/dependencies/ContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  88. package/lib/dependencies/ContextElementDependency.js +1 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  90. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  91. package/lib/dependencies/CssUrlDependency.js +3 -5
  92. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  93. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  94. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  95. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  96. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
  97. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  98. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  99. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  100. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  101. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
  102. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  103. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  104. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  105. package/lib/dependencies/HtmlEntryDependency.js +124 -102
  106. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  107. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  108. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  109. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  110. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  111. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  112. package/lib/dependencies/ImportParserPlugin.js +1 -1
  113. package/lib/dependencies/LoaderPlugin.js +26 -1
  114. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  115. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  116. package/lib/dependencies/URLContextDependency.js +1 -1
  117. package/lib/dependencies/URLDependency.js +6 -5
  118. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  119. package/lib/dependencies/WorkerDependency.js +7 -7
  120. package/lib/dependencies/WorkletDependency.js +7 -11
  121. package/lib/dll/DelegatedModule.js +18 -1
  122. package/lib/dll/DllReferencePlugin.js +11 -8
  123. package/lib/dll/LibManifestPlugin.js +1 -1
  124. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  125. package/lib/errors/DuplicateModulesWarning.js +12 -7
  126. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  127. package/lib/errors/ExternalStarReexportError.js +44 -0
  128. package/lib/errors/HookWebpackError.js +3 -2
  129. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  130. package/lib/errors/ModuleParseError.js +2 -1
  131. package/lib/errors/UnusedAssetsWarning.js +36 -0
  132. package/lib/errors/UnusedFederationWarning.js +35 -0
  133. package/lib/errors/UnusedModulesWarning.js +38 -0
  134. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  135. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  136. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  137. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  138. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  139. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  140. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  141. package/lib/html/HtmlGenerator.js +72 -87
  142. package/lib/html/HtmlModulesPlugin.js +418 -200
  143. package/lib/html/HtmlParser.js +110 -147
  144. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  145. package/lib/html/data.js +142 -7
  146. package/lib/html/htmlMinify.js +92 -122
  147. package/lib/html/syntax.js +1618 -1391
  148. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  149. package/lib/index.js +49 -3
  150. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  151. package/lib/javascript/JavascriptGenerator.js +8 -1
  152. package/lib/javascript/JavascriptModule.js +1 -0
  153. package/lib/javascript/JavascriptModulesPlugin.js +73 -72
  154. package/lib/javascript/JavascriptParser.js +1970 -900
  155. package/lib/javascript/StartupHelpers.js +27 -3
  156. package/lib/javascript/data.js +172 -0
  157. package/lib/javascript/grammar.js +5546 -0
  158. package/lib/javascript/parser.js +1500 -0
  159. package/lib/javascript/regexp.js +1762 -0
  160. package/lib/javascript/regexpData.js +51 -0
  161. package/lib/javascript/syntax.js +9061 -5262
  162. package/lib/json/JsonGenerator.js +7 -1
  163. package/lib/library/ModuleLibraryPlugin.js +171 -132
  164. package/lib/loaders/LoaderRunner.js +137 -9
  165. package/lib/node/NodeWatchFileSystem.js +3 -9
  166. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  167. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  168. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  169. package/lib/optimize/ConcatenatedModule.js +178 -120
  170. package/lib/optimize/ConstExportsPlugin.js +50 -39
  171. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  172. package/lib/optimize/InlineExports.js +20 -123
  173. package/lib/optimize/InnerGraphPlugin.js +7 -13
  174. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  175. package/lib/optimize/MangleExportsPlugin.js +13 -4
  176. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  177. package/lib/optimize/RealContentHashPlugin.js +68 -9
  178. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  179. package/lib/optimize/SplitChunksPlugin.js +2 -4
  180. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  181. package/lib/performance/BroadContextsPlugin.js +1 -1
  182. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  183. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  184. package/lib/performance/EvalUsagePlugin.js +5 -2
  185. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  186. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  187. package/lib/performance/SizeLimitsPlugin.js +2 -4
  188. package/lib/performance/TopLevelThisPlugin.js +5 -4
  189. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  190. package/lib/performance/UnusedFederationPlugin.js +147 -0
  191. package/lib/performance/UnusedModulesPlugin.js +141 -0
  192. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  193. package/lib/performance/isOnlyReexported.js +65 -0
  194. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  195. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  196. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  197. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  198. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  199. package/lib/prefetch/ResourceHintPlugin.js +18 -23
  200. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  201. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  202. package/lib/rules/RuleSetCompiler.js +211 -4
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +98 -66
  204. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  205. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  206. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  207. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  208. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  209. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  210. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  211. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  212. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  213. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  214. package/lib/runtime/HelperRuntimeModule.js +10 -0
  215. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +305 -224
  216. package/lib/runtime/NonceRuntimeModule.js +9 -0
  217. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  218. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  219. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  220. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  221. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  222. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  223. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  224. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  225. package/lib/schemes/DataUriPlugin.js +3 -6
  226. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +9 -9
  228. package/lib/serialization/FileMiddleware.js +16 -16
  229. package/lib/serialization/ObjectMiddleware.js +168 -139
  230. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  231. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  232. package/lib/sharing/ShareRuntimeModule.js +9 -0
  233. package/lib/sharing/declaredShared.js +47 -0
  234. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  235. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  236. package/lib/typescript/TypeScriptPlugin.js +2 -3
  237. package/lib/url/URLParserPlugin.js +6 -8
  238. package/lib/util/LocConverter.js +4 -7
  239. package/lib/util/SourceProcessor.js +91 -91
  240. package/lib/util/async.js +292 -0
  241. package/lib/util/buildDiagnostics.js +69 -0
  242. package/lib/util/chainedImports.js +3 -4
  243. package/lib/util/concatenate.js +4 -4
  244. package/lib/util/createHooksRegistry.js +1 -2
  245. package/lib/util/dataURL.js +2 -3
  246. package/lib/util/deterministicGrouping.js +8 -13
  247. package/lib/util/findGraphRoots.js +6 -13
  248. package/lib/util/fs.js +27 -1
  249. package/lib/util/globUtils.js +1 -1
  250. package/lib/util/handlerKeys.js +40 -0
  251. package/lib/util/hash/wasm-hash.js +3 -4
  252. package/lib/util/identifier.js +20 -0
  253. package/lib/util/internalSerializables.js +5 -1
  254. package/lib/util/registerExternalSerializer.js +6 -45
  255. package/lib/util/semver.js +5 -3
  256. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  257. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  258. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  259. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  260. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  261. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  262. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  263. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  264. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  265. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  266. package/package.json +55 -46
  267. package/schemas/WebpackOptions.check.js +1 -1
  268. package/schemas/WebpackOptions.json +379 -66
  269. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  270. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  271. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  272. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  273. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  274. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  275. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  276. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  277. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  278. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  279. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  280. package/types.d.ts +1723 -604
  281. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  282. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  283. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -2,6 +2,28 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  */
4
4
 
5
+ /*
6
+
7
+ Format:
8
+
9
+ File -> Section*
10
+ Section -> ObjectSection | ReferenceSection | EscapeSection | OtherSection
11
+
12
+ ObjectSection -> ESCAPE (
13
+ number:relativeOffset (number > 0) |
14
+ string:request (string|null):export
15
+ ) Section:value* ESCAPE ESCAPE_END_OBJECT
16
+ ReferenceSection -> ESCAPE number:relativeOffset (number < 0)
17
+ EscapeSection -> ESCAPE ESCAPE_ESCAPE_VALUE (escaped value ESCAPE)
18
+ EscapeSection -> ESCAPE ESCAPE_UNDEFINED (escaped value ESCAPE)
19
+ OtherSection -> any (except ESCAPE)
20
+
21
+ Why using null as escape value?
22
+ Multiple null values can merged by the BinaryMiddleware, which makes it very efficient
23
+ Technically any value can be used.
24
+
25
+ */
26
+
5
27
  "use strict";
6
28
 
7
29
  const { DEFAULTS } = require("../config/defaults");
@@ -29,28 +51,6 @@ const SetObjectSerializer = require("./SetObjectSerializer");
29
51
 
30
52
  /** @typedef {new (...params: EXPECTED_ANY[]) => EXPECTED_ANY} Constructor */
31
53
 
32
- /*
33
-
34
- Format:
35
-
36
- File -> Section*
37
- Section -> ObjectSection | ReferenceSection | EscapeSection | OtherSection
38
-
39
- ObjectSection -> ESCAPE (
40
- number:relativeOffset (number > 0) |
41
- string:request (string|null):export
42
- ) Section:value* ESCAPE ESCAPE_END_OBJECT
43
- ReferenceSection -> ESCAPE number:relativeOffset (number < 0)
44
- EscapeSection -> ESCAPE ESCAPE_ESCAPE_VALUE (escaped value ESCAPE)
45
- EscapeSection -> ESCAPE ESCAPE_UNDEFINED (escaped value ESCAPE)
46
- OtherSection -> any (except ESCAPE)
47
-
48
- Why using null as escape value?
49
- Multiple null values can merged by the BinaryMiddleware, which makes it very efficient
50
- Technically any value can be used.
51
-
52
- */
53
-
54
54
  /**
55
55
  * Defines the object serializer snapshot type used by this module.
56
56
  * @typedef {object} ObjectSerializerSnapshot
@@ -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;
@@ -195,9 +183,8 @@ if (typeof AggregateError !== "undefined") {
195
183
  );
196
184
  }
197
185
 
198
- // If in a sandboxed environment (e.g. jest), this escapes the sandbox and registers
199
- // real Object and Array types to. These types may occur in the wild too, e.g. when
200
- // using Structured Clone in postMessage.
186
+ // In a sandboxed environment such as jest, this escapes the sandbox to register
187
+ // the real Object and Array too, which reach us through a structured clone.
201
188
  // eslint-disable-next-line n/exports-style
202
189
  if (exports.constructor !== Object) {
203
190
  // eslint-disable-next-line n/exports-style
@@ -463,16 +450,22 @@ class ObjectMiddleware extends SerializerMiddleware {
463
450
  let currentPosTypeLookup = 0;
464
451
  /** @type {Map<SerializerConfigWithSerializer, number>} */
465
452
  let objectTypeLookup = new Map();
466
- /** @type {Set<ComplexSerializableType>} */
467
- const cycleStack = new Set();
453
+ /**
454
+ * One-entry cache in front of `objectTypeLookup`, since runs of one class are common.
455
+ * @type {SerializerConfigWithSerializer | undefined}
456
+ */
457
+ let lastConfig;
458
+ /** @type {number} */
459
+ let lastConfigIndex = 0;
460
+ /** @type {ComplexSerializableType[]} */
461
+ const cycleStack = [];
468
462
  /**
469
463
  * Returns stack.
470
464
  * @param {ComplexSerializableType} item item to stack
471
465
  * @returns {string} stack
472
466
  */
473
467
  const stackToString = (item) => {
474
- const arr = [...cycleStack];
475
- arr.push(item);
468
+ const arr = [...cycleStack, item];
476
469
  return arr
477
470
  .map((item) => {
478
471
  if (typeof item === "string") {
@@ -528,63 +521,35 @@ class ObjectMiddleware extends SerializerMiddleware {
528
521
  };
529
522
  /** @type {undefined | WeakSet<Error>} */
530
523
  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
524
+ /**
525
+ * Appends the path from the root to `item`, once per error.
526
+ * @param {Error} err error thrown while writing `item`
527
+ * @param {ComplexSerializableType} item item being written
528
+ * @returns {Error} err
529
+ */
530
+ const attachSerializationPath = (err, item) => {
531
+ if (hasDebugInfoAttached === undefined) {
532
+ hasDebugInfoAttached = new WeakSet();
533
+ }
534
+ if (!hasDebugInfoAttached.has(err)) {
535
+ err.message += `\nwhile serializing ${stackToString(item)}`;
536
+ hasDebugInfoAttached.add(err);
537
+ }
538
+ return err;
574
539
  };
575
- this.extendContext(ctx);
576
540
  // Dispatched on `typeof` first: two thirds of the items are numbers,
577
541
  // booleans and `undefined`, and only 3% are buffers.
578
542
  /**
579
- * Processes the provided item.
543
+ * Writes one item into the output; the context is returned so writes chain.
580
544
  * @param {ComplexSerializableType} item item to serialize
545
+ * @returns {ObjectSerializerContext<EXPECTED_ANY>} context
581
546
  */
582
547
  const process = (item) => {
583
548
  switch (typeof item) {
584
549
  case "number":
585
550
  case "boolean":
586
551
  result.push(item);
587
- return;
552
+ return ctx;
588
553
  case "string": {
589
554
  if (item.length > 1) {
590
555
  // short strings are shorter when not emitting a reference (this saves 1 byte per empty string)
@@ -602,10 +567,10 @@ class ObjectMiddleware extends SerializerMiddleware {
602
567
  ) {
603
568
  // A back-reference is `null` + the offset.
604
569
  result.push(ESCAPE, offset);
605
- return;
570
+ return ctx;
606
571
  }
607
572
  }
608
- addReferenceable(item);
573
+ referenceable.set(item, currentPos++);
609
574
  }
610
575
 
611
576
  if (item.length > 102400 && context.logger) {
@@ -617,87 +582,115 @@ class ObjectMiddleware extends SerializerMiddleware {
617
582
  }
618
583
 
619
584
  result.push(item);
620
- return;
585
+ return ctx;
621
586
  }
622
587
  case "undefined":
623
588
  result.push(ESCAPE, ESCAPE_UNDEFINED);
624
- return;
589
+ return ctx;
625
590
  case "object": {
626
591
  // ESCAPE is null, so this covers null too
627
592
  if (item === ESCAPE) {
628
593
  result.push(ESCAPE, ESCAPE_ESCAPE_VALUE);
629
- return;
594
+ return ctx;
630
595
  }
631
596
 
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;
597
+ // buffers and objects share one reference table, so a single
598
+ // lookup answers both before the costlier buffer test
599
+ const ref = referenceable.get(item);
600
+ if (ref !== undefined) {
601
+ if (ref === IN_PROGRESS) {
602
+ throw attachSerializationPath(
603
+ new Error(
604
+ "This is a circular references. To serialize circular references use 'setCircularReference' somewhere in the circle during serialize and deserialize."
605
+ ),
606
+ item
607
+ );
638
608
  }
609
+ result.push(ESCAPE, ref - currentPos);
610
+ return ctx;
611
+ }
612
+
613
+ if (Buffer.isBuffer(item)) {
639
614
  const alreadyUsedBuffer = dedupeBuffer(item);
640
615
  if (alreadyUsedBuffer !== item) {
641
616
  const ref = referenceable.get(alreadyUsedBuffer);
642
617
  if (ref !== undefined) {
643
618
  referenceable.set(item, ref);
644
619
  result.push(ESCAPE, ref - currentPos);
645
- return;
620
+ return ctx;
646
621
  }
647
622
  item = alreadyUsedBuffer;
648
623
  }
649
- addReferenceable(item);
624
+ referenceable.set(item, currentPos++);
650
625
 
651
626
  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
- );
627
+ return ctx;
666
628
  }
667
629
 
668
630
  // Keyed by the registration itself: one per class, so it stands in for
669
631
  // `${request}/${name}` without building that string per object.
670
- const config = ObjectMiddleware.getSerializerFor(
671
- /** @type {Constructor} */
672
- (item)
632
+ const proto = Object.getPrototypeOf(item);
633
+ const registered = serializers.get(
634
+ proto === null ? null : proto.constructor
673
635
  );
636
+ /** @type {SerializerConfigWithSerializer} */
637
+ let config;
638
+ if (registered !== undefined && registered.serializer !== undefined) {
639
+ config = /** @type {SerializerConfigWithSerializer} */ (registered);
640
+ } else {
641
+ try {
642
+ // re-resolved so the miss reports which class is unregistered
643
+ config = ObjectMiddleware.getSerializerFor(
644
+ /** @type {Constructor} */
645
+ (item)
646
+ );
647
+ } catch (err) {
648
+ if (err === NOT_SERIALIZABLE) throw err;
649
+ throw attachSerializationPath(/** @type {Error} */ (err), item);
650
+ }
651
+ }
674
652
  const { request, name, serializer } = config;
675
- const lastIndex = objectTypeLookup.get(config);
653
+ const lastIndex =
654
+ config === lastConfig
655
+ ? lastConfigIndex
656
+ : objectTypeLookup.get(config);
676
657
 
677
658
  if (lastIndex === undefined) {
678
- objectTypeLookup.set(config, currentPosTypeLookup++);
659
+ lastConfigIndex = currentPosTypeLookup++;
660
+ objectTypeLookup.set(config, lastConfigIndex);
679
661
 
680
662
  result.push(ESCAPE, request, name);
681
663
  } else {
664
+ lastConfigIndex = lastIndex;
682
665
  result.push(ESCAPE, currentPosTypeLookup - lastIndex);
683
666
  }
667
+ lastConfig = config;
684
668
 
685
- cycleStack.add(item);
669
+ referenceable.set(item, IN_PROGRESS);
670
+ cycleStack.push(item);
686
671
 
687
672
  try {
688
673
  serializer.serialize(item, ctx);
689
- } finally {
690
- cycleStack.delete(item);
674
+ } catch (err) {
675
+ cycleStack.pop();
676
+ if (err !== NOT_SERIALIZABLE) {
677
+ attachSerializationPath(/** @type {Error} */ (err), item);
678
+ }
679
+ throw err;
691
680
  }
681
+ cycleStack.pop();
692
682
 
693
683
  result.push(ESCAPE, ESCAPE_END_OBJECT);
694
684
 
695
- addReferenceable(item);
696
- return;
685
+ referenceable.set(item, currentPos++);
686
+ return ctx;
697
687
  }
698
688
  case "function": {
699
689
  if (!SerializerMiddleware.isLazy(item)) {
700
- throw new Error(`Unexpected function ${item}`);
690
+ throw attachSerializationPath(
691
+ new Error(`Unexpected function ${item}`),
692
+ item
693
+ );
701
694
  }
702
695
 
703
696
  /** @type {SerializedType | undefined} */
@@ -708,10 +701,10 @@ class ObjectMiddleware extends SerializerMiddleware {
708
701
  if (typeof serializedData === "function") {
709
702
  result.push(serializedData);
710
703
  } else {
711
- throw new Error("Not implemented");
704
+ throw attachSerializationPath(new Error("Not implemented"), item);
712
705
  }
713
706
  } else if (SerializerMiddleware.isLazy(item, this)) {
714
- throw new Error("Not implemented");
707
+ throw attachSerializationPath(new Error("Not implemented"), item);
715
708
  } else {
716
709
  const data =
717
710
  /** @type {() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>} */
@@ -723,12 +716,50 @@ class ObjectMiddleware extends SerializerMiddleware {
723
716
  SerializerMiddleware.setLazySerializedValue(item, data);
724
717
  result.push(data);
725
718
  }
726
- return;
719
+ return ctx;
727
720
  }
728
721
  default:
729
722
  result.push(item);
730
723
  }
724
+ return ctx;
725
+ };
726
+ /** @type {ObjectSerializerContext<EXPECTED_ANY>} */
727
+ let ctx = {
728
+ write: process,
729
+ setCircularReference(ref) {
730
+ addReferenceable(ref);
731
+ },
732
+ snapshot() {
733
+ return {
734
+ length: result.length,
735
+ cycleStackSize: cycleStack.length,
736
+ referenceableSize: referenceable.size,
737
+ currentPos,
738
+ objectTypeLookupSize: objectTypeLookup.size,
739
+ currentPosTypeLookup
740
+ };
741
+ },
742
+ rollback(snapshot) {
743
+ result.length = snapshot.length;
744
+ cycleStack.length = snapshot.cycleStackSize;
745
+ // a `setCircularReference` since the snapshot replaced a marker on an
746
+ // item already keyed here, which `setMapSize` cannot undo
747
+ for (let i = 0; i < cycleStack.length; i++) {
748
+ const item = /** @type {ReferenceableItem} */ (cycleStack[i]);
749
+ const ref = referenceable.get(item);
750
+ if (ref !== undefined && ref >= snapshot.currentPos) {
751
+ referenceable.set(item, IN_PROGRESS);
752
+ }
753
+ }
754
+ setMapSize(referenceable, snapshot.referenceableSize);
755
+ currentPos = snapshot.currentPos;
756
+ setMapSize(objectTypeLookup, snapshot.objectTypeLookupSize);
757
+ lastConfig = undefined;
758
+ currentPosTypeLookup = snapshot.currentPosTypeLookup;
759
+ },
760
+ ...context
731
761
  };
762
+ this.extendContext(ctx);
732
763
 
733
764
  try {
734
765
  for (const item of data) {
@@ -740,10 +771,9 @@ class ObjectMiddleware extends SerializerMiddleware {
740
771
 
741
772
  throw err;
742
773
  } finally {
743
- // Get rid of these references to avoid leaking memory
744
- // This happens because the optimized code v8 generates
745
- // is optimized for our "ctx.write" method so it will reference
746
- // it from e. g. Dependency.prototype.serialize -(IC)-> ctx.write
774
+ // Drop these references, which would otherwise leak: v8 optimizes the
775
+ // generated code for this `ctx.write`, so an inline cache on
776
+ // `Dependency.prototype.serialize` keeps pointing at it.
747
777
  data =
748
778
  result =
749
779
  referenceable =
@@ -942,10 +972,9 @@ class ObjectMiddleware extends SerializerMiddleware {
942
972
  }
943
973
  return result;
944
974
  } finally {
945
- // Get rid of these references to avoid leaking memory
946
- // This happens because the optimized code v8 generates
947
- // is optimized for our "ctx.read" method so it will reference
948
- // it from e. g. Dependency.prototype.deserialize -(IC)-> ctx.read
975
+ // Drop these references, which would otherwise leak: v8 optimizes the
976
+ // generated code for this `ctx.read`, so an inline cache on
977
+ // `Dependency.prototype.deserialize` keeps pointing at it.
949
978
  result =
950
979
  referenceable =
951
980
  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;
@@ -1274,10 +1274,9 @@ const SIMPLE_EXTRACTORS = {
1274
1274
  { name, chunkGroup },
1275
1275
  { compilation }
1276
1276
  ) => {
1277
- // SSR frameworks consume this to inject the initial-chunk +
1278
- // URL-asset `<link>` tags into their server-rendered HTML without
1279
- // having to walk the chunk graph themselves. Only entrypoints
1280
- // carry hints; split-chunk / async chunk groups are skipped.
1277
+ // An SSR framework reads this to inject the `<link>` tags into its own
1278
+ // HTML without walking the chunk graph. Only entrypoints carry hints, so
1279
+ // split-chunk and async groups are skipped.
1281
1280
  if (!compilation.entrypoints.get(name)) return;
1282
1281
 
1283
1282
  const ResourceHintPlugin = require("../prefetch/ResourceHintPlugin");
@@ -1340,9 +1339,11 @@ const SIMPLE_EXTRACTORS = {
1340
1339
  const warnings = module.getWarnings();
1341
1340
  const warningsCount =
1342
1341
  warnings !== undefined ? countIterable(warnings) : 0;
1343
- const { cacheable, notCacheableReasons } = /** @type {BuildInfo} */ (
1342
+ const { cacheable, diagnostics } = /** @type {BuildInfo} */ (
1344
1343
  module.buildInfo
1345
1344
  );
1345
+ const notCacheableReasons =
1346
+ diagnostics === undefined ? undefined : diagnostics.notCacheableReasons;
1346
1347
  const preOrderIndex = /** @type {number} */ (
1347
1348
  moduleGraph.getPreOrderIndex(module)
1348
1349
  );
@@ -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"
@@ -122,9 +122,8 @@ const composeWithLoaderSourceMap = (
122
122
  */
123
123
  const stripTypes = (input) => {
124
124
  try {
125
- // Pass only `mode`. `sourceUrl` would emit a `//# sourceURL=…` pragma
126
- // into the output (V8 debugger hint), and `sourceMap: true` is
127
- // rejected in strip mode — we build the source map by hand instead.
125
+ // Only `mode`: `sourceUrl` would emit a `//# sourceURL=` pragma, and
126
+ // `sourceMap: true` is rejected in strip mode, so the map is built by hand.
128
127
  // eslint-disable-next-line n/no-unsupported-features/node-builtins
129
128
  return mod.stripTypeScriptTypes(input, { mode: "strip" });
130
129
  } catch (err) {
@@ -257,10 +257,9 @@ class URLParserPlugin {
257
257
  relative
258
258
  );
259
259
  dep.loc = parser.getLocation(expr);
260
- // `parser.javascript.urlHints` provides project-wide defaults
261
- // (resolved per-request, with `test` / `include` / `exclude`
262
- // matching); a per-URL magic comment for the same hint wins
263
- // when both are set.
260
+ // `parser.javascript.urlHints` gives the project-wide defaults,
261
+ // resolved per request; a per-URL magic comment for the same hint
262
+ // wins where both are set.
264
263
  ResourceHintPlugin.applyResourceHints(
265
264
  dep,
266
265
  this.options.urlHints,
@@ -270,10 +269,9 @@ class URLParserPlugin {
270
269
  parser.getLocation(expr)
271
270
  );
272
271
  parser.state.current.addDependency(dep);
273
- // For ESM module output the template embeds the asset's resolved
274
- // filename, so the asset must be code-generated first. Only added in
275
- // that mode — a code-gen dependency on an asset that a later watch
276
- // rebuild leaves unaffected can otherwise deadlock the scheduler.
272
+ // The ESM template embeds the asset's resolved filename, so the asset
273
+ // must be code-generated first. Added in that mode only: elsewhere the
274
+ // extra code-gen dependency can deadlock a watch rebuild.
277
275
  if (parser.state.compilation.options.output.module) {
278
276
  parser.state.module.addCodeGenerationDependency(dep);
279
277
  }