@eriche/webpack 4.47.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/LICENSE +20 -0
- package/README.md +784 -0
- package/SECURITY.md +9 -0
- package/bin/webpack.js +171 -0
- package/buildin/amd-define.js +3 -0
- package/buildin/amd-options.js +2 -0
- package/buildin/global.js +20 -0
- package/buildin/harmony-module.js +24 -0
- package/buildin/module.js +22 -0
- package/buildin/system.js +7 -0
- package/declarations/WebpackOptions.d.ts +1466 -0
- package/declarations/plugins/BannerPlugin.d.ts +49 -0
- package/declarations/plugins/DllPlugin.d.ts +32 -0
- package/declarations/plugins/DllReferencePlugin.d.ts +126 -0
- package/declarations/plugins/HashedModuleIdsPlugin.d.ts +24 -0
- package/declarations/plugins/IgnorePlugin.d.ts +27 -0
- package/declarations/plugins/LoaderOptionsPlugin.d.ts +27 -0
- package/declarations/plugins/ProgressPlugin.d.ts +42 -0
- package/declarations/plugins/SourceMapDevToolPlugin.d.ts +94 -0
- package/declarations/plugins/WatchIgnorePlugin.d.ts +10 -0
- package/declarations/plugins/debug/ProfilingPlugin.d.ts +12 -0
- package/declarations/plugins/optimize/AggressiveSplittingPlugin.d.ts +24 -0
- package/declarations/plugins/optimize/LimitChunkCountPlugin.d.ts +16 -0
- package/declarations/plugins/optimize/MinChunkSizePlugin.d.ts +12 -0
- package/declarations/plugins/optimize/OccurrenceOrderChunkIdsPlugin.d.ts +12 -0
- package/declarations/plugins/optimize/OccurrenceOrderModuleIdsPlugin.d.ts +12 -0
- package/hot/dev-server.js +61 -0
- package/hot/emitter.js +2 -0
- package/hot/log-apply-result.js +44 -0
- package/hot/log.js +59 -0
- package/hot/only-dev-server.js +102 -0
- package/hot/poll.js +37 -0
- package/hot/signal.js +62 -0
- package/lib/APIPlugin.js +84 -0
- package/lib/AbstractMethodError.js +43 -0
- package/lib/AmdMainTemplatePlugin.js +106 -0
- package/lib/AsyncDependenciesBlock.js +110 -0
- package/lib/AsyncDependencyToInitialChunkError.js +31 -0
- package/lib/AutomaticPrefetchPlugin.js +57 -0
- package/lib/BannerPlugin.js +122 -0
- package/lib/BasicEvaluatedExpression.js +248 -0
- package/lib/CachePlugin.js +100 -0
- package/lib/CaseSensitiveModulesWarning.js +67 -0
- package/lib/Chunk.js +875 -0
- package/lib/ChunkGroup.js +513 -0
- package/lib/ChunkRenderError.js +32 -0
- package/lib/ChunkTemplate.js +87 -0
- package/lib/CommentCompilationWarning.js +32 -0
- package/lib/CommonJsStuffPlugin.js +116 -0
- package/lib/CompatibilityPlugin.js +70 -0
- package/lib/Compilation.js +2327 -0
- package/lib/Compiler.js +735 -0
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ConstPlugin.js +348 -0
- package/lib/ContextExclusionPlugin.js +28 -0
- package/lib/ContextModule.js +872 -0
- package/lib/ContextModuleFactory.js +262 -0
- package/lib/ContextReplacementPlugin.js +133 -0
- package/lib/DefinePlugin.js +289 -0
- package/lib/DelegatedModule.js +114 -0
- package/lib/DelegatedModuleFactoryPlugin.js +95 -0
- package/lib/DelegatedPlugin.js +39 -0
- package/lib/DependenciesBlock.js +124 -0
- package/lib/DependenciesBlockVariable.js +72 -0
- package/lib/Dependency.js +89 -0
- package/lib/DllEntryPlugin.js +54 -0
- package/lib/DllModule.js +60 -0
- package/lib/DllModuleFactory.js +29 -0
- package/lib/DllPlugin.js +49 -0
- package/lib/DllReferencePlugin.js +156 -0
- package/lib/DynamicEntryPlugin.js +94 -0
- package/lib/EntryModuleNotFoundError.js +21 -0
- package/lib/EntryOptionPlugin.js +46 -0
- package/lib/Entrypoint.js +64 -0
- package/lib/EnvironmentPlugin.js +72 -0
- package/lib/ErrorHelpers.js +60 -0
- package/lib/EvalDevToolModulePlugin.js +27 -0
- package/lib/EvalDevToolModuleTemplatePlugin.js +61 -0
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +120 -0
- package/lib/EvalSourceMapDevToolPlugin.js +41 -0
- package/lib/ExportPropertyMainTemplatePlugin.js +53 -0
- package/lib/ExtendedAPIPlugin.js +88 -0
- package/lib/ExternalModule.js +179 -0
- package/lib/ExternalModuleFactoryPlugin.js +110 -0
- package/lib/ExternalsPlugin.js +23 -0
- package/lib/FlagAllModulesAsUsedPlugin.js +38 -0
- package/lib/FlagDependencyExportsPlugin.js +174 -0
- package/lib/FlagDependencyUsagePlugin.js +116 -0
- package/lib/FlagInitialModulesAsUsedPlugin.js +36 -0
- package/lib/FunctionModulePlugin.js +19 -0
- package/lib/FunctionModuleTemplatePlugin.js +102 -0
- package/lib/Generator.js +60 -0
- package/lib/GraphHelpers.js +65 -0
- package/lib/HarmonyLinkingError.js +17 -0
- package/lib/HashedModuleIdsPlugin.js +63 -0
- package/lib/HotModuleReplacement.runtime.js +721 -0
- package/lib/HotModuleReplacementPlugin.js +425 -0
- package/lib/HotUpdateChunk.js +17 -0
- package/lib/HotUpdateChunkTemplate.js +78 -0
- package/lib/IgnorePlugin.js +91 -0
- package/lib/JavascriptGenerator.js +229 -0
- package/lib/JavascriptModulesPlugin.js +185 -0
- package/lib/JsonGenerator.js +57 -0
- package/lib/JsonModulesPlugin.js +30 -0
- package/lib/JsonParser.js +27 -0
- package/lib/LibManifestPlugin.js +90 -0
- package/lib/LibraryTemplatePlugin.js +186 -0
- package/lib/LoaderOptionsPlugin.js +58 -0
- package/lib/LoaderTargetPlugin.js +24 -0
- package/lib/MainTemplate.js +568 -0
- package/lib/MemoryOutputFileSystem.js +5 -0
- package/lib/Module.js +435 -0
- package/lib/ModuleBuildError.js +52 -0
- package/lib/ModuleDependencyError.js +35 -0
- package/lib/ModuleDependencyWarning.js +25 -0
- package/lib/ModuleError.js +36 -0
- package/lib/ModuleFilenameHelpers.js +179 -0
- package/lib/ModuleNotFoundError.js +23 -0
- package/lib/ModuleParseError.js +67 -0
- package/lib/ModuleReason.js +48 -0
- package/lib/ModuleTemplate.js +93 -0
- package/lib/ModuleWarning.js +36 -0
- package/lib/MultiCompiler.js +290 -0
- package/lib/MultiEntryPlugin.js +80 -0
- package/lib/MultiModule.js +87 -0
- package/lib/MultiModuleFactory.js +23 -0
- package/lib/MultiStats.js +92 -0
- package/lib/MultiWatching.js +50 -0
- package/lib/NamedChunksPlugin.js +29 -0
- package/lib/NamedModulesPlugin.js +58 -0
- package/lib/NoEmitOnErrorsPlugin.js +20 -0
- package/lib/NoModeWarning.js +23 -0
- package/lib/NodeStuffPlugin.js +118 -0
- package/lib/NormalModule.js +582 -0
- package/lib/NormalModuleFactory.js +528 -0
- package/lib/NormalModuleReplacementPlugin.js +51 -0
- package/lib/NullFactory.js +12 -0
- package/lib/OptionsApply.js +10 -0
- package/lib/OptionsDefaulter.js +141 -0
- package/lib/Parser.js +2454 -0
- package/lib/ParserHelpers.js +103 -0
- package/lib/PrefetchPlugin.js +37 -0
- package/lib/ProgressPlugin.js +307 -0
- package/lib/ProvidePlugin.js +86 -0
- package/lib/RawModule.js +56 -0
- package/lib/RecordIdsPlugin.js +236 -0
- package/lib/RemovedPluginError.js +11 -0
- package/lib/RequestShortener.js +83 -0
- package/lib/RequireJsStuffPlugin.js +66 -0
- package/lib/ResolverFactory.js +74 -0
- package/lib/RuleSet.js +567 -0
- package/lib/RuntimeTemplate.js +336 -0
- package/lib/SetVarMainTemplatePlugin.js +69 -0
- package/lib/SingleEntryPlugin.js +63 -0
- package/lib/SizeFormatHelpers.js +24 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -0
- package/lib/SourceMapDevToolPlugin.js +418 -0
- package/lib/Stats.js +1685 -0
- package/lib/SystemMainTemplatePlugin.js +137 -0
- package/lib/Template.js +291 -0
- package/lib/TemplatedPathPlugin.js +188 -0
- package/lib/UmdMainTemplatePlugin.js +305 -0
- package/lib/UnsupportedFeatureWarning.js +30 -0
- package/lib/UseStrictPlugin.js +54 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +37 -0
- package/lib/WarnNoModeSetPlugin.js +17 -0
- package/lib/WatchIgnorePlugin.js +106 -0
- package/lib/Watching.js +211 -0
- package/lib/WebpackError.js +31 -0
- package/lib/WebpackOptionsApply.js +546 -0
- package/lib/WebpackOptionsDefaulter.js +391 -0
- package/lib/WebpackOptionsValidationError.js +390 -0
- package/lib/buildChunkGraph.js +712 -0
- package/lib/compareLocations.js +52 -0
- package/lib/debug/ProfilingPlugin.js +442 -0
- package/lib/dependencies/AMDDefineDependency.js +137 -0
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +336 -0
- package/lib/dependencies/AMDPlugin.js +249 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +49 -0
- package/lib/dependencies/AMDRequireContextDependency.js +20 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +47 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +274 -0
- package/lib/dependencies/AMDRequireDependency.js +135 -0
- package/lib/dependencies/AMDRequireItemDependency.js +22 -0
- package/lib/dependencies/CommonJsPlugin.js +158 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -0
- package/lib/dependencies/CommonJsRequireDependency.js +22 -0
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +138 -0
- package/lib/dependencies/ConstDependency.js +33 -0
- package/lib/dependencies/ContextDependency.js +68 -0
- package/lib/dependencies/ContextDependencyHelpers.js +232 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +43 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +39 -0
- package/lib/dependencies/ContextElementDependency.js +21 -0
- package/lib/dependencies/CriticalDependencyWarning.js +20 -0
- package/lib/dependencies/DelegatedExportsDependency.js +33 -0
- package/lib/dependencies/DelegatedSourceDependency.js +18 -0
- package/lib/dependencies/DependencyReference.js +64 -0
- package/lib/dependencies/DllEntryDependency.js +20 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +48 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +96 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +154 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +58 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +659 -0
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +54 -0
- package/lib/dependencies/HarmonyImportDependency.js +109 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +222 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +163 -0
- package/lib/dependencies/HarmonyInitDependency.js +60 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +143 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -0
- package/lib/dependencies/ImportContextDependency.js +23 -0
- package/lib/dependencies/ImportDependenciesBlock.js +18 -0
- package/lib/dependencies/ImportDependency.js +34 -0
- package/lib/dependencies/ImportEagerDependency.js +32 -0
- package/lib/dependencies/ImportParserPlugin.js +248 -0
- package/lib/dependencies/ImportPlugin.js +79 -0
- package/lib/dependencies/ImportWeakDependency.js +34 -0
- package/lib/dependencies/JsonExportsDependency.js +26 -0
- package/lib/dependencies/LoaderDependency.js +21 -0
- package/lib/dependencies/LoaderPlugin.js +115 -0
- package/lib/dependencies/LocalModule.js +23 -0
- package/lib/dependencies/LocalModuleDependency.js +28 -0
- package/lib/dependencies/LocalModulesHelpers.js +52 -0
- package/lib/dependencies/ModuleDependency.js +23 -0
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +23 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +23 -0
- package/lib/dependencies/MultiEntryDependency.js +25 -0
- package/lib/dependencies/NullDependency.js +20 -0
- package/lib/dependencies/PrefetchDependency.js +18 -0
- package/lib/dependencies/RequireContextDependency.js +22 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -0
- package/lib/dependencies/RequireContextPlugin.js +143 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -0
- package/lib/dependencies/RequireEnsureDependency.js +58 -0
- package/lib/dependencies/RequireEnsureItemDependency.js +21 -0
- package/lib/dependencies/RequireEnsurePlugin.js +74 -0
- package/lib/dependencies/RequireHeaderDependency.js +26 -0
- package/lib/dependencies/RequireIncludeDependency.js +39 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -0
- package/lib/dependencies/RequireIncludePlugin.js +61 -0
- package/lib/dependencies/RequireResolveContextDependency.js +23 -0
- package/lib/dependencies/RequireResolveDependency.js +22 -0
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +86 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +26 -0
- package/lib/dependencies/SingleEntryDependency.js +21 -0
- package/lib/dependencies/SystemPlugin.js +122 -0
- package/lib/dependencies/UnsupportedDependency.js +27 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +31 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +54 -0
- package/lib/dependencies/WebpackMissingModule.js +20 -0
- package/lib/dependencies/getFunctionExpression.js +52 -0
- package/lib/formatLocation.js +75 -0
- package/lib/logging/Logger.js +128 -0
- package/lib/logging/createConsoleLogger.js +210 -0
- package/lib/logging/runtime.js +36 -0
- package/lib/logging/truncateArgs.js +76 -0
- package/lib/node/NodeChunkTemplatePlugin.js +31 -0
- package/lib/node/NodeEnvironmentPlugin.js +44 -0
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -0
- package/lib/node/NodeMainTemplate.runtime.js +32 -0
- package/lib/node/NodeMainTemplateAsync.runtime.js +50 -0
- package/lib/node/NodeMainTemplatePlugin.js +321 -0
- package/lib/node/NodeOutputFileSystem.js +22 -0
- package/lib/node/NodeSourcePlugin.js +141 -0
- package/lib/node/NodeTargetPlugin.js +19 -0
- package/lib/node/NodeTemplatePlugin.js +31 -0
- package/lib/node/NodeWatchFileSystem.js +109 -0
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +61 -0
- package/lib/node/nodeConsole.js +135 -0
- package/lib/optimize/AggressiveMergingPlugin.js +87 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +294 -0
- package/lib/optimize/ChunkModuleIdRangePlugin.js +66 -0
- package/lib/optimize/ConcatenatedModule.js +1477 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +99 -0
- package/lib/optimize/LimitChunkCountPlugin.js +231 -0
- package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -0
- package/lib/optimize/MinChunkSizePlugin.js +82 -0
- package/lib/optimize/MinMaxSizeWarning.js +29 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +485 -0
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +66 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +112 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +135 -0
- package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -0
- package/lib/optimize/RemoveParentModulesPlugin.js +127 -0
- package/lib/optimize/RuntimeChunkPlugin.js +41 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +352 -0
- package/lib/optimize/SplitChunksPlugin.js +971 -0
- package/lib/performance/AssetsOverSizeLimitWarning.js +30 -0
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +30 -0
- package/lib/performance/NoAsyncChunksWarning.js +21 -0
- package/lib/performance/SizeLimitsPlugin.js +125 -0
- package/lib/util/LazyBucketSortedSet.js +235 -0
- package/lib/util/Queue.js +46 -0
- package/lib/util/Semaphore.js +53 -0
- package/lib/util/SetHelpers.js +48 -0
- package/lib/util/SortableSet.js +140 -0
- package/lib/util/StackedSetMap.js +142 -0
- package/lib/util/TrackingSet.js +35 -0
- package/lib/util/cachedMerge.js +35 -0
- package/lib/util/cleverMerge.js +77 -0
- package/lib/util/createHash.js +174 -0
- package/lib/util/deterministicGrouping.js +274 -0
- package/lib/util/hash/BatchedHash.js +71 -0
- package/lib/util/hash/md4.js +25 -0
- package/lib/util/hash/wasm-hash.js +174 -0
- package/lib/util/identifier.js +127 -0
- package/lib/util/objectToMap.js +16 -0
- package/lib/validateSchema.js +67 -0
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +17 -0
- package/lib/wasm/WasmFinalizeExportsPlugin.js +69 -0
- package/lib/wasm/WasmMainTemplatePlugin.js +341 -0
- package/lib/wasm/WebAssemblyGenerator.js +458 -0
- package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +152 -0
- package/lib/wasm/WebAssemblyModulesPlugin.js +128 -0
- package/lib/wasm/WebAssemblyParser.js +175 -0
- package/lib/wasm/WebAssemblyUtils.js +59 -0
- package/lib/web/FetchCompileWasmTemplatePlugin.js +37 -0
- package/lib/web/JsonpChunkTemplatePlugin.js +71 -0
- package/lib/web/JsonpExportMainTemplatePlugin.js +50 -0
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -0
- package/lib/web/JsonpMainTemplate.runtime.js +71 -0
- package/lib/web/JsonpMainTemplatePlugin.js +615 -0
- package/lib/web/JsonpTemplatePlugin.js +23 -0
- package/lib/web/WebEnvironmentPlugin.js +18 -0
- package/lib/webpack.js +206 -0
- package/lib/webpack.web.js +31 -0
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -0
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -0
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +73 -0
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +192 -0
- package/lib/webworker/WebWorkerTemplatePlugin.js +25 -0
- package/package.json +211 -0
- package/schemas/WebpackOptions.json +2285 -0
- package/schemas/ajv.absolutePath.js +57 -0
- package/schemas/plugins/BannerPlugin.json +101 -0
- package/schemas/plugins/DllPlugin.json +36 -0
- package/schemas/plugins/DllReferencePlugin.json +205 -0
- package/schemas/plugins/HashedModuleIdsPlugin.json +26 -0
- package/schemas/plugins/IgnorePlugin.json +37 -0
- package/schemas/plugins/LoaderOptionsPlugin.json +27 -0
- package/schemas/plugins/ProgressPlugin.json +52 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +185 -0
- package/schemas/plugins/WatchIgnorePlugin.json +18 -0
- package/schemas/plugins/debug/ProfilingPlugin.json +13 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +16 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +12 -0
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +11 -0
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +11 -0
- package/web_modules/node-libs-browser.js +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
// TODO webpack 5 remove this plugin
|
|
8
|
+
// It has been splitted into separate plugins for modules and chunks
|
|
9
|
+
class OccurrenceOrderPlugin {
|
|
10
|
+
constructor(preferEntry) {
|
|
11
|
+
if (preferEntry !== undefined && typeof preferEntry !== "boolean") {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"Argument should be a boolean.\nFor more info on this plugin, see https://webpack.js.org/plugins/"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
this.preferEntry = preferEntry;
|
|
17
|
+
}
|
|
18
|
+
apply(compiler) {
|
|
19
|
+
const preferEntry = this.preferEntry;
|
|
20
|
+
compiler.hooks.compilation.tap("OccurrenceOrderPlugin", compilation => {
|
|
21
|
+
compilation.hooks.optimizeModuleOrder.tap(
|
|
22
|
+
"OccurrenceOrderPlugin",
|
|
23
|
+
modules => {
|
|
24
|
+
const occursInInitialChunksMap = new Map();
|
|
25
|
+
const occursInAllChunksMap = new Map();
|
|
26
|
+
|
|
27
|
+
const initialChunkChunkMap = new Map();
|
|
28
|
+
const entryCountMap = new Map();
|
|
29
|
+
for (const m of modules) {
|
|
30
|
+
let initial = 0;
|
|
31
|
+
let entry = 0;
|
|
32
|
+
for (const c of m.chunksIterable) {
|
|
33
|
+
if (c.canBeInitial()) initial++;
|
|
34
|
+
if (c.entryModule === m) entry++;
|
|
35
|
+
}
|
|
36
|
+
initialChunkChunkMap.set(m, initial);
|
|
37
|
+
entryCountMap.set(m, entry);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const countOccursInEntry = (sum, r) => {
|
|
41
|
+
if (!r.module) {
|
|
42
|
+
return sum;
|
|
43
|
+
}
|
|
44
|
+
return sum + initialChunkChunkMap.get(r.module);
|
|
45
|
+
};
|
|
46
|
+
const countOccurs = (sum, r) => {
|
|
47
|
+
if (!r.module) {
|
|
48
|
+
return sum;
|
|
49
|
+
}
|
|
50
|
+
let factor = 1;
|
|
51
|
+
if (typeof r.dependency.getNumberOfIdOccurrences === "function") {
|
|
52
|
+
factor = r.dependency.getNumberOfIdOccurrences();
|
|
53
|
+
}
|
|
54
|
+
if (factor === 0) {
|
|
55
|
+
return sum;
|
|
56
|
+
}
|
|
57
|
+
return sum + factor * r.module.getNumberOfChunks();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (preferEntry) {
|
|
61
|
+
for (const m of modules) {
|
|
62
|
+
const result =
|
|
63
|
+
m.reasons.reduce(countOccursInEntry, 0) +
|
|
64
|
+
initialChunkChunkMap.get(m) +
|
|
65
|
+
entryCountMap.get(m);
|
|
66
|
+
occursInInitialChunksMap.set(m, result);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const originalOrder = new Map();
|
|
71
|
+
let i = 0;
|
|
72
|
+
for (const m of modules) {
|
|
73
|
+
const result =
|
|
74
|
+
m.reasons.reduce(countOccurs, 0) +
|
|
75
|
+
m.getNumberOfChunks() +
|
|
76
|
+
entryCountMap.get(m);
|
|
77
|
+
occursInAllChunksMap.set(m, result);
|
|
78
|
+
originalOrder.set(m, i++);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
modules.sort((a, b) => {
|
|
82
|
+
if (preferEntry) {
|
|
83
|
+
const aEntryOccurs = occursInInitialChunksMap.get(a);
|
|
84
|
+
const bEntryOccurs = occursInInitialChunksMap.get(b);
|
|
85
|
+
if (aEntryOccurs > bEntryOccurs) return -1;
|
|
86
|
+
if (aEntryOccurs < bEntryOccurs) return 1;
|
|
87
|
+
}
|
|
88
|
+
const aOccurs = occursInAllChunksMap.get(a);
|
|
89
|
+
const bOccurs = occursInAllChunksMap.get(b);
|
|
90
|
+
if (aOccurs > bOccurs) return -1;
|
|
91
|
+
if (aOccurs < bOccurs) return 1;
|
|
92
|
+
const orgA = originalOrder.get(a);
|
|
93
|
+
const orgB = originalOrder.get(b);
|
|
94
|
+
return orgA - orgB;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
compilation.hooks.optimizeChunkOrder.tap(
|
|
99
|
+
"OccurrenceOrderPlugin",
|
|
100
|
+
chunks => {
|
|
101
|
+
const occursInInitialChunksMap = new Map();
|
|
102
|
+
const originalOrder = new Map();
|
|
103
|
+
|
|
104
|
+
let i = 0;
|
|
105
|
+
for (const c of chunks) {
|
|
106
|
+
let occurs = 0;
|
|
107
|
+
for (const chunkGroup of c.groupsIterable) {
|
|
108
|
+
for (const parent of chunkGroup.parentsIterable) {
|
|
109
|
+
if (parent.isInitial()) occurs++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
occursInInitialChunksMap.set(c, occurs);
|
|
113
|
+
originalOrder.set(c, i++);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
chunks.sort((a, b) => {
|
|
117
|
+
const aEntryOccurs = occursInInitialChunksMap.get(a);
|
|
118
|
+
const bEntryOccurs = occursInInitialChunksMap.get(b);
|
|
119
|
+
if (aEntryOccurs > bEntryOccurs) return -1;
|
|
120
|
+
if (aEntryOccurs < bEntryOccurs) return 1;
|
|
121
|
+
const aOccurs = a.getNumberOfGroups();
|
|
122
|
+
const bOccurs = b.getNumberOfGroups();
|
|
123
|
+
if (aOccurs > bOccurs) return -1;
|
|
124
|
+
if (aOccurs < bOccurs) return 1;
|
|
125
|
+
const orgA = originalOrder.get(a);
|
|
126
|
+
const orgB = originalOrder.get(b);
|
|
127
|
+
return orgA - orgB;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = OccurrenceOrderPlugin;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
class RemoveEmptyChunksPlugin {
|
|
8
|
+
apply(compiler) {
|
|
9
|
+
compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => {
|
|
10
|
+
const handler = chunks => {
|
|
11
|
+
for (let i = chunks.length - 1; i >= 0; i--) {
|
|
12
|
+
const chunk = chunks[i];
|
|
13
|
+
if (
|
|
14
|
+
chunk.isEmpty() &&
|
|
15
|
+
!chunk.hasRuntime() &&
|
|
16
|
+
!chunk.hasEntryModule()
|
|
17
|
+
) {
|
|
18
|
+
chunk.remove("empty");
|
|
19
|
+
chunks.splice(i, 1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
compilation.hooks.optimizeChunksBasic.tap(
|
|
24
|
+
"RemoveEmptyChunksPlugin",
|
|
25
|
+
handler
|
|
26
|
+
);
|
|
27
|
+
compilation.hooks.optimizeChunksAdvanced.tap(
|
|
28
|
+
"RemoveEmptyChunksPlugin",
|
|
29
|
+
handler
|
|
30
|
+
);
|
|
31
|
+
compilation.hooks.optimizeExtractedChunksBasic.tap(
|
|
32
|
+
"RemoveEmptyChunksPlugin",
|
|
33
|
+
handler
|
|
34
|
+
);
|
|
35
|
+
compilation.hooks.optimizeExtractedChunksAdvanced.tap(
|
|
36
|
+
"RemoveEmptyChunksPlugin",
|
|
37
|
+
handler
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
module.exports = RemoveEmptyChunksPlugin;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const Queue = require("../util/Queue");
|
|
8
|
+
const { intersect } = require("../util/SetHelpers");
|
|
9
|
+
|
|
10
|
+
const getParentChunksWithModule = (currentChunk, module) => {
|
|
11
|
+
const chunks = [];
|
|
12
|
+
const stack = new Set(currentChunk.parentsIterable);
|
|
13
|
+
|
|
14
|
+
for (const chunk of stack) {
|
|
15
|
+
if (chunk.containsModule(module)) {
|
|
16
|
+
chunks.push(chunk);
|
|
17
|
+
} else {
|
|
18
|
+
for (const parent of chunk.parentsIterable) {
|
|
19
|
+
stack.add(parent);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return chunks;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
class RemoveParentModulesPlugin {
|
|
28
|
+
apply(compiler) {
|
|
29
|
+
compiler.hooks.compilation.tap("RemoveParentModulesPlugin", compilation => {
|
|
30
|
+
const handler = (chunks, chunkGroups) => {
|
|
31
|
+
const queue = new Queue();
|
|
32
|
+
const availableModulesMap = new WeakMap();
|
|
33
|
+
|
|
34
|
+
for (const chunkGroup of compilation.entrypoints.values()) {
|
|
35
|
+
// initialize available modules for chunks without parents
|
|
36
|
+
availableModulesMap.set(chunkGroup, new Set());
|
|
37
|
+
for (const child of chunkGroup.childrenIterable) {
|
|
38
|
+
queue.enqueue(child);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
while (queue.length > 0) {
|
|
43
|
+
const chunkGroup = queue.dequeue();
|
|
44
|
+
let availableModules = availableModulesMap.get(chunkGroup);
|
|
45
|
+
let changed = false;
|
|
46
|
+
for (const parent of chunkGroup.parentsIterable) {
|
|
47
|
+
const availableModulesInParent = availableModulesMap.get(parent);
|
|
48
|
+
if (availableModulesInParent !== undefined) {
|
|
49
|
+
// If we know the available modules in parent: process these
|
|
50
|
+
if (availableModules === undefined) {
|
|
51
|
+
// if we have not own info yet: create new entry
|
|
52
|
+
availableModules = new Set(availableModulesInParent);
|
|
53
|
+
for (const chunk of parent.chunks) {
|
|
54
|
+
for (const m of chunk.modulesIterable) {
|
|
55
|
+
availableModules.add(m);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
availableModulesMap.set(chunkGroup, availableModules);
|
|
59
|
+
changed = true;
|
|
60
|
+
} else {
|
|
61
|
+
for (const m of availableModules) {
|
|
62
|
+
if (
|
|
63
|
+
!parent.containsModule(m) &&
|
|
64
|
+
!availableModulesInParent.has(m)
|
|
65
|
+
) {
|
|
66
|
+
availableModules.delete(m);
|
|
67
|
+
changed = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (changed) {
|
|
74
|
+
// if something changed: enqueue our children
|
|
75
|
+
for (const child of chunkGroup.childrenIterable) {
|
|
76
|
+
queue.enqueue(child);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// now we have available modules for every chunk
|
|
82
|
+
for (const chunk of chunks) {
|
|
83
|
+
const availableModulesSets = Array.from(
|
|
84
|
+
chunk.groupsIterable,
|
|
85
|
+
chunkGroup => availableModulesMap.get(chunkGroup)
|
|
86
|
+
);
|
|
87
|
+
if (availableModulesSets.some(s => s === undefined)) continue; // No info about this chunk group
|
|
88
|
+
const availableModules =
|
|
89
|
+
availableModulesSets.length === 1
|
|
90
|
+
? availableModulesSets[0]
|
|
91
|
+
: intersect(availableModulesSets);
|
|
92
|
+
const numberOfModules = chunk.getNumberOfModules();
|
|
93
|
+
const toRemove = new Set();
|
|
94
|
+
if (numberOfModules < availableModules.size) {
|
|
95
|
+
for (const m of chunk.modulesIterable) {
|
|
96
|
+
if (availableModules.has(m)) {
|
|
97
|
+
toRemove.add(m);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
for (const m of availableModules) {
|
|
102
|
+
if (chunk.containsModule(m)) {
|
|
103
|
+
toRemove.add(m);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const module of toRemove) {
|
|
108
|
+
module.rewriteChunkInReasons(
|
|
109
|
+
chunk,
|
|
110
|
+
getParentChunksWithModule(chunk, module)
|
|
111
|
+
);
|
|
112
|
+
chunk.removeModule(module);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
compilation.hooks.optimizeChunksBasic.tap(
|
|
117
|
+
"RemoveParentModulesPlugin",
|
|
118
|
+
handler
|
|
119
|
+
);
|
|
120
|
+
compilation.hooks.optimizeExtractedChunksBasic.tap(
|
|
121
|
+
"RemoveParentModulesPlugin",
|
|
122
|
+
handler
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
module.exports = RemoveParentModulesPlugin;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
module.exports = class RuntimeChunkPlugin {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = Object.assign(
|
|
10
|
+
{
|
|
11
|
+
name: entrypoint => `runtime~${entrypoint.name}`
|
|
12
|
+
},
|
|
13
|
+
options
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
apply(compiler) {
|
|
18
|
+
compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => {
|
|
19
|
+
compilation.hooks.optimizeChunksAdvanced.tap("RuntimeChunkPlugin", () => {
|
|
20
|
+
for (const entrypoint of compilation.entrypoints.values()) {
|
|
21
|
+
const chunk = entrypoint.getRuntimeChunk();
|
|
22
|
+
let name = this.options.name;
|
|
23
|
+
if (typeof name === "function") {
|
|
24
|
+
name = name(entrypoint);
|
|
25
|
+
}
|
|
26
|
+
if (
|
|
27
|
+
chunk.getNumberOfModules() > 0 ||
|
|
28
|
+
!chunk.preventIntegration ||
|
|
29
|
+
chunk.name !== name
|
|
30
|
+
) {
|
|
31
|
+
const newChunk = compilation.addChunk(name);
|
|
32
|
+
newChunk.preventIntegration = true;
|
|
33
|
+
entrypoint.unshiftChunk(newChunk);
|
|
34
|
+
newChunk.addGroup(entrypoint);
|
|
35
|
+
entrypoint.setRuntimeChunk(newChunk);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const mm = require("micromatch");
|
|
8
|
+
const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
|
|
9
|
+
const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
|
|
10
|
+
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
|
|
11
|
+
|
|
12
|
+
/** @typedef {import("../Module")} Module */
|
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Object} ExportInModule
|
|
17
|
+
* @property {Module} module the module
|
|
18
|
+
* @property {string} exportName the name of the export
|
|
19
|
+
* @property {boolean} checked if the export is conditional
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {Object} ReexportInfo
|
|
24
|
+
* @property {Map<string, ExportInModule[]>} static
|
|
25
|
+
* @property {Map<Module, Set<string>>} dynamic
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {ReexportInfo} info info object
|
|
30
|
+
* @param {string} exportName name of export
|
|
31
|
+
* @returns {ExportInModule | undefined} static export
|
|
32
|
+
*/
|
|
33
|
+
const getMappingFromInfo = (info, exportName) => {
|
|
34
|
+
const staticMappings = info.static.get(exportName);
|
|
35
|
+
if (staticMappings !== undefined) {
|
|
36
|
+
if (staticMappings.length === 1) return staticMappings[0];
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const dynamicMappings = Array.from(info.dynamic).filter(
|
|
40
|
+
([_, ignored]) => !ignored.has(exportName)
|
|
41
|
+
);
|
|
42
|
+
if (dynamicMappings.length === 1) {
|
|
43
|
+
return {
|
|
44
|
+
module: dynamicMappings[0][0],
|
|
45
|
+
exportName,
|
|
46
|
+
checked: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {ReexportInfo} info info object
|
|
54
|
+
* @param {string} exportName name of export of source module
|
|
55
|
+
* @param {Module} module the target module
|
|
56
|
+
* @param {string} innerExportName name of export of target module
|
|
57
|
+
* @param {boolean} checked true, if existence of target module is checked
|
|
58
|
+
*/
|
|
59
|
+
const addStaticReexport = (
|
|
60
|
+
info,
|
|
61
|
+
exportName,
|
|
62
|
+
module,
|
|
63
|
+
innerExportName,
|
|
64
|
+
checked
|
|
65
|
+
) => {
|
|
66
|
+
let mappings = info.static.get(exportName);
|
|
67
|
+
if (mappings !== undefined) {
|
|
68
|
+
for (const mapping of mappings) {
|
|
69
|
+
if (mapping.module === module && mapping.exportName === innerExportName) {
|
|
70
|
+
mapping.checked = mapping.checked && checked;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
mappings = [];
|
|
76
|
+
info.static.set(exportName, mappings);
|
|
77
|
+
}
|
|
78
|
+
mappings.push({
|
|
79
|
+
module,
|
|
80
|
+
exportName: innerExportName,
|
|
81
|
+
checked
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {ReexportInfo} info info object
|
|
87
|
+
* @param {Module} module the reexport module
|
|
88
|
+
* @param {Set<string>} ignored ignore list
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
const addDynamicReexport = (info, module, ignored) => {
|
|
92
|
+
const existingList = info.dynamic.get(module);
|
|
93
|
+
if (existingList !== undefined) {
|
|
94
|
+
for (const key of existingList) {
|
|
95
|
+
if (!ignored.has(key)) existingList.delete(key);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
info.dynamic.set(module, new Set(ignored));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
class SideEffectsFlagPlugin {
|
|
103
|
+
apply(compiler) {
|
|
104
|
+
compiler.hooks.normalModuleFactory.tap("SideEffectsFlagPlugin", nmf => {
|
|
105
|
+
nmf.hooks.module.tap("SideEffectsFlagPlugin", (module, data) => {
|
|
106
|
+
const resolveData = data.resourceResolveData;
|
|
107
|
+
if (
|
|
108
|
+
resolveData &&
|
|
109
|
+
resolveData.descriptionFileData &&
|
|
110
|
+
resolveData.relativePath
|
|
111
|
+
) {
|
|
112
|
+
const sideEffects = resolveData.descriptionFileData.sideEffects;
|
|
113
|
+
const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects(
|
|
114
|
+
resolveData.relativePath,
|
|
115
|
+
sideEffects
|
|
116
|
+
);
|
|
117
|
+
if (!hasSideEffects) {
|
|
118
|
+
module.factoryMeta.sideEffectFree = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return module;
|
|
123
|
+
});
|
|
124
|
+
nmf.hooks.module.tap("SideEffectsFlagPlugin", (module, data) => {
|
|
125
|
+
if (data.settings.sideEffects === false) {
|
|
126
|
+
module.factoryMeta.sideEffectFree = true;
|
|
127
|
+
} else if (data.settings.sideEffects === true) {
|
|
128
|
+
module.factoryMeta.sideEffectFree = false;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
compiler.hooks.compilation.tap("SideEffectsFlagPlugin", compilation => {
|
|
133
|
+
compilation.hooks.optimizeDependencies.tap(
|
|
134
|
+
"SideEffectsFlagPlugin",
|
|
135
|
+
modules => {
|
|
136
|
+
/** @type {Map<Module, ReexportInfo>} */
|
|
137
|
+
const reexportMaps = new Map();
|
|
138
|
+
|
|
139
|
+
// Capture reexports of sideEffectFree modules
|
|
140
|
+
for (const module of modules) {
|
|
141
|
+
/** @type {Dependency[]} */
|
|
142
|
+
const removeDependencies = [];
|
|
143
|
+
for (const dep of module.dependencies) {
|
|
144
|
+
if (dep instanceof HarmonyImportSideEffectDependency) {
|
|
145
|
+
if (dep.module && dep.module.factoryMeta.sideEffectFree) {
|
|
146
|
+
removeDependencies.push(dep);
|
|
147
|
+
}
|
|
148
|
+
} else if (
|
|
149
|
+
dep instanceof HarmonyExportImportedSpecifierDependency
|
|
150
|
+
) {
|
|
151
|
+
if (module.factoryMeta.sideEffectFree) {
|
|
152
|
+
const mode = dep.getMode(true);
|
|
153
|
+
if (
|
|
154
|
+
mode.type === "safe-reexport" ||
|
|
155
|
+
mode.type === "checked-reexport" ||
|
|
156
|
+
mode.type === "dynamic-reexport" ||
|
|
157
|
+
mode.type === "reexport-non-harmony-default" ||
|
|
158
|
+
mode.type === "reexport-non-harmony-default-strict" ||
|
|
159
|
+
mode.type === "reexport-named-default"
|
|
160
|
+
) {
|
|
161
|
+
let info = reexportMaps.get(module);
|
|
162
|
+
if (!info) {
|
|
163
|
+
reexportMaps.set(
|
|
164
|
+
module,
|
|
165
|
+
(info = {
|
|
166
|
+
static: new Map(),
|
|
167
|
+
dynamic: new Map()
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const targetModule = dep._module;
|
|
172
|
+
switch (mode.type) {
|
|
173
|
+
case "safe-reexport":
|
|
174
|
+
for (const [key, id] of mode.map) {
|
|
175
|
+
if (id) {
|
|
176
|
+
addStaticReexport(
|
|
177
|
+
info,
|
|
178
|
+
key,
|
|
179
|
+
targetModule,
|
|
180
|
+
id,
|
|
181
|
+
false
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
case "checked-reexport":
|
|
187
|
+
for (const [key, id] of mode.map) {
|
|
188
|
+
if (id) {
|
|
189
|
+
addStaticReexport(
|
|
190
|
+
info,
|
|
191
|
+
key,
|
|
192
|
+
targetModule,
|
|
193
|
+
id,
|
|
194
|
+
true
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
break;
|
|
199
|
+
case "dynamic-reexport":
|
|
200
|
+
addDynamicReexport(info, targetModule, mode.ignored);
|
|
201
|
+
break;
|
|
202
|
+
case "reexport-non-harmony-default":
|
|
203
|
+
case "reexport-non-harmony-default-strict":
|
|
204
|
+
case "reexport-named-default":
|
|
205
|
+
addStaticReexport(
|
|
206
|
+
info,
|
|
207
|
+
mode.name,
|
|
208
|
+
targetModule,
|
|
209
|
+
"default",
|
|
210
|
+
false
|
|
211
|
+
);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Flatten reexports
|
|
221
|
+
for (const info of reexportMaps.values()) {
|
|
222
|
+
const dynamicReexports = info.dynamic;
|
|
223
|
+
info.dynamic = new Map();
|
|
224
|
+
for (const reexport of dynamicReexports) {
|
|
225
|
+
let [targetModule, ignored] = reexport;
|
|
226
|
+
for (;;) {
|
|
227
|
+
const innerInfo = reexportMaps.get(targetModule);
|
|
228
|
+
if (!innerInfo) break;
|
|
229
|
+
|
|
230
|
+
for (const [key, reexports] of innerInfo.static) {
|
|
231
|
+
if (ignored.has(key)) continue;
|
|
232
|
+
for (const { module, exportName, checked } of reexports) {
|
|
233
|
+
addStaticReexport(info, key, module, exportName, checked);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Follow dynamic reexport if there is only one
|
|
238
|
+
if (innerInfo.dynamic.size !== 1) {
|
|
239
|
+
// When there are more then one, we don't know which one
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
ignored = new Set(ignored);
|
|
244
|
+
for (const [innerModule, innerIgnored] of innerInfo.dynamic) {
|
|
245
|
+
for (const key of innerIgnored) {
|
|
246
|
+
if (ignored.has(key)) continue;
|
|
247
|
+
// This reexports ends here
|
|
248
|
+
addStaticReexport(info, key, targetModule, key, true);
|
|
249
|
+
ignored.add(key);
|
|
250
|
+
}
|
|
251
|
+
targetModule = innerModule;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Update reexport as all other cases has been handled
|
|
256
|
+
addDynamicReexport(info, targetModule, ignored);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
for (const info of reexportMaps.values()) {
|
|
261
|
+
const staticReexports = info.static;
|
|
262
|
+
info.static = new Map();
|
|
263
|
+
for (const [key, reexports] of staticReexports) {
|
|
264
|
+
for (let mapping of reexports) {
|
|
265
|
+
for (;;) {
|
|
266
|
+
const innerInfo = reexportMaps.get(mapping.module);
|
|
267
|
+
if (!innerInfo) break;
|
|
268
|
+
|
|
269
|
+
const newMapping = getMappingFromInfo(
|
|
270
|
+
innerInfo,
|
|
271
|
+
mapping.exportName
|
|
272
|
+
);
|
|
273
|
+
if (!newMapping) break;
|
|
274
|
+
mapping = newMapping;
|
|
275
|
+
}
|
|
276
|
+
addStaticReexport(
|
|
277
|
+
info,
|
|
278
|
+
key,
|
|
279
|
+
mapping.module,
|
|
280
|
+
mapping.exportName,
|
|
281
|
+
mapping.checked
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Update imports along the reexports from sideEffectFree modules
|
|
288
|
+
for (const pair of reexportMaps) {
|
|
289
|
+
const module = pair[0];
|
|
290
|
+
const info = pair[1];
|
|
291
|
+
let newReasons = undefined;
|
|
292
|
+
for (let i = 0; i < module.reasons.length; i++) {
|
|
293
|
+
const reason = module.reasons[i];
|
|
294
|
+
const dep = reason.dependency;
|
|
295
|
+
if (
|
|
296
|
+
(dep instanceof HarmonyExportImportedSpecifierDependency ||
|
|
297
|
+
(dep instanceof HarmonyImportSpecifierDependency &&
|
|
298
|
+
!dep.namespaceObjectAsContext)) &&
|
|
299
|
+
dep._id
|
|
300
|
+
) {
|
|
301
|
+
const mapping = getMappingFromInfo(info, dep._id);
|
|
302
|
+
if (mapping) {
|
|
303
|
+
dep.redirectedModule = mapping.module;
|
|
304
|
+
dep.redirectedId = mapping.exportName;
|
|
305
|
+
mapping.module.addReason(
|
|
306
|
+
reason.module,
|
|
307
|
+
dep,
|
|
308
|
+
reason.explanation
|
|
309
|
+
? reason.explanation +
|
|
310
|
+
" (skipped side-effect-free modules)"
|
|
311
|
+
: "(skipped side-effect-free modules)"
|
|
312
|
+
);
|
|
313
|
+
// removing the currect reason, by not adding it to the newReasons array
|
|
314
|
+
// lazily create the newReasons array
|
|
315
|
+
if (newReasons === undefined) {
|
|
316
|
+
newReasons = i === 0 ? [] : module.reasons.slice(0, i);
|
|
317
|
+
}
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (newReasons !== undefined) newReasons.push(reason);
|
|
322
|
+
}
|
|
323
|
+
if (newReasons !== undefined) {
|
|
324
|
+
module.reasons = newReasons;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
static moduleHasSideEffects(moduleName, flagValue) {
|
|
333
|
+
switch (typeof flagValue) {
|
|
334
|
+
case "undefined":
|
|
335
|
+
return true;
|
|
336
|
+
case "boolean":
|
|
337
|
+
return flagValue;
|
|
338
|
+
case "string":
|
|
339
|
+
if (process.platform === "win32") {
|
|
340
|
+
flagValue = flagValue.replace(/\\/g, "/");
|
|
341
|
+
}
|
|
342
|
+
return mm.isMatch(moduleName, flagValue, {
|
|
343
|
+
matchBase: true
|
|
344
|
+
});
|
|
345
|
+
case "object":
|
|
346
|
+
return flagValue.some(glob =>
|
|
347
|
+
SideEffectsFlagPlugin.moduleHasSideEffects(moduleName, glob)
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
module.exports = SideEffectsFlagPlugin;
|