webpack 5.104.1 → 5.105.1

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 (323) hide show
  1. package/README.md +2 -2
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +85 -15
  4. package/lib/AbstractMethodError.js +1 -0
  5. package/lib/AsyncDependenciesBlock.js +17 -2
  6. package/lib/AsyncDependencyToInitialChunkError.js +3 -0
  7. package/lib/AutomaticPrefetchPlugin.js +1 -1
  8. package/lib/BannerPlugin.js +5 -1
  9. package/lib/CacheFacade.js +2 -2
  10. package/lib/CaseSensitiveModulesWarning.js +1 -0
  11. package/lib/Chunk.js +9 -5
  12. package/lib/ChunkGraph.js +30 -9
  13. package/lib/ChunkGroup.js +6 -3
  14. package/lib/ChunkRenderError.js +9 -2
  15. package/lib/CleanPlugin.js +4 -1
  16. package/lib/CodeGenerationError.js +7 -1
  17. package/lib/CodeGenerationResults.js +10 -3
  18. package/lib/CommentCompilationWarning.js +2 -1
  19. package/lib/Compilation.js +284 -236
  20. package/lib/Compiler.js +4 -3
  21. package/lib/ConcatenationScope.js +2 -1
  22. package/lib/ConcurrentCompilationError.js +3 -3
  23. package/lib/ContextModule.js +248 -111
  24. package/lib/ContextModuleFactory.js +14 -2
  25. package/lib/DefinePlugin.js +15 -8
  26. package/lib/DelegatedModule.js +6 -0
  27. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  28. package/lib/Dependency.js +6 -1
  29. package/lib/DependencyTemplates.js +3 -2
  30. package/lib/DllModule.js +2 -0
  31. package/lib/DllReferencePlugin.js +1 -0
  32. package/lib/DotenvPlugin.js +11 -5
  33. package/lib/DynamicEntryPlugin.js +8 -1
  34. package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
  35. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  36. package/lib/ExportsInfo.js +8 -4
  37. package/lib/ExternalModule.js +16 -0
  38. package/lib/ExternalModuleFactoryPlugin.js +9 -2
  39. package/lib/ExternalsPlugin.js +2 -1
  40. package/lib/FalseIIFEUmdWarning.js +1 -0
  41. package/lib/FileSystemInfo.js +49 -25
  42. package/lib/FlagDependencyExportsPlugin.js +8 -1
  43. package/lib/FlagDependencyUsagePlugin.js +9 -7
  44. package/lib/HarmonyLinkingError.js +1 -0
  45. package/lib/HookWebpackError.js +2 -0
  46. package/lib/HotModuleReplacementPlugin.js +16 -2
  47. package/lib/IgnoreWarningsPlugin.js +5 -2
  48. package/lib/InitFragment.js +1 -0
  49. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  50. package/lib/LibManifestPlugin.js +1 -0
  51. package/lib/ManifestPlugin.js +8 -1
  52. package/lib/Module.js +7 -4
  53. package/lib/ModuleBuildError.js +3 -1
  54. package/lib/ModuleDependencyError.js +1 -0
  55. package/lib/ModuleDependencyWarning.js +1 -0
  56. package/lib/ModuleError.js +4 -1
  57. package/lib/ModuleFilenameHelpers.js +4 -2
  58. package/lib/ModuleGraph.js +3 -0
  59. package/lib/ModuleGraphConnection.js +10 -1
  60. package/lib/ModuleHashingError.js +2 -0
  61. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  62. package/lib/ModuleNotFoundError.js +1 -0
  63. package/lib/ModuleParseError.js +5 -1
  64. package/lib/ModuleProfile.js +1 -1
  65. package/lib/ModuleRestoreError.js +2 -0
  66. package/lib/ModuleSourceTypeConstants.js +1 -11
  67. package/lib/ModuleStoreError.js +2 -0
  68. package/lib/ModuleWarning.js +3 -1
  69. package/lib/MultiCompiler.js +11 -7
  70. package/lib/MultiWatching.js +2 -2
  71. package/lib/NoModeWarning.js +1 -0
  72. package/lib/NodeStuffInWebError.js +1 -0
  73. package/lib/NormalModule.js +28 -5
  74. package/lib/NormalModuleFactory.js +20 -4
  75. package/lib/OptionsApply.js +3 -1
  76. package/lib/ProgressPlugin.js +4 -0
  77. package/lib/RawModule.js +2 -0
  78. package/lib/RuntimeModule.js +10 -0
  79. package/lib/RuntimePlugin.js +7 -9
  80. package/lib/RuntimeTemplate.js +14 -7
  81. package/lib/SourceMapDevToolPlugin.js +30 -23
  82. package/lib/Template.js +10 -5
  83. package/lib/TemplatedPathPlugin.js +4 -2
  84. package/lib/UnhandledSchemeError.js +1 -0
  85. package/lib/UnsupportedFeatureWarning.js +3 -0
  86. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  87. package/lib/WatchIgnorePlugin.js +1 -1
  88. package/lib/Watching.js +5 -0
  89. package/lib/WebpackError.js +4 -0
  90. package/lib/WebpackOptionsApply.js +61 -41
  91. package/lib/asset/AssetBytesGenerator.js +1 -0
  92. package/lib/asset/AssetGenerator.js +18 -3
  93. package/lib/asset/AssetModulesPlugin.js +33 -2
  94. package/lib/asset/AssetParser.js +4 -0
  95. package/lib/asset/AssetSourceGenerator.js +1 -0
  96. package/lib/asset/RawDataUrlModule.js +4 -0
  97. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  98. package/lib/buildChunkGraph.js +31 -2
  99. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  100. package/lib/cache/PackFileCacheStrategy.js +41 -8
  101. package/lib/cache/getLazyHashedEtag.js +13 -4
  102. package/lib/cache/mergeEtags.js +3 -1
  103. package/lib/cli.js +3 -1
  104. package/lib/config/defaults.js +65 -44
  105. package/lib/config/normalization.js +96 -0
  106. package/lib/container/ContainerEntryDependency.js +3 -0
  107. package/lib/container/ContainerEntryModule.js +7 -0
  108. package/lib/container/ContainerExposedDependency.js +1 -0
  109. package/lib/container/FallbackDependency.js +1 -0
  110. package/lib/container/FallbackItemDependency.js +1 -0
  111. package/lib/container/FallbackModule.js +4 -0
  112. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  113. package/lib/container/ModuleFederationPlugin.js +1 -1
  114. package/lib/container/RemoteModule.js +24 -0
  115. package/lib/css/CssGenerator.js +31 -4
  116. package/lib/css/CssModulesPlugin.js +26 -30
  117. package/lib/css/CssParser.js +12 -9
  118. package/lib/debug/ProfilingPlugin.js +1 -0
  119. package/lib/dependencies/AMDDefineDependency.js +3 -1
  120. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  121. package/lib/dependencies/AMDPlugin.js +1 -1
  122. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  123. package/lib/dependencies/CachedConstDependency.js +1 -0
  124. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  125. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  126. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  127. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  128. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  129. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  130. package/lib/dependencies/ConstDependency.js +1 -0
  131. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  132. package/lib/dependencies/ContextElementDependency.js +1 -0
  133. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  134. package/lib/dependencies/CssIcssExportDependency.js +7 -4
  135. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  136. package/lib/dependencies/CssUrlDependency.js +2 -3
  137. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  138. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  139. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  140. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
  141. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  142. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  143. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  144. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  145. package/lib/dependencies/HarmonyImportDependency.js +1 -1
  146. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +269 -5
  147. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  148. package/lib/dependencies/ImportDependency.js +1 -0
  149. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  150. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  151. package/lib/dependencies/ImportParserPlugin.js +7 -12
  152. package/lib/dependencies/LoaderPlugin.js +3 -0
  153. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  154. package/lib/dependencies/ModuleDependency.js +1 -0
  155. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  156. package/lib/dependencies/ProvidedDependency.js +1 -0
  157. package/lib/dependencies/RequireContextPlugin.js +1 -0
  158. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
  159. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  160. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  161. package/lib/dependencies/WorkerDependency.js +9 -3
  162. package/lib/dependencies/WorkerPlugin.js +1 -0
  163. package/lib/dependencies/getFunctionExpression.js +3 -1
  164. package/lib/electron/ElectronTargetPlugin.js +3 -1
  165. package/lib/errors/BuildCycleError.js +4 -1
  166. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  167. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  168. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  169. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  170. package/lib/hmr/lazyCompilationBackend.js +3 -2
  171. package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
  172. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
  173. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
  174. package/lib/ids/HashedModuleIdsPlugin.js +3 -8
  175. package/lib/ids/IdHelpers.js +10 -8
  176. package/lib/ids/NamedChunkIdsPlugin.js +7 -5
  177. package/lib/ids/NamedModuleIdsPlugin.js +1 -0
  178. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  179. package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
  180. package/lib/ids/SyncModuleIdsPlugin.js +30 -20
  181. package/lib/index.js +2 -2
  182. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  183. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  184. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  185. package/lib/javascript/JavascriptParser.js +47 -14
  186. package/lib/json/JsonGenerator.js +1 -0
  187. package/lib/json/JsonParser.js +9 -2
  188. package/lib/library/AbstractLibraryPlugin.js +4 -1
  189. package/lib/library/AmdLibraryPlugin.js +2 -1
  190. package/lib/library/AssignLibraryPlugin.js +6 -2
  191. package/lib/library/EnableLibraryPlugin.js +1 -0
  192. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  193. package/lib/library/JsonpLibraryPlugin.js +1 -1
  194. package/lib/library/ModuleLibraryPlugin.js +130 -13
  195. package/lib/library/SystemLibraryPlugin.js +4 -1
  196. package/lib/library/UmdLibraryPlugin.js +4 -3
  197. package/lib/logging/Logger.js +9 -5
  198. package/lib/logging/createConsoleLogger.js +4 -0
  199. package/lib/logging/truncateArgs.js +1 -1
  200. package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
  201. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  202. package/lib/node/NodeTargetPlugin.js +10 -1
  203. package/lib/node/NodeTemplatePlugin.js +1 -0
  204. package/lib/node/NodeWatchFileSystem.js +6 -0
  205. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
  206. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  207. package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
  208. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
  209. package/lib/node/nodeConsole.js +18 -1
  210. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  211. package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
  212. package/lib/optimize/ConcatenatedModule.js +33 -19
  213. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  214. package/lib/optimize/InnerGraph.js +5 -3
  215. package/lib/optimize/InnerGraphPlugin.js +25 -25
  216. package/lib/optimize/LimitChunkCountPlugin.js +3 -2
  217. package/lib/optimize/MangleExportsPlugin.js +14 -2
  218. package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
  219. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  220. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  221. package/lib/optimize/RealContentHashPlugin.js +37 -27
  222. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  223. package/lib/optimize/RuntimeChunkPlugin.js +3 -5
  224. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  225. package/lib/optimize/SplitChunksPlugin.js +23 -5
  226. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  227. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  228. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  229. package/lib/performance/SizeLimitsPlugin.js +6 -6
  230. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
  231. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
  232. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
  233. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  234. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  235. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  236. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  237. package/lib/rules/RuleSetCompiler.js +6 -0
  238. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  239. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  240. package/lib/runtime/CompatRuntimeModule.js +1 -0
  241. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  242. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
  243. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  244. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  245. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  246. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  247. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
  248. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  249. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  250. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  251. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  252. package/lib/schemes/HttpUriPlugin.js +39 -20
  253. package/lib/schemes/VirtualUrlPlugin.js +28 -2
  254. package/lib/serialization/BinaryMiddleware.js +4 -0
  255. package/lib/serialization/FileMiddleware.js +9 -4
  256. package/lib/serialization/ObjectMiddleware.js +34 -11
  257. package/lib/serialization/PlainObjectSerializer.js +2 -0
  258. package/lib/sharing/ConsumeSharedModule.js +60 -0
  259. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  260. package/lib/sharing/ProvideSharedModule.js +4 -0
  261. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  262. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  263. package/lib/sharing/utils.js +8 -6
  264. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
  265. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  266. package/lib/stats/StatsFactory.js +2 -2
  267. package/lib/url/URLParserPlugin.js +5 -3
  268. package/lib/util/AppendOnlyStackedSet.js +57 -0
  269. package/lib/util/Hash.js +1 -0
  270. package/lib/util/IterableHelpers.js +1 -0
  271. package/lib/util/LazyBucketSortedSet.js +1 -0
  272. package/lib/util/LazySet.js +1 -0
  273. package/lib/util/ParallelismFactorCalculator.js +1 -0
  274. package/lib/util/SortableSet.js +1 -0
  275. package/lib/util/StringXor.js +1 -0
  276. package/lib/util/binarySearchBounds.js +15 -8
  277. package/lib/util/chainedImports.js +1 -1
  278. package/lib/util/cleverMerge.js +6 -1
  279. package/lib/util/comparators.js +21 -1
  280. package/lib/util/compileBooleanMatcher.js +3 -3
  281. package/lib/util/concatenate.js +3 -2
  282. package/lib/util/conventions.js +3 -2
  283. package/lib/util/deterministicGrouping.js +13 -1
  284. package/lib/util/extractSourceMap.js +12 -13
  285. package/lib/util/fs.js +15 -19
  286. package/lib/util/hash/BatchedHash.js +4 -0
  287. package/lib/util/hash/BulkUpdateHash.js +8 -1
  288. package/lib/util/hash/hash-digest.js +1 -0
  289. package/lib/util/hash/wasm-hash.js +18 -2
  290. package/lib/util/identifier.js +7 -2
  291. package/lib/util/magicComment.js +1 -1
  292. package/lib/util/propertyName.js +1 -1
  293. package/lib/util/registerExternalSerializer.js +1 -0
  294. package/lib/util/runtime.js +15 -1
  295. package/lib/util/semver.js +1 -0
  296. package/lib/util/serialization.js +2 -2
  297. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
  298. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  299. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  300. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  301. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  302. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  303. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  304. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  305. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  306. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  307. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  308. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  309. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  310. package/lib/webpack.js +16 -4
  311. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  312. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
  313. package/package.json +33 -36
  314. package/schemas/WebpackOptions.check.js +1 -1
  315. package/schemas/WebpackOptions.json +121 -55
  316. package/schemas/plugins/BannerPlugin.json +2 -2
  317. package/schemas/plugins/IgnorePlugin.json +1 -1
  318. package/schemas/plugins/ManifestPlugin.json +3 -3
  319. package/schemas/plugins/ProgressPlugin.json +1 -1
  320. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  321. package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
  322. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  323. package/types.d.ts +440 -137
@@ -28,6 +28,7 @@ const propertyAccess = require("../util/propertyAccess");
28
28
  const ConstDependency = require("./ConstDependency");
29
29
 
30
30
  /** @typedef {import("estree").MemberExpression} MemberExpression */
31
+ /** @typedef {import("estree").Identifier} Identifier */
31
32
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
32
33
  /** @typedef {import("../Compiler")} Compiler */
33
34
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
@@ -44,18 +45,24 @@ const getCriticalDependencyWarning = memoize(() =>
44
45
 
45
46
  const PLUGIN_NAME = "ImportMetaPlugin";
46
47
 
48
+ /** @type {WeakMap<Compilation, { stringify: string, env: Record<string, string> }>} */
49
+ const compilationMetaEnvMap = new WeakMap();
50
+
47
51
  /**
48
52
  * Collect import.meta.env definitions from DefinePlugin and build JSON string
49
53
  * @param {Compilation} compilation the compilation
50
- * @returns {string} env object as JSON string
54
+ * @returns {{ stringify: string, env: Record<string, string> }} env object as JSON string
51
55
  */
52
56
  const collectImportMetaEnvDefinitions = (compilation) => {
53
- const definePluginHooks = DefinePlugin.getCompilationHooks(compilation);
54
- const definitions = definePluginHooks.definitions.call({});
55
- if (!definitions) {
56
- return "{}";
57
+ const cached = compilationMetaEnvMap.get(compilation);
58
+ if (cached) {
59
+ return cached;
57
60
  }
58
61
 
62
+ const definePluginHooks = DefinePlugin.getCompilationHooks(compilation);
63
+ const definitions = definePluginHooks.definitions.call({});
64
+ /** @type {Record<string, string>} */
65
+ const env = {};
59
66
  /** @type {string[]} */
60
67
  const pairs = [];
61
68
  for (const key of Object.keys(definitions)) {
@@ -63,10 +70,12 @@ const collectImportMetaEnvDefinitions = (compilation) => {
63
70
  const envKey = key.slice("import.meta.env.".length);
64
71
  const value = definitions[key];
65
72
  pairs.push(`${JSON.stringify(envKey)}:${value}`);
73
+ env[envKey] = /** @type {string} */ (value);
66
74
  }
67
75
  }
68
-
69
- return `{${pairs.join(",")}}`;
76
+ const result = { stringify: `{${pairs.join(",")}}`, env };
77
+ compilationMetaEnvMap.set(compilation, result);
78
+ return result;
70
79
  };
71
80
 
72
81
  /**
@@ -148,10 +157,15 @@ class ImportMetaPlugin {
148
157
  * @param {Members} members members
149
158
  * @returns {string} error message
150
159
  */
151
- const importMetaUnknownProperty = (members) =>
152
- `${Template.toNormalComment(
160
+ const importMetaUnknownProperty = (members) => {
161
+ if (importMeta === "preserve-unknown") {
162
+ return `import.meta${propertyAccess(members, 0)}`;
163
+ }
164
+ return `${Template.toNormalComment(
153
165
  `unsupported import.meta.${members.join(".")}`
154
166
  )} undefined${propertyAccess(members, 1)}`;
167
+ };
168
+
155
169
  parser.hooks.typeof
156
170
  .for("import.meta")
157
171
  .tap(
@@ -223,6 +237,9 @@ class ImportMetaPlugin {
223
237
  RuntimeGlobals.module
224
238
  );
225
239
  break;
240
+ case "env":
241
+ str += `env: ${collectImportMetaEnvDefinitions(compilation).stringify},`;
242
+ break;
226
243
  default:
227
244
  str += `[${JSON.stringify(
228
245
  prop.id
@@ -327,12 +344,31 @@ class ImportMetaPlugin {
327
344
  PLUGIN_NAME,
328
345
  toConstantDependency(parser, JSON.stringify("object"))
329
346
  );
347
+ parser.hooks.expressionMemberChain
348
+ .for("import.meta")
349
+ .tap(PLUGIN_NAME, (expr, members) => {
350
+ if (members[0] === "env" && members[1]) {
351
+ const name = members[1];
352
+ const { env } = collectImportMetaEnvDefinitions(compilation);
353
+ if (!Object.prototype.hasOwnProperty.call(env, name)) {
354
+ const dep = new ConstDependency(
355
+ "undefined",
356
+ /** @type {Range} */ (expr.range)
357
+ );
358
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
359
+ parser.state.module.addPresentationalDependency(dep);
360
+ return true;
361
+ }
362
+ }
363
+ });
330
364
  parser.hooks.expression
331
365
  .for("import.meta.env")
332
366
  .tap(PLUGIN_NAME, (expr) => {
333
- const envCode = collectImportMetaEnvDefinitions(compilation);
367
+ const { stringify } =
368
+ collectImportMetaEnvDefinitions(compilation);
369
+
334
370
  const dep = new ConstDependency(
335
- envCode,
371
+ stringify,
336
372
  /** @type {Range} */ (expr.range)
337
373
  );
338
374
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
@@ -355,6 +391,11 @@ class ImportMetaPlugin {
355
391
  parser.hooks.unhandledExpressionMemberChain
356
392
  .for("import.meta")
357
393
  .tap(PLUGIN_NAME, (expr, members) => {
394
+ // unknown import.meta properties should be determined at runtime
395
+ if (importMeta === "preserve-unknown") {
396
+ return true;
397
+ }
398
+
358
399
  // keep import.meta.env unknown property
359
400
  // don't evaluate import.meta.env.UNKNOWN_PROPERTY -> undefined.UNKNOWN_PROPERTY
360
401
  // `dirname` and `filename` logic in NodeStuffPlugin
@@ -373,6 +414,7 @@ class ImportMetaPlugin {
373
414
  parser.state.module.addPresentationalDependency(dep);
374
415
  return true;
375
416
  });
417
+
376
418
  parser.hooks.evaluate
377
419
  .for("MemberExpression")
378
420
  .tap(PLUGIN_NAME, (expression) => {
@@ -17,7 +17,7 @@ const ContextDependencyHelpers = require("./ContextDependencyHelpers");
17
17
  const ImportContextDependency = require("./ImportContextDependency");
18
18
  const ImportDependency = require("./ImportDependency");
19
19
  const ImportEagerDependency = require("./ImportEagerDependency");
20
- const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
20
+ const { createGetImportPhase } = require("./ImportPhase");
21
21
  const ImportWeakDependency = require("./ImportWeakDependency");
22
22
 
23
23
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
@@ -262,11 +262,14 @@ class ImportParserPlugin {
262
262
  parser.hooks.importCall.tap(PLUGIN_NAME, (expr, importThen) => {
263
263
  const param = parser.evaluateExpression(expr.source);
264
264
 
265
+ /** @type {null | string} */
265
266
  let chunkName = null;
266
267
  let mode = /** @type {ContextMode} */ (this.options.dynamicImportMode);
268
+ /** @type {null | RegExp} */
267
269
  let include = null;
270
+ /** @type {null | RegExp} */
268
271
  let exclude = null;
269
- /** @type {RawReferencedExports | null} */
272
+ /** @type {null | RawReferencedExports} */
270
273
  let exports = null;
271
274
  /** @type {RawChunkGroupOptions} */
272
275
  const groupOptions = {};
@@ -557,15 +560,6 @@ class ImportParserPlugin {
557
560
  mode = "async-weak";
558
561
  }
559
562
 
560
- if (ImportPhaseUtils.isDefer(phase)) {
561
- parser.state.module.addWarning(
562
- new UnsupportedFeatureWarning(
563
- "import.defer() is not yet supported for ContextModule (the import path is a dynamic expression).",
564
- /** @type {DependencyLocation} */ (expr.loc)
565
- )
566
- );
567
- }
568
-
569
563
  const dep = ContextDependencyHelpers.create(
570
564
  ImportContextDependency,
571
565
  /** @type {Range} */ (expr.range),
@@ -586,7 +580,8 @@ class ImportParserPlugin {
586
580
  typePrefix: "import()",
587
581
  category: "esm",
588
582
  referencedExports: exports,
589
- attributes: getImportAttributes(expr)
583
+ attributes: getImportAttributes(expr),
584
+ phase
590
585
  },
591
586
  parser
592
587
  );
@@ -10,6 +10,7 @@ const LazySet = require("../util/LazySet");
10
10
  const LoaderDependency = require("./LoaderDependency");
11
11
  const LoaderImportDependency = require("./LoaderImportDependency");
12
12
 
13
+ /** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
13
14
  /** @typedef {import("../Compilation").DependencyConstructor} DependencyConstructor */
14
15
  /** @typedef {import("../Compilation").ExecuteModuleExports} ExecuteModuleExports */
15
16
  /** @typedef {import("../Compilation").ExecuteModuleResult} ExecuteModuleResult */
@@ -116,7 +117,9 @@ class LoaderPlugin {
116
117
  )
117
118
  );
118
119
  }
120
+ /** @type {null | RawSourceMap} */
119
121
  let map;
122
+ /** @type {string | Buffer | undefined} */
120
123
  let source;
121
124
  if (moduleSource.sourceAndMap) {
122
125
  const sourceAndMap = moduleSource.sourceAndMap();
@@ -30,6 +30,7 @@ class ModuleDecoratorDependency extends NullDependency {
30
30
  super();
31
31
  this.decorator = decorator;
32
32
  this.allowExportsAccess = allowExportsAccess;
33
+ /** @type {undefined | string} */
33
34
  this._hashUpdate = undefined;
34
35
  }
35
36
 
@@ -27,6 +27,7 @@ class ModuleDependency extends Dependency {
27
27
  this.sourceOrder = sourceOrder;
28
28
  /** @type {Range | undefined} */
29
29
  this.range = undefined;
30
+ /** @type {undefined | string} */
30
31
  this._context = undefined;
31
32
  }
32
33
 
@@ -0,0 +1,87 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Natsu @xiaoxiaojx
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const InitFragment = require("../InitFragment");
9
+ const makeSerializable = require("../util/makeSerializable");
10
+ const NullDependency = require("./NullDependency");
11
+
12
+ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
+ /** @typedef {import("../Dependency")} Dependency */
14
+ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
17
+ /**
18
+ * A dependency that adds an init fragment to the module
19
+ */
20
+ class ModuleInitFragmentDependency extends NullDependency {
21
+ /**
22
+ * @param {string} initCode the initialization code
23
+ * @param {string[]} runtimeRequirements runtime requirements
24
+ * @param {string=} key unique key to avoid emitting the same initialization code twice
25
+ */
26
+ constructor(initCode, runtimeRequirements, key) {
27
+ super();
28
+ this.initCode = initCode;
29
+ this.runtimeRequirements = runtimeRequirements;
30
+ this.key = key;
31
+ }
32
+
33
+ /**
34
+ * @param {ObjectSerializerContext} context context
35
+ */
36
+ serialize(context) {
37
+ const { write } = context;
38
+ write(this.initCode);
39
+ write(this.runtimeRequirements);
40
+ write(this.key);
41
+ super.serialize(context);
42
+ }
43
+
44
+ /**
45
+ * @param {ObjectDeserializerContext} context context
46
+ */
47
+ deserialize(context) {
48
+ const { read } = context;
49
+ this.initCode = read();
50
+ this.runtimeRequirements = read();
51
+ this.key = read();
52
+ super.deserialize(context);
53
+ }
54
+ }
55
+
56
+ makeSerializable(
57
+ ModuleInitFragmentDependency,
58
+ "webpack/lib/dependencies/ModuleInitFragmentDependency"
59
+ );
60
+
61
+ ModuleInitFragmentDependency.Template = class ModuleInitFragmentDependencyTemplate extends (
62
+ NullDependency.Template
63
+ ) {
64
+ /**
65
+ * @param {Dependency} dependency the dependency for which the template should be applied
66
+ * @param {ReplaceSource} source the current replace source which can be modified
67
+ * @param {DependencyTemplateContext} templateContext the context object
68
+ * @returns {void}
69
+ */
70
+ apply(dependency, source, { initFragments, runtimeRequirements }) {
71
+ const dep = /** @type {ModuleInitFragmentDependency} */ (dependency);
72
+ for (const req of dep.runtimeRequirements) {
73
+ runtimeRequirements.add(req);
74
+ }
75
+ initFragments.push(
76
+ new InitFragment(
77
+ dep.initCode,
78
+ InitFragment.STAGE_CONSTANTS,
79
+ 0,
80
+ dep.key,
81
+ undefined
82
+ )
83
+ );
84
+ }
85
+ };
86
+
87
+ module.exports = ModuleInitFragmentDependency;
@@ -44,6 +44,7 @@ class ProvidedDependency extends ModuleDependency {
44
44
  this.identifier = identifier;
45
45
  this.ids = ids;
46
46
  this.range = range;
47
+ /** @type {undefined | string} */
47
48
  this._hashUpdate = undefined;
48
49
  }
49
50
 
@@ -86,6 +86,7 @@ class RequireContextPlugin {
86
86
  )
87
87
  ).options;
88
88
 
89
+ /** @type {{ context: string, request: string }[]} */
89
90
  let newItems;
90
91
  if (!finalResolveOptions.fullySpecified) {
91
92
  newItems = [];
@@ -13,7 +13,7 @@ const makeSerializable = require("../util/makeSerializable");
13
13
 
14
14
  class RequireEnsureDependenciesBlock extends AsyncDependenciesBlock {
15
15
  /**
16
- * @param {GroupOptions | null} chunkName chunk name
16
+ * @param {GroupOptions | string | null} chunkName chunk name
17
17
  * @param {(DependencyLocation | null)=} loc location info
18
18
  */
19
19
  constructor(chunkName, loc) {
@@ -10,11 +10,14 @@ const RequireEnsureDependency = require("./RequireEnsureDependency");
10
10
  const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
11
11
  const getFunctionExpression = require("./getFunctionExpression");
12
12
 
13
+ /** @typedef {import("estree").Expression} Expression */
14
+ /** @typedef {import("estree").SpreadElement} SpreadElement */
13
15
  /** @typedef {import("../AsyncDependenciesBlock").GroupOptions} GroupOptions */
14
16
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
15
17
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
16
18
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
17
19
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
20
+ /** @typedef {import("./getFunctionExpression").FunctionExpressionResult} FunctionExpressionResult */
18
21
 
19
22
  const PLUGIN_NAME = "RequireEnsureDependenciesBlockParserPlugin";
20
23
 
@@ -27,8 +30,10 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
27
30
  parser.hooks.call.for("require.ensure").tap(PLUGIN_NAME, (expr) => {
28
31
  /** @type {string | GroupOptions | null} */
29
32
  let chunkName = null;
30
- let errorExpressionArg = null;
31
- let errorExpression = null;
33
+ /** @type {undefined | Expression | SpreadElement} */
34
+ let errorExpressionArg;
35
+ /** @type {undefined | FunctionExpressionResult} */
36
+ let errorExpression;
32
37
  switch (expr.arguments.length) {
33
38
  case 4: {
34
39
  const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]);
@@ -24,6 +24,7 @@ class RuntimeRequirementsDependency extends NullDependency {
24
24
  constructor(runtimeRequirements) {
25
25
  super();
26
26
  this.runtimeRequirements = new Set(runtimeRequirements);
27
+ /** @type {undefined | string} */
27
28
  this._hashUpdate = undefined;
28
29
  }
29
30
 
@@ -23,20 +23,26 @@ const ModuleDependency = require("./ModuleDependency");
23
23
  /** @typedef {import("../util/Hash")} Hash */
24
24
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
25
25
 
26
+ /**
27
+ * @typedef {object} WorkerDependencyOptions
28
+ * @property {string=} publicPath public path for the worker
29
+ * @property {boolean=} needNewUrl true when need generate `new URL(...)`, otherwise false
30
+ */
31
+
26
32
  class WorkerDependency extends ModuleDependency {
27
33
  /**
28
34
  * @param {string} request request
29
35
  * @param {Range} range range
30
- * @param {object} workerDependencyOptions options
31
- * @param {string=} workerDependencyOptions.publicPath public path for the worker
32
- * @param {boolean=} workerDependencyOptions.needNewUrl need generate `new URL(...)`
36
+ * @param {WorkerDependencyOptions} workerDependencyOptions options
33
37
  */
34
38
  constructor(request, range, workerDependencyOptions) {
35
39
  super(request);
36
40
  this.range = range;
37
41
  // If options are updated, don't forget to update the hash and serialization functions
42
+ /** @type {WorkerDependencyOptions} */
38
43
  this.options = workerDependencyOptions;
39
44
  /** Cache the hash */
45
+ /** @type {undefined | string} */
40
46
  this._hashUpdate = undefined;
41
47
  }
42
48
 
@@ -387,6 +387,7 @@ class WorkerPlugin {
387
387
 
388
388
  const block = new AsyncDependenciesBlock({
389
389
  name: entryOptions.name,
390
+ circular: false,
390
391
  entryOptions: {
391
392
  chunkLoading: this._chunkLoading,
392
393
  wasmLoading: this._wasmLoading,
@@ -10,9 +10,11 @@
10
10
  /** @typedef {import("estree").FunctionExpression} FunctionExpression */
11
11
  /** @typedef {import("estree").SpreadElement} SpreadElement */
12
12
 
13
+ /** @typedef {{ fn: FunctionExpression | ArrowFunctionExpression, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined }} FunctionExpressionResult */
14
+
13
15
  /**
14
16
  * @param {Expression | SpreadElement} expr expressions
15
- * @returns {{ fn: FunctionExpression | ArrowFunctionExpression, expressions: (Expression | SpreadElement)[], needThis: boolean | undefined } | undefined} function expression with additional information
17
+ * @returns {FunctionExpressionResult | undefined} function expression with additional information
16
18
  */
17
19
  module.exports = (expr) => {
18
20
  // <FunctionExpression>
@@ -8,12 +8,14 @@
8
8
  const ExternalsPlugin = require("../ExternalsPlugin");
9
9
 
10
10
  /** @typedef {import("../Compiler")} Compiler */
11
+ /** @typedef {"main" | "preload" | "renderer"} ElectronContext */
11
12
 
12
13
  class ElectronTargetPlugin {
13
14
  /**
14
- * @param {"main" | "preload" | "renderer"=} context in main, preload or renderer context?
15
+ * @param {ElectronContext=} context in main, preload or renderer context?
15
16
  */
16
17
  constructor(context) {
18
+ /** @type {ElectronContext | undefined} */
17
19
  this._context = context;
18
20
  }
19
21
 
@@ -11,7 +11,7 @@ const WebpackError = require("../WebpackError");
11
11
 
12
12
  class BuildCycleError extends WebpackError {
13
13
  /**
14
- * Creates an instance of ModuleDependencyError.
14
+ * Creates an instance of BuildCycleError.
15
15
  * @param {Module} module the module starting the cycle
16
16
  */
17
17
  constructor(module) {
@@ -19,9 +19,12 @@ class BuildCycleError extends WebpackError {
19
19
  "There is a circular build dependency, which makes it impossible to create this module"
20
20
  );
21
21
 
22
+ /** @type {string} */
22
23
  this.name = "BuildCycleError";
24
+ /** @type {Module} */
23
25
  this.module = module;
24
26
  }
25
27
  }
26
28
 
29
+ /** @type {typeof BuildCycleError} */
27
30
  module.exports = BuildCycleError;
@@ -212,6 +212,7 @@ class ModuleChunkFormatPlugin {
212
212
  )}\n`
213
213
  );
214
214
 
215
+ /** @type {Set<Chunk>} */
215
216
  const loadedChunks = new Set();
216
217
  for (let i = 0; i < entries.length; i++) {
217
218
  const [module, entrypoint] = entries[i];
@@ -225,13 +226,14 @@ class ModuleChunkFormatPlugin {
225
226
  /** @type {Chunk} */ (runtimeChunk),
226
227
  undefined
227
228
  );
229
+ /** @type {Set<Chunk>} */
228
230
  const processChunks = new Set();
229
- for (const _chunk of chunks) {
230
- if (loadedChunks.has(_chunk)) {
231
+ for (const chunk of chunks) {
232
+ if (loadedChunks.has(chunk)) {
231
233
  continue;
232
234
  }
233
- loadedChunks.add(_chunk);
234
- processChunks.add(_chunk);
235
+ loadedChunks.add(chunk);
236
+ processChunks.add(chunk);
235
237
  }
236
238
  const sourceWithDependentChunks = withDependentChunks(
237
239
  processChunks,
@@ -36,6 +36,7 @@ class ModuleChunkLoadingPlugin {
36
36
  : globalChunkLoading;
37
37
  return chunkLoading === "import";
38
38
  };
39
+ /** @type {WeakSet<Chunk>} */
39
40
  const onceForChunkSet = new WeakSet();
40
41
  /**
41
42
  * @param {Chunk} chunk chunk to check
@@ -60,6 +60,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
60
60
  */
61
61
  constructor(runtimeRequirements) {
62
62
  super("import chunk loading", RuntimeModule.STAGE_ATTACH);
63
+ /** @type {ReadOnlyRuntimeRequirements} */
63
64
  this._runtimeRequirements = runtimeRequirements;
64
65
  }
65
66
 
@@ -33,6 +33,8 @@ const { registerNotSerializable } = require("../util/serialization");
33
33
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
34
34
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
35
35
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
36
+ /** @typedef {import("../Module").Sources} Sources */
37
+ /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
36
38
  /** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
37
39
  /** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
38
40
  /** @typedef {import("../RequestShortener")} RequestShortener */
@@ -225,7 +227,9 @@ class LazyCompilationProxyModule extends Module {
225
227
  * @returns {CodeGenerationResult} result
226
228
  */
227
229
  codeGeneration({ runtimeTemplate, chunkGraph, moduleGraph }) {
230
+ /** @type {Sources} */
228
231
  const sources = new Map();
232
+ /** @type {RuntimeRequirements} */
229
233
  const runtimeRequirements = new Set();
230
234
  runtimeRequirements.add(RuntimeGlobals.module);
231
235
  const clientDep = /** @type {CommonJsRequireDependency} */ (
@@ -247,6 +251,7 @@ class LazyCompilationProxyModule extends Module {
247
251
  Boolean(block)
248
252
  )}, module: module, onError: onError });`
249
253
  ]);
254
+ /** @type {string} */
250
255
  let source;
251
256
  if (block) {
252
257
  const dep = block.dependencies[0];
@@ -19,11 +19,12 @@
19
19
  /** @typedef {() => Server} CreateServerFunction */
20
20
 
21
21
  /**
22
- * @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend
22
+ * @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]> }} options additional options for the backend
23
23
  * @returns {BackendHandler} backend
24
24
  */
25
25
  module.exports = (options) => (compiler, callback) => {
26
26
  const logger = compiler.getInfrastructureLogger("LazyCompilationBackend");
27
+ /** @type {Map<string, number>} */
27
28
  const activeModules = new Map();
28
29
  const prefix = "/lazy-compilation-using-";
29
30
 
@@ -152,7 +153,7 @@ module.exports = (options) => (compiler, callback) => {
152
153
  const key = `${encodeURIComponent(
153
154
  originalModule.identifier().replace(/\\/g, "/").replace(/@/g, "_")
154
155
  ).replace(/%(2F|3A|24|26|2B|2C|3B|3D)/g, decodeURIComponent)}`;
155
- const active = activeModules.get(key) > 0;
156
+ const active = /** @type {number} */ (activeModules.get(key)) > 0;
156
157
  return {
157
158
  client: `${options.client}?${encodeURIComponent(urlBase + prefix)}`,
158
159
  data: key,
@@ -13,6 +13,7 @@ const {
13
13
 
14
14
  /** @typedef {import("../Compiler")} Compiler */
15
15
  /** @typedef {import("../Module")} Module */
16
+ /** @typedef {import("../ChunkGraph").ModuleComparator} ModuleComparator */
16
17
 
17
18
  /**
18
19
  * @typedef {object} ChunkModuleIdRangePluginOptions
@@ -29,6 +30,7 @@ class ChunkModuleIdRangePlugin {
29
30
  * @param {ChunkModuleIdRangePluginOptions} options options object
30
31
  */
31
32
  constructor(options) {
33
+ /** @type {ChunkModuleIdRangePluginOptions} */
32
34
  this.options = options;
33
35
  }
34
36
 
@@ -38,26 +40,26 @@ class ChunkModuleIdRangePlugin {
38
40
  * @returns {void}
39
41
  */
40
42
  apply(compiler) {
41
- const options = this.options;
42
43
  compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
43
44
  const moduleGraph = compilation.moduleGraph;
44
45
  compilation.hooks.moduleIds.tap(PLUGIN_NAME, (modules) => {
45
46
  const chunkGraph = compilation.chunkGraph;
46
47
  const chunk = find(
47
48
  compilation.chunks,
48
- (chunk) => chunk.name === options.name
49
+ (chunk) => chunk.name === this.options.name
49
50
  );
50
51
  if (!chunk) {
51
52
  throw new Error(
52
- `${PLUGIN_NAME}: Chunk with name '${options.name}"' was not found`
53
+ `${PLUGIN_NAME}: Chunk with name '${this.options.name}"' was not found`
53
54
  );
54
55
  }
55
56
 
56
57
  /** @type {Module[]} */
57
58
  let chunkModules;
58
- if (options.order) {
59
+ if (this.options.order) {
60
+ /** @type {ModuleComparator} */
59
61
  let cmpFn;
60
- switch (options.order) {
62
+ switch (this.options.order) {
61
63
  case "index":
62
64
  case "preOrderIndex":
63
65
  cmpFn = compareModulesByPreOrderIndexOrIdentifier(moduleGraph);
@@ -76,13 +78,13 @@ class ChunkModuleIdRangePlugin {
76
78
  .sort(compareModulesByPreOrderIndexOrIdentifier(moduleGraph));
77
79
  }
78
80
 
79
- let currentId = options.start || 0;
81
+ let currentId = this.options.start || 0;
80
82
  for (let i = 0; i < chunkModules.length; i++) {
81
83
  const m = chunkModules[i];
82
84
  if (m.needId && chunkGraph.getModuleId(m) === null) {
83
85
  chunkGraph.setModuleId(m, currentId++);
84
86
  }
85
- if (options.end && currentId > options.end) break;
87
+ if (this.options.end && currentId > this.options.end) break;
86
88
  }
87
89
  });
88
90
  });
@@ -27,6 +27,7 @@ class DeterministicChunkIdsPlugin {
27
27
  * @param {DeterministicChunkIdsPluginOptions=} options options
28
28
  */
29
29
  constructor(options = {}) {
30
+ /** @type {DeterministicChunkIdsPluginOptions} */
30
31
  this.options = options;
31
32
  }
32
33
 
@@ -34,6 +34,7 @@ class DeterministicModuleIdsPlugin {
34
34
  * @param {DeterministicModuleIdsPluginOptions=} options options
35
35
  */
36
36
  constructor(options = {}) {
37
+ /** @type {DeterministicModuleIdsPluginOptions} */
37
38
  this.options = options;
38
39
  }
39
40