webpack 5.86.0 → 5.88.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (207) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/CaseSensitiveModulesWarning.js +3 -1
  5. package/lib/ChunkGraph.js +4 -4
  6. package/lib/ChunkGroup.js +10 -3
  7. package/lib/CompatibilityPlugin.js +50 -30
  8. package/lib/Compilation.js +2 -1
  9. package/lib/Compiler.js +3 -1
  10. package/lib/ConcatenationScope.js +2 -2
  11. package/lib/ConditionalInitFragment.js +11 -1
  12. package/lib/ConstPlugin.js +57 -29
  13. package/lib/ContextModule.js +4 -1
  14. package/lib/ContextReplacementPlugin.js +13 -0
  15. package/lib/DelegatedModule.js +15 -3
  16. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  17. package/lib/Dependency.js +11 -5
  18. package/lib/DllEntryPlugin.js +11 -1
  19. package/lib/DllReferencePlugin.js +13 -1
  20. package/lib/Entrypoint.js +1 -1
  21. package/lib/ErrorHelpers.js +1 -0
  22. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  23. package/lib/ExportsInfo.js +17 -3
  24. package/lib/ExportsInfoApiPlugin.js +14 -5
  25. package/lib/ExternalModule.js +5 -0
  26. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  27. package/lib/FlagDependencyUsagePlugin.js +3 -1
  28. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  29. package/lib/HotModuleReplacementPlugin.js +8 -0
  30. package/lib/InitFragment.js +28 -5
  31. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  32. package/lib/LibManifestPlugin.js +20 -4
  33. package/lib/Module.js +7 -2
  34. package/lib/ModuleDependencyError.js +4 -2
  35. package/lib/ModuleDependencyWarning.js +4 -2
  36. package/lib/ModuleGraph.js +31 -24
  37. package/lib/ModuleGraphConnection.js +19 -6
  38. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  39. package/lib/ModuleNotFoundError.js +5 -2
  40. package/lib/ModuleProfile.js +1 -0
  41. package/lib/ModuleRestoreError.js +2 -0
  42. package/lib/ModuleStoreError.js +2 -1
  43. package/lib/ModuleTypeConstants.js +7 -0
  44. package/lib/MultiWatching.js +4 -0
  45. package/lib/NodeStuffPlugin.js +32 -6
  46. package/lib/ProvidePlugin.js +13 -4
  47. package/lib/RawModule.js +3 -1
  48. package/lib/RequireJsStuffPlugin.js +7 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimeModule.js +3 -3
  51. package/lib/RuntimePlugin.js +6 -3
  52. package/lib/RuntimeTemplate.js +22 -4
  53. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  54. package/lib/SourceMapDevToolPlugin.js +7 -2
  55. package/lib/UseStrictPlugin.js +10 -3
  56. package/lib/WebpackError.js +6 -5
  57. package/lib/WebpackIsIncludedPlugin.js +6 -4
  58. package/lib/WebpackOptionsApply.js +1 -1
  59. package/lib/WebpackOptionsDefaulter.js +10 -3
  60. package/lib/asset/AssetGenerator.js +2 -1
  61. package/lib/asset/AssetParser.js +11 -6
  62. package/lib/asset/AssetSourceParser.js +8 -3
  63. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  64. package/lib/cache/IdleFileCachePlugin.js +2 -1
  65. package/lib/cache/PackFileCacheStrategy.js +35 -14
  66. package/lib/config/browserslistTargetHandler.js +7 -7
  67. package/lib/config/defaults.js +43 -26
  68. package/lib/container/RemoteRuntimeModule.js +1 -1
  69. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  70. package/lib/css/CssModulesPlugin.js +5 -2
  71. package/lib/css/CssParser.js +22 -0
  72. package/lib/dependencies/AMDDefineDependency.js +34 -4
  73. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  74. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  75. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  76. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  77. package/lib/dependencies/CommonJsPlugin.js +13 -8
  78. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  79. package/lib/dependencies/ConstDependency.js +2 -2
  80. package/lib/dependencies/ContextDependency.js +7 -2
  81. package/lib/dependencies/CssImportDependency.js +1 -1
  82. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  83. package/lib/dependencies/CssUrlDependency.js +3 -3
  84. package/lib/dependencies/DllEntryDependency.js +5 -0
  85. package/lib/dependencies/DynamicExports.js +10 -6
  86. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  87. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  88. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  89. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  90. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExports.js +9 -5
  93. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  94. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  95. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  96. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  97. package/lib/dependencies/ImportDependency.js +5 -3
  98. package/lib/dependencies/ImportEagerDependency.js +5 -3
  99. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  100. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  101. package/lib/dependencies/ImportParserPlugin.js +62 -25
  102. package/lib/dependencies/ImportWeakDependency.js +5 -3
  103. package/lib/dependencies/ModuleDependency.js +1 -1
  104. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  105. package/lib/dependencies/ProvidedDependency.js +4 -1
  106. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  107. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  109. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  110. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  111. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  112. package/lib/dependencies/SystemPlugin.js +17 -5
  113. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  114. package/lib/dependencies/URLDependency.js +2 -2
  115. package/lib/dependencies/URLPlugin.js +9 -4
  116. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  117. package/lib/dependencies/WorkerPlugin.js +59 -22
  118. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  119. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  120. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  121. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  122. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  123. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  124. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  125. package/lib/javascript/JavascriptParser.js +135 -63
  126. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  127. package/lib/logging/runtime.js +1 -1
  128. package/lib/logging/truncateArgs.js +4 -0
  129. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  130. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  131. package/lib/optimize/InnerGraph.js +1 -1
  132. package/lib/optimize/InnerGraphPlugin.js +2 -1
  133. package/lib/performance/SizeLimitsPlugin.js +7 -4
  134. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  135. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  136. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  137. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  138. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  139. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  140. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  141. package/lib/rules/RuleSetCompiler.js +3 -3
  142. package/lib/rules/UseEffectRulePlugin.js +6 -4
  143. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  144. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  145. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  146. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  147. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  148. package/lib/runtime/CompatRuntimeModule.js +7 -2
  149. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  150. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  151. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  152. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  153. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  154. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  155. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  156. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  157. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  158. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  159. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  160. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  161. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  162. package/lib/runtime/NonceRuntimeModule.js +1 -1
  163. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  164. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  165. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  166. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  167. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  168. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  169. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  170. package/lib/serialization/ObjectMiddleware.js +6 -3
  171. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  172. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  173. package/lib/sharing/ProvideSharedDependency.js +11 -0
  174. package/lib/sharing/ProvideSharedModule.js +4 -0
  175. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  176. package/lib/sharing/ShareRuntimeModule.js +12 -5
  177. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  178. package/lib/sharing/utils.js +32 -5
  179. package/lib/util/AsyncQueue.js +4 -2
  180. package/lib/util/ParallelismFactorCalculator.js +10 -0
  181. package/lib/util/Semaphore.js +1 -1
  182. package/lib/util/createHash.js +30 -9
  183. package/lib/util/deprecation.js +10 -3
  184. package/lib/util/deterministicGrouping.js +50 -11
  185. package/lib/util/findGraphRoots.js +4 -2
  186. package/lib/util/memoize.js +3 -3
  187. package/lib/util/processAsyncTree.js +7 -1
  188. package/lib/util/registerExternalSerializer.js +1 -1
  189. package/lib/util/runtime.js +14 -1
  190. package/lib/util/smartGrouping.js +1 -1
  191. package/lib/validateSchema.js +6 -2
  192. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  193. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  194. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  195. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  196. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  197. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  198. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  199. package/lib/webpack.js +11 -2
  200. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  201. package/module.d.ts +1 -0
  202. package/package.json +5 -4
  203. package/schemas/WebpackOptions.check.js +1 -1
  204. package/schemas/WebpackOptions.json +39 -5
  205. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  206. package/schemas/plugins/css/CssParserOptions.json +1 -1
  207. package/types.d.ts +519 -222
@@ -7,9 +7,13 @@
7
7
 
8
8
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
9
9
 
10
+ /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
10
11
  /** @typedef {import("./Compilation")} Compilation */
11
12
 
12
13
  class SourceMapDevToolModuleOptionsPlugin {
14
+ /**
15
+ * @param {SourceMapDevToolPluginOptions} options options
16
+ */
13
17
  constructor(options) {
14
18
  this.options = options;
15
19
  }
@@ -22,6 +22,7 @@ const { makePathsAbsolute } = require("./util/identifier");
22
22
  /** @typedef {import("./Cache").Etag} Etag */
23
23
  /** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
24
24
  /** @typedef {import("./Chunk")} Chunk */
25
+ /** @typedef {import("./Compilation").Asset} Asset */
25
26
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
26
27
  /** @typedef {import("./Compilation").PathData} PathData */
27
28
  /** @typedef {import("./Compiler")} Compiler */
@@ -227,7 +228,9 @@ class SourceMapDevToolPlugin {
227
228
  asyncLib.each(
228
229
  files,
229
230
  (file, callback) => {
230
- const asset = compilation.getAsset(file);
231
+ const asset =
232
+ /** @type {Readonly<Asset>} */
233
+ (compilation.getAsset(file));
231
234
  if (asset.info.related && asset.info.related.sourceMap) {
232
235
  fileIndex++;
233
236
  return callback();
@@ -363,7 +366,9 @@ class SourceMapDevToolPlugin {
363
366
  // find modules with conflicting source names
364
367
  for (let idx = 0; idx < allModules.length; idx++) {
365
368
  const module = allModules[idx];
366
- let sourceName = moduleToSourceNameMapping.get(module);
369
+ let sourceName =
370
+ /** @type {string} */
371
+ (moduleToSourceNameMapping.get(module));
367
372
  let hasName = conflictDetectionSet.has(sourceName);
368
373
  if (!hasName) {
369
374
  conflictDetectionSet.add(sourceName);
@@ -13,7 +13,10 @@ const {
13
13
  const ConstDependency = require("./dependencies/ConstDependency");
14
14
 
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
17
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
16
18
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
17
20
 
18
21
  const PLUGIN_NAME = "UseStrictPlugin";
19
22
 
@@ -42,10 +45,14 @@ class UseStrictPlugin {
42
45
  // Remove "use strict" expression. It will be added later by the renderer again.
43
46
  // This is necessary in order to not break the strict mode when webpack prepends code.
44
47
  // @see https://github.com/webpack/webpack/issues/1970
45
- const dep = new ConstDependency("", firstNode.range);
46
- dep.loc = firstNode.loc;
48
+ const dep = new ConstDependency(
49
+ "",
50
+ /** @type {Range} */ (firstNode.range)
51
+ );
52
+ dep.loc = /** @type {DependencyLocation} */ (firstNode.loc);
47
53
  parser.state.module.addPresentationalDependency(dep);
48
- parser.state.module.buildInfo.strict = true;
54
+ /** @type {BuildInfo} */
55
+ (parser.state.module.buildInfo).strict = true;
49
56
  }
50
57
  });
51
58
  };
@@ -22,16 +22,17 @@ class WebpackError extends Error {
22
22
  constructor(message) {
23
23
  super(message);
24
24
 
25
+ /** @type {string | undefined} */
25
26
  this.details = undefined;
26
- /** @type {Module} */
27
+ /** @type {Module | undefined | null} */
27
28
  this.module = undefined;
28
- /** @type {DependencyLocation} */
29
+ /** @type {DependencyLocation | undefined} */
29
30
  this.loc = undefined;
30
- /** @type {boolean} */
31
+ /** @type {boolean | undefined} */
31
32
  this.hideStack = undefined;
32
- /** @type {Chunk} */
33
+ /** @type {Chunk | undefined} */
33
34
  this.chunk = undefined;
34
- /** @type {string} */
35
+ /** @type {string | undefined} */
35
36
  this.file = undefined;
36
37
  }
37
38
 
@@ -16,10 +16,12 @@ const {
16
16
  toConstantDependency
17
17
  } = require("./javascript/JavascriptParserHelpers");
18
18
 
19
- /** @typedef {import("enhanced-resolve/lib/Resolver")} Resolver */
19
+ /** @typedef {import("enhanced-resolve").Resolver} Resolver */
20
20
  /** @typedef {import("./Compiler")} Compiler */
21
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
21
22
  /** @typedef {import("./Module")} Module */
22
23
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
24
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
23
25
 
24
26
  const PLUGIN_NAME = "WebpackIsIncludedPlugin";
25
27
 
@@ -61,10 +63,10 @@ class WebpackIsIncludedPlugin {
61
63
  if (!request.isString()) return;
62
64
 
63
65
  const dep = new WebpackIsIncludedDependency(
64
- request.string,
65
- expr.range
66
+ /** @type {string} */ (request.string),
67
+ /** @type {Range} */ (expr.range)
66
68
  );
67
- dep.loc = expr.loc;
69
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
68
70
  parser.state.module.addDependency(dep);
69
71
  return true;
70
72
  });
@@ -566,7 +566,7 @@ class WebpackOptionsApply extends OptionsApply {
566
566
  for (const minimizer of options.optimization.minimizer) {
567
567
  if (typeof minimizer === "function") {
568
568
  minimizer.call(compiler, compiler);
569
- } else if (minimizer !== "...") {
569
+ } else if (minimizer !== "..." && minimizer) {
570
570
  minimizer.apply(compiler);
571
571
  }
572
572
  }
@@ -8,11 +8,18 @@
8
8
  const { applyWebpackOptionsDefaults } = require("./config/defaults");
9
9
  const { getNormalizedWebpackOptions } = require("./config/normalization");
10
10
 
11
+ /** @typedef {import("./config/normalization").WebpackOptions} WebpackOptions */
12
+ /** @typedef {import("./config/normalization").WebpackOptionsNormalized} WebpackOptionsNormalized */
13
+
11
14
  class WebpackOptionsDefaulter {
15
+ /**
16
+ * @param {WebpackOptions} options webpack options
17
+ * @returns {WebpackOptionsNormalized} normalized webpack options
18
+ */
12
19
  process(options) {
13
- options = getNormalizedWebpackOptions(options);
14
- applyWebpackOptionsDefaults(options);
15
- return options;
20
+ const normalizedOptions = getNormalizedWebpackOptions(options);
21
+ applyWebpackOptionsDefaults(normalizedOptions);
22
+ return normalizedOptions;
16
23
  }
17
24
  }
18
25
 
@@ -181,6 +181,7 @@ class AssetGenerator extends Generator {
181
181
  );
182
182
  }
183
183
 
184
+ /** @type {string | boolean | undefined} */
184
185
  let mimeType = this.dataUrlOptions.mimetype;
185
186
  if (mimeType === undefined) {
186
187
  const ext = path.extname(module.nameForCondition());
@@ -213,7 +214,7 @@ class AssetGenerator extends Generator {
213
214
  );
214
215
  }
215
216
 
216
- return mimeType;
217
+ return /** @type {string} */ (mimeType);
217
218
  }
218
219
 
219
220
  /**
@@ -9,6 +9,8 @@ const Parser = require("../Parser");
9
9
 
10
10
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserDataUrlOptions} AssetParserDataUrlOptions */
11
11
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
12
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
13
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
12
14
  /** @typedef {import("../Parser").ParserState} ParserState */
13
15
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
14
16
 
@@ -30,22 +32,25 @@ class AssetParser extends Parser {
30
32
  if (typeof source === "object" && !Buffer.isBuffer(source)) {
31
33
  throw new Error("AssetParser doesn't accept preparsed AST");
32
34
  }
33
- state.module.buildInfo.strict = true;
34
- state.module.buildMeta.exportsType = "default";
35
- state.module.buildMeta.defaultObject = false;
35
+
36
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
37
+ buildInfo.strict = true;
38
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
39
+ buildMeta.exportsType = "default";
40
+ buildMeta.defaultObject = false;
36
41
 
37
42
  if (typeof this.dataUrlCondition === "function") {
38
- state.module.buildInfo.dataUrl = this.dataUrlCondition(source, {
43
+ buildInfo.dataUrl = this.dataUrlCondition(source, {
39
44
  filename: state.module.matchResource || state.module.resource,
40
45
  module: state.module
41
46
  });
42
47
  } else if (typeof this.dataUrlCondition === "boolean") {
43
- state.module.buildInfo.dataUrl = this.dataUrlCondition;
48
+ buildInfo.dataUrl = this.dataUrlCondition;
44
49
  } else if (
45
50
  this.dataUrlCondition &&
46
51
  typeof this.dataUrlCondition === "object"
47
52
  ) {
48
- state.module.buildInfo.dataUrl =
53
+ buildInfo.dataUrl =
49
54
  Buffer.byteLength(source) <=
50
55
  /** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */
51
56
  (this.dataUrlCondition.maxSize);
@@ -7,6 +7,8 @@
7
7
 
8
8
  const Parser = require("../Parser");
9
9
 
10
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
11
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
10
12
  /** @typedef {import("../Parser").ParserState} ParserState */
11
13
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
12
14
 
@@ -21,9 +23,12 @@ class AssetSourceParser extends Parser {
21
23
  throw new Error("AssetSourceParser doesn't accept preparsed AST");
22
24
  }
23
25
  const { module } = state;
24
- module.buildInfo.strict = true;
25
- module.buildMeta.exportsType = "default";
26
- state.module.buildMeta.defaultObject = false;
26
+ /** @type {BuildInfo} */
27
+ (module.buildInfo).strict = true;
28
+ /** @type {BuildMeta} */
29
+ (module.buildMeta).exportsType = "default";
30
+ /** @type {BuildMeta} */
31
+ (state.module.buildMeta).defaultObject = false;
27
32
 
28
33
  return state;
29
34
  }
@@ -29,6 +29,10 @@ class AwaitDependenciesInitFragment extends InitFragment {
29
29
  this.promises = promises;
30
30
  }
31
31
 
32
+ /**
33
+ * @param {AwaitDependenciesInitFragment} other other AwaitDependenciesInitFragment
34
+ * @returns {AwaitDependenciesInitFragment} AwaitDependenciesInitFragment
35
+ */
32
36
  merge(other) {
33
37
  const promises = new Set(other.promises);
34
38
  for (const p of this.promises) {
@@ -50,7 +50,7 @@ class IdleFileCachePlugin {
50
50
  let timeSpendInStore = 0;
51
51
  let avgTimeSpendInStore = 0;
52
52
 
53
- /** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise>} */
53
+ /** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise<void>>} */
54
54
  const pendingIdleTasks = new Map();
55
55
 
56
56
  compiler.cache.hooks.store.tap(
@@ -171,6 +171,7 @@ class IdleFileCachePlugin {
171
171
  isInitialStore = false;
172
172
  }
173
173
  };
174
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
174
175
  let idleTimer = undefined;
175
176
  compiler.cache.hooks.beginIdle.tap(
176
177
  { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
@@ -22,6 +22,8 @@ const {
22
22
  /** @typedef {import("../Compiler")} Compiler */
23
23
  /** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
24
24
  /** @typedef {import("../logging/Logger").Logger} Logger */
25
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
26
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
25
27
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
26
28
 
27
29
  class PackContainer {
@@ -58,6 +60,9 @@ class PackContainer {
58
60
  writeLazy(this.data);
59
61
  }
60
62
 
63
+ /**
64
+ * @param {ObjectDeserializerContext} context context
65
+ */
61
66
  deserialize({ read }) {
62
67
  this.version = read();
63
68
  this.buildSnapshot = read();
@@ -99,7 +104,7 @@ class Pack {
99
104
  constructor(logger, maxAge) {
100
105
  /** @type {Map<string, PackItemInfo>} */
101
106
  this.itemInfo = new Map();
102
- /** @type {string[]} */
107
+ /** @type {(string | undefined)[]} */
103
108
  this.requests = [];
104
109
  this.requestsTimeout = undefined;
105
110
  /** @type {Map<string, PackItemInfo>} */
@@ -111,6 +116,9 @@ class Pack {
111
116
  this.maxAge = maxAge;
112
117
  }
113
118
 
119
+ /**
120
+ * @param {string} identifier identifier
121
+ */
114
122
  _addRequest(identifier) {
115
123
  this.requests.push(identifier);
116
124
  if (this.requestsTimeout === undefined) {
@@ -149,7 +157,7 @@ class Pack {
149
157
  if (!this.content[loc]) {
150
158
  return undefined;
151
159
  }
152
- return this.content[loc].get(identifier);
160
+ return /** @type {PackContent} */ (this.content[loc]).get(identifier);
153
161
  }
154
162
  }
155
163
 
@@ -175,7 +183,7 @@ class Pack {
175
183
  if (loc >= 0) {
176
184
  this._addRequest(identifier);
177
185
  this.freshContent.set(identifier, info);
178
- const content = this.content[loc];
186
+ const content = /** @type {PackContent} */ (this.content[loc]);
179
187
  content.delete(identifier);
180
188
  if (content.items.size === 0) {
181
189
  this.content[loc] = undefined;
@@ -351,11 +359,12 @@ class Pack {
351
359
  mergedIndices = smallUnusedContents;
352
360
  } else return;
353
361
 
362
+ /** @type {PackContent[] } */
354
363
  const mergedContent = [];
355
364
 
356
365
  // 3. Remove old content entries
357
366
  for (const i of mergedIndices) {
358
- mergedContent.push(this.content[i]);
367
+ mergedContent.push(/** @type {PackContent} */ (this.content[i]));
359
368
  this.content[i] = undefined;
360
369
  }
361
370
 
@@ -364,7 +373,7 @@ class Pack {
364
373
  const mergedItems = new Set();
365
374
  /** @type {Set<string>} */
366
375
  const mergedUsedItems = new Set();
367
- /** @type {(function(Map<string, any>): Promise)[]} */
376
+ /** @type {(function(Map<string, any>): Promise<void>)[]} */
368
377
  const addToMergedMap = [];
369
378
  for (const content of mergedContent) {
370
379
  for (const identifier of content.items) {
@@ -498,17 +507,20 @@ class Pack {
498
507
  * Only runs for one content to avoid large invalidation.
499
508
  */
500
509
  _gcOldestContent() {
501
- /** @type {PackItemInfo} */
510
+ /** @type {PackItemInfo | undefined} */
502
511
  let oldest = undefined;
503
512
  for (const info of this.itemInfo.values()) {
504
513
  if (oldest === undefined || info.lastAccess < oldest.lastAccess) {
505
514
  oldest = info;
506
515
  }
507
516
  }
508
- if (Date.now() - oldest.lastAccess > this.maxAge) {
509
- const loc = oldest.location;
517
+ if (
518
+ Date.now() - /** @type {PackItemInfo} */ (oldest).lastAccess >
519
+ this.maxAge
520
+ ) {
521
+ const loc = /** @type {PackItemInfo} */ (oldest).location;
510
522
  if (loc < 0) return;
511
- const content = this.content[loc];
523
+ const content = /** @type {PackContent} */ (this.content[loc]);
512
524
  const items = new Set(content.items);
513
525
  const usedItems = new Set(content.used);
514
526
  this._gcAndUpdateLocation(items, usedItems, loc);
@@ -771,6 +783,7 @@ class PackContent {
771
783
 
772
784
  // We are in state B
773
785
  const { lazyName } = this;
786
+ /** @type {string | undefined} */
774
787
  let timeMessage;
775
788
  if (lazyName) {
776
789
  // only log once
@@ -811,7 +824,7 @@ class PackContent {
811
824
 
812
825
  /**
813
826
  * @param {string} reason explanation why unpack is necessary
814
- * @returns {void | Promise} maybe a promise if lazy
827
+ * @returns {void | Promise<void>} maybe a promise if lazy
815
828
  */
816
829
  unpack(reason) {
817
830
  if (this.content) return;
@@ -819,6 +832,7 @@ class PackContent {
819
832
  // Move from state B to C
820
833
  if (this.lazy) {
821
834
  const { lazyName } = this;
835
+ /** @type {string | undefined} */
822
836
  let timeMessage;
823
837
  if (lazyName) {
824
838
  // only log once
@@ -862,6 +876,9 @@ class PackContent {
862
876
  return size;
863
877
  }
864
878
 
879
+ /**
880
+ * @param {string} identifier identifier
881
+ */
865
882
  delete(identifier) {
866
883
  this.items.delete(identifier);
867
884
  this.used.delete(identifier);
@@ -906,6 +923,7 @@ class PackContent {
906
923
  }
907
924
  // State B2
908
925
  const { lazyName } = this;
926
+ /** @type {string | undefined} */
909
927
  let timeMessage;
910
928
  if (lazyName) {
911
929
  // only log once
@@ -1028,17 +1046,20 @@ class PackFileCacheStrategy {
1028
1046
  this.buildDependencies = new Set();
1029
1047
  /** @type {LazySet<string>} */
1030
1048
  this.newBuildDependencies = new LazySet();
1031
- /** @type {Snapshot} */
1049
+ /** @type {Snapshot | undefined} */
1032
1050
  this.resolveBuildDependenciesSnapshot = undefined;
1033
- /** @type {Map<string, string | false>} */
1051
+ /** @type {Map<string, string | false> | undefined} */
1034
1052
  this.resolveResults = undefined;
1035
- /** @type {Snapshot} */
1053
+ /** @type {Snapshot | undefined} */
1036
1054
  this.buildSnapshot = undefined;
1037
- /** @type {Promise<Pack>} */
1055
+ /** @type {Promise<Pack> | undefined} */
1038
1056
  this.packPromise = this._openPack();
1039
1057
  this.storePromise = Promise.resolve();
1040
1058
  }
1041
1059
 
1060
+ /**
1061
+ * @returns {Promise<Pack>} pack
1062
+ */
1042
1063
  _getPack() {
1043
1064
  if (this.packPromise === undefined) {
1044
1065
  this.packPromise = this.storePromise.then(() => this._openPack());
@@ -120,7 +120,7 @@ const resolve = browsers => {
120
120
  and_qq: [10, 4],
121
121
  // baidu: Not supported
122
122
  // and_uc: Not supported
123
- // kaios: Not supported
123
+ kaios: [3, 0],
124
124
  node: [12, 17]
125
125
  });
126
126
 
@@ -187,7 +187,7 @@ const resolve = browsers => {
187
187
  // and_qq: Unknown support
188
188
  // baidu: Unknown support
189
189
  // and_uc: Unknown support
190
- // kaios: Unknown support
190
+ kaios: [3, 0],
191
191
  node: [0, 12]
192
192
  }),
193
193
  destructuring: rawChecker({
@@ -206,7 +206,7 @@ const resolve = browsers => {
206
206
  // and_qq: Unknown support
207
207
  // baidu: Unknown support
208
208
  // and_uc: Unknown support
209
- // kaios: Unknown support
209
+ kaios: [2, 5],
210
210
  node: [6, 0]
211
211
  }),
212
212
  bigIntLiteral: rawChecker({
@@ -225,7 +225,7 @@ const resolve = browsers => {
225
225
  // and_qq: Not supported
226
226
  // baidu: Not supported
227
227
  // and_uc: Not supported
228
- // kaios: Not supported
228
+ kaios: [3, 0],
229
229
  node: [10, 4]
230
230
  }),
231
231
  // Support syntax `import` and `export` and no limitations and bugs on Node.js
@@ -246,7 +246,7 @@ const resolve = browsers => {
246
246
  and_qq: [10, 4],
247
247
  // baidu: Not supported
248
248
  // and_uc: Not supported
249
- // kaios: Not supported
249
+ kaios: [3, 0],
250
250
  node: [12, 17]
251
251
  }),
252
252
  dynamicImport: es6DynamicImport,
@@ -269,7 +269,7 @@ const resolve = browsers => {
269
269
  // and_qq: Unknown support
270
270
  // baidu: Unknown support
271
271
  // and_uc: Unknown support
272
- // kaios: Unknown support
272
+ kaios: [3, 0],
273
273
  node: 12
274
274
  }),
275
275
  optionalChaining: rawChecker({
@@ -288,7 +288,7 @@ const resolve = browsers => {
288
288
  // and_qq: Not supported
289
289
  // baidu: Not supported
290
290
  // and_uc: Not supported
291
- // kaios: Not supported
291
+ kaios: [3, 0],
292
292
  node: 14
293
293
  }),
294
294
  templateLiteral: rawChecker({
@@ -15,7 +15,9 @@ const {
15
15
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
16
16
  WEBASSEMBLY_MODULE_TYPE_SYNC,
17
17
  ASSET_MODULE_TYPE,
18
- CSS_MODULE_TYPE
18
+ CSS_MODULE_TYPE_AUTO,
19
+ CSS_MODULE_TYPE,
20
+ CSS_MODULE_TYPE_MODULE
19
21
  } = require("../ModuleTypeConstants");
20
22
  const Template = require("../Template");
21
23
  const { cleverMerge } = require("../util/cleverMerge");
@@ -298,7 +300,10 @@ const applyWebpackOptionsDefaults = options => {
298
300
  cache,
299
301
  context: /** @type {Context} */ (options.context),
300
302
  targetProperties,
301
- mode: /** @type {Mode} */ (options.mode)
303
+ mode: /** @type {Mode} */ (options.mode),
304
+ css:
305
+ /** @type {NonNullable<ExperimentsNormalized["css"]>} */
306
+ (options.experiments.css)
302
307
  }),
303
308
  options.resolve
304
309
  );
@@ -533,6 +538,7 @@ const applyJavascriptParserOptionsDefaults = (
533
538
  D(parserOptions, "dynamicImportMode", "lazy");
534
539
  D(parserOptions, "dynamicImportPrefetch", false);
535
540
  D(parserOptions, "dynamicImportPreload", false);
541
+ D(parserOptions, "dynamicImportFetchPriority", false);
536
542
  D(parserOptions, "createRequire", isNode);
537
543
  if (futureDefaults) D(parserOptions, "exportsPresence", "error");
538
544
  };
@@ -704,38 +710,24 @@ const applyModuleDefaults = (
704
710
  });
705
711
  }
706
712
  if (css) {
707
- const cssRule = {
708
- type: CSS_MODULE_TYPE,
709
- resolve: {
710
- fullySpecified: true,
711
- preferRelative: true
712
- }
713
- };
714
- const cssModulesRule = {
715
- type: "css/module",
716
- resolve: {
717
- fullySpecified: true
718
- }
713
+ const resolve = {
714
+ fullySpecified: true,
715
+ preferRelative: true
719
716
  };
720
717
  rules.push({
721
718
  test: /\.css$/i,
722
- oneOf: [
723
- {
724
- test: /\.module\.css$/i,
725
- ...cssModulesRule
726
- },
727
- {
728
- ...cssRule
729
- }
730
- ]
719
+ type: CSS_MODULE_TYPE_AUTO,
720
+ resolve
731
721
  });
732
722
  rules.push({
733
723
  mimetype: "text/css+module",
734
- ...cssModulesRule
724
+ type: CSS_MODULE_TYPE_MODULE,
725
+ resolve
735
726
  });
736
727
  rules.push({
737
728
  mimetype: "text/css",
738
- ...cssRule
729
+ type: CSS_MODULE_TYPE,
730
+ resolve
739
731
  });
740
732
  }
741
733
  rules.push(
@@ -1398,9 +1390,16 @@ const applyOptimizationDefaults = (
1398
1390
  * @param {string} options.context build context
1399
1391
  * @param {TargetProperties | false} options.targetProperties target properties
1400
1392
  * @param {Mode} options.mode mode
1393
+ * @param {CssExperimentOptions|false} options.css is css enabled
1401
1394
  * @returns {ResolveOptions} resolve options
1402
1395
  */
1403
- const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
1396
+ const getResolveDefaults = ({
1397
+ cache,
1398
+ context,
1399
+ targetProperties,
1400
+ mode,
1401
+ css
1402
+ }) => {
1404
1403
  /** @type {string[]} */
1405
1404
  const conditions = ["webpack"];
1406
1405
 
@@ -1468,6 +1467,24 @@ const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
1468
1467
  }
1469
1468
  };
1470
1469
 
1470
+ if (css) {
1471
+ const styleConditions = [];
1472
+
1473
+ styleConditions.push("webpack");
1474
+ styleConditions.push(mode === "development" ? "development" : "production");
1475
+ styleConditions.push("style");
1476
+
1477
+ resolveOptions.byDependency["css-import"] = {
1478
+ // We avoid using any main files because we have to be consistent with CSS `@import`
1479
+ // and CSS `@import` does not handle `main` files in directories,
1480
+ // you should always specify the full URL for styles
1481
+ mainFiles: [],
1482
+ mainFields: ["style", "..."],
1483
+ conditionNames: styleConditions,
1484
+ extensions: [".css"]
1485
+ };
1486
+ }
1487
+
1471
1488
  return resolveOptions;
1472
1489
  };
1473
1490
 
@@ -18,7 +18,7 @@ class RemoteRuntimeModule extends RuntimeModule {
18
18
  }
19
19
 
20
20
  /**
21
- * @returns {string} runtime code
21
+ * @returns {string | null} runtime code
22
22
  */
23
23
  generate() {
24
24
  const { compilation, chunkGraph } = this;