webpack 5.98.0 → 5.99.1
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 +7 -3
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +326 -152
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +40 -17
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +13 -13
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +50 -8
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +93 -26
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssModulesPlugin.js +30 -5
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +24 -8
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +51 -31
- package/lib/javascript/JavascriptParser.js +287 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -2
- package/lib/json/JsonParser.js +8 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +87 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
package/lib/ExportsInfo.js
CHANGED
@@ -10,6 +10,7 @@ const SortableSet = require("./util/SortableSet");
|
|
10
10
|
const makeSerializable = require("./util/makeSerializable");
|
11
11
|
const { forEachRuntime } = require("./util/runtime");
|
12
12
|
|
13
|
+
/** @typedef {import("./Dependency")} Dependency */
|
13
14
|
/** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
|
14
15
|
/** @typedef {import("./Module")} Module */
|
15
16
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
@@ -34,6 +35,12 @@ const RETURNS_TRUE = () => true;
|
|
34
35
|
const CIRCULAR = Symbol("circular target");
|
35
36
|
|
36
37
|
class RestoreProvidedData {
|
38
|
+
/**
|
39
|
+
* @param {TODO[]} exports exports
|
40
|
+
* @param {ExportInfo["provided"]} otherProvided other provided
|
41
|
+
* @param {ExportInfo["canMangleProvide"]} otherCanMangleProvide other can mangle provide
|
42
|
+
* @param {ExportInfo["terminalBinding"]} otherTerminalBinding other terminal binding
|
43
|
+
*/
|
37
44
|
constructor(
|
38
45
|
exports,
|
39
46
|
otherProvided,
|
@@ -78,7 +85,7 @@ class ExportsInfo {
|
|
78
85
|
constructor() {
|
79
86
|
/** @type {Exports} */
|
80
87
|
this._exports = new Map();
|
81
|
-
this._otherExportsInfo = new ExportInfo(null);
|
88
|
+
this._otherExportsInfo = new ExportInfo(/** @type {TODO} */ (null));
|
82
89
|
this._sideEffectsOnlyInfo = new ExportInfo("*side effects only*");
|
83
90
|
this._exportsAreOrdered = false;
|
84
91
|
/** @type {ExportsInfo=} */
|
@@ -288,7 +295,7 @@ class ExportsInfo {
|
|
288
295
|
/**
|
289
296
|
* @param {boolean=} canMangle true, if exports can still be mangled (defaults to false)
|
290
297
|
* @param {Set<string>=} excludeExports list of unaffected exports
|
291
|
-
* @param {
|
298
|
+
* @param {Dependency=} targetKey use this as key for the target
|
292
299
|
* @param {ModuleGraphConnection=} targetModule set this module as target
|
293
300
|
* @param {number=} priority priority
|
294
301
|
* @returns {boolean} true, if this call changed something
|
@@ -777,7 +784,7 @@ class ExportsInfo {
|
|
777
784
|
}
|
778
785
|
|
779
786
|
/**
|
780
|
-
* @param {
|
787
|
+
* @param {RestoreProvidedData} data data
|
781
788
|
*/
|
782
789
|
restoreProvided({
|
783
790
|
otherProvided,
|
@@ -809,9 +816,18 @@ class ExportsInfo {
|
|
809
816
|
}
|
810
817
|
}
|
811
818
|
|
819
|
+
/** @typedef {Map<string, RuntimeUsageStateType>} UsedInRuntime */
|
820
|
+
|
812
821
|
/** @typedef {{ module: Module, export: string[] }} TargetItemWithoutConnection */
|
813
|
-
|
814
|
-
/** @typedef {
|
822
|
+
|
823
|
+
/** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItemWithConnection */
|
824
|
+
|
825
|
+
/** @typedef {(target: TargetItemWithConnection) => boolean} ResolveTargetFilter */
|
826
|
+
|
827
|
+
/** @typedef {(module: Module) => boolean} ValidTargetModuleFilter */
|
828
|
+
|
829
|
+
/** @typedef {{ connection: ModuleGraphConnection, export: string[], priority: number }} TargetItem */
|
830
|
+
/** @typedef {Map<Dependency | undefined, TargetItem>} Target */
|
815
831
|
|
816
832
|
class ExportInfo {
|
817
833
|
/**
|
@@ -833,7 +849,7 @@ class ExportInfo {
|
|
833
849
|
this._globalUsed = initFrom ? initFrom._globalUsed : undefined;
|
834
850
|
/**
|
835
851
|
* @private
|
836
|
-
* @type {
|
852
|
+
* @type {UsedInRuntime | undefined}
|
837
853
|
*/
|
838
854
|
this._usedInRuntime =
|
839
855
|
initFrom && initFrom._usedInRuntime
|
@@ -896,7 +912,7 @@ class ExportInfo {
|
|
896
912
|
// TODO webpack 5 remove
|
897
913
|
/**
|
898
914
|
* @private
|
899
|
-
* @param {
|
915
|
+
* @param {EXPECTED_ANY} v v
|
900
916
|
*/
|
901
917
|
set used(v) {
|
902
918
|
throw new Error("REMOVED");
|
@@ -911,7 +927,7 @@ class ExportInfo {
|
|
911
927
|
// TODO webpack 5 remove
|
912
928
|
/**
|
913
929
|
* @private
|
914
|
-
* @param {
|
930
|
+
* @param {EXPECTED_ANY} v v
|
915
931
|
*/
|
916
932
|
set usedName(v) {
|
917
933
|
throw new Error("REMOVED");
|
@@ -996,7 +1012,7 @@ class ExportInfo {
|
|
996
1012
|
}
|
997
1013
|
|
998
1014
|
/**
|
999
|
-
* @param {
|
1015
|
+
* @param {(condition: UsageStateType) => boolean} condition compare with old value
|
1000
1016
|
* @param {UsageStateType} newValue set when condition is true
|
1001
1017
|
* @param {RuntimeSpec} runtime only apply to this runtime
|
1002
1018
|
* @returns {boolean} true when something has changed
|
@@ -1015,7 +1031,8 @@ class ExportInfo {
|
|
1015
1031
|
if (newValue !== UsageState.Unused && condition(UsageState.Unused)) {
|
1016
1032
|
this._usedInRuntime = new Map();
|
1017
1033
|
forEachRuntime(runtime, runtime =>
|
1018
|
-
|
1034
|
+
/** @type {UsedInRuntime} */
|
1035
|
+
(this._usedInRuntime).set(/** @type {string} */ (runtime), newValue)
|
1019
1036
|
);
|
1020
1037
|
return true;
|
1021
1038
|
}
|
@@ -1023,15 +1040,18 @@ class ExportInfo {
|
|
1023
1040
|
let changed = false;
|
1024
1041
|
forEachRuntime(runtime, _runtime => {
|
1025
1042
|
const runtime = /** @type {string} */ (_runtime);
|
1043
|
+
const usedInRuntime =
|
1044
|
+
/** @type {UsedInRuntime} */
|
1045
|
+
(this._usedInRuntime);
|
1026
1046
|
let oldValue =
|
1027
1047
|
/** @type {UsageStateType} */
|
1028
|
-
(
|
1048
|
+
(usedInRuntime.get(runtime));
|
1029
1049
|
if (oldValue === undefined) oldValue = UsageState.Unused;
|
1030
1050
|
if (newValue !== oldValue && condition(oldValue)) {
|
1031
1051
|
if (newValue === UsageState.Unused) {
|
1032
|
-
|
1052
|
+
usedInRuntime.delete(runtime);
|
1033
1053
|
} else {
|
1034
|
-
|
1054
|
+
usedInRuntime.set(runtime, newValue);
|
1035
1055
|
}
|
1036
1056
|
changed = true;
|
1037
1057
|
}
|
@@ -1059,7 +1079,8 @@ class ExportInfo {
|
|
1059
1079
|
if (newValue !== UsageState.Unused) {
|
1060
1080
|
this._usedInRuntime = new Map();
|
1061
1081
|
forEachRuntime(runtime, runtime =>
|
1062
|
-
|
1082
|
+
/** @type {UsedInRuntime} */
|
1083
|
+
(this._usedInRuntime).set(/** @type {string} */ (runtime), newValue)
|
1063
1084
|
);
|
1064
1085
|
return true;
|
1065
1086
|
}
|
@@ -1067,15 +1088,18 @@ class ExportInfo {
|
|
1067
1088
|
let changed = false;
|
1068
1089
|
forEachRuntime(runtime, _runtime => {
|
1069
1090
|
const runtime = /** @type {string} */ (_runtime);
|
1091
|
+
const usedInRuntime =
|
1092
|
+
/** @type {UsedInRuntime} */
|
1093
|
+
(this._usedInRuntime);
|
1070
1094
|
let oldValue =
|
1071
1095
|
/** @type {UsageStateType} */
|
1072
|
-
(
|
1096
|
+
(usedInRuntime.get(runtime));
|
1073
1097
|
if (oldValue === undefined) oldValue = UsageState.Unused;
|
1074
1098
|
if (newValue !== oldValue) {
|
1075
1099
|
if (newValue === UsageState.Unused) {
|
1076
|
-
|
1100
|
+
usedInRuntime.delete(runtime);
|
1077
1101
|
} else {
|
1078
|
-
|
1102
|
+
usedInRuntime.set(runtime, newValue);
|
1079
1103
|
}
|
1080
1104
|
changed = true;
|
1081
1105
|
}
|
@@ -1089,7 +1113,7 @@ class ExportInfo {
|
|
1089
1113
|
}
|
1090
1114
|
|
1091
1115
|
/**
|
1092
|
-
* @param {
|
1116
|
+
* @param {Dependency} key the key
|
1093
1117
|
* @returns {boolean} true, if something has changed
|
1094
1118
|
*/
|
1095
1119
|
unsetTarget(key) {
|
@@ -1102,7 +1126,7 @@ class ExportInfo {
|
|
1102
1126
|
}
|
1103
1127
|
|
1104
1128
|
/**
|
1105
|
-
* @param {
|
1129
|
+
* @param {Dependency} key the key
|
1106
1130
|
* @param {ModuleGraphConnection} connection the target module if a single one
|
1107
1131
|
* @param {(string[] | null)=} exportName the exported name
|
1108
1132
|
* @param {number=} priority priority
|
@@ -1203,7 +1227,8 @@ class ExportInfo {
|
|
1203
1227
|
} else if (
|
1204
1228
|
runtime !== undefined &&
|
1205
1229
|
Array.from(runtime).every(
|
1206
|
-
runtime =>
|
1230
|
+
runtime =>
|
1231
|
+
!(/** @type {UsedInRuntime} */ (this._usedInRuntime).has(runtime))
|
1207
1232
|
)
|
1208
1233
|
) {
|
1209
1234
|
return false;
|
@@ -1232,7 +1257,7 @@ class ExportInfo {
|
|
1232
1257
|
|
1233
1258
|
/**
|
1234
1259
|
* @param {ModuleGraph} moduleGraph the module graph
|
1235
|
-
* @param {
|
1260
|
+
* @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target
|
1236
1261
|
* @returns {ExportInfo | ExportsInfo | undefined} the terminal binding export(s) info if known
|
1237
1262
|
*/
|
1238
1263
|
getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
@@ -1262,6 +1287,7 @@ class ExportInfo {
|
|
1262
1287
|
if (maxPriority === minPriority) return (this._maxTarget = this._target);
|
1263
1288
|
|
1264
1289
|
// This is an edge case
|
1290
|
+
/** @type {Target} */
|
1265
1291
|
const map = new Map();
|
1266
1292
|
for (const [key, value] of /** @type {Target} */ (this._target)) {
|
1267
1293
|
if (maxPriority === value.priority) {
|
@@ -1274,7 +1300,7 @@ class ExportInfo {
|
|
1274
1300
|
|
1275
1301
|
/**
|
1276
1302
|
* @param {ModuleGraph} moduleGraph the module graph
|
1277
|
-
* @param {
|
1303
|
+
* @param {ValidTargetModuleFilter} validTargetModuleFilter a valid target module
|
1278
1304
|
* @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
|
1279
1305
|
*/
|
1280
1306
|
findTarget(moduleGraph, validTargetModuleFilter) {
|
@@ -1283,7 +1309,7 @@ class ExportInfo {
|
|
1283
1309
|
|
1284
1310
|
/**
|
1285
1311
|
* @param {ModuleGraph} moduleGraph the module graph
|
1286
|
-
* @param {
|
1312
|
+
* @param {ValidTargetModuleFilter} validTargetModuleFilter a valid target module
|
1287
1313
|
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
1288
1314
|
* @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
|
1289
1315
|
*/
|
@@ -1324,8 +1350,8 @@ class ExportInfo {
|
|
1324
1350
|
|
1325
1351
|
/**
|
1326
1352
|
* @param {ModuleGraph} moduleGraph the module graph
|
1327
|
-
* @param {
|
1328
|
-
* @returns {
|
1353
|
+
* @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target
|
1354
|
+
* @returns {TargetItemWithConnection | undefined} the target
|
1329
1355
|
*/
|
1330
1356
|
getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
1331
1357
|
const result = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
@@ -1335,15 +1361,15 @@ class ExportInfo {
|
|
1335
1361
|
|
1336
1362
|
/**
|
1337
1363
|
* @param {ModuleGraph} moduleGraph the module graph
|
1338
|
-
* @param {
|
1364
|
+
* @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target
|
1339
1365
|
* @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
|
1340
|
-
* @returns {
|
1366
|
+
* @returns {TargetItemWithConnection | CIRCULAR | undefined} the target
|
1341
1367
|
*/
|
1342
1368
|
_getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) {
|
1343
1369
|
/**
|
1344
|
-
* @param {TargetItem | null} inputTarget unresolved target
|
1370
|
+
* @param {TargetItem | undefined | null} inputTarget unresolved target
|
1345
1371
|
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
1346
|
-
* @returns {
|
1372
|
+
* @returns {TargetItemWithConnection | CIRCULAR | null} resolved target
|
1347
1373
|
*/
|
1348
1374
|
const resolveTarget = (inputTarget, alreadyVisited) => {
|
1349
1375
|
if (!inputTarget) return null;
|
@@ -1354,7 +1380,7 @@ class ExportInfo {
|
|
1354
1380
|
export: undefined
|
1355
1381
|
};
|
1356
1382
|
}
|
1357
|
-
/** @type {
|
1383
|
+
/** @type {TargetItemWithConnection} */
|
1358
1384
|
let target = {
|
1359
1385
|
module: inputTarget.connection.module,
|
1360
1386
|
connection: inputTarget.connection,
|
@@ -1365,7 +1391,7 @@ class ExportInfo {
|
|
1365
1391
|
for (;;) {
|
1366
1392
|
const exportsInfo = moduleGraph.getExportsInfo(target.module);
|
1367
1393
|
const exportInfo = exportsInfo.getExportInfo(
|
1368
|
-
/** @type {NonNullable<
|
1394
|
+
/** @type {NonNullable<TargetItemWithConnection["export"]>} */
|
1369
1395
|
(target.export)[0]
|
1370
1396
|
);
|
1371
1397
|
if (!exportInfo) return target;
|
@@ -1378,7 +1404,7 @@ class ExportInfo {
|
|
1378
1404
|
if (newTarget === CIRCULAR) return CIRCULAR;
|
1379
1405
|
if (!newTarget) return target;
|
1380
1406
|
if (
|
1381
|
-
/** @type {NonNullable<
|
1407
|
+
/** @type {NonNullable<TargetItemWithConnection["export"]>} */
|
1382
1408
|
(target.export).length === 1
|
1383
1409
|
) {
|
1384
1410
|
target = newTarget;
|
@@ -1389,10 +1415,10 @@ class ExportInfo {
|
|
1389
1415
|
connection: newTarget.connection,
|
1390
1416
|
export: newTarget.export
|
1391
1417
|
? newTarget.export.concat(
|
1392
|
-
/** @type {NonNullable<
|
1418
|
+
/** @type {NonNullable<TargetItemWithConnection["export"]>} */
|
1393
1419
|
(target.export).slice(1)
|
1394
1420
|
)
|
1395
|
-
: /** @type {NonNullable<
|
1421
|
+
: /** @type {NonNullable<TargetItemWithConnection["export"]>} */
|
1396
1422
|
(target.export).slice(1)
|
1397
1423
|
};
|
1398
1424
|
}
|
@@ -1433,17 +1459,20 @@ class ExportInfo {
|
|
1433
1459
|
/**
|
1434
1460
|
* Move the target forward as long resolveTargetFilter is fulfilled
|
1435
1461
|
* @param {ModuleGraph} moduleGraph the module graph
|
1436
|
-
* @param {
|
1437
|
-
* @param {
|
1438
|
-
* @returns {
|
1462
|
+
* @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target
|
1463
|
+
* @param {(target: TargetItemWithConnection) => ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection
|
1464
|
+
* @returns {TargetItemWithConnection | undefined} the resolved target when moved
|
1439
1465
|
*/
|
1440
1466
|
moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) {
|
1441
1467
|
const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
1442
1468
|
if (target === CIRCULAR) return;
|
1443
1469
|
if (!target) return;
|
1444
1470
|
const originalTarget =
|
1445
|
-
/** @type {
|
1446
|
-
(
|
1471
|
+
/** @type {TargetItem} */
|
1472
|
+
(
|
1473
|
+
/** @type {Target} */
|
1474
|
+
(this._getMaxTarget()).values().next().value
|
1475
|
+
);
|
1447
1476
|
if (
|
1448
1477
|
originalTarget.connection === target.connection &&
|
1449
1478
|
originalTarget.export === target.export
|
@@ -1457,7 +1486,9 @@ class ExportInfo {
|
|
1457
1486
|
connection: updateOriginalConnection
|
1458
1487
|
? updateOriginalConnection(target)
|
1459
1488
|
: target.connection,
|
1460
|
-
export: /** @type {NonNullable<
|
1489
|
+
export: /** @type {NonNullable<TargetItemWithConnection["export"]>} */ (
|
1490
|
+
target.export
|
1491
|
+
),
|
1461
1492
|
priority: 0
|
1462
1493
|
});
|
1463
1494
|
return target;
|
@@ -1622,3 +1653,4 @@ class ExportInfo {
|
|
1622
1653
|
module.exports = ExportsInfo;
|
1623
1654
|
module.exports.ExportInfo = ExportInfo;
|
1624
1655
|
module.exports.UsageState = UsageState;
|
1656
|
+
module.exports.RestoreProvidedData = RestoreProvidedData;
|
package/lib/ExternalModule.js
CHANGED
@@ -19,6 +19,7 @@ const {
|
|
19
19
|
const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
|
20
20
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
21
21
|
const Template = require("./Template");
|
22
|
+
const { DEFAULTS } = require("./config/defaults");
|
22
23
|
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
|
23
24
|
const createHash = require("./util/createHash");
|
24
25
|
const extractUrlAndGlobal = require("./util/extractUrlAndGlobal");
|
@@ -31,16 +32,19 @@ const { register } = require("./util/serialization");
|
|
31
32
|
/** @typedef {import("./Chunk")} Chunk */
|
32
33
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
33
34
|
/** @typedef {import("./Compilation")} Compilation */
|
35
|
+
/** @typedef {import("./Compilation").UnsafeCacheData} UnsafeCacheData */
|
34
36
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
35
37
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
36
38
|
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
37
39
|
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
38
40
|
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
41
|
+
/** @typedef {import("./Module").BuildCallback} BuildCallback */
|
39
42
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
40
43
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
41
44
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
42
45
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
43
46
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
47
|
+
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
|
44
48
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
45
49
|
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
46
50
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
@@ -212,7 +216,7 @@ const getSourceForImportExternal = (
|
|
212
216
|
|
213
217
|
/**
|
214
218
|
* @param {string} key key
|
215
|
-
* @param {
|
219
|
+
* @param {TODO | undefined} value value
|
216
220
|
* @returns {undefined | string} replaced value
|
217
221
|
*/
|
218
222
|
const importAssertionReplacer = (key, value) => {
|
@@ -233,7 +237,12 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
233
237
|
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
234
238
|
* @param {string | HashConstructor=} hashFunction the hash function to use
|
235
239
|
*/
|
236
|
-
constructor(
|
240
|
+
constructor(
|
241
|
+
request,
|
242
|
+
ident,
|
243
|
+
dependencyMeta,
|
244
|
+
hashFunction = DEFAULTS.HASH_FUNCTION
|
245
|
+
) {
|
237
246
|
if (ident === undefined) {
|
238
247
|
ident = Template.toIdentifier(request);
|
239
248
|
if (ident !== request) {
|
@@ -554,7 +563,7 @@ class ExternalModule extends Module {
|
|
554
563
|
|
555
564
|
/**
|
556
565
|
* @param {NeedBuildContext} context context info
|
557
|
-
* @param {
|
566
|
+
* @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
|
558
567
|
* @returns {void}
|
559
568
|
*/
|
560
569
|
needBuild(context, callback) {
|
@@ -566,7 +575,7 @@ class ExternalModule extends Module {
|
|
566
575
|
* @param {Compilation} compilation the compilation
|
567
576
|
* @param {ResolverWithOptions} resolver the resolver
|
568
577
|
* @param {InputFileSystem} fs the file system
|
569
|
-
* @param {
|
578
|
+
* @param {BuildCallback} callback callback function
|
570
579
|
* @returns {void}
|
571
580
|
*/
|
572
581
|
build(options, compilation, resolver, fs, callback) {
|
@@ -647,7 +656,7 @@ class ExternalModule extends Module {
|
|
647
656
|
|
648
657
|
/**
|
649
658
|
* restore unsafe cache data
|
650
|
-
* @param {
|
659
|
+
* @param {UnsafeCacheData} unsafeCacheData data from getUnsafeCacheData
|
651
660
|
* @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
652
661
|
*/
|
653
662
|
restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
@@ -15,10 +15,13 @@ const ImportDependency = require("./dependencies/ImportDependency");
|
|
15
15
|
const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
|
16
16
|
|
17
17
|
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionData} ExternalItemFunctionData */
|
18
|
+
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
|
19
|
+
/** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
|
18
20
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
19
21
|
/** @typedef {import("./Compilation").DepConstructor} DepConstructor */
|
20
22
|
/** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
|
21
23
|
/** @typedef {import("./Module")} Module */
|
24
|
+
/** @typedef {import("./ModuleFactory").IssuerLayer} IssuerLayer */
|
22
25
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
23
26
|
|
24
27
|
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9-]+ /;
|
@@ -27,7 +30,7 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|
27
30
|
// TODO webpack 6 remove this
|
28
31
|
const callDeprecatedExternals = util.deprecate(
|
29
32
|
/**
|
30
|
-
* @param {
|
33
|
+
* @param {EXPECTED_FUNCTION} externalsFunction externals function
|
31
34
|
* @param {string} context context
|
32
35
|
* @param {string} request request
|
33
36
|
* @param {(err: Error | null | undefined, value: ExternalValue | undefined, ty: ExternalType | undefined) => void} cb cb
|
@@ -40,19 +43,26 @@ const callDeprecatedExternals = util.deprecate(
|
|
40
43
|
"DEP_WEBPACK_EXTERNALS_FUNCTION_PARAMETERS"
|
41
44
|
);
|
42
45
|
|
46
|
+
/** @typedef {ExternalItemObjectKnown & ExternalItemObjectUnknown} ExternalItemObject */
|
47
|
+
|
48
|
+
/**
|
49
|
+
* @template {ExternalItemObject} T
|
50
|
+
* @typedef {WeakMap<T, Map<IssuerLayer, Omit<T, "byLayer">>>} ExternalWeakCache
|
51
|
+
*/
|
52
|
+
|
53
|
+
/** @type {ExternalWeakCache<ExternalItemObject>} */
|
43
54
|
const cache = new WeakMap();
|
44
55
|
|
45
56
|
/**
|
46
|
-
* @
|
47
|
-
* @param {
|
48
|
-
* @
|
49
|
-
* @returns {Omit<T, "byLayer">} result
|
57
|
+
* @param {ExternalItemObject} obj obj
|
58
|
+
* @param {IssuerLayer} layer layer
|
59
|
+
* @returns {Omit<ExternalItemObject, "byLayer">} result
|
50
60
|
*/
|
51
61
|
const resolveLayer = (obj, layer) => {
|
52
|
-
let map = cache.get(
|
62
|
+
let map = cache.get(obj);
|
53
63
|
if (map === undefined) {
|
54
64
|
map = new Map();
|
55
|
-
cache.set(
|
65
|
+
cache.set(obj, map);
|
56
66
|
} else {
|
57
67
|
const cacheEntry = map.get(layer);
|
58
68
|
if (cacheEntry !== undefined) return cacheEntry;
|
@@ -89,10 +99,12 @@ class ExternalModuleFactoryPlugin {
|
|
89
99
|
const dependency = data.dependencies[0];
|
90
100
|
const dependencyType = data.dependencyType;
|
91
101
|
|
102
|
+
/** @typedef {(err?: Error | null, externalModule?: ExternalModule) => void} HandleExternalCallback */
|
103
|
+
|
92
104
|
/**
|
93
105
|
* @param {ExternalValue} value the external config
|
94
106
|
* @param {ExternalType | undefined} type type of external
|
95
|
-
* @param {
|
107
|
+
* @param {HandleExternalCallback} callback callback
|
96
108
|
* @returns {void}
|
97
109
|
*/
|
98
110
|
const handleExternal = (value, type, callback) => {
|
@@ -176,7 +188,7 @@ class ExternalModuleFactoryPlugin {
|
|
176
188
|
|
177
189
|
/**
|
178
190
|
* @param {Externals} externals externals config
|
179
|
-
* @param {
|
191
|
+
* @param {HandleExternalCallback} callback callback
|
180
192
|
* @returns {void}
|
181
193
|
*/
|
182
194
|
const handleExternals = (externals, callback) => {
|
@@ -273,8 +285,7 @@ class ExternalModuleFactoryPlugin {
|
|
273
285
|
context,
|
274
286
|
request,
|
275
287
|
resolveContext,
|
276
|
-
|
277
|
-
(callback)
|
288
|
+
callback
|
278
289
|
);
|
279
290
|
} else {
|
280
291
|
return new Promise((resolve, reject) => {
|
@@ -300,7 +311,8 @@ class ExternalModuleFactoryPlugin {
|
|
300
311
|
} else if (typeof externals === "object") {
|
301
312
|
const resolvedExternals = resolveLayer(
|
302
313
|
externals,
|
303
|
-
|
314
|
+
/** @type {IssuerLayer} */
|
315
|
+
(contextInfo.issuerLayer)
|
304
316
|
);
|
305
317
|
if (
|
306
318
|
Object.prototype.hasOwnProperty.call(
|