webpack 5.95.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 (145) 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/EvalDevToolModulePlugin.js +5 -2
  19. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  20. package/lib/ExternalModule.js +40 -7
  21. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  22. package/lib/FileSystemInfo.js +12 -8
  23. package/lib/Generator.js +5 -4
  24. package/lib/HotModuleReplacementPlugin.js +8 -6
  25. package/lib/IgnorePlugin.js +19 -1
  26. package/lib/LoaderOptionsPlugin.js +3 -1
  27. package/lib/Module.js +9 -8
  28. package/lib/ModuleSourceTypesConstants.js +100 -0
  29. package/lib/NormalModule.js +27 -17
  30. package/lib/NormalModuleFactory.js +38 -22
  31. package/lib/OptionsApply.js +12 -1
  32. package/lib/ProgressPlugin.js +50 -10
  33. package/lib/RawModule.js +3 -4
  34. package/lib/RuntimeModule.js +3 -4
  35. package/lib/RuntimePlugin.js +11 -4
  36. package/lib/RuntimeTemplate.js +13 -42
  37. package/lib/SourceMapDevToolPlugin.js +10 -7
  38. package/lib/Watching.js +2 -2
  39. package/lib/WebpackOptionsApply.js +42 -21
  40. package/lib/asset/AssetGenerator.js +347 -194
  41. package/lib/asset/AssetModulesPlugin.js +2 -1
  42. package/lib/asset/AssetSourceGenerator.js +82 -27
  43. package/lib/asset/RawDataUrlModule.js +5 -4
  44. package/lib/buildChunkGraph.js +2 -2
  45. package/lib/cache/PackFileCacheStrategy.js +69 -31
  46. package/lib/cache/ResolverCachePlugin.js +248 -173
  47. package/lib/config/defaults.js +134 -126
  48. package/lib/container/ContainerEntryModule.js +3 -4
  49. package/lib/container/ContainerPlugin.js +8 -0
  50. package/lib/container/FallbackModule.js +2 -2
  51. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  52. package/lib/container/ModuleFederationPlugin.js +38 -1
  53. package/lib/container/RemoteModule.js +4 -2
  54. package/lib/container/RemoteRuntimeModule.js +4 -2
  55. package/lib/css/CssExportsGenerator.js +16 -12
  56. package/lib/css/CssGenerator.js +22 -16
  57. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  58. package/lib/css/CssModulesPlugin.js +122 -77
  59. package/lib/css/CssParser.js +655 -526
  60. package/lib/css/walkCssTokens.js +1168 -338
  61. package/lib/debug/ProfilingPlugin.js +5 -0
  62. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  63. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  64. package/lib/dependencies/CssExportDependency.js +3 -3
  65. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  66. package/lib/dependencies/CssUrlDependency.js +33 -3
  67. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  68. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  69. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  71. package/lib/dependencies/ImportParserPlugin.js +9 -7
  72. package/lib/dependencies/LoaderPlugin.js +19 -0
  73. package/lib/dependencies/SystemPlugin.js +2 -1
  74. package/lib/dependencies/URLPlugin.js +7 -1
  75. package/lib/dependencies/WorkerPlugin.js +1 -1
  76. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  77. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  78. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  79. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  80. package/lib/hmr/lazyCompilationBackend.js +1 -7
  81. package/lib/index.js +35 -6
  82. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  83. package/lib/javascript/JavascriptGenerator.js +8 -8
  84. package/lib/javascript/JavascriptModulesPlugin.js +126 -73
  85. package/lib/javascript/JavascriptParser.js +338 -117
  86. package/lib/json/JsonGenerator.js +5 -5
  87. package/lib/library/EnableLibraryPlugin.js +2 -2
  88. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  89. package/lib/library/UmdLibraryPlugin.js +16 -8
  90. package/lib/logging/Logger.js +11 -11
  91. package/lib/logging/createConsoleLogger.js +14 -14
  92. package/lib/logging/truncateArgs.js +1 -1
  93. package/lib/node/NodeWatchFileSystem.js +3 -1
  94. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  95. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  96. package/lib/node/nodeConsole.js +11 -8
  97. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  98. package/lib/optimize/ConcatenatedModule.js +43 -145
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  100. package/lib/optimize/InnerGraphPlugin.js +57 -16
  101. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  102. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  103. package/lib/optimize/RealContentHashPlugin.js +1 -1
  104. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  105. package/lib/rules/RuleSetCompiler.js +2 -2
  106. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  107. package/lib/schemes/DataUriPlugin.js +1 -1
  108. package/lib/serialization/BinaryMiddleware.js +32 -19
  109. package/lib/serialization/ObjectMiddleware.js +23 -9
  110. package/lib/serialization/SerializerMiddleware.js +3 -2
  111. package/lib/serialization/types.js +2 -2
  112. package/lib/sharing/ConsumeSharedModule.js +2 -3
  113. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  114. package/lib/sharing/ProvideSharedModule.js +2 -3
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  116. package/lib/stats/StatsFactory.js +12 -12
  117. package/lib/stats/StatsPrinter.js +7 -7
  118. package/lib/util/AsyncQueue.js +17 -1
  119. package/lib/util/IterableHelpers.js +1 -1
  120. package/lib/util/SetHelpers.js +1 -1
  121. package/lib/util/cleverMerge.js +48 -24
  122. package/lib/util/concatenate.js +227 -0
  123. package/lib/util/create-schema-validation.js +22 -9
  124. package/lib/util/deprecation.js +86 -28
  125. package/lib/util/fs.js +9 -9
  126. package/lib/util/hash/wasm-hash.js +12 -1
  127. package/lib/util/magicComment.js +21 -0
  128. package/lib/util/makeSerializable.js +24 -1
  129. package/lib/util/memoize.js +2 -1
  130. package/lib/util/runtime.js +4 -1
  131. package/lib/util/semver.js +130 -23
  132. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  133. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  134. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  135. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  136. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  137. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  138. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  139. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  140. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  141. package/package.json +17 -18
  142. package/schemas/WebpackOptions.check.js +1 -1
  143. package/schemas/WebpackOptions.json +8 -2
  144. package/types.d.ts +801 -259
  145. package/lib/util/mergeScope.js +0 -76
@@ -0,0 +1,250 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Zackary Jackson @ScriptedAlchemy
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
9
+ const ExternalModule = require("../ExternalModule");
10
+ const { STAGE_ADVANCED } = require("../OptimizationStages");
11
+ const memoize = require("../util/memoize");
12
+ const { forEachRuntime } = require("../util/runtime");
13
+
14
+ /** @typedef {import("../Compilation")} Compilation */
15
+ /** @typedef {import("../Compiler")} Compiler */
16
+ /** @typedef {import("../Dependency")} Dependency */
17
+ /** @typedef {import("../Module")} Module */
18
+
19
+ const getModuleFederationPlugin = memoize(() =>
20
+ require("./ModuleFederationPlugin")
21
+ );
22
+
23
+ const PLUGIN_NAME = "HoistContainerReferences";
24
+
25
+ /**
26
+ * This class is used to hoist container references in the code.
27
+ */
28
+ class HoistContainerReferences {
29
+ /**
30
+ * Apply the plugin to the compiler.
31
+ * @param {Compiler} compiler The webpack compiler instance.
32
+ */
33
+ apply(compiler) {
34
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
35
+ const hooks =
36
+ getModuleFederationPlugin().getCompilationHooks(compilation);
37
+ const depsToTrace = new Set();
38
+ const entryExternalsToHoist = new Set();
39
+ hooks.addContainerEntryDependency.tap(PLUGIN_NAME, dep => {
40
+ depsToTrace.add(dep);
41
+ });
42
+ hooks.addFederationRuntimeDependency.tap(PLUGIN_NAME, dep => {
43
+ depsToTrace.add(dep);
44
+ });
45
+
46
+ compilation.hooks.addEntry.tap(PLUGIN_NAME, entryDep => {
47
+ if (entryDep.type === "entry") {
48
+ entryExternalsToHoist.add(entryDep);
49
+ }
50
+ });
51
+
52
+ // Hook into the optimizeChunks phase
53
+ compilation.hooks.optimizeChunks.tap(
54
+ {
55
+ name: PLUGIN_NAME,
56
+ // advanced stage is where SplitChunksPlugin runs.
57
+ stage: STAGE_ADVANCED + 1
58
+ },
59
+ chunks => {
60
+ this.hoistModulesInChunks(
61
+ compilation,
62
+ depsToTrace,
63
+ entryExternalsToHoist
64
+ );
65
+ }
66
+ );
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Hoist modules in chunks.
72
+ * @param {Compilation} compilation The webpack compilation instance.
73
+ * @param {Set<Dependency>} depsToTrace Set of container entry dependencies.
74
+ * @param {Set<Dependency>} entryExternalsToHoist Set of container entry dependencies to hoist.
75
+ */
76
+ hoistModulesInChunks(compilation, depsToTrace, entryExternalsToHoist) {
77
+ const { chunkGraph, moduleGraph } = compilation;
78
+
79
+ // loop over entry points
80
+ for (const dep of entryExternalsToHoist) {
81
+ const entryModule = moduleGraph.getModule(dep);
82
+ if (!entryModule) continue;
83
+ // get all the external module types and hoist them to the runtime chunk, this will get RemoteModule externals
84
+ const allReferencedModules = getAllReferencedModules(
85
+ compilation,
86
+ entryModule,
87
+ "external",
88
+ false
89
+ );
90
+
91
+ const containerRuntimes = chunkGraph.getModuleRuntimes(entryModule);
92
+ const runtimes = new Set();
93
+
94
+ for (const runtimeSpec of containerRuntimes) {
95
+ forEachRuntime(runtimeSpec, runtimeKey => {
96
+ if (runtimeKey) {
97
+ runtimes.add(runtimeKey);
98
+ }
99
+ });
100
+ }
101
+
102
+ for (const runtime of runtimes) {
103
+ const runtimeChunk = compilation.namedChunks.get(runtime);
104
+ if (!runtimeChunk) continue;
105
+
106
+ for (const module of allReferencedModules) {
107
+ if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {
108
+ chunkGraph.connectChunkAndModule(runtimeChunk, module);
109
+ }
110
+ }
111
+ }
112
+ this.cleanUpChunks(compilation, allReferencedModules);
113
+ }
114
+
115
+ // handle container entry specifically
116
+ for (const dep of depsToTrace) {
117
+ const containerEntryModule = moduleGraph.getModule(dep);
118
+ if (!containerEntryModule) continue;
119
+ const allReferencedModules = getAllReferencedModules(
120
+ compilation,
121
+ containerEntryModule,
122
+ "initial",
123
+ false
124
+ );
125
+
126
+ const allRemoteReferences = getAllReferencedModules(
127
+ compilation,
128
+ containerEntryModule,
129
+ "external",
130
+ false
131
+ );
132
+
133
+ for (const remote of allRemoteReferences) {
134
+ allReferencedModules.add(remote);
135
+ }
136
+
137
+ const containerRuntimes =
138
+ chunkGraph.getModuleRuntimes(containerEntryModule);
139
+ const runtimes = new Set();
140
+
141
+ for (const runtimeSpec of containerRuntimes) {
142
+ forEachRuntime(runtimeSpec, runtimeKey => {
143
+ if (runtimeKey) {
144
+ runtimes.add(runtimeKey);
145
+ }
146
+ });
147
+ }
148
+
149
+ for (const runtime of runtimes) {
150
+ const runtimeChunk = compilation.namedChunks.get(runtime);
151
+ if (!runtimeChunk) continue;
152
+
153
+ for (const module of allReferencedModules) {
154
+ if (!chunkGraph.isModuleInChunk(module, runtimeChunk)) {
155
+ chunkGraph.connectChunkAndModule(runtimeChunk, module);
156
+ }
157
+ }
158
+ }
159
+ this.cleanUpChunks(compilation, allReferencedModules);
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Clean up chunks by disconnecting unused modules.
165
+ * @param {Compilation} compilation The webpack compilation instance.
166
+ * @param {Set<Module>} modules Set of modules to clean up.
167
+ */
168
+ cleanUpChunks(compilation, modules) {
169
+ const { chunkGraph } = compilation;
170
+ for (const module of modules) {
171
+ for (const chunk of chunkGraph.getModuleChunks(module)) {
172
+ if (!chunk.hasRuntime()) {
173
+ chunkGraph.disconnectChunkAndModule(chunk, module);
174
+ if (
175
+ chunkGraph.getNumberOfChunkModules(chunk) === 0 &&
176
+ chunkGraph.getNumberOfEntryModules(chunk) === 0
177
+ ) {
178
+ chunkGraph.disconnectChunk(chunk);
179
+ compilation.chunks.delete(chunk);
180
+ if (chunk.name) {
181
+ compilation.namedChunks.delete(chunk.name);
182
+ }
183
+ }
184
+ }
185
+ }
186
+ }
187
+ modules.clear();
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Helper method to collect all referenced modules recursively.
193
+ * @param {Compilation} compilation The webpack compilation instance.
194
+ * @param {Module} module The module to start collecting from.
195
+ * @param {string} type The type of modules to collect ("initial", "external", or "all").
196
+ * @param {boolean} includeInitial Should include the referenced module passed
197
+ * @returns {Set<Module>} Set of collected modules.
198
+ */
199
+ function getAllReferencedModules(compilation, module, type, includeInitial) {
200
+ const collectedModules = new Set(includeInitial ? [module] : []);
201
+ const visitedModules = new WeakSet([module]);
202
+ const stack = [module];
203
+
204
+ while (stack.length > 0) {
205
+ const currentModule = stack.pop();
206
+ if (!currentModule) continue;
207
+
208
+ const outgoingConnections =
209
+ compilation.moduleGraph.getOutgoingConnections(currentModule);
210
+ if (outgoingConnections) {
211
+ for (const connection of outgoingConnections) {
212
+ const connectedModule = connection.module;
213
+
214
+ // Skip if module has already been visited
215
+ if (!connectedModule || visitedModules.has(connectedModule)) {
216
+ continue;
217
+ }
218
+
219
+ // Handle 'initial' type (skipping async blocks)
220
+ if (type === "initial") {
221
+ const parentBlock = compilation.moduleGraph.getParentBlock(
222
+ /** @type {Dependency} */
223
+ (connection.dependency)
224
+ );
225
+ if (parentBlock instanceof AsyncDependenciesBlock) {
226
+ continue;
227
+ }
228
+ }
229
+
230
+ // Handle 'external' type (collecting only external modules)
231
+ if (type === "external") {
232
+ if (connection.module instanceof ExternalModule) {
233
+ collectedModules.add(connectedModule);
234
+ }
235
+ } else {
236
+ // Handle 'all' or unspecified types
237
+ collectedModules.add(connectedModule);
238
+ }
239
+
240
+ // Add connected module to the stack and mark it as visited
241
+ visitedModules.add(connectedModule);
242
+ stack.push(connectedModule);
243
+ }
244
+ }
245
+ }
246
+
247
+ return collectedModules;
248
+ }
249
+
250
+ module.exports = HoistContainerReferences;
@@ -5,16 +5,26 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { SyncHook } = require("tapable");
8
9
  const isValidExternalsType = require("../../schemas/plugins/container/ExternalsType.check.js");
10
+ const Compilation = require("../Compilation");
9
11
  const SharePlugin = require("../sharing/SharePlugin");
10
12
  const createSchemaValidation = require("../util/create-schema-validation");
11
13
  const ContainerPlugin = require("./ContainerPlugin");
12
14
  const ContainerReferencePlugin = require("./ContainerReferencePlugin");
15
+ const HoistContainerReferences = require("./HoistContainerReferencesPlugin");
13
16
 
14
17
  /** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ExternalsType} ExternalsType */
15
18
  /** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").ModuleFederationPluginOptions} ModuleFederationPluginOptions */
16
19
  /** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").Shared} Shared */
17
20
  /** @typedef {import("../Compiler")} Compiler */
21
+ /** @typedef {import("../Dependency")} Dependency */
22
+
23
+ /**
24
+ * @typedef {object} CompilationHooks
25
+ * @property {SyncHook<Dependency>} addContainerEntryDependency
26
+ * @property {SyncHook<Dependency>} addFederationRuntimeDependency
27
+ */
18
28
 
19
29
  const validate = createSchemaValidation(
20
30
  require("../../schemas/plugins/container/ModuleFederationPlugin.check.js"),
@@ -24,6 +34,10 @@ const validate = createSchemaValidation(
24
34
  baseDataPath: "options"
25
35
  }
26
36
  );
37
+
38
+ /** @type {WeakMap<Compilation, CompilationHooks>} */
39
+ const compilationHooksMap = new WeakMap();
40
+
27
41
  class ModuleFederationPlugin {
28
42
  /**
29
43
  * @param {ModuleFederationPluginOptions} options options
@@ -34,6 +48,28 @@ class ModuleFederationPlugin {
34
48
  this._options = options;
35
49
  }
36
50
 
51
+ /**
52
+ * Get the compilation hooks associated with this plugin.
53
+ * @param {Compilation} compilation The compilation instance.
54
+ * @returns {CompilationHooks} The hooks for the compilation.
55
+ */
56
+ static getCompilationHooks(compilation) {
57
+ if (!(compilation instanceof Compilation)) {
58
+ throw new TypeError(
59
+ "The 'compilation' argument must be an instance of Compilation"
60
+ );
61
+ }
62
+ let hooks = compilationHooksMap.get(compilation);
63
+ if (!hooks) {
64
+ hooks = {
65
+ addContainerEntryDependency: new SyncHook(["dependency"]),
66
+ addFederationRuntimeDependency: new SyncHook(["dependency"])
67
+ };
68
+ compilationHooksMap.set(compilation, hooks);
69
+ }
70
+ return hooks;
71
+ }
72
+
37
73
  /**
38
74
  * Apply the plugin
39
75
  * @param {Compiler} compiler the compiler instance
@@ -61,7 +97,7 @@ class ModuleFederationPlugin {
61
97
  : Object.keys(options.exposes).length > 0)
62
98
  ) {
63
99
  new ContainerPlugin({
64
- name: options.name,
100
+ name: /** @type {string} */ (options.name),
65
101
  library,
66
102
  filename: options.filename,
67
103
  runtime: options.runtime,
@@ -87,6 +123,7 @@ class ModuleFederationPlugin {
87
123
  shareScope: options.shareScope
88
124
  }).apply(compiler);
89
125
  }
126
+ new HoistContainerReferences().apply(compiler);
90
127
  });
91
128
  }
92
129
  }
@@ -7,6 +7,9 @@
7
7
 
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Module = require("../Module");
10
+ const {
11
+ REMOTE_AND_SHARE_INIT_TYPES
12
+ } = require("../ModuleSourceTypesConstants");
10
13
  const { WEBPACK_MODULE_TYPE_REMOTE } = require("../ModuleTypeConstants");
11
14
  const RuntimeGlobals = require("../RuntimeGlobals");
12
15
  const makeSerializable = require("../util/makeSerializable");
@@ -30,7 +33,6 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency");
30
33
  /** @typedef {import("../util/Hash")} Hash */
31
34
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
32
35
 
33
- const TYPES = new Set(["remote", "share-init"]);
34
36
  const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
35
37
 
36
38
  class RemoteModule extends Module {
@@ -123,7 +125,7 @@ class RemoteModule extends Module {
123
125
  * @returns {SourceTypes} types available (do not mutate)
124
126
  */
125
127
  getSourceTypes() {
126
- return TYPES;
128
+ return REMOTE_AND_SHARE_INIT_TYPES;
127
129
  }
128
130
 
129
131
  /**
@@ -32,7 +32,9 @@ class RemoteRuntimeModule extends RuntimeModule {
32
32
  const chunkToRemotesMapping = {};
33
33
  /** @type {Record<ModuleId, [string, string, string | number | null]>} */
34
34
  const idToExternalAndNameMapping = {};
35
- for (const chunk of /** @type {Chunk} */ (this.chunk).getAllAsyncChunks()) {
35
+ for (const chunk of /** @type {Chunk} */ (
36
+ this.chunk
37
+ ).getAllReferencedChunks()) {
36
38
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
37
39
  chunk,
38
40
  "remote"
@@ -84,7 +86,7 @@ class RemoteRuntimeModule extends RuntimeModule {
84
86
  'if(!error) error = new Error("Container missing");',
85
87
  'if(typeof error.message === "string")',
86
88
  Template.indent(
87
- `error.message += '\\nwhile loading "' + data[1] + '" from ' + data[2];`
89
+ "error.message += '\\nwhile loading \"' + data[1] + '\" from ' + data[2];"
88
90
  ),
89
91
  `${
90
92
  RuntimeGlobals.moduleFactories
@@ -8,18 +8,21 @@
8
8
  const { ReplaceSource, RawSource, ConcatSource } = require("webpack-sources");
9
9
  const { UsageState } = require("../ExportsInfo");
10
10
  const Generator = require("../Generator");
11
+ const { JS_TYPES } = require("../ModuleSourceTypesConstants");
11
12
  const RuntimeGlobals = require("../RuntimeGlobals");
12
13
  const Template = require("../Template");
13
14
 
14
15
  /** @typedef {import("webpack-sources").Source} Source */
15
16
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
16
17
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
18
+ /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
17
19
  /** @typedef {import("../Dependency")} Dependency */
18
20
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
19
21
  /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
20
22
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
21
23
  /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
22
24
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
25
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
23
26
  /** @typedef {import("../NormalModule")} NormalModule */
24
27
  /** @typedef {import("../util/Hash")} Hash */
25
28
 
@@ -28,19 +31,15 @@ const Template = require("../Template");
28
31
  * @typedef {import("../InitFragment")<T>} InitFragment
29
32
  */
30
33
 
31
- const TYPES = new Set(["javascript"]);
32
-
33
34
  class CssExportsGenerator extends Generator {
34
35
  /**
35
- * @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
36
- * @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
36
+ * @param {CssGeneratorExportsConvention} convention the convention of the exports name
37
+ * @param {CssGeneratorLocalIdentName} localIdentName css export local ident name
37
38
  * @param {boolean} esModule whether to use ES modules syntax
38
39
  */
39
40
  constructor(convention, localIdentName, esModule) {
40
41
  super();
41
- /** @type {CssGeneratorExportsConvention | undefined} */
42
42
  this.convention = convention;
43
- /** @type {CssGeneratorLocalIdentName | undefined} */
44
43
  this.localIdentName = localIdentName;
45
44
  /** @type {boolean} */
46
45
  this.esModule = esModule;
@@ -68,11 +67,11 @@ class CssExportsGenerator extends Generator {
68
67
  /**
69
68
  * @param {NormalModule} module module for which the code should be generated
70
69
  * @param {GenerateContext} generateContext context for generate
71
- * @returns {Source} generated code
70
+ * @returns {Source | null} generated code
72
71
  */
73
72
  generate(module, generateContext) {
74
73
  const source = new ReplaceSource(new RawSource(""));
75
- /** @type {InitFragment<TODO>[]} */
74
+ /** @type {InitFragment<GenerateContext>[]} */
76
75
  const initFragments = [];
77
76
  /** @type {CssExportsData} */
78
77
  const cssExportsData = {
@@ -82,6 +81,7 @@ class CssExportsGenerator extends Generator {
82
81
 
83
82
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
84
83
 
84
+ /** @type {InitFragment<GenerateContext>[] | undefined} */
85
85
  let chunkInitFragments;
86
86
  const runtimeRequirements = new Set();
87
87
 
@@ -95,12 +95,16 @@ class CssExportsGenerator extends Generator {
95
95
  runtime: generateContext.runtime,
96
96
  runtimeRequirements,
97
97
  concatenationScope: generateContext.concatenationScope,
98
- codeGenerationResults: generateContext.codeGenerationResults,
98
+ codeGenerationResults:
99
+ /** @type {CodeGenerationResults} */
100
+ (generateContext.codeGenerationResults),
99
101
  initFragments,
100
102
  cssExportsData,
101
103
  get chunkInitFragments() {
102
104
  if (!chunkInitFragments) {
103
- const data = generateContext.getData();
105
+ const data =
106
+ /** @type {NonNullable<GenerateContext["getData"]>} */
107
+ (generateContext.getData)();
104
108
  chunkInitFragments = data.get("chunkInitFragments");
105
109
  if (!chunkInitFragments) {
106
110
  chunkInitFragments = [];
@@ -176,10 +180,10 @@ class CssExportsGenerator extends Generator {
176
180
 
177
181
  /**
178
182
  * @param {NormalModule} module fresh module
179
- * @returns {Set<string>} available types (do not mutate)
183
+ * @returns {SourceTypes} available types (do not mutate)
180
184
  */
181
185
  getTypes(module) {
182
- return TYPES;
186
+ return JS_TYPES;
183
187
  }
184
188
 
185
189
  /**
@@ -8,32 +8,31 @@
8
8
  const { ReplaceSource } = require("webpack-sources");
9
9
  const Generator = require("../Generator");
10
10
  const InitFragment = require("../InitFragment");
11
+ const { CSS_TYPES } = require("../ModuleSourceTypesConstants");
11
12
  const RuntimeGlobals = require("../RuntimeGlobals");
12
13
 
13
14
  /** @typedef {import("webpack-sources").Source} Source */
14
15
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
15
16
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
17
+ /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
16
18
  /** @typedef {import("../Dependency")} Dependency */
17
19
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
18
20
  /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
19
21
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
20
22
  /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
23
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
21
24
  /** @typedef {import("../NormalModule")} NormalModule */
22
25
  /** @typedef {import("../util/Hash")} Hash */
23
26
 
24
- const TYPES = new Set(["css"]);
25
-
26
27
  class CssGenerator extends Generator {
27
28
  /**
28
- * @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
29
- * @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
29
+ * @param {CssGeneratorExportsConvention} convention the convention of the exports name
30
+ * @param {CssGeneratorLocalIdentName} localIdentName css export local ident name
30
31
  * @param {boolean} esModule whether to use ES modules syntax
31
32
  */
32
33
  constructor(convention, localIdentName, esModule) {
33
34
  super();
34
- /** @type {CssGeneratorExportsConvention | undefined} */
35
35
  this.convention = convention;
36
- /** @type {CssGeneratorLocalIdentName | undefined} */
37
36
  this.localIdentName = localIdentName;
38
37
  /** @type {boolean} */
39
38
  this.esModule = esModule;
@@ -42,12 +41,12 @@ class CssGenerator extends Generator {
42
41
  /**
43
42
  * @param {NormalModule} module module for which the code should be generated
44
43
  * @param {GenerateContext} generateContext context for generate
45
- * @returns {Source} generated code
44
+ * @returns {Source | null} generated code
46
45
  */
47
46
  generate(module, generateContext) {
48
47
  const originalSource = /** @type {Source} */ (module.originalSource());
49
48
  const source = new ReplaceSource(originalSource);
50
- /** @type {InitFragment[]} */
49
+ /** @type {InitFragment<GenerateContext>[]} */
51
50
  const initFragments = [];
52
51
  /** @type {CssExportsData} */
53
52
  const cssExportsData = {
@@ -57,6 +56,7 @@ class CssGenerator extends Generator {
57
56
 
58
57
  generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
59
58
 
59
+ /** @type {InitFragment<GenerateContext>[] | undefined} */
60
60
  let chunkInitFragments;
61
61
  /** @type {DependencyTemplateContext} */
62
62
  const templateContext = {
@@ -68,12 +68,16 @@ class CssGenerator extends Generator {
68
68
  runtime: generateContext.runtime,
69
69
  runtimeRequirements: generateContext.runtimeRequirements,
70
70
  concatenationScope: generateContext.concatenationScope,
71
- codeGenerationResults: generateContext.codeGenerationResults,
71
+ codeGenerationResults:
72
+ /** @type {CodeGenerationResults} */
73
+ (generateContext.codeGenerationResults),
72
74
  initFragments,
73
75
  cssExportsData,
74
76
  get chunkInitFragments() {
75
77
  if (!chunkInitFragments) {
76
- const data = generateContext.getData();
78
+ const data =
79
+ /** @type {NonNullable<GenerateContext["getData"]>} */
80
+ (generateContext.getData)();
77
81
  chunkInitFragments = data.get("chunkInitFragments");
78
82
  if (!chunkInitFragments) {
79
83
  chunkInitFragments = [];
@@ -89,9 +93,9 @@ class CssGenerator extends Generator {
89
93
  * @param {Dependency} dependency dependency
90
94
  */
91
95
  const handleDependency = dependency => {
92
- const constructor = /** @type {new (...args: any[]) => Dependency} */ (
93
- dependency.constructor
94
- );
96
+ const constructor =
97
+ /** @type {new (...args: EXPECTED_ANY[]) => Dependency} */
98
+ (dependency.constructor);
95
99
  const template = generateContext.dependencyTemplates.get(constructor);
96
100
  if (!template) {
97
101
  throw new Error(
@@ -110,7 +114,9 @@ class CssGenerator extends Generator {
110
114
  }
111
115
  }
112
116
 
113
- const data = generateContext.getData();
117
+ const data =
118
+ /** @type {NonNullable<GenerateContext["getData"]>} */
119
+ (generateContext.getData)();
114
120
  data.set("css-exports", cssExportsData);
115
121
 
116
122
  return InitFragment.addToSource(source, initFragments, generateContext);
@@ -118,10 +124,10 @@ class CssGenerator extends Generator {
118
124
 
119
125
  /**
120
126
  * @param {NormalModule} module fresh module
121
- * @returns {Set<string>} available types (do not mutate)
127
+ * @returns {SourceTypes} available types (do not mutate)
122
128
  */
123
129
  getTypes(module) {
124
- return TYPES;
130
+ return CSS_TYPES;
125
131
  }
126
132
 
127
133
  /**
@@ -93,12 +93,6 @@ class CssLoadingRuntimeModule extends RuntimeModule {
93
93
  const withLoading =
94
94
  _runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
95
95
  hasCssMatcher !== false;
96
- const withPrefetch = this._runtimeRequirements.has(
97
- RuntimeGlobals.prefetchChunkHandlers
98
- );
99
- const withPreload = this._runtimeRequirements.has(
100
- RuntimeGlobals.preloadChunkHandlers
101
- );
102
96
  /** @type {boolean} */
103
97
  const withHmr = _runtimeRequirements.has(
104
98
  RuntimeGlobals.hmrDownloadUpdateHandlers
@@ -118,6 +112,13 @@ class CssLoadingRuntimeModule extends RuntimeModule {
118
112
  return null;
119
113
  }
120
114
 
115
+ const withPrefetch =
116
+ this._runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers) &&
117
+ chunk.hasChildByOrder(chunkGraph, "prefetch", true, chunkHasCss);
118
+ const withPreload =
119
+ this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers) &&
120
+ chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasCss);
121
+
121
122
  const { linkPreload, linkPrefetch } =
122
123
  CssLoadingRuntimeModule.getCompilationHooks(compilation);
123
124