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
@@ -17,11 +17,12 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
17
17
  * @returns {string} mode
18
18
  */
19
19
  function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
20
- if (exportsType === "namespace") return `/* ${exportsType} */ 0`;
21
- if (exportsType === "default-only") return `/* ${exportsType} */ 1`;
20
+ // number is from createFakeNamespaceObject mode ^ 1
21
+ if (exportsType === "namespace") return `/* ${exportsType} */ 8`;
22
+ if (exportsType === "default-only") return `/* ${exportsType} */ 0`;
22
23
  if (exportsType === "default-with-named") return `/* ${exportsType} */ 2`;
23
- if (exportsType === "dynamic") return `/* ${exportsType} */ 3`;
24
- return "";
24
+ if (exportsType === "dynamic") return `/* ${exportsType} */ 6`;
25
+ throw new Error(`Unknown exports type: ${exportsType}`);
25
26
  }
26
27
 
27
28
  /**
@@ -52,6 +53,7 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
52
53
  */
53
54
  constructor(hasAsyncRuntime) {
54
55
  super("make optimized deferred namespace object");
56
+ /** @type {boolean} */
55
57
  this.hasAsyncRuntime = hasAsyncRuntime;
56
58
  }
57
59
 
@@ -66,10 +68,6 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
66
68
  // Note: must be a function (not arrow), because this is used in body!
67
69
  `${fn} = function(moduleId, mode${hasAsync ? ", asyncDeps" : ""}) {`,
68
70
  Template.indent([
69
- "// mode: 0 => namespace (esm)",
70
- "// mode: 1 => default-only (esm strict cjs)",
71
- "// mode: 2 => default-with-named (esm-cjs compat)",
72
- "// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
73
71
  "var r = this;",
74
72
  hasAsync ? "var isAsync = asyncDeps && asyncDeps.length;" : "",
75
73
  "var obj = {",
@@ -83,7 +81,7 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
83
81
  // if exportsType is "namespace" we can generate the most optimized code,
84
82
  // on the second access, we can avoid trigger the getter.
85
83
  // we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
86
- 'if(mode == 0 || (mode == 3 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
84
+ 'if(mode & 8 || (mode & 4 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
87
85
  "return exports;"
88
86
  ]),
89
87
  "}"
@@ -120,11 +118,6 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
120
118
  ? "init?.();"
121
119
  : "if (init) init();";
122
120
  return `${fn} = ${runtimeTemplate.basicFunction("moduleId, mode", [
123
- "// mode: 0 => namespace (esm)",
124
- "// mode: 1 => default-only (esm strict cjs)",
125
- "// mode: 2 => default-with-named (esm-cjs compat)",
126
- "// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
127
- "",
128
121
  "var cachedModule = __webpack_module_cache__[moduleId];",
129
122
  "if (cachedModule && cachedModule.error === undefined) {",
130
123
  Template.indent([
@@ -132,10 +125,8 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
132
125
  hasAsync
133
126
  ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
134
127
  : "",
135
- "if (mode == 0) return exports;",
136
- `if (mode == 1) return ${RuntimeGlobals.createFakeNamespaceObject}(exports);`,
137
- `if (mode == 2) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 2);`,
138
- `if (mode == 3) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 6);` // 2 | 4
128
+ "if (mode & 8) return exports;",
129
+ `return ${RuntimeGlobals.createFakeNamespaceObject}(exports, mode);`
139
130
  ]),
140
131
  "}",
141
132
  "",
@@ -145,7 +136,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
145
136
  ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in ns) ns = ns[${RuntimeGlobals.asyncModuleExportSymbol}];`
146
137
  : "",
147
138
  "init = null;",
148
- "if (mode == 0 || mode == 3 && ns.__esModule && typeof ns === 'object') {",
139
+ "if (mode & 8 || mode & 4 && ns.__esModule && typeof ns === 'object') {",
149
140
  Template.indent([
150
141
  "delete handler.defineProperty;",
151
142
  "delete handler.deleteProperty;",
@@ -155,17 +146,9 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
155
146
  "delete handler.ownKeys;",
156
147
  "delete handler.getOwnPropertyDescriptor;"
157
148
  ]),
158
- "} else if (mode == 1) {",
159
- Template.indent([
160
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns);`
161
- ]),
162
- "} else if (mode == 2) {",
163
- Template.indent([
164
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, 2);`
165
- ]),
166
- "} else if (mode == 3) {",
149
+ "} else {",
167
150
  Template.indent([
168
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, 6);`
151
+ `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, mode);`
169
152
  ]),
170
153
  "}"
171
154
  ])};`,
@@ -211,14 +194,14 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
211
194
  `getOwnPropertyDescriptor: ${runtimeTemplate.basicFunction("_, name", [
212
195
  "switch (name) {",
213
196
  Template.indent([
214
- 'case "__esModule": return { value: true, configurable: !!mode };',
215
- 'case Symbol.toStringTag: return { value: "Deferred Module", configurable: !!mode };',
197
+ 'case "__esModule": return { value: true, configurable: !(mode & 8) };',
198
+ 'case Symbol.toStringTag: return { value: "Deferred Module", configurable: !(mode & 8) };',
216
199
  'case "then": return undefined;'
217
200
  ]),
218
201
  "}",
219
202
  init,
220
203
  "var desc = Reflect.getOwnPropertyDescriptor(ns, name);",
221
- 'if (mode == 2 && name == "default" && !desc) {',
204
+ 'if (mode & 2 && name == "default" && !desc) {',
222
205
  Template.indent("desc = { value: ns, configurable: true };"),
223
206
  "}",
224
207
  "return desc;"
@@ -16,6 +16,7 @@ class PublicPathRuntimeModule extends RuntimeModule {
16
16
  */
17
17
  constructor(publicPath) {
18
18
  super("publicPath", RuntimeModule.STAGE_BASIC);
19
+ /** @type {PublicPath} */
19
20
  this.publicPath = publicPath;
20
21
  }
21
22
 
@@ -25,7 +25,9 @@ class StartupChunkDependenciesPlugin {
25
25
  * @param {Options} options options
26
26
  */
27
27
  constructor(options) {
28
+ /** @type {ChunkLoadingType} */
28
29
  this.chunkLoading = options.chunkLoading;
30
+ /** @type {boolean} */
29
31
  this.asyncChunkLoading =
30
32
  typeof options.asyncChunkLoading === "boolean"
31
33
  ? options.asyncChunkLoading
@@ -19,6 +19,7 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
19
19
  */
20
20
  constructor(asyncChunkLoading) {
21
21
  super("startup chunk dependencies", RuntimeModule.STAGE_TRIGGER);
22
+ /** @type {boolean} */
22
23
  this.asyncChunkLoading = asyncChunkLoading;
23
24
  }
24
25
 
@@ -15,6 +15,7 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
15
15
  */
16
16
  constructor(asyncChunkLoading) {
17
17
  super("startup entrypoint");
18
+ /** @type {boolean} */
18
19
  this.asyncChunkLoading = asyncChunkLoading;
19
20
  }
20
21
 
@@ -36,12 +36,20 @@ const getHttps = memoize(() => require("https"));
36
36
 
37
37
  const MAX_REDIRECTS = 5;
38
38
 
39
+ /** @typedef {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} Fetch */
40
+
41
+ /**
42
+ * @typedef {object} EventsMap
43
+ * @property {[Error]} error
44
+ */
45
+
39
46
  /**
40
47
  * @param {typeof import("http") | typeof import("https")} request request
41
48
  * @param {string | URL | undefined} proxy proxy
42
- * @returns {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} fn
49
+ * @returns {Fetch} fn
43
50
  */
44
51
  const proxyFetch = (request, proxy) => (url, options, callback) => {
52
+ /** @type {EventEmitter<EventsMap>} */
45
53
  const eventEmitter = new EventEmitter();
46
54
 
47
55
  /**
@@ -104,9 +112,7 @@ const validate = createSchemaValidation(
104
112
  * @returns {string} safe path
105
113
  */
106
114
  const toSafePath = (str) =>
107
- str
108
- .replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, "")
109
- .replace(/[^a-zA-Z0-9._-]+/g, "_");
115
+ str.replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi, "").replace(/[^a-z0-9._-]+/gi, "_");
110
116
 
111
117
  /**
112
118
  * @param {Buffer} content content
@@ -454,6 +460,9 @@ class HttpUriPlugin {
454
460
  apply(compiler) {
455
461
  const proxy =
456
462
  this._proxy || process.env.http_proxy || process.env.HTTP_PROXY;
463
+ /**
464
+ * @type {{ scheme: "http" | "https", fetch: Fetch }[]}
465
+ */
457
466
  const schemes = [
458
467
  {
459
468
  scheme: "http",
@@ -660,6 +669,7 @@ class HttpUriPlugin {
660
669
  * @returns {string} absolute, validated redirect target
661
670
  */
662
671
  const validateRedirectLocation = (location, base) => {
672
+ /** @type {URL} */
663
673
  let nextUrl;
664
674
  try {
665
675
  nextUrl = new URL(location, base);
@@ -707,6 +717,7 @@ class HttpUriPlugin {
707
717
 
708
718
  if ("location" in result) {
709
719
  // Validate redirect target before following
720
+ /** @type {string} */
710
721
  let absolute;
711
722
  try {
712
723
  absolute = validateRedirectLocation(result.location, url);
@@ -845,6 +856,7 @@ class HttpUriPlugin {
845
856
  res.statusCode >= 301 &&
846
857
  res.statusCode <= 308
847
858
  ) {
859
+ /** @type {string} */
848
860
  let absolute;
849
861
  try {
850
862
  absolute = validateRedirectLocation(location, url);
@@ -891,9 +903,15 @@ class HttpUriPlugin {
891
903
  stream = stream.pipe(createInflate());
892
904
  }
893
905
 
894
- stream.on("data", (chunk) => {
895
- bufferArr.push(chunk);
896
- });
906
+ stream.on(
907
+ "data",
908
+ /**
909
+ * @param {Buffer} chunk chunk
910
+ */
911
+ (chunk) => {
912
+ bufferArr.push(chunk);
913
+ }
914
+ );
897
915
 
898
916
  stream.on("end", () => {
899
917
  if (!res.complete) {
@@ -953,6 +971,7 @@ class HttpUriPlugin {
953
971
  * @returns {boolean} true when allowed, otherwise false
954
972
  */
955
973
  const isAllowed = (uri) => {
974
+ /** @type {URL} */
956
975
  let parsedUri;
957
976
  try {
958
977
  // Parse the URI to prevent userinfo bypass attacks
@@ -963,6 +982,7 @@ class HttpUriPlugin {
963
982
  }
964
983
  for (const allowed of allowedUris) {
965
984
  if (typeof allowed === "string") {
985
+ /** @type {URL} */
966
986
  let parsedAllowed;
967
987
  try {
968
988
  parsedAllowed = new URL(allowed);
@@ -58,17 +58,19 @@ function normalizeModule(virtualConfig) {
58
58
  return virtualConfig;
59
59
  }
60
60
 
61
+ /** @typedef {{ [key: string]: VirtualModuleConfig }} NormalizedModules */
62
+
61
63
  /**
62
64
  * Normalizes all virtual modules with the given scheme
63
65
  * @param {VirtualModules} virtualConfigs The virtual modules to normalize
64
66
  * @param {string} scheme The URL scheme to use
65
- * @returns {{ [key: string]: VirtualModuleConfig }} The normalized virtual modules
67
+ * @returns {NormalizedModules} The normalized virtual modules
66
68
  */
67
69
  function normalizeModules(virtualConfigs, scheme) {
68
70
  return Object.keys(virtualConfigs).reduce((pre, id) => {
69
71
  pre[toVid(id, scheme)] = normalizeModule(virtualConfigs[id]);
70
72
  return pre;
71
- }, /** @type {{ [key: string]: VirtualModuleConfig }} */ ({}));
73
+ }, /** @type {NormalizedModules} */ ({}));
72
74
  }
73
75
 
74
76
  /**
@@ -105,7 +107,9 @@ class VirtualUrlPlugin {
105
107
  * @param {string=} scheme The URL scheme to use
106
108
  */
107
109
  constructor(modules, scheme) {
110
+ /** @type {string} */
108
111
  this.scheme = scheme || DEFAULT_SCHEME;
112
+ /** @type {NormalizedModules} */
109
113
  this.modules = normalizeModules(modules, this.scheme);
110
114
  }
111
115
 
@@ -135,6 +139,7 @@ class VirtualUrlPlugin {
135
139
  const type = virtualConfig.type;
136
140
  resourceData.path = path + type;
137
141
  resourceData.resource = path;
142
+ resourceData.context = compiler.context;
138
143
 
139
144
  if (virtualConfig.version) {
140
145
  const cacheKey = toCacheKey(resourceData.resource, scheme);
@@ -313,6 +313,7 @@ class BinaryMiddleware extends SerializerMiddleware {
313
313
  /** @type {number[]} */
314
314
  const lengths = [];
315
315
  for (const item of serializedData) {
316
+ /** @type {undefined | number} */
316
317
  let last;
317
318
  if (typeof item === "function") {
318
319
  lengths.push(0);
@@ -490,8 +491,10 @@ class BinaryMiddleware extends SerializerMiddleware {
490
491
  }
491
492
  case "boolean": {
492
493
  let lastByte = thing === true ? 1 : 0;
494
+ /** @type {number[]} */
493
495
  const bytes = [];
494
496
  let count = 1;
497
+ /** @type {undefined | number} */
495
498
  let n;
496
499
  for (n = 1; n < 0xffffffff && i + n < data.length; n++) {
497
500
  const item = data[i + n];
@@ -541,6 +544,7 @@ class BinaryMiddleware extends SerializerMiddleware {
541
544
  }
542
545
  case "object": {
543
546
  if (thing === null) {
547
+ /** @type {number} */
544
548
  let n;
545
549
  for (n = 1; n < 0x100000104 && i + n < data.length; n++) {
546
550
  const item = data[i + n];
@@ -21,7 +21,7 @@ const { dirname, join, mkdirp } = require("../util/fs");
21
21
  const memoize = require("../util/memoize");
22
22
  const SerializerMiddleware = require("./SerializerMiddleware");
23
23
 
24
- /** @typedef {typeof import("../util/Hash")} Hash */
24
+ /** @typedef {import("../util/Hash").HashFunction} HashFunction */
25
25
  /** @typedef {import("../util/fs").IStats} IStats */
26
26
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
27
27
  /** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
@@ -49,7 +49,7 @@ const WRITE_LIMIT_CHUNK = 511 * 1024 * 1024;
49
49
 
50
50
  /**
51
51
  * @param {Buffer[]} buffers buffers
52
- * @param {string | Hash} hashFunction hash function to use
52
+ * @param {HashFunction} hashFunction hash function to use
53
53
  * @returns {string} hash
54
54
  */
55
55
  const hashForName = (buffers, hashFunction) => {
@@ -101,7 +101,7 @@ const readUInt64LE = Buffer.prototype.readBigUInt64LE
101
101
  * @param {(BufferSerializableType | LazyFunction)[]} data data to be serialized
102
102
  * @param {string | boolean} name file base name
103
103
  * @param {(name: string | false, buffers: Buffer[], size: number) => Promise<void>} writeFile writes a file
104
- * @param {string | Hash} hashFunction hash function to use
104
+ * @param {HashFunction=} hashFunction hash function to use
105
105
  * @returns {Promise<SerializeResult>} resulting file pointer and promise
106
106
  */
107
107
  const serialize = async (
@@ -336,6 +336,7 @@ const deserialize = async (middleware, name, readFile) => {
336
336
  throw new Error("Invalid file version");
337
337
  }
338
338
  const sectionCount = readUInt32LE();
339
+ /** @type {number[]} */
339
340
  const lengths = [];
340
341
  let lastLengthPositive = false;
341
342
  for (let i = 0; i < sectionCount; i++) {
@@ -433,11 +434,13 @@ const deserialize = async (middleware, name, readFile) => {
433
434
  class FileMiddleware extends SerializerMiddleware {
434
435
  /**
435
436
  * @param {IntermediateFileSystem} fs filesystem
436
- * @param {string | Hash} hashFunction hash function to use
437
+ * @param {HashFunction} hashFunction hash function to use
437
438
  */
438
439
  constructor(fs, hashFunction = DEFAULTS.HASH_FUNCTION) {
439
440
  super();
441
+ /** @type {IntermediateFileSystem} */
440
442
  this.fs = fs;
443
+ /** @type {HashFunction} */
441
444
  this._hashFunction = hashFunction;
442
445
  }
443
446
 
@@ -454,6 +457,7 @@ class FileMiddleware extends SerializerMiddleware {
454
457
 
455
458
  // It's important that we don't touch existing files during serialization
456
459
  // because serialize may read existing files (when deserializing)
460
+ /** @type {Set<string>} */
457
461
  const allWrittenFiles = new Set();
458
462
  /**
459
463
  * @param {string | false} name name
@@ -472,6 +476,7 @@ class FileMiddleware extends SerializerMiddleware {
472
476
  */
473
477
  (resolve, reject) => {
474
478
  let stream = this.fs.createWriteStream(`${file}_`);
479
+ /** @type {undefined | import("zlib").Gzip | import("zlib").BrotliCompress} */
475
480
  let compression;
476
481
  if (file.endsWith(".gz")) {
477
482
  compression = createGzip({
@@ -18,7 +18,7 @@ const SerializerMiddleware = require("./SerializerMiddleware");
18
18
  const SetObjectSerializer = require("./SetObjectSerializer");
19
19
 
20
20
  /** @typedef {import("../logging/Logger").Logger} Logger */
21
- /** @typedef {typeof import("../util/Hash")} Hash */
21
+ /** @typedef {import("../util/Hash").HashFunction} HashFunction */
22
22
  /** @typedef {import("./SerializerMiddleware").LazyOptions} LazyOptions */
23
23
  /** @typedef {import("./types").ComplexSerializableType} ComplexSerializableType */
24
24
  /** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
@@ -111,7 +111,7 @@ const setMapSize = (map, size) => {
111
111
 
112
112
  /**
113
113
  * @param {Buffer} buffer buffer
114
- * @param {string | Hash} hashFunction hash function to use
114
+ * @param {HashFunction} hashFunction hash function to use
115
115
  * @returns {string} hash
116
116
  */
117
117
  const toHash = (buffer, hashFunction) => {
@@ -207,17 +207,21 @@ const loaders = new Map();
207
207
  /** @typedef {PrimitiveSerializableType[]} SerializedType */
208
208
  /** @typedef {{ logger: Logger }} Context */
209
209
 
210
+ /** @typedef {(context: ObjectSerializerContext | ObjectDeserializerContext) => void} ExtendContext */
211
+
210
212
  /**
211
213
  * @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
212
214
  */
213
215
  class ObjectMiddleware extends SerializerMiddleware {
214
216
  /**
215
- * @param {(context: ObjectSerializerContext | ObjectDeserializerContext) => void} extendContext context extensions
216
- * @param {string | Hash} hashFunction hash function to use
217
+ * @param {ExtendContext} extendContext context extensions
218
+ * @param {HashFunction} hashFunction hash function to use
217
219
  */
218
220
  constructor(extendContext, hashFunction = DEFAULTS.HASH_FUNCTION) {
219
221
  super();
222
+ /** @type {ExtendContext} */
220
223
  this.extendContext = extendContext;
224
+ /** @type {HashFunction} */
221
225
  this._hashFunction = hashFunction;
222
226
  }
223
227
 
@@ -276,11 +280,12 @@ class ObjectMiddleware extends SerializerMiddleware {
276
280
  }
277
281
 
278
282
  /**
279
- * @param {Constructor} object for serialization
283
+ * @param {EXPECTED_ANY} object for serialization
280
284
  * @returns {SerializerConfigWithSerializer} Serializer config
281
285
  */
282
286
  static getSerializerFor(object) {
283
287
  const proto = Object.getPrototypeOf(object);
288
+ /** @type {null | Constructor} */
284
289
  let c;
285
290
  if (proto === null) {
286
291
  // Object created with Object.create(null)
@@ -295,7 +300,11 @@ class ObjectMiddleware extends SerializerMiddleware {
295
300
  }
296
301
  const config = serializers.get(c);
297
302
 
298
- if (!config) throw new Error(`No serializer registered for ${c.name}`);
303
+ if (!config) {
304
+ throw new Error(
305
+ `No serializer registered for ${/** @type {Constructor} */ (c).name}`
306
+ );
307
+ }
299
308
  if (config === NOT_SERIALIZABLE) throw NOT_SERIALIZABLE;
300
309
 
301
310
  return /** @type {SerializerConfigWithSerializer} */ (config);
@@ -345,6 +354,7 @@ class ObjectMiddleware extends SerializerMiddleware {
345
354
  const addReferenceable = (item) => {
346
355
  referenceable.set(item, currentPos++);
347
356
  };
357
+ /** @type {Map<number, Buffer | [Buffer, Buffer] | Map<string, Buffer>>} */
348
358
  let bufferDedupeMap = new Map();
349
359
  /**
350
360
  * @param {Buffer} buf buffer
@@ -366,6 +376,7 @@ class ObjectMiddleware extends SerializerMiddleware {
366
376
  return buf;
367
377
  }
368
378
  const hash = toHash(entry, this._hashFunction);
379
+ /** @type {Map<string, Buffer>} */
369
380
  const newMap = new Map();
370
381
  newMap.set(hash, entry);
371
382
  bufferDedupeMap.set(len, newMap);
@@ -384,8 +395,10 @@ class ObjectMiddleware extends SerializerMiddleware {
384
395
  entry.push(buf);
385
396
  return buf;
386
397
  }
398
+ /** @type {Map<string, Buffer>} */
387
399
  const newMap = new Map();
388
400
  const hash = toHash(buf, this._hashFunction);
401
+ /** @type {undefined | Buffer} */
389
402
  let found;
390
403
  for (const item of entry) {
391
404
  const itemHash = toHash(item, this._hashFunction);
@@ -408,7 +421,9 @@ class ObjectMiddleware extends SerializerMiddleware {
408
421
  return buf;
409
422
  };
410
423
  let currentPosTypeLookup = 0;
424
+ /** @type {Map<ComplexSerializableType, number>} */
411
425
  let objectTypeLookup = new Map();
426
+ /** @type {Set<ComplexSerializableType>} */
412
427
  const cycleStack = new Set();
413
428
  /**
414
429
  * @param {ComplexSerializableType} item item to stack
@@ -441,12 +456,18 @@ class ObjectMiddleware extends SerializerMiddleware {
441
456
  if (item.constructor === Object) {
442
457
  return `Object { ${Object.keys(item).join(", ")} }`;
443
458
  }
444
- if (item.constructor === Map) return `Map { ${item.size} items }`;
459
+ if (item.constructor === Map) {
460
+ return `Map { ${/** @type {Map<EXPECTED_ANY, EXPECTED_ANY>} */ (item).size} items }`;
461
+ }
445
462
  if (item.constructor === Array) {
446
- return `Array { ${item.length} items }`;
463
+ return `Array { ${/** @type {EXPECTED_ANY[]} */ (item).length} items }`;
464
+ }
465
+ if (item.constructor === Set) {
466
+ return `Set { ${/** @type {Set<EXPECTED_ANY>} */ (item).size} items }`;
467
+ }
468
+ if (item.constructor === RegExp) {
469
+ return /** @type {RegExp} */ (item).toString();
447
470
  }
448
- if (item.constructor === Set) return `Set { ${item.size} items }`;
449
- if (item.constructor === RegExp) return item.toString();
450
471
  return `${item.constructor.name}`;
451
472
  }
452
473
  return `Object [null prototype] { ${Object.keys(item).join(
@@ -464,7 +485,7 @@ class ObjectMiddleware extends SerializerMiddleware {
464
485
  })
465
486
  .join(" -> ");
466
487
  };
467
- /** @type {WeakSet<Error>} */
488
+ /** @type {undefined | WeakSet<Error>} */
468
489
  let hasDebugInfoAttached;
469
490
  /** @type {ObjectSerializerContext} */
470
491
  let ctx = {
@@ -723,6 +744,7 @@ class ObjectMiddleware extends SerializerMiddleware {
723
744
  );
724
745
  } else {
725
746
  const request = nextItem;
747
+ /** @type {undefined | ObjectSerializer} */
726
748
  let serializer;
727
749
 
728
750
  if (typeof request === "number") {
@@ -788,6 +810,7 @@ class ObjectMiddleware extends SerializerMiddleware {
788
810
  // As this is only for error handling, we omit creating a Map for
789
811
  // faster access to this information, as this would affect performance
790
812
  // in the good case
813
+ /** @type {undefined | [Constructor | null, SerializerConfig]} */
791
814
  let serializerEntry;
792
815
  for (const entry of serializers) {
793
816
  if (entry[1].serializer === serializer) {
@@ -20,7 +20,9 @@ const cache = new WeakMap();
20
20
  */
21
21
  class ObjectStructure {
22
22
  constructor() {
23
+ /** @type {undefined | keyof T[]} */
23
24
  this.keys = undefined;
25
+ /** @type {undefined | Map<keyof T, ObjectStructure<T>>} */
24
26
  this.children = undefined;
25
27
  }
26
28
 
@@ -17,6 +17,9 @@ const makeSerializable = require("../util/makeSerializable");
17
17
  const { rangeToString, stringifyHoley } = require("../util/semver");
18
18
  const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependency");
19
19
 
20
+ /** @type {WeakMap<ModuleGraph, WeakMap<ConsumeSharedModule, Module | null>>} */
21
+ const fallbackModuleCache = new WeakMap();
22
+
20
23
  /** @typedef {import("../config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
21
24
  /** @typedef {import("../Compilation")} Compilation */
22
25
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
@@ -27,7 +30,10 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
27
30
  /** @typedef {import("../Module").LibIdent} LibIdent */
28
31
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
29
32
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
33
+ /** @typedef {import("../Module").Sources} Sources */
30
34
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
35
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
36
+ /** @typedef {import("../Module").ExportsType} ExportsType */
31
37
  /** @typedef {import("../RequestShortener")} RequestShortener */
32
38
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
33
39
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -153,6 +159,57 @@ class ConsumeSharedModule extends Module {
153
159
  return CONSUME_SHARED_TYPES;
154
160
  }
155
161
 
162
+ /**
163
+ * @param {ModuleGraph} moduleGraph the module graph
164
+ * @returns {Module | null} fallback module
165
+ */
166
+ _getFallbackModule(moduleGraph) {
167
+ let moduleCache = fallbackModuleCache.get(moduleGraph);
168
+ if (!moduleCache) {
169
+ moduleCache = new WeakMap();
170
+ fallbackModuleCache.set(moduleGraph, moduleCache);
171
+ }
172
+ const cached = moduleCache.get(this);
173
+ if (cached !== undefined) {
174
+ return cached;
175
+ }
176
+
177
+ /** @type {undefined | null | Module} */
178
+ let fallbackModule = null;
179
+
180
+ if (this.options.import) {
181
+ if (this.options.eager) {
182
+ const dep = this.dependencies[0];
183
+ if (dep) {
184
+ fallbackModule = moduleGraph.getModule(dep);
185
+ }
186
+ } else {
187
+ const block = this.blocks[0];
188
+ if (block && block.dependencies.length > 0) {
189
+ fallbackModule = moduleGraph.getModule(block.dependencies[0]);
190
+ }
191
+ }
192
+ }
193
+
194
+ moduleCache.set(this, fallbackModule);
195
+ return fallbackModule;
196
+ }
197
+
198
+ /**
199
+ * @param {ModuleGraph} moduleGraph the module graph
200
+ * @param {boolean | undefined} strict the importing module is strict
201
+ * @returns {ExportsType} export type
202
+ * "namespace": Exports is already a namespace object. namespace = exports.
203
+ * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
204
+ * "default-only": Provide a namespace object with only default export. namespace = { default: exports }
205
+ * "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
206
+ */
207
+ getExportsType(moduleGraph, strict) {
208
+ const fallbackModule = this._getFallbackModule(moduleGraph);
209
+ if (!fallbackModule) return "dynamic";
210
+ return fallbackModule.getExportsType(moduleGraph, strict);
211
+ }
212
+
156
213
  /**
157
214
  * @param {string=} type the source type for which the size should be estimated
158
215
  * @returns {number} the estimated size of the module (must be non-zero)
@@ -186,6 +243,7 @@ class ConsumeSharedModule extends Module {
186
243
  singleton,
187
244
  eager
188
245
  } = this.options;
246
+ /** @type {undefined | string} */
189
247
  let fallbackCode;
190
248
  if (request) {
191
249
  if (eager) {
@@ -219,6 +277,7 @@ class ConsumeSharedModule extends Module {
219
277
  args.push(fallbackCode);
220
278
  }
221
279
 
280
+ /** @type {string} */
222
281
  let fn;
223
282
 
224
283
  if (requiredVersion) {
@@ -232,6 +291,7 @@ class ConsumeSharedModule extends Module {
232
291
  }
233
292
 
234
293
  const code = runtimeTemplate.returningFunction(`${fn}(${args.join(", ")})`);
294
+ /** @type {Sources} */
235
295
  const sources = new Map();
236
296
  sources.set("consume-shared", new RawSource(code));
237
297
  return {