webpack 5.104.1 → 5.105.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/bin/webpack.js +6 -3
  2. package/lib/APIPlugin.js +85 -15
  3. package/lib/AbstractMethodError.js +1 -0
  4. package/lib/AsyncDependenciesBlock.js +13 -1
  5. package/lib/AsyncDependencyToInitialChunkError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +2 -0
  8. package/lib/CacheFacade.js +2 -2
  9. package/lib/CaseSensitiveModulesWarning.js +1 -0
  10. package/lib/Chunk.js +8 -4
  11. package/lib/ChunkGraph.js +30 -9
  12. package/lib/ChunkGroup.js +6 -3
  13. package/lib/ChunkRenderError.js +2 -0
  14. package/lib/CleanPlugin.js +4 -1
  15. package/lib/CodeGenerationError.js +7 -1
  16. package/lib/CodeGenerationResults.js +10 -3
  17. package/lib/CommentCompilationWarning.js +2 -1
  18. package/lib/Compilation.js +280 -236
  19. package/lib/Compiler.js +3 -2
  20. package/lib/ConcatenationScope.js +2 -1
  21. package/lib/ConcurrentCompilationError.js +3 -3
  22. package/lib/ContextModule.js +248 -111
  23. package/lib/ContextModuleFactory.js +14 -2
  24. package/lib/DefinePlugin.js +3 -1
  25. package/lib/DelegatedModule.js +6 -0
  26. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  27. package/lib/Dependency.js +6 -1
  28. package/lib/DependencyTemplates.js +3 -2
  29. package/lib/DllModule.js +2 -0
  30. package/lib/DllReferencePlugin.js +1 -0
  31. package/lib/DotenvPlugin.js +11 -5
  32. package/lib/DynamicEntryPlugin.js +1 -0
  33. package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
  34. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  35. package/lib/ExportsInfo.js +8 -4
  36. package/lib/ExternalModule.js +16 -0
  37. package/lib/FalseIIFEUmdWarning.js +1 -0
  38. package/lib/FileSystemInfo.js +49 -25
  39. package/lib/FlagDependencyExportsPlugin.js +8 -1
  40. package/lib/FlagDependencyUsagePlugin.js +9 -7
  41. package/lib/HarmonyLinkingError.js +1 -0
  42. package/lib/HookWebpackError.js +2 -0
  43. package/lib/HotModuleReplacementPlugin.js +16 -2
  44. package/lib/InitFragment.js +1 -0
  45. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  46. package/lib/LibManifestPlugin.js +1 -0
  47. package/lib/ManifestPlugin.js +4 -1
  48. package/lib/Module.js +7 -4
  49. package/lib/ModuleBuildError.js +3 -1
  50. package/lib/ModuleDependencyError.js +1 -0
  51. package/lib/ModuleDependencyWarning.js +1 -0
  52. package/lib/ModuleError.js +2 -1
  53. package/lib/ModuleFilenameHelpers.js +2 -1
  54. package/lib/ModuleGraph.js +3 -0
  55. package/lib/ModuleGraphConnection.js +10 -1
  56. package/lib/ModuleHashingError.js +2 -0
  57. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  58. package/lib/ModuleNotFoundError.js +1 -0
  59. package/lib/ModuleParseError.js +5 -1
  60. package/lib/ModuleProfile.js +1 -1
  61. package/lib/ModuleRestoreError.js +2 -0
  62. package/lib/ModuleSourceTypeConstants.js +1 -11
  63. package/lib/ModuleStoreError.js +2 -0
  64. package/lib/ModuleWarning.js +3 -1
  65. package/lib/MultiCompiler.js +11 -7
  66. package/lib/MultiWatching.js +2 -2
  67. package/lib/NoModeWarning.js +1 -0
  68. package/lib/NodeStuffInWebError.js +1 -0
  69. package/lib/NormalModule.js +26 -5
  70. package/lib/NormalModuleFactory.js +20 -4
  71. package/lib/OptionsApply.js +3 -1
  72. package/lib/ProgressPlugin.js +4 -0
  73. package/lib/RawModule.js +2 -0
  74. package/lib/RuntimeModule.js +10 -0
  75. package/lib/RuntimePlugin.js +7 -9
  76. package/lib/RuntimeTemplate.js +14 -7
  77. package/lib/SourceMapDevToolPlugin.js +30 -23
  78. package/lib/Template.js +10 -5
  79. package/lib/TemplatedPathPlugin.js +4 -2
  80. package/lib/UnhandledSchemeError.js +1 -0
  81. package/lib/UnsupportedFeatureWarning.js +1 -0
  82. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  83. package/lib/WatchIgnorePlugin.js +1 -1
  84. package/lib/Watching.js +5 -0
  85. package/lib/WebpackError.js +4 -0
  86. package/lib/WebpackOptionsApply.js +60 -40
  87. package/lib/asset/AssetBytesGenerator.js +1 -0
  88. package/lib/asset/AssetGenerator.js +9 -3
  89. package/lib/asset/AssetModulesPlugin.js +33 -2
  90. package/lib/asset/AssetSourceGenerator.js +1 -0
  91. package/lib/asset/RawDataUrlModule.js +4 -0
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +31 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  95. package/lib/cache/PackFileCacheStrategy.js +41 -8
  96. package/lib/cache/getLazyHashedEtag.js +13 -4
  97. package/lib/cache/mergeEtags.js +3 -1
  98. package/lib/cli.js +3 -1
  99. package/lib/config/defaults.js +65 -44
  100. package/lib/config/normalization.js +96 -0
  101. package/lib/container/ContainerEntryModule.js +4 -0
  102. package/lib/container/FallbackModule.js +2 -0
  103. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  104. package/lib/container/RemoteModule.js +19 -0
  105. package/lib/css/CssGenerator.js +31 -4
  106. package/lib/css/CssModulesPlugin.js +26 -30
  107. package/lib/css/CssParser.js +12 -9
  108. package/lib/debug/ProfilingPlugin.js +1 -0
  109. package/lib/dependencies/AMDDefineDependency.js +3 -1
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  111. package/lib/dependencies/AMDPlugin.js +1 -1
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  113. package/lib/dependencies/CachedConstDependency.js +1 -0
  114. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  118. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  120. package/lib/dependencies/ConstDependency.js +1 -0
  121. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  122. package/lib/dependencies/ContextElementDependency.js +1 -0
  123. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  124. package/lib/dependencies/CssIcssExportDependency.js +5 -4
  125. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  126. package/lib/dependencies/CssUrlDependency.js +2 -3
  127. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  128. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  129. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  130. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
  131. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  132. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  133. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  134. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  135. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
  136. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  137. package/lib/dependencies/ImportDependency.js +1 -0
  138. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  139. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  140. package/lib/dependencies/ImportParserPlugin.js +7 -12
  141. package/lib/dependencies/LoaderPlugin.js +3 -0
  142. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +1 -0
  144. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  145. package/lib/dependencies/ProvidedDependency.js +1 -0
  146. package/lib/dependencies/RequireContextPlugin.js +1 -0
  147. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  148. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  149. package/lib/dependencies/WorkerDependency.js +9 -3
  150. package/lib/dependencies/WorkerPlugin.js +1 -0
  151. package/lib/dependencies/getFunctionExpression.js +3 -1
  152. package/lib/errors/BuildCycleError.js +4 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  156. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  157. package/lib/hmr/lazyCompilationBackend.js +3 -2
  158. package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
  159. package/lib/ids/IdHelpers.js +10 -8
  160. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
  161. package/lib/ids/SyncModuleIdsPlugin.js +5 -1
  162. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  163. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  164. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  165. package/lib/javascript/JavascriptParser.js +47 -14
  166. package/lib/json/JsonParser.js +6 -0
  167. package/lib/library/AbstractLibraryPlugin.js +4 -1
  168. package/lib/library/AmdLibraryPlugin.js +2 -1
  169. package/lib/library/AssignLibraryPlugin.js +6 -2
  170. package/lib/library/EnableLibraryPlugin.js +1 -0
  171. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  172. package/lib/library/JsonpLibraryPlugin.js +1 -1
  173. package/lib/library/ModuleLibraryPlugin.js +130 -13
  174. package/lib/library/SystemLibraryPlugin.js +4 -1
  175. package/lib/library/UmdLibraryPlugin.js +4 -3
  176. package/lib/logging/createConsoleLogger.js +3 -0
  177. package/lib/logging/truncateArgs.js +1 -1
  178. package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
  179. package/lib/node/NodeTargetPlugin.js +1 -0
  180. package/lib/node/NodeWatchFileSystem.js +3 -0
  181. package/lib/node/nodeConsole.js +18 -1
  182. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  183. package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
  184. package/lib/optimize/ConcatenatedModule.js +33 -19
  185. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  186. package/lib/optimize/InnerGraph.js +5 -3
  187. package/lib/optimize/InnerGraphPlugin.js +25 -25
  188. package/lib/optimize/MangleExportsPlugin.js +14 -2
  189. package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
  190. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  191. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  192. package/lib/optimize/RealContentHashPlugin.js +35 -27
  193. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  194. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  195. package/lib/optimize/SplitChunksPlugin.js +14 -3
  196. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  197. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  198. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  199. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  200. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  201. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  202. package/lib/rules/RuleSetCompiler.js +2 -0
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  204. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  205. package/lib/runtime/CompatRuntimeModule.js +1 -0
  206. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  207. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  208. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  209. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  210. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  211. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
  212. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  213. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  214. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  215. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  216. package/lib/schemes/HttpUriPlugin.js +27 -7
  217. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  218. package/lib/serialization/BinaryMiddleware.js +4 -0
  219. package/lib/serialization/FileMiddleware.js +9 -4
  220. package/lib/serialization/ObjectMiddleware.js +34 -11
  221. package/lib/serialization/PlainObjectSerializer.js +2 -0
  222. package/lib/sharing/ConsumeSharedModule.js +60 -0
  223. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  224. package/lib/sharing/ProvideSharedModule.js +4 -0
  225. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  226. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  227. package/lib/sharing/utils.js +8 -6
  228. package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
  229. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  230. package/lib/stats/StatsFactory.js +2 -2
  231. package/lib/url/URLParserPlugin.js +4 -3
  232. package/lib/util/AppendOnlyStackedSet.js +57 -0
  233. package/lib/util/Hash.js +1 -0
  234. package/lib/util/IterableHelpers.js +1 -0
  235. package/lib/util/LazyBucketSortedSet.js +1 -0
  236. package/lib/util/LazySet.js +1 -0
  237. package/lib/util/ParallelismFactorCalculator.js +1 -0
  238. package/lib/util/SortableSet.js +1 -0
  239. package/lib/util/StringXor.js +1 -0
  240. package/lib/util/binarySearchBounds.js +15 -8
  241. package/lib/util/chainedImports.js +1 -1
  242. package/lib/util/cleverMerge.js +6 -1
  243. package/lib/util/comparators.js +21 -1
  244. package/lib/util/compileBooleanMatcher.js +3 -3
  245. package/lib/util/concatenate.js +3 -2
  246. package/lib/util/conventions.js +3 -2
  247. package/lib/util/deterministicGrouping.js +13 -1
  248. package/lib/util/extractSourceMap.js +12 -13
  249. package/lib/util/fs.js +15 -19
  250. package/lib/util/hash/BatchedHash.js +3 -0
  251. package/lib/util/hash/BulkUpdateHash.js +7 -1
  252. package/lib/util/hash/hash-digest.js +1 -0
  253. package/lib/util/hash/wasm-hash.js +16 -1
  254. package/lib/util/identifier.js +7 -2
  255. package/lib/util/magicComment.js +1 -1
  256. package/lib/util/propertyName.js +1 -1
  257. package/lib/util/registerExternalSerializer.js +1 -0
  258. package/lib/util/runtime.js +15 -1
  259. package/lib/util/semver.js +1 -0
  260. package/lib/util/serialization.js +2 -2
  261. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
  262. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  263. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  264. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  265. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  266. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  267. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  268. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  269. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  270. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  271. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  272. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  273. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  274. package/lib/webpack.js +13 -3
  275. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  276. package/package.json +20 -28
  277. package/schemas/WebpackOptions.check.js +1 -1
  278. package/schemas/WebpackOptions.json +71 -5
  279. package/types.d.ts +339 -93
@@ -97,6 +97,7 @@ class ContextModuleFactory extends ModuleFactory {
97
97
  ),
98
98
  alternativeRequests
99
99
  });
100
+ /** @type {ResolverFactory} */
100
101
  this.resolverFactory = resolverFactory;
101
102
  }
102
103
 
@@ -110,8 +111,11 @@ class ContextModuleFactory extends ModuleFactory {
110
111
  const dependencies = /** @type {ContextDependency[]} */ (data.dependencies);
111
112
  const resolveOptions = data.resolveOptions;
112
113
  const dependency = dependencies[0];
114
+ /** @type {FileSystemDependencies} */
113
115
  const fileDependencies = new LazySet();
116
+ /** @type {FileSystemDependencies} */
114
117
  const missingDependencies = new LazySet();
118
+ /** @type {FileSystemDependencies} */
115
119
  const contextDependencies = new LazySet();
116
120
  this.hooks.beforeResolve.callAsync(
117
121
  {
@@ -154,6 +158,7 @@ class ContextModuleFactory extends ModuleFactory {
154
158
  const idx = request.lastIndexOf("!");
155
159
  if (idx >= 0) {
156
160
  let loadersRequest = request.slice(0, idx + 1);
161
+ /** @type {number} */
157
162
  let i;
158
163
  for (
159
164
  i = 0;
@@ -165,7 +170,7 @@ class ContextModuleFactory extends ModuleFactory {
165
170
  loadersRequest = loadersRequest
166
171
  .slice(i)
167
172
  .replace(/!+$/, "")
168
- .replace(/!!+/g, "!");
173
+ .replace(/!{2,}/g, "!");
169
174
  loaders = loadersRequest === "" ? [] : loadersRequest.split("!");
170
175
  resource = request.slice(idx + 1);
171
176
  } else {
@@ -439,6 +444,7 @@ class ContextModuleFactory extends ModuleFactory {
439
444
 
440
445
  if (!result) return callback(null, []);
441
446
 
447
+ /** @type {ContextElementDependency[]} */
442
448
  const flattenedResult = [];
443
449
 
444
450
  for (const item of result) {
@@ -466,7 +472,13 @@ class ContextModuleFactory extends ModuleFactory {
466
472
  */
467
473
  const visitResource = (resource, callback) => {
468
474
  if (typeof fs.realpath === "function") {
469
- addDirectoryChecked(resource, resource, new Set(), callback);
475
+ addDirectoryChecked(
476
+ resource,
477
+ resource,
478
+ /** @type {Set<string>} */
479
+ new Set(),
480
+ callback
481
+ );
470
482
  } else {
471
483
  addDirectory(resource, resource, addSubDirectory, callback);
472
484
  }
@@ -138,7 +138,7 @@ function getObjKeys(properties) {
138
138
  /** @typedef {boolean | undefined | null} AsiSafe */
139
139
 
140
140
  /**
141
- * @param {EXPECTED_ANY[] | {[k: string]: EXPECTED_ANY}} obj obj
141
+ * @param {EXPECTED_ANY[] | { [k: string]: EXPECTED_ANY }} obj obj
142
142
  * @param {JavascriptParser} parser Parser
143
143
  * @param {ValueCacheVersions} valueCacheVersions valueCacheVersions
144
144
  * @param {string} key the defined key
@@ -158,6 +158,7 @@ const stringifyObj = (
158
158
  asiSafe,
159
159
  objKeys
160
160
  ) => {
161
+ /** @type {string} */
161
162
  let code;
162
163
  const arr = Array.isArray(obj);
163
164
  if (arr) {
@@ -418,6 +419,7 @@ class DefinePlugin {
418
419
  * @returns {void}
419
420
  */
420
421
  const handler = (parser) => {
422
+ /** @type {Set<string>} */
421
423
  const hooked = new Set();
422
424
  const mainValue =
423
425
  /** @type {ValueCacheVersion} */
@@ -32,6 +32,8 @@ const makeSerializable = require("./util/makeSerializable");
32
32
  /** @typedef {import("./Module").LibIdent} LibIdent */
33
33
  /** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
34
34
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
35
+ /** @typedef {import("./Module").Sources} Sources */
36
+ /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
35
37
  /** @typedef {import("./RequestShortener")} RequestShortener */
36
38
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
37
39
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -76,6 +78,7 @@ class DelegatedModule extends Module {
76
78
  this.delegateData = data;
77
79
 
78
80
  // Build info
81
+ /** @type {undefined | DelegatedSourceDependency} */
79
82
  this.delegatedSourceDependency = undefined;
80
83
  }
81
84
 
@@ -152,6 +155,7 @@ class DelegatedModule extends Module {
152
155
  codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) {
153
156
  const dep = /** @type {DelegatedSourceDependency} */ (this.dependencies[0]);
154
157
  const sourceModule = moduleGraph.getModule(dep);
158
+ /** @type {string} */
155
159
  let str;
156
160
 
157
161
  if (!sourceModule) {
@@ -163,6 +167,7 @@ class DelegatedModule extends Module {
163
167
  module: sourceModule,
164
168
  chunkGraph,
165
169
  request: dep.request,
170
+ /** @type {RuntimeRequirements} */
166
171
  runtimeRequirements: new Set()
167
172
  })})`;
168
173
 
@@ -178,6 +183,7 @@ class DelegatedModule extends Module {
178
183
  str += ";";
179
184
  }
180
185
 
186
+ /** @type {Sources} */
181
187
  const sources = new Map();
182
188
  if (this.useSourceMap || this.useSimpleSourceMap) {
183
189
  sources.set(JAVASCRIPT_TYPE, new OriginalSource(str, this.identifier()));
@@ -9,6 +9,7 @@ const DelegatedModule = require("./DelegatedModule");
9
9
 
10
10
  /** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
11
11
  /** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsContent} DllReferencePluginOptionsContent */
12
+ /** @typedef {import("./DelegatedModule").DelegatedModuleData} DelegatedModuleData */
12
13
  /** @typedef {import("./DelegatedModule").DelegatedModuleSourceRequest} DelegatedModuleSourceRequest */
13
14
  /** @typedef {import("./DelegatedModule").DelegatedModuleType} DelegatedModuleType */
14
15
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
@@ -51,6 +52,7 @@ class DelegatedModuleFactoryPlugin {
51
52
  const { request } = dependency;
52
53
  if (request && request.startsWith(`${scope}/`)) {
53
54
  const innerRequest = `.${request.slice(scope.length)}`;
55
+ /** @type {undefined | DelegatedModuleData} */
54
56
  let resolved;
55
57
  if (innerRequest in this.options.content) {
56
58
  resolved = this.options.content[innerRequest];
package/lib/Dependency.js CHANGED
@@ -48,9 +48,11 @@ const memoize = require("./util/memoize");
48
48
 
49
49
  /** @typedef {SyntheticDependencyLocation | RealDependencyLocation} DependencyLocation */
50
50
 
51
+ /** @typedef {string} ExportInfoName */
52
+
51
53
  /**
52
54
  * @typedef {object} ExportSpec
53
- * @property {string} name the name of the export
55
+ * @property {ExportInfoName} name the name of the export
54
56
  * @property {boolean=} canMangle can the export be renamed (defaults to true)
55
57
  * @property {boolean=} terminalBinding is the export a terminal binding that should be checked for export star conflicts
56
58
  * @property {(string | ExportSpec)[]=} exports nested exports
@@ -113,8 +115,11 @@ class Dependency {
113
115
  this._locSC = 0;
114
116
  this._locEL = 0;
115
117
  this._locEC = 0;
118
+ /** @type {undefined | number} */
116
119
  this._locI = undefined;
120
+ /** @type {undefined | string} */
117
121
  this._locN = undefined;
122
+ /** @type {undefined | DependencyLocation} */
118
123
  this._loc = undefined;
119
124
  }
120
125
 
@@ -10,17 +10,18 @@ const createHash = require("./util/createHash");
10
10
 
11
11
  /** @typedef {import("./Compilation").DependencyConstructor} DependencyConstructor */
12
12
  /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
13
- /** @typedef {typeof import("./util/Hash")} Hash */
13
+ /** @typedef {import("./util/Hash").HashFunction} HashFunction */
14
14
 
15
15
  class DependencyTemplates {
16
16
  /**
17
- * @param {string | Hash} hashFunction the hash function to use
17
+ * @param {HashFunction} hashFunction the hash function to use
18
18
  */
19
19
  constructor(hashFunction = DEFAULTS.HASH_FUNCTION) {
20
20
  /** @type {Map<DependencyConstructor, DependencyTemplate>} */
21
21
  this._map = new Map();
22
22
  /** @type {string} */
23
23
  this._hash = "31d6cfe0d16ae931b73c59d7e0c089c0";
24
+ /** @type {HashFunction} */
24
25
  this._hashFunction = hashFunction;
25
26
  }
26
27
 
package/lib/DllModule.js CHANGED
@@ -25,6 +25,7 @@ const makeSerializable = require("./util/makeSerializable");
25
25
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
26
26
  /** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
27
27
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
28
+ /** @typedef {import("./Module").Sources} Sources */
28
29
  /** @typedef {import("./RequestShortener")} RequestShortener */
29
30
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
30
31
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -93,6 +94,7 @@ class DllModule extends Module {
93
94
  * @returns {CodeGenerationResult} result
94
95
  */
95
96
  codeGeneration(context) {
97
+ /** @type {Sources} */
96
98
  const sources = new Map();
97
99
  sources.set(
98
100
  JAVASCRIPT_TYPE,
@@ -109,6 +109,7 @@ class DllReferencePlugin {
109
109
  "content" in this.options ? this.options.content : undefined;
110
110
  if ("manifest" in this.options) {
111
111
  const manifestParameter = this.options.manifest;
112
+ /** @type {undefined | DllReferencePluginOptionsManifest} */
112
113
  let manifest;
113
114
  if (typeof manifestParameter === "string") {
114
115
  const data =
@@ -25,9 +25,9 @@ const DEFAULT_OPTIONS = {
25
25
  };
26
26
 
27
27
  // Regex for parsing .env files
28
- // ported from https://github.com/motdotla/dotenv/blob/master/lib/main.js#L32
28
+ // ported from https://github.com/motdotla/dotenv/blob/master/lib/main.js#L49
29
29
  const LINE =
30
- /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
30
+ /^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?$/gm;
31
31
 
32
32
  const PLUGIN_NAME = "DotenvPlugin";
33
33
 
@@ -60,9 +60,11 @@ function parse(src) {
60
60
  let lines = src.toString();
61
61
 
62
62
  // Convert line breaks to same format
63
- lines = lines.replace(/\r\n?/gm, "\n");
63
+ lines = lines.replace(/\r\n?/g, "\n");
64
64
 
65
+ /** @type {null | RegExpExecArray} */
65
66
  let match;
67
+
66
68
  while ((match = LINE.exec(lines)) !== null) {
67
69
  const key = match[1];
68
70
 
@@ -112,10 +114,12 @@ function _resolveEscapeSequences(value) {
112
114
  function expandValue(value, processEnv, runningParsed) {
113
115
  const env = { ...runningParsed, ...processEnv }; // process.env wins
114
116
 
115
- const regex = /(?<!\\)\$\{([^{}]+)\}|(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)/g;
117
+ const regex = /(?<!\\)\$\{([^{}]+)\}|(?<!\\)\$([a-z_]\w*)/gi;
116
118
 
117
119
  let result = value;
120
+ /** @type {null | RegExpExecArray} */
118
121
  let match;
122
+ /** @type {Set<string>} */
119
123
  const seen = new Set(); // self-referential checker
120
124
 
121
125
  while ((match = regex.exec(result)) !== null) {
@@ -133,7 +137,9 @@ function expandValue(value, processEnv, runningParsed) {
133
137
  const r = expression.split(/** @type {string} */ (splitter));
134
138
  // const r = splitter ? expression.split(splitter) : [expression];
135
139
 
140
+ /** @type {string} */
136
141
  let defaultValue;
142
+ /** @type {undefined | null | string} */
137
143
  let value;
138
144
 
139
145
  const key = r.shift();
@@ -303,7 +309,7 @@ class DotenvPlugin {
303
309
  * @param {InputFileSystem} fs input file system
304
310
  * @param {string} dir dir to load `.env` files
305
311
  * @param {string} mode mode
306
- * @returns {Promise<{parsed: Env, fileDependencies: string[], missingDependencies: string[]}>} parsed env variables and dependencies
312
+ * @returns {Promise<{ parsed: Env, fileDependencies: string[], missingDependencies: string[] }>} parsed env variables and dependencies
307
313
  */
308
314
  async _getParsed(fs, dir, mode) {
309
315
  /** @type {string[]} */
@@ -44,6 +44,7 @@ class DynamicEntryPlugin {
44
44
  compiler.hooks.make.tapPromise(PLUGIN_NAME, (compilation) =>
45
45
  Promise.resolve(this.entry())
46
46
  .then((entry) => {
47
+ /** @type {Promise<void>[]} */
47
48
  const promises = [];
48
49
  for (const name of Object.keys(entry)) {
49
50
  const desc = entry[name];
@@ -24,6 +24,7 @@ However, your target environment does not appear to support 'async/await'.
24
24
  As a result, the code may not run as expected or may cause runtime errors.`;
25
25
  super(message);
26
26
 
27
+ /** @type {string} */
27
28
  this.name = "EnvironmentNotSupportAsyncWarning";
28
29
  this.module = module;
29
30
  }
@@ -119,6 +119,7 @@ class EvalSourceMapDevToolPlugin {
119
119
  });
120
120
  /** @type {RawSourceMap} */
121
121
  let sourceMap;
122
+ /** @type {string | Buffer} */
122
123
  let content;
123
124
  if (source.sourceAndMap) {
124
125
  const sourceAndMap = source.sourceAndMap(options);
@@ -164,20 +165,23 @@ class EvalSourceMapDevToolPlugin {
164
165
  }
165
166
  );
166
167
  sourceMap.sources = moduleFilenames;
167
- sourceMap.ignoreList = options.ignoreList
168
- ? sourceMap.sources.reduce(
169
- /** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
170
- (acc, sourceName, idx) => {
171
- const rule = /** @type {Rules} */ (options.ignoreList);
172
- if (ModuleFilenameHelpers.matchPart(sourceName, rule)) {
173
- acc.push(idx);
174
- }
175
- return acc;
168
+ if (options.ignoreList) {
169
+ const ignoreList = sourceMap.sources.reduce(
170
+ /** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
171
+ (acc, sourceName, idx) => {
172
+ const rule = /** @type {Rules} */ (options.ignoreList);
173
+ if (ModuleFilenameHelpers.matchPart(sourceName, rule)) {
174
+ acc.push(idx);
176
175
  }
177
- ),
178
- []
179
- )
180
- : [];
176
+ return acc;
177
+ }
178
+ ),
179
+ []
180
+ );
181
+ if (ignoreList.length > 0) {
182
+ sourceMap.ignoreList = ignoreList;
183
+ }
184
+ }
181
185
 
182
186
  if (options.noSources) {
183
187
  sourceMap.sourcesContent = undefined;
@@ -13,6 +13,7 @@ const { forEachRuntime } = require("./util/runtime");
13
13
 
14
14
  /** @typedef {import("./Dependency")} Dependency */
15
15
  /** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
16
+ /** @typedef {import("./Dependency").ExportInfoName} ExportInfoName */
16
17
  /** @typedef {import("./Dependency").ExportsSpecExcludeExports} ExportsSpecExcludeExports */
17
18
  /** @typedef {import("./dependencies/HarmonyImportDependency")} HarmonyImportDependency */
18
19
  /** @typedef {import("./Module")} Module */
@@ -25,8 +26,6 @@ const { forEachRuntime } = require("./util/runtime");
25
26
  /** @typedef {typeof UsageState.OnlyPropertiesUsed | typeof UsageState.NoInfo | typeof UsageState.Unknown | typeof UsageState.Used} RuntimeUsageStateType */
26
27
  /** @typedef {typeof UsageState.Unused | RuntimeUsageStateType} UsageStateType */
27
28
 
28
- /** @typedef {string} ExportInfoName */
29
-
30
29
  /** @typedef {Map<string, RuntimeUsageStateType>} UsedInRuntime */
31
30
  /** @typedef {{ module: Module, export: ExportInfoName[], deferred: boolean }} TargetItemWithoutConnection */
32
31
  /** @typedef {{ module: Module, connection: ModuleGraphConnection, export: ExportInfoName[] | undefined }} TargetItemWithConnection */
@@ -111,8 +110,11 @@ class ExportsInfo {
111
110
  constructor() {
112
111
  /** @type {Exports} */
113
112
  this._exports = new Map();
113
+ /** @type {ExportInfo} */
114
114
  this._otherExportsInfo = new ExportInfo(null);
115
+ /** @type {ExportInfo} */
115
116
  this._sideEffectsOnlyInfo = new ExportInfo("*side effects only*");
117
+ /** @type {boolean} */
116
118
  this._exportsAreOrdered = false;
117
119
  /** @type {ExportsInfo=} */
118
120
  this._redirectTo = undefined;
@@ -613,6 +615,7 @@ class ExportsInfo {
613
615
  * @returns {ExportInfo[]} exports that are relevant (not unused and potential provided)
614
616
  */
615
617
  getRelevantExports(runtime) {
618
+ /** @type {ExportInfo[]} */
616
619
  const list = [];
617
620
  for (const exportInfo of this._exports.values()) {
618
621
  const used = exportInfo.getUsed(runtime);
@@ -655,6 +658,7 @@ class ExportsInfo {
655
658
  * @returns {string} key representing the usage
656
659
  */
657
660
  getUsageKey(runtime) {
661
+ /** @type {(string | number)[]} */
658
662
  const key = [];
659
663
  if (this._redirectTo !== undefined) {
660
664
  key.push(this._redirectTo.getUsageKey(runtime));
@@ -916,7 +920,7 @@ class ExportInfo {
916
920
  /** @type {Target | undefined} */
917
921
  this._target = undefined;
918
922
  if (initFrom && initFrom._target) {
919
- this._target = new Map();
923
+ this._target = /** @type {Target} */ (new Map());
920
924
  for (const [key, value] of initFrom._target) {
921
925
  this._target.set(key, {
922
926
  connection: value.connection,
@@ -1155,7 +1159,7 @@ class ExportInfo {
1155
1159
  setTarget(key, connection, exportName, priority = 0) {
1156
1160
  if (exportName) exportName = [...exportName];
1157
1161
  if (!this._target) {
1158
- this._target = new Map();
1162
+ this._target = /** @type {Target} */ (new Map());
1159
1163
  this._target.set(key, {
1160
1164
  connection,
1161
1165
  export: /** @type {ExportInfoName[]} */ (exportName),
@@ -45,12 +45,15 @@ const { register } = require("./util/serialization");
45
45
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
46
46
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
47
47
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
48
+ /** @typedef {import("./Module").CodeGenerationResultData} CodeGenerationResultData */
48
49
  /** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
49
50
  /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
50
51
  /** @typedef {import("./Module").LibIdent} LibIdent */
51
52
  /** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
52
53
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
54
+ /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
53
55
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
56
+ /** @typedef {import("./Module").Sources} Sources */
54
57
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
55
58
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
56
59
  /** @typedef {import("./RequestShortener")} RequestShortener */
@@ -82,11 +85,15 @@ const { register } = require("./util/serialization");
82
85
 
83
86
  /** @typedef {true | [string, string][]} Imported */
84
87
 
88
+ /** @type {RuntimeRequirements} */
85
89
  const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
90
+ /** @type {RuntimeRequirements} */
86
91
  const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
92
+ /** @type {RuntimeRequirements} */
87
93
  const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
88
94
  RuntimeGlobals.definePropertyGetters
89
95
  ]);
96
+ /** @type {RuntimeRequirements} */
90
97
  const EMPTY_RUNTIME_REQUIREMENTS = new Set();
91
98
 
92
99
  /**
@@ -400,6 +407,7 @@ const generateModuleRemapping = (
400
407
  runtimeTemplate
401
408
  ) => {
402
409
  if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) {
410
+ /** @type {string[]} */
403
411
  const properties = [];
404
412
  for (const exportInfo of exportsInfo.orderedExports) {
405
413
  const used = exportInfo.getUsedName(exportInfo.name, runtime);
@@ -488,6 +496,7 @@ const getSourceForModuleExternal = (
488
496
  let expression = baseAccess;
489
497
 
490
498
  const useNamespace = imported === true;
499
+ /** @type {undefined | string} */
491
500
  let moduleRemapping;
492
501
  if (useNamespace) {
493
502
  moduleRemapping = generateModuleRemapping(
@@ -978,22 +987,27 @@ class ExternalModule extends Module {
978
987
  const { request, externalType } = this._getRequestAndExternalType();
979
988
  switch (externalType) {
980
989
  case "asset": {
990
+ /** @type {Sources} */
981
991
  const sources = new Map();
982
992
  sources.set(
983
993
  JAVASCRIPT_TYPE,
984
994
  new RawSource(`module.exports = ${JSON.stringify(request)};`)
985
995
  );
996
+ /** @type {CodeGenerationResultData} */
986
997
  const data = new Map();
987
998
  data.set("url", { javascript: request });
988
999
  return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
989
1000
  }
990
1001
  case "css-url": {
1002
+ /** @type {Sources} */
991
1003
  const sources = new Map();
1004
+ /** @type {CodeGenerationResultData} */
992
1005
  const data = new Map();
993
1006
  data.set("url", { "css-url": request });
994
1007
  return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
995
1008
  }
996
1009
  case "css-import": {
1010
+ /** @type {Sources} */
997
1011
  const sources = new Map();
998
1012
  const dependencyMeta = /** @type {CssImportDependencyMeta} */ (
999
1013
  this.dependencyMeta
@@ -1056,12 +1070,14 @@ class ExternalModule extends Module {
1056
1070
  sourceString = `${sourceData.init}\n${sourceString}`;
1057
1071
  }
1058
1072
 
1073
+ /** @type {undefined | CodeGenerationResultData} */
1059
1074
  let data;
1060
1075
  if (sourceData.chunkInitFragments) {
1061
1076
  data = new Map();
1062
1077
  data.set("chunkInitFragments", sourceData.chunkInitFragments);
1063
1078
  }
1064
1079
 
1080
+ /** @type {Sources} */
1065
1081
  const sources = new Map();
1066
1082
  if (this.useSourceMap || this.useSimpleSourceMap) {
1067
1083
  sources.set(
@@ -10,6 +10,7 @@ const WebpackError = require("./WebpackError");
10
10
  class FalseIIFEUmdWarning extends WebpackError {
11
11
  constructor() {
12
12
  super();
13
+ /** @type {string} */
13
14
  this.name = "FalseIIFEUmdWarning";
14
15
  this.message =
15
16
  "Configuration:\nSetting 'output.iife' to 'false' is incompatible with 'output.library.type' set to 'umd'. This configuration may cause unexpected behavior, as UMD libraries are expected to use an IIFE (Immediately Invoked Function Expression) to support various module formats. Consider setting 'output.iife' to 'true' or choosing a different 'library.type' to ensure compatibility.\nLearn more: https://webpack.js.org/configuration/output/";