@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
@@ -18,6 +18,17 @@ const numberHash = require("../util/numberHash");
18
18
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
19
19
  /** @typedef {import("../css/CssModule").CssModuleBuildMeta} CssModuleBuildMeta */
20
20
 
21
+ // Numbers longer than this are written in exponential form ("...e+xx"), so a
22
+ // longer string can't be a plain integer id.
23
+ const MAX_NUMERIC_STRING_LENGTH = 21;
24
+ // Char codes bounding the "looks like a plain number" fast check in `avoidNumber`.
25
+ const CC_HYPHEN_MINUS = 45;
26
+ const CC_DIGIT_ONE = 49;
27
+ const CC_DIGIT_NINE = 57;
28
+ // Long ids are truncated to this length and disambiguated with a short hash.
29
+ const MAX_SHORTENED_STRING_LENGTH = 100;
30
+ const SHORTENED_STRING_HASH_LENGTH = 6;
31
+
21
32
  /**
22
33
  * Returns hash.
23
34
  * @param {string} str string to hash
@@ -38,14 +49,12 @@ const getHash = (str, len, hashFunction) => {
38
49
  * @returns {string} string prefixed by an underscore if it is a number
39
50
  */
40
51
  const avoidNumber = (str) => {
41
- // max length of a number is 21 chars, bigger numbers a written as "...e+xx"
42
- if (str.length > 21) return str;
52
+ if (str.length > MAX_NUMERIC_STRING_LENGTH) return str;
43
53
  const firstChar = str.charCodeAt(0);
44
- // skip everything that doesn't look like a number
45
- // charCodes: "-": 45, "1": 49, "9": 57
46
- if (firstChar < 49) {
47
- if (firstChar !== 45) return str;
48
- } else if (firstChar > 57) {
54
+ // Skip everything that doesn't start like a number ("-" or a digit).
55
+ if (firstChar < CC_DIGIT_ONE) {
56
+ if (firstChar !== CC_HYPHEN_MINUS) return str;
57
+ } else if (firstChar > CC_DIGIT_NINE) {
49
58
  return str;
50
59
  }
51
60
  if (str === String(Number(str))) {
@@ -70,11 +79,16 @@ const requestToId = (request) =>
70
79
  * @returns {string} string with limited max length to 100 chars
71
80
  */
72
81
  const shortenLongString = (string, delimiter, hashFunction) => {
73
- if (string.length < 100) return string;
82
+ if (string.length < MAX_SHORTENED_STRING_LENGTH) return string;
74
83
  return (
75
- string.slice(0, 100 - 6 - delimiter.length) +
84
+ string.slice(
85
+ 0,
86
+ MAX_SHORTENED_STRING_LENGTH -
87
+ SHORTENED_STRING_HASH_LENGTH -
88
+ delimiter.length
89
+ ) +
76
90
  delimiter +
77
- getHash(string, 6, hashFunction)
91
+ getHash(string, SHORTENED_STRING_HASH_LENGTH, hashFunction)
78
92
  );
79
93
  };
80
94
 
@@ -330,23 +330,89 @@ const printGeneratedCodeForStack = (module, code) => {
330
330
  * @property {boolean=} renderInObject render module in object container
331
331
  */
332
332
 
333
+ const createCompilationHooks = () => ({
334
+ /**
335
+ * @type {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>}
336
+ */
337
+ renderModuleContent: new SyncWaterfallHook([
338
+ "source",
339
+ "module",
340
+ "moduleRenderContext"
341
+ ]),
342
+ /**
343
+ * @type {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>}
344
+ */
345
+ renderModuleContainer: new SyncWaterfallHook([
346
+ "source",
347
+ "module",
348
+ "moduleRenderContext"
349
+ ]),
350
+ /**
351
+ * @type {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>}
352
+ */
353
+ renderModulePackage: new SyncWaterfallHook([
354
+ "source",
355
+ "module",
356
+ "moduleRenderContext"
357
+ ]),
358
+ /**
359
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
360
+ */
361
+ render: new SyncWaterfallHook(["source", "renderContext"]),
362
+ /**
363
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
364
+ * @since 5.41.0
365
+ */
366
+ renderContent: new SyncWaterfallHook(["source", "renderContext"]),
367
+ /**
368
+ * @type {SyncWaterfallHook<[Source, Module, StartupRenderContext]>}
369
+ * @since 5.22.0
370
+ */
371
+ renderStartup: new SyncWaterfallHook([
372
+ "source",
373
+ "module",
374
+ "startupRenderContext"
375
+ ]),
376
+ /**
377
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
378
+ */
379
+ renderChunk: new SyncWaterfallHook(["source", "renderContext"]),
380
+ /**
381
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
382
+ */
383
+ renderMain: new SyncWaterfallHook(["source", "renderContext"]),
384
+ /**
385
+ * @type {SyncWaterfallHook<[string, RenderBootstrapContext]>}
386
+ */
387
+ renderRequire: new SyncWaterfallHook(["code", "renderContext"]),
388
+ /**
389
+ * @type {SyncBailHook<[Module, Partial<RenderBootstrapContext>], string | void>}
390
+ * @since 5.22.0
391
+ */
392
+ inlineInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
393
+ /**
394
+ * @type {SyncBailHook<[Module, RenderContext], string | void>}
395
+ * @since 5.22.0
396
+ */
397
+ embedInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
398
+ /**
399
+ * @type {SyncBailHook<[RenderContext], string | void>}
400
+ * @since 5.26.1
401
+ */
402
+ strictRuntimeBailout: new SyncBailHook(["renderContext"]),
403
+ /**
404
+ * @type {SyncHook<[Chunk, Hash, ChunkHashContext]>}
405
+ */
406
+ chunkHash: new SyncHook(["chunk", "hash", "context"]),
407
+ /**
408
+ * @type {SyncBailHook<[Chunk, RenderContext], boolean | void>}
409
+ * @since 5.2.1
410
+ */
411
+ useSourceMap: new SyncBailHook(["chunk", "renderContext"])
412
+ });
413
+
333
414
  /**
334
- * Defines the compilation hooks type used by this module.
335
- * @typedef {object} CompilationHooks
336
- * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContent
337
- * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContainer
338
- * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModulePackage
339
- * @property {SyncWaterfallHook<[Source, RenderContext]>} renderChunk
340
- * @property {SyncWaterfallHook<[Source, RenderContext]>} renderMain
341
- * @property {SyncWaterfallHook<[Source, RenderContext]>} renderContent
342
- * @property {SyncWaterfallHook<[Source, RenderContext]>} render
343
- * @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
344
- * @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
345
- * @property {SyncBailHook<[Module, Partial<RenderBootstrapContext>], string | void>} inlineInRuntimeBailout
346
- * @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
347
- * @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
348
- * @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
349
- * @property {SyncBailHook<[Chunk, RenderContext], boolean | void>} useSourceMap
415
+ * @typedef {ReturnType<typeof createCompilationHooks>} CompilationHooks
350
416
  */
351
417
 
352
418
  /**
@@ -2288,39 +2354,7 @@ class JavascriptModulesPlugin {
2288
2354
  }
2289
2355
 
2290
2356
  JavascriptModulesPlugin.getCompilationHooks = createHooksRegistry(
2291
- () =>
2292
- /** @type {CompilationHooks} */ ({
2293
- renderModuleContent: new SyncWaterfallHook([
2294
- "source",
2295
- "module",
2296
- "moduleRenderContext"
2297
- ]),
2298
- renderModuleContainer: new SyncWaterfallHook([
2299
- "source",
2300
- "module",
2301
- "moduleRenderContext"
2302
- ]),
2303
- renderModulePackage: new SyncWaterfallHook([
2304
- "source",
2305
- "module",
2306
- "moduleRenderContext"
2307
- ]),
2308
- render: new SyncWaterfallHook(["source", "renderContext"]),
2309
- renderContent: new SyncWaterfallHook(["source", "renderContext"]),
2310
- renderStartup: new SyncWaterfallHook([
2311
- "source",
2312
- "module",
2313
- "startupRenderContext"
2314
- ]),
2315
- renderChunk: new SyncWaterfallHook(["source", "renderContext"]),
2316
- renderMain: new SyncWaterfallHook(["source", "renderContext"]),
2317
- renderRequire: new SyncWaterfallHook(["code", "renderContext"]),
2318
- inlineInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
2319
- embedInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
2320
- strictRuntimeBailout: new SyncBailHook(["renderContext"]),
2321
- chunkHash: new SyncHook(["chunk", "hash", "context"]),
2322
- useSourceMap: new SyncBailHook(["chunk", "renderContext"])
2323
- })
2357
+ createCompilationHooks
2324
2358
  );
2325
2359
 
2326
2360
  module.exports = JavascriptModulesPlugin;
@@ -514,11 +514,17 @@ class JavascriptParser extends Parser {
514
514
  evaluateDefinedIdentifier: new HookMap(
515
515
  () => new SyncBailHook(["expression"])
516
516
  ),
517
- /** @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression | null | undefined>>} */
517
+ /**
518
+ * @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression | null | undefined>>}
519
+ * @since 5.73.0
520
+ */
518
521
  evaluateNewExpression: new HookMap(
519
522
  () => new SyncBailHook(["expression"])
520
523
  ),
521
- /** @type {HookMap<SyncBailHook<[CallExpression], BasicEvaluatedExpression | null | undefined>>} */
524
+ /**
525
+ * @type {HookMap<SyncBailHook<[CallExpression], BasicEvaluatedExpression | null | undefined>>}
526
+ * @since 5.73.0
527
+ */
522
528
  evaluateCallExpression: new HookMap(
523
529
  () => new SyncBailHook(["expression"])
524
530
  ),
@@ -532,12 +538,18 @@ class JavascriptParser extends Parser {
532
538
  ),
533
539
  /** @type {SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>} */
534
540
  preStatement: new SyncBailHook(["statement"]),
535
- /** @type {HookMap<SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>>} */
541
+ /**
542
+ * @type {HookMap<SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>>}
543
+ * @since 5.109.0
544
+ */
536
545
  preStatementByType: new HookMap(() => new SyncBailHook(["statement"])),
537
546
 
538
547
  /** @type {SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>} */
539
548
  blockPreStatement: new SyncBailHook(["declaration"]),
540
- /** @type {HookMap<SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>>} */
549
+ /**
550
+ * @type {HookMap<SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>>}
551
+ * @since 5.109.0
552
+ */
541
553
  blockPreStatementByType: new HookMap(
542
554
  () => new SyncBailHook(["declaration"])
543
555
  ),
@@ -545,7 +557,10 @@ class JavascriptParser extends Parser {
545
557
  statement: new SyncBailHook(["statement"]),
546
558
  /** @type {SyncBailHook<[IfStatement], boolean | void>} */
547
559
  statementIf: new SyncBailHook(["statement"]),
548
- /** @type {SyncBailHook<[Expression], GuardCollection | void>} */
560
+ /**
561
+ * @type {SyncBailHook<[Expression], GuardCollection | void>}
562
+ * @since 5.105.0
563
+ */
549
564
  collectGuards: new SyncBailHook(["expression"]),
550
565
  /** @type {SyncBailHook<[Expression, ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration], boolean | void>} */
551
566
  classExtendsExpression: new SyncBailHook([
@@ -554,7 +569,10 @@ class JavascriptParser extends Parser {
554
569
  ]),
555
570
  /** @type {SyncBailHook<[MethodDefinition | PropertyDefinition | StaticBlock, ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration], boolean | void>} */
556
571
  classBodyElement: new SyncBailHook(["element", "classDefinition"]),
557
- /** @type {SyncBailHook<[Expression, MethodDefinition | PropertyDefinition, ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration], boolean | void>} */
572
+ /**
573
+ * @type {SyncBailHook<[Expression, MethodDefinition | PropertyDefinition, ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration], boolean | void>}
574
+ * @since 5.36.0
575
+ */
558
576
  classBodyValue: new SyncBailHook([
559
577
  "expression",
560
578
  "element",
@@ -604,13 +622,19 @@ class JavascriptParser extends Parser {
604
622
  varDeclarationLet: new HookMap(() => new SyncBailHook(["declaration"])),
605
623
  /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
606
624
  varDeclarationConst: new HookMap(() => new SyncBailHook(["declaration"])),
607
- /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
625
+ /**
626
+ * @type {HookMap<SyncBailHook<[Identifier], boolean | void>>}
627
+ * @since 5.100.0
628
+ */
608
629
  varDeclarationUsing: new HookMap(() => new SyncBailHook(["declaration"])),
609
630
  /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
610
631
  varDeclarationVar: new HookMap(() => new SyncBailHook(["declaration"])),
611
632
  /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
612
633
  pattern: new HookMap(() => new SyncBailHook(["pattern"])),
613
- /** @type {SyncBailHook<[Expression], boolean | void>} */
634
+ /**
635
+ * @type {SyncBailHook<[Expression], boolean | void>}
636
+ * @since 5.101.3
637
+ */
614
638
  collectDestructuringAssignmentProperties: new SyncBailHook([
615
639
  "expression"
616
640
  ]),
@@ -671,7 +695,10 @@ class JavascriptParser extends Parser {
671
695
  optionalChaining: new SyncBailHook(["optionalChaining"]),
672
696
  /** @type {HookMap<SyncBailHook<[NewExpression], boolean | void>>} */
673
697
  new: new HookMap(() => new SyncBailHook(["expression"])),
674
- /** @type {SyncBailHook<[BinaryExpression], boolean | void>} */
698
+ /**
699
+ * @type {SyncBailHook<[BinaryExpression], boolean | void>}
700
+ * @since 5.71.0
701
+ */
675
702
  binaryExpression: new SyncBailHook(["binaryExpression"]),
676
703
  /** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
677
704
  expression: new HookMap(() => new SyncBailHook(["expression"])),
@@ -695,11 +722,17 @@ class JavascriptParser extends Parser {
695
722
  expressionLogicalOperator: new SyncBailHook(["expression"]),
696
723
  /** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
697
724
  program: new SyncBailHook(["ast", "comments"]),
698
- /** @type {SyncBailHook<[ThrowStatement | ReturnStatement], boolean | void>} */
725
+ /**
726
+ * @type {SyncBailHook<[ThrowStatement | ReturnStatement], boolean | void>}
727
+ * @since 5.99.0
728
+ */
699
729
  terminate: new SyncBailHook(["statement"]),
700
730
  /** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
701
731
  finish: new SyncBailHook(["ast", "comments"]),
702
- /** @type {SyncBailHook<[Statement], boolean | void>} */
732
+ /**
733
+ * @type {SyncBailHook<[Statement], boolean | void>}
734
+ * @since 5.99.9
735
+ */
703
736
  unusedStatement: new SyncBailHook(["statement"])
704
737
  });
705
738
  this.sourceType = sourceType;
@@ -5625,8 +5658,10 @@ class JavascriptParser extends Parser {
5625
5658
  }
5626
5659
 
5627
5660
  /**
5628
- * First significant char code at or after `pos`, skipping whitespace and
5629
- * comments, or -1 at end of source.
5661
+ * First significant char code at or after `pos`, skipping whitespace,
5662
+ * comments and grouping `)` (a parenthesized node's range excludes its
5663
+ * wrapping parens, so a `,`/`;` separator can sit behind them), or -1 at
5664
+ * end of source.
5630
5665
  * @param {string} source source text
5631
5666
  * @param {number} pos start offset
5632
5667
  * @returns {number} char code of the next token, or -1
@@ -5643,6 +5678,7 @@ class JavascriptParser extends Parser {
5643
5678
  c === 13 ||
5644
5679
  c === 11 ||
5645
5680
  c === 12 ||
5681
+ c === 41 /* ) */ ||
5646
5682
  c === 0xa0 ||
5647
5683
  c === 0xfeff ||
5648
5684
  c === 0x2028 ||