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
@@ -39,6 +39,7 @@ const {
39
39
 
40
40
  /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptionsNormalized */
41
41
  /** @typedef {import("../../declarations/WebpackOptions").Context} Context */
42
+ /** @typedef {import("../../declarations/WebpackOptions").DevTool} Devtool */
42
43
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
43
44
  /** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
44
45
  /** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
@@ -72,6 +73,8 @@ const {
72
73
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
73
74
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
74
75
  /** @typedef {import("../Module")} Module */
76
+ /** @typedef {import("../javascript/EnableChunkLoadingPlugin").ChunkLoadingTypes} ChunkLoadingTypes */
77
+ /** @typedef {import("../wasm/EnableWasmLoadingPlugin").WasmLoadingTypes} WasmLoadingTypes */
75
78
  /** @typedef {import("./target").PlatformTargetProperties} PlatformTargetProperties */
76
79
  /** @typedef {import("./target").TargetProperties} TargetProperties */
77
80
 
@@ -90,14 +93,14 @@ const {
90
93
  * hotUpdateChunkFilename: NonNullable<Output["hotUpdateChunkFilename"]>,
91
94
  * hotUpdateGlobal: NonNullable<Output["hotUpdateGlobal"]>,
92
95
  * assetModuleFilename: NonNullable<Output["assetModuleFilename"]>,
93
- * webassemblyModuleFilename: NonNullable<Output["webassemblyModuleFilename"]>
96
+ * webassemblyModuleFilename: NonNullable<Output["webassemblyModuleFilename"]>,
94
97
  * sourceMapFilename: NonNullable<Output["sourceMapFilename"]>,
95
98
  * hotUpdateMainFilename: NonNullable<Output["hotUpdateMainFilename"]>,
96
99
  * devtoolNamespace: NonNullable<Output["devtoolNamespace"]>,
97
- * publicPath: NonNullable<Output["publicPath"]>
98
- * workerPublicPath: NonNullable<Output["workerPublicPath"]>
99
- * workerWasmLoading: NonNullable<Output["workerWasmLoading"]>
100
- * workerChunkLoading: NonNullable<Output["workerChunkLoading"]>
100
+ * publicPath: NonNullable<Output["publicPath"]>,
101
+ * workerPublicPath: NonNullable<Output["workerPublicPath"]>,
102
+ * workerWasmLoading: NonNullable<Output["workerWasmLoading"]>,
103
+ * workerChunkLoading: NonNullable<Output["workerChunkLoading"]>,
101
104
  * chunkFormat: NonNullable<Output["chunkFormat"]>,
102
105
  * module: NonNullable<Output["module"]>,
103
106
  * asyncChunks: NonNullable<Output["asyncChunks"]>,
@@ -187,31 +190,11 @@ const {
187
190
  */
188
191
 
189
192
  /**
190
- * @typedef {WebpackOptionsNormalized
191
- * & { context: NonNullable<WebpackOptionsNormalized["context"]> }
192
- * & { infrastructureLogging: InfrastructureLoggingNormalizedWithDefaults }
193
- * } WebpackOptionsNormalizedWithBaseDefaults
193
+ * @typedef {WebpackOptionsNormalized & { context: NonNullable<WebpackOptionsNormalized["context"]> } & { infrastructureLogging: InfrastructureLoggingNormalizedWithDefaults }} WebpackOptionsNormalizedWithBaseDefaults
194
194
  */
195
195
 
196
196
  /**
197
- * @typedef {WebpackOptionsNormalizedWithBaseDefaults
198
- * & { target: NonNullable<WebpackOptionsNormalized["target"]> }
199
- * & { output: OutputNormalizedWithDefaults }
200
- * & { optimization: OptimizationNormalizedWithDefaults }
201
- * & { devtool: NonNullable<WebpackOptionsNormalized["devtool"]> }
202
- * & { stats: NonNullable<WebpackOptionsNormalized["stats"]> }
203
- * & { node: NonNullable<WebpackOptionsNormalized["node"]> }
204
- * & { profile: NonNullable<WebpackOptionsNormalized["profile"]> }
205
- * & { parallelism: NonNullable<WebpackOptionsNormalized["parallelism"]> }
206
- * & { snapshot: SnapshotNormalizedWithDefaults }
207
- * & { externalsPresets: ExternalsPresetsNormalizedWithDefaults }
208
- * & { externalsType: NonNullable<WebpackOptionsNormalized["externalsType"]> }
209
- * & { watch: NonNullable<WebpackOptionsNormalized["watch"]> }
210
- * & { performance: NonNullable<WebpackOptionsNormalized["performance"]> }
211
- * & { recordsInputPath: NonNullable<WebpackOptionsNormalized["recordsInputPath"]> }
212
- * & { recordsOutputPath: NonNullable<WebpackOptionsNormalized["recordsOutputPath"]>
213
- * & { dotenv: NonNullable<WebpackOptionsNormalized["dotenv"]> }
214
- * }} WebpackOptionsNormalizedWithDefaults
197
+ * @typedef {WebpackOptionsNormalizedWithBaseDefaults & { target: NonNullable<WebpackOptionsNormalized["target"]> } & { output: OutputNormalizedWithDefaults } & { optimization: OptimizationNormalizedWithDefaults } & { devtool: NonNullable<WebpackOptionsNormalized["devtool"]> } & { stats: NonNullable<WebpackOptionsNormalized["stats"]> } & { node: NonNullable<WebpackOptionsNormalized["node"]> } & { profile: NonNullable<WebpackOptionsNormalized["profile"]> } & { parallelism: NonNullable<WebpackOptionsNormalized["parallelism"]> } & { snapshot: SnapshotNormalizedWithDefaults } & { externalsPresets: ExternalsPresetsNormalizedWithDefaults } & { externalsType: NonNullable<WebpackOptionsNormalized["externalsType"]> } & { watch: NonNullable<WebpackOptionsNormalized["watch"]> } & { performance: NonNullable<WebpackOptionsNormalized["performance"]> } & { recordsInputPath: NonNullable<WebpackOptionsNormalized["recordsInputPath"]> } & { recordsOutputPath: NonNullable<WebpackOptionsNormalized["recordsOutputPath"]> } & { dotenv: NonNullable<WebpackOptionsNormalized["dotenv"]> }} WebpackOptionsNormalizedWithDefaults
215
198
  */
216
199
 
217
200
  /**
@@ -342,7 +325,28 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
342
325
  }
343
326
  }
344
327
 
345
- F(options, "devtool", () => (development ? "eval" : false));
328
+ F(
329
+ options,
330
+ "devtool",
331
+ () =>
332
+ /** @type {Devtool} */ (
333
+ development
334
+ ? [
335
+ options.experiments.css
336
+ ? {
337
+ type: "css",
338
+ use: "source-map"
339
+ }
340
+ : undefined,
341
+ {
342
+ type: "javascript",
343
+ use: "eval"
344
+ }
345
+ ].filter(Boolean)
346
+ : false
347
+ )
348
+ );
349
+
346
350
  D(options, "watch", false);
347
351
  D(options, "profile", false);
348
352
  D(options, "parallelism", 100);
@@ -423,7 +427,10 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
423
427
  isNode: targetProperties && targetProperties.node === true,
424
428
  uniqueName: /** @type {string} */ (options.output.uniqueName),
425
429
  targetProperties,
426
- mode: options.mode
430
+ mode: options.mode,
431
+ outputModule:
432
+ /** @type {NonNullable<WebpackOptionsNormalized["output"]["module"]>} */
433
+ (options.output.module)
427
434
  });
428
435
 
429
436
  applyExternalsPresetsDefaults(options.externalsPresets, {
@@ -715,11 +722,12 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
715
722
  * @param {boolean} options.futureDefaults is future defaults enabled
716
723
  * @param {boolean} options.deferImport is defer import enabled
717
724
  * @param {boolean} options.isNode is node target platform
725
+ * @param {boolean} options.outputModule is output.module enabled
718
726
  * @returns {void}
719
727
  */
720
728
  const applyJavascriptParserOptionsDefaults = (
721
729
  parserOptions,
722
- { futureDefaults, deferImport, isNode }
730
+ { futureDefaults, deferImport, isNode, outputModule }
723
731
  ) => {
724
732
  D(parserOptions, "unknownContextRequest", ".");
725
733
  D(parserOptions, "unknownContextRegExp", false);
@@ -733,7 +741,7 @@ const applyJavascriptParserOptionsDefaults = (
733
741
  D(parserOptions, "wrappedContextRecursive", true);
734
742
  D(parserOptions, "wrappedContextCritical", false);
735
743
  D(parserOptions, "strictThisContextOnImports", false);
736
- D(parserOptions, "importMeta", true);
744
+ D(parserOptions, "importMeta", outputModule ? "preserve-unknown" : true);
737
745
  D(parserOptions, "dynamicImportMode", "lazy");
738
746
  D(parserOptions, "dynamicImportPrefetch", false);
739
747
  D(parserOptions, "dynamicImportPreload", false);
@@ -786,6 +794,7 @@ const applyCssGeneratorOptionsDefaults = (
786
794
  * @param {HashSalt} options.hashSalt hash salt
787
795
  * @param {HashDigest} options.hashDigest hash digest
788
796
  * @param {HashDigestLength} options.hashDigestLength hash digest length
797
+ * @param {boolean} options.outputModule is output.module enabled
789
798
  * @returns {void}
790
799
  */
791
800
  const applyModuleDefaults = (
@@ -803,7 +812,8 @@ const applyModuleDefaults = (
803
812
  uniqueName,
804
813
  targetProperties,
805
814
  mode,
806
- deferImport
815
+ deferImport,
816
+ outputModule
807
817
  }
808
818
  ) => {
809
819
  if (cache) {
@@ -862,7 +872,8 @@ const applyModuleDefaults = (
862
872
  {
863
873
  futureDefaults,
864
874
  deferImport,
865
- isNode
875
+ isNode,
876
+ outputModule
866
877
  }
867
878
  );
868
879
 
@@ -1443,9 +1454,7 @@ const applyOutputDefaults = (
1443
1454
  throw new Error(
1444
1455
  "For the selected environment is no default ESM chunk format available:\n" +
1445
1456
  "ESM exports can be chosen when 'import()' is available.\n" +
1446
- `JSONP Array push can be chosen when 'document' is available.\n${
1447
- helpMessage
1448
- }`
1457
+ `JSONP Array push can be chosen when 'document' is available.\n${helpMessage}`
1449
1458
  );
1450
1459
  } else {
1451
1460
  if (tp.document) return "array-push";
@@ -1460,9 +1469,7 @@ const applyOutputDefaults = (
1460
1469
  : ""
1461
1470
  }\n` +
1462
1471
  "JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.\n" +
1463
- `CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.\n${
1464
- helpMessage
1465
- }`
1472
+ `CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.\n${helpMessage}`
1466
1473
  );
1467
1474
  }
1468
1475
  }
@@ -1588,7 +1595,7 @@ const applyOutputDefaults = (
1588
1595
  "policyName",
1589
1596
  () =>
1590
1597
  /** @type {NonNullable<Output["uniqueName"]>} */
1591
- (output.uniqueName).replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
1598
+ (output.uniqueName).replace(/[^a-z0-9\-#=_/@.%]+/gi, "_") || "webpack"
1592
1599
  );
1593
1600
  D(trustedTypes, "onPolicyCreationFailure", "stop");
1594
1601
  }
@@ -1617,6 +1624,7 @@ const applyOutputDefaults = (
1617
1624
  });
1618
1625
 
1619
1626
  A(output, "enabledChunkLoadingTypes", () => {
1627
+ /** @type {ChunkLoadingTypes} */
1620
1628
  const enabledChunkLoadingTypes = new Set();
1621
1629
  if (output.chunkLoading) {
1622
1630
  enabledChunkLoadingTypes.add(output.chunkLoading);
@@ -1633,6 +1641,7 @@ const applyOutputDefaults = (
1633
1641
  });
1634
1642
 
1635
1643
  A(output, "enabledWasmLoadingTypes", () => {
1644
+ /** @type {WasmLoadingTypes} */
1636
1645
  const enabledWasmLoadingTypes = new Set();
1637
1646
  if (output.wasmLoading) {
1638
1647
  enabledWasmLoadingTypes.add(output.wasmLoading);
@@ -1957,6 +1966,20 @@ const getResolveDefaults = ({
1957
1966
  extensions: [...jsExtensions]
1958
1967
  });
1959
1968
 
1969
+ /** @type {() => ResolveOptions} */
1970
+ const workerDeps = () => {
1971
+ const options = esmDeps();
1972
+
1973
+ const conditionNames = options.conditionNames
1974
+ ? ["worker", ...options.conditionNames]
1975
+ : options.conditionNames;
1976
+ return {
1977
+ ...options,
1978
+ conditionNames,
1979
+ preferRelative: true
1980
+ };
1981
+ };
1982
+
1960
1983
  /** @type {ResolveOptions} */
1961
1984
  const resolveOptions = {
1962
1985
  cache,
@@ -1976,10 +1999,7 @@ const getResolveDefaults = ({
1976
1999
  url: {
1977
2000
  preferRelative: true
1978
2001
  },
1979
- worker: {
1980
- ...esmDeps(),
1981
- preferRelative: true
1982
- },
2002
+ worker: workerDeps(),
1983
2003
  commonjs: cjsDeps(),
1984
2004
  amd: cjsDeps(),
1985
2005
  // for backward-compat: loadModule
@@ -1992,6 +2012,7 @@ const getResolveDefaults = ({
1992
2012
  };
1993
2013
 
1994
2014
  if (css) {
2015
+ /** @type {string[]} */
1995
2016
  const styleConditions = [];
1996
2017
 
1997
2018
  styleConditions.push("webpack");
@@ -24,6 +24,11 @@ const util = require("util");
24
24
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
25
25
  /** @typedef {import("../WebpackError")} WebpackError */
26
26
 
27
+ /**
28
+ * @typedef {object} WebpackOptionsInterception
29
+ * @property {WebpackOptionsNormalized["devtool"]=} devtool
30
+ */
31
+
27
32
  const handledDeprecatedNoEmitOnErrors = util.deprecate(
28
33
  /**
29
34
  * @param {boolean} noEmitOnErrors no emit on errors
@@ -582,4 +587,95 @@ const getNormalizedOptimizationRuntimeChunk = (runtimeChunk) => {
582
587
  };
583
588
  };
584
589
 
590
+ /**
591
+ * @param {WebpackOptionsNormalized} options options to be intercepted
592
+ * @returns {{ options: WebpackOptionsNormalized, interception?: WebpackOptionsInterception }} options and interception
593
+ */
594
+ const applyWebpackOptionsInterception = (options) => {
595
+ // Return origin options when backCompat is disabled
596
+ if (options.experiments.futureDefaults) {
597
+ return {
598
+ options
599
+ };
600
+ }
601
+
602
+ // TODO webpack6 - remove compatibility logic and move `devtools` fully into `devtool` with multi-type support
603
+ let _devtool = options.devtool;
604
+ /** @type {WebpackOptionsNormalized["devtool"]} */
605
+ let cached;
606
+
607
+ const devtoolBackCompat = () => {
608
+ if (Array.isArray(_devtool)) {
609
+ if (cached) return cached;
610
+ // Prefer `all`, then `javascript`, then `css`
611
+ const match = ["all", "javascript", "css"]
612
+ .map((type) =>
613
+ /** @type {Extract<WebpackOptionsNormalized["devtool"], EXPECTED_ANY[]>} */ (
614
+ _devtool
615
+ ).find((item) => item.type === type)
616
+ )
617
+ .find(Boolean);
618
+
619
+ // If `devtool: []` is specified, return `false` here
620
+ return (cached = match ? match.use : false);
621
+ }
622
+ return _devtool;
623
+ };
624
+
625
+ /** @type {ProxyHandler<WebpackOptionsNormalized>} */
626
+ const handler = Object.create(null);
627
+ handler.get = (target, prop, receiver) => {
628
+ if (prop === "devtool") {
629
+ return devtoolBackCompat();
630
+ }
631
+ return Reflect.get(target, prop, receiver);
632
+ };
633
+ handler.set = (target, prop, value, receiver) => {
634
+ if (prop === "devtool") {
635
+ _devtool = value;
636
+ cached = undefined;
637
+ return true;
638
+ }
639
+ return Reflect.set(target, prop, value, receiver);
640
+ };
641
+ handler.deleteProperty = (target, prop) => {
642
+ if (prop === "devtool") {
643
+ _devtool = undefined;
644
+ cached = undefined;
645
+ return true;
646
+ }
647
+ return Reflect.deleteProperty(target, prop);
648
+ };
649
+ handler.defineProperty = (target, prop, descriptor) => {
650
+ if (prop === "devtool") {
651
+ _devtool = descriptor.value;
652
+ cached = undefined;
653
+ return true;
654
+ }
655
+ return Reflect.defineProperty(target, prop, descriptor);
656
+ };
657
+ handler.getOwnPropertyDescriptor = (target, prop) => {
658
+ if (prop === "devtool") {
659
+ return {
660
+ configurable: true,
661
+ enumerable: true,
662
+ value: devtoolBackCompat(),
663
+ writable: true
664
+ };
665
+ }
666
+ return Reflect.getOwnPropertyDescriptor(target, prop);
667
+ };
668
+
669
+ return {
670
+ options: new Proxy(options, handler),
671
+ interception: {
672
+ get devtool() {
673
+ return _devtool;
674
+ }
675
+ }
676
+ };
677
+ };
678
+
679
+ module.exports.applyWebpackOptionsInterception =
680
+ applyWebpackOptionsInterception;
585
681
  module.exports.getNormalizedWebpackOptions = getNormalizedWebpackOptions;
@@ -28,6 +28,7 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
28
28
  /** @typedef {import("../Module").LibIdent} LibIdent */
29
29
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
30
30
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
31
+ /** @typedef {import("../Module").Sources} Sources */
31
32
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
32
33
  /** @typedef {import("../RequestShortener")} RequestShortener */
33
34
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
@@ -147,12 +148,14 @@ class ContainerEntryModule extends Module {
147
148
  * @returns {CodeGenerationResult} result
148
149
  */
149
150
  codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }) {
151
+ /** @type {Sources} */
150
152
  const sources = new Map();
151
153
  const runtimeRequirements = new Set([
152
154
  RuntimeGlobals.definePropertyGetters,
153
155
  RuntimeGlobals.hasOwnProperty,
154
156
  RuntimeGlobals.exports
155
157
  ]);
158
+ /** @type {string[]} */
156
159
  const getters = [];
157
160
 
158
161
  for (const block of this.blocks) {
@@ -167,6 +170,7 @@ class ContainerEntryModule extends Module {
167
170
  };
168
171
  });
169
172
 
173
+ /** @type {string} */
170
174
  let str;
171
175
 
172
176
  if (modules.some((m) => !m.module)) {
@@ -28,6 +28,7 @@ const FallbackItemDependency = require("./FallbackItemDependency");
28
28
  /** @typedef {import("../Module").NameForCondition} NameForCondition */
29
29
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
30
30
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
31
+ /** @typedef {import("../Module").Sources} Sources */
31
32
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
32
33
  /** @typedef {import("../RequestShortener")} RequestShortener */
33
34
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
@@ -158,6 +159,7 @@ class FallbackModule extends Module {
158
159
  ])};`,
159
160
  "module.exports = loop();"
160
161
  ]);
162
+ /** @type {Sources} */
161
163
  const sources = new Map();
162
164
  sources.set(JAVASCRIPT_TYPE, new RawSource(code));
163
165
  return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS };
@@ -34,7 +34,9 @@ class HoistContainerReferences {
34
34
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
35
35
  const hooks =
36
36
  getModuleFederationPlugin().getCompilationHooks(compilation);
37
+ /** @type {Set<Dependency>} */
37
38
  const depsToTrace = new Set();
39
+ /** @type {Set<Dependency>} */
38
40
  const entryExternalsToHoist = new Set();
39
41
  hooks.addContainerEntryDependency.tap(PLUGIN_NAME, (dep) => {
40
42
  depsToTrace.add(dep);
@@ -89,6 +91,7 @@ class HoistContainerReferences {
89
91
  );
90
92
 
91
93
  const containerRuntimes = chunkGraph.getModuleRuntimes(entryModule);
94
+ /** @type {Set<string>} */
92
95
  const runtimes = new Set();
93
96
 
94
97
  for (const runtimeSpec of containerRuntimes) {
@@ -136,6 +139,7 @@ class HoistContainerReferences {
136
139
 
137
140
  const containerRuntimes =
138
141
  chunkGraph.getModuleRuntimes(containerEntryModule);
142
+ /** @type {Set<string>} */
139
143
  const runtimes = new Set();
140
144
 
141
145
  for (const runtimeSpec of containerRuntimes) {
@@ -198,7 +202,9 @@ class HoistContainerReferences {
198
202
  */
199
203
  function getAllReferencedModules(compilation, module, type, includeInitial) {
200
204
  const collectedModules = new Set(includeInitial ? [module] : []);
205
+ /** @type {WeakSet<Module>} */
201
206
  const visitedModules = new WeakSet([module]);
207
+ /** @type {Module[]} */
202
208
  const stack = [module];
203
209
 
204
210
  while (stack.length > 0) {
@@ -18,13 +18,17 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency");
18
18
  /** @typedef {import("../Compilation")} Compilation */
19
19
  /** @typedef {import("../Module").BuildCallback} BuildCallback */
20
20
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
21
+ /** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
21
22
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
22
23
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
23
24
  /** @typedef {import("../Module").LibIdent} LibIdent */
24
25
  /** @typedef {import("../Module").NameForCondition} NameForCondition */
25
26
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
26
27
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
28
+ /** @typedef {import("../Module").Sources} Sources */
27
29
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
30
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
31
+ /** @typedef {import("../Module").ExportsType} ExportsType */
28
32
  /** @typedef {import("../RequestShortener")} RequestShortener */
29
33
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
30
34
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -128,6 +132,19 @@ class RemoteModule extends Module {
128
132
  return REMOTE_AND_SHARE_INIT_TYPES;
129
133
  }
130
134
 
135
+ /**
136
+ * @param {ModuleGraph} moduleGraph the module graph
137
+ * @param {boolean | undefined} strict the importing module is strict
138
+ * @returns {ExportsType} export type
139
+ * "namespace": Exports is already a namespace object. namespace = exports.
140
+ * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
141
+ * "default-only": Provide a namespace object with only default export. namespace = { default: exports }
142
+ * "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
143
+ */
144
+ getExportsType(moduleGraph, strict) {
145
+ return "dynamic";
146
+ }
147
+
131
148
  /**
132
149
  * @returns {NameForCondition | null} absolute path which should be used for condition matching (usually the resource path)
133
150
  */
@@ -142,8 +159,10 @@ class RemoteModule extends Module {
142
159
  codeGeneration({ moduleGraph, chunkGraph }) {
143
160
  const module = moduleGraph.getModule(this.dependencies[0]);
144
161
  const id = module && chunkGraph.getModuleId(module);
162
+ /** @type {Sources} */
145
163
  const sources = new Map();
146
164
  sources.set("remote", new RawSource(""));
165
+ /** @type {CodeGenerationResultData} */
147
166
  const data = new Map();
148
167
  data.set("share-init", [
149
168
  {
@@ -19,6 +19,7 @@ const {
19
19
  const RuntimeGlobals = require("../RuntimeGlobals");
20
20
  const Template = require("../Template");
21
21
  const CssImportDependency = require("../dependencies/CssImportDependency");
22
+ const EntryDependency = require("../dependencies/EntryDependency");
22
23
  const { getUndoPath } = require("../util/identifier");
23
24
  const memoize = require("../util/memoize");
24
25
 
@@ -362,6 +363,7 @@ class CssGenerator extends Generator {
362
363
 
363
364
  if (generateContext.concatenationScope) {
364
365
  const source = new ConcatSource();
366
+ /** @type {Set<string>} */
365
367
  const usedIdentifiers = new Set();
366
368
  const { RESERVED_IDENTIFIER } = getPropertyName();
367
369
 
@@ -413,6 +415,7 @@ class CssGenerator extends Generator {
413
415
  );
414
416
  }
415
417
 
418
+ /** @type {string[]} */
416
419
  const exports = [];
417
420
 
418
421
  for (const [name, v] of cssData.exports) {
@@ -465,13 +468,19 @@ class CssGenerator extends Generator {
465
468
  * @returns {SourceTypes} available types (do not mutate)
466
469
  */
467
470
  getTypes(module) {
468
- if (this._generatesJsOnly(module)) {
469
- return JAVASCRIPT_TYPES;
470
- }
471
+ const exportType = /** @type {BuildMeta} */ (module.buildMeta).exportType;
471
472
  const sourceTypes = new Set();
472
473
  const connections = this._moduleGraph.getIncomingConnections(module);
474
+
475
+ let isEntryModule = false;
473
476
  for (const connection of connections) {
474
- if (connection.dependency instanceof CssImportDependency) {
477
+ if (connection.dependency instanceof EntryDependency) {
478
+ isEntryModule = true;
479
+ }
480
+ if (
481
+ exportType === "link" &&
482
+ connection.dependency instanceof CssImportDependency
483
+ ) {
475
484
  continue;
476
485
  }
477
486
  if (!connection.originModule) {
@@ -479,7 +488,25 @@ class CssGenerator extends Generator {
479
488
  }
480
489
  if (connection.originModule.type.split("/")[0] !== CSS_TYPE) {
481
490
  sourceTypes.add(JAVASCRIPT_TYPE);
491
+ } else {
492
+ const originModule = /** @type {CssModule} */ connection.originModule;
493
+ const originExportType = /** @type {BuildMeta} */ (
494
+ originModule.buildMeta
495
+ ).exportType;
496
+ if (
497
+ /** @type {boolean} */ (
498
+ originExportType && originExportType !== "link"
499
+ )
500
+ ) {
501
+ sourceTypes.add(JAVASCRIPT_TYPE);
502
+ }
503
+ }
504
+ }
505
+ if (this._generatesJsOnly(module)) {
506
+ if (sourceTypes.has(JAVASCRIPT_TYPE) || isEntryModule) {
507
+ return JAVASCRIPT_TYPES;
482
508
  }
509
+ return new Set();
483
510
  }
484
511
  if (sourceTypes.has(JAVASCRIPT_TYPE)) {
485
512
  return JAVASCRIPT_AND_CSS_TYPES;