webpack 5.90.3 → 5.92.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1826 -639
@@ -17,6 +17,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
|
|
17
17
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
18
18
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
19
19
|
/** @typedef {import("./Compiler")} Compiler */
|
20
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
20
21
|
|
21
22
|
const validate = createSchemaValidation(
|
22
23
|
require("../schemas/plugins/DllReferencePlugin.check.js"),
|
@@ -34,7 +35,7 @@ class DllReferencePlugin {
|
|
34
35
|
constructor(options) {
|
35
36
|
validate(options);
|
36
37
|
this.options = options;
|
37
|
-
/** @type {WeakMap<
|
38
|
+
/** @type {WeakMap<object, {path: string, data: DllReferencePluginOptionsManifest?, error: Error?}>} */
|
38
39
|
this._compilationData = new WeakMap();
|
39
40
|
}
|
40
41
|
|
@@ -60,7 +61,8 @@ class DllReferencePlugin {
|
|
60
61
|
if ("manifest" in this.options) {
|
61
62
|
const manifest = this.options.manifest;
|
62
63
|
if (typeof manifest === "string") {
|
63
|
-
|
64
|
+
/** @type {InputFileSystem} */
|
65
|
+
(compiler.inputFileSystem).readFile(manifest, (err, result) => {
|
64
66
|
if (err) return callback(err);
|
65
67
|
const data = {
|
66
68
|
path: manifest,
|
@@ -70,7 +72,9 @@ class DllReferencePlugin {
|
|
70
72
|
// Catch errors parsing the manifest so that blank
|
71
73
|
// or malformed manifest files don't kill the process.
|
72
74
|
try {
|
73
|
-
data.data = parseJson(
|
75
|
+
data.data = parseJson(
|
76
|
+
/** @type {Buffer} */ (result).toString("utf-8")
|
77
|
+
);
|
74
78
|
} catch (e) {
|
75
79
|
// Store the error in the params so that it can
|
76
80
|
// be added as a compilation error later on.
|
package/lib/EntryOptionPlugin.js
CHANGED
@@ -41,7 +41,10 @@ class EntryOptionPlugin {
|
|
41
41
|
name,
|
42
42
|
desc
|
43
43
|
);
|
44
|
-
|
44
|
+
const descImport =
|
45
|
+
/** @type {Exclude<EntryDescription["import"], undefined>} */
|
46
|
+
(desc.import);
|
47
|
+
for (const entry of descImport) {
|
45
48
|
new EntryPlugin(context, entry, options).apply(compiler);
|
46
49
|
}
|
47
50
|
}
|
package/lib/EntryPlugin.js
CHANGED
@@ -59,7 +59,12 @@ class EntryPlugin {
|
|
59
59
|
static createDependency(entry, options) {
|
60
60
|
const dep = new EntryDependency(entry);
|
61
61
|
// TODO webpack 6 remove string option
|
62
|
-
dep.loc = {
|
62
|
+
dep.loc = {
|
63
|
+
name:
|
64
|
+
typeof options === "object"
|
65
|
+
? /** @type {string} */ (options.name)
|
66
|
+
: options
|
67
|
+
};
|
63
68
|
return dep;
|
64
69
|
}
|
65
70
|
}
|
package/lib/Entrypoint.js
CHANGED
@@ -89,7 +89,7 @@ class Entrypoint extends ChunkGroup {
|
|
89
89
|
/**
|
90
90
|
* @param {Chunk} oldChunk chunk to be replaced
|
91
91
|
* @param {Chunk} newChunk New chunk that will be replaced with
|
92
|
-
* @returns {boolean} returns true if the replacement was successful
|
92
|
+
* @returns {boolean | undefined} returns true if the replacement was successful
|
93
93
|
*/
|
94
94
|
replaceChunk(oldChunk, newChunk) {
|
95
95
|
if (this._runtimeChunk === oldChunk) this._runtimeChunk = newChunk;
|
@@ -12,6 +12,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
|
|
12
12
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
13
13
|
|
14
14
|
/** @typedef {import("webpack-sources").Source} Source */
|
15
|
+
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
15
16
|
/** @typedef {import("./Compiler")} Compiler */
|
16
17
|
|
17
18
|
/** @type {WeakMap<Source, Source>} */
|
@@ -27,7 +28,17 @@ const devtoolWarning = new RawSource(`/*
|
|
27
28
|
*/
|
28
29
|
`);
|
29
30
|
|
31
|
+
/**
|
32
|
+
* @typedef {object} EvalDevToolModulePluginOptions
|
33
|
+
* @property {OutputOptions["devtoolNamespace"]=} namespace namespace
|
34
|
+
* @property {string=} sourceUrlComment source url comment
|
35
|
+
* @property {OutputOptions["devtoolModuleFilenameTemplate"]=} moduleFilenameTemplate module filename template
|
36
|
+
*/
|
37
|
+
|
30
38
|
class EvalDevToolModulePlugin {
|
39
|
+
/**
|
40
|
+
* @param {EvalDevToolModulePluginOptions=} options options
|
41
|
+
*/
|
31
42
|
constructor(options) {
|
32
43
|
this.namespace = options.namespace || "";
|
33
44
|
this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
|
package/lib/ExportsInfo.js
CHANGED
@@ -171,6 +171,10 @@ class ExportsInfo {
|
|
171
171
|
this._exportsAreOrdered = true;
|
172
172
|
}
|
173
173
|
|
174
|
+
/**
|
175
|
+
* @param {ExportsInfo | undefined} exportsInfo exports info
|
176
|
+
* @returns {boolean} result
|
177
|
+
*/
|
174
178
|
setRedirectNamedTo(exportsInfo) {
|
175
179
|
if (this._redirectTo === exportsInfo) return false;
|
176
180
|
this._redirectTo = exportsInfo;
|
@@ -207,9 +211,6 @@ class ExportsInfo {
|
|
207
211
|
this._redirectTo.setHasUseInfo();
|
208
212
|
} else {
|
209
213
|
this._otherExportsInfo.setHasUseInfo();
|
210
|
-
if (this._otherExportsInfo.canMangleUse === undefined) {
|
211
|
-
this._otherExportsInfo.canMangleUse = true;
|
212
|
-
}
|
213
214
|
}
|
214
215
|
}
|
215
216
|
|
@@ -479,6 +480,7 @@ class ExportsInfo {
|
|
479
480
|
* @returns {SortableSet<string> | boolean | null} set of used exports, or true (when namespace object is used), or false (when unused), or null (when unknown)
|
480
481
|
*/
|
481
482
|
getUsedExports(runtime) {
|
483
|
+
// eslint-disable-next-line no-constant-binary-expression
|
482
484
|
if (!this._redirectTo !== undefined) {
|
483
485
|
switch (this._otherExportsInfo.getUsed(runtime)) {
|
484
486
|
case UsageState.NoInfo:
|
@@ -527,6 +529,7 @@ class ExportsInfo {
|
|
527
529
|
* @returns {null | true | string[]} list of exports when known
|
528
530
|
*/
|
529
531
|
getProvidedExports() {
|
532
|
+
// eslint-disable-next-line no-constant-binary-expression
|
530
533
|
if (!this._redirectTo !== undefined) {
|
531
534
|
switch (this._otherExportsInfo.provided) {
|
532
535
|
case undefined:
|
@@ -670,7 +673,7 @@ class ExportsInfo {
|
|
670
673
|
}
|
671
674
|
|
672
675
|
/**
|
673
|
-
* @param {string | string[]} name the export name
|
676
|
+
* @param {string | string[] | undefined} name the export name
|
674
677
|
* @param {RuntimeSpec} runtime check usage for this runtime only
|
675
678
|
* @returns {string | string[] | false} the used name
|
676
679
|
*/
|
@@ -807,16 +810,28 @@ class ExportInfo {
|
|
807
810
|
constructor(name, initFrom) {
|
808
811
|
/** @type {string} */
|
809
812
|
this.name = name;
|
810
|
-
/**
|
813
|
+
/**
|
814
|
+
* @private
|
815
|
+
* @type {string | null}
|
816
|
+
*/
|
811
817
|
this._usedName = initFrom ? initFrom._usedName : null;
|
812
|
-
/**
|
818
|
+
/**
|
819
|
+
* @private
|
820
|
+
* @type {UsageStateType}
|
821
|
+
*/
|
813
822
|
this._globalUsed = initFrom ? initFrom._globalUsed : undefined;
|
814
|
-
/**
|
823
|
+
/**
|
824
|
+
* @private
|
825
|
+
* @type {Map<string, RuntimeUsageStateType>}
|
826
|
+
*/
|
815
827
|
this._usedInRuntime =
|
816
828
|
initFrom && initFrom._usedInRuntime
|
817
829
|
? new Map(initFrom._usedInRuntime)
|
818
830
|
: undefined;
|
819
|
-
/**
|
831
|
+
/**
|
832
|
+
* @private
|
833
|
+
* @type {boolean}
|
834
|
+
*/
|
820
835
|
this._hasUseInRuntimeInfo = initFrom
|
821
836
|
? initFrom._hasUseInRuntimeInfo
|
822
837
|
: false;
|
package/lib/ExternalModule.js
CHANGED
@@ -29,18 +29,23 @@ const { register } = require("./util/serialization");
|
|
29
29
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
30
30
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
31
31
|
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
32
|
+
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
33
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
32
34
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
33
35
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
34
36
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
35
37
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
36
38
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
39
|
+
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
37
40
|
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
41
|
+
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
38
42
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
39
43
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
40
44
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
41
45
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
42
46
|
/** @typedef {import("./WebpackError")} WebpackError */
|
43
47
|
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
48
|
+
/** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
44
49
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
45
50
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
46
51
|
/** @typedef {import("./util/Hash")} Hash */
|
@@ -48,13 +53,18 @@ const { register } = require("./util/serialization");
|
|
48
53
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
49
54
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
50
55
|
|
56
|
+
/** @typedef {{ attributes?: ImportAttributes }} ImportDependencyMeta */
|
57
|
+
/** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
|
58
|
+
|
59
|
+
/** @typedef {ImportDependencyMeta | CssImportDependencyMeta} DependencyMeta */
|
60
|
+
|
51
61
|
/**
|
52
|
-
* @typedef {
|
62
|
+
* @typedef {object} SourceData
|
53
63
|
* @property {boolean=} iife
|
54
64
|
* @property {string=} init
|
55
65
|
* @property {string} expression
|
56
66
|
* @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
|
57
|
-
* @property {
|
67
|
+
* @property {ReadOnlyRuntimeRequirements=} runtimeRequirements
|
58
68
|
*/
|
59
69
|
|
60
70
|
const TYPES = new Set(["javascript"]);
|
@@ -107,15 +117,19 @@ const getSourceForCommonJsExternal = moduleAndSpecifiers => {
|
|
107
117
|
/**
|
108
118
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
109
119
|
* @param {string} importMetaName import.meta name
|
120
|
+
* @param {boolean} needPrefix need to use `node:` prefix for `module` import
|
110
121
|
* @returns {SourceData} the generated source
|
111
122
|
*/
|
112
123
|
const getSourceForCommonJsExternalInNodeModule = (
|
113
124
|
moduleAndSpecifiers,
|
114
|
-
importMetaName
|
125
|
+
importMetaName,
|
126
|
+
needPrefix
|
115
127
|
) => {
|
116
128
|
const chunkInitFragments = [
|
117
129
|
new InitFragment(
|
118
|
-
|
130
|
+
`import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "${
|
131
|
+
needPrefix ? "node:" : ""
|
132
|
+
}module";\n`,
|
119
133
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
120
134
|
0,
|
121
135
|
"external module node-commonjs"
|
@@ -141,43 +155,78 @@ const getSourceForCommonJsExternalInNodeModule = (
|
|
141
155
|
/**
|
142
156
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
143
157
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
158
|
+
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
144
159
|
* @returns {SourceData} the generated source
|
145
160
|
*/
|
146
|
-
const getSourceForImportExternal = (
|
161
|
+
const getSourceForImportExternal = (
|
162
|
+
moduleAndSpecifiers,
|
163
|
+
runtimeTemplate,
|
164
|
+
dependencyMeta
|
165
|
+
) => {
|
147
166
|
const importName = runtimeTemplate.outputOptions.importFunctionName;
|
148
167
|
if (!runtimeTemplate.supportsDynamicImport() && importName === "import") {
|
149
168
|
throw new Error(
|
150
169
|
"The target environment doesn't support 'import()' so it's not possible to use external type 'import'"
|
151
170
|
);
|
152
171
|
}
|
172
|
+
const attributes =
|
173
|
+
dependencyMeta && dependencyMeta.attributes
|
174
|
+
? dependencyMeta.attributes._isLegacyAssert
|
175
|
+
? `, { assert: ${JSON.stringify(
|
176
|
+
dependencyMeta.attributes,
|
177
|
+
importAssertionReplacer
|
178
|
+
)} }`
|
179
|
+
: `, { with: ${JSON.stringify(dependencyMeta.attributes)} }`
|
180
|
+
: "";
|
153
181
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
154
182
|
return {
|
155
|
-
expression: `${importName}(${JSON.stringify(
|
183
|
+
expression: `${importName}(${JSON.stringify(
|
184
|
+
moduleAndSpecifiers
|
185
|
+
)}${attributes});`
|
156
186
|
};
|
157
187
|
}
|
158
188
|
if (moduleAndSpecifiers.length === 1) {
|
159
189
|
return {
|
160
|
-
expression: `${importName}(${JSON.stringify(
|
190
|
+
expression: `${importName}(${JSON.stringify(
|
191
|
+
moduleAndSpecifiers[0]
|
192
|
+
)}${attributes});`
|
161
193
|
};
|
162
194
|
}
|
163
195
|
const moduleName = moduleAndSpecifiers[0];
|
164
196
|
return {
|
165
197
|
expression: `${importName}(${JSON.stringify(
|
166
198
|
moduleName
|
167
|
-
)}).then(${runtimeTemplate.returningFunction(
|
199
|
+
)}${attributes}).then(${runtimeTemplate.returningFunction(
|
168
200
|
`module${propertyAccess(moduleAndSpecifiers, 1)}`,
|
169
201
|
"module"
|
170
202
|
)});`
|
171
203
|
};
|
172
204
|
};
|
173
205
|
|
206
|
+
/**
|
207
|
+
* @param {string} key key
|
208
|
+
* @param {any | undefined} value value
|
209
|
+
* @returns {undefined | string} replaced value
|
210
|
+
*/
|
211
|
+
const importAssertionReplacer = (key, value) => {
|
212
|
+
if (key === "_isLegacyAssert") {
|
213
|
+
return undefined;
|
214
|
+
}
|
215
|
+
|
216
|
+
return value;
|
217
|
+
};
|
218
|
+
|
219
|
+
/**
|
220
|
+
* @extends {InitFragment<ChunkRenderContext>}
|
221
|
+
*/
|
174
222
|
class ModuleExternalInitFragment extends InitFragment {
|
175
223
|
/**
|
176
224
|
* @param {string} request import source
|
177
225
|
* @param {string=} ident recomputed ident
|
226
|
+
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
178
227
|
* @param {string | HashConstructor=} hashFunction the hash function to use
|
179
228
|
*/
|
180
|
-
constructor(request, ident, hashFunction = "md4") {
|
229
|
+
constructor(request, ident, dependencyMeta, hashFunction = "md4") {
|
181
230
|
if (ident === undefined) {
|
182
231
|
ident = Template.toIdentifier(request);
|
183
232
|
if (ident !== request) {
|
@@ -189,14 +238,24 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
189
238
|
}
|
190
239
|
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
191
240
|
super(
|
192
|
-
`import * as ${identifier} from ${JSON.stringify(request)}
|
241
|
+
`import * as ${identifier} from ${JSON.stringify(request)}${
|
242
|
+
dependencyMeta && dependencyMeta.attributes
|
243
|
+
? dependencyMeta.attributes._isLegacyAssert
|
244
|
+
? ` assert ${JSON.stringify(
|
245
|
+
dependencyMeta.attributes,
|
246
|
+
importAssertionReplacer
|
247
|
+
)}`
|
248
|
+
: ` with ${JSON.stringify(dependencyMeta.attributes)}`
|
249
|
+
: ""
|
250
|
+
};\n`,
|
193
251
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
194
252
|
0,
|
195
253
|
`external module import ${ident}`
|
196
254
|
);
|
197
255
|
this._ident = ident;
|
198
|
-
this._identifier = identifier;
|
199
256
|
this._request = request;
|
257
|
+
this._dependencyMeta = request;
|
258
|
+
this._identifier = identifier;
|
200
259
|
}
|
201
260
|
|
202
261
|
getNamespaceIdentifier() {
|
@@ -212,13 +271,21 @@ register(
|
|
212
271
|
serialize(obj, { write }) {
|
213
272
|
write(obj._request);
|
214
273
|
write(obj._ident);
|
274
|
+
write(obj._dependencyMeta);
|
215
275
|
},
|
216
276
|
deserialize({ read }) {
|
217
|
-
return new ModuleExternalInitFragment(read(), read());
|
277
|
+
return new ModuleExternalInitFragment(read(), read(), read());
|
218
278
|
}
|
219
279
|
}
|
220
280
|
);
|
221
281
|
|
282
|
+
/**
|
283
|
+
* @param {string} input input
|
284
|
+
* @param {ExportsInfo} exportsInfo the exports info
|
285
|
+
* @param {RuntimeSpec=} runtime the runtime
|
286
|
+
* @param {RuntimeTemplate=} runtimeTemplate the runtime template
|
287
|
+
* @returns {string | undefined} the module remapping
|
288
|
+
*/
|
222
289
|
const generateModuleRemapping = (
|
223
290
|
input,
|
224
291
|
exportsInfo,
|
@@ -242,9 +309,11 @@ const generateModuleRemapping = (
|
|
242
309
|
}
|
243
310
|
}
|
244
311
|
properties.push(
|
245
|
-
`[${JSON.stringify(used)}]: ${
|
246
|
-
|
247
|
-
|
312
|
+
`[${JSON.stringify(used)}]: ${
|
313
|
+
/** @type {RuntimeTemplate} */ (runtimeTemplate).returningFunction(
|
314
|
+
`${input}${propertyAccess([exportInfo.name])}`
|
315
|
+
)
|
316
|
+
}`
|
248
317
|
);
|
249
318
|
}
|
250
319
|
return `x({ ${properties.join(", ")} })`;
|
@@ -256,19 +325,22 @@ const generateModuleRemapping = (
|
|
256
325
|
* @param {ExportsInfo} exportsInfo exports info of this module
|
257
326
|
* @param {RuntimeSpec} runtime the runtime
|
258
327
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
328
|
+
* @param {ImportDependencyMeta} dependencyMeta the dependency meta
|
259
329
|
* @returns {SourceData} the generated source
|
260
330
|
*/
|
261
331
|
const getSourceForModuleExternal = (
|
262
332
|
moduleAndSpecifiers,
|
263
333
|
exportsInfo,
|
264
334
|
runtime,
|
265
|
-
runtimeTemplate
|
335
|
+
runtimeTemplate,
|
336
|
+
dependencyMeta
|
266
337
|
) => {
|
267
338
|
if (!Array.isArray(moduleAndSpecifiers))
|
268
339
|
moduleAndSpecifiers = [moduleAndSpecifiers];
|
269
340
|
const initFragment = new ModuleExternalInitFragment(
|
270
341
|
moduleAndSpecifiers[0],
|
271
342
|
undefined,
|
343
|
+
dependencyMeta,
|
272
344
|
runtimeTemplate.outputOptions.hashFunction
|
273
345
|
);
|
274
346
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
@@ -284,13 +356,15 @@ const getSourceForModuleExternal = (
|
|
284
356
|
let expression = moduleRemapping || baseAccess;
|
285
357
|
return {
|
286
358
|
expression,
|
287
|
-
init:
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
359
|
+
init: moduleRemapping
|
360
|
+
? `var x = ${runtimeTemplate.basicFunction(
|
361
|
+
"y",
|
362
|
+
`var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x`
|
363
|
+
)} \nvar y = ${runtimeTemplate.returningFunction(
|
364
|
+
runtimeTemplate.returningFunction("x"),
|
365
|
+
"x"
|
366
|
+
)}`
|
367
|
+
: undefined,
|
294
368
|
runtimeRequirements: moduleRemapping
|
295
369
|
? RUNTIME_REQUIREMENTS_FOR_MODULE
|
296
370
|
: undefined,
|
@@ -397,13 +471,16 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|
397
471
|
};
|
398
472
|
};
|
399
473
|
|
474
|
+
/** @typedef {Record<string, string | string[]>} RequestRecord */
|
475
|
+
|
400
476
|
class ExternalModule extends Module {
|
401
477
|
/**
|
402
|
-
* @param {string | string[] |
|
403
|
-
* @param {
|
478
|
+
* @param {string | string[] | RequestRecord} request request
|
479
|
+
* @param {string} type type
|
404
480
|
* @param {string} userRequest user request
|
481
|
+
* @param {DependencyMeta=} dependencyMeta dependency meta
|
405
482
|
*/
|
406
|
-
constructor(request, type, userRequest) {
|
483
|
+
constructor(request, type, userRequest, dependencyMeta) {
|
407
484
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
408
485
|
|
409
486
|
// Info from Factory
|
@@ -413,6 +490,8 @@ class ExternalModule extends Module {
|
|
413
490
|
this.externalType = type;
|
414
491
|
/** @type {string} */
|
415
492
|
this.userRequest = userRequest;
|
493
|
+
/** @type {DependencyMeta=} */
|
494
|
+
this.dependencyMeta = dependencyMeta;
|
416
495
|
}
|
417
496
|
|
418
497
|
/**
|
@@ -549,6 +628,11 @@ class ExternalModule extends Module {
|
|
549
628
|
callback();
|
550
629
|
}
|
551
630
|
|
631
|
+
/**
|
632
|
+
* restore unsafe cache data
|
633
|
+
* @param {object} unsafeCacheData data from getUnsafeCacheData
|
634
|
+
* @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
635
|
+
*/
|
552
636
|
restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
553
637
|
this._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
554
638
|
}
|
@@ -577,13 +661,25 @@ class ExternalModule extends Module {
|
|
577
661
|
return { request, externalType };
|
578
662
|
}
|
579
663
|
|
664
|
+
/**
|
665
|
+
* @private
|
666
|
+
* @param {string | string[]} request request
|
667
|
+
* @param {string} externalType the external type
|
668
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
669
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
670
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
671
|
+
* @param {RuntimeSpec} runtime the runtime
|
672
|
+
* @param {DependencyMeta | undefined} dependencyMeta the dependency meta
|
673
|
+
* @returns {SourceData} the source data
|
674
|
+
*/
|
580
675
|
_getSourceData(
|
581
676
|
request,
|
582
677
|
externalType,
|
583
678
|
runtimeTemplate,
|
584
679
|
moduleGraph,
|
585
680
|
chunkGraph,
|
586
|
-
runtime
|
681
|
+
runtime,
|
682
|
+
dependencyMeta
|
587
683
|
) {
|
588
684
|
switch (externalType) {
|
589
685
|
case "this":
|
@@ -601,10 +697,12 @@ class ExternalModule extends Module {
|
|
601
697
|
case "commonjs-static":
|
602
698
|
return getSourceForCommonJsExternal(request);
|
603
699
|
case "node-commonjs":
|
604
|
-
return this.buildInfo.module
|
700
|
+
return /** @type {BuildInfo} */ (this.buildInfo).module
|
605
701
|
? getSourceForCommonJsExternalInNodeModule(
|
606
702
|
request,
|
607
|
-
|
703
|
+
/** @type {string} */
|
704
|
+
(runtimeTemplate.outputOptions.importMetaName),
|
705
|
+
runtimeTemplate.supportNodePrefixForCoreModules()
|
608
706
|
)
|
609
707
|
: getSourceForCommonJsExternal(request);
|
610
708
|
case "amd":
|
@@ -622,11 +720,15 @@ class ExternalModule extends Module {
|
|
622
720
|
);
|
623
721
|
}
|
624
722
|
case "import":
|
625
|
-
return getSourceForImportExternal(
|
723
|
+
return getSourceForImportExternal(
|
724
|
+
request,
|
725
|
+
runtimeTemplate,
|
726
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
727
|
+
);
|
626
728
|
case "script":
|
627
729
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
628
730
|
case "module": {
|
629
|
-
if (!this.buildInfo.module) {
|
731
|
+
if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
|
630
732
|
if (!runtimeTemplate.supportsDynamicImport()) {
|
631
733
|
throw new Error(
|
632
734
|
"The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script" +
|
@@ -635,7 +737,11 @@ class ExternalModule extends Module {
|
|
635
737
|
: "")
|
636
738
|
);
|
637
739
|
}
|
638
|
-
return getSourceForImportExternal(
|
740
|
+
return getSourceForImportExternal(
|
741
|
+
request,
|
742
|
+
runtimeTemplate,
|
743
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
744
|
+
);
|
639
745
|
}
|
640
746
|
if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
|
641
747
|
throw new Error(
|
@@ -646,7 +752,8 @@ class ExternalModule extends Module {
|
|
646
752
|
request,
|
647
753
|
moduleGraph.getExportsInfo(this),
|
648
754
|
runtime,
|
649
|
-
runtimeTemplate
|
755
|
+
runtimeTemplate,
|
756
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
650
757
|
);
|
651
758
|
}
|
652
759
|
case "var":
|
@@ -688,9 +795,24 @@ class ExternalModule extends Module {
|
|
688
795
|
}
|
689
796
|
case "css-import": {
|
690
797
|
const sources = new Map();
|
798
|
+
const dependencyMeta = /** @type {CssImportDependencyMeta} */ (
|
799
|
+
this.dependencyMeta
|
800
|
+
);
|
801
|
+
const layer =
|
802
|
+
dependencyMeta.layer !== undefined
|
803
|
+
? ` layer(${dependencyMeta.layer})`
|
804
|
+
: "";
|
805
|
+
const supports = dependencyMeta.supports
|
806
|
+
? ` supports(${dependencyMeta.supports})`
|
807
|
+
: "";
|
808
|
+
const media = dependencyMeta.media ? ` ${dependencyMeta.media}` : "";
|
691
809
|
sources.set(
|
692
810
|
"css-import",
|
693
|
-
new RawSource(
|
811
|
+
new RawSource(
|
812
|
+
`@import url(${JSON.stringify(
|
813
|
+
request
|
814
|
+
)})${layer}${supports}${media};`
|
815
|
+
)
|
694
816
|
);
|
695
817
|
return {
|
696
818
|
sources,
|
@@ -704,7 +826,8 @@ class ExternalModule extends Module {
|
|
704
826
|
runtimeTemplate,
|
705
827
|
moduleGraph,
|
706
828
|
chunkGraph,
|
707
|
-
runtime
|
829
|
+
runtime,
|
830
|
+
this.dependencyMeta
|
708
831
|
);
|
709
832
|
|
710
833
|
let sourceString = sourceData.expression;
|
@@ -792,6 +915,7 @@ class ExternalModule extends Module {
|
|
792
915
|
write(this.request);
|
793
916
|
write(this.externalType);
|
794
917
|
write(this.userRequest);
|
918
|
+
write(this.dependencyMeta);
|
795
919
|
|
796
920
|
super.serialize(context);
|
797
921
|
}
|
@@ -805,6 +929,7 @@ class ExternalModule extends Module {
|
|
805
929
|
this.request = read();
|
806
930
|
this.externalType = read();
|
807
931
|
this.userRequest = read();
|
932
|
+
this.dependencyMeta = read();
|
808
933
|
|
809
934
|
super.deserialize(context);
|
810
935
|
}
|
@@ -7,9 +7,16 @@
|
|
7
7
|
|
8
8
|
const util = require("util");
|
9
9
|
const ExternalModule = require("./ExternalModule");
|
10
|
+
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
11
|
+
const CssImportDependency = require("./dependencies/CssImportDependency");
|
12
|
+
const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
|
13
|
+
const ImportDependency = require("./dependencies/ImportDependency");
|
10
14
|
const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
|
11
15
|
|
12
16
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
17
|
+
/** @typedef {import("./Compilation").DepConstructor} DepConstructor */
|
18
|
+
/** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
|
19
|
+
/** @typedef {import("./Module")} Module */
|
13
20
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
14
21
|
|
15
22
|
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9-]+ /;
|
@@ -67,7 +74,7 @@ class ExternalModuleFactoryPlugin {
|
|
67
74
|
/**
|
68
75
|
* @param {string|string[]|boolean|Record<string, string|string[]>} value the external config
|
69
76
|
* @param {string|undefined} type type of external
|
70
|
-
* @param {function(Error=, ExternalModule=): void} callback callback
|
77
|
+
* @param {function((Error | null)=, ExternalModule=): void} callback callback
|
71
78
|
* @returns {void}
|
72
79
|
*/
|
73
80
|
const handleExternal = (value, type, callback) => {
|
@@ -105,12 +112,34 @@ class ExternalModuleFactoryPlugin {
|
|
105
112
|
];
|
106
113
|
}
|
107
114
|
}
|
115
|
+
|
116
|
+
// TODO make it pluggable/add hooks to `ExternalModule` to allow output modules own externals?
|
117
|
+
/** @type {DependencyMeta | undefined} */
|
118
|
+
let dependencyMeta;
|
119
|
+
|
120
|
+
if (
|
121
|
+
dependency instanceof HarmonyImportDependency ||
|
122
|
+
dependency instanceof ImportDependency ||
|
123
|
+
dependency instanceof ContextElementDependency
|
124
|
+
) {
|
125
|
+
dependencyMeta = {
|
126
|
+
attributes: dependency.assertions
|
127
|
+
};
|
128
|
+
} else if (dependency instanceof CssImportDependency) {
|
129
|
+
dependencyMeta = {
|
130
|
+
layer: dependency.layer,
|
131
|
+
supports: dependency.supports,
|
132
|
+
media: dependency.media
|
133
|
+
};
|
134
|
+
}
|
135
|
+
|
108
136
|
callback(
|
109
137
|
null,
|
110
138
|
new ExternalModule(
|
111
139
|
externalConfig,
|
112
140
|
type || globalType,
|
113
|
-
dependency.request
|
141
|
+
dependency.request,
|
142
|
+
dependencyMeta
|
114
143
|
)
|
115
144
|
);
|
116
145
|
};
|
@@ -128,7 +157,13 @@ class ExternalModuleFactoryPlugin {
|
|
128
157
|
} else if (Array.isArray(externals)) {
|
129
158
|
let i = 0;
|
130
159
|
const next = () => {
|
160
|
+
/** @type {boolean | undefined} */
|
131
161
|
let asyncFlag;
|
162
|
+
/**
|
163
|
+
* @param {(Error | null)=} err err
|
164
|
+
* @param {ExternalModule=} module module
|
165
|
+
* @returns {void}
|
166
|
+
*/
|
132
167
|
const handleExternalsAndCallback = (err, module) => {
|
133
168
|
if (err) return callback(err);
|
134
169
|
if (!module) {
|