webpack 5.94.0 → 5.96.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 (151) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EnvironmentPlugin.js +3 -2
  19. package/lib/EvalDevToolModulePlugin.js +5 -2
  20. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  21. package/lib/ExternalModule.js +118 -99
  22. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  23. package/lib/FileSystemInfo.js +12 -8
  24. package/lib/Generator.js +5 -4
  25. package/lib/HotModuleReplacementPlugin.js +8 -6
  26. package/lib/IgnorePlugin.js +19 -1
  27. package/lib/LoaderOptionsPlugin.js +3 -1
  28. package/lib/Module.js +9 -8
  29. package/lib/ModuleSourceTypesConstants.js +100 -0
  30. package/lib/NormalModule.js +27 -13
  31. package/lib/NormalModuleFactory.js +38 -22
  32. package/lib/OptionsApply.js +12 -1
  33. package/lib/ProgressPlugin.js +50 -10
  34. package/lib/RawModule.js +3 -4
  35. package/lib/RuntimeModule.js +3 -4
  36. package/lib/RuntimePlugin.js +11 -4
  37. package/lib/RuntimeTemplate.js +13 -42
  38. package/lib/SourceMapDevToolPlugin.js +10 -7
  39. package/lib/TemplatedPathPlugin.js +9 -3
  40. package/lib/Watching.js +2 -2
  41. package/lib/WebpackOptionsApply.js +42 -21
  42. package/lib/asset/AssetGenerator.js +347 -194
  43. package/lib/asset/AssetModulesPlugin.js +2 -1
  44. package/lib/asset/AssetSourceGenerator.js +82 -27
  45. package/lib/asset/RawDataUrlModule.js +5 -4
  46. package/lib/buildChunkGraph.js +79 -62
  47. package/lib/cache/PackFileCacheStrategy.js +69 -31
  48. package/lib/cache/ResolverCachePlugin.js +248 -173
  49. package/lib/config/defaults.js +135 -126
  50. package/lib/container/ContainerEntryModule.js +3 -4
  51. package/lib/container/ContainerPlugin.js +8 -0
  52. package/lib/container/FallbackModule.js +2 -2
  53. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  54. package/lib/container/ModuleFederationPlugin.js +38 -1
  55. package/lib/container/RemoteModule.js +4 -2
  56. package/lib/container/RemoteRuntimeModule.js +4 -2
  57. package/lib/css/CssExportsGenerator.js +16 -12
  58. package/lib/css/CssGenerator.js +22 -16
  59. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  60. package/lib/css/CssModulesPlugin.js +122 -77
  61. package/lib/css/CssParser.js +655 -526
  62. package/lib/css/walkCssTokens.js +1168 -338
  63. package/lib/debug/ProfilingPlugin.js +5 -0
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  66. package/lib/dependencies/ContextDependency.js +6 -1
  67. package/lib/dependencies/ContextElementDependency.js +33 -6
  68. package/lib/dependencies/CssExportDependency.js +3 -3
  69. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  70. package/lib/dependencies/CssUrlDependency.js +33 -3
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  75. package/lib/dependencies/ImportParserPlugin.js +9 -7
  76. package/lib/dependencies/LoaderPlugin.js +19 -0
  77. package/lib/dependencies/SystemPlugin.js +2 -1
  78. package/lib/dependencies/URLPlugin.js +7 -1
  79. package/lib/dependencies/WorkerPlugin.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  81. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  82. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  83. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  84. package/lib/hmr/lazyCompilationBackend.js +1 -7
  85. package/lib/index.js +35 -6
  86. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  87. package/lib/javascript/JavascriptGenerator.js +8 -8
  88. package/lib/javascript/JavascriptModulesPlugin.js +166 -88
  89. package/lib/javascript/JavascriptParser.js +338 -117
  90. package/lib/json/JsonGenerator.js +5 -5
  91. package/lib/library/EnableLibraryPlugin.js +2 -2
  92. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  93. package/lib/library/UmdLibraryPlugin.js +16 -8
  94. package/lib/logging/Logger.js +11 -11
  95. package/lib/logging/createConsoleLogger.js +14 -14
  96. package/lib/logging/truncateArgs.js +1 -1
  97. package/lib/node/NodeWatchFileSystem.js +3 -1
  98. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  99. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  100. package/lib/node/nodeConsole.js +11 -8
  101. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  102. package/lib/optimize/ConcatenatedModule.js +44 -148
  103. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  104. package/lib/optimize/InnerGraphPlugin.js +57 -16
  105. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  106. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  107. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  108. package/lib/optimize/RealContentHashPlugin.js +1 -1
  109. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  110. package/lib/rules/RuleSetCompiler.js +2 -2
  111. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  112. package/lib/schemes/DataUriPlugin.js +1 -1
  113. package/lib/serialization/BinaryMiddleware.js +32 -19
  114. package/lib/serialization/ObjectMiddleware.js +23 -9
  115. package/lib/serialization/SerializerMiddleware.js +3 -2
  116. package/lib/serialization/types.js +2 -2
  117. package/lib/sharing/ConsumeSharedModule.js +2 -3
  118. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  119. package/lib/sharing/ProvideSharedModule.js +2 -3
  120. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  121. package/lib/stats/StatsFactory.js +12 -12
  122. package/lib/stats/StatsPrinter.js +7 -7
  123. package/lib/util/AsyncQueue.js +17 -1
  124. package/lib/util/IterableHelpers.js +1 -1
  125. package/lib/util/LazySet.js +12 -0
  126. package/lib/util/SetHelpers.js +1 -1
  127. package/lib/util/cleverMerge.js +48 -24
  128. package/lib/util/concatenate.js +227 -0
  129. package/lib/util/create-schema-validation.js +22 -9
  130. package/lib/util/deprecation.js +86 -28
  131. package/lib/util/fs.js +10 -10
  132. package/lib/util/hash/wasm-hash.js +12 -1
  133. package/lib/util/magicComment.js +21 -0
  134. package/lib/util/makeSerializable.js +24 -1
  135. package/lib/util/memoize.js +2 -1
  136. package/lib/util/runtime.js +10 -1
  137. package/lib/util/semver.js +130 -23
  138. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  140. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  141. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  142. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  143. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  144. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  145. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  146. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  147. package/package.json +19 -20
  148. package/schemas/WebpackOptions.check.js +1 -1
  149. package/schemas/WebpackOptions.json +12 -2
  150. package/types.d.ts +817 -269
  151. package/lib/util/mergeScope.js +0 -76
@@ -11,6 +11,11 @@ const EnvironmentNotSupportAsyncWarning = require("./EnvironmentNotSupportAsyncW
11
11
  const { UsageState } = require("./ExportsInfo");
12
12
  const InitFragment = require("./InitFragment");
13
13
  const Module = require("./Module");
14
+ const {
15
+ JS_TYPES,
16
+ CSS_URL_TYPES,
17
+ CSS_IMPORT_TYPES
18
+ } = require("./ModuleSourceTypesConstants");
14
19
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
15
20
  const RuntimeGlobals = require("./RuntimeGlobals");
16
21
  const Template = require("./Template");
@@ -30,6 +35,7 @@ const { register } = require("./util/serialization");
30
35
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
31
36
  /** @typedef {import("./ExportsInfo")} ExportsInfo */
32
37
  /** @typedef {import("./Generator").GenerateContext} GenerateContext */
38
+ /** @typedef {import("./Generator").SourceTypes} SourceTypes */
33
39
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
34
40
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
35
41
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
@@ -37,7 +43,6 @@ const { register } = require("./util/serialization");
37
43
  /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
38
44
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
39
45
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
40
- /** @typedef {import("./Module").SourceTypes} SourceTypes */
41
46
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
42
47
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
43
48
  /** @typedef {import("./RequestShortener")} RequestShortener */
@@ -55,8 +60,9 @@ const { register } = require("./util/serialization");
55
60
 
56
61
  /** @typedef {{ attributes?: ImportAttributes, externalType: "import" | "module" | undefined }} ImportDependencyMeta */
57
62
  /** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
63
+ /** @typedef {{ sourceType: "css-url" }} AssetDependencyMeta */
58
64
 
59
- /** @typedef {ImportDependencyMeta | CssImportDependencyMeta} DependencyMeta */
65
+ /** @typedef {ImportDependencyMeta | CssImportDependencyMeta | AssetDependencyMeta} DependencyMeta */
60
66
 
61
67
  /**
62
68
  * @typedef {object} SourceData
@@ -67,8 +73,6 @@ const { register } = require("./util/serialization");
67
73
  * @property {ReadOnlyRuntimeRequirements=} runtimeRequirements
68
74
  */
69
75
 
70
- const TYPES = new Set(["javascript"]);
71
- const CSS_TYPES = new Set(["css-import"]);
72
76
  const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
73
77
  const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
74
78
  const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
@@ -500,7 +504,18 @@ class ExternalModule extends Module {
500
504
  * @returns {SourceTypes} types available (do not mutate)
501
505
  */
502
506
  getSourceTypes() {
503
- return this.externalType === "css-import" ? CSS_TYPES : TYPES;
507
+ if (
508
+ this.externalType === "asset" &&
509
+ this.dependencyMeta &&
510
+ /** @type {AssetDependencyMeta} */
511
+ (this.dependencyMeta).sourceType === "css-url"
512
+ ) {
513
+ return CSS_URL_TYPES;
514
+ } else if (this.externalType === "css-import") {
515
+ return CSS_IMPORT_TYPES;
516
+ }
517
+
518
+ return JS_TYPES;
504
519
  }
505
520
 
506
521
  /**
@@ -526,7 +541,7 @@ class ExternalModule extends Module {
526
541
  * @returns {string} a unique identifier of the module
527
542
  */
528
543
  identifier() {
529
- return `external ${this.externalType} ${JSON.stringify(this.request)}`;
544
+ return `external ${this._resolveExternalType(this.externalType)} ${JSON.stringify(this.request)}`;
530
545
  }
531
546
 
532
547
  /**
@@ -546,25 +561,6 @@ class ExternalModule extends Module {
546
561
  return callback(null, !this.buildMeta);
547
562
  }
548
563
 
549
- /**
550
- * @param {string} externalType raw external type
551
- * @returns {string} resolved external type
552
- */
553
- getModuleImportType(externalType) {
554
- if (externalType === "module-import") {
555
- if (
556
- this.dependencyMeta &&
557
- /** @type {ImportDependencyMeta} */ (this.dependencyMeta).externalType
558
- ) {
559
- return /** @type {ImportDependencyMeta} */ (this.dependencyMeta)
560
- .externalType;
561
- }
562
- return "module";
563
- }
564
-
565
- return externalType;
566
- }
567
-
568
564
  /**
569
565
  * @param {WebpackOptions} options webpack options
570
566
  * @param {Compilation} compilation the compilation
@@ -597,6 +593,25 @@ class ExternalModule extends Module {
597
593
  canMangle = true;
598
594
  }
599
595
  break;
596
+ case "module":
597
+ if (this.buildInfo.module) {
598
+ if (!Array.isArray(request) || request.length === 1) {
599
+ this.buildMeta.exportsType = "namespace";
600
+ canMangle = true;
601
+ }
602
+ } else {
603
+ this.buildMeta.async = true;
604
+ EnvironmentNotSupportAsyncWarning.check(
605
+ this,
606
+ compilation.runtimeTemplate,
607
+ "external module"
608
+ );
609
+ if (!Array.isArray(request) || request.length === 1) {
610
+ this.buildMeta.exportsType = "namespace";
611
+ canMangle = false;
612
+ }
613
+ }
614
+ break;
600
615
  case "script":
601
616
  this.buildMeta.async = true;
602
617
  EnvironmentNotSupportAsyncWarning.check(
@@ -613,45 +628,18 @@ class ExternalModule extends Module {
613
628
  "external promise"
614
629
  );
615
630
  break;
616
- case "module":
617
631
  case "import":
618
- case "module-import": {
619
- const type = this.getModuleImportType(externalType);
620
- if (type === "module") {
621
- if (this.buildInfo.module) {
622
- if (!Array.isArray(request) || request.length === 1) {
623
- this.buildMeta.exportsType = "namespace";
624
- canMangle = true;
625
- }
626
- } else {
627
- this.buildMeta.async = true;
628
- EnvironmentNotSupportAsyncWarning.check(
629
- this,
630
- compilation.runtimeTemplate,
631
- "external module"
632
- );
633
- if (!Array.isArray(request) || request.length === 1) {
634
- this.buildMeta.exportsType = "namespace";
635
- canMangle = false;
636
- }
637
- }
638
- }
639
-
640
- if (type === "import") {
641
- this.buildMeta.async = true;
642
- EnvironmentNotSupportAsyncWarning.check(
643
- this,
644
- compilation.runtimeTemplate,
645
- "external import"
646
- );
647
- if (!Array.isArray(request) || request.length === 1) {
648
- this.buildMeta.exportsType = "namespace";
649
- canMangle = false;
650
- }
632
+ this.buildMeta.async = true;
633
+ EnvironmentNotSupportAsyncWarning.check(
634
+ this,
635
+ compilation.runtimeTemplate,
636
+ "external import"
637
+ );
638
+ if (!Array.isArray(request) || request.length === 1) {
639
+ this.buildMeta.exportsType = "namespace";
640
+ canMangle = false;
651
641
  }
652
-
653
642
  break;
654
- }
655
643
  }
656
644
  this.addDependency(new StaticExportsDependency(true, canMangle));
657
645
  callback();
@@ -687,9 +675,43 @@ class ExternalModule extends Module {
687
675
  let { request, externalType } = this;
688
676
  if (typeof request === "object" && !Array.isArray(request))
689
677
  request = request[externalType];
678
+ externalType = this._resolveExternalType(externalType);
690
679
  return { request, externalType };
691
680
  }
692
681
 
682
+ /**
683
+ * Resolve the detailed external type from the raw external type.
684
+ * e.g. resolve "module" or "import" from "module-import" type
685
+ * @param {string} externalType raw external type
686
+ * @returns {string} resolved external type
687
+ */
688
+ _resolveExternalType(externalType) {
689
+ if (externalType === "module-import") {
690
+ if (
691
+ this.dependencyMeta &&
692
+ /** @type {ImportDependencyMeta} */
693
+ (this.dependencyMeta).externalType
694
+ ) {
695
+ return /** @type {ImportDependencyMeta} */ (this.dependencyMeta)
696
+ .externalType;
697
+ }
698
+ return "module";
699
+ } else if (externalType === "asset") {
700
+ if (
701
+ this.dependencyMeta &&
702
+ /** @type {AssetDependencyMeta} */
703
+ (this.dependencyMeta).sourceType
704
+ ) {
705
+ return /** @type {AssetDependencyMeta} */ (this.dependencyMeta)
706
+ .sourceType;
707
+ }
708
+
709
+ return "asset";
710
+ }
711
+
712
+ return externalType;
713
+ }
714
+
693
715
  /**
694
716
  * @private
695
717
  * @param {string | string[]} request request
@@ -749,52 +771,43 @@ class ExternalModule extends Module {
749
771
  runtimeTemplate
750
772
  );
751
773
  }
774
+ case "import":
775
+ return getSourceForImportExternal(
776
+ request,
777
+ runtimeTemplate,
778
+ /** @type {ImportDependencyMeta} */ (dependencyMeta)
779
+ );
752
780
  case "script":
753
781
  return getSourceForScriptExternal(request, runtimeTemplate);
754
- case "module":
755
- case "import":
756
- case "module-import": {
757
- const type = this.getModuleImportType(externalType);
758
- if (type === "import") {
759
- return getSourceForImportExternal(
760
- request,
761
- runtimeTemplate,
762
- /** @type {ImportDependencyMeta} */ (dependencyMeta)
763
- );
764
- }
765
-
766
- if (type === "module") {
767
- if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
768
- if (!runtimeTemplate.supportsDynamicImport()) {
769
- throw new Error(
770
- `The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script${
771
- runtimeTemplate.supportsEcmaScriptModuleSyntax()
772
- ? "\nDid you mean to build a EcmaScript Module ('output.module: true')?"
773
- : ""
774
- }`
775
- );
776
- }
777
- return getSourceForImportExternal(
778
- request,
779
- runtimeTemplate,
780
- /** @type {ImportDependencyMeta} */ (dependencyMeta)
781
- );
782
- }
783
- if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
782
+ case "module": {
783
+ if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
784
+ if (!runtimeTemplate.supportsDynamicImport()) {
784
785
  throw new Error(
785
- "The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
786
+ `The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script${
787
+ runtimeTemplate.supportsEcmaScriptModuleSyntax()
788
+ ? "\nDid you mean to build a EcmaScript Module ('output.module: true')?"
789
+ : ""
790
+ }`
786
791
  );
787
792
  }
788
- return getSourceForModuleExternal(
793
+ return getSourceForImportExternal(
789
794
  request,
790
- moduleGraph.getExportsInfo(this),
791
- runtime,
792
795
  runtimeTemplate,
793
796
  /** @type {ImportDependencyMeta} */ (dependencyMeta)
794
797
  );
795
798
  }
796
-
797
- break;
799
+ if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
800
+ throw new Error(
801
+ "The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
802
+ );
803
+ }
804
+ return getSourceForModuleExternal(
805
+ request,
806
+ moduleGraph.getExportsInfo(this),
807
+ runtime,
808
+ runtimeTemplate,
809
+ /** @type {ImportDependencyMeta} */ (dependencyMeta)
810
+ );
798
811
  }
799
812
  case "var":
800
813
  case "promise":
@@ -830,7 +843,13 @@ class ExternalModule extends Module {
830
843
  new RawSource(`module.exports = ${JSON.stringify(request)};`)
831
844
  );
832
845
  const data = new Map();
833
- data.set("url", request);
846
+ data.set("url", { javascript: request });
847
+ return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
848
+ }
849
+ case "css-url": {
850
+ const sources = new Map();
851
+ const data = new Map();
852
+ data.set("url", { "css-url": request });
834
853
  return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
835
854
  }
836
855
  case "css-import": {
@@ -939,7 +958,7 @@ class ExternalModule extends Module {
939
958
  updateHash(hash, context) {
940
959
  const { chunkGraph } = context;
941
960
  hash.update(
942
- `${this.externalType}${JSON.stringify(this.request)}${this.isOptional(
961
+ `${this._resolveExternalType(this.externalType)}${JSON.stringify(this.request)}${this.isOptional(
943
962
  chunkGraph.moduleGraph
944
963
  )}`
945
964
  );
@@ -9,10 +9,12 @@ const util = require("util");
9
9
  const ExternalModule = require("./ExternalModule");
10
10
  const ContextElementDependency = require("./dependencies/ContextElementDependency");
11
11
  const CssImportDependency = require("./dependencies/CssImportDependency");
12
+ const CssUrlDependency = require("./dependencies/CssUrlDependency");
12
13
  const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
13
14
  const ImportDependency = require("./dependencies/ImportDependency");
14
15
  const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
15
16
 
17
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionData} ExternalItemFunctionData */
16
18
  /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
17
19
  /** @typedef {import("./Compilation").DepConstructor} DepConstructor */
18
20
  /** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
@@ -24,6 +26,12 @@ const EMPTY_RESOLVE_OPTIONS = {};
24
26
 
25
27
  // TODO webpack 6 remove this
26
28
  const callDeprecatedExternals = util.deprecate(
29
+ /**
30
+ * @param {TODO} externalsFunction externals function
31
+ * @param {string} context context
32
+ * @param {string} request request
33
+ * @param {(err: Error | null | undefined, value: ExternalValue | undefined, ty: ExternalType | undefined) => void} cb cb
34
+ */
27
35
  (externalsFunction, context, request, cb) => {
28
36
  // eslint-disable-next-line no-useless-call
29
37
  externalsFunction.call(null, context, request, cb);
@@ -35,15 +43,16 @@ const callDeprecatedExternals = util.deprecate(
35
43
  const cache = new WeakMap();
36
44
 
37
45
  /**
38
- * @param {object} obj obj
46
+ * @template {object} T
47
+ * @param {T} obj obj
39
48
  * @param {TODO} layer layer
40
- * @returns {object} result
49
+ * @returns {Omit<T, "byLayer">} result
41
50
  */
42
51
  const resolveLayer = (obj, layer) => {
43
- let map = cache.get(obj);
52
+ let map = cache.get(/** @type {object} */ (obj));
44
53
  if (map === undefined) {
45
54
  map = new Map();
46
- cache.set(obj, map);
55
+ cache.set(/** @type {object} */ (obj), map);
47
56
  } else {
48
57
  const cacheEntry = map.get(layer);
49
58
  if (cacheEntry !== undefined) return cacheEntry;
@@ -53,8 +62,8 @@ const resolveLayer = (obj, layer) => {
53
62
  return result;
54
63
  };
55
64
 
56
- /** @typedef {string|string[]|boolean|Record<string, string|string[]>} ExternalValue */
57
- /** @typedef {string|undefined} ExternalType */
65
+ /** @typedef {string | string[] | boolean | Record<string, string | string[]>} ExternalValue */
66
+ /** @typedef {string | undefined} ExternalType */
58
67
 
59
68
  class ExternalModuleFactoryPlugin {
60
69
  /**
@@ -117,6 +126,8 @@ class ExternalModuleFactoryPlugin {
117
126
  }
118
127
  }
119
128
 
129
+ const resolvedType = /** @type {string} */ (type || globalType);
130
+
120
131
  // TODO make it pluggable/add hooks to `ExternalModule` to allow output modules own externals?
121
132
  /** @type {DependencyMeta | undefined} */
122
133
  let dependencyMeta;
@@ -145,12 +156,18 @@ class ExternalModuleFactoryPlugin {
145
156
  };
146
157
  }
147
158
 
159
+ if (
160
+ resolvedType === "asset" &&
161
+ dependency instanceof CssUrlDependency
162
+ ) {
163
+ dependencyMeta = { sourceType: "css-url" };
164
+ }
165
+
148
166
  callback(
149
167
  null,
150
168
  new ExternalModule(
151
169
  externalConfig,
152
- /** @type {string} */
153
- (type || globalType),
170
+ resolvedType,
154
171
  dependency.request,
155
172
  dependencyMeta
156
173
  )
@@ -204,6 +221,12 @@ class ExternalModuleFactoryPlugin {
204
221
  return handleExternal(dependency.request, undefined, callback);
205
222
  }
206
223
  } else if (typeof externals === "function") {
224
+ /**
225
+ * @param {Error | null | undefined} err err
226
+ * @param {ExternalValue=} value value
227
+ * @param {ExternalType=} type type
228
+ * @returns {void}
229
+ */
207
230
  const cb = (err, value, type) => {
208
231
  if (err) return callback(err);
209
232
  if (value !== undefined) {
@@ -250,7 +273,8 @@ class ExternalModuleFactoryPlugin {
250
273
  context,
251
274
  request,
252
275
  resolveContext,
253
- callback
276
+ /** @type {TODO} */
277
+ (callback)
254
278
  );
255
279
  } else {
256
280
  return new Promise((resolve, reject) => {
@@ -3631,8 +3631,7 @@ class FileSystemInfo {
3631
3631
  this._readContext(
3632
3632
  {
3633
3633
  path,
3634
- fromImmutablePath: () =>
3635
- /** @type {ContextHash} */ (/** @type {unknown} */ ("")),
3634
+ fromImmutablePath: () => /** @type {ContextHash | ""} */ (""),
3636
3635
  fromManagedItem: info => info || "",
3637
3636
  fromSymlink: (file, target, callback) => {
3638
3637
  callback(
@@ -3773,18 +3772,23 @@ class FileSystemInfo {
3773
3772
  this._readContext(
3774
3773
  {
3775
3774
  path,
3776
- fromImmutablePath: () => null,
3775
+ fromImmutablePath: () =>
3776
+ /** @type {ContextTimestampAndHash | null} */ (null),
3777
3777
  fromManagedItem: info => ({
3778
3778
  safeTime: 0,
3779
3779
  timestampHash: info,
3780
3780
  hash: info || ""
3781
3781
  }),
3782
3782
  fromSymlink: (file, target, callback) => {
3783
- callback(null, {
3784
- timestampHash: target,
3785
- hash: target,
3786
- symlinks: new Set([target])
3787
- });
3783
+ callback(
3784
+ null,
3785
+ /** @type {TODO} */
3786
+ ({
3787
+ timestampHash: target,
3788
+ hash: target,
3789
+ symlinks: new Set([target])
3790
+ })
3791
+ );
3788
3792
  },
3789
3793
  fromFile: (file, stat, callback) => {
3790
3794
  this._getFileTimestampAndHash(file, callback);
package/lib/Generator.js CHANGED
@@ -14,6 +14,7 @@
14
14
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
15
15
  /** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
16
16
  /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
17
+ /** @typedef {import("./Module").SourceTypes} SourceTypes */
17
18
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
18
19
  /** @typedef {import("./NormalModule")} NormalModule */
19
20
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
@@ -55,7 +56,7 @@ class Generator {
55
56
  /**
56
57
  * @abstract
57
58
  * @param {NormalModule} module fresh module
58
- * @returns {Set<string>} available types (do not mutate)
59
+ * @returns {SourceTypes} available types (do not mutate)
59
60
  */
60
61
  getTypes(module) {
61
62
  const AbstractMethodError = require("./AbstractMethodError");
@@ -79,7 +80,7 @@ class Generator {
79
80
  * @abstract
80
81
  * @param {NormalModule} module module for which the code should be generated
81
82
  * @param {GenerateContext} generateContext context for generate
82
- * @returns {Source} generated code
83
+ * @returns {Source | null} generated code
83
84
  */
84
85
  generate(
85
86
  module,
@@ -119,7 +120,7 @@ class ByTypeGenerator extends Generator {
119
120
 
120
121
  /**
121
122
  * @param {NormalModule} module fresh module
122
- * @returns {Set<string>} available types (do not mutate)
123
+ * @returns {SourceTypes} available types (do not mutate)
123
124
  */
124
125
  getTypes(module) {
125
126
  return this._types;
@@ -139,7 +140,7 @@ class ByTypeGenerator extends Generator {
139
140
  /**
140
141
  * @param {NormalModule} module module for which the code should be generated
141
142
  * @param {GenerateContext} generateContext context for generate
142
- * @returns {Source} generated code
143
+ * @returns {Source | null} generated code
143
144
  */
144
145
  generate(module, generateContext) {
145
146
  const type = generateContext.type;
@@ -44,6 +44,7 @@ const {
44
44
 
45
45
  /** @typedef {import("estree").CallExpression} CallExpression */
46
46
  /** @typedef {import("estree").Expression} Expression */
47
+ /** @typedef {import("estree").SpreadElement} SpreadElement */
47
48
  /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
48
49
  /** @typedef {import("./Chunk")} Chunk */
49
50
  /** @typedef {import("./Chunk").ChunkId} ChunkId */
@@ -60,8 +61,8 @@ const {
60
61
 
61
62
  /**
62
63
  * @typedef {object} HMRJavascriptParserHooks
63
- * @property {SyncBailHook<[TODO, string[]], void>} hotAcceptCallback
64
- * @property {SyncBailHook<[TODO, string[]], void>} hotAcceptWithoutCallback
64
+ * @property {SyncBailHook<[Expression | SpreadElement, string[]], void>} hotAcceptCallback
65
+ * @property {SyncBailHook<[CallExpression, string[]], void>} hotAcceptWithoutCallback
65
66
  */
66
67
 
67
68
  /** @typedef {{ updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */
@@ -133,10 +134,9 @@ class HotModuleReplacementPlugin {
133
134
  /** @type {BuildInfo} */
134
135
  (module.buildInfo).moduleConcatenationBailout =
135
136
  "Hot Module Replacement";
137
+
136
138
  if (expr.arguments.length >= 1) {
137
- const arg = parser.evaluateExpression(
138
- /** @type {Expression} */ (expr.arguments[0])
139
- );
139
+ const arg = parser.evaluateExpression(expr.arguments[0]);
140
140
  /** @type {BasicEvaluatedExpression[]} */
141
141
  let params = [];
142
142
  if (arg.isString()) {
@@ -686,7 +686,9 @@ class HotModuleReplacementPlugin {
686
686
  if (backCompat)
687
687
  ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
688
688
  hotUpdateChunk.id = chunkId;
689
- hotUpdateChunk.runtime = newRuntime;
689
+ hotUpdateChunk.runtime = currentChunk
690
+ ? currentChunk.runtime
691
+ : newRuntime;
690
692
  if (currentChunk) {
691
693
  for (const group of currentChunk.groupsIterable)
692
694
  hotUpdateChunk.addGroup(group);
@@ -5,6 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const RawModule = require("./RawModule");
9
+ const EntryDependency = require("./dependencies/EntryDependency");
8
10
  const createSchemaValidation = require("./util/create-schema-validation");
9
11
 
10
12
  /** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
@@ -73,7 +75,23 @@ class IgnorePlugin {
73
75
  */
74
76
  apply(compiler) {
75
77
  compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => {
76
- nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
78
+ nmf.hooks.beforeResolve.tap("IgnorePlugin", resolveData => {
79
+ const result = this.checkIgnore(resolveData);
80
+
81
+ if (
82
+ result === false &&
83
+ resolveData.dependencies.length > 0 &&
84
+ resolveData.dependencies[0] instanceof EntryDependency
85
+ ) {
86
+ resolveData.ignoredModule = new RawModule(
87
+ "",
88
+ "ignored-entry-module",
89
+ "(ignored-entry-module)"
90
+ );
91
+ }
92
+
93
+ return result;
94
+ });
77
95
  });
78
96
  compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => {
79
97
  cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
@@ -69,7 +69,9 @@ class LoaderOptionsPlugin {
69
69
  if (key === "include" || key === "exclude" || key === "test") {
70
70
  continue;
71
71
  }
72
- context[key] = options[key];
72
+
73
+ /** @type {any} */
74
+ (context)[key] = options[key];
73
75
  }
74
76
  }
75
77
  }