@depup/webpack 5.109.0-depup.0 → 5.109.2-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 (62) hide show
  1. package/README.md +4 -4
  2. package/bin/webpack.js +12 -0
  3. package/changes.json +4 -4
  4. package/lib/ChunkGraph.js +17 -15
  5. package/lib/CleanPlugin.js +11 -9
  6. package/lib/CompatibilityPlugin.js +31 -0
  7. package/lib/Compilation.js +21 -5
  8. package/lib/Compiler.js +16 -4
  9. package/lib/DefinePlugin.js +47 -20
  10. package/lib/ExportsInfo.js +22 -5
  11. package/lib/ExternalModule.js +10 -7
  12. package/lib/FileSystemInfo.js +126 -26
  13. package/lib/FlagDependencyUsagePlugin.js +33 -12
  14. package/lib/InitFragment.js +20 -32
  15. package/lib/ModuleFilenameHelpers.js +13 -2
  16. package/lib/NormalModule.js +80 -71
  17. package/lib/NormalModuleFactory.js +8 -2
  18. package/lib/RuntimePlugin.js +40 -113
  19. package/lib/Template.js +23 -3
  20. package/lib/cache/PackFileCacheStrategy.js +259 -5
  21. package/lib/config/defaults.js +21 -2
  22. package/lib/container/HoistContainerReferencesPlugin.js +47 -55
  23. package/lib/container/ModuleFederationPlugin.js +15 -9
  24. package/lib/css/CssGenerator.js +8 -2
  25. package/lib/css/CssLoadingRuntimeModule.js +25 -12
  26. package/lib/css/CssModulesPlugin.js +29 -18
  27. package/lib/css/CssParser.js +135 -50
  28. package/lib/css/syntax.js +862 -765
  29. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
  30. package/lib/dependencies/CommonJsFullRequireDependency.js +33 -4
  31. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -0
  32. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -1
  33. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +17 -9
  34. package/lib/dependencies/HarmonyImportDependency.js +1 -1
  35. package/lib/dependencies/HarmonyImportGuard.js +2 -1
  36. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -7
  37. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -9
  38. package/lib/hmr/lazyCompilationBackend.js +19 -4
  39. package/lib/html/HtmlGenerator.js +23 -3
  40. package/lib/html/HtmlModulesPlugin.js +30 -12
  41. package/lib/html/syntax.js +2485 -2399
  42. package/lib/ids/IdHelpers.js +24 -10
  43. package/lib/javascript/JavascriptModulesPlugin.js +83 -49
  44. package/lib/javascript/JavascriptParser.js +49 -13
  45. package/lib/javascript/syntax.js +700 -43
  46. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +10 -2
  47. package/lib/node/ReadFileCompileWasmPlugin.js +10 -2
  48. package/lib/optimize/AggressiveMergingPlugin.js +19 -15
  49. package/lib/optimize/ConcatenatedModule.js +19 -15
  50. package/lib/optimize/ModuleConcatenationPlugin.js +73 -24
  51. package/lib/optimize/RealContentHashPlugin.js +10 -7
  52. package/lib/optimize/SplitChunksPlugin.js +146 -44
  53. package/lib/prefetch/ResourceHintPlugin.js +96 -72
  54. package/lib/serialization/BinaryMiddleware.js +270 -938
  55. package/lib/serialization/FileMiddleware.js +299 -60
  56. package/lib/stats/DefaultStatsFactoryPlugin.js +204 -198
  57. package/lib/stats/DefaultStatsPrinterPlugin.js +24 -166
  58. package/lib/stats/StatsFactory.js +31 -9
  59. package/lib/util/identifier.js +21 -1
  60. package/package.json +10 -10
  61. package/schemas/WebpackOptions.json +110 -55
  62. package/types.d.ts +832 -247
@@ -100,6 +100,67 @@ const compilationResolvers = new WeakMap();
100
100
  // magic comments still work — they route through `applyParsedHints`.
101
101
  const DEFAULT_ASSETS_EXCLUDE_REGEXP = /\.(?:webmanifest|pdf|txt)(?:\?.*)?$/i;
102
102
 
103
+ // Initial-graph auto hints target JS chunk output files only.
104
+ const JS_CHUNK_FILE_REGEXP = /\.m?jsx?$/i;
105
+
106
+ /**
107
+ * True for the URL-referenced-asset deps that can carry resource-hint flags.
108
+ * Type guard so callers keep the narrowed union without re-listing the classes.
109
+ * @param {import("../Dependency")} dep dependency
110
+ * @returns {dep is URLDependency | CssUrlDependency | HtmlSourceDependency} whether it is a URL asset dep
111
+ */
112
+ const isUrlAssetDep = (dep) =>
113
+ dep instanceof URLDependency ||
114
+ dep instanceof CssUrlDependency ||
115
+ dep instanceof HtmlSourceDependency;
116
+
117
+ /**
118
+ * True for the CSS / HTML URL-asset deps whose templates don't run for JS
119
+ * output — the plugin lifts their hint flags into JS runtime requirements
120
+ * itself. JS `URLDependency` lifts its own, so it is excluded here.
121
+ * @param {import("../Dependency")} dep dependency
122
+ * @returns {dep is CssUrlDependency | HtmlSourceDependency} whether it is a CSS/HTML URL asset dep
123
+ */
124
+ const isCssOrHtmlUrlAssetDep = (dep) =>
125
+ dep instanceof CssUrlDependency || dep instanceof HtmlSourceDependency;
126
+
127
+ /**
128
+ * Entry chunk name for a hint's `hostChunks` (Vite's `hostId`); the id is a
129
+ * stable fallback for unnamed chunks.
130
+ * @param {import("../Chunk")} chunk chunk
131
+ * @returns {string} name or stringified id
132
+ */
133
+ const chunkHostName = (chunk) => chunk.name || String(chunk.id);
134
+
135
+ /**
136
+ * Walk `chunks` × their modules × dependencies and yield each distinct
137
+ * URL-asset module carrying a prefetch/preload flag, deduping targets within a
138
+ * single call. One shared walk for the entrypoint-hint and HTML-hint passes,
139
+ * which would otherwise each re-implement the same 4-level nesting.
140
+ * @param {Compilation} compilation compilation
141
+ * @param {Iterable<import("../Chunk")>} chunks chunks to scan
142
+ * @returns {IterableIterator<{ dep: URLDependency | CssUrlDependency | HtmlSourceDependency, target: Module, chunk: import("../Chunk") }>} hinted assets
143
+ */
144
+ function* iterateHintedUrlAssets(compilation, chunks) {
145
+ const { chunkGraph, moduleGraph } = compilation;
146
+ /** @type {WeakSet<Module>} */
147
+ const seen = new WeakSet();
148
+ for (const chunk of chunks) {
149
+ for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
150
+ const deps = module.dependencies;
151
+ if (!deps) continue;
152
+ for (const dep of deps) {
153
+ if (!isUrlAssetDep(dep)) continue;
154
+ if (!dep.prefetch && !dep.preload) continue;
155
+ const target = moduleGraph.getModule(dep);
156
+ if (!target || seen.has(target)) continue;
157
+ seen.add(target);
158
+ yield { dep, target, chunk };
159
+ }
160
+ }
161
+ }
162
+ }
163
+
103
164
  /**
104
165
  * Merge the matching `UrlHintRule`s for a request. Rules match by
105
166
  * `test`/`include`/`exclude` (omit all three → matches everything); later
@@ -238,13 +299,13 @@ const collectEntrypointHints = (compilation, entryName, hints) => {
238
299
  for (const chunk of entrypoint.chunks) {
239
300
  if (chunk === entryChunk) continue;
240
301
  for (const file of chunk.files) {
241
- if (!/\.m?jsx?$/i.test(file)) continue;
302
+ if (!JS_CHUNK_FILE_REGEXP.test(file)) continue;
242
303
  const href = publicPath + file;
243
304
  /** @type {EntrypointHint} */
244
305
  const h = {
245
306
  rel,
246
307
  href,
247
- hostChunks: [chunk.name || String(chunk.id)]
308
+ hostChunks: [chunkHostName(chunk)]
248
309
  };
249
310
  if (rel === "preload") h.as = "script";
250
311
  push(h);
@@ -256,45 +317,30 @@ const collectEntrypointHints = (compilation, entryName, hints) => {
256
317
  // runtime via `dynamicImportPrefetch/Preload` parser options).
257
318
  /** @type {Set<import("../Chunk")>} */
258
319
  const chunkSet = new Set(entrypoint.chunks);
259
- const rt = entrypoint.getRuntimeChunk();
260
- if (rt) chunkSet.add(rt);
261
- /** @type {WeakSet<Module>} */
262
- const seenAssets = new WeakSet();
263
- for (const chunk of chunkSet) {
264
- for (const m of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
265
- if (!m.dependencies) continue;
266
- for (const d of m.dependencies) {
267
- if (
268
- !(d instanceof URLDependency) &&
269
- !(d instanceof CssUrlDependency) &&
270
- !(d instanceof HtmlSourceDependency)
271
- ) {
272
- continue;
273
- }
274
- if (!d.prefetch && !d.preload) continue;
275
- const t = compilation.moduleGraph.getModule(d);
276
- if (!t || seenAssets.has(t)) continue;
277
- seenAssets.add(t);
278
- const buildInfo =
279
- /** @type {{ filename?: string }} */
280
- (t.buildInfo);
281
- if (!buildInfo || !buildInfo.filename) continue;
282
- const asAttr =
283
- d.asAttribute ||
284
- ResourceHintRuntimeModule.guessAsAttribute(d.request);
285
- /** @type {EntrypointHint} */
286
- const h = {
287
- rel: d.preload ? "preload" : "prefetch",
288
- href: publicPath + buildInfo.filename,
289
- hostChunks: [chunk.name || String(chunk.id)]
290
- };
291
- if (asAttr) h.as = asAttr;
292
- if (d.typeAttribute) h.type = d.typeAttribute;
293
- if (d.mediaAttribute) h.media = d.mediaAttribute;
294
- if (d.fetchPriority) h.fetchPriority = d.fetchPriority;
295
- push(h);
296
- }
297
- }
320
+ const runtimeChunk = entrypoint.getRuntimeChunk();
321
+ if (runtimeChunk) chunkSet.add(runtimeChunk);
322
+ for (const { dep, target, chunk } of iterateHintedUrlAssets(
323
+ compilation,
324
+ chunkSet
325
+ )) {
326
+ const buildInfo =
327
+ /** @type {{ filename?: string }} */
328
+ (target.buildInfo);
329
+ if (!buildInfo || !buildInfo.filename) continue;
330
+ const asAttribute =
331
+ dep.asAttribute ||
332
+ ResourceHintRuntimeModule.guessAsAttribute(dep.request);
333
+ /** @type {EntrypointHint} */
334
+ const h = {
335
+ rel: dep.preload ? "preload" : "prefetch",
336
+ href: publicPath + buildInfo.filename,
337
+ hostChunks: [chunkHostName(chunk)]
338
+ };
339
+ if (asAttribute) h.as = asAttribute;
340
+ if (dep.typeAttribute) h.type = dep.typeAttribute;
341
+ if (dep.mediaAttribute) h.media = dep.mediaAttribute;
342
+ if (dep.fetchPriority) h.fetchPriority = dep.fetchPriority;
343
+ push(h);
298
344
  }
299
345
  // `hostType`: `"html"` iff the entrypoint has an extracted HTML page
300
346
  // (any `HtmlEntryDependency` with elementKind `script`/`script-module` on
@@ -493,33 +539,16 @@ class ResourceHintPlugin {
493
539
  const chunks = new Set(entrypoint.chunks);
494
540
  const entry = entrypoint.getEntrypointChunk();
495
541
  if (entry) chunks.add(entry);
496
- const rt = entrypoint.getRuntimeChunk();
497
- if (rt) chunks.add(rt);
542
+ const runtimeChunk = entrypoint.getRuntimeChunk();
543
+ if (runtimeChunk) chunks.add(runtimeChunk);
498
544
  /** @type {HtmlHintedAsset[]} */
499
545
  const hinted = [];
500
- /** @type {WeakSet<Module>} */
501
- const seen = new WeakSet();
502
- for (const c of chunks) {
503
- for (const m of compilation.chunkGraph.getChunkModulesIterable(
504
- c
505
- )) {
506
- if (!m.dependencies) continue;
507
- for (const d of m.dependencies) {
508
- if (
509
- !(d instanceof URLDependency) &&
510
- !(d instanceof CssUrlDependency) &&
511
- !(d instanceof HtmlSourceDependency)
512
- ) {
513
- continue;
514
- }
515
- if (!d.prefetch && !d.preload) continue;
516
- const t = compilation.moduleGraph.getModule(d);
517
- if (!t || seen.has(t)) continue;
518
- seen.add(t);
519
- anyHtmlHinted.add(t);
520
- hinted.push({ module: t, dep: d });
521
- }
522
- }
546
+ for (const { dep: assetDep, target } of iterateHintedUrlAssets(
547
+ compilation,
548
+ chunks
549
+ )) {
550
+ anyHtmlHinted.add(target);
551
+ hinted.push({ module: target, dep: assetDep });
523
552
  }
524
553
  // Multiple HtmlEntryDeps may share an entryName (e.g. a
525
554
  // `<script>` and a `<link rel="modulepreload">` for the
@@ -571,12 +600,7 @@ class ResourceHintPlugin {
571
600
  (module).dependencies;
572
601
  if (!deps) continue;
573
602
  for (const dep of deps) {
574
- if (
575
- !(dep instanceof CssUrlDependency) &&
576
- !(dep instanceof HtmlSourceDependency)
577
- ) {
578
- continue;
579
- }
603
+ if (!isCssOrHtmlUrlAssetDep(dep)) continue;
580
604
  if (dep.prefetch) hasPrefetch = true;
581
605
  if (dep.preload) hasPreload = true;
582
606
  if (hasPrefetch && hasPreload) break;