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
@@ -18,7 +18,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
18
18
  /**
19
19
  * @param {JavascriptParser} parser the parser
20
20
  * @param {string} value the const value
21
- * @param {string[]=} runtimeRequirements runtime requirements
21
+ * @param {(string[] | null)=} runtimeRequirements runtime requirements
22
22
  * @returns {function(Expression): true} plugin function
23
23
  */
24
24
  exports.toConstantDependency = (parser, value, runtimeRequirements) => {
@@ -12,8 +12,10 @@ const { getAllChunks } = require("./ChunkHelpers");
12
12
 
13
13
  /** @typedef {import("../util/Hash")} Hash */
14
14
  /** @typedef {import("../Chunk")} Chunk */
15
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
15
16
  /** @typedef {import("../Compilation")} Compilation */
16
17
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
+ /** @typedef {import("../Entrypoint")} Entrypoint */
17
19
  /** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
18
20
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
19
21
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
@@ -73,9 +75,15 @@ exports.generateEntryStartup = (
73
75
  let currentModuleIds = undefined;
74
76
 
75
77
  for (const [module, entrypoint] of entries) {
76
- const runtimeChunk = entrypoint.getRuntimeChunk();
78
+ const runtimeChunk =
79
+ /** @type {Entrypoint} */
80
+ (entrypoint).getRuntimeChunk();
77
81
  const moduleId = chunkGraph.getModuleId(module);
78
- const chunks = getAllChunks(entrypoint, chunk, runtimeChunk);
82
+ const chunks = getAllChunks(
83
+ /** @type {Entrypoint} */ (entrypoint),
84
+ chunk,
85
+ runtimeChunk
86
+ );
79
87
  if (
80
88
  currentChunks &&
81
89
  currentChunks.size === chunks.size &&
@@ -108,11 +116,18 @@ exports.generateEntryStartup = (
108
116
  */
109
117
  exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
110
118
  for (const [module, entrypoint] of entries) {
111
- const runtimeChunk = entrypoint.getRuntimeChunk();
119
+ const runtimeChunk =
120
+ /** @type {Entrypoint} */
121
+ (entrypoint).getRuntimeChunk();
112
122
  const moduleId = chunkGraph.getModuleId(module);
113
123
  hash.update(`${moduleId}`);
114
- for (const c of getAllChunks(entrypoint, chunk, runtimeChunk))
124
+ for (const c of getAllChunks(
125
+ /** @type {Entrypoint} */ (entrypoint),
126
+ chunk,
127
+ /** @type {Chunk} */ (runtimeChunk)
128
+ )) {
115
129
  hash.update(`${c.id}`);
130
+ }
116
131
  }
117
132
  };
118
133
 
@@ -126,7 +141,9 @@ exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
126
141
  const initialChunkIds = new Set(chunk.ids);
127
142
  for (const c of chunk.getAllInitialChunks()) {
128
143
  if (c === chunk || filterFn(c, chunkGraph)) continue;
129
- for (const id of c.ids) initialChunkIds.add(id);
144
+ for (const id of /** @type {ChunkId[]} */ (c.ids)) {
145
+ initialChunkIds.add(id);
146
+ }
130
147
  }
131
148
  return initialChunkIds;
132
149
  };
@@ -26,7 +26,7 @@ const COMMON_LIBRARY_NAME_MESSAGE =
26
26
 
27
27
  /**
28
28
  * @template T
29
- * @typedef {Object} LibraryContext
29
+ * @typedef {object} LibraryContext
30
30
  * @property {Compilation} compilation
31
31
  * @property {ChunkGraph} chunkGraph
32
32
  * @property {T} options
@@ -37,7 +37,7 @@ const COMMON_LIBRARY_NAME_MESSAGE =
37
37
  */
38
38
  class AbstractLibraryPlugin {
39
39
  /**
40
- * @param {Object} options options
40
+ * @param {object} options options
41
41
  * @param {string} options.pluginName name of the plugin
42
42
  * @param {LibraryType} options.type used library type
43
43
  */
@@ -21,13 +21,13 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
21
21
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
22
22
 
23
23
  /**
24
- * @typedef {Object} AmdLibraryPluginOptions
24
+ * @typedef {object} AmdLibraryPluginOptions
25
25
  * @property {LibraryType} type
26
26
  * @property {boolean=} requireAsWrapper
27
27
  */
28
28
 
29
29
  /**
30
- * @typedef {Object} AmdLibraryPluginParsed
30
+ * @typedef {object} AmdLibraryPluginParsed
31
31
  * @property {string} name
32
32
  * @property {string} amdContainer
33
33
  */
@@ -91,7 +91,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
91
91
  };
92
92
 
93
93
  /**
94
- * @typedef {Object} AssignLibraryPluginOptions
94
+ * @typedef {object} AssignLibraryPluginOptions
95
95
  * @property {LibraryType} type
96
96
  * @property {string[] | "global"} prefix name prefix
97
97
  * @property {string | false} declare declare name as variable
@@ -100,7 +100,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
100
100
  */
101
101
 
102
102
  /**
103
- * @typedef {Object} AssignLibraryPluginParsed
103
+ * @typedef {object} AssignLibraryPluginParsed
104
104
  * @property {string | string[]} name
105
105
  * @property {string | string[] | undefined} export
106
106
  */
@@ -323,7 +323,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
323
323
  true
324
324
  )};\n`
325
325
  );
326
- /** @type {String} */
326
+ /** @type {string} */
327
327
  let exports = RuntimeGlobals.exports;
328
328
  if (exportAccess) {
329
329
  result.add(
@@ -22,12 +22,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
22
22
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
23
23
 
24
24
  /**
25
- * @typedef {Object} ExportPropertyLibraryPluginParsed
25
+ * @typedef {object} ExportPropertyLibraryPluginParsed
26
26
  * @property {string | string[]} export
27
27
  */
28
28
 
29
29
  /**
30
- * @typedef {Object} ExportPropertyLibraryPluginOptions
30
+ * @typedef {object} ExportPropertyLibraryPluginOptions
31
31
  * @property {LibraryType} type
32
32
  * @property {boolean} nsObjectUsed the namespace object is used
33
33
  */
@@ -19,12 +19,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
19
19
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
20
20
 
21
21
  /**
22
- * @typedef {Object} JsonpLibraryPluginOptions
22
+ * @typedef {object} JsonpLibraryPluginOptions
23
23
  * @property {LibraryType} type
24
24
  */
25
25
 
26
26
  /**
27
- * @typedef {Object} JsonpLibraryPluginParsed
27
+ * @typedef {object} JsonpLibraryPluginParsed
28
28
  * @property {string} name
29
29
  */
30
30
 
@@ -23,12 +23,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
23
23
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
24
24
 
25
25
  /**
26
- * @typedef {Object} ModuleLibraryPluginOptions
26
+ * @typedef {object} ModuleLibraryPluginOptions
27
27
  * @property {LibraryType} type
28
28
  */
29
29
 
30
30
  /**
31
- * @typedef {Object} ModuleLibraryPluginParsed
31
+ * @typedef {object} ModuleLibraryPluginParsed
32
32
  * @property {string} name
33
33
  */
34
34
 
@@ -23,12 +23,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
23
23
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
24
24
 
25
25
  /**
26
- * @typedef {Object} SystemLibraryPluginOptions
26
+ * @typedef {object} SystemLibraryPluginOptions
27
27
  * @property {LibraryType} type
28
28
  */
29
29
 
30
30
  /**
31
- * @typedef {Object} SystemLibraryPluginParsed
31
+ * @typedef {object} SystemLibraryPluginParsed
32
32
  * @property {string} name
33
33
  */
34
34
 
@@ -18,8 +18,13 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
18
18
  /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
19
19
  /** @typedef {import("../Compiler")} Compiler */
20
20
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
21
+ /** @typedef {import("../ExternalModule").RequestRecord} RequestRecord */
21
22
  /** @typedef {import("../util/Hash")} Hash */
22
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
23
+ /**
24
+ * @template T
25
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>}
26
+ * LibraryContext<T>
27
+ */
23
28
 
24
29
  /**
25
30
  * @param {string[]} accessor the accessor to convert to path
@@ -53,13 +58,13 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
53
58
  /** @typedef {string | string[] | LibraryCustomUmdObject} UmdLibraryPluginName */
54
59
 
55
60
  /**
56
- * @typedef {Object} UmdLibraryPluginOptions
61
+ * @typedef {object} UmdLibraryPluginOptions
57
62
  * @property {LibraryType} type
58
63
  * @property {boolean=} optionalAmdExternalAsGlobal
59
64
  */
60
65
 
61
66
  /**
62
- * @typedef {Object} UmdLibraryPluginParsed
67
+ * @typedef {object} UmdLibraryPluginParsed
63
68
  * @property {string | string[]} name
64
69
  * @property {LibraryCustomUmdObject} names
65
70
  * @property {string | LibraryCustomUmdCommentObject} auxiliaryComment
@@ -158,24 +163,38 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
158
163
  });
159
164
  };
160
165
 
166
+ /**
167
+ * @param {ExternalModule[]} modules external modules
168
+ * @returns {string} result
169
+ */
161
170
  const externalsDepsArray = modules => {
162
171
  return `[${replaceKeys(
163
172
  modules
164
173
  .map(m =>
165
174
  JSON.stringify(
166
- typeof m.request === "object" ? m.request.amd : m.request
175
+ typeof m.request === "object"
176
+ ? /** @type {RequestRecord} */
177
+ (m.request).amd
178
+ : m.request
167
179
  )
168
180
  )
169
181
  .join(", ")
170
182
  )}]`;
171
183
  };
172
184
 
185
+ /**
186
+ * @param {ExternalModule[]} modules external modules
187
+ * @returns {string} result
188
+ */
173
189
  const externalsRootArray = modules => {
174
190
  return replaceKeys(
175
191
  modules
176
192
  .map(m => {
177
193
  let request = m.request;
178
- if (typeof request === "object") request = request.root;
194
+ if (typeof request === "object")
195
+ request =
196
+ /** @type {RequestRecord} */
197
+ (request).root;
179
198
  return `root${accessorToObjectAccess([].concat(request))}`;
180
199
  })
181
200
  .join(", ")
@@ -194,7 +213,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
194
213
  let request = m.request;
195
214
  if (typeof request === "object") {
196
215
  request =
197
- /** @type {Record<string, string | string[]>} */
216
+ /** @type {RequestRecord} */
198
217
  (request)[type];
199
218
  }
200
219
  if (request === undefined) {
@@ -233,8 +252,14 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
233
252
  .join(", ");
234
253
  };
235
254
 
255
+ /**
256
+ * @param {string| string[]} library library name
257
+ * @returns {string} stringified library name
258
+ */
236
259
  const libraryName = library => {
237
- return JSON.stringify(replaceKeys([].concat(library).pop()));
260
+ return JSON.stringify(
261
+ replaceKeys(/** @type {string[]} */ ([]).concat(library).pop())
262
+ );
238
263
  };
239
264
 
240
265
  let amdFactory;
@@ -313,11 +338,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
313
338
  " else\n" +
314
339
  " " +
315
340
  replaceKeys(
316
- accessorAccess(
317
- "root",
318
- /** @type {string | string[]} */ (names.root) ||
319
- /** @type {string} */ (names.commonjs)
320
- )
341
+ accessorAccess("root", names.root || names.commonjs)
321
342
  ) +
322
343
  " = factory(" +
323
344
  externalsRootArray(externals) +
@@ -95,19 +95,32 @@ class WebpackLogger {
95
95
  this[LOG_SYMBOL](LogType.groupEnd, args);
96
96
  }
97
97
 
98
+ /**
99
+ * @param {string=} label label
100
+ */
98
101
  profile(label) {
99
102
  this[LOG_SYMBOL](LogType.profile, [label]);
100
103
  }
101
104
 
105
+ /**
106
+ * @param {string=} label label
107
+ */
102
108
  profileEnd(label) {
103
109
  this[LOG_SYMBOL](LogType.profileEnd, [label]);
104
110
  }
105
111
 
112
+ /**
113
+ * @param {string} label label
114
+ */
106
115
  time(label) {
116
+ /** @type {Map<string | undefined, [number, number]>} */
107
117
  this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map();
108
118
  this[TIMERS_SYMBOL].set(label, process.hrtime());
109
119
  }
110
120
 
121
+ /**
122
+ * @param {string=} label label
123
+ */
111
124
  timeLog(label) {
112
125
  const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
113
126
  if (!prev) {
@@ -117,16 +130,23 @@ class WebpackLogger {
117
130
  this[LOG_SYMBOL](LogType.time, [label, ...time]);
118
131
  }
119
132
 
133
+ /**
134
+ * @param {string=} label label
135
+ */
120
136
  timeEnd(label) {
121
137
  const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
122
138
  if (!prev) {
123
139
  throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`);
124
140
  }
125
141
  const time = process.hrtime(prev);
126
- this[TIMERS_SYMBOL].delete(label);
142
+ /** @type {Map<string | undefined, [number, number]>} */
143
+ (this[TIMERS_SYMBOL]).delete(label);
127
144
  this[LOG_SYMBOL](LogType.time, [label, ...time]);
128
145
  }
129
146
 
147
+ /**
148
+ * @param {string=} label label
149
+ */
130
150
  timeAggregate(label) {
131
151
  const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
132
152
  if (!prev) {
@@ -135,7 +155,9 @@ class WebpackLogger {
135
155
  );
136
156
  }
137
157
  const time = process.hrtime(prev);
138
- this[TIMERS_SYMBOL].delete(label);
158
+ /** @type {Map<string | undefined, [number, number]>} */
159
+ (this[TIMERS_SYMBOL]).delete(label);
160
+ /** @type {Map<string | undefined, [number, number]>} */
139
161
  this[TIMERS_AGGREGATES_SYMBOL] =
140
162
  this[TIMERS_AGGREGATES_SYMBOL] || new Map();
141
163
  const current = this[TIMERS_AGGREGATES_SYMBOL].get(label);
@@ -151,6 +173,9 @@ class WebpackLogger {
151
173
  this[TIMERS_AGGREGATES_SYMBOL].set(label, time);
152
174
  }
153
175
 
176
+ /**
177
+ * @param {string=} label label
178
+ */
154
179
  timeAggregateEnd(label) {
155
180
  if (this[TIMERS_AGGREGATES_SYMBOL] === undefined) return;
156
181
  const time = this[TIMERS_AGGREGATES_SYMBOL].get(label);
@@ -12,9 +12,10 @@ const { LogType } = require("./Logger");
12
12
  /** @typedef {import("./Logger").LogTypeEnum} LogTypeEnum */
13
13
 
14
14
  /** @typedef {function(string): boolean} FilterFunction */
15
+ /** @typedef {function(string, LogTypeEnum, any[]): void} LoggingFunction */
15
16
 
16
17
  /**
17
- * @typedef {Object} LoggerConsole
18
+ * @typedef {object} LoggerConsole
18
19
  * @property {function(): void} clear
19
20
  * @property {function(): void} trace
20
21
  * @property {(...args: any[]) => void} info
@@ -32,7 +33,7 @@ const { LogType } = require("./Logger");
32
33
  */
33
34
 
34
35
  /**
35
- * @typedef {Object} LoggerOptions
36
+ * @typedef {object} LoggerOptions
36
37
  * @property {false|true|"none"|"error"|"warn"|"info"|"log"|"verbose"} level loglevel
37
38
  * @property {FilterTypes|boolean} debug filter for debug logging
38
39
  * @property {LoggerConsole} console the console to log to
@@ -40,7 +41,7 @@ const { LogType } = require("./Logger");
40
41
 
41
42
  /**
42
43
  * @param {FilterItemTypes} item an input item
43
- * @returns {FilterFunction} filter function
44
+ * @returns {FilterFunction | undefined} filter function
44
45
  */
45
46
  const filterToFunction = item => {
46
47
  if (typeof item === "string") {
@@ -76,15 +77,18 @@ const LogLevel = {
76
77
 
77
78
  /**
78
79
  * @param {LoggerOptions} options options object
79
- * @returns {function(string, LogTypeEnum, any[]): void} logging function
80
+ * @returns {LoggingFunction} logging function
80
81
  */
81
82
  module.exports = ({ level = "info", debug = false, console }) => {
82
83
  const debugFilters =
83
- typeof debug === "boolean"
84
- ? [() => debug]
85
- : /** @type {FilterItemTypes[]} */ ([])
86
- .concat(debug)
87
- .map(filterToFunction);
84
+ /** @type {FilterFunction[]} */
85
+ (
86
+ typeof debug === "boolean"
87
+ ? [() => debug]
88
+ : /** @type {FilterItemTypes[]} */ ([])
89
+ .concat(debug)
90
+ .map(filterToFunction)
91
+ );
88
92
  /** @type {number} */
89
93
  const loglevel = LogLevel[`${level}`] || 0;
90
94
 
@@ -11,7 +11,8 @@ const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenc
11
11
  /** @typedef {import("../Chunk")} Chunk */
12
12
  /** @typedef {import("../Compiler")} Compiler */
13
13
 
14
- /** @typedef {Object} CommonJsChunkLoadingPluginOptions
14
+ /**
15
+ * @typedef {object} CommonJsChunkLoadingPluginOptions
15
16
  * @property {boolean} [asyncChunkLoading] enable async chunk loading
16
17
  */
17
18
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
8
+ const CachedInputFileSystem = require("enhanced-resolve").CachedInputFileSystem;
9
9
  const fs = require("graceful-fs");
10
10
  const createConsoleLogger = require("../logging/createConsoleLogger");
11
11
  const NodeWatchFileSystem = require("./NodeWatchFileSystem");
@@ -13,10 +13,11 @@ const nodeConsole = require("./nodeConsole");
13
13
 
14
14
  /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
15
15
  /** @typedef {import("../Compiler")} Compiler */
16
+ /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
16
17
 
17
18
  class NodeEnvironmentPlugin {
18
19
  /**
19
- * @param {Object} options options
20
+ * @param {object} options options
20
21
  * @param {InfrastructureLogging} options.infrastructureLogging infrastructure logging options
21
22
  */
22
23
  constructor(options) {
@@ -38,18 +39,23 @@ class NodeEnvironmentPlugin {
38
39
  nodeConsole({
39
40
  colors: infrastructureLogging.colors,
40
41
  appendOnly: infrastructureLogging.appendOnly,
41
- stream: infrastructureLogging.stream
42
+ stream:
43
+ /** @type {NodeJS.WritableStream} */
44
+ (infrastructureLogging.stream)
42
45
  })
43
46
  });
44
47
  compiler.inputFileSystem = new CachedInputFileSystem(fs, 60000);
45
- const inputFileSystem = compiler.inputFileSystem;
48
+ const inputFileSystem =
49
+ /** @type {InputFileSystem} */
50
+ (compiler.inputFileSystem);
46
51
  compiler.outputFileSystem = fs;
47
52
  compiler.intermediateFileSystem = fs;
48
- compiler.watchFileSystem = new NodeWatchFileSystem(
49
- compiler.inputFileSystem
50
- );
53
+ compiler.watchFileSystem = new NodeWatchFileSystem(inputFileSystem);
51
54
  compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
52
- if (compiler.inputFileSystem === inputFileSystem) {
55
+ if (
56
+ compiler.inputFileSystem === inputFileSystem &&
57
+ inputFileSystem.purge
58
+ ) {
53
59
  compiler.fsStartTime = Date.now();
54
60
  inputFileSystem.purge();
55
61
  }
@@ -11,7 +11,7 @@ const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
13
  /**
14
- * @typedef {Object} NodeTemplatePluginOptions
14
+ * @typedef {object} NodeTemplatePluginOptions
15
15
  * @property {boolean} [asyncChunkLoading] enable async chunk loading
16
16
  */
17
17
 
@@ -10,11 +10,15 @@ const Watchpack = require("watchpack");
10
10
 
11
11
  /** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */
12
12
  /** @typedef {import("../FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
13
+ /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
13
14
  /** @typedef {import("../util/fs").WatchFileSystem} WatchFileSystem */
14
15
  /** @typedef {import("../util/fs").WatchMethod} WatchMethod */
15
16
  /** @typedef {import("../util/fs").Watcher} Watcher */
16
17
 
17
18
  class NodeWatchFileSystem {
19
+ /**
20
+ * @param {InputFileSystem} inputFileSystem input filesystem
21
+ */
18
22
  constructor(inputFileSystem) {
19
23
  this.inputFileSystem = inputFileSystem;
20
24
  this.watcherOptions = {
@@ -26,10 +30,10 @@ class NodeWatchFileSystem {
26
30
  /**
27
31
  * @param {Iterable<string>} files watched files
28
32
  * @param {Iterable<string>} directories watched directories
29
- * @param {Iterable<string>} missing watched exitance entries
33
+ * @param {Iterable<string>} missing watched existence entries
30
34
  * @param {number} startTime timestamp of start time
31
35
  * @param {WatchOptions} options options object
32
- * @param {function((Error | null)=, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
36
+ * @param {function(Error | null, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
33
37
  * @param {function(string, number): void} callbackUndelayed callback when the first change was detected
34
38
  * @returns {Watcher} a watcher
35
39
  */
@@ -81,28 +85,35 @@ class NodeWatchFileSystem {
81
85
  }
82
86
  return { fileTimeInfoEntries, contextTimeInfoEntries };
83
87
  };
84
- this.watcher.once("aggregated", (changes, removals) => {
85
- // pause emitting events (avoids clearing aggregated changes and removals on timeout)
86
- this.watcher.pause();
88
+ this.watcher.once(
89
+ "aggregated",
90
+ /**
91
+ * @param {Set<string>} changes changes
92
+ * @param {Set<string>} removals removals
93
+ */
94
+ (changes, removals) => {
95
+ // pause emitting events (avoids clearing aggregated changes and removals on timeout)
96
+ this.watcher.pause();
87
97
 
88
- if (this.inputFileSystem && this.inputFileSystem.purge) {
89
98
  const fs = this.inputFileSystem;
90
- for (const item of changes) {
91
- fs.purge(item);
92
- }
93
- for (const item of removals) {
94
- fs.purge(item);
99
+ if (fs && fs.purge) {
100
+ for (const item of changes) {
101
+ fs.purge(item);
102
+ }
103
+ for (const item of removals) {
104
+ fs.purge(item);
105
+ }
95
106
  }
107
+ const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo();
108
+ callback(
109
+ null,
110
+ fileTimeInfoEntries,
111
+ contextTimeInfoEntries,
112
+ changes,
113
+ removals
114
+ );
96
115
  }
97
- const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo();
98
- callback(
99
- null,
100
- fileTimeInfoEntries,
101
- contextTimeInfoEntries,
102
- changes,
103
- removals
104
- );
105
- });
116
+ );
106
117
 
107
118
  this.watcher.watch({ files, directories, missing, startTime });
108
119
 
@@ -124,8 +135,8 @@ class NodeWatchFileSystem {
124
135
  getAggregatedRemovals: util.deprecate(
125
136
  () => {
126
137
  const items = this.watcher && this.watcher.aggregatedRemovals;
127
- if (items && this.inputFileSystem && this.inputFileSystem.purge) {
128
- const fs = this.inputFileSystem;
138
+ const fs = this.inputFileSystem;
139
+ if (items && fs && fs.purge) {
129
140
  for (const item of items) {
130
141
  fs.purge(item);
131
142
  }
@@ -138,8 +149,8 @@ class NodeWatchFileSystem {
138
149
  getAggregatedChanges: util.deprecate(
139
150
  () => {
140
151
  const items = this.watcher && this.watcher.aggregatedChanges;
141
- if (items && this.inputFileSystem && this.inputFileSystem.purge) {
142
- const fs = this.inputFileSystem;
152
+ const fs = this.inputFileSystem;
153
+ if (items && fs && fs.purge) {
143
154
  for (const item of items) {
144
155
  fs.purge(item);
145
156
  }
@@ -166,8 +177,8 @@ class NodeWatchFileSystem {
166
177
  getInfo: () => {
167
178
  const removals = this.watcher && this.watcher.aggregatedRemovals;
168
179
  const changes = this.watcher && this.watcher.aggregatedChanges;
169
- if (this.inputFileSystem && this.inputFileSystem.purge) {
170
- const fs = this.inputFileSystem;
180
+ const fs = this.inputFileSystem;
181
+ if (fs && fs.purge) {
171
182
  if (removals) {
172
183
  for (const item of removals) {
173
184
  fs.purge(item);
@@ -18,10 +18,11 @@ const { getUndoPath } = require("../util/identifier");
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
19
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
20
  /** @typedef {import("../Compilation")} Compilation */
21
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
21
22
 
22
23
  class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
23
24
  /**
24
- * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
25
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
25
26
  */
26
27
  constructor(runtimeRequirements) {
27
28
  super("readFile chunk loading", RuntimeModule.STAGE_ATTACH);
@@ -14,7 +14,7 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
14
14
  /** @typedef {import("../Compiler")} Compiler */
15
15
 
16
16
  /**
17
- * @typedef {Object} ReadFileCompileWasmPluginOptions
17
+ * @typedef {object} ReadFileCompileWasmPluginOptions
18
18
  * @property {boolean} [mangleImports] mangle imports
19
19
  */
20
20
 
@@ -18,10 +18,11 @@ const { getUndoPath } = require("../util/identifier");
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
19
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
20
  /** @typedef {import("../Compilation")} Compilation */
21
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
21
22
 
22
23
  class RequireChunkLoadingRuntimeModule extends RuntimeModule {
23
24
  /**
24
- * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
25
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
25
26
  */
26
27
  constructor(runtimeRequirements) {
27
28
  super("require chunk loading", RuntimeModule.STAGE_ATTACH);