webpack 5.90.3 → 5.92.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 (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -12,25 +12,47 @@ const Chunk = require("./Chunk");
12
12
  const Module = require("./Module");
13
13
  const { parseResource } = require("./util/identifier");
14
14
 
15
+ /** @typedef {import("./ChunkGraph")} ChunkGraph */
15
16
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
16
17
  /** @typedef {import("./Compilation").PathData} PathData */
17
18
  /** @typedef {import("./Compiler")} Compiler */
18
19
 
19
20
  const REGEXP = /\[\\*([\w:]+)\\*\]/gi;
20
21
 
22
+ /**
23
+ * @param {string | number} id id
24
+ * @returns {string | number} result
25
+ */
21
26
  const prepareId = id => {
22
27
  if (typeof id !== "string") return id;
23
28
 
24
29
  if (/^"\s\+*.*\+\s*"$/.test(id)) {
25
30
  const match = /^"\s\+*\s*(.*)\s*\+\s*"$/.exec(id);
26
31
 
27
- return `" + (${match[1]} + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
32
+ return `" + (${
33
+ /** @type {string[]} */ (match)[1]
34
+ } + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
28
35
  }
29
36
 
30
37
  return id.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
31
38
  };
32
39
 
40
+ /**
41
+ * @callback ReplacerFunction
42
+ * @param {string} match
43
+ * @param {string | undefined} arg
44
+ * @param {string} input
45
+ */
46
+
47
+ /**
48
+ * @param {ReplacerFunction} replacer replacer
49
+ * @param {((arg0: number) => string) | undefined} handler handler
50
+ * @param {AssetInfo | undefined} assetInfo asset info
51
+ * @param {string} hashName hash name
52
+ * @returns {ReplacerFunction} hash replacer function
53
+ */
33
54
  const hashLength = (replacer, handler, assetInfo, hashName) => {
55
+ /** @type {ReplacerFunction} */
34
56
  const fn = (match, arg, input) => {
35
57
  let result;
36
58
  const length = arg && parseInt(arg, 10);
@@ -58,7 +80,15 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
58
80
  return fn;
59
81
  };
60
82
 
83
+ /** @typedef {(match: string, arg?: string, input?: string) => string} Replacer */
84
+
85
+ /**
86
+ * @param {string | number | null | undefined | (() => string | number | null | undefined)} value value
87
+ * @param {boolean=} allowEmpty allow empty
88
+ * @returns {Replacer} replacer
89
+ */
61
90
  const replacer = (value, allowEmpty) => {
91
+ /** @type {Replacer} */
62
92
  const fn = (match, arg, input) => {
63
93
  if (typeof value === "function") {
64
94
  value = value();
@@ -81,6 +111,12 @@ const replacer = (value, allowEmpty) => {
81
111
 
82
112
  const deprecationCache = new Map();
83
113
  const deprecatedFunction = (() => () => {})();
114
+ /**
115
+ * @param {Function} fn function
116
+ * @param {string} message message
117
+ * @param {string} code code
118
+ * @returns {function(...any[]): void} function with deprecation output
119
+ */
84
120
  const deprecated = (fn, message, code) => {
85
121
  let d = deprecationCache.get(message);
86
122
  if (d === undefined) {
@@ -96,7 +132,7 @@ const deprecated = (fn, message, code) => {
96
132
  /**
97
133
  * @param {string | function(PathData, AssetInfo=): string} path the raw path
98
134
  * @param {PathData} data context data
99
- * @param {AssetInfo} assetInfo extra info about the asset (will be written to)
135
+ * @param {AssetInfo | undefined} assetInfo extra info about the asset (will be written to)
100
136
  * @returns {string} the interpolated path
101
137
  */
102
138
  const replacePathVariables = (path, data, assetInfo) => {
@@ -227,7 +263,7 @@ const replacePathVariables = (path, data, assetInfo) => {
227
263
  ),
228
264
  data.contentHashWithLength ||
229
265
  ("contentHashWithLength" in chunk && chunk.contentHashWithLength
230
- ? chunk.contentHashWithLength[contentHashType]
266
+ ? chunk.contentHashWithLength[/** @type {string} */ (contentHashType)]
231
267
  : undefined),
232
268
  assetInfo,
233
269
  "contenthash"
@@ -255,13 +291,18 @@ const replacePathVariables = (path, data, assetInfo) => {
255
291
 
256
292
  const idReplacer = replacer(() =>
257
293
  prepareId(
258
- module instanceof Module ? chunkGraph.getModuleId(module) : module.id
294
+ module instanceof Module
295
+ ? /** @type {ChunkGraph} */ (chunkGraph).getModuleId(module)
296
+ : module.id
259
297
  )
260
298
  );
261
299
  const moduleHashReplacer = hashLength(
262
300
  replacer(() =>
263
301
  module instanceof Module
264
- ? chunkGraph.getRenderedModuleHash(module, data.runtime)
302
+ ? /** @type {ChunkGraph} */ (chunkGraph).getRenderedModuleHash(
303
+ module,
304
+ data.runtime
305
+ )
265
306
  : module.hash
266
307
  ),
267
308
  "hashWithLength" in module ? module.hashWithLength : undefined,
@@ -269,7 +310,7 @@ const replacePathVariables = (path, data, assetInfo) => {
269
310
  "modulehash"
270
311
  );
271
312
  const contentHashReplacer = hashLength(
272
- replacer(data.contentHash),
313
+ replacer(/** @type {string} */ (data.contentHash)),
273
314
  undefined,
274
315
  assetInfo,
275
316
  "contenthash"
@@ -300,7 +341,7 @@ const replacePathVariables = (path, data, assetInfo) => {
300
341
  if (typeof data.runtime === "string") {
301
342
  replacements.set(
302
343
  "runtime",
303
- replacer(() => prepareId(data.runtime))
344
+ replacer(() => prepareId(/** @type {string} */ (data.runtime)))
304
345
  );
305
346
  } else {
306
347
  replacements.set("runtime", replacer("_"));
package/lib/Watching.js CHANGED
@@ -13,11 +13,12 @@ const Stats = require("./Stats");
13
13
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
14
14
  /** @typedef {import("./WebpackError")} WebpackError */
15
15
  /** @typedef {import("./logging/Logger").Logger} Logger */
16
+ /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
16
17
 
17
18
  /**
18
19
  * @template T
19
20
  * @callback Callback
20
- * @param {(Error | null)=} err
21
+ * @param {Error | null} err
21
22
  * @param {T=} result
22
23
  */
23
24
 
@@ -171,8 +172,16 @@ class Watching {
171
172
  this._invalidReported = false;
172
173
  this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
173
174
  if (err) return this._done(err);
174
- const onCompiled = (err, compilation) => {
175
- if (err) return this._done(err, compilation);
175
+ /**
176
+ * @param {Error | null} err error
177
+ * @param {Compilation=} _compilation compilation
178
+ * @returns {void}
179
+ */
180
+ const onCompiled = (err, _compilation) => {
181
+ if (err) return this._done(err, _compilation);
182
+
183
+ const compilation = /** @type {Compilation} */ (_compilation);
184
+
176
185
  if (this.invalid) return this._done(null, compilation);
177
186
 
178
187
  if (this.compiler.hooks.shouldEmit.call(compilation) === false) {
@@ -195,7 +204,9 @@ class Watching {
195
204
  if (compilation.hooks.needAdditionalPass.call()) {
196
205
  compilation.needAdditionalPass = true;
197
206
 
198
- compilation.startTime = this.startTime;
207
+ compilation.startTime = /** @type {number} */ (
208
+ this.startTime
209
+ );
199
210
  compilation.endTime = Date.now();
200
211
  logger.time("done hook");
201
212
  const stats = new Stats(compilation);
@@ -239,10 +250,12 @@ class Watching {
239
250
  _done(err, compilation) {
240
251
  this.running = false;
241
252
 
242
- const logger = compilation && compilation.getLogger("webpack.Watching");
253
+ const logger =
254
+ /** @type {Logger} */
255
+ (compilation && compilation.getLogger("webpack.Watching"));
243
256
 
244
- /** @type {Stats | null} */
245
- let stats = null;
257
+ /** @type {Stats | undefined} */
258
+ let stats = undefined;
246
259
 
247
260
  /**
248
261
  * @param {Error} err error
@@ -267,13 +280,11 @@ class Watching {
267
280
  !(this._isBlocked() && (this.blocked = true))
268
281
  ) {
269
282
  if (compilation) {
270
- /** @type {Logger} */
271
- (logger).time("storeBuildDependencies");
283
+ logger.time("storeBuildDependencies");
272
284
  this.compiler.cache.storeBuildDependencies(
273
285
  compilation.buildDependencies,
274
286
  err => {
275
- /** @type {Logger} */
276
- (logger).timeEnd("storeBuildDependencies");
287
+ logger.timeEnd("storeBuildDependencies");
277
288
  if (err) return handleError(err);
278
289
  this._go();
279
290
  }
@@ -285,7 +296,7 @@ class Watching {
285
296
  }
286
297
 
287
298
  if (compilation) {
288
- compilation.startTime = this.startTime;
299
+ compilation.startTime = /** @type {number} */ (this.startTime);
289
300
  compilation.endTime = Date.now();
290
301
  stats = new Stats(compilation);
291
302
  }
@@ -294,28 +305,22 @@ class Watching {
294
305
 
295
306
  const cbs = this.callbacks;
296
307
  this.callbacks = [];
297
- /** @type {Logger} */
298
- (logger).time("done hook");
308
+ logger.time("done hook");
299
309
  this.compiler.hooks.done.callAsync(/** @type {Stats} */ (stats), err => {
300
- /** @type {Logger} */
301
- (logger).timeEnd("done hook");
310
+ logger.timeEnd("done hook");
302
311
  if (err) return handleError(err, cbs);
303
- this.handler(null, /** @type {Stats} */ (stats));
304
- /** @type {Logger} */
305
- (logger).time("storeBuildDependencies");
312
+ this.handler(null, stats);
313
+ logger.time("storeBuildDependencies");
306
314
  this.compiler.cache.storeBuildDependencies(
307
315
  /** @type {Compilation} */
308
316
  (compilation).buildDependencies,
309
317
  err => {
310
- /** @type {Logger} */
311
- (logger).timeEnd("storeBuildDependencies");
318
+ logger.timeEnd("storeBuildDependencies");
312
319
  if (err) return handleError(err, cbs);
313
- /** @type {Logger} */
314
- (logger).time("beginIdle");
320
+ logger.time("beginIdle");
315
321
  this.compiler.cache.beginIdle();
316
322
  this.compiler.idle = true;
317
- /** @type {Logger} */
318
- (logger).timeEnd("beginIdle");
323
+ logger.timeEnd("beginIdle");
319
324
  process.nextTick(() => {
320
325
  if (!this.closed) {
321
326
  this.watch(
@@ -343,43 +348,45 @@ class Watching {
343
348
  */
344
349
  watch(files, dirs, missing) {
345
350
  this.pausedWatcher = null;
346
- this.watcher = this.compiler.watchFileSystem.watch(
347
- files,
348
- dirs,
349
- missing,
350
- this.lastWatcherStartTime,
351
- this.watchOptions,
352
- (
353
- err,
354
- fileTimeInfoEntries,
355
- contextTimeInfoEntries,
356
- changedFiles,
357
- removedFiles
358
- ) => {
359
- if (err) {
360
- this.compiler.modifiedFiles = undefined;
361
- this.compiler.removedFiles = undefined;
362
- this.compiler.fileTimestamps = undefined;
363
- this.compiler.contextTimestamps = undefined;
364
- this.compiler.fsStartTime = undefined;
365
- return this.handler(err);
366
- }
367
- this._invalidate(
351
+ this.watcher =
352
+ /** @type {WatchFileSystem} */
353
+ (this.compiler.watchFileSystem).watch(
354
+ files,
355
+ dirs,
356
+ missing,
357
+ /** @type {number} */ (this.lastWatcherStartTime),
358
+ this.watchOptions,
359
+ (
360
+ err,
368
361
  fileTimeInfoEntries,
369
362
  contextTimeInfoEntries,
370
363
  changedFiles,
371
364
  removedFiles
372
- );
373
- this._onChange();
374
- },
375
- (fileName, changeTime) => {
376
- if (!this._invalidReported) {
377
- this._invalidReported = true;
378
- this.compiler.hooks.invalid.call(fileName, changeTime);
365
+ ) => {
366
+ if (err) {
367
+ this.compiler.modifiedFiles = undefined;
368
+ this.compiler.removedFiles = undefined;
369
+ this.compiler.fileTimestamps = undefined;
370
+ this.compiler.contextTimestamps = undefined;
371
+ this.compiler.fsStartTime = undefined;
372
+ return this.handler(err);
373
+ }
374
+ this._invalidate(
375
+ fileTimeInfoEntries,
376
+ contextTimeInfoEntries,
377
+ changedFiles,
378
+ removedFiles
379
+ );
380
+ this._onChange();
381
+ },
382
+ (fileName, changeTime) => {
383
+ if (!this._invalidReported) {
384
+ this._invalidReported = true;
385
+ this.compiler.hooks.invalid.call(fileName, changeTime);
386
+ }
387
+ this._onInvalid();
379
388
  }
380
- this._onInvalid();
381
- }
382
- );
389
+ );
383
390
  }
384
391
 
385
392
  /**
@@ -452,7 +459,7 @@ class Watching {
452
459
  return;
453
460
  }
454
461
  /**
455
- * @param {(WebpackError | null)=} err error if any
462
+ * @param {WebpackError | null} err error if any
456
463
  * @param {Compilation=} compilation compilation if any
457
464
  */
458
465
  const finalCallback = (err, compilation) => {
@@ -466,7 +473,7 @@ class Watching {
466
473
  this.compiler.contextTimestamps = undefined;
467
474
  this.compiler.fsStartTime = undefined;
468
475
  /**
469
- * @param {(WebpackError | null)=} err error if any
476
+ * @param {WebpackError | null} err error if any
470
477
  */
471
478
  const shutdown = err => {
472
479
  this.compiler.hooks.watchClose.call();
@@ -508,7 +515,7 @@ class Watching {
508
515
  this.invalid = true;
509
516
  this._done = finalCallback;
510
517
  } else {
511
- finalCallback();
518
+ finalCallback(null);
512
519
  }
513
520
  }
514
521
  }
@@ -22,17 +22,17 @@ class WebpackError extends Error {
22
22
  constructor(message) {
23
23
  super(message);
24
24
 
25
- /** @type {string | undefined} */
25
+ /** @type {string=} */
26
26
  this.details = undefined;
27
- /** @type {Module | undefined | null} */
27
+ /** @type {(Module | null)=} */
28
28
  this.module = undefined;
29
- /** @type {DependencyLocation | undefined} */
29
+ /** @type {DependencyLocation=} */
30
30
  this.loc = undefined;
31
- /** @type {boolean | undefined} */
31
+ /** @type {boolean=} */
32
32
  this.hideStack = undefined;
33
- /** @type {Chunk | undefined} */
33
+ /** @type {Chunk=} */
34
34
  this.chunk = undefined;
35
- /** @type {string | undefined} */
35
+ /** @type {string=} */
36
36
  this.file = undefined;
37
37
  }
38
38
 
@@ -57,6 +57,8 @@ const { cleverMerge } = require("./util/cleverMerge");
57
57
 
58
58
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
59
59
  /** @typedef {import("./Compiler")} Compiler */
60
+ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
61
+ /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
60
62
 
61
63
  class WebpackOptionsApply extends OptionsApply {
62
64
  constructor() {
@@ -455,7 +457,10 @@ class WebpackOptionsApply extends OptionsApply {
455
457
  }
456
458
  if (options.optimization.runtimeChunk) {
457
459
  const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
458
- new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
460
+ new RuntimeChunkPlugin(
461
+ /** @type {{ name?: (entrypoint: { name: string }) => string }} */
462
+ (options.optimization.runtimeChunk)
463
+ ).apply(compiler);
459
464
  }
460
465
  if (!options.optimization.emitOnErrors) {
461
466
  const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
@@ -649,7 +654,9 @@ class WebpackOptionsApply extends OptionsApply {
649
654
  new IdleFileCachePlugin(
650
655
  new PackFileCacheStrategy({
651
656
  compiler,
652
- fs: compiler.intermediateFileSystem,
657
+ fs: /** @type {IntermediateFileSystem} */ (
658
+ compiler.intermediateFileSystem
659
+ ),
653
660
  context: options.context,
654
661
  cacheLocation: cacheOptions.cacheLocation,
655
662
  version: cacheOptions.version,
@@ -694,14 +701,18 @@ class WebpackOptionsApply extends OptionsApply {
694
701
  .for("normal")
695
702
  .tap("WebpackOptionsApply", resolveOptions => {
696
703
  resolveOptions = cleverMerge(options.resolve, resolveOptions);
697
- resolveOptions.fileSystem = compiler.inputFileSystem;
704
+ resolveOptions.fileSystem =
705
+ /** @type {InputFileSystem} */
706
+ (compiler.inputFileSystem);
698
707
  return resolveOptions;
699
708
  });
700
709
  compiler.resolverFactory.hooks.resolveOptions
701
710
  .for("context")
702
711
  .tap("WebpackOptionsApply", resolveOptions => {
703
712
  resolveOptions = cleverMerge(options.resolve, resolveOptions);
704
- resolveOptions.fileSystem = compiler.inputFileSystem;
713
+ resolveOptions.fileSystem =
714
+ /** @type {InputFileSystem} */
715
+ (compiler.inputFileSystem);
705
716
  resolveOptions.resolveToContext = true;
706
717
  return resolveOptions;
707
718
  });
@@ -709,7 +720,9 @@ class WebpackOptionsApply extends OptionsApply {
709
720
  .for("loader")
710
721
  .tap("WebpackOptionsApply", resolveOptions => {
711
722
  resolveOptions = cleverMerge(options.resolveLoader, resolveOptions);
712
- resolveOptions.fileSystem = compiler.inputFileSystem;
723
+ resolveOptions.fileSystem =
724
+ /** @type {InputFileSystem} */
725
+ (compiler.inputFileSystem);
713
726
  return resolveOptions;
714
727
  });
715
728
  compiler.hooks.afterResolvers.call(compiler);
@@ -12,6 +12,7 @@ const ConcatenationScope = require("../ConcatenationScope");
12
12
  const Generator = require("../Generator");
13
13
  const { ASSET_MODULE_TYPE } = require("../ModuleTypeConstants");
14
14
  const RuntimeGlobals = require("../RuntimeGlobals");
15
+ const CssUrlDependency = require("../dependencies/CssUrlDependency");
15
16
  const createHash = require("../util/createHash");
16
17
  const { makePathsRelative } = require("../util/identifier");
17
18
  const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
@@ -321,6 +322,7 @@ class AssetGenerator extends Generator {
321
322
  }
322
323
  );
323
324
  let assetPath;
325
+ let assetPathForCss;
324
326
  if (this.publicPath !== undefined) {
325
327
  const { path, info } =
326
328
  runtimeTemplate.compilation.getAssetPathWithInfo(
@@ -335,12 +337,24 @@ class AssetGenerator extends Generator {
335
337
  );
336
338
  assetInfo = mergeAssetInfo(assetInfo, info);
337
339
  assetPath = JSON.stringify(path + filename);
340
+ assetPathForCss = path + filename;
338
341
  } else {
339
342
  runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p
340
343
  assetPath = runtimeTemplate.concatenation(
341
344
  { expr: RuntimeGlobals.publicPath },
342
345
  filename
343
346
  );
347
+ const compilation = runtimeTemplate.compilation;
348
+ const path =
349
+ compilation.outputOptions.publicPath === "auto"
350
+ ? CssUrlDependency.PUBLIC_PATH_AUTO
351
+ : compilation.getAssetPath(
352
+ compilation.outputOptions.publicPath,
353
+ {
354
+ hash: compilation.hash
355
+ }
356
+ );
357
+ assetPathForCss = path + filename;
344
358
  }
345
359
  assetInfo = {
346
360
  sourceFilename,
@@ -371,6 +385,7 @@ class AssetGenerator extends Generator {
371
385
  data.set("fullContentHash", fullHash);
372
386
  data.set("filename", filename);
373
387
  data.set("assetInfo", assetInfo);
388
+ data.set("assetPathForCss", assetPathForCss);
374
389
  }
375
390
  content = assetPath;
376
391
  }
@@ -71,7 +71,9 @@ class RawDataUrlModule extends Module {
71
71
  * @returns {string} a user readable identifier of the module
72
72
  */
73
73
  readableIdentifier(requestShortener) {
74
- return requestShortener.shorten(this.readableIdentifierStr);
74
+ return /** @type {string} */ (
75
+ requestShortener.shorten(this.readableIdentifierStr)
76
+ );
75
77
  }
76
78
 
77
79
  /**
@@ -13,7 +13,7 @@ const Template = require("../Template");
13
13
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
14
14
 
15
15
  /**
16
- * @typedef {GenerateContext} Context
16
+ * @extends {InitFragment<GenerateContext>}
17
17
  */
18
18
  class AwaitDependenciesInitFragment extends InitFragment {
19
19
  /**
@@ -43,7 +43,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
43
43
 
44
44
  /**
45
45
  * @param {GenerateContext} context context
46
- * @returns {string | Source} the source code that will be included as initialization code
46
+ * @returns {string | Source | undefined} the source code that will be included as initialization code
47
47
  */
48
48
  getContent({ runtimeRequirements }) {
49
49
  runtimeRequirements.add(RuntimeGlobals.module);