webpack 5.100.2 → 5.101.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 +12 -10
- package/bin/webpack.js +7 -7
- package/lib/APIPlugin.js +12 -14
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +4 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +7 -7
- package/lib/CaseSensitiveModulesWarning.js +2 -2
- package/lib/Chunk.js +3 -3
- package/lib/ChunkGraph.js +21 -18
- package/lib/ChunkGroup.js +4 -4
- package/lib/CleanPlugin.js +19 -53
- package/lib/CodeGenerationResults.js +3 -3
- package/lib/CompatibilityPlugin.js +6 -6
- package/lib/Compilation.js +126 -113
- package/lib/Compiler.js +37 -37
- package/lib/ConcatenationScope.js +39 -1
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +12 -11
- package/lib/ContextModuleFactory.js +11 -11
- package/lib/ContextReplacementPlugin.js +5 -5
- package/lib/DefinePlugin.js +24 -22
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/DllEntryPlugin.js +1 -1
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/DynamicEntryPlugin.js +3 -3
- package/lib/EntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +2 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -5
- package/lib/ExportsInfo.js +9 -9
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +163 -48
- package/lib/ExternalModuleFactoryPlugin.js +2 -2
- package/lib/ExternalsPlugin.js +45 -0
- package/lib/FileSystemInfo.js +64 -61
- package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +7 -7
- package/lib/FlagDependencyUsagePlugin.js +4 -4
- package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +27 -27
- package/lib/IgnorePlugin.js +3 -3
- package/lib/IgnoreWarningsPlugin.js +4 -4
- package/lib/InitFragment.js +6 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +1 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/LoaderTargetPlugin.js +2 -2
- package/lib/MainTemplate.js +1 -1
- package/lib/Module.js +1 -1
- package/lib/ModuleFilenameHelpers.js +3 -3
- package/lib/ModuleGraph.js +9 -5
- package/lib/ModuleInfoHeaderPlugin.js +3 -3
- package/lib/ModuleParseError.js +5 -3
- package/lib/MultiCompiler.js +29 -24
- package/lib/MultiStats.js +18 -13
- package/lib/MultiWatching.js +1 -1
- package/lib/NoEmitOnErrorsPlugin.js +2 -2
- package/lib/NodeStuffPlugin.js +27 -15
- package/lib/NormalModule.js +23 -23
- package/lib/NormalModuleFactory.js +23 -21
- package/lib/NormalModuleReplacementPlugin.js +3 -3
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/ProgressPlugin.js +11 -11
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeGlobals.js +20 -0
- package/lib/RuntimePlugin.js +16 -16
- package/lib/RuntimeTemplate.js +35 -26
- package/lib/SizeFormatHelpers.js +1 -1
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -4
- package/lib/SourceMapDevToolPlugin.js +9 -9
- package/lib/Stats.js +2 -2
- package/lib/Template.js +1 -1
- package/lib/TemplatedPathPlugin.js +2 -2
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +1 -1
- package/lib/WatchIgnorePlugin.js +2 -2
- package/lib/Watching.js +12 -12
- package/lib/WebpackIsIncludedPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +3 -3
- package/lib/asset/AssetGenerator.js +1 -1
- package/lib/asset/AssetModulesPlugin.js +6 -6
- package/lib/async-modules/AsyncModuleHelpers.js +1 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +36 -24
- package/lib/async-modules/InferAsyncModulesPlugin.js +3 -3
- package/lib/buildChunkGraph.js +5 -5
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
- package/lib/cache/IdleFileCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +20 -20
- package/lib/cache/ResolverCachePlugin.js +4 -4
- package/lib/cli.js +196 -14
- package/lib/config/browserslistTargetHandler.js +6 -6
- package/lib/config/defaults.js +23 -14
- package/lib/config/normalization.js +41 -38
- package/lib/config/target.js +4 -4
- package/lib/container/ContainerEntryModule.js +3 -3
- package/lib/container/ContainerPlugin.js +3 -3
- package/lib/container/ContainerReferencePlugin.js +3 -3
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/HoistContainerReferencesPlugin.js +7 -7
- package/lib/container/options.js +4 -4
- package/lib/css/CssGenerator.js +5 -3
- package/lib/css/CssLoadingRuntimeModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +25 -22
- package/lib/css/CssParser.js +5 -5
- package/lib/css/walkCssTokens.js +9 -9
- package/lib/debug/ProfilingPlugin.js +5 -5
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -4
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/AMDRequireArrayDependency.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +21 -19
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CssIcssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +4 -4
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/HarmonyAcceptDependency.js +39 -5
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +17 -13
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -8
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyExports.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +28 -9
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +56 -48
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +3 -4
- package/lib/dependencies/HarmonyModulesPlugin.js +2 -8
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -4
- package/lib/dependencies/ImportMetaPlugin.js +7 -7
- package/lib/dependencies/ImportParserPlugin.js +4 -4
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +4 -4
- package/lib/dependencies/ProvidedDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -3
- package/lib/dependencies/SystemPlugin.js +3 -3
- package/lib/dependencies/WorkerPlugin.js +5 -5
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -5
- package/lib/esm/ModuleChunkLoadingPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -11
- package/lib/formatLocation.js +2 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +39 -27
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -32
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +6 -6
- package/lib/hmr/lazyCompilationBackend.js +6 -6
- package/lib/ids/ChunkModuleIdRangePlugin.js +4 -4
- package/lib/ids/DeterministicChunkIdsPlugin.js +5 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +9 -9
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +2 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -4
- package/lib/ids/SyncModuleIdsPlugin.js +4 -4
- package/lib/index.js +10 -6
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +3 -3
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +16 -16
- package/lib/javascript/JavascriptParser.js +80 -78
- package/lib/javascript/JavascriptParserHelpers.js +3 -3
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +2 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/library/AbstractLibraryPlugin.js +3 -3
- package/lib/library/AmdLibraryPlugin.js +3 -3
- package/lib/library/AssignLibraryPlugin.js +2 -2
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +7 -2
- package/lib/library/SystemLibraryPlugin.js +6 -4
- package/lib/library/UmdLibraryPlugin.js +14 -14
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/logging/runtime.js +3 -3
- package/lib/logging/truncateArgs.js +4 -4
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +16 -14
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +7 -7
- package/lib/node/ReadFileCompileWasmPlugin.js +7 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -4
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveMergingPlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -10
- package/lib/optimize/ConcatenatedModule.js +161 -52
- package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -2
- package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +14 -12
- package/lib/optimize/LimitChunkCountPlugin.js +5 -5
- package/lib/optimize/MangleExportsPlugin.js +5 -5
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/MinChunkSizePlugin.js +3 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +45 -38
- package/lib/optimize/RealContentHashPlugin.js +23 -23
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/RuntimeChunkPlugin.js +2 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +5 -5
- package/lib/optimize/SplitChunksPlugin.js +20 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +4 -4
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -3
- package/lib/rules/BasicMatcherRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +10 -10
- package/lib/rules/UseEffectRulePlugin.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +15 -15
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
- package/lib/schemes/DataUriPlugin.js +3 -3
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +40 -36
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +11 -11
- package/lib/serialization/FileMiddleware.js +17 -17
- package/lib/serialization/ObjectMiddleware.js +8 -8
- package/lib/serialization/Serializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +4 -4
- package/lib/sharing/ProvideSharedPlugin.js +4 -4
- package/lib/sharing/SharePlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +85 -80
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -15
- package/lib/stats/DefaultStatsPrinterPlugin.js +87 -87
- package/lib/stats/StatsFactory.js +7 -7
- package/lib/stats/StatsPrinter.js +9 -9
- package/lib/url/URLParserPlugin.js +5 -5
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +2 -2
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/SetHelpers.js +2 -2
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/StackedMap.js +1 -1
- package/lib/util/TupleSet.js +1 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/cleverMerge.js +8 -8
- package/lib/util/comparators.js +10 -10
- package/lib/util/compileBooleanMatcher.js +20 -20
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +4 -4
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/deprecation.js +4 -4
- package/lib/util/deterministicGrouping.js +7 -7
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +3 -3
- package/lib/util/identifier.js +14 -14
- package/lib/util/magicComment.js +5 -1
- package/lib/util/memoize.js +1 -1
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +1 -1
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +6 -6
- package/lib/util/semver.js +16 -16
- package/lib/util/serialization.js +5 -5
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -9
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +14 -14
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -2
- package/lib/wasm-sync/WebAssemblyParser.js +2 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
- package/lib/web/FetchCompileWasmPlugin.js +4 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +17 -12
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +13 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +4 -0
- package/types.d.ts +151 -44
package/lib/ExternalModule.js
CHANGED
|
@@ -75,8 +75,11 @@ const { register } = require("./util/serialization");
|
|
|
75
75
|
* @property {string} expression
|
|
76
76
|
* @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
|
|
77
77
|
* @property {ReadOnlyRuntimeRequirements=} runtimeRequirements
|
|
78
|
+
* @property {[string, string][]=} specifiers
|
|
78
79
|
*/
|
|
79
80
|
|
|
81
|
+
/** @typedef {true | [string, string][]} Imported */
|
|
82
|
+
|
|
80
83
|
const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
|
|
81
84
|
const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
|
|
82
85
|
const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
|
|
@@ -96,7 +99,9 @@ const getSourceForGlobalVariableExternal = (variableName, type) => {
|
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
// needed for e.g. window["some"]["thing"]
|
|
99
|
-
const objectLookup = variableName
|
|
102
|
+
const objectLookup = variableName
|
|
103
|
+
.map((r) => `[${JSON.stringify(r)}]`)
|
|
104
|
+
.join("");
|
|
100
105
|
return {
|
|
101
106
|
iife: type === "this",
|
|
102
107
|
expression: `${type}${objectLookup}`
|
|
@@ -107,7 +112,7 @@ const getSourceForGlobalVariableExternal = (variableName, type) => {
|
|
|
107
112
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
|
108
113
|
* @returns {SourceData} the generated source
|
|
109
114
|
*/
|
|
110
|
-
const getSourceForCommonJsExternal = moduleAndSpecifiers => {
|
|
115
|
+
const getSourceForCommonJsExternal = (moduleAndSpecifiers) => {
|
|
111
116
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
|
112
117
|
return {
|
|
113
118
|
expression: `require(${JSON.stringify(moduleAndSpecifiers)})`
|
|
@@ -123,21 +128,24 @@ const getSourceForCommonJsExternal = moduleAndSpecifiers => {
|
|
|
123
128
|
};
|
|
124
129
|
|
|
125
130
|
/**
|
|
126
|
-
* @param {string|string[]} moduleAndSpecifiers the module request
|
|
127
|
-
* @param {
|
|
128
|
-
* @param {boolean} needPrefix need to use `node:` prefix for `module` import
|
|
131
|
+
* @param {string | string[]} moduleAndSpecifiers the module request
|
|
132
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
129
133
|
* @returns {SourceData} the generated source
|
|
130
134
|
*/
|
|
131
135
|
const getSourceForCommonJsExternalInNodeModule = (
|
|
132
136
|
moduleAndSpecifiers,
|
|
133
|
-
|
|
134
|
-
needPrefix
|
|
137
|
+
runtimeTemplate
|
|
135
138
|
) => {
|
|
139
|
+
const importMetaName =
|
|
140
|
+
/** @type {string} */
|
|
141
|
+
(runtimeTemplate.outputOptions.importMetaName);
|
|
142
|
+
|
|
143
|
+
// /** @type {boolean} */
|
|
144
|
+
// (runtimeTemplate.supportNodePrefixForCoreModules())
|
|
145
|
+
|
|
136
146
|
const chunkInitFragments = [
|
|
137
147
|
new InitFragment(
|
|
138
|
-
`import { createRequire as __WEBPACK_EXTERNAL_createRequire } from
|
|
139
|
-
needPrefix ? "node:" : ""
|
|
140
|
-
}module";\n`,
|
|
148
|
+
`import { createRequire as __WEBPACK_EXTERNAL_createRequire } from ${runtimeTemplate.renderNodePrefixForCoreModule("module")};\n`,
|
|
141
149
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
|
142
150
|
0,
|
|
143
151
|
"external module node-commonjs"
|
|
@@ -215,10 +223,9 @@ const getSourceForImportExternal = (
|
|
|
215
223
|
};
|
|
216
224
|
|
|
217
225
|
/**
|
|
218
|
-
* @
|
|
219
|
-
* @param {
|
|
220
|
-
* @
|
|
221
|
-
* @returns {undefined | T[keyof T]} replaced value
|
|
226
|
+
* @param {string} key key
|
|
227
|
+
* @param {ImportAttributes | string | boolean | undefined} value value
|
|
228
|
+
* @returns {ImportAttributes | string | boolean | undefined} replaced value
|
|
222
229
|
*/
|
|
223
230
|
const importAssertionReplacer = (key, value) => {
|
|
224
231
|
if (key === "_isLegacyAssert") {
|
|
@@ -229,17 +236,19 @@ const importAssertionReplacer = (key, value) => {
|
|
|
229
236
|
};
|
|
230
237
|
|
|
231
238
|
/**
|
|
232
|
-
* @extends {InitFragment<
|
|
239
|
+
* @extends {InitFragment<GenerateContext>}
|
|
233
240
|
*/
|
|
234
241
|
class ModuleExternalInitFragment extends InitFragment {
|
|
235
242
|
/**
|
|
236
243
|
* @param {string} request import source
|
|
244
|
+
* @param {Imported} imported the imported specifiers
|
|
237
245
|
* @param {string=} ident recomputed ident
|
|
238
246
|
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
|
239
247
|
* @param {HashFunction=} hashFunction the hash function to use
|
|
240
248
|
*/
|
|
241
249
|
constructor(
|
|
242
250
|
request,
|
|
251
|
+
imported,
|
|
243
252
|
ident,
|
|
244
253
|
dependencyMeta,
|
|
245
254
|
hashFunction = DEFAULTS.HASH_FUNCTION
|
|
@@ -253,28 +262,78 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
|
253
262
|
.slice(0, 8)}`;
|
|
254
263
|
}
|
|
255
264
|
}
|
|
265
|
+
|
|
256
266
|
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
|
257
267
|
super(
|
|
258
|
-
|
|
259
|
-
dependencyMeta && dependencyMeta.attributes
|
|
260
|
-
? dependencyMeta.attributes._isLegacyAssert
|
|
261
|
-
? ` assert ${JSON.stringify(
|
|
262
|
-
dependencyMeta.attributes,
|
|
263
|
-
importAssertionReplacer
|
|
264
|
-
)}`
|
|
265
|
-
: ` with ${JSON.stringify(dependencyMeta.attributes)}`
|
|
266
|
-
: ""
|
|
267
|
-
};\n`,
|
|
268
|
+
"",
|
|
268
269
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
|
269
270
|
0,
|
|
270
|
-
`external module import ${ident}`
|
|
271
|
+
`external module import ${ident} ${imported === true ? imported : imported.join(" ")}`
|
|
271
272
|
);
|
|
272
273
|
this._ident = ident;
|
|
273
274
|
this._request = request;
|
|
274
|
-
this._dependencyMeta =
|
|
275
|
+
this._dependencyMeta = dependencyMeta;
|
|
276
|
+
this._imported = imported;
|
|
275
277
|
this._identifier = identifier;
|
|
276
278
|
}
|
|
277
279
|
|
|
280
|
+
/**
|
|
281
|
+
* @returns {Imported} imported
|
|
282
|
+
*/
|
|
283
|
+
getImported() {
|
|
284
|
+
return this._imported;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @param {Imported} imported imported
|
|
289
|
+
*/
|
|
290
|
+
setImported(imported) {
|
|
291
|
+
this._imported = imported;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @param {GenerateContext} context context
|
|
296
|
+
* @returns {string | Source | undefined} the source code that will be included as initialization code
|
|
297
|
+
*/
|
|
298
|
+
getContent(context) {
|
|
299
|
+
const {
|
|
300
|
+
_dependencyMeta: dependencyMeta,
|
|
301
|
+
_imported: imported,
|
|
302
|
+
_request: request,
|
|
303
|
+
_identifier: identifier
|
|
304
|
+
} = this;
|
|
305
|
+
const attributes =
|
|
306
|
+
dependencyMeta && dependencyMeta.attributes
|
|
307
|
+
? dependencyMeta.attributes._isLegacyAssert &&
|
|
308
|
+
dependencyMeta.attributes._isLegacyAssert
|
|
309
|
+
? ` assert ${JSON.stringify(
|
|
310
|
+
dependencyMeta.attributes,
|
|
311
|
+
importAssertionReplacer
|
|
312
|
+
)}`
|
|
313
|
+
: ` with ${JSON.stringify(dependencyMeta.attributes)}`
|
|
314
|
+
: "";
|
|
315
|
+
let content = "";
|
|
316
|
+
if (imported === true) {
|
|
317
|
+
// namespace
|
|
318
|
+
content = `import * as ${identifier} from ${JSON.stringify(request)}${
|
|
319
|
+
attributes
|
|
320
|
+
};\n`;
|
|
321
|
+
} else if (imported.length === 0) {
|
|
322
|
+
// just import, no use
|
|
323
|
+
content = `import ${JSON.stringify(request)}${attributes};\n`;
|
|
324
|
+
} else {
|
|
325
|
+
content = `import { ${imported
|
|
326
|
+
.map(([name, finalName]) => {
|
|
327
|
+
if (name !== finalName) {
|
|
328
|
+
return `${name} as ${finalName}`;
|
|
329
|
+
}
|
|
330
|
+
return name;
|
|
331
|
+
})
|
|
332
|
+
.join(", ")} } from ${JSON.stringify(request)}${attributes};\n`;
|
|
333
|
+
}
|
|
334
|
+
return content;
|
|
335
|
+
}
|
|
336
|
+
|
|
278
337
|
getNamespaceIdentifier() {
|
|
279
338
|
return this._identifier;
|
|
280
339
|
}
|
|
@@ -287,11 +346,12 @@ register(
|
|
|
287
346
|
{
|
|
288
347
|
serialize(obj, { write }) {
|
|
289
348
|
write(obj._request);
|
|
349
|
+
write(obj._imported);
|
|
290
350
|
write(obj._ident);
|
|
291
351
|
write(obj._dependencyMeta);
|
|
292
352
|
},
|
|
293
353
|
deserialize({ read }) {
|
|
294
|
-
return new ModuleExternalInitFragment(read(), read(), read());
|
|
354
|
+
return new ModuleExternalInitFragment(read(), read(), read(), read());
|
|
295
355
|
}
|
|
296
356
|
}
|
|
297
357
|
);
|
|
@@ -343,6 +403,7 @@ const generateModuleRemapping = (
|
|
|
343
403
|
* @param {RuntimeSpec} runtime the runtime
|
|
344
404
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
345
405
|
* @param {ImportDependencyMeta} dependencyMeta the dependency meta
|
|
406
|
+
* @param {ConcatenationScope=} concatenationScope concatenationScope
|
|
346
407
|
* @returns {SourceData} the generated source
|
|
347
408
|
*/
|
|
348
409
|
const getSourceForModuleExternal = (
|
|
@@ -350,28 +411,71 @@ const getSourceForModuleExternal = (
|
|
|
350
411
|
exportsInfo,
|
|
351
412
|
runtime,
|
|
352
413
|
runtimeTemplate,
|
|
353
|
-
dependencyMeta
|
|
414
|
+
dependencyMeta,
|
|
415
|
+
concatenationScope
|
|
354
416
|
) => {
|
|
355
417
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
|
356
418
|
moduleAndSpecifiers = [moduleAndSpecifiers];
|
|
357
419
|
}
|
|
420
|
+
|
|
421
|
+
/** @type {Imported} */
|
|
422
|
+
let imported = true;
|
|
423
|
+
if (concatenationScope) {
|
|
424
|
+
const usedExports = exportsInfo.getUsedExports(runtime);
|
|
425
|
+
switch (usedExports) {
|
|
426
|
+
case true:
|
|
427
|
+
case null:
|
|
428
|
+
// unknown exports
|
|
429
|
+
imported = true;
|
|
430
|
+
break;
|
|
431
|
+
case false:
|
|
432
|
+
// no used exports
|
|
433
|
+
imported = [];
|
|
434
|
+
break;
|
|
435
|
+
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
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
358
454
|
const initFragment = new ModuleExternalInitFragment(
|
|
359
455
|
moduleAndSpecifiers[0],
|
|
456
|
+
imported,
|
|
360
457
|
undefined,
|
|
361
458
|
dependencyMeta,
|
|
362
459
|
runtimeTemplate.outputOptions.hashFunction
|
|
363
460
|
);
|
|
461
|
+
const specifiers = imported === true ? undefined : imported;
|
|
364
462
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
|
365
463
|
moduleAndSpecifiers,
|
|
366
464
|
1
|
|
367
465
|
)}`;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
466
|
+
let expression = baseAccess;
|
|
467
|
+
|
|
468
|
+
const useNamespace = imported === true;
|
|
469
|
+
let moduleRemapping;
|
|
470
|
+
if (useNamespace) {
|
|
471
|
+
moduleRemapping = generateModuleRemapping(
|
|
472
|
+
baseAccess,
|
|
473
|
+
exportsInfo,
|
|
474
|
+
runtime,
|
|
475
|
+
runtimeTemplate
|
|
476
|
+
);
|
|
477
|
+
expression = moduleRemapping || baseAccess;
|
|
478
|
+
}
|
|
375
479
|
return {
|
|
376
480
|
expression,
|
|
377
481
|
init: moduleRemapping
|
|
@@ -383,10 +487,13 @@ const getSourceForModuleExternal = (
|
|
|
383
487
|
"x"
|
|
384
488
|
)}`
|
|
385
489
|
: undefined,
|
|
490
|
+
specifiers,
|
|
386
491
|
runtimeRequirements: moduleRemapping
|
|
387
492
|
? RUNTIME_REQUIREMENTS_FOR_MODULE
|
|
388
493
|
: undefined,
|
|
389
|
-
chunkInitFragments: [
|
|
494
|
+
chunkInitFragments: [
|
|
495
|
+
/** @type {InitFragment<EXPECTED_ANY>} */ (initFragment)
|
|
496
|
+
]
|
|
390
497
|
};
|
|
391
498
|
};
|
|
392
499
|
|
|
@@ -733,6 +840,7 @@ class ExternalModule extends Module {
|
|
|
733
840
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
734
841
|
* @param {RuntimeSpec} runtime the runtime
|
|
735
842
|
* @param {DependencyMeta | undefined} dependencyMeta the dependency meta
|
|
843
|
+
* @param {ConcatenationScope=} concatenationScope concatenationScope
|
|
736
844
|
* @returns {SourceData} the source data
|
|
737
845
|
*/
|
|
738
846
|
_getSourceData(
|
|
@@ -742,7 +850,8 @@ class ExternalModule extends Module {
|
|
|
742
850
|
moduleGraph,
|
|
743
851
|
chunkGraph,
|
|
744
852
|
runtime,
|
|
745
|
-
dependencyMeta
|
|
853
|
+
dependencyMeta,
|
|
854
|
+
concatenationScope
|
|
746
855
|
) {
|
|
747
856
|
switch (externalType) {
|
|
748
857
|
case "this":
|
|
@@ -761,13 +870,7 @@ class ExternalModule extends Module {
|
|
|
761
870
|
return getSourceForCommonJsExternal(request);
|
|
762
871
|
case "node-commonjs":
|
|
763
872
|
return /** @type {BuildInfo} */ (this.buildInfo).javascriptModule
|
|
764
|
-
? getSourceForCommonJsExternalInNodeModule(
|
|
765
|
-
request,
|
|
766
|
-
/** @type {string} */
|
|
767
|
-
(runtimeTemplate.outputOptions.importMetaName),
|
|
768
|
-
/** @type {boolean} */
|
|
769
|
-
(runtimeTemplate.supportNodePrefixForCoreModules())
|
|
770
|
-
)
|
|
873
|
+
? getSourceForCommonJsExternalInNodeModule(request, runtimeTemplate)
|
|
771
874
|
: getSourceForCommonJsExternal(request);
|
|
772
875
|
case "amd":
|
|
773
876
|
case "amd-require":
|
|
@@ -818,7 +921,8 @@ class ExternalModule extends Module {
|
|
|
818
921
|
moduleGraph.getExportsInfo(this),
|
|
819
922
|
runtime,
|
|
820
923
|
runtimeTemplate,
|
|
821
|
-
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
|
924
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta),
|
|
925
|
+
concatenationScope
|
|
822
926
|
);
|
|
823
927
|
}
|
|
824
928
|
case "var":
|
|
@@ -898,14 +1002,24 @@ class ExternalModule extends Module {
|
|
|
898
1002
|
moduleGraph,
|
|
899
1003
|
chunkGraph,
|
|
900
1004
|
runtime,
|
|
901
|
-
this.dependencyMeta
|
|
1005
|
+
this.dependencyMeta,
|
|
1006
|
+
concatenationScope
|
|
902
1007
|
);
|
|
903
1008
|
|
|
1009
|
+
// sourceString can be empty str only when there is concatenationScope
|
|
904
1010
|
let sourceString = sourceData.expression;
|
|
905
1011
|
if (sourceData.iife) {
|
|
906
1012
|
sourceString = `(function() { return ${sourceString}; }())`;
|
|
907
1013
|
}
|
|
908
|
-
|
|
1014
|
+
|
|
1015
|
+
const specifiers = sourceData.specifiers;
|
|
1016
|
+
if (specifiers) {
|
|
1017
|
+
sourceString = "";
|
|
1018
|
+
const scope = /** @type {ConcatenationScope} */ (concatenationScope);
|
|
1019
|
+
for (const [specifier, finalName] of specifiers) {
|
|
1020
|
+
scope.registerRawExport(specifier, finalName);
|
|
1021
|
+
}
|
|
1022
|
+
} else if (concatenationScope) {
|
|
909
1023
|
sourceString = `${
|
|
910
1024
|
runtimeTemplate.supportsConst() ? "const" : "var"
|
|
911
1025
|
} ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
|
|
@@ -1011,3 +1125,4 @@ class ExternalModule extends Module {
|
|
|
1011
1125
|
makeSerializable(ExternalModule, "webpack/lib/ExternalModule");
|
|
1012
1126
|
|
|
1013
1127
|
module.exports = ExternalModule;
|
|
1128
|
+
module.exports.ModuleExternalInitFragment = ModuleExternalInitFragment;
|
|
@@ -264,7 +264,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
264
264
|
request: dependency.request,
|
|
265
265
|
dependencyType,
|
|
266
266
|
contextInfo,
|
|
267
|
-
getResolve: options => (context, request, callback) => {
|
|
267
|
+
getResolve: (options) => (context, request, callback) => {
|
|
268
268
|
const resolveContext = {
|
|
269
269
|
fileDependencies: data.fileDependencies,
|
|
270
270
|
missingDependencies: data.missingDependencies,
|
|
@@ -307,7 +307,7 @@ class ExternalModuleFactoryPlugin {
|
|
|
307
307
|
},
|
|
308
308
|
cb
|
|
309
309
|
);
|
|
310
|
-
if (promise && promise.then) promise.then(r => cb(null, r), cb);
|
|
310
|
+
if (promise && promise.then) promise.then((r) => cb(null, r), cb);
|
|
311
311
|
}
|
|
312
312
|
return;
|
|
313
313
|
} else if (typeof externals === "object") {
|
package/lib/ExternalsPlugin.js
CHANGED
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const { ModuleExternalInitFragment } = require("./ExternalModule");
|
|
8
9
|
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
|
10
|
+
const ConcatenatedModule = require("./optimize/ConcatenatedModule");
|
|
9
11
|
|
|
10
12
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
|
11
13
|
/** @typedef {import("./Compiler")} Compiler */
|
|
14
|
+
/** @typedef {import("./optimize/ConcatenatedModule").ConcatenatedModuleInfo} ConcatenatedModuleInfo */
|
|
12
15
|
|
|
13
16
|
const PLUGIN_NAME = "ExternalsPlugin";
|
|
14
17
|
|
|
@@ -33,6 +36,48 @@ class ExternalsPlugin {
|
|
|
33
36
|
normalModuleFactory
|
|
34
37
|
);
|
|
35
38
|
});
|
|
39
|
+
|
|
40
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
41
|
+
const { concatenatedModuleInfo } =
|
|
42
|
+
ConcatenatedModule.getCompilationHooks(compilation);
|
|
43
|
+
concatenatedModuleInfo.tap(PLUGIN_NAME, (updatedInfo, moduleInfo) => {
|
|
44
|
+
const rawExportMap =
|
|
45
|
+
/** @type {ConcatenatedModuleInfo} */ updatedInfo.rawExportMap;
|
|
46
|
+
|
|
47
|
+
if (!rawExportMap) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const chunkInitFragments =
|
|
52
|
+
/** @type {ConcatenatedModuleInfo} */ moduleInfo.chunkInitFragments;
|
|
53
|
+
const moduleExternalInitFragments = chunkInitFragments
|
|
54
|
+
? chunkInitFragments.filter(
|
|
55
|
+
(fragment) => fragment instanceof ModuleExternalInitFragment
|
|
56
|
+
)
|
|
57
|
+
: [];
|
|
58
|
+
|
|
59
|
+
let initFragmentChanged = false;
|
|
60
|
+
|
|
61
|
+
for (const fragment of moduleExternalInitFragments) {
|
|
62
|
+
const imported = fragment.getImported();
|
|
63
|
+
|
|
64
|
+
if (Array.isArray(imported)) {
|
|
65
|
+
const newImported = imported.map(([specifier, finalName]) => [
|
|
66
|
+
specifier,
|
|
67
|
+
rawExportMap.has(specifier)
|
|
68
|
+
? rawExportMap.get(specifier)
|
|
69
|
+
: finalName
|
|
70
|
+
]);
|
|
71
|
+
fragment.setImported(newImported);
|
|
72
|
+
initFragmentChanged = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (initFragmentChanged) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
36
81
|
}
|
|
37
82
|
}
|
|
38
83
|
|