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
@@ -11,8 +11,8 @@ const Entrypoint = require("../Entrypoint");
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* @param {Entrypoint} entrypoint a chunk group
|
14
|
-
* @param {Chunk=} excludedChunk1 current chunk which is excluded
|
15
|
-
* @param {Chunk=} excludedChunk2 runtime chunk which is excluded
|
14
|
+
* @param {(Chunk | null)=} excludedChunk1 current chunk which is excluded
|
15
|
+
* @param {(Chunk | null)=} excludedChunk2 runtime chunk which is excluded
|
16
16
|
* @returns {Set<Chunk>} chunks
|
17
17
|
*/
|
18
18
|
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
@@ -32,7 +32,7 @@ class CommonJsChunkFormatPlugin {
|
|
32
32
|
"CommonJsChunkFormatPlugin",
|
33
33
|
compilation => {
|
34
34
|
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
35
|
-
"
|
35
|
+
"CommonJsChunkFormatPlugin",
|
36
36
|
(chunk, set, { chunkGraph }) => {
|
37
37
|
if (chunk.hasRuntime()) return;
|
38
38
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
@@ -199,7 +199,6 @@ class JavascriptGenerator extends Generator {
|
|
199
199
|
chunkGraph: generateContext.chunkGraph,
|
200
200
|
module,
|
201
201
|
runtime: generateContext.runtime,
|
202
|
-
runtimes: generateContext.runtimes,
|
203
202
|
runtimeRequirements: generateContext.runtimeRequirements,
|
204
203
|
concatenationScope: generateContext.concatenationScope,
|
205
204
|
codeGenerationResults: generateContext.codeGenerationResults,
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const eslintScope = require("eslint-scope");
|
8
9
|
const { SyncWaterfallHook, SyncHook, SyncBailHook } = require("tapable");
|
9
10
|
const vm = require("vm");
|
10
11
|
const {
|
@@ -12,7 +13,8 @@ const {
|
|
12
13
|
OriginalSource,
|
13
14
|
PrefixSource,
|
14
15
|
RawSource,
|
15
|
-
CachedSource
|
16
|
+
CachedSource,
|
17
|
+
ReplaceSource
|
16
18
|
} = require("webpack-sources");
|
17
19
|
const Compilation = require("../Compilation");
|
18
20
|
const { tryRunOrWebpackError } = require("../HookWebpackError");
|
@@ -30,11 +32,13 @@ const { last, someInIterable } = require("../util/IterableHelpers");
|
|
30
32
|
const StringXor = require("../util/StringXor");
|
31
33
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
32
34
|
const createHash = require("../util/createHash");
|
35
|
+
const { getPathInAst, getAllReferences } = require("../util/mergeScope");
|
33
36
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
34
37
|
const { intersectRuntime } = require("../util/runtime");
|
35
38
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
36
39
|
const JavascriptParser = require("./JavascriptParser");
|
37
40
|
|
41
|
+
/** @typedef {import("eslint-scope").Variable} Variable */
|
38
42
|
/** @typedef {import("webpack-sources").Source} Source */
|
39
43
|
/** @typedef {import("../Chunk")} Chunk */
|
40
44
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
@@ -85,7 +89,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
85
89
|
};
|
86
90
|
|
87
91
|
/**
|
88
|
-
* @typedef {
|
92
|
+
* @typedef {object} RenderContext
|
89
93
|
* @property {Chunk} chunk the chunk
|
90
94
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
91
95
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -96,7 +100,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
96
100
|
*/
|
97
101
|
|
98
102
|
/**
|
99
|
-
* @typedef {
|
103
|
+
* @typedef {object} MainRenderContext
|
100
104
|
* @property {Chunk} chunk the chunk
|
101
105
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
102
106
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -108,7 +112,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
108
112
|
*/
|
109
113
|
|
110
114
|
/**
|
111
|
-
* @typedef {
|
115
|
+
* @typedef {object} ChunkRenderContext
|
112
116
|
* @property {Chunk} chunk the chunk
|
113
117
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
114
118
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -120,7 +124,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
120
124
|
*/
|
121
125
|
|
122
126
|
/**
|
123
|
-
* @typedef {
|
127
|
+
* @typedef {object} RenderBootstrapContext
|
124
128
|
* @property {Chunk} chunk the chunk
|
125
129
|
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
126
130
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -132,7 +136,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
132
136
|
/** @typedef {RenderContext & { inlined: boolean }} StartupRenderContext */
|
133
137
|
|
134
138
|
/**
|
135
|
-
* @typedef {
|
139
|
+
* @typedef {object} CompilationHooks
|
136
140
|
* @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModuleContent
|
137
141
|
* @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModuleContainer
|
138
142
|
* @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModulePackage
|
@@ -818,13 +822,19 @@ class JavascriptModulesPlugin {
|
|
818
822
|
const lastInlinedModule = last(inlinedModules);
|
819
823
|
const startupSource = new ConcatSource();
|
820
824
|
startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`);
|
825
|
+
const renamedInlinedModule = this.renameInlineModule(
|
826
|
+
allModules,
|
827
|
+
renderContext,
|
828
|
+
inlinedModules,
|
829
|
+
chunkRenderContext,
|
830
|
+
hooks
|
831
|
+
);
|
832
|
+
|
821
833
|
for (const m of inlinedModules) {
|
822
|
-
const renderedModule =
|
823
|
-
m
|
824
|
-
chunkRenderContext,
|
825
|
-
|
826
|
-
false
|
827
|
-
);
|
834
|
+
const renderedModule =
|
835
|
+
renamedInlinedModule.get(m) ||
|
836
|
+
this.renderModule(m, chunkRenderContext, hooks, false);
|
837
|
+
|
828
838
|
if (renderedModule) {
|
829
839
|
const innerStrict = !allStrict && m.buildInfo.strict;
|
830
840
|
const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
|
@@ -840,11 +850,9 @@ class JavascriptModulesPlugin {
|
|
840
850
|
? // TODO check globals and top-level declarations of other entries and chunk modules
|
841
851
|
// to make a better decision
|
842
852
|
"it need to be isolated against other entry modules."
|
843
|
-
:
|
844
|
-
?
|
845
|
-
:
|
846
|
-
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
|
847
|
-
: hooks.embedInRuntimeBailout.call(m, renderContext);
|
853
|
+
: exports && !webpackExports
|
854
|
+
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
|
855
|
+
: hooks.embedInRuntimeBailout.call(m, renderContext);
|
848
856
|
let footer;
|
849
857
|
if (iife !== undefined) {
|
850
858
|
startupSource.add(
|
@@ -1383,6 +1391,155 @@ class JavascriptModulesPlugin {
|
|
1383
1391
|
"JavascriptModulesPlugin.getCompilationHooks().renderRequire"
|
1384
1392
|
);
|
1385
1393
|
}
|
1394
|
+
|
1395
|
+
/**
|
1396
|
+
* @param {Module[]} allModules allModules
|
1397
|
+
* @param {MainRenderContext} renderContext renderContext
|
1398
|
+
* @param {Set<Module>} inlinedModules inlinedModules
|
1399
|
+
* @param {ChunkRenderContext} chunkRenderContext chunkRenderContext
|
1400
|
+
* @param {CompilationHooks} hooks hooks
|
1401
|
+
* @returns {Map<Module, Source>} renamed inlined modules
|
1402
|
+
*/
|
1403
|
+
renameInlineModule(
|
1404
|
+
allModules,
|
1405
|
+
renderContext,
|
1406
|
+
inlinedModules,
|
1407
|
+
chunkRenderContext,
|
1408
|
+
hooks
|
1409
|
+
) {
|
1410
|
+
const { runtimeTemplate } = renderContext;
|
1411
|
+
|
1412
|
+
/** @type {Map<Module, { source: Source, ast: any, variables: Set<Variable>, usedInNonInlined: Set<Variable>}>} */
|
1413
|
+
const inlinedModulesToInfo = new Map();
|
1414
|
+
/** @type {Set<string>} */
|
1415
|
+
const nonInlinedModuleThroughIdentifiers = new Set();
|
1416
|
+
/** @type {Map<Module, Source>} */
|
1417
|
+
const renamedInlinedModules = new Map();
|
1418
|
+
|
1419
|
+
for (const m of allModules) {
|
1420
|
+
const isInlinedModule = inlinedModules && inlinedModules.has(m);
|
1421
|
+
const moduleSource = this.renderModule(
|
1422
|
+
m,
|
1423
|
+
chunkRenderContext,
|
1424
|
+
hooks,
|
1425
|
+
isInlinedModule ? false : true
|
1426
|
+
);
|
1427
|
+
|
1428
|
+
if (!moduleSource) continue;
|
1429
|
+
const code = /** @type {string} */ (moduleSource.source());
|
1430
|
+
const ast = JavascriptParser._parse(code, {
|
1431
|
+
sourceType: "auto"
|
1432
|
+
});
|
1433
|
+
|
1434
|
+
const scopeManager = eslintScope.analyze(ast, {
|
1435
|
+
ecmaVersion: 6,
|
1436
|
+
sourceType: "module",
|
1437
|
+
optimistic: true,
|
1438
|
+
ignoreEval: true
|
1439
|
+
});
|
1440
|
+
|
1441
|
+
const globalScope = scopeManager.acquire(ast);
|
1442
|
+
if (inlinedModules && inlinedModules.has(m)) {
|
1443
|
+
const moduleScope = globalScope.childScopes[0];
|
1444
|
+
inlinedModulesToInfo.set(m, {
|
1445
|
+
source: moduleSource,
|
1446
|
+
ast,
|
1447
|
+
variables: new Set(moduleScope.variables),
|
1448
|
+
usedInNonInlined: new Set()
|
1449
|
+
});
|
1450
|
+
} else {
|
1451
|
+
for (const ref of globalScope.through) {
|
1452
|
+
nonInlinedModuleThroughIdentifiers.add(ref.identifier.name);
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
}
|
1456
|
+
|
1457
|
+
for (const [, { variables, usedInNonInlined }] of inlinedModulesToInfo) {
|
1458
|
+
for (const variable of variables) {
|
1459
|
+
if (nonInlinedModuleThroughIdentifiers.has(variable.name)) {
|
1460
|
+
usedInNonInlined.add(variable);
|
1461
|
+
}
|
1462
|
+
}
|
1463
|
+
}
|
1464
|
+
|
1465
|
+
for (const [m, moduleInfo] of inlinedModulesToInfo) {
|
1466
|
+
const { ast, source: _source, usedInNonInlined } = moduleInfo;
|
1467
|
+
const source = new ReplaceSource(_source);
|
1468
|
+
if (usedInNonInlined.size === 0) {
|
1469
|
+
renamedInlinedModules.set(m, source);
|
1470
|
+
continue;
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
const usedNames = new Set(
|
1474
|
+
Array.from(inlinedModulesToInfo.get(m).variables).map(v => v.name)
|
1475
|
+
);
|
1476
|
+
|
1477
|
+
for (const variable of usedInNonInlined) {
|
1478
|
+
const references = getAllReferences(variable);
|
1479
|
+
const allIdentifiers = new Set(
|
1480
|
+
references.map(r => r.identifier).concat(variable.identifiers)
|
1481
|
+
);
|
1482
|
+
|
1483
|
+
const newName = this.findNewName(
|
1484
|
+
variable.name,
|
1485
|
+
usedNames,
|
1486
|
+
m.readableIdentifier(runtimeTemplate.requestShortener)
|
1487
|
+
);
|
1488
|
+
usedNames.add(newName);
|
1489
|
+
for (const identifier of allIdentifiers) {
|
1490
|
+
const r = identifier.range;
|
1491
|
+
const path = getPathInAst(ast, identifier);
|
1492
|
+
if (path && path.length > 1) {
|
1493
|
+
const maybeProperty =
|
1494
|
+
path[1].type === "AssignmentPattern" && path[1].left === path[0]
|
1495
|
+
? path[2]
|
1496
|
+
: path[1];
|
1497
|
+
if (maybeProperty.type === "Property" && maybeProperty.shorthand) {
|
1498
|
+
source.insert(r[1], `: ${newName}`);
|
1499
|
+
continue;
|
1500
|
+
}
|
1501
|
+
}
|
1502
|
+
source.replace(r[0], r[1] - 1, newName);
|
1503
|
+
}
|
1504
|
+
}
|
1505
|
+
|
1506
|
+
renamedInlinedModules.set(m, source);
|
1507
|
+
}
|
1508
|
+
|
1509
|
+
return renamedInlinedModules;
|
1510
|
+
}
|
1511
|
+
|
1512
|
+
/**
|
1513
|
+
* @param {string} oldName oldName
|
1514
|
+
* @param {Set<string>} usedName usedName
|
1515
|
+
* @param {string} extraInfo extraInfo
|
1516
|
+
* @returns {string} extraInfo
|
1517
|
+
*/
|
1518
|
+
findNewName(oldName, usedName, extraInfo) {
|
1519
|
+
let name = oldName;
|
1520
|
+
|
1521
|
+
// Remove uncool stuff
|
1522
|
+
extraInfo = extraInfo.replace(
|
1523
|
+
/\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
|
1524
|
+
""
|
1525
|
+
);
|
1526
|
+
const splittedInfo = extraInfo.split("/");
|
1527
|
+
while (splittedInfo.length) {
|
1528
|
+
name = splittedInfo.pop() + (name ? "_" + name : "");
|
1529
|
+
const nameIdent = Template.toIdentifier(name);
|
1530
|
+
if (!usedName.has(nameIdent)) {
|
1531
|
+
return nameIdent;
|
1532
|
+
}
|
1533
|
+
}
|
1534
|
+
|
1535
|
+
let i = 0;
|
1536
|
+
let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
|
1537
|
+
while (usedName.has(nameWithNumber)) {
|
1538
|
+
i++;
|
1539
|
+
nameWithNumber = Template.toIdentifier(`${name}_${i}`);
|
1540
|
+
}
|
1541
|
+
return nameWithNumber;
|
1542
|
+
}
|
1386
1543
|
}
|
1387
1544
|
|
1388
1545
|
module.exports = JavascriptModulesPlugin;
|