webpack 5.101.2 → 5.102.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/README.md +21 -26
- package/lib/APIPlugin.js +30 -36
- package/lib/AsyncDependenciesBlock.js +1 -4
- package/lib/BannerPlugin.js +0 -1
- package/lib/Cache.js +7 -6
- package/lib/CacheFacade.js +0 -1
- package/lib/Chunk.js +49 -31
- package/lib/ChunkGraph.js +35 -25
- package/lib/ChunkGroup.js +8 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +3 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +29 -12
- package/lib/Compilation.js +204 -185
- package/lib/Compiler.js +36 -35
- package/lib/ConcatenationScope.js +6 -1
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +18 -10
- package/lib/ContextExclusionPlugin.js +0 -1
- package/lib/ContextModule.js +22 -20
- package/lib/ContextModuleFactory.js +30 -11
- package/lib/ContextReplacementPlugin.js +38 -15
- package/lib/DefinePlugin.js +18 -8
- package/lib/DelegatedModule.js +7 -11
- package/lib/DependenciesBlock.js +0 -2
- package/lib/Dependency.js +9 -11
- package/lib/DependencyTemplates.js +1 -3
- package/lib/DllModule.js +1 -7
- package/lib/DllReferencePlugin.js +2 -4
- package/lib/DynamicEntryPlugin.js +0 -2
- package/lib/EntryOptionPlugin.js +0 -5
- package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
- package/lib/EvalDevToolModulePlugin.js +4 -3
- package/lib/EvalSourceMapDevToolPlugin.js +3 -4
- package/lib/ExportsInfo.js +50 -49
- package/lib/ExternalModule.js +84 -52
- package/lib/ExternalModuleFactoryPlugin.js +27 -7
- package/lib/ExternalsPlugin.js +24 -17
- package/lib/FileSystemInfo.js +96 -78
- package/lib/FlagDependencyUsagePlugin.js +3 -4
- package/lib/Generator.js +2 -13
- package/lib/GraphHelpers.js +0 -3
- package/lib/HookWebpackError.js +0 -2
- package/lib/HotModuleReplacementPlugin.js +22 -24
- package/lib/HotUpdateChunk.js +0 -3
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InitFragment.js +41 -29
- package/lib/InvalidDependenciesModuleWarning.js +0 -1
- package/lib/LibManifestPlugin.js +4 -6
- package/lib/LoaderOptionsPlugin.js +1 -10
- package/lib/MainTemplate.js +8 -19
- package/lib/Module.js +32 -20
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleFilenameHelpers.js +41 -24
- package/lib/ModuleGraph.js +30 -16
- package/lib/ModuleInfoHeaderPlugin.js +0 -1
- package/lib/ModuleTemplate.js +0 -2
- package/lib/ModuleTypeConstants.js +11 -1
- package/lib/MultiCompiler.js +23 -15
- package/lib/MultiWatching.js +6 -10
- package/lib/NodeStuffPlugin.js +2 -10
- package/lib/NormalModule.js +145 -88
- package/lib/NormalModuleFactory.js +59 -40
- package/lib/OptionsApply.js +1 -1
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +6 -10
- package/lib/ProvidePlugin.js +5 -7
- package/lib/RawModule.js +1 -6
- package/lib/RecordIdsPlugin.js +10 -6
- package/lib/ResolverFactory.js +0 -2
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +1 -3
- package/lib/RuntimePlugin.js +26 -22
- package/lib/RuntimeTemplate.js +12 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +6 -11
- package/lib/Stats.js +0 -1
- package/lib/Template.js +6 -11
- package/lib/TemplatedPathPlugin.js +2 -1
- package/lib/WatchIgnorePlugin.js +2 -3
- package/lib/Watching.js +15 -15
- package/lib/WebpackIsIncludedPlugin.js +0 -2
- package/lib/WebpackOptionsApply.js +74 -107
- package/lib/asset/AssetBytesGenerator.js +166 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +20 -34
- package/lib/asset/AssetModulesPlugin.js +34 -16
- package/lib/asset/AssetParser.js +7 -3
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/asset/RawDataUrlModule.js +3 -2
- package/lib/async-modules/AsyncModuleHelpers.js +6 -4
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +0 -1
- package/lib/cache/MemoryCachePlugin.js +0 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
- package/lib/cache/PackFileCacheStrategy.js +14 -1
- package/lib/cache/ResolverCachePlugin.js +9 -15
- package/lib/config/defaults.js +155 -21
- package/lib/config/normalization.js +18 -3
- package/lib/container/ContainerEntryDependency.js +0 -1
- package/lib/container/ContainerEntryModule.js +3 -7
- package/lib/container/ContainerPlugin.js +1 -2
- package/lib/container/ContainerReferencePlugin.js +0 -1
- package/lib/container/FallbackDependency.js +2 -1
- package/lib/container/FallbackModule.js +6 -7
- package/lib/container/ModuleFederationPlugin.js +0 -1
- package/lib/container/RemoteModule.js +8 -8
- package/lib/container/RemoteRuntimeModule.js +2 -2
- package/lib/css/CssGenerator.js +3 -6
- package/lib/css/CssLoadingRuntimeModule.js +6 -9
- package/lib/css/CssModulesPlugin.js +11 -13
- package/lib/css/CssParser.js +3 -3
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +35 -8
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/CachedConstDependency.js +0 -4
- package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
- package/lib/dependencies/CommonJsExportsDependency.js +2 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
- package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +9 -4
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
- package/lib/dependencies/ContextElementDependency.js +22 -11
- package/lib/dependencies/CssIcssImportDependency.js +0 -2
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
- package/lib/dependencies/CssImportDependency.js +0 -8
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -4
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +0 -6
- package/lib/dependencies/ExportsInfoDependency.js +7 -9
- package/lib/dependencies/ExternalModuleDependency.js +0 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
- package/lib/dependencies/HarmonyImportDependency.js +30 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +38 -24
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
- package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
- package/lib/dependencies/ImportDependency.js +18 -6
- package/lib/dependencies/ImportEagerDependency.js +2 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
- package/lib/dependencies/ImportMetaPlugin.js +8 -1
- package/lib/dependencies/ImportParserPlugin.js +294 -45
- package/lib/dependencies/ImportWeakDependency.js +2 -3
- package/lib/dependencies/JsonExportsDependency.js +0 -1
- package/lib/dependencies/LoaderDependency.js +0 -3
- package/lib/dependencies/LoaderImportDependency.js +0 -3
- package/lib/dependencies/LoaderPlugin.js +11 -5
- package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
- package/lib/dependencies/ModuleDependency.js +3 -9
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/ProvidedDependency.js +6 -8
- package/lib/dependencies/PureExpressionDependency.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/RequireIncludeDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
- package/lib/dependencies/StaticExportsDependency.js +3 -5
- package/lib/dependencies/URLDependency.js +2 -7
- package/lib/dependencies/URLPlugin.js +1 -2
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
- package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
- package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
- package/lib/dependencies/WorkerDependency.js +2 -3
- package/lib/dependencies/WorkerPlugin.js +3 -9
- package/lib/dependencies/processExportInfo.js +2 -3
- package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/hmr/lazyCompilationBackend.js +13 -10
- package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
- package/lib/ids/NamedChunkIdsPlugin.js +1 -6
- package/lib/ids/NamedModuleIdsPlugin.js +1 -5
- package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
- package/lib/ids/SyncModuleIdsPlugin.js +4 -3
- package/lib/index.js +8 -7
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
- package/lib/javascript/BasicEvaluatedExpression.js +13 -6
- package/lib/javascript/ChunkFormatHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
- package/lib/javascript/JavascriptGenerator.js +2 -3
- package/lib/javascript/JavascriptModulesPlugin.js +44 -21
- package/lib/javascript/JavascriptParser.js +159 -93
- package/lib/javascript/JavascriptParserHelpers.js +2 -2
- package/lib/javascript/StartupHelpers.js +2 -4
- package/lib/json/JsonData.js +1 -1
- package/lib/json/JsonGenerator.js +4 -5
- package/lib/json/JsonModulesPlugin.js +0 -3
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +0 -1
- package/lib/library/AssignLibraryPlugin.js +23 -12
- package/lib/library/EnableLibraryPlugin.js +7 -11
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
- package/lib/library/JsonpLibraryPlugin.js +5 -2
- package/lib/library/ModuleLibraryPlugin.js +88 -43
- package/lib/library/SystemLibraryPlugin.js +0 -1
- package/lib/library/UmdLibraryPlugin.js +12 -18
- package/lib/logging/Logger.js +12 -10
- package/lib/logging/createConsoleLogger.js +15 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeWatchFileSystem.js +4 -4
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
- package/lib/optimize/ConcatenatedModule.js +142 -100
- package/lib/optimize/InnerGraph.js +17 -11
- package/lib/optimize/InnerGraphPlugin.js +0 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
- package/lib/optimize/RuntimeChunkPlugin.js +0 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
- package/lib/optimize/SplitChunksPlugin.js +46 -40
- package/lib/performance/SizeLimitsPlugin.js +2 -1
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/rules/BasicMatcherRulePlugin.js +0 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
- package/lib/rules/RuleSetCompiler.js +8 -6
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +0 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
- package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
- package/lib/runtime/SystemContextRuntimeModule.js +0 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
- package/lib/schemes/DataUriPlugin.js +2 -28
- package/lib/schemes/FileUriPlugin.js +5 -2
- package/lib/schemes/HttpUriPlugin.js +4 -2
- package/lib/schemes/VirtualUrlPlugin.js +11 -11
- package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
- package/lib/serialization/ObjectMiddleware.js +30 -19
- package/lib/serialization/SerializerMiddleware.js +1 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +3 -5
- package/lib/sharing/ConsumeSharedPlugin.js +2 -4
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
- package/lib/sharing/ProvideSharedModule.js +3 -7
- package/lib/sharing/SharePlugin.js +0 -2
- package/lib/sharing/ShareRuntimeModule.js +4 -1
- package/lib/sharing/resolveMatchedConfigs.js +14 -6
- package/lib/sharing/utils.js +0 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +178 -94
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
- package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
- package/lib/stats/StatsFactory.js +14 -11
- package/lib/url/URLParserPlugin.js +2 -4
- package/lib/util/ArrayHelpers.js +4 -4
- package/lib/util/AsyncQueue.js +1 -0
- package/lib/util/LazySet.js +2 -2
- package/lib/util/StackedCacheMap.js +0 -2
- package/lib/util/TupleSet.js +9 -4
- package/lib/util/URLAbsoluteSpecifier.js +0 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/chainedImports.js +3 -1
- package/lib/util/cleverMerge.js +15 -18
- package/lib/util/comparators.js +2 -4
- package/lib/util/compileBooleanMatcher.js +11 -9
- package/lib/util/concatenate.js +1 -2
- package/lib/util/create-schema-validation.js +0 -1
- package/lib/util/dataURL.js +39 -0
- package/lib/util/deprecation.js +29 -31
- package/lib/util/deterministicGrouping.js +34 -30
- package/lib/util/extractSourceMap.js +319 -0
- package/lib/util/findGraphRoots.js +15 -5
- package/lib/util/fs.js +29 -8
- package/lib/util/semver.js +9 -8
- package/lib/util/smartGrouping.js +41 -26
- package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
- package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
- package/lib/wasm-sync/WebAssemblyParser.js +1 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/web/JsonpTemplatePlugin.js +0 -1
- package/lib/webpack.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +13 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +77 -93
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +1140 -505
- package/SECURITY.md +0 -9
package/lib/ExportsInfo.js
CHANGED
|
@@ -12,6 +12,8 @@ const { forEachRuntime } = require("./util/runtime");
|
|
|
12
12
|
|
|
13
13
|
/** @typedef {import("./Dependency")} Dependency */
|
|
14
14
|
/** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
|
|
15
|
+
/** @typedef {import("./Dependency").ExportsSpecExcludeExports} ExportsSpecExcludeExports */
|
|
16
|
+
/** @typedef {import("./dependencies/HarmonyImportDependency")} HarmonyImportDependency */
|
|
15
17
|
/** @typedef {import("./Module")} Module */
|
|
16
18
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
|
17
19
|
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
|
|
@@ -22,17 +24,22 @@ const { forEachRuntime } = require("./util/runtime");
|
|
|
22
24
|
/** @typedef {typeof UsageState.OnlyPropertiesUsed | typeof UsageState.NoInfo | typeof UsageState.Unknown | typeof UsageState.Used} RuntimeUsageStateType */
|
|
23
25
|
/** @typedef {typeof UsageState.Unused | RuntimeUsageStateType} UsageStateType */
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
Unused: /** @type {0} */ (0),
|
|
27
|
-
OnlyPropertiesUsed: /** @type {1} */ (1),
|
|
28
|
-
NoInfo: /** @type {2} */ (2),
|
|
29
|
-
Unknown: /** @type {3} */ (3),
|
|
30
|
-
Used: /** @type {4} */ (4)
|
|
31
|
-
});
|
|
27
|
+
/** @typedef {string} ExportInfoName */
|
|
32
28
|
|
|
33
|
-
|
|
29
|
+
/** @typedef {Map<string, RuntimeUsageStateType>} UsedInRuntime */
|
|
30
|
+
/** @typedef {{ module: Module, export: ExportInfoName[], deferred: boolean }} TargetItemWithoutConnection */
|
|
31
|
+
/** @typedef {{ module: Module, connection: ModuleGraphConnection, export: ExportInfoName[] | undefined }} TargetItemWithConnection */
|
|
32
|
+
/** @typedef {(target: TargetItemWithConnection) => boolean} ResolveTargetFilter */
|
|
33
|
+
/** @typedef {(module: Module) => boolean} ValidTargetModuleFilter */
|
|
34
|
+
/** @typedef {{ connection: ModuleGraphConnection, export: ExportInfoName[], priority: number }} TargetItem */
|
|
35
|
+
/** @typedef {Map<Dependency | undefined, TargetItem>} Target */
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
/** @typedef {string | null} ExportInfoUsedName */
|
|
38
|
+
/** @typedef {boolean | null} ExportInfoProvided */
|
|
39
|
+
|
|
40
|
+
/** @typedef {Map<ExportInfoName, ExportInfo>} Exports */
|
|
41
|
+
/** @typedef {string | string[] | false} UsedName */
|
|
42
|
+
/** @typedef {Set<ExportInfo>} AlreadyVisitedExportInfo */
|
|
36
43
|
|
|
37
44
|
/**
|
|
38
45
|
* @typedef {object} RestoreProvidedDataExports
|
|
@@ -43,6 +50,18 @@ const CIRCULAR = Symbol("circular target");
|
|
|
43
50
|
* @property {RestoreProvidedData | undefined} exportsInfo
|
|
44
51
|
*/
|
|
45
52
|
|
|
53
|
+
const UsageState = Object.freeze({
|
|
54
|
+
Unused: /** @type {0} */ (0),
|
|
55
|
+
OnlyPropertiesUsed: /** @type {1} */ (1),
|
|
56
|
+
NoInfo: /** @type {2} */ (2),
|
|
57
|
+
Unknown: /** @type {3} */ (3),
|
|
58
|
+
Used: /** @type {4} */ (4)
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const RETURNS_TRUE = () => true;
|
|
62
|
+
|
|
63
|
+
const CIRCULAR = Symbol("circular target");
|
|
64
|
+
|
|
46
65
|
class RestoreProvidedData {
|
|
47
66
|
/**
|
|
48
67
|
* @param {RestoreProvidedDataExports[]} exports exports
|
|
@@ -87,14 +106,11 @@ makeSerializable(
|
|
|
87
106
|
"RestoreProvidedData"
|
|
88
107
|
);
|
|
89
108
|
|
|
90
|
-
/** @typedef {Map<ExportInfoName, ExportInfo>} Exports */
|
|
91
|
-
/** @typedef {string | string[] | false} UsedName */
|
|
92
|
-
|
|
93
109
|
class ExportsInfo {
|
|
94
110
|
constructor() {
|
|
95
111
|
/** @type {Exports} */
|
|
96
112
|
this._exports = new Map();
|
|
97
|
-
this._otherExportsInfo = new ExportInfo(
|
|
113
|
+
this._otherExportsInfo = new ExportInfo(null);
|
|
98
114
|
this._sideEffectsOnlyInfo = new ExportInfo("*side effects only*");
|
|
99
115
|
this._exportsAreOrdered = false;
|
|
100
116
|
/** @type {ExportsInfo=} */
|
|
@@ -171,7 +187,7 @@ class ExportsInfo {
|
|
|
171
187
|
*/
|
|
172
188
|
_sortExportsMap(exports) {
|
|
173
189
|
if (exports.size > 1) {
|
|
174
|
-
/** @type {
|
|
190
|
+
/** @type {ExportInfoName[]} */
|
|
175
191
|
const namesInOrder = [];
|
|
176
192
|
for (const entry of exports.values()) {
|
|
177
193
|
namesInOrder.push(entry.name);
|
|
@@ -308,7 +324,7 @@ class ExportsInfo {
|
|
|
308
324
|
|
|
309
325
|
/**
|
|
310
326
|
* @param {boolean=} canMangle true, if exports can still be mangled (defaults to false)
|
|
311
|
-
* @param {
|
|
327
|
+
* @param {ExportsSpecExcludeExports=} excludeExports list of unaffected exports
|
|
312
328
|
* @param {Dependency=} targetKey use this as key for the target
|
|
313
329
|
* @param {ModuleGraphConnection=} targetModule set this module as target
|
|
314
330
|
* @param {number=} priority priority
|
|
@@ -505,7 +521,7 @@ class ExportsInfo {
|
|
|
505
521
|
|
|
506
522
|
/**
|
|
507
523
|
* @param {RuntimeSpec} runtime the runtime
|
|
508
|
-
* @returns {SortableSet<
|
|
524
|
+
* @returns {SortableSet<ExportInfoName> | boolean | null} set of used exports, or true (when namespace object is used), or false (when unused), or null (when unknown)
|
|
509
525
|
*/
|
|
510
526
|
getUsedExports(runtime) {
|
|
511
527
|
switch (this._otherExportsInfo.getUsed(runtime)) {
|
|
@@ -517,6 +533,7 @@ class ExportsInfo {
|
|
|
517
533
|
return true;
|
|
518
534
|
}
|
|
519
535
|
|
|
536
|
+
/** @type {ExportInfoName[]} */
|
|
520
537
|
const array = [];
|
|
521
538
|
if (!this._exportsAreOrdered) this._sortExports();
|
|
522
539
|
for (const exportInfo of this._exports.values()) {
|
|
@@ -548,11 +565,11 @@ class ExportsInfo {
|
|
|
548
565
|
return false;
|
|
549
566
|
}
|
|
550
567
|
}
|
|
551
|
-
return /** @type {SortableSet<
|
|
568
|
+
return /** @type {SortableSet<ExportInfoName>} */ (new SortableSet(array));
|
|
552
569
|
}
|
|
553
570
|
|
|
554
571
|
/**
|
|
555
|
-
* @returns {null | true |
|
|
572
|
+
* @returns {null | true | ExportInfoName[]} list of exports when known
|
|
556
573
|
*/
|
|
557
574
|
getProvidedExports() {
|
|
558
575
|
switch (this._otherExportsInfo.provided) {
|
|
@@ -564,7 +581,7 @@ class ExportsInfo {
|
|
|
564
581
|
return true;
|
|
565
582
|
}
|
|
566
583
|
|
|
567
|
-
/** @type {
|
|
584
|
+
/** @type {ExportInfoName[]} */
|
|
568
585
|
const array = [];
|
|
569
586
|
if (!this._exportsAreOrdered) this._sortExports();
|
|
570
587
|
for (const exportInfo of this._exports.values()) {
|
|
@@ -831,32 +848,14 @@ class ExportsInfo {
|
|
|
831
848
|
}
|
|
832
849
|
}
|
|
833
850
|
|
|
834
|
-
/** @typedef {Map<string, RuntimeUsageStateType>} UsedInRuntime */
|
|
835
|
-
|
|
836
|
-
/** @typedef {{ module: Module, export: string[], deferred: boolean }} TargetItemWithoutConnection */
|
|
837
|
-
|
|
838
|
-
/** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItemWithConnection */
|
|
839
|
-
|
|
840
|
-
/** @typedef {(target: TargetItemWithConnection) => boolean} ResolveTargetFilter */
|
|
841
|
-
|
|
842
|
-
/** @typedef {(module: Module) => boolean} ValidTargetModuleFilter */
|
|
843
|
-
|
|
844
|
-
/** @typedef {{ connection: ModuleGraphConnection, export: string[], priority: number }} TargetItem */
|
|
845
|
-
|
|
846
|
-
/** @typedef {Map<Dependency | undefined, TargetItem>} Target */
|
|
847
|
-
|
|
848
|
-
/** @typedef {string} ExportInfoName */
|
|
849
|
-
/** @typedef {string | null} ExportInfoUsedName */
|
|
850
|
-
/** @typedef {boolean | null} ExportInfoProvided */
|
|
851
|
-
|
|
852
851
|
class ExportInfo {
|
|
853
852
|
/**
|
|
854
|
-
* @param {ExportInfoName} name the original name of the export
|
|
853
|
+
* @param {ExportInfoName | null} name the original name of the export
|
|
855
854
|
* @param {ExportInfo=} initFrom init values from this ExportInfo
|
|
856
855
|
*/
|
|
857
856
|
constructor(name, initFrom) {
|
|
858
857
|
/** @type {ExportInfoName} */
|
|
859
|
-
this.name = name;
|
|
858
|
+
this.name = /** @type {ExportInfoName} */ (name);
|
|
860
859
|
/**
|
|
861
860
|
* @private
|
|
862
861
|
* @type {ExportInfoUsedName}
|
|
@@ -1058,8 +1057,8 @@ class ExportInfo {
|
|
|
1058
1057
|
}
|
|
1059
1058
|
} else {
|
|
1060
1059
|
let changed = false;
|
|
1061
|
-
forEachRuntime(runtime, (
|
|
1062
|
-
const runtime = /** @type {string} */ (
|
|
1060
|
+
forEachRuntime(runtime, (runtime_) => {
|
|
1061
|
+
const runtime = /** @type {string} */ (runtime_);
|
|
1063
1062
|
const usedInRuntime =
|
|
1064
1063
|
/** @type {UsedInRuntime} */
|
|
1065
1064
|
(this._usedInRuntime);
|
|
@@ -1148,7 +1147,7 @@ class ExportInfo {
|
|
|
1148
1147
|
/**
|
|
1149
1148
|
* @param {Dependency} key the key
|
|
1150
1149
|
* @param {ModuleGraphConnection} connection the target module if a single one
|
|
1151
|
-
* @param {
|
|
1150
|
+
* @param {ExportInfoName[] | null=} exportName the exported name
|
|
1152
1151
|
* @param {number=} priority priority
|
|
1153
1152
|
* @returns {boolean} true, if something has changed
|
|
1154
1153
|
*/
|
|
@@ -1158,7 +1157,7 @@ class ExportInfo {
|
|
|
1158
1157
|
this._target = new Map();
|
|
1159
1158
|
this._target.set(key, {
|
|
1160
1159
|
connection,
|
|
1161
|
-
export: /** @type {
|
|
1160
|
+
export: /** @type {ExportInfoName[]} */ (exportName),
|
|
1162
1161
|
priority
|
|
1163
1162
|
});
|
|
1164
1163
|
return true;
|
|
@@ -1168,7 +1167,7 @@ class ExportInfo {
|
|
|
1168
1167
|
if (oldTarget === null && !connection) return false;
|
|
1169
1168
|
this._target.set(key, {
|
|
1170
1169
|
connection,
|
|
1171
|
-
export: /** @type {
|
|
1170
|
+
export: /** @type {ExportInfoName[]} */ (exportName),
|
|
1172
1171
|
priority
|
|
1173
1172
|
});
|
|
1174
1173
|
this._maxTarget = undefined;
|
|
@@ -1182,7 +1181,7 @@ class ExportInfo {
|
|
|
1182
1181
|
: oldTarget.export)
|
|
1183
1182
|
) {
|
|
1184
1183
|
oldTarget.connection = connection;
|
|
1185
|
-
oldTarget.export = /** @type {
|
|
1184
|
+
oldTarget.export = /** @type {ExportInfoName[]} */ (exportName);
|
|
1186
1185
|
oldTarget.priority = priority;
|
|
1187
1186
|
this._maxTarget = undefined;
|
|
1188
1187
|
return true;
|
|
@@ -1331,7 +1330,7 @@ class ExportInfo {
|
|
|
1331
1330
|
/**
|
|
1332
1331
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
1333
1332
|
* @param {ValidTargetModuleFilter} validTargetModuleFilter a valid target module
|
|
1334
|
-
* @param {
|
|
1333
|
+
* @param {AlreadyVisitedExportInfo} alreadyVisited set of already visited export info to avoid circular references
|
|
1335
1334
|
* @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
|
|
1336
1335
|
*/
|
|
1337
1336
|
_findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
|
|
@@ -1345,7 +1344,9 @@ class ExportInfo {
|
|
|
1345
1344
|
module: rawTarget.connection.module,
|
|
1346
1345
|
export: rawTarget.export,
|
|
1347
1346
|
deferred: Boolean(
|
|
1348
|
-
rawTarget.connection.dependency &&
|
|
1347
|
+
rawTarget.connection.dependency &&
|
|
1348
|
+
/** @type {HarmonyImportDependency} */
|
|
1349
|
+
(rawTarget.connection.dependency).defer
|
|
1349
1350
|
)
|
|
1350
1351
|
};
|
|
1351
1352
|
for (;;) {
|
|
@@ -1387,13 +1388,13 @@ class ExportInfo {
|
|
|
1387
1388
|
/**
|
|
1388
1389
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
1389
1390
|
* @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target
|
|
1390
|
-
* @param {
|
|
1391
|
+
* @param {AlreadyVisitedExportInfo | undefined} alreadyVisited set of already visited export info to avoid circular references
|
|
1391
1392
|
* @returns {TargetItemWithConnection | CIRCULAR | undefined} the target
|
|
1392
1393
|
*/
|
|
1393
1394
|
_getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) {
|
|
1394
1395
|
/**
|
|
1395
1396
|
* @param {TargetItem | undefined | null} inputTarget unresolved target
|
|
1396
|
-
* @param {
|
|
1397
|
+
* @param {AlreadyVisitedExportInfo} alreadyVisited set of already visited export info to avoid circular references
|
|
1397
1398
|
* @returns {TargetItemWithConnection | CIRCULAR | null} resolved target
|
|
1398
1399
|
*/
|
|
1399
1400
|
const resolveTarget = (inputTarget, alreadyVisited) => {
|
package/lib/ExternalModule.js
CHANGED
|
@@ -29,22 +29,23 @@ const { register } = require("./util/serialization");
|
|
|
29
29
|
|
|
30
30
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
31
31
|
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
32
|
-
/** @typedef {import("
|
|
32
|
+
/** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
33
33
|
/** @typedef {import("./Chunk")} Chunk */
|
|
34
34
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
|
35
35
|
/** @typedef {import("./Compilation")} Compilation */
|
|
36
36
|
/** @typedef {import("./Compilation").UnsafeCacheData} UnsafeCacheData */
|
|
37
37
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
|
38
|
-
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
|
39
38
|
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
|
40
39
|
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
|
41
40
|
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
|
41
|
+
/** @typedef {import("./Module").ModuleId} ModuleId */
|
|
42
42
|
/** @typedef {import("./Module").BuildCallback} BuildCallback */
|
|
43
43
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
|
44
44
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
|
45
45
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
|
46
46
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
47
47
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
|
48
|
+
/** @typedef {import("./Module").LibIdent} LibIdent */
|
|
48
49
|
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
|
|
49
50
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
|
50
51
|
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
@@ -53,7 +54,6 @@ const { register } = require("./util/serialization");
|
|
|
53
54
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
|
54
55
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
55
56
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
|
56
|
-
/** @typedef {import("./WebpackError")} WebpackError */
|
|
57
57
|
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
|
58
58
|
/** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|
59
59
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
@@ -88,7 +88,7 @@ const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
|
|
|
88
88
|
const EMPTY_RUNTIME_REQUIREMENTS = new Set([]);
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* @param {string|string[]} variableName the variable name or path
|
|
91
|
+
* @param {string | string[]} variableName the variable name or path
|
|
92
92
|
* @param {string} type the module system
|
|
93
93
|
* @returns {SourceData} the generated source
|
|
94
94
|
*/
|
|
@@ -108,8 +108,10 @@ const getSourceForGlobalVariableExternal = (variableName, type) => {
|
|
|
108
108
|
};
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
/** @typedef {string | string[]} ModuleAndSpecifiers */
|
|
112
|
+
|
|
111
113
|
/**
|
|
112
|
-
* @param {
|
|
114
|
+
* @param {ModuleAndSpecifiers} moduleAndSpecifiers the module request
|
|
113
115
|
* @returns {SourceData} the generated source
|
|
114
116
|
*/
|
|
115
117
|
const getSourceForCommonJsExternal = (moduleAndSpecifiers) => {
|
|
@@ -128,7 +130,24 @@ const getSourceForCommonJsExternal = (moduleAndSpecifiers) => {
|
|
|
128
130
|
};
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
|
-
* @param {
|
|
133
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
134
|
+
* @returns {InitFragment<ChunkRenderContext>} code
|
|
135
|
+
*/
|
|
136
|
+
const getExternalModuleNodeCommonjsInitFragment = (runtimeTemplate) => {
|
|
137
|
+
const importMetaName = runtimeTemplate.outputOptions.importMetaName;
|
|
138
|
+
|
|
139
|
+
return new InitFragment(
|
|
140
|
+
`import { createRequire as __WEBPACK_EXTERNAL_createRequire } from ${runtimeTemplate.renderNodePrefixForCoreModule(
|
|
141
|
+
"module"
|
|
142
|
+
)};\n${runtimeTemplate.renderConst()} __WEBPACK_EXTERNAL_createRequire_require = __WEBPACK_EXTERNAL_createRequire(${importMetaName}.url);\n`,
|
|
143
|
+
InitFragment.STAGE_HARMONY_IMPORTS,
|
|
144
|
+
0,
|
|
145
|
+
"external module node-commonjs"
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @param {ModuleAndSpecifiers} moduleAndSpecifiers the module request
|
|
132
151
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
133
152
|
* @returns {SourceData} the generated source
|
|
134
153
|
*/
|
|
@@ -136,25 +155,13 @@ const getSourceForCommonJsExternalInNodeModule = (
|
|
|
136
155
|
moduleAndSpecifiers,
|
|
137
156
|
runtimeTemplate
|
|
138
157
|
) => {
|
|
139
|
-
const importMetaName =
|
|
140
|
-
/** @type {string} */
|
|
141
|
-
(runtimeTemplate.outputOptions.importMetaName);
|
|
142
|
-
|
|
143
|
-
// /** @type {boolean} */
|
|
144
|
-
// (runtimeTemplate.supportNodePrefixForCoreModules())
|
|
145
|
-
|
|
146
158
|
const chunkInitFragments = [
|
|
147
|
-
|
|
148
|
-
`import { createRequire as __WEBPACK_EXTERNAL_createRequire } from ${runtimeTemplate.renderNodePrefixForCoreModule("module")};\n`,
|
|
149
|
-
InitFragment.STAGE_HARMONY_IMPORTS,
|
|
150
|
-
0,
|
|
151
|
-
"external module node-commonjs"
|
|
152
|
-
)
|
|
159
|
+
getExternalModuleNodeCommonjsInitFragment(runtimeTemplate)
|
|
153
160
|
];
|
|
154
161
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
|
155
162
|
return {
|
|
156
163
|
chunkInitFragments,
|
|
157
|
-
expression: `
|
|
164
|
+
expression: `__WEBPACK_EXTERNAL_createRequire_require(${JSON.stringify(
|
|
158
165
|
moduleAndSpecifiers
|
|
159
166
|
)})`
|
|
160
167
|
};
|
|
@@ -162,14 +169,14 @@ const getSourceForCommonJsExternalInNodeModule = (
|
|
|
162
169
|
const moduleName = moduleAndSpecifiers[0];
|
|
163
170
|
return {
|
|
164
171
|
chunkInitFragments,
|
|
165
|
-
expression: `
|
|
172
|
+
expression: `__WEBPACK_EXTERNAL_createRequire_require(${JSON.stringify(
|
|
166
173
|
moduleName
|
|
167
174
|
)})${propertyAccess(moduleAndSpecifiers, 1)}`
|
|
168
175
|
};
|
|
169
176
|
};
|
|
170
177
|
|
|
171
178
|
/**
|
|
172
|
-
* @param {
|
|
179
|
+
* @param {ModuleAndSpecifiers} moduleAndSpecifiers the module request
|
|
173
180
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
174
181
|
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
|
175
182
|
* @returns {SourceData} the generated source
|
|
@@ -263,7 +270,6 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
|
263
270
|
}
|
|
264
271
|
}
|
|
265
272
|
|
|
266
|
-
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
|
267
273
|
super(
|
|
268
274
|
"",
|
|
269
275
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
|
@@ -273,8 +279,8 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
|
273
279
|
this._ident = ident;
|
|
274
280
|
this._request = request;
|
|
275
281
|
this._dependencyMeta = dependencyMeta;
|
|
276
|
-
this.
|
|
277
|
-
this.
|
|
282
|
+
this._identifier = this.buildIdentifier(ident);
|
|
283
|
+
this._imported = this.buildImported(imported);
|
|
278
284
|
}
|
|
279
285
|
|
|
280
286
|
/**
|
|
@@ -337,6 +343,28 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
|
337
343
|
getNamespaceIdentifier() {
|
|
338
344
|
return this._identifier;
|
|
339
345
|
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* @param {string} ident ident
|
|
349
|
+
* @returns {string} identifier
|
|
350
|
+
*/
|
|
351
|
+
buildIdentifier(ident) {
|
|
352
|
+
return `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @param {Imported} imported imported
|
|
357
|
+
* @returns {Imported} normalized imported
|
|
358
|
+
*/
|
|
359
|
+
buildImported(imported) {
|
|
360
|
+
if (Array.isArray(imported)) {
|
|
361
|
+
return imported.map(([name]) => {
|
|
362
|
+
const ident = `${this._ident}_${name}`;
|
|
363
|
+
return [name, this.buildIdentifier(ident)];
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
return imported;
|
|
367
|
+
}
|
|
340
368
|
}
|
|
341
369
|
|
|
342
370
|
register(
|
|
@@ -398,7 +426,7 @@ const generateModuleRemapping = (
|
|
|
398
426
|
};
|
|
399
427
|
|
|
400
428
|
/**
|
|
401
|
-
* @param {
|
|
429
|
+
* @param {ModuleAndSpecifiers} moduleAndSpecifiers the module request
|
|
402
430
|
* @param {ExportsInfo} exportsInfo exports info of this module
|
|
403
431
|
* @param {RuntimeSpec} runtime the runtime
|
|
404
432
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
@@ -433,21 +461,7 @@ const getSourceForModuleExternal = (
|
|
|
433
461
|
imported = [];
|
|
434
462
|
break;
|
|
435
463
|
default:
|
|
436
|
-
imported = [];
|
|
437
|
-
if (exportsInfo.isUsed(runtime) === false) {
|
|
438
|
-
// no used, only
|
|
439
|
-
}
|
|
440
|
-
for (const [name] of usedExports.entries()) {
|
|
441
|
-
let counter = 0;
|
|
442
|
-
let finalName = name;
|
|
443
|
-
|
|
444
|
-
if (concatenationScope) {
|
|
445
|
-
while (!concatenationScope.registerUsedName(finalName)) {
|
|
446
|
-
finalName = `${name}_${counter++}`;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
imported.push([name, finalName]);
|
|
450
|
-
}
|
|
464
|
+
imported = [...usedExports.entries()];
|
|
451
465
|
}
|
|
452
466
|
}
|
|
453
467
|
|
|
@@ -458,7 +472,24 @@ const getSourceForModuleExternal = (
|
|
|
458
472
|
dependencyMeta,
|
|
459
473
|
runtimeTemplate.outputOptions.hashFunction
|
|
460
474
|
);
|
|
461
|
-
const
|
|
475
|
+
const normalizedImported = initFragment.getImported();
|
|
476
|
+
const specifiers =
|
|
477
|
+
normalizedImported === true
|
|
478
|
+
? undefined
|
|
479
|
+
: /** @type {[string, string][]} */ (
|
|
480
|
+
normalizedImported.map(([name, rawFinalName]) => {
|
|
481
|
+
let finalName = rawFinalName;
|
|
482
|
+
let counter = 0;
|
|
483
|
+
|
|
484
|
+
if (concatenationScope) {
|
|
485
|
+
while (!concatenationScope.registerUsedName(finalName)) {
|
|
486
|
+
finalName = `${finalName}_${counter++}`;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return [name, finalName];
|
|
490
|
+
})
|
|
491
|
+
);
|
|
492
|
+
|
|
462
493
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
|
463
494
|
moduleAndSpecifiers,
|
|
464
495
|
1
|
|
@@ -498,7 +529,7 @@ const getSourceForModuleExternal = (
|
|
|
498
529
|
};
|
|
499
530
|
|
|
500
531
|
/**
|
|
501
|
-
* @param {string|string[]} urlAndGlobal the script request
|
|
532
|
+
* @param {string | string[]} urlAndGlobal the script request
|
|
502
533
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
503
534
|
* @returns {SourceData} the generated source
|
|
504
535
|
*/
|
|
@@ -546,9 +577,9 @@ const checkExternalVariable = (variableName, request, runtimeTemplate) =>
|
|
|
546
577
|
)} }\n`;
|
|
547
578
|
|
|
548
579
|
/**
|
|
549
|
-
* @param {string
|
|
580
|
+
* @param {ModuleId | string} id the module id
|
|
550
581
|
* @param {boolean} optional true, if the module is optional
|
|
551
|
-
* @param {string|string[]} request the request path
|
|
582
|
+
* @param {string | string[]} request the request path
|
|
552
583
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
553
584
|
* @returns {SourceData} the generated source
|
|
554
585
|
*/
|
|
@@ -575,7 +606,7 @@ const getSourceForAmdOrUmdExternal = (
|
|
|
575
606
|
|
|
576
607
|
/**
|
|
577
608
|
* @param {boolean} optional true, if the module is optional
|
|
578
|
-
* @param {string|string[]} request the request path
|
|
609
|
+
* @param {string | string[]} request the request path
|
|
579
610
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
580
611
|
* @returns {SourceData} the generated source
|
|
581
612
|
*/
|
|
@@ -596,10 +627,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|
|
596
627
|
};
|
|
597
628
|
|
|
598
629
|
/** @typedef {Record<string, string | string[]>} RequestRecord */
|
|
630
|
+
/** @typedef {string | string[] | RequestRecord} ExternalModuleRequest */
|
|
599
631
|
|
|
600
632
|
class ExternalModule extends Module {
|
|
601
633
|
/**
|
|
602
|
-
* @param {
|
|
634
|
+
* @param {ExternalModuleRequest} request request
|
|
603
635
|
* @param {string} type type
|
|
604
636
|
* @param {string} userRequest user request
|
|
605
637
|
* @param {DependencyMeta=} dependencyMeta dependency meta
|
|
@@ -608,7 +640,7 @@ class ExternalModule extends Module {
|
|
|
608
640
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
|
609
641
|
|
|
610
642
|
// Info from Factory
|
|
611
|
-
/** @type {
|
|
643
|
+
/** @type {ExternalModuleRequest} */
|
|
612
644
|
this.request = request;
|
|
613
645
|
/** @type {string} */
|
|
614
646
|
this.externalType = type;
|
|
@@ -638,7 +670,7 @@ class ExternalModule extends Module {
|
|
|
638
670
|
|
|
639
671
|
/**
|
|
640
672
|
* @param {LibIdentOptions} options options
|
|
641
|
-
* @returns {
|
|
673
|
+
* @returns {LibIdent | null} an identifier for library inclusion
|
|
642
674
|
*/
|
|
643
675
|
libIdent(options) {
|
|
644
676
|
return this.userRequest;
|
|
@@ -1020,9 +1052,7 @@ class ExternalModule extends Module {
|
|
|
1020
1052
|
scope.registerRawExport(specifier, finalName);
|
|
1021
1053
|
}
|
|
1022
1054
|
} else if (concatenationScope) {
|
|
1023
|
-
sourceString = `${
|
|
1024
|
-
runtimeTemplate.supportsConst() ? "const" : "var"
|
|
1025
|
-
} ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
|
|
1055
|
+
sourceString = `${runtimeTemplate.renderConst()} ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
|
|
1026
1056
|
concatenationScope.registerNamespaceExport(
|
|
1027
1057
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
1028
1058
|
);
|
|
@@ -1126,3 +1156,5 @@ makeSerializable(ExternalModule, "webpack/lib/ExternalModule");
|
|
|
1126
1156
|
|
|
1127
1157
|
module.exports = ExternalModule;
|
|
1128
1158
|
module.exports.ModuleExternalInitFragment = ModuleExternalInitFragment;
|
|
1159
|
+
module.exports.getExternalModuleNodeCommonjsInitFragment =
|
|
1160
|
+
getExternalModuleNodeCommonjsInitFragment;
|
|
@@ -14,16 +14,33 @@ const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency"
|
|
|
14
14
|
const ImportDependency = require("./dependencies/ImportDependency");
|
|
15
15
|
const { cachedSetProperty, resolveByProperty } = require("./util/cleverMerge");
|
|
16
16
|
|
|
17
|
-
/** @typedef {import("
|
|
17
|
+
/** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
|
|
18
|
+
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
|
19
|
+
/** @typedef {import("../declarations/WebpackOptions").ExternalItemValue} ExternalItemValue */
|
|
18
20
|
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
|
|
19
21
|
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
|
|
20
22
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
|
21
|
-
/** @typedef {import("./Compilation").DepConstructor} DepConstructor */
|
|
22
23
|
/** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
|
|
23
|
-
/** @typedef {import("./Module")} Module */
|
|
24
24
|
/** @typedef {import("./ModuleFactory").IssuerLayer} IssuerLayer */
|
|
25
|
+
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateDataContextInfo} ModuleFactoryCreateDataContextInfo */
|
|
25
26
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
|
26
27
|
|
|
28
|
+
/** @typedef {((context: string, request: string, callback: (err?: Error | null, result?: string | false, resolveRequest?: import('enhanced-resolve').ResolveRequest) => void) => void)} ExternalItemFunctionDataGetResolveCallbackResult */
|
|
29
|
+
/** @typedef {((context: string, request: string) => Promise<string>)} ExternalItemFunctionDataGetResolveResult */
|
|
30
|
+
/** @typedef {(options?: ResolveOptions) => ExternalItemFunctionDataGetResolveCallbackResult | ExternalItemFunctionDataGetResolveResult} ExternalItemFunctionDataGetResolve */
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {object} ExternalItemFunctionData
|
|
34
|
+
* @property {string} context the directory in which the request is placed
|
|
35
|
+
* @property {ModuleFactoryCreateDataContextInfo} contextInfo contextual information
|
|
36
|
+
* @property {string} dependencyType the category of the referencing dependency
|
|
37
|
+
* @property {ExternalItemFunctionDataGetResolve} getResolve get a resolve function with the current resolver options
|
|
38
|
+
* @property {string} request the request as written by the user in the require/import expression/statement
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/** @typedef {((data: ExternalItemFunctionData, callback: (err?: (Error | null), result?: ExternalItemValue) => void) => void)} ExternalItemFunctionCallback */
|
|
42
|
+
/** @typedef {((data: import("../lib/ExternalModuleFactoryPlugin").ExternalItemFunctionData) => Promise<ExternalItemValue>)} ExternalItemFunctionPromise */
|
|
43
|
+
|
|
27
44
|
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9-]+ /;
|
|
28
45
|
const EMPTY_RESOLVE_OPTIONS = {};
|
|
29
46
|
|
|
@@ -79,7 +96,7 @@ const PLUGIN_NAME = "ExternalModuleFactoryPlugin";
|
|
|
79
96
|
|
|
80
97
|
class ExternalModuleFactoryPlugin {
|
|
81
98
|
/**
|
|
82
|
-
* @param {string
|
|
99
|
+
* @param {string} type default external type
|
|
83
100
|
* @param {Externals} externals externals config
|
|
84
101
|
*/
|
|
85
102
|
constructor(type, externals) {
|
|
@@ -140,7 +157,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
140
157
|
}
|
|
141
158
|
}
|
|
142
159
|
|
|
143
|
-
const resolvedType =
|
|
160
|
+
const resolvedType = type || globalType;
|
|
144
161
|
|
|
145
162
|
// TODO make it pluggable/add hooks to `ExternalModule` to allow output modules own externals?
|
|
146
163
|
/** @type {DependencyMeta | undefined} */
|
|
@@ -159,7 +176,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
159
176
|
: undefined;
|
|
160
177
|
|
|
161
178
|
dependencyMeta = {
|
|
162
|
-
attributes: dependency.
|
|
179
|
+
attributes: dependency.attributes,
|
|
163
180
|
externalType
|
|
164
181
|
};
|
|
165
182
|
} else if (dependency instanceof CssImportDependency) {
|
|
@@ -265,6 +282,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
265
282
|
dependencyType,
|
|
266
283
|
contextInfo,
|
|
267
284
|
getResolve: (options) => (context, request, callback) => {
|
|
285
|
+
/** @type {ResolveContext} */
|
|
268
286
|
const resolveContext = {
|
|
269
287
|
fileDependencies: data.fileDependencies,
|
|
270
288
|
missingDependencies: data.missingDependencies,
|
|
@@ -307,7 +325,9 @@ class ExternalModuleFactoryPlugin {
|
|
|
307
325
|
},
|
|
308
326
|
cb
|
|
309
327
|
);
|
|
310
|
-
if (promise && promise.then)
|
|
328
|
+
if (promise && promise.then) {
|
|
329
|
+
promise.then((r) => cb(null, r), cb);
|
|
330
|
+
}
|
|
311
331
|
}
|
|
312
332
|
return;
|
|
313
333
|
} else if (typeof externals === "object") {
|