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.
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +13 -1
- package/lib/AsyncDependencyToInitialChunkError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +2 -0
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +8 -4
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +2 -0
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +280 -236
- package/lib/Compiler.js +3 -2
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +3 -1
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +1 -0
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +4 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +2 -1
- package/lib/ModuleFilenameHelpers.js +2 -1
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +26 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +60 -40
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +9 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/FallbackModule.js +2 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/RemoteModule.js +19 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +5 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
- package/lib/ids/SyncModuleIdsPlugin.js +5 -1
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonParser.js +6 -0
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/createConsoleLogger.js +3 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +3 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +35 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +14 -3
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +2 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +27 -7
- package/lib/schemes/VirtualUrlPlugin.js +7 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +4 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/BulkUpdateHash.js +7 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +16 -1
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +13 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/package.json +20 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +71 -5
- 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
|
-
|
|
21
|
-
if (exportsType === "
|
|
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} */
|
|
24
|
-
|
|
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
|
|
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
|
|
136
|
-
`
|
|
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
|
|
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
|
|
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,
|
|
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:
|
|
215
|
-
'case Symbol.toStringTag: return { value: "Deferred Module", configurable:
|
|
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
|
|
204
|
+
'if (mode & 2 && name == "default" && !desc) {',
|
|
222
205
|
Template.indent("desc = { value: ns, configurable: true };"),
|
|
223
206
|
"}",
|
|
224
207
|
"return desc;"
|
|
@@ -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
|
|
@@ -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 {
|
|
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(
|
|
895
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
216
|
-
* @param {
|
|
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 {
|
|
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)
|
|
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)
|
|
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) {
|
|
@@ -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 {
|