@depup/webpack 5.110.1-depup.0 → 5.111.1-depup.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 (304) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/ChunkGraph.js +20 -18
  8. package/lib/CircularModulesPlugin.js +157 -55
  9. package/lib/CleanPlugin.js +2 -2
  10. package/lib/CompatibilityPlugin.js +3 -4
  11. package/lib/Compilation.js +337 -338
  12. package/lib/Compiler.js +213 -51
  13. package/lib/ConcatenationScope.js +25 -35
  14. package/lib/ConstPlugin.js +16 -132
  15. package/lib/CopyPlugin.js +1054 -0
  16. package/lib/DefinePlugin.js +24 -8
  17. package/lib/DependencyTemplate.js +2 -1
  18. package/lib/DotenvPlugin.js +64 -40
  19. package/lib/ErrorHelpers.js +113 -0
  20. package/lib/ExportsInfo.js +30 -16
  21. package/lib/ExternalModule.js +47 -22
  22. package/lib/FileSystemInfo.js +17 -14
  23. package/lib/FlagDependencyExportsPlugin.js +53 -34
  24. package/lib/FlagDependencyUsagePlugin.js +17 -15
  25. package/lib/Generator.js +24 -2
  26. package/lib/HotModuleReplacementPlugin.js +55 -7
  27. package/lib/IgnorePlugin.js +1 -1
  28. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  29. package/lib/LoaderOptionsPlugin.js +1 -1
  30. package/lib/MainTemplate.js +5 -1
  31. package/lib/Module.js +19 -10
  32. package/lib/ModuleGraph.js +6 -9
  33. package/lib/MultiCompiler.js +7 -17
  34. package/lib/MultiWatching.js +1 -1
  35. package/lib/NormalModule.js +148 -70
  36. package/lib/NormalModuleFactory.js +1 -1
  37. package/lib/RuntimeGlobals.js +21 -7
  38. package/lib/RuntimeModule.js +28 -12
  39. package/lib/RuntimePlugin.js +33 -3
  40. package/lib/RuntimeTemplate.js +1147 -847
  41. package/lib/SourceMapDevToolPlugin.js +54 -104
  42. package/lib/TemplatedPathPlugin.js +16 -59
  43. package/lib/Watching.js +9 -0
  44. package/lib/WebpackOptionsApply.js +84 -91
  45. package/lib/asset/AssetBytesGenerator.js +7 -1
  46. package/lib/asset/AssetGenerator.js +50 -24
  47. package/lib/asset/AssetModule.js +3 -0
  48. package/lib/asset/AssetSourceGenerator.js +7 -1
  49. package/lib/asset/WebManifestParser.js +7 -5
  50. package/lib/async-modules/AsyncModuleHelpers.js +10 -4
  51. package/lib/buildChunkGraph.js +11 -15
  52. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  53. package/lib/cache/IdleFileCachePlugin.js +2 -2
  54. package/lib/cache/MemoryCachePlugin.js +4 -4
  55. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  56. package/lib/cache/PackFileCacheStrategy.js +17 -19
  57. package/lib/cache/getLazyHashedEtag.js +3 -5
  58. package/lib/config/browserslistTargetHandler.js +17 -4
  59. package/lib/config/defaults.js +162 -142
  60. package/lib/config/getClaimedAssetTypes.js +10 -11
  61. package/lib/config/normalization.js +100 -20
  62. package/lib/config/target.js +13 -4
  63. package/lib/container/ContainerReferencePlugin.js +6 -0
  64. package/lib/container/RemoteRuntimeModule.js +9 -0
  65. package/lib/container/declaredRemotes.js +39 -0
  66. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  67. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  68. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  69. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  70. package/lib/css/CssGenerator.js +27 -11
  71. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +92 -15
  73. package/lib/css/CssModule.js +1 -1
  74. package/lib/css/CssModulesPlugin.js +3 -10
  75. package/lib/css/CssParser.js +162 -31
  76. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  77. package/lib/css/cssMinify.js +43 -32
  78. package/lib/css/data.js +3526 -871
  79. package/lib/css/syntax.js +6455 -1237
  80. package/lib/debug/ProfilingPlugin.js +7 -4
  81. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  82. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  83. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  84. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  85. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  86. package/lib/dependencies/CommonJsPlugin.js +19 -3
  87. package/lib/dependencies/CommonJsRequireDependency.js +32 -9
  88. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  89. package/lib/dependencies/ContextDependency.js +1 -1
  90. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  91. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
  92. package/lib/dependencies/ContextElementDependency.js +1 -1
  93. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  94. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  95. package/lib/dependencies/CssUrlDependency.js +3 -5
  96. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  97. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  98. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
  99. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
  100. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  101. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
  102. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  103. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  104. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  105. package/lib/dependencies/HarmonyImportDependency.js +99 -41
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  109. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  110. package/lib/dependencies/HtmlEntryDependency.js +136 -104
  111. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  112. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  113. package/lib/dependencies/ImportContextDependency.js +43 -3
  114. package/lib/dependencies/ImportDependency.js +8 -29
  115. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  116. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  117. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  118. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  119. package/lib/dependencies/ImportParserPlugin.js +25 -15
  120. package/lib/dependencies/LoaderPlugin.js +26 -1
  121. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  122. package/lib/dependencies/RequireHeaderDependency.js +20 -21
  123. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  124. package/lib/dependencies/URLContextDependency.js +1 -1
  125. package/lib/dependencies/URLDependency.js +6 -5
  126. package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
  127. package/lib/dependencies/WorkerDependency.js +12 -18
  128. package/lib/dependencies/WorkletDependency.js +12 -20
  129. package/lib/dependencies/importOptionsCheck.js +47 -0
  130. package/lib/dll/DelegatedModule.js +18 -1
  131. package/lib/dll/DllReferencePlugin.js +11 -8
  132. package/lib/dll/LibManifestPlugin.js +1 -1
  133. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  134. package/lib/errors/DotenvFileError.js +29 -0
  135. package/lib/errors/DuplicateModulesWarning.js +12 -7
  136. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  137. package/lib/errors/ExternalStarReexportError.js +44 -0
  138. package/lib/errors/HookWebpackError.js +3 -2
  139. package/lib/errors/ImportedBindingAssignmentError.js +30 -0
  140. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  141. package/lib/errors/ModuleParseError.js +2 -1
  142. package/lib/errors/UnusedAssetsWarning.js +36 -0
  143. package/lib/errors/UnusedFederationWarning.js +35 -0
  144. package/lib/errors/UnusedModulesWarning.js +38 -0
  145. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  146. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  147. package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
  148. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
  149. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  150. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  151. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  152. package/lib/html/HtmlGenerator.js +72 -87
  153. package/lib/html/HtmlModulesPlugin.js +479 -215
  154. package/lib/html/HtmlParser.js +110 -147
  155. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  156. package/lib/html/data.js +142 -7
  157. package/lib/html/htmlMinify.js +92 -122
  158. package/lib/html/syntax.js +2031 -1556
  159. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  160. package/lib/index.js +49 -3
  161. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  162. package/lib/javascript/JavascriptGenerator.js +8 -1
  163. package/lib/javascript/JavascriptModule.js +1 -0
  164. package/lib/javascript/JavascriptModulesPlugin.js +76 -80
  165. package/lib/javascript/JavascriptParser.js +1970 -900
  166. package/lib/javascript/StartupHelpers.js +27 -3
  167. package/lib/javascript/data.js +172 -0
  168. package/lib/javascript/grammar.js +5546 -0
  169. package/lib/javascript/parser.js +1500 -0
  170. package/lib/javascript/regexp.js +1762 -0
  171. package/lib/javascript/regexpData.js +51 -0
  172. package/lib/javascript/syntax.js +9061 -5262
  173. package/lib/json/JsonGenerator.js +7 -1
  174. package/lib/library/ModuleLibraryPlugin.js +171 -132
  175. package/lib/loaders/LoaderRunner.js +170 -14
  176. package/lib/node/NodeWatchFileSystem.js +3 -9
  177. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  178. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
  179. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  180. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  181. package/lib/optimize/ConcatenatedModule.js +222 -125
  182. package/lib/optimize/ConstExportsPlugin.js +50 -34
  183. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  184. package/lib/optimize/InlineExports.js +20 -2
  185. package/lib/optimize/InnerGraphPlugin.js +7 -13
  186. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  187. package/lib/optimize/MangleExportsPlugin.js +13 -4
  188. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  189. package/lib/optimize/RealContentHashPlugin.js +179 -44
  190. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  191. package/lib/optimize/SplitChunksPlugin.js +2 -4
  192. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  193. package/lib/performance/BroadContextsPlugin.js +1 -1
  194. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  195. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  196. package/lib/performance/EvalUsagePlugin.js +5 -2
  197. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  198. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  199. package/lib/performance/SizeLimitsPlugin.js +2 -4
  200. package/lib/performance/TopLevelThisPlugin.js +5 -4
  201. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  202. package/lib/performance/UnusedFederationPlugin.js +147 -0
  203. package/lib/performance/UnusedModulesPlugin.js +141 -0
  204. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  205. package/lib/performance/isOnlyReexported.js +65 -0
  206. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  207. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  208. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  209. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  210. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  211. package/lib/prefetch/ResourceHintPlugin.js +29 -35
  212. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  213. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  214. package/lib/rules/RuleSetCompiler.js +211 -4
  215. package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
  216. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  217. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  218. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  219. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  220. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  221. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  222. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  223. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  224. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  225. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  226. package/lib/runtime/HelperRuntimeModule.js +10 -0
  227. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
  228. package/lib/runtime/NonceRuntimeModule.js +9 -0
  229. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  230. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  231. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  232. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  233. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  234. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  235. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  236. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  237. package/lib/schemes/DataUriPlugin.js +3 -6
  238. package/lib/schemes/HttpUriPlugin.js +22 -5
  239. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  240. package/lib/serialization/BinaryMiddleware.js +9 -9
  241. package/lib/serialization/FileMiddleware.js +31 -18
  242. package/lib/serialization/ObjectMiddleware.js +168 -139
  243. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  244. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  245. package/lib/sharing/ShareRuntimeModule.js +9 -0
  246. package/lib/sharing/declaredShared.js +47 -0
  247. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  248. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  249. package/lib/typescript/TypeScriptPlugin.js +10 -13
  250. package/lib/url/URLParserPlugin.js +6 -8
  251. package/lib/util/ArrayQueue.js +3 -3
  252. package/lib/util/LocConverter.js +4 -7
  253. package/lib/util/SourceProcessor.js +115 -99
  254. package/lib/util/URLAbsoluteSpecifier.js +3 -1
  255. package/lib/util/async.js +292 -0
  256. package/lib/util/buildDiagnostics.js +69 -0
  257. package/lib/util/chainedImports.js +3 -4
  258. package/lib/util/concatenate.js +4 -4
  259. package/lib/util/conventions.js +5 -1
  260. package/lib/util/createHooksRegistry.js +1 -2
  261. package/lib/util/createMappings.js +25 -3
  262. package/lib/util/dataURL.js +2 -3
  263. package/lib/util/deterministicGrouping.js +8 -13
  264. package/lib/util/findGraphRoots.js +6 -13
  265. package/lib/util/fs.js +27 -1
  266. package/lib/util/globUtils.js +1 -1
  267. package/lib/util/handlerKeys.js +40 -0
  268. package/lib/util/hash/wasm-hash.js +3 -4
  269. package/lib/util/identifier.js +20 -0
  270. package/lib/util/internalSerializables.js +7 -1
  271. package/lib/util/registerExternalSerializer.js +6 -45
  272. package/lib/util/removeBOM.js +82 -1
  273. package/lib/util/semver.js +5 -3
  274. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
  275. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
  276. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  277. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  278. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
  279. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  280. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  281. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  282. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  283. package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
  284. package/lib/web/FetchCompileWasmPlugin.js +4 -2
  285. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  286. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  287. package/package.json +55 -46
  288. package/schemas/WebpackOptions.check.js +1 -1
  289. package/schemas/WebpackOptions.json +388 -76
  290. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  291. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  292. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  293. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  294. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  295. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  296. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  297. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  298. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  299. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  300. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  301. package/types.d.ts +1795 -608
  302. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  303. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  304. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const util = require("util");
9
+ const { fileUrlToPath } = require("../util/identifier");
9
10
 
10
11
  /**
11
12
  * @import {
@@ -138,6 +139,28 @@ const keyedNestedConfig = (value, fn, customKeys) => {
138
139
  return result;
139
140
  };
140
141
 
142
+ /**
143
+ * Converts a file URL to the path it names. Anything that is not a string is
144
+ * returned unchanged, so `false` and `undefined` pass through.
145
+ * @template {string | false | undefined} T
146
+ * @param {T} pathOrUrl an absolute path, a file URL, `false` or `undefined`
147
+ * @returns {T} an absolute path, `false` or `undefined`
148
+ */
149
+ const optionalFileUrlToPath = (pathOrUrl) =>
150
+ typeof pathOrUrl === "string"
151
+ ? /** @type {T} */ (fileUrlToPath(pathOrUrl))
152
+ : pathOrUrl;
153
+
154
+ /**
155
+ * Converts every file URL of a list to the path it names.
156
+ * @param {(string | RegExp)[]} pathsOrUrls absolute paths, file URLs or regular expressions
157
+ * @returns {(string | RegExp)[]} absolute paths and regular expressions
158
+ */
159
+ const fileUrlsToPaths = (pathsOrUrls) =>
160
+ pathsOrUrls.map((pathOrUrl) =>
161
+ typeof pathOrUrl === "string" ? fileUrlToPath(pathOrUrl) : pathOrUrl
162
+ );
163
+
141
164
  /**
142
165
  * Normalize `output.resourceHints` into its object form: the scalar / array /
143
166
  * function shorthand becomes `{ initial: <value> }` (with `"preload"` aliased to
@@ -162,6 +185,40 @@ const normalizeResourceHints = (resourceHints) => {
162
185
  return { initial: alias(resourceHints) };
163
186
  };
164
187
 
188
+ /**
189
+ * @typedef {object} NormalizedBuildDependencyItem
190
+ * @property {string} dependency request to resolve
191
+ * @property {boolean} optional when true the dependency may be missing
192
+ */
193
+
194
+ /**
195
+ * @param {import("../../declarations/WebpackOptions").BuildDependencyItem} item build dependency
196
+ * @returns {NormalizedBuildDependencyItem} normalized build dependency
197
+ */
198
+ const normalizeBuildDependencyItem = (item) => {
199
+ if (typeof item === "string") {
200
+ return { dependency: item, optional: false };
201
+ }
202
+ return {
203
+ dependency: item.dependency,
204
+ optional: item.optional === true
205
+ };
206
+ };
207
+
208
+ /**
209
+ * @param {import("../../declarations/WebpackOptions").FileCacheOptions["buildDependencies"]=} buildDependencies build dependencies
210
+ * @returns {Record<string, NormalizedBuildDependencyItem[]>} normalized build dependencies
211
+ */
212
+ const normalizeBuildDependencies = (buildDependencies) => {
213
+ /** @type {Record<string, NormalizedBuildDependencyItem[]>} */
214
+ const result = Object.create(null);
215
+ if (buildDependencies === undefined) return result;
216
+ for (const key of Object.keys(buildDependencies)) {
217
+ result[key] = buildDependencies[key].map(normalizeBuildDependencyItem);
218
+ }
219
+ return result;
220
+ };
221
+
165
222
  /**
166
223
  * Gets normalized webpack options.
167
224
  * @param {WebpackOptions} config input config
@@ -189,9 +246,11 @@ const getNormalizedWebpackOptions = (config) => ({
189
246
  maxMemoryGenerations: cache.maxMemoryGenerations,
190
247
  maxAge: cache.maxAge,
191
248
  profile: cache.profile,
192
- buildDependencies: cloneObject(cache.buildDependencies),
193
- cacheDirectory: cache.cacheDirectory,
194
- cacheLocation: cache.cacheLocation,
249
+ buildDependencies: normalizeBuildDependencies(
250
+ cache.buildDependencies
251
+ ),
252
+ cacheDirectory: optionalFileUrlToPath(cache.cacheDirectory),
253
+ cacheLocation: optionalFileUrlToPath(cache.cacheLocation),
195
254
  hashAlgorithm: cache.hashAlgorithm,
196
255
  compression: cache.compression,
197
256
  idleTimeout: cache.idleTimeout,
@@ -214,7 +273,7 @@ const getNormalizedWebpackOptions = (config) => ({
214
273
  }
215
274
  })
216
275
  ),
217
- context: config.context,
276
+ context: optionalFileUrlToPath(config.context),
218
277
  dependencies: config.dependencies,
219
278
  devServer: optionalNestedConfig(config.devServer, (devServer) => {
220
279
  if (devServer === false) return false;
@@ -331,7 +390,14 @@ const getNormalizedWebpackOptions = (config) => ({
331
390
  cacheGroups: cloneObject(splitChunks.cacheGroups)
332
391
  }
333
392
  ),
334
- minimize: getNormalizedOptimizationMinimize(optimization.minimize),
393
+ // TODO webpack 6: normalize `minimize` to the per-asset-type object and
394
+ // drop `minimizeOptions` — a breaking change for what plugins read back.
395
+ minimize:
396
+ typeof optimization.minimize === "object" ? true : optimization.minimize,
397
+ minimizeOptions: getNormalizedOptimizationMinimizeOptions(
398
+ optimization.minimize,
399
+ optimization.minimizeOptions
400
+ ),
335
401
  minimizer:
336
402
  optimization.minimizer !== undefined
337
403
  ? /** @type {OptimizationNormalized["minimizer"]} */ (
@@ -374,6 +440,9 @@ const getNormalizedWebpackOptions = (config) => ({
374
440
  cssChunkFilename: output.cssChunkFilename,
375
441
  clean: output.clean,
376
442
  compareBeforeEmit: output.compareBeforeEmit,
443
+ copy: optionalNestedConfig(output.copy, (copy) => ({
444
+ patterns: typeof copy === "string" ? [copy] : [...copy]
445
+ })),
377
446
  crossOriginLoading: output.crossOriginLoading,
378
447
  devtoolFallbackModuleFilenameTemplate:
379
448
  output.devtoolFallbackModuleFilenameTemplate,
@@ -432,7 +501,7 @@ const getNormalizedWebpackOptions = (config) => ({
432
501
  : libraryBase.umdNamedDefine
433
502
  },
434
503
  module: output.module,
435
- path: output.path,
504
+ path: optionalFileUrlToPath(output.path),
436
505
  pathinfo: output.pathinfo,
437
506
  publicPath: output.publicPath,
438
507
  resourceHints: normalizeResourceHints(output.resourceHints),
@@ -474,14 +543,16 @@ const getNormalizedWebpackOptions = (config) => ({
474
543
  nestedArray(config.plugins, (p) => p.filter(Boolean))
475
544
  ),
476
545
  profile: config.profile,
477
- recordsInputPath:
546
+ recordsInputPath: optionalFileUrlToPath(
478
547
  config.recordsInputPath !== undefined
479
548
  ? config.recordsInputPath
480
- : config.recordsPath,
481
- recordsOutputPath:
549
+ : config.recordsPath
550
+ ),
551
+ recordsOutputPath: optionalFileUrlToPath(
482
552
  config.recordsOutputPath !== undefined
483
553
  ? config.recordsOutputPath
484
- : config.recordsPath,
554
+ : config.recordsPath
555
+ ),
485
556
  resolve: nestedConfig(config.resolve, (resolve) => ({
486
557
  ...resolve,
487
558
  byDependency: keyedNestedConfig(resolve.byDependency, cloneObject)
@@ -517,9 +588,15 @@ const getNormalizedWebpackOptions = (config) => ({
517
588
  hash: contextModule.hash
518
589
  })
519
590
  ),
520
- immutablePaths: optionalNestedArray(snapshot.immutablePaths, (p) => [...p]),
521
- managedPaths: optionalNestedArray(snapshot.managedPaths, (p) => [...p]),
522
- unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, (p) => [...p])
591
+ immutablePaths: optionalNestedArray(
592
+ snapshot.immutablePaths,
593
+ fileUrlsToPaths
594
+ ),
595
+ managedPaths: optionalNestedArray(snapshot.managedPaths, fileUrlsToPaths),
596
+ unmanagedPaths: optionalNestedArray(
597
+ snapshot.unmanagedPaths,
598
+ fileUrlsToPaths
599
+ )
523
600
  })),
524
601
  stats: nestedConfig(config.stats, (stats) => {
525
602
  if (stats === false) {
@@ -612,15 +689,18 @@ const getNormalizedEntryStatic = (entry) => {
612
689
  };
613
690
 
614
691
  /**
615
- * Gets normalized optimization minimize: the `true` shorthand becomes an empty
616
- * per-asset-type object, so downstream only sees `false` or the object form.
692
+ * Gets the per-asset-type minimize options. `minimize` itself stays a boolean,
693
+ * and its object form is a shorthand an explicit `minimizeOptions` overrides.
617
694
  * @param {Optimization["minimize"]} minimize minimize option
618
- * @returns {OptimizationNormalized["minimize"]} normalized minimize option
695
+ * @param {Optimization["minimizeOptions"]} minimizeOptions minimizeOptions option
696
+ * @returns {OptimizationNormalized["minimizeOptions"]} normalized minimize options
619
697
  */
620
- const getNormalizedOptimizationMinimize = (minimize) => {
621
- if (minimize === undefined) return;
622
- if (minimize === false) return false;
623
- if (minimize === true) return {};
698
+ const getNormalizedOptimizationMinimizeOptions = (
699
+ minimize,
700
+ minimizeOptions
701
+ ) => {
702
+ if (minimizeOptions !== undefined) return cloneObject(minimizeOptions);
703
+ if (typeof minimize !== "object") return;
624
704
  return cloneObject(minimize);
625
705
  };
626
706
 
@@ -82,6 +82,7 @@ const getDefaultTarget = (context) => {
82
82
  * @property {boolean | null} templateLiteral template literal is available
83
83
  * @property {boolean | null} asyncFunction async functions and await are available
84
84
  * @property {boolean | null} generator generator functions and yield are available
85
+ * @property {boolean | null} topLevelAwait top-level await is available
85
86
  * @property {(boolean | null)=} deferImport deferred evaluation (`import defer`, `import.defer()`) is available (optional; absent means "assume unavailable")
86
87
  * @property {(boolean | null)=} sourceImport source phase imports (`import source`, `import.source()`) are available (optional; absent means "assume unavailable")
87
88
  */
@@ -269,6 +270,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
269
270
  arrowFunction: v(6),
270
271
  asyncFunction: v(7, 6),
271
272
  generator: v(4),
273
+ // v14.8.0
274
+ topLevelAwait: v(14, 8),
272
275
  forOf: v(5),
273
276
  destructuring: v(6),
274
277
  bigIntLiteral: v(10, 4),
@@ -329,6 +332,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
329
332
  templateLiteral: true,
330
333
  asyncFunction: true,
331
334
  generator: true,
335
+ topLevelAwait: true,
332
336
  // import defer - v2.8.0
333
337
  deferImport: v(2, 8),
334
338
  // import source - v2.6.0
@@ -341,10 +345,9 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
341
345
  "Bun in version X.Y. Output is always ECMAScript modules. Examples: bun, bun1.1.",
342
346
  /^bun((\d+)(?:\.(\d+))?)?$/,
343
347
  () => ({
344
- // Bun is a modern, Node.js-compatible runtime; every released version
345
- // supports the full modern ECMAScript feature set, so the version is
346
- // accepted but does not gate any feature. Output is always ESM, so sync
347
- // CommonJS `require` is never available.
348
+ // Every released Bun supports the full modern feature set, so a version is
349
+ // accepted but gates nothing. Output is always ESM, leaving no synchronous
350
+ // CommonJS `require`.
348
351
  node: true,
349
352
  bun: true,
350
353
  web: false,
@@ -380,6 +383,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
380
383
  arrowFunction: true,
381
384
  asyncFunction: true,
382
385
  generator: true,
386
+ topLevelAwait: true,
383
387
  forOf: true,
384
388
  destructuring: true,
385
389
  bigIntLiteral: true,
@@ -437,6 +441,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
437
441
  arrowFunction: v(1, 1),
438
442
  asyncFunction: v(1, 7),
439
443
  generator: v(1, 1),
444
+ // 12.0.0 - Chromium 89
445
+ topLevelAwait: v(12),
440
446
  forOf: v(0, 36),
441
447
  destructuring: v(1, 1),
442
448
  bigIntLiteral: v(4),
@@ -486,6 +492,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
486
492
  arrowFunction: v(0, 15),
487
493
  asyncFunction: v(0, 21),
488
494
  generator: v(0, 15),
495
+ // 0.52.0 - Chromium 89
496
+ topLevelAwait: v(0, 52),
489
497
  forOf: v(0, 13),
490
498
  destructuring: v(0, 15),
491
499
  bigIntLiteral: v(0, 32),
@@ -515,6 +523,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
515
523
  destructuring: v >= 2015,
516
524
  module: v >= 2015,
517
525
  asyncFunction: v >= 2017,
526
+ topLevelAwait: v >= 2022,
518
527
  generator: v >= 2015,
519
528
  globalThis: v >= 2020,
520
529
  symbol: v >= 2015,
@@ -14,6 +14,7 @@ const FallbackModuleFactory = require("./FallbackModuleFactory");
14
14
  const RemoteModule = require("./RemoteModule");
15
15
  const RemoteRuntimeModule = require("./RemoteRuntimeModule");
16
16
  const RemoteToExternalDependency = require("./RemoteToExternalDependency");
17
+ const { addDeclaredRemotes } = require("./declaredRemotes");
17
18
  const { parseOptions } = require("./options");
18
19
 
19
20
  /**
@@ -91,6 +92,11 @@ class ContainerReferencePlugin {
91
92
  compiler.hooks.compilation.tap(
92
93
  PLUGIN_NAME,
93
94
  (compilation, { normalModuleFactory }) => {
95
+ addDeclaredRemotes(
96
+ compilation,
97
+ remotes.map(([key]) => key)
98
+ );
99
+
94
100
  compilation.dependencyFactories.set(
95
101
  RemoteToExternalDependency,
96
102
  normalModuleFactory
@@ -20,6 +20,15 @@ class RemoteRuntimeModule extends RuntimeModule {
20
20
  super("remotes loading");
21
21
  }
22
22
 
23
+ /**
24
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
25
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
26
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
27
+ */
28
+ getInstalledChunkHandlers() {
29
+ return [[RuntimeGlobals.ensureChunkHandlers, "remotes"]];
30
+ }
31
+
23
32
  /**
24
33
  * Generates runtime code for this runtime module.
25
34
  * @returns {string | null} runtime code
@@ -0,0 +1,39 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @import Compilation from "../Compilation" */
9
+
10
+ /** @type {WeakMap<Compilation, Set<string>>} */
11
+ const DECLARED_REMOTES = new WeakMap();
12
+
13
+ /**
14
+ * The remote names this build declared, in declaration order, which is the
15
+ * order `factorize` resolves a request against them in.
16
+ * @param {Compilation} compilation the compilation
17
+ * @returns {Set<string> | undefined} the declared names, when any were declared
18
+ */
19
+ const getDeclaredRemotes = (compilation) => DECLARED_REMOTES.get(compilation);
20
+
21
+ /**
22
+ * Records declared names, adding to any a previous application made.
23
+ * @param {Compilation} compilation the compilation
24
+ * @param {Iterable<string>} names what this application declared
25
+ * @returns {void}
26
+ */
27
+ const addDeclaredRemotes = (compilation, names) => {
28
+ let declared = DECLARED_REMOTES.get(compilation);
29
+
30
+ if (declared === undefined) {
31
+ declared = new Set();
32
+ DECLARED_REMOTES.set(compilation, declared);
33
+ }
34
+
35
+ for (const name of names) declared.add(name);
36
+ };
37
+
38
+ module.exports.addDeclaredRemotes = addDeclaredRemotes;
39
+ module.exports.getDeclaredRemotes = getDeclaredRemotes;
@@ -4,7 +4,7 @@
4
4
 
5
5
  "use strict";
6
6
 
7
- /** @import Compiler from "./Compiler" */
7
+ /** @import Compiler from "../Compiler" */
8
8
 
9
9
  const PLUGIN_NAME = "ContextExclusionPlugin";
10
10
 
@@ -6,49 +6,52 @@
6
6
  "use strict";
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
- const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
10
- const Module = require("./Module");
9
+ const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
+ const Module = require("../Module");
11
11
  const {
12
12
  JAVASCRIPT_TYPE,
13
13
  JAVASCRIPT_TYPES
14
- } = require("./ModuleSourceTypeConstants");
15
- const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
16
- const RuntimeGlobals = require("./RuntimeGlobals");
17
- const Template = require("./Template");
14
+ } = require("../ModuleSourceTypeConstants");
15
+ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("../ModuleTypeConstants");
16
+ const RuntimeGlobals = require("../RuntimeGlobals");
17
+ const Template = require("../Template");
18
18
  const {
19
19
  getOutgoingAsyncModules
20
- } = require("./async-modules/AsyncModuleHelpers");
21
- const { ImportPhase, ImportPhaseUtils } = require("./dependencies/ImportPhase");
22
- const { makeWebpackError } = require("./errors/HookWebpackError");
23
- const WebpackError = require("./errors/WebpackError");
20
+ } = require("../async-modules/AsyncModuleHelpers");
21
+ const {
22
+ ImportPhase,
23
+ ImportPhaseUtils
24
+ } = require("../dependencies/ImportPhase");
25
+ const { makeWebpackError } = require("../errors/HookWebpackError");
26
+ const WebpackError = require("../errors/WebpackError");
24
27
  const {
25
28
  compareLocations,
26
29
  compareModulesById,
27
30
  compareSelect,
28
31
  concatComparators,
29
32
  keepOriginalOrder
30
- } = require("./util/comparators");
33
+ } = require("../util/comparators");
31
34
  const {
32
35
  contextify,
33
36
  makePathsRelative,
34
37
  parseResource
35
- } = require("./util/identifier");
36
- const makeSerializable = require("./util/makeSerializable");
37
- const { propertyAccess } = require("./util/property");
38
+ } = require("../util/identifier");
39
+ const makeSerializable = require("../util/makeSerializable");
40
+ const { propertyAccess } = require("../util/property");
38
41
 
39
42
  /** @import { Source } from "webpack-sources" */
40
- /** @import { ResolveOptions } from "../declarations/WebpackOptions" */
43
+ /** @import { ResolveOptions } from "../../declarations/WebpackOptions" */
41
44
  /**
42
45
  * @import {
43
46
  * WebpackOptionsNormalizedWithDefaults as WebpackOptions
44
- * } from "./config/defaults"
47
+ * } from "../config/defaults"
45
48
  */
46
- /** @import Chunk, { ChunkId, ChunkName } from "./Chunk" */
47
- /** @import ChunkGraph, { ModuleId } from "./ChunkGraph" */
48
- /** @import { RawChunkGroupOptions } from "./ChunkGroup" */
49
- /** @import Compilation, { FileSystemDependencies } from "./Compilation" */
50
- /** @import Dependency, { RawReferencedExports } from "./Dependency" */
51
- /** @import { Snapshot } from "./FileSystemInfo" */
49
+ /** @import Chunk, { ChunkId, ChunkName } from "../Chunk" */
50
+ /** @import ChunkGraph, { ModuleId } from "../ChunkGraph" */
51
+ /** @import { RawChunkGroupOptions } from "../ChunkGroup" */
52
+ /** @import Compilation, { FileSystemDependencies } from "../Compilation" */
53
+ /** @import Dependency, { RawReferencedExports } from "../Dependency" */
54
+ /** @import { Snapshot } from "../FileSystemInfo" */
52
55
  /**
53
56
  * @import {
54
57
  * BuildCallback,
@@ -63,17 +66,17 @@ const { propertyAccess } = require("./util/property");
63
66
  * RuntimeRequirements,
64
67
  * Sources,
65
68
  * SourceTypes
66
- * } from "./Module"
69
+ * } from "../Module"
67
70
  */
68
- /** @import RequestShortener from "./RequestShortener" */
69
- /** @import { ResolverWithOptions } from "./ResolverFactory" */
70
- /** @import RuntimeTemplate from "./RuntimeTemplate" */
71
- /** @import ContextElementDependency from "./dependencies/ContextElementDependency" */
72
- /** @import { ImportAttributes } from "./javascript/JavascriptParser" */
73
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext<[string, boolean]>} ObjectDeserializerContext */
74
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext<[string, boolean]>} ObjectSerializerContext */
75
- /** @import { InputFileSystem } from "./util/fs" */
76
- /** @import { ImportPhaseType } from "./dependencies/ImportPhase" */
71
+ /** @import RequestShortener from "../RequestShortener" */
72
+ /** @import { ResolverWithOptions } from "../ResolverFactory" */
73
+ /** @import RuntimeTemplate from "../RuntimeTemplate" */
74
+ /** @import ContextElementDependency from "../dependencies/ContextElementDependency" */
75
+ /** @import { ImportAttributes } from "../javascript/JavascriptParser" */
76
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[string, boolean]>} ObjectDeserializerContext */
77
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[string, boolean]>} ObjectSerializerContext */
78
+ /** @import { InputFileSystem } from "../util/fs" */
79
+ /** @import { ImportPhaseType } from "../dependencies/ImportPhase" */
77
80
 
78
81
  /** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
79
82
 
@@ -213,6 +216,7 @@ class ContextModule extends Module {
213
216
  * @returns {void}
214
217
  */
215
218
  updateCacheModule(module) {
219
+ super.updateCacheModule(module);
216
220
  const m = /** @type {ContextModule} */ (module);
217
221
  this.resolveDependencies = m.resolveDependencies;
218
222
  this.options = m.options;
@@ -878,7 +882,9 @@ class ContextModule extends Module {
878
882
  }
879
883
  const type =
880
884
  typeof fakeMap === "number" ? fakeMap : fakeMapDataExpression;
881
- return `${asyncDeps} ? ${asyncDeps}.length ? ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(${asyncDeps}).then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, id, ${type} ^ 1, true)) : ${RuntimeGlobals.makeDeferredNamespaceObject}(id, ${type} ^ 1 | 16) : ${source}`;
885
+ // The bound third argument absorbs the promise's resolved value, which
886
+ // would otherwise land in the export-names parameter.
887
+ return `${asyncDeps} ? ${asyncDeps}.length ? ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(${asyncDeps}).then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, id, ${type} ^ 1, undefined)) : ${RuntimeGlobals.makeDeferredNamespaceObject}(id, ${type} ^ 1 | 16) : ${source}`;
882
888
  }
883
889
  return source;
884
890
  }
@@ -1212,60 +1218,11 @@ module.exports = webpackAsyncContext;`;
1212
1218
  }
1213
1219
  const shortMode = hasNoChunk && hasNoModuleDeferred && !hasFakeMap;
1214
1220
  // Sorted before anything is keyed by request, so two items sharing one leave the
1215
- // same last writer in the map and in the loaders beside it.
1221
+ // same last writer in the map.
1216
1222
  const sortedItems = items.sort((a, b) => {
1217
1223
  if (a.userRequest === b.userRequest) return 0;
1218
1224
  return a.userRequest < b.userRequest ? -1 : 1;
1219
1225
  });
1220
- let needEnsureChunk = !hasNoChunk;
1221
- /** @type {Map<string, string[]> | undefined} */
1222
- let loaders;
1223
- // Only module output can name a chunk in an `import()`, so nothing else pays for
1224
- // building the loaders just to throw them away.
1225
- if (!hasNoChunk && runtimeTemplate.isModule()) {
1226
- /** @type {Map<string, string[]>} */
1227
- const perRequest = new Map();
1228
- let hasAnalyzable = false;
1229
- let hasFallback = false;
1230
- /**
1231
- * @param {Chunk} chunk one chunk a request needs
1232
- * @returns {string} a thunk loading it, by literal name where the chunk has one
1233
- */
1234
- const loaderFor = (chunk) => {
1235
- // `.ei` always imports, where `.e` skips a chunk already loaded — the same
1236
- // filter `blockPromise` applies before reaching for it.
1237
- const analyzable =
1238
- chunk.hasRuntime() || chunk.id === null
1239
- ? null
1240
- : runtimeTemplate.analyzableChunkImport(
1241
- chunk,
1242
- "",
1243
- runtimeRequirements,
1244
- this,
1245
- chunkGraph
1246
- );
1247
- if (analyzable !== null) {
1248
- hasAnalyzable = true;
1249
- return runtimeTemplate.returningFunction(analyzable);
1250
- }
1251
- hasFallback = true;
1252
- return runtimeTemplate.returningFunction(
1253
- `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)})`
1254
- );
1255
- };
1256
- for (const item of sortedItems) {
1257
- perRequest.set(
1258
- item.userRequest,
1259
- /** @type {Chunk[]} */ (item.chunks).map(loaderFor)
1260
- );
1261
- }
1262
- // Nothing gained when no chunk can be spelled out, and the plain id map is
1263
- // smaller, so the loaders are only written when at least one names its chunk.
1264
- if (hasAnalyzable) {
1265
- loaders = perRequest;
1266
- needEnsureChunk = hasFallback;
1267
- }
1268
- }
1269
1226
  /** @type {Record<string, ModuleId | (ModuleId | FakeMapType | ChunkId[] | (ModuleId[] | undefined))[]>} */
1270
1227
  const map = Object.create(null);
1271
1228
  for (const item of sortedItems) {
@@ -1299,16 +1256,16 @@ module.exports = webpackAsyncContext;`;
1299
1256
  const asyncDepsPosition = hasNoChunk ? chunksPosition : chunksPosition + 1;
1300
1257
  const requestPrefix = hasNoChunk
1301
1258
  ? "Promise.resolve()"
1302
- : loaders !== undefined
1303
- ? hasMultipleOrNoChunks
1304
- ? `Promise.all(ids[${chunksPosition}].map(${runtimeTemplate.returningFunction("load()", "load")}))`
1305
- : `ids[${chunksPosition}][0]()`
1306
- : hasMultipleOrNoChunks
1307
- ? `Promise.all(ids[${chunksPosition}].map(${RuntimeGlobals.ensureChunk}))`
1308
- : `${RuntimeGlobals.ensureChunk}(ids[${chunksPosition}][0])`;
1309
- // Only the id map reads it; nothing loads a chunk when there is none to load, and
1310
- // a map of loaders spells out every one it could reach for.
1311
- if (needEnsureChunk) {
1259
+ : hasMultipleOrNoChunks
1260
+ ? // Wrapped because `map` hands its callback an index too, which the loader
1261
+ // would otherwise read as a fetch priority.
1262
+ `Promise.all(ids[${chunksPosition}].map(${runtimeTemplate.returningFunction(
1263
+ `${RuntimeGlobals.ensureChunk}(id)`,
1264
+ "id"
1265
+ )}))`
1266
+ : `${RuntimeGlobals.ensureChunk}(ids[${chunksPosition}][0])`;
1267
+ // Nothing loads a chunk when there is none to load.
1268
+ if (!hasNoChunk) {
1312
1269
  runtimeRequirements.add(RuntimeGlobals.ensureChunk);
1313
1270
  }
1314
1271
  const returnModuleObject = this.getReturnModuleObjectSource(
@@ -1352,26 +1309,7 @@ function webpackAsyncContext(req) {
1352
1309
  return ${requestPrefix}.then(${runtimeTemplate.returningFunction(returnModuleObject)});
1353
1310
  }`;
1354
1311
 
1355
- // A loader is source, not data, so the map holding one is written out rather than
1356
- // serialized — one entry per line, keeping the request next to what loads it.
1357
- const mapSource =
1358
- loaders === undefined
1359
- ? JSON.stringify(map, null, "\t")
1360
- : `{\n${Object.keys(map)
1361
- .map((request) => {
1362
- const slots =
1363
- /** @type {(ModuleId | FakeMapType | ChunkId[] | (ModuleId[] | undefined))[]} */
1364
- (map[request]).map((slot, index) =>
1365
- index === chunksPosition
1366
- ? `[${/** @type {string[]} */ (loaders.get(request)).join(", ")}]`
1367
- : // An absent `asyncDeps` slot is `null` to `JSON.stringify`.
1368
- slot === undefined
1369
- ? "null"
1370
- : JSON.stringify(slot)
1371
- );
1372
- return `\t${JSON.stringify(request)}: [${slots.join(", ")}]`;
1373
- })
1374
- .join(",\n")}\n}`;
1312
+ const mapSource = JSON.stringify(map, null, "\t");
1375
1313
 
1376
1314
  return `${cst} map = ${mapSource};
1377
1315
  ${webpackAsyncContext}
@@ -1538,7 +1476,7 @@ module.exports = webpackEmptyAsyncContext;`;
1538
1476
  const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
1539
1477
  const globImportAccess = this.getImportPropertyAccess();
1540
1478
  const sortedDependencies =
1541
- /** @type {import("./dependencies/ContextElementDependency")[]} */
1479
+ /** @type {import("../dependencies/ContextElementDependency")[]} */
1542
1480
  (dependencies).sort((a, b) =>
1543
1481
  a.userRequest < b.userRequest
1544
1482
  ? -1
@@ -1742,6 +1680,7 @@ module.exports = webpackEmptyAsyncContext;`;
1742
1680
  ImportPhaseUtils.isDefer(this.options.phase || ImportPhase.Evaluation)
1743
1681
  ) {
1744
1682
  set.add(RuntimeGlobals.makeDeferredNamespaceObject);
1683
+ set.add(RuntimeGlobals.hasSynthesizedDeferredNamespace);
1745
1684
  }
1746
1685
  }
1747
1686
  return {
@@ -1788,6 +1727,6 @@ module.exports = webpackEmptyAsyncContext;`;
1788
1727
  }
1789
1728
  }
1790
1729
 
1791
- makeSerializable(ContextModule, "webpack/lib/ContextModule");
1730
+ makeSerializable(ContextModule, "webpack/lib/context/ContextModule");
1792
1731
 
1793
1732
  module.exports = ContextModule;