webpack 5.112.0 → 5.112.2

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 (263) hide show
  1. package/bin/webpack.js +13 -7
  2. package/lib/Compilation.js +198 -61
  3. package/lib/Compiler.js +12 -25
  4. package/lib/asset/AssetBytesGenerator.js +14 -6
  5. package/lib/asset/AssetBytesParser.js +10 -8
  6. package/lib/asset/AssetGenerator.js +36 -48
  7. package/lib/asset/AssetModule.js +11 -0
  8. package/lib/asset/AssetModulesPlugin.js +5 -4
  9. package/lib/asset/AssetParser.js +8 -8
  10. package/lib/asset/AssetSourceGenerator.js +16 -8
  11. package/lib/asset/AssetSourceParser.js +10 -8
  12. package/lib/asset/WebManifestGenerator.js +11 -6
  13. package/lib/asset/WebManifestParser.js +3 -3
  14. package/lib/async-modules/AsyncModuleHelpers.js +8 -2
  15. package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
  16. package/lib/cache/CacheFacade.js +1 -1
  17. package/lib/cache/PackFileCacheStrategy.js +6 -10
  18. package/lib/cache/ResolverCachePlugin.js +58 -8
  19. package/lib/config/WebpackOptionsApply.js +8 -28
  20. package/lib/config/cli.js +9 -6
  21. package/lib/config/defaults.js +24 -13
  22. package/lib/config/getClaimedAssetTypes.js +2 -2
  23. package/lib/config/target.js +1 -1
  24. package/lib/context/ContextModule.js +1 -1
  25. package/lib/context/ContextModuleFactory.js +1 -1
  26. package/lib/context/ContextReplacementPlugin.js +3 -9
  27. package/lib/css/CssGenerator.js +40 -47
  28. package/lib/css/CssModule.js +10 -0
  29. package/lib/css/CssModulesPlugin.js +13 -6
  30. package/lib/css/CssParser.js +33 -32
  31. package/lib/css/conventions.js +1 -1
  32. package/lib/css/data.js +224 -219
  33. package/lib/css/syntax-parser.js +1312 -312
  34. package/lib/css/syntax-printer.js +1142 -1025
  35. package/lib/debug/ProfilingPlugin.js +65 -43
  36. package/lib/define/DefinePlugin.js +10 -15
  37. package/lib/define/DotenvPlugin.js +10 -6
  38. package/lib/define/EnvironmentPlugin.js +4 -2
  39. package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
  40. package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  41. package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
  42. package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
  43. package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
  44. package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
  45. package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
  46. package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
  47. package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
  48. package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
  49. package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
  50. package/lib/dependencies/core/CachedConstDependency.js +9 -6
  51. package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
  52. package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
  53. package/lib/dependencies/css/CssUrlDependency.js +2 -6
  54. package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
  55. package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
  56. package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
  57. package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
  58. package/lib/dependencies/esm/ESMExports.js +2 -10
  59. package/lib/dependencies/esm/ESMImportDependency.js +17 -2
  60. package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
  61. package/lib/dependencies/esm/ESMImportGuard.js +11 -23
  62. package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
  63. package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
  64. package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
  65. package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
  66. package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
  67. package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
  68. package/lib/dependencies/helpers/DynamicExports.js +4 -6
  69. package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
  70. package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
  71. package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
  72. package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
  73. package/lib/dependencies/import/ImportParserPlugin.js +3 -6
  74. package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
  75. package/lib/dependencies/url/URLParserPlugin.js +1 -1
  76. package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
  77. package/lib/devtool/ModuleFilenameHelpers.js +1 -1
  78. package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
  79. package/lib/dll/DelegatedModule.js +3 -3
  80. package/lib/dll/DllModule.js +3 -1
  81. package/lib/dll/DllReferencePlugin.js +1 -4
  82. package/lib/errors/AbstractMethodError.js +1 -1
  83. package/lib/errors/ErrorHelpers.js +2 -1
  84. package/lib/errors/HookWebpackError.js +2 -1
  85. package/lib/errors/JSONParseError.js +4 -4
  86. package/lib/errors/WebpackError.js +3 -2
  87. package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
  88. package/lib/externals/ExternalModule.js +12 -9
  89. package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
  90. package/lib/externals/ExternalsPlugin.js +1 -1
  91. package/lib/fs/FileSystemInfo.js +4 -4
  92. package/lib/graph/AsyncDependenciesBlock.js +1 -1
  93. package/lib/graph/ChunkGraph.js +5 -0
  94. package/lib/graph/Dependency.js +8 -2
  95. package/lib/graph/ExportsInfo.js +1 -1
  96. package/lib/graph/ModuleGraph.js +14 -3
  97. package/lib/graph/buildChunkGraph.js +17 -19
  98. package/lib/graph/findGraphRoots.js +1 -1
  99. package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
  100. package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
  101. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
  102. package/lib/hmr/LazyCompilationPlugin.js +1 -7
  103. package/lib/html/HtmlGenerator.js +25 -17
  104. package/lib/html/HtmlModule.js +11 -1
  105. package/lib/html/HtmlModulesPlugin.js +12 -11
  106. package/lib/html/HtmlParser.js +10 -9
  107. package/lib/html/builtinEmbeddedRenderer.js +31 -33
  108. package/lib/html/data.js +42 -21
  109. package/lib/html/htmlMinify.js +4 -1
  110. package/lib/html/syntax-parser.js +34 -35
  111. package/lib/html/syntax-printer.js +2 -3
  112. package/lib/html/xmlMinify.js +4 -1
  113. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  114. package/lib/index.js +13 -12
  115. package/lib/javascript/APIPlugin.js +7 -13
  116. package/lib/javascript/BasicEvaluatedExpression.js +5 -5
  117. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
  118. package/lib/javascript/ConstPlugin.js +1 -1
  119. package/lib/javascript/JavascriptGenerator.js +16 -11
  120. package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
  121. package/lib/javascript/JavascriptModule.js +10 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +2 -4
  123. package/lib/javascript/JavascriptParser.js +99 -11
  124. package/lib/javascript/ScopeAnalyzer.js +183 -107
  125. package/lib/javascript/UseStrictPlugin.js +2 -5
  126. package/lib/javascript/jsMinify.js +1 -1
  127. package/lib/javascript/regexp.js +2 -2
  128. package/lib/javascript/syntax-parser.js +2114 -1506
  129. package/lib/javascript/syntax-printer-data.js +167 -1
  130. package/lib/javascript/syntax-printer.js +9554 -2782
  131. package/lib/json/JsonGenerator.js +15 -7
  132. package/lib/json/JsonModule.js +11 -0
  133. package/lib/json/JsonParser.js +7 -6
  134. package/lib/library/AssignLibraryPlugin.js +1 -1
  135. package/lib/library/JsonpLibraryPlugin.js +1 -1
  136. package/lib/library/ModuleLibraryPlugin.js +399 -23
  137. package/lib/loaders/LoaderRunner.js +76 -38
  138. package/lib/loaders/loadLoader.js +16 -10
  139. package/lib/module/Generator.js +17 -9
  140. package/lib/module/Module.js +2 -2
  141. package/lib/module/NormalModule.js +7 -5
  142. package/lib/module/NormalModuleFactory.js +11 -17
  143. package/lib/module/Parser.js +9 -2
  144. package/lib/module/extractSourceMap.js +69 -18
  145. package/lib/module/findCaseMismatch.js +2 -2
  146. package/lib/node/ExternalModuleInitFragment.js +2 -2
  147. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
  148. package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
  149. package/lib/node/nodeConsole.js +4 -3
  150. package/lib/optimize/CircularModulesPlugin.js +1 -1
  151. package/lib/optimize/ConcatenatedModule.js +4 -8
  152. package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
  153. package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
  154. package/lib/optimize/InlineExports.js +4 -7
  155. package/lib/optimize/LazyBarrels.js +41 -5
  156. package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
  157. package/lib/optimize/RealContentHashPlugin.js +2 -6
  158. package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
  159. package/lib/optimize/SplitChunksPlugin.js +11 -24
  160. package/lib/optimize/TupleQueue.js +1 -1
  161. package/lib/output/CleanPlugin.js +3 -1
  162. package/lib/output/CopyPlugin.js +3 -4
  163. package/lib/performance/EvalUsagePlugin.js +1 -3
  164. package/lib/performance/HotspotsPlugin.js +33 -9
  165. package/lib/performance/PureAnnotationsPlugin.js +16 -10
  166. package/lib/performance/TopLevelThisPlugin.js +17 -9
  167. package/lib/prefetch/ResourceHintPlugin.js +1 -1
  168. package/lib/provide/ProvidedDependency.js +36 -4
  169. package/lib/rules/BasicEffectRulePlugin.js +1 -1
  170. package/lib/rules/RuleSetCompiler.js +15 -5
  171. package/lib/rules/UseEffectRulePlugin.js +1 -3
  172. package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
  173. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
  174. package/lib/runtime/RuntimeGlobals.js +6 -0
  175. package/lib/runtime/RuntimePlugin.js +2 -0
  176. package/lib/schemes/HttpUriPlugin.js +1 -2
  177. package/lib/schemes/VirtualUrlPlugin.js +3 -1
  178. package/lib/serialization/AggregateErrorSerializer.js +3 -3
  179. package/lib/serialization/BinaryMiddleware.js +4 -1
  180. package/lib/serialization/ErrorObjectSerializer.js +2 -5
  181. package/lib/serialization/ObjectMiddleware.js +17 -15
  182. package/lib/serialization/PlainObjectSerializer.js +3 -7
  183. package/lib/serialization/Serializer.js +21 -11
  184. package/lib/serialization/SerializerMiddleware.js +8 -6
  185. package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
  186. package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
  187. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
  188. package/lib/stats/StatsFactory.js +194 -24
  189. package/lib/stats/StatsPrinter.js +126 -13
  190. package/lib/template/DependencyTemplate.js +1 -1
  191. package/lib/template/RuntimeTemplate.js +13 -32
  192. package/lib/template/Template.js +1 -1
  193. package/lib/util/SourceProcessor.js +146 -29
  194. package/lib/util/WeakTupleMap.js +10 -4
  195. package/lib/util/cleverMerge.js +61 -33
  196. package/lib/util/comparators.js +9 -5
  197. package/lib/util/dataURL.js +2 -0
  198. package/lib/util/deprecation.js +4 -3
  199. package/lib/util/globUtils.js +1 -4
  200. package/lib/util/internalSerializables.js +2 -0
  201. package/lib/util/makeSerializable.js +6 -4
  202. package/lib/util/memoize.js +1 -1
  203. package/lib/util/parseJson.js +2 -2
  204. package/lib/util/serialization.js +31 -27
  205. package/lib/wasm/AsyncWasmModule.js +12 -2
  206. package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
  207. package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
  208. package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
  209. package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
  210. package/lib/wasm-sync/SyncWasmModule.js +16 -1
  211. package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
  212. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
  213. package/lib/wasm-sync/WebAssemblyParser.js +10 -12
  214. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
  215. package/lib/web/FetchCompileWasmPlugin.js +2 -6
  216. package/package.json +18 -19
  217. package/schemas/WebpackOptions.check.js +3 -3
  218. package/schemas/WebpackOptions.json +2 -2
  219. package/schemas/plugins/BannerPlugin.check.js +3 -3
  220. package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
  221. package/schemas/plugins/HtmlParserOptions.check.js +3 -3
  222. package/schemas/plugins/IgnorePlugin.check.js +3 -3
  223. package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
  224. package/schemas/plugins/ManifestPlugin.check.js +3 -3
  225. package/schemas/plugins/ProgressPlugin.check.js +3 -3
  226. package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
  227. package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
  228. package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
  229. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
  230. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
  231. package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
  232. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
  233. package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
  234. package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
  235. package/schemas/plugins/container/ExternalsType.check.js +3 -3
  236. package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
  237. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
  238. package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
  239. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
  240. package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
  241. package/schemas/plugins/css/CssParserOptions.check.js +3 -3
  242. package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
  243. package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
  244. package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
  245. package/schemas/plugins/dll/DllPlugin.check.js +3 -3
  246. package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
  247. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
  248. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
  249. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
  250. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
  251. package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
  252. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
  253. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
  254. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
  255. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
  256. package/schemas/plugins/output/CleanOptions.check.js +7 -0
  257. package/schemas/plugins/output/CleanOptions.json +3 -0
  258. package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
  259. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
  260. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
  261. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
  262. package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
  263. package/types.d.ts +1482 -358
@@ -35,7 +35,12 @@ const getOutgoingAsyncModules = (moduleGraph, module) => {
35
35
  // Walk the imports in source order: the spec gathers these from
36
36
  // `[[RequestedModules]]`, and their evaluation order is observable.
37
37
  for (const dependency of module.dependencies) {
38
- if (!isDependencyKind(dependency, "esm-import")) continue;
38
+ if (
39
+ !isDependencyKind(dependency, "esm-import") &&
40
+ !isDependencyKind(dependency, "provided")
41
+ ) {
42
+ continue;
43
+ }
39
44
  const referenced = moduleGraph.getModule(dependency);
40
45
  if (!referenced || seen.has(referenced)) continue;
41
46
  const connections = outgoingConnectionMap.get(referenced);
@@ -44,7 +49,8 @@ const getOutgoingAsyncModules = (moduleGraph, module) => {
44
49
  connections.some(
45
50
  (c) =>
46
51
  c.dependency !== null &&
47
- isDependencyKind(c.dependency, "esm-import") &&
52
+ (isDependencyKind(c.dependency, "esm-import") ||
53
+ isDependencyKind(c.dependency, "provided")) &&
48
54
  c.isTargetActive(undefined)
49
55
  )
50
56
  ) {
@@ -8,7 +8,7 @@
8
8
  const isDependencyKind = require("../graph/isDependencyKind");
9
9
 
10
10
  /** @import Compiler from "../Compiler" */
11
- /** @import Module from "../module/Module" */
11
+ /** @import Module, { BuildMeta } from "../module/Module" */
12
12
 
13
13
  const PLUGIN_NAME = "InferAsyncModulesPlugin";
14
14
 
@@ -39,7 +39,12 @@ class InferAsyncModulesPlugin {
39
39
  connections.some(
40
40
  (c) =>
41
41
  c.dependency !== null &&
42
- isDependencyKind(c.dependency, "esm-import") &&
42
+ (isDependencyKind(c.dependency, "esm-import") ||
43
+ // only an ESM module has the async wrapper to await it in
44
+ (isDependencyKind(c.dependency, "provided") &&
45
+ /** @type {BuildMeta} */
46
+ (/** @type {Module} */ (originModule).buildMeta)
47
+ .exportsType === "namespace")) &&
43
48
  c.isTargetActive(undefined)
44
49
  )
45
50
  ) {
@@ -42,7 +42,7 @@ class MultiItemCache {
42
42
  this._items = items;
43
43
  // @ts-expect-error expected - returns the single ItemCacheFacade when passed an array of length 1
44
44
  // eslint-disable-next-line no-constructor-return
45
- if (items.length === 1) return /** @type {ItemCacheFacade} */ (items[0]);
45
+ if (items.length === 1) return items[0];
46
46
  }
47
47
 
48
48
  /**
@@ -215,7 +215,7 @@ class Pack {
215
215
  if (!this.content[loc]) {
216
216
  return;
217
217
  }
218
- return /** @type {PackContent} */ (this.content[loc]).get(identifier);
218
+ return this.content[loc].get(identifier);
219
219
  }
220
220
 
221
221
  /**
@@ -328,7 +328,9 @@ class Pack {
328
328
  let ignoreNextTimeTick = false;
329
329
  const createNextPack = () => {
330
330
  const loc = this._findLocation();
331
- this.content[loc] = /** @type {EXPECTED_ANY} */ (null); // reserve
331
+ this.content[loc] = /** @type {PackContent} */ (
332
+ /** @type {PackContent | null} */ (null)
333
+ ); // reserve
332
334
  /** @type {PackItem} */
333
335
  const pack = {
334
336
  items: new Set(),
@@ -1010,9 +1012,7 @@ class PackContent {
1010
1012
  );
1011
1013
  logger.time(timeMessage);
1012
1014
  }
1013
- const value =
1014
- /** @type {PackContentItems | Promise<PackContentItems>} */
1015
- (this.lazy());
1015
+ const value = this.lazy();
1016
1016
  if ("then" in value) {
1017
1017
  return value.then((data) => {
1018
1018
  if (timeMessage) {
@@ -1789,11 +1789,7 @@ class PackFileCacheStrategy {
1789
1789
  const mtimeMs = await new Promise((resolve, reject) => {
1790
1790
  fs.stat(file, (err, stats) => {
1791
1791
  if (err) return reject(err);
1792
- resolve(
1793
- /** @type {number} */ (
1794
- /** @type {import("../fs/fs").IStats} */ (stats).mtimeMs
1795
- )
1796
- );
1792
+ resolve(/** @type {import("../fs/fs").IStats} */ (stats).mtimeMs);
1797
1793
  });
1798
1794
  });
1799
1795
  const entry = referencedFilesCache.get(name);
@@ -25,7 +25,6 @@ const makeSerializable = require("../util/makeSerializable");
25
25
  * SnapshotOptions
26
26
  * } from "../fs/FileSystemInfo"
27
27
  */
28
- /** @import { ResolveOptionsWithDependencyType } from "../resolve/ResolverFactory" */
29
28
  /**
30
29
  * @import {
31
30
  * ObjectDeserializerContext,
@@ -128,6 +127,10 @@ class ResolverCachePlugin {
128
127
  let fileSystemInfo;
129
128
  /** @type {SnapshotOptions | undefined} */
130
129
  let snapshotOptions;
130
+ // paths the watcher reported for this build; a snapshot can miss them when
131
+ // the resolve read a cached file system state, e.g. inside a managed path
132
+ /** @type {Set<string> | undefined} */
133
+ let changedPaths;
131
134
  let realResolves = 0;
132
135
  let cachedResolves = 0;
133
136
  let cacheInvalidResolves = 0;
@@ -137,10 +140,17 @@ class ResolverCachePlugin {
137
140
  compiler.hooks.shutdown.tap(PLUGIN_NAME, () => {
138
141
  fileSystemInfo = undefined;
139
142
  snapshotOptions = undefined;
143
+ changedPaths = undefined;
140
144
  });
141
145
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
142
146
  snapshotOptions = compilation.options.snapshot.resolve;
143
147
  fileSystemInfo = compilation.fileSystemInfo;
148
+ const { modifiedFiles, removedFiles } = compiler;
149
+ changedPaths =
150
+ (modifiedFiles && modifiedFiles.size > 0) ||
151
+ (removedFiles && removedFiles.size > 0)
152
+ ? new Set([...(modifiedFiles || []), ...(removedFiles || [])])
153
+ : undefined;
144
154
  compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
145
155
  if (realResolves + cachedResolves > 0) {
146
156
  const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
@@ -157,6 +167,24 @@ class ResolverCachePlugin {
157
167
  });
158
168
  });
159
169
 
170
+ /**
171
+ * @param {InstanceType<Snapshot>} snapshot snapshot of a cached resolve
172
+ * @returns {boolean} true, when the watcher reported one of its paths
173
+ */
174
+ const dependsOnChangedPath = (snapshot) => {
175
+ if (changedPaths === undefined) return false;
176
+ for (const iterable of [
177
+ snapshot.getMissingIterable(),
178
+ snapshot.getFileIterable(),
179
+ snapshot.getContextIterable()
180
+ ]) {
181
+ for (const item of iterable) {
182
+ if (changedPaths.has(item)) return true;
183
+ }
184
+ }
185
+ return false;
186
+ };
187
+
160
188
  /** @typedef {(err?: Error | null, resolveRequest?: ResolveRequest | null) => void} Callback */
161
189
  /** @typedef {ResolveRequest & { _ResolverCachePluginCacheMiss: true }} ResolveRequestWithCacheMiss */
162
190
 
@@ -227,9 +255,20 @@ class ResolverCachePlugin {
227
255
  const fileDependencies = newResolveContext.fileDependencies;
228
256
  const contextDependencies = newResolveContext.contextDependencies;
229
257
  const missingDependencies = newResolveContext.missingDependencies;
230
- // Only reachable past the `!fileSystemInfo` guard on the resolve tap.
231
- const fsInfo = /** @type {FileSystemInfo} */ (fileSystemInfo);
232
- fsInfo.createSnapshot(
258
+ const resolveResult = withYield ? yieldResult : result;
259
+ // the compiler was closed while resolving, e.g. after a bailed build
260
+ if (!fileSystemInfo) {
261
+ if (withYield && result) {
262
+ /** @type {ResolveRequest[]} */
263
+ (yieldResult).push(result);
264
+ }
265
+ return callback(
266
+ null,
267
+ /** @type {ResolveRequest} */
268
+ (resolveResult)
269
+ );
270
+ }
271
+ fileSystemInfo.createSnapshot(
233
272
  resolveTime,
234
273
  /** @type {Dependencies} */
235
274
  (fileDependencies),
@@ -240,7 +279,6 @@ class ResolverCachePlugin {
240
279
  snapshotOptions,
241
280
  (err, snapshot) => {
242
281
  if (err) return callback(err);
243
- const resolveResult = withYield ? yieldResult : result;
244
282
  // since we intercept resolve hook
245
283
  // we still can get result in callback
246
284
  if (withYield && result) {
@@ -287,9 +325,7 @@ class ResolverCachePlugin {
287
325
  const activeRequests = new Map();
288
326
  /** @type {Map<string, [ActiveRequest[], Yield[]]>} */
289
327
  const activeRequestsWithYield = new Map();
290
- const hook =
291
- /** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
292
- (_hook);
328
+ const hook = _hook;
293
329
  hook.tap(PLUGIN_NAME, (resolver, options, userOptions) => {
294
330
  if (
295
331
  /** @type {ResolveOptions & { cache: boolean }} */
@@ -416,6 +452,20 @@ class ResolverCachePlugin {
416
452
  const processCacheResult = (err, cacheEntry) => {
417
453
  if (err) return done(err);
418
454
 
455
+ // the compiler was closed while reading the cache
456
+ if (
457
+ cacheEntry &&
458
+ (!fileSystemInfo || dependsOnChangedPath(cacheEntry.snapshot))
459
+ ) {
460
+ cacheInvalidResolves++;
461
+ return doRealResolve(
462
+ itemCache,
463
+ resolver,
464
+ resolveContext,
465
+ request,
466
+ done
467
+ );
468
+ }
419
469
  if (cacheEntry) {
420
470
  const { snapshot, result } = cacheEntry;
421
471
  const fsInfo = /** @type {FileSystemInfo} */ (fileSystemInfo);
@@ -342,9 +342,7 @@ class WebpackOptionsApply extends OptionsApply {
342
342
  }
343
343
  }
344
344
 
345
- const enabledChunkLoadingTypes =
346
- /** @type {NonNullable<WebpackOptions["output"]["enabledChunkLoadingTypes"]>} */
347
- (options.output.enabledChunkLoadingTypes);
345
+ const enabledChunkLoadingTypes = options.output.enabledChunkLoadingTypes;
348
346
 
349
347
  if (enabledChunkLoadingTypes.length > 0) {
350
348
  for (const type of enabledChunkLoadingTypes) {
@@ -354,9 +352,7 @@ class WebpackOptionsApply extends OptionsApply {
354
352
  }
355
353
  }
356
354
 
357
- const enabledWasmLoadingTypes =
358
- /** @type {NonNullable<WebpackOptions["output"]["enabledWasmLoadingTypes"]>} */
359
- (options.output.enabledWasmLoadingTypes);
355
+ const enabledWasmLoadingTypes = options.output.enabledWasmLoadingTypes;
360
356
 
361
357
  if (enabledWasmLoadingTypes.length > 0) {
362
358
  for (const type of enabledWasmLoadingTypes) {
@@ -366,9 +362,7 @@ class WebpackOptionsApply extends OptionsApply {
366
362
  }
367
363
  }
368
364
 
369
- const enabledLibraryTypes =
370
- /** @type {NonNullable<WebpackOptions["output"]["enabledLibraryTypes"]>} */
371
- (options.output.enabledLibraryTypes);
365
+ const enabledLibraryTypes = options.output.enabledLibraryTypes;
372
366
 
373
367
  if (enabledLibraryTypes.length > 0) {
374
368
  let once = true;
@@ -755,9 +749,7 @@ class WebpackOptionsApply extends OptionsApply {
755
749
  hashFunction:
756
750
  /** @type {NonNullable<WebpackOptions["output"]["hashFunction"]>} */
757
751
  (options.output.hashFunction),
758
- hashDigest:
759
- /** @type {NonNullable<WebpackOptions["output"]["hashDigest"]>} */
760
- (options.output.hashDigest),
752
+ hashDigest: options.output.hashDigest,
761
753
  onDemand: !options.optimization.realContentHash
762
754
  }).apply(compiler);
763
755
  }
@@ -1115,26 +1107,14 @@ class WebpackOptionsApply extends OptionsApply {
1115
1107
  } = require("../util/globUtils");
1116
1108
 
1117
1109
  return compileRelativeGlobPaths(paths, (pattern) =>
1118
- createPathGlobPrefixRegExp(
1119
- pattern,
1120
- /** @type {string} */ (options.context)
1121
- )
1110
+ createPathGlobPrefixRegExp(pattern, options.context)
1122
1111
  );
1123
1112
  };
1124
1113
  const snapshotOptions = {
1125
1114
  ...options.snapshot,
1126
- managedPaths: compileSnapshotPaths(
1127
- /** @type {NonNullable<WebpackOptions["snapshot"]["managedPaths"]>} */
1128
- (options.snapshot.managedPaths)
1129
- ),
1130
- immutablePaths: compileSnapshotPaths(
1131
- /** @type {NonNullable<WebpackOptions["snapshot"]["immutablePaths"]>} */
1132
- (options.snapshot.immutablePaths)
1133
- ),
1134
- unmanagedPaths: compileSnapshotPaths(
1135
- /** @type {NonNullable<WebpackOptions["snapshot"]["unmanagedPaths"]>} */
1136
- (options.snapshot.unmanagedPaths)
1137
- )
1115
+ managedPaths: compileSnapshotPaths(options.snapshot.managedPaths),
1116
+ immutablePaths: compileSnapshotPaths(options.snapshot.immutablePaths),
1117
+ unmanagedPaths: compileSnapshotPaths(options.snapshot.unmanagedPaths)
1138
1118
  };
1139
1119
 
1140
1120
  new AddManagedPathsPlugin(
package/lib/config/cli.js CHANGED
@@ -229,8 +229,10 @@ const getArguments = (schema = webpackSchema) => {
229
229
  description: undefined,
230
230
  simpleType:
231
231
  /** @type {SimpleType} */
232
- (/** @type {unknown} */ (undefined)),
233
- multiple: /** @type {boolean} */ (/** @type {unknown} */ (undefined))
232
+ (/** @type {SimpleType | undefined} */ (undefined)),
233
+ multiple: /** @type {boolean} */ (
234
+ /** @type {boolean | undefined} */ (undefined)
235
+ )
234
236
  };
235
237
  };
236
238
 
@@ -278,8 +280,10 @@ const getArguments = (schema = webpackSchema) => {
278
280
  description: undefined,
279
281
  simpleType:
280
282
  /** @type {SimpleType} */
281
- (/** @type {unknown} */ (undefined)),
282
- multiple: /** @type {boolean} */ (/** @type {unknown} */ (undefined))
283
+ (/** @type {SimpleType | undefined} */ (undefined)),
284
+ multiple: /** @type {boolean} */ (
285
+ /** @type {boolean | undefined} */ (undefined)
286
+ )
283
287
  };
284
288
  }
285
289
 
@@ -440,8 +444,7 @@ const getArguments = (schema = webpackSchema) => {
440
444
 
441
445
  for (let i = 0; i < items.length; i++) {
442
446
  addedArguments += traverse(
443
- /** @type {Schema} */
444
- (items[i]),
447
+ items[i],
445
448
  schemaPath,
446
449
  fullPath,
447
450
  inArray,
@@ -87,6 +87,8 @@ const {
87
87
  */
88
88
  /** @import { WasmLoadingTypes } from "../wasm/EnableWasmLoadingPlugin" */
89
89
  /** @import { PlatformTargetProperties, TargetProperties } from "./target" */
90
+ /** @import Compiler from "../Compiler" */
91
+ /** @typedef {Parameters<import("minimizer-webpack-plugin")["apply"]>[0]} MinimizerCompiler */
90
92
 
91
93
  /**
92
94
  * Defines the recursive non nullable type used by this module.
@@ -279,18 +281,20 @@ const A = (obj, prop, factory) => {
279
281
  if (value === undefined) {
280
282
  obj[prop] = factory();
281
283
  } else if (Array.isArray(value)) {
282
- /** @type {EXPECTED_ANY[] | undefined} */
284
+ /** @type {(T[P] extends (infer E)[] ? E : never)[] | undefined} */
283
285
  let newArray;
284
286
  for (let i = 0; i < value.length; i++) {
285
287
  const item = value[i];
286
288
  if (item === "...") {
287
289
  if (newArray === undefined) {
288
290
  newArray = value.slice(0, i);
289
- obj[prop] = /** @type {T[P]} */ (/** @type {unknown} */ (newArray));
291
+ obj[prop] = /** @type {T[P]} */ (
292
+ /** @type {T[P] | NonNullable<typeof newArray>} */ (newArray)
293
+ );
290
294
  }
291
295
  const items =
292
- /** @type {EXPECTED_ANY[]} */
293
- (/** @type {unknown} */ (factory()));
296
+ /** @type {NonNullable<typeof newArray>} */
297
+ (/** @type {T[P] | NonNullable<typeof newArray>} */ (factory()));
294
298
  if (items !== undefined) {
295
299
  for (const item of items) {
296
300
  newArray.push(item);
@@ -1708,7 +1712,7 @@ const applyOutputDefaults = (
1708
1712
  )
1709
1713
  );
1710
1714
 
1711
- const environment = /** @type {Environment} */ (output.environment);
1715
+ const environment = output.environment;
1712
1716
  /**
1713
1717
  * Returns true, when v is truthy or undefined.
1714
1718
  * @param {boolean | undefined} v value
@@ -2498,13 +2502,12 @@ const applyOptimizationDefaults = (
2498
2502
  D(optimization, "realContentHash", production);
2499
2503
  // A plugin assigning the object shorthand in `apply()` runs after
2500
2504
  // normalization: it replaces `minimizeOptions`, keeping `minimize` boolean.
2501
- const minimizeAssignedInApply = /** @type {unknown} */ (
2502
- optimization.minimize
2503
- );
2504
- if (typeof minimizeAssignedInApply === "object") {
2505
- optimization.minimizeOptions = /** @type {OptimizationMinimizeOptions} */ (
2506
- minimizeAssignedInApply
2505
+ const minimizeAssignedInApply =
2506
+ /** @type {Optimization["minimize"] | OptimizationMinimizeOptions} */ (
2507
+ optimization.minimize
2507
2508
  );
2509
+ if (typeof minimizeAssignedInApply === "object") {
2510
+ optimization.minimizeOptions = minimizeAssignedInApply;
2508
2511
  optimization.minimize = true;
2509
2512
  }
2510
2513
  D(optimization, "minimize", production);
@@ -2613,7 +2616,11 @@ const applyOptimizationDefaults = (
2613
2616
  test: assetNameTest(["[cm]?js"]),
2614
2617
  minify: javascriptMinify,
2615
2618
  minimizerOptions: javascriptOptions
2616
- }).apply(/** @type {EXPECTED_ANY} */ (compiler));
2619
+ }).apply(
2620
+ /** @type {MinimizerCompiler} */ (
2621
+ /** @type {Compiler | MinimizerCompiler} */ (compiler)
2622
+ )
2623
+ );
2617
2624
  return;
2618
2625
  }
2619
2626
  /** @type {(typeof javascriptMinify | string)[]} */
@@ -2703,7 +2710,11 @@ const applyOptimizationDefaults = (
2703
2710
  test: assetNameTest(extensions),
2704
2711
  minify,
2705
2712
  minimizerOptions
2706
- }).apply(/** @type {EXPECTED_ANY} */ (compiler));
2713
+ }).apply(
2714
+ /** @type {MinimizerCompiler} */ (
2715
+ /** @type {Compiler | MinimizerCompiler} */ (compiler)
2716
+ )
2717
+ );
2707
2718
  }
2708
2719
  }
2709
2720
  ]);
@@ -9,10 +9,10 @@ const { matchObject } = require("../devtool/ModuleFilenameHelpers");
9
9
 
10
10
  /** @import Compiler from "../Compiler" */
11
11
  /** @import { MatchObject } from "../devtool/ModuleFilenameHelpers" */
12
- /** @typedef {MatchObject & { minimizer?: import("minimizer-webpack-plugin").InternalPluginOptions<EXPECTED_ANY>["minimizer"] }} MinimizerOptions */
12
+ /** @typedef {MatchObject & { minimizer?: import("minimizer-webpack-plugin").InternalPluginOptions<import("terser").MinifyOptions>["minimizer"] }} MinimizerOptions */
13
13
 
14
14
  /**
15
- * @param {unknown} candidate a configured plugin or minimizer entry
15
+ * @param {NonNullable<Compiler["options"]["optimization"]["minimizer"]>[number] | Compiler["options"]["plugins"][number]} candidate a configured plugin or minimizer entry
16
16
  * @param {string} file probe filename
17
17
  * @returns {boolean} whether the candidate minimizes that file
18
18
  */
@@ -120,7 +120,7 @@ const getDefaultTarget = (context) => {
120
120
  */
121
121
  const versionDependent = (major, minor) => {
122
122
  if (!major) {
123
- return () => /** @type {undefined} */ (undefined);
123
+ return () => undefined;
124
124
  }
125
125
  /** @type {number} */
126
126
  const nMajor = Number(major);
@@ -659,7 +659,7 @@ class ContextModule extends Module {
659
659
  snapshotOptions,
660
660
  (err, snapshot) => {
661
661
  if (err) return callback(err);
662
- /** @type {BuildInfo} */
662
+ /** @type {ContextModuleBuildInfo} */
663
663
  (this.buildInfo).snapshot = snapshot;
664
664
  callback();
665
665
  }
@@ -588,7 +588,7 @@ class ContextModuleFactory extends ModuleFactory {
588
588
  )) {
589
589
  if (
590
590
  !(regExp instanceof RegExp) ||
591
- !regExp.test(/** @type {string} */ (alt.request))
591
+ !regExp.test(alt.request)
592
592
  ) {
593
593
  continue;
594
594
  }
@@ -82,17 +82,11 @@ class ContextReplacementPlugin {
82
82
  newContentRecursive = undefined;
83
83
  }
84
84
  // new webpack.ContextReplacementPlugin(/selector/, './folder', false, /selector/);
85
- this.newContentResource =
86
- /** @type {string | undefined} */
87
- (newContentResource);
85
+ this.newContentResource = newContentResource;
88
86
  /** @type {boolean | undefined} */
89
- this.newContentRecursive =
90
- /** @type {boolean | undefined} */
91
- (newContentRecursive);
87
+ this.newContentRecursive = newContentRecursive;
92
88
  /** @type {RegExp | undefined} */
93
- this.newContentRegExp =
94
- /** @type {RegExp | undefined} */
95
- (newContentRegExp);
89
+ this.newContentRegExp = newContentRegExp;
96
90
  }
97
91
  }
98
92