webpack 5.101.3 → 5.102.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -26
- package/lib/APIPlugin.js +30 -36
- package/lib/AsyncDependenciesBlock.js +1 -4
- package/lib/BannerPlugin.js +0 -1
- package/lib/Cache.js +7 -6
- package/lib/CacheFacade.js +0 -1
- package/lib/Chunk.js +49 -31
- package/lib/ChunkGraph.js +37 -27
- package/lib/ChunkGroup.js +8 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +3 -3
- package/lib/CodeGenerationResults.js +3 -2
- package/lib/CompatibilityPlugin.js +29 -12
- package/lib/Compilation.js +209 -196
- package/lib/Compiler.js +36 -35
- package/lib/ConcatenationScope.js +6 -1
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +6 -5
- package/lib/ContextExclusionPlugin.js +0 -1
- package/lib/ContextModule.js +25 -21
- package/lib/ContextModuleFactory.js +30 -11
- package/lib/ContextReplacementPlugin.js +38 -15
- package/lib/DefinePlugin.js +5 -9
- package/lib/DelegatedModule.js +7 -11
- package/lib/DependenciesBlock.js +0 -2
- package/lib/Dependency.js +9 -11
- package/lib/DependencyTemplates.js +2 -4
- package/lib/DllModule.js +1 -7
- package/lib/DllReferencePlugin.js +2 -4
- package/lib/DynamicEntryPlugin.js +0 -2
- package/lib/EntryOptionPlugin.js +0 -5
- package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
- package/lib/EvalDevToolModulePlugin.js +4 -3
- package/lib/EvalSourceMapDevToolPlugin.js +3 -4
- package/lib/ExportsInfo.js +50 -49
- package/lib/ExternalModule.js +84 -52
- package/lib/ExternalModuleFactoryPlugin.js +27 -7
- package/lib/ExternalsPlugin.js +24 -17
- package/lib/FileSystemInfo.js +105 -90
- package/lib/FlagDependencyUsagePlugin.js +3 -4
- package/lib/Generator.js +2 -13
- package/lib/GraphHelpers.js +0 -3
- package/lib/HookWebpackError.js +0 -2
- package/lib/HotModuleReplacementPlugin.js +22 -24
- package/lib/HotUpdateChunk.js +0 -3
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InitFragment.js +41 -29
- package/lib/InvalidDependenciesModuleWarning.js +0 -1
- package/lib/LibManifestPlugin.js +4 -6
- package/lib/LoaderOptionsPlugin.js +1 -10
- package/lib/MainTemplate.js +8 -19
- package/lib/Module.js +32 -20
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleFilenameHelpers.js +42 -25
- package/lib/ModuleGraph.js +30 -16
- package/lib/ModuleInfoHeaderPlugin.js +0 -1
- package/lib/ModuleTemplate.js +0 -2
- package/lib/ModuleTypeConstants.js +11 -1
- package/lib/MultiCompiler.js +23 -15
- package/lib/MultiWatching.js +6 -10
- package/lib/NodeStuffPlugin.js +2 -10
- package/lib/NormalModule.js +146 -89
- package/lib/NormalModuleFactory.js +132 -42
- package/lib/OptionsApply.js +1 -1
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +6 -10
- package/lib/ProvidePlugin.js +5 -7
- package/lib/RawModule.js +1 -6
- package/lib/RecordIdsPlugin.js +10 -6
- package/lib/ResolverFactory.js +0 -2
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +1 -3
- package/lib/RuntimePlugin.js +26 -22
- package/lib/RuntimeTemplate.js +22 -12
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +11 -18
- package/lib/Stats.js +0 -1
- package/lib/Template.js +6 -11
- package/lib/TemplatedPathPlugin.js +2 -1
- package/lib/WatchIgnorePlugin.js +2 -3
- package/lib/Watching.js +15 -15
- package/lib/WebpackIsIncludedPlugin.js +0 -2
- package/lib/WebpackOptionsApply.js +74 -107
- package/lib/asset/AssetBytesGenerator.js +167 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +22 -37
- package/lib/asset/AssetModulesPlugin.js +34 -16
- package/lib/asset/AssetParser.js +7 -3
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/asset/RawDataUrlModule.js +3 -2
- package/lib/async-modules/AsyncModuleHelpers.js +6 -4
- package/lib/buildChunkGraph.js +0 -1
- package/lib/cache/MemoryCachePlugin.js +0 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
- package/lib/cache/PackFileCacheStrategy.js +14 -1
- package/lib/cache/ResolverCachePlugin.js +9 -15
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +77 -76
- package/lib/config/defaults.js +162 -23
- package/lib/config/normalization.js +18 -3
- package/lib/config/target.js +1 -1
- package/lib/container/ContainerEntryDependency.js +0 -1
- package/lib/container/ContainerEntryModule.js +3 -7
- package/lib/container/ContainerPlugin.js +1 -2
- package/lib/container/ContainerReferencePlugin.js +0 -1
- package/lib/container/FallbackDependency.js +2 -1
- package/lib/container/FallbackModule.js +6 -7
- package/lib/container/ModuleFederationPlugin.js +0 -1
- package/lib/container/RemoteModule.js +8 -8
- package/lib/container/RemoteRuntimeModule.js +2 -2
- package/lib/css/CssGenerator.js +3 -6
- package/lib/css/CssLoadingRuntimeModule.js +6 -9
- package/lib/css/CssModulesPlugin.js +13 -19
- package/lib/css/CssParser.js +3 -3
- package/lib/css/walkCssTokens.js +2 -2
- package/lib/debug/ProfilingPlugin.js +35 -8
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/CachedConstDependency.js +0 -4
- package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
- package/lib/dependencies/CommonJsExportsDependency.js +2 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
- package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +9 -4
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
- package/lib/dependencies/ContextElementDependency.js +22 -11
- package/lib/dependencies/CssIcssImportDependency.js +0 -2
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
- package/lib/dependencies/CssImportDependency.js +0 -8
- package/lib/dependencies/CssLocalIdentifierDependency.js +4 -7
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +0 -6
- package/lib/dependencies/ExportsInfoDependency.js +7 -9
- package/lib/dependencies/ExternalModuleDependency.js +0 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
- package/lib/dependencies/HarmonyImportDependency.js +33 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -23
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
- package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
- package/lib/dependencies/ImportContextDependency.js +13 -0
- package/lib/dependencies/ImportDependency.js +18 -6
- package/lib/dependencies/ImportEagerDependency.js +2 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
- package/lib/dependencies/ImportMetaPlugin.js +3 -2
- package/lib/dependencies/ImportParserPlugin.js +288 -45
- package/lib/dependencies/ImportWeakDependency.js +2 -3
- package/lib/dependencies/JsonExportsDependency.js +0 -1
- package/lib/dependencies/LoaderDependency.js +0 -3
- package/lib/dependencies/LoaderImportDependency.js +0 -3
- package/lib/dependencies/LoaderPlugin.js +11 -5
- package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
- package/lib/dependencies/ModuleDependency.js +3 -9
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/ProvidedDependency.js +6 -8
- package/lib/dependencies/PureExpressionDependency.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/RequireIncludeDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
- package/lib/dependencies/StaticExportsDependency.js +3 -5
- package/lib/dependencies/URLDependency.js +2 -7
- package/lib/dependencies/URLPlugin.js +1 -2
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
- package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
- package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
- package/lib/dependencies/WorkerDependency.js +2 -3
- package/lib/dependencies/WorkerPlugin.js +4 -12
- package/lib/dependencies/processExportInfo.js +2 -3
- package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/hmr/lazyCompilationBackend.js +13 -10
- package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
- package/lib/ids/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +1 -1
- package/lib/ids/NamedChunkIdsPlugin.js +1 -6
- package/lib/ids/NamedModuleIdsPlugin.js +1 -5
- package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
- package/lib/ids/SyncModuleIdsPlugin.js +4 -3
- package/lib/index.js +8 -7
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
- package/lib/javascript/BasicEvaluatedExpression.js +13 -6
- package/lib/javascript/ChunkFormatHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
- package/lib/javascript/JavascriptGenerator.js +2 -3
- package/lib/javascript/JavascriptModulesPlugin.js +46 -24
- package/lib/javascript/JavascriptParser.js +120 -55
- package/lib/javascript/JavascriptParserHelpers.js +2 -2
- package/lib/javascript/StartupHelpers.js +2 -4
- package/lib/json/JsonData.js +1 -1
- package/lib/json/JsonGenerator.js +4 -5
- package/lib/json/JsonModulesPlugin.js +0 -3
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +0 -1
- package/lib/library/AssignLibraryPlugin.js +23 -12
- package/lib/library/EnableLibraryPlugin.js +7 -11
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
- package/lib/library/JsonpLibraryPlugin.js +5 -2
- package/lib/library/ModuleLibraryPlugin.js +88 -43
- package/lib/library/SystemLibraryPlugin.js +15 -6
- package/lib/library/UmdLibraryPlugin.js +12 -18
- package/lib/logging/Logger.js +12 -10
- package/lib/logging/createConsoleLogger.js +15 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeWatchFileSystem.js +4 -4
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
- package/lib/optimize/ConcatenatedModule.js +142 -100
- package/lib/optimize/InnerGraph.js +17 -11
- package/lib/optimize/InnerGraphPlugin.js +0 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
- package/lib/optimize/RealContentHashPlugin.js +5 -3
- package/lib/optimize/RuntimeChunkPlugin.js +0 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
- package/lib/optimize/SplitChunksPlugin.js +46 -40
- package/lib/performance/SizeLimitsPlugin.js +2 -1
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/rules/BasicMatcherRulePlugin.js +0 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
- package/lib/rules/RuleSetCompiler.js +8 -6
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +0 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
- package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
- package/lib/runtime/SystemContextRuntimeModule.js +0 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
- package/lib/schemes/DataUriPlugin.js +2 -28
- package/lib/schemes/FileUriPlugin.js +5 -2
- package/lib/schemes/HttpUriPlugin.js +4 -2
- package/lib/schemes/VirtualUrlPlugin.js +11 -11
- package/lib/serialization/FileMiddleware.js +1 -1
- package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
- package/lib/serialization/ObjectMiddleware.js +31 -20
- package/lib/serialization/SerializerMiddleware.js +1 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +3 -5
- package/lib/sharing/ConsumeSharedPlugin.js +2 -4
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
- package/lib/sharing/ProvideSharedModule.js +3 -7
- package/lib/sharing/SharePlugin.js +0 -2
- package/lib/sharing/ShareRuntimeModule.js +4 -1
- package/lib/sharing/resolveMatchedConfigs.js +14 -6
- package/lib/sharing/utils.js +0 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +179 -95
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
- package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
- package/lib/stats/StatsFactory.js +14 -11
- package/lib/url/URLParserPlugin.js +2 -4
- package/lib/util/ArrayHelpers.js +4 -4
- package/lib/util/AsyncQueue.js +1 -0
- package/lib/util/Hash.js +35 -5
- package/lib/util/LazySet.js +2 -2
- package/lib/util/StackedCacheMap.js +0 -2
- package/lib/util/TupleSet.js +9 -4
- package/lib/util/URLAbsoluteSpecifier.js +0 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/chainedImports.js +3 -1
- package/lib/util/cleverMerge.js +15 -18
- package/lib/util/comparators.js +2 -4
- package/lib/util/compileBooleanMatcher.js +11 -9
- package/lib/util/concatenate.js +1 -2
- package/lib/util/create-schema-validation.js +1 -2
- package/lib/util/createHash.js +85 -15
- package/lib/util/dataURL.js +39 -0
- package/lib/util/deprecation.js +29 -31
- package/lib/util/deterministicGrouping.js +34 -30
- package/lib/util/extractSourceMap.js +319 -0
- package/lib/util/findGraphRoots.js +15 -5
- package/lib/util/fs.js +29 -8
- package/lib/util/hash/BatchedHash.js +47 -8
- package/lib/util/hash/wasm-hash.js +53 -13
- package/lib/util/semver.js +9 -8
- package/lib/util/smartGrouping.js +41 -26
- package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
- package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -10
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
- package/lib/wasm-sync/WebAssemblyParser.js +1 -13
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/web/JsonpTemplatePlugin.js +0 -1
- package/lib/webpack.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +21 -21
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +93 -96
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +1699 -706
- package/SECURITY.md +0 -9
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
package/lib/Compiler.js
CHANGED
|
@@ -38,9 +38,9 @@ const webpack = require(".");
|
|
|
38
38
|
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
|
39
39
|
/** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */
|
|
40
40
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
|
41
|
-
/** @typedef {import("../declarations/WebpackOptions").
|
|
41
|
+
/** @typedef {import("../declarations/WebpackOptions").Plugins} Plugins */
|
|
42
|
+
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
|
|
42
43
|
/** @typedef {import("./Chunk")} Chunk */
|
|
43
|
-
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
|
44
44
|
/** @typedef {import("./Dependency")} Dependency */
|
|
45
45
|
/** @typedef {import("./HotModuleReplacementPlugin").ChunkHashes} ChunkHashes */
|
|
46
46
|
/** @typedef {import("./HotModuleReplacementPlugin").ChunkModuleHashes} ChunkModuleHashes */
|
|
@@ -70,23 +70,18 @@ const webpack = require(".");
|
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* @template T
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
75
|
-
* @param {T=} result
|
|
73
|
+
* @template [R=void]
|
|
74
|
+
* @typedef {import("./webpack").Callback<T, R>} Callback
|
|
76
75
|
*/
|
|
77
76
|
|
|
78
|
-
/**
|
|
79
|
-
* @template T
|
|
80
|
-
* @callback Callback
|
|
81
|
-
* @param {(Error | null)=} err
|
|
82
|
-
* @param {T=} result
|
|
83
|
-
*/
|
|
77
|
+
/** @typedef {import("./webpack").ErrorCallback} ErrorCallback */
|
|
84
78
|
|
|
85
79
|
/**
|
|
86
80
|
* @callback RunAsChildCallback
|
|
87
81
|
* @param {Error | null} err
|
|
88
82
|
* @param {Chunk[]=} entries
|
|
89
83
|
* @param {Compilation=} compilation
|
|
84
|
+
* @returns {void}
|
|
90
85
|
*/
|
|
91
86
|
|
|
92
87
|
/**
|
|
@@ -122,7 +117,8 @@ const webpack = require(".");
|
|
|
122
117
|
/** @typedef {{ buildInfo: BuildInfo, references: WeakReferences | undefined, memCache: MemCache }} ModuleMemCachesItem */
|
|
123
118
|
|
|
124
119
|
/**
|
|
125
|
-
* @
|
|
120
|
+
* @template T
|
|
121
|
+
* @param {T[]} array an array
|
|
126
122
|
* @returns {boolean} true, if the array is sorted
|
|
127
123
|
*/
|
|
128
124
|
const isSorted = (array) => {
|
|
@@ -478,12 +474,13 @@ class Compiler {
|
|
|
478
474
|
|
|
479
475
|
/**
|
|
480
476
|
* @param {WatchOptions} watchOptions the watcher's options
|
|
481
|
-
* @param {
|
|
482
|
-
* @returns {Watching} a compiler watcher
|
|
477
|
+
* @param {Callback<Stats>} handler signals when the call finishes
|
|
478
|
+
* @returns {Watching | undefined} a compiler watcher
|
|
483
479
|
*/
|
|
484
480
|
watch(watchOptions, handler) {
|
|
485
481
|
if (this.running) {
|
|
486
|
-
|
|
482
|
+
handler(new ConcurrentCompilationError());
|
|
483
|
+
return;
|
|
487
484
|
}
|
|
488
485
|
|
|
489
486
|
this.running = true;
|
|
@@ -493,12 +490,13 @@ class Compiler {
|
|
|
493
490
|
}
|
|
494
491
|
|
|
495
492
|
/**
|
|
496
|
-
* @param {
|
|
493
|
+
* @param {Callback<Stats>} callback signals when the call finishes
|
|
497
494
|
* @returns {void}
|
|
498
495
|
*/
|
|
499
496
|
run(callback) {
|
|
500
497
|
if (this.running) {
|
|
501
|
-
|
|
498
|
+
callback(new ConcurrentCompilationError());
|
|
499
|
+
return;
|
|
502
500
|
}
|
|
503
501
|
|
|
504
502
|
/** @type {Logger | undefined} */
|
|
@@ -695,7 +693,7 @@ class Compiler {
|
|
|
695
693
|
|
|
696
694
|
/**
|
|
697
695
|
* @param {Compilation} compilation the compilation
|
|
698
|
-
* @param {
|
|
696
|
+
* @param {ErrorCallback} callback signals when the assets are emitted
|
|
699
697
|
* @returns {void}
|
|
700
698
|
*/
|
|
701
699
|
emitAssets(compilation, callback) {
|
|
@@ -1028,7 +1026,7 @@ ${other}`);
|
|
|
1028
1026
|
this.hooks.afterEmit.callAsync(compilation, (err) => {
|
|
1029
1027
|
if (err) return callback(err);
|
|
1030
1028
|
|
|
1031
|
-
return callback();
|
|
1029
|
+
return callback(null);
|
|
1032
1030
|
});
|
|
1033
1031
|
}
|
|
1034
1032
|
);
|
|
@@ -1046,7 +1044,7 @@ ${other}`);
|
|
|
1046
1044
|
}
|
|
1047
1045
|
|
|
1048
1046
|
/**
|
|
1049
|
-
* @param {
|
|
1047
|
+
* @param {ErrorCallback} callback signals when the call finishes
|
|
1050
1048
|
* @returns {void}
|
|
1051
1049
|
*/
|
|
1052
1050
|
emitRecords(callback) {
|
|
@@ -1065,12 +1063,12 @@ ${other}`);
|
|
|
1065
1063
|
} else if (this.recordsOutputPath) {
|
|
1066
1064
|
this._emitRecords(callback);
|
|
1067
1065
|
} else {
|
|
1068
|
-
callback();
|
|
1066
|
+
callback(null);
|
|
1069
1067
|
}
|
|
1070
1068
|
}
|
|
1071
1069
|
|
|
1072
1070
|
/**
|
|
1073
|
-
* @param {
|
|
1071
|
+
* @param {ErrorCallback} callback signals when the call finishes
|
|
1074
1072
|
* @returns {void}
|
|
1075
1073
|
*/
|
|
1076
1074
|
_emitRecords(callback) {
|
|
@@ -1119,7 +1117,7 @@ ${other}`);
|
|
|
1119
1117
|
}
|
|
1120
1118
|
|
|
1121
1119
|
/**
|
|
1122
|
-
* @param {
|
|
1120
|
+
* @param {ErrorCallback} callback signals when the call finishes
|
|
1123
1121
|
* @returns {void}
|
|
1124
1122
|
*/
|
|
1125
1123
|
readRecords(callback) {
|
|
@@ -1140,28 +1138,29 @@ ${other}`);
|
|
|
1140
1138
|
this._readRecords(callback);
|
|
1141
1139
|
} else {
|
|
1142
1140
|
this.records = {};
|
|
1143
|
-
callback();
|
|
1141
|
+
callback(null);
|
|
1144
1142
|
}
|
|
1145
1143
|
}
|
|
1146
1144
|
|
|
1147
1145
|
/**
|
|
1148
|
-
* @param {
|
|
1146
|
+
* @param {ErrorCallback} callback signals when the call finishes
|
|
1149
1147
|
* @returns {void}
|
|
1150
1148
|
*/
|
|
1151
1149
|
_readRecords(callback) {
|
|
1152
1150
|
if (!this.recordsInputPath) {
|
|
1153
1151
|
this.records = {};
|
|
1154
|
-
return callback();
|
|
1152
|
+
return callback(null);
|
|
1155
1153
|
}
|
|
1156
1154
|
/** @type {InputFileSystem} */
|
|
1157
1155
|
(this.inputFileSystem).stat(this.recordsInputPath, (err) => {
|
|
1158
1156
|
// It doesn't exist
|
|
1159
1157
|
// We can ignore this.
|
|
1160
|
-
if (err) return callback();
|
|
1158
|
+
if (err) return callback(null);
|
|
1161
1159
|
|
|
1162
1160
|
/** @type {InputFileSystem} */
|
|
1163
1161
|
(this.inputFileSystem).readFile(
|
|
1164
|
-
/** @type {string} */
|
|
1162
|
+
/** @type {string} */
|
|
1163
|
+
(this.recordsInputPath),
|
|
1165
1164
|
(err, content) => {
|
|
1166
1165
|
if (err) return callback(err);
|
|
1167
1166
|
|
|
@@ -1177,7 +1176,7 @@ ${other}`);
|
|
|
1177
1176
|
);
|
|
1178
1177
|
}
|
|
1179
1178
|
|
|
1180
|
-
return callback();
|
|
1179
|
+
return callback(null);
|
|
1181
1180
|
}
|
|
1182
1181
|
);
|
|
1183
1182
|
});
|
|
@@ -1188,7 +1187,7 @@ ${other}`);
|
|
|
1188
1187
|
* @param {string} compilerName the compiler's name
|
|
1189
1188
|
* @param {number} compilerIndex the compiler's index
|
|
1190
1189
|
* @param {Partial<OutputOptions>=} outputOptions the output options
|
|
1191
|
-
* @param {
|
|
1190
|
+
* @param {Plugins=} plugins the plugins to apply
|
|
1192
1191
|
* @returns {Compiler} a child compiler
|
|
1193
1192
|
*/
|
|
1194
1193
|
createChildCompiler(
|
|
@@ -1239,7 +1238,10 @@ ${other}`);
|
|
|
1239
1238
|
childCompiler.root = this.root;
|
|
1240
1239
|
if (Array.isArray(plugins)) {
|
|
1241
1240
|
for (const plugin of plugins) {
|
|
1242
|
-
if (plugin) {
|
|
1241
|
+
if (typeof plugin === "function") {
|
|
1242
|
+
/** @type {WebpackPluginFunction} */
|
|
1243
|
+
(plugin).call(childCompiler, childCompiler);
|
|
1244
|
+
} else if (plugin) {
|
|
1243
1245
|
plugin.apply(childCompiler);
|
|
1244
1246
|
}
|
|
1245
1247
|
}
|
|
@@ -1311,8 +1313,7 @@ ${other}`);
|
|
|
1311
1313
|
fs: /** @type {InputFileSystem} */ (this.inputFileSystem),
|
|
1312
1314
|
resolverFactory: this.resolverFactory,
|
|
1313
1315
|
options: this.options.module,
|
|
1314
|
-
associatedObjectForCache: this.root
|
|
1315
|
-
layers: this.options.experiments.layers
|
|
1316
|
+
associatedObjectForCache: this.root
|
|
1316
1317
|
});
|
|
1317
1318
|
this._lastNormalModuleFactory = normalModuleFactory;
|
|
1318
1319
|
this.hooks.normalModuleFactory.call(normalModuleFactory);
|
|
@@ -1334,7 +1335,7 @@ ${other}`);
|
|
|
1334
1335
|
}
|
|
1335
1336
|
|
|
1336
1337
|
/**
|
|
1337
|
-
* @param {
|
|
1338
|
+
* @param {Callback<Compilation>} callback signals when the compilation finishes
|
|
1338
1339
|
* @returns {void}
|
|
1339
1340
|
*/
|
|
1340
1341
|
compile(callback) {
|
|
@@ -1385,7 +1386,7 @@ ${other}`);
|
|
|
1385
1386
|
}
|
|
1386
1387
|
|
|
1387
1388
|
/**
|
|
1388
|
-
* @param {
|
|
1389
|
+
* @param {ErrorCallback} callback signals when the compiler closes
|
|
1389
1390
|
* @returns {void}
|
|
1390
1391
|
*/
|
|
1391
1392
|
close(callback) {
|
|
@@ -10,16 +10,18 @@ const {
|
|
|
10
10
|
NAMESPACE_OBJECT_EXPORT
|
|
11
11
|
} = require("./util/concatenate");
|
|
12
12
|
|
|
13
|
+
/** @typedef {import("./Chunk")} Chunk */
|
|
13
14
|
/** @typedef {import("./Module")} Module */
|
|
14
15
|
/** @typedef {import("./optimize/ConcatenatedModule").ConcatenatedModuleInfo} ConcatenatedModuleInfo */
|
|
15
16
|
/** @typedef {import("./optimize/ConcatenatedModule").ModuleInfo} ModuleInfo */
|
|
17
|
+
/** @typedef {import("./optimize/ConcatenatedModule").ExportName} Ids */
|
|
16
18
|
|
|
17
19
|
const MODULE_REFERENCE_REGEXP =
|
|
18
20
|
/^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(_deferredImport)?(?:_asiSafe(\d))?__$/;
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* @typedef {object} ModuleReferenceOptions
|
|
22
|
-
* @property {
|
|
24
|
+
* @property {Ids} ids the properties/exports of the module
|
|
23
25
|
* @property {boolean} call true, when this referenced export is called
|
|
24
26
|
* @property {boolean} directImport true, when this referenced export is directly imported (not via property access)
|
|
25
27
|
* @property {boolean} deferredImport true, when this referenced export is deferred
|
|
@@ -187,4 +189,7 @@ class ConcatenationScope {
|
|
|
187
189
|
ConcatenationScope.DEFAULT_EXPORT = DEFAULT_EXPORT;
|
|
188
190
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT = NAMESPACE_OBJECT_EXPORT;
|
|
189
191
|
|
|
192
|
+
/** @type {WeakMap<Chunk, Set<string>>} */
|
|
193
|
+
ConcatenationScope.chunkUsedNames = new WeakMap();
|
|
194
|
+
|
|
190
195
|
module.exports = ConcatenationScope;
|
|
@@ -78,7 +78,7 @@ class ConditionalInitFragment extends InitFragment {
|
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* @param {GenerateContext} context context
|
|
81
|
-
* @returns {string | Source
|
|
81
|
+
* @returns {string | Source | undefined} the source code that will be included at the end of the module
|
|
82
82
|
*/
|
|
83
83
|
getEndContent(context) {
|
|
84
84
|
if (this.runtimeCondition === false || !this.endContent) return "";
|
package/lib/ConstPlugin.js
CHANGED
|
@@ -24,12 +24,13 @@ const { parseResource } = require("./util/identifier");
|
|
|
24
24
|
/** @typedef {import("estree").Super} Super */
|
|
25
25
|
/** @typedef {import("estree").VariableDeclaration} VariableDeclaration */
|
|
26
26
|
/** @typedef {import("./Compiler")} Compiler */
|
|
27
|
-
/** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
|
28
27
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
|
29
28
|
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
|
30
29
|
|
|
30
|
+
/** @typedef {Set<string>} Declarations */
|
|
31
|
+
|
|
31
32
|
/**
|
|
32
|
-
* @param {
|
|
33
|
+
* @param {Declarations} declarations set of declarations
|
|
33
34
|
* @param {Identifier | Pattern} pattern pattern to collect declarations from
|
|
34
35
|
*/
|
|
35
36
|
const collectDeclaration = (declarations, pattern) => {
|
|
@@ -65,12 +66,12 @@ const collectDeclaration = (declarations, pattern) => {
|
|
|
65
66
|
/**
|
|
66
67
|
* @param {Statement} branch branch to get hoisted declarations from
|
|
67
68
|
* @param {boolean} includeFunctionDeclarations whether to include function declarations
|
|
68
|
-
* @returns {
|
|
69
|
+
* @returns {string[]} hoisted declarations
|
|
69
70
|
*/
|
|
70
71
|
const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
|
71
|
-
/** @type {
|
|
72
|
+
/** @type {Declarations} */
|
|
72
73
|
const declarations = new Set();
|
|
73
|
-
/** @type {
|
|
74
|
+
/** @type {(Statement | null | undefined)[]} */
|
|
74
75
|
const stack = [branch];
|
|
75
76
|
while (stack.length > 0) {
|
|
76
77
|
const node = stack.pop();
|
package/lib/ContextModule.js
CHANGED
|
@@ -30,25 +30,27 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
30
30
|
|
|
31
31
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
32
32
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
|
33
|
-
/** @typedef {import("
|
|
33
|
+
/** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
34
34
|
/** @typedef {import("./Chunk")} Chunk */
|
|
35
35
|
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
|
36
|
+
/** @typedef {import("./Chunk").ChunkName} ChunkName */
|
|
36
37
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
|
37
38
|
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
|
38
39
|
/** @typedef {import("./ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
|
39
40
|
/** @typedef {import("./Compilation")} Compilation */
|
|
40
41
|
/** @typedef {import("./Dependency")} Dependency */
|
|
41
|
-
/** @typedef {import("./
|
|
42
|
+
/** @typedef {import("./Dependency").RawReferencedExports} RawReferencedExports */
|
|
42
43
|
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
|
43
44
|
/** @typedef {import("./Module").BuildCallback} BuildCallback */
|
|
44
45
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
|
46
|
+
/** @typedef {import("./Module").FileSystemDependencies} FileSystemDependencies */
|
|
45
47
|
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
|
46
48
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
|
47
49
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
|
48
50
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
|
51
|
+
/** @typedef {import("./Module").LibIdent} LibIdent */
|
|
49
52
|
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
|
|
50
53
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
|
51
|
-
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
|
52
54
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
|
53
55
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
54
56
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
|
@@ -56,7 +58,6 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
56
58
|
/** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|
57
59
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
58
60
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
59
|
-
/** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
|
|
60
61
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
61
62
|
|
|
62
63
|
/** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
|
|
@@ -65,17 +66,17 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
65
66
|
* @typedef {object} ContextOptions
|
|
66
67
|
* @property {ContextMode} mode
|
|
67
68
|
* @property {boolean} recursive
|
|
68
|
-
* @property {RegExp} regExp
|
|
69
|
-
* @property {
|
|
69
|
+
* @property {RegExp | false | null} regExp
|
|
70
|
+
* @property {"strict" | boolean=} namespaceObject
|
|
70
71
|
* @property {string=} addon
|
|
71
|
-
* @property {
|
|
72
|
-
* @property {
|
|
73
|
-
* @property {
|
|
72
|
+
* @property {ChunkName=} chunkName
|
|
73
|
+
* @property {RegExp | null=} include
|
|
74
|
+
* @property {RegExp | null=} exclude
|
|
74
75
|
* @property {RawChunkGroupOptions=} groupOptions
|
|
75
76
|
* @property {string=} typePrefix
|
|
76
77
|
* @property {string=} category
|
|
77
|
-
* @property {
|
|
78
|
-
* @property {string=} layer
|
|
78
|
+
* @property {RawReferencedExports | null=} referencedExports exports referenced from modules (won't be mangled)
|
|
79
|
+
* @property {string | null=} layer
|
|
79
80
|
* @property {ImportAttributes=} attributes
|
|
80
81
|
*/
|
|
81
82
|
|
|
@@ -93,6 +94,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
93
94
|
* @callback ResolveDependenciesCallback
|
|
94
95
|
* @param {Error | null} err
|
|
95
96
|
* @param {ContextElementDependency[]=} dependencies
|
|
97
|
+
* @returns {void}
|
|
96
98
|
*/
|
|
97
99
|
|
|
98
100
|
/**
|
|
@@ -106,8 +108,6 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
106
108
|
|
|
107
109
|
/** @typedef {Record<ModuleId, FakeMapType>} FakeMap */
|
|
108
110
|
|
|
109
|
-
const SNAPSHOT_OPTIONS = { timestamp: true };
|
|
110
|
-
|
|
111
111
|
class ContextModule extends Module {
|
|
112
112
|
/**
|
|
113
113
|
* @param {ResolveDependencies} resolveDependencies function to get dependencies in this context
|
|
@@ -254,10 +254,12 @@ class ContextModule extends Module {
|
|
|
254
254
|
} else if (this.options.namespaceObject) {
|
|
255
255
|
identifier += "|namespace object";
|
|
256
256
|
}
|
|
257
|
+
if (this.options.attributes) {
|
|
258
|
+
identifier += `|importAttributes: ${JSON.stringify(this.options.attributes)}`;
|
|
259
|
+
}
|
|
257
260
|
if (this.layer) {
|
|
258
261
|
identifier += `|layer: ${this.layer}`;
|
|
259
262
|
}
|
|
260
|
-
|
|
261
263
|
return identifier;
|
|
262
264
|
}
|
|
263
265
|
|
|
@@ -334,7 +336,7 @@ class ContextModule extends Module {
|
|
|
334
336
|
|
|
335
337
|
/**
|
|
336
338
|
* @param {LibIdentOptions} options options
|
|
337
|
-
* @returns {
|
|
339
|
+
* @returns {LibIdent | null} an identifier for library inclusion
|
|
338
340
|
*/
|
|
339
341
|
libIdent(options) {
|
|
340
342
|
let identifier;
|
|
@@ -532,6 +534,8 @@ class ContextModule extends Module {
|
|
|
532
534
|
}
|
|
533
535
|
if (!this.context && !this.options.resource) return callback();
|
|
534
536
|
|
|
537
|
+
const snapshotOptions = compilation.options.snapshot.contextModule;
|
|
538
|
+
|
|
535
539
|
compilation.fileSystemInfo.createSnapshot(
|
|
536
540
|
startTime,
|
|
537
541
|
null,
|
|
@@ -541,7 +545,7 @@ class ContextModule extends Module {
|
|
|
541
545
|
? [this.options.resource]
|
|
542
546
|
: /** @type {string[]} */ (this.options.resource),
|
|
543
547
|
null,
|
|
544
|
-
|
|
548
|
+
snapshotOptions,
|
|
545
549
|
(err, snapshot) => {
|
|
546
550
|
if (err) return callback(err);
|
|
547
551
|
/** @type {BuildInfo} */
|
|
@@ -553,10 +557,10 @@ class ContextModule extends Module {
|
|
|
553
557
|
}
|
|
554
558
|
|
|
555
559
|
/**
|
|
556
|
-
* @param {
|
|
557
|
-
* @param {
|
|
558
|
-
* @param {
|
|
559
|
-
* @param {
|
|
560
|
+
* @param {FileSystemDependencies} fileDependencies set where file dependencies are added to
|
|
561
|
+
* @param {FileSystemDependencies} contextDependencies set where context dependencies are added to
|
|
562
|
+
* @param {FileSystemDependencies} missingDependencies set where missing dependencies are added to
|
|
563
|
+
* @param {FileSystemDependencies} buildDependencies set where build dependencies are added to
|
|
560
564
|
*/
|
|
561
565
|
addCacheDependencies(
|
|
562
566
|
fileDependencies,
|
|
@@ -578,7 +582,7 @@ class ContextModule extends Module {
|
|
|
578
582
|
/**
|
|
579
583
|
* @param {Dependency[]} dependencies all dependencies
|
|
580
584
|
* @param {ChunkGraph} chunkGraph chunk graph
|
|
581
|
-
* @returns {Map<string,
|
|
585
|
+
* @returns {Map<string, ModuleId>} map with user requests
|
|
582
586
|
*/
|
|
583
587
|
getUserRequestMap(dependencies, chunkGraph) {
|
|
584
588
|
const moduleGraph = chunkGraph.moduleGraph;
|
|
@@ -17,11 +17,11 @@ const { join } = require("./util/fs");
|
|
|
17
17
|
|
|
18
18
|
/** @typedef {import("./ContextModule").ContextModuleOptions} ContextModuleOptions */
|
|
19
19
|
/** @typedef {import("./ContextModule").ResolveDependenciesCallback} ResolveDependenciesCallback */
|
|
20
|
-
/** @typedef {import("./Module")} Module */
|
|
21
20
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
|
22
21
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
|
|
23
22
|
/** @typedef {import("./ResolverFactory")} ResolverFactory */
|
|
24
23
|
/** @typedef {import("./dependencies/ContextDependency")} ContextDependency */
|
|
24
|
+
/** @typedef {import("./dependencies/ContextDependency").ContextOptions} ContextOptions */
|
|
25
25
|
/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
|
|
26
26
|
/**
|
|
27
27
|
* @template T
|
|
@@ -31,9 +31,23 @@ const { join } = require("./util/fs");
|
|
|
31
31
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
32
32
|
/** @typedef {{ context: string, request: string }} ContextAlternativeRequest */
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {object} ContextResolveData
|
|
36
|
+
* @property {string} context
|
|
37
|
+
* @property {string} request
|
|
38
|
+
* @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions
|
|
39
|
+
* @property {LazySet<string>} fileDependencies
|
|
40
|
+
* @property {LazySet<string>} missingDependencies
|
|
41
|
+
* @property {LazySet<string>} contextDependencies
|
|
42
|
+
* @property {ContextDependency[]} dependencies
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/** @typedef {ContextResolveData & ContextOptions} BeforeContextResolveData */
|
|
46
|
+
/** @typedef {BeforeContextResolveData & { resource: string | string[], resourceQuery: string | undefined, resourceFragment: string | undefined, resolveDependencies: ContextModuleFactory["resolveDependencies"] }} AfterContextResolveData */
|
|
47
|
+
|
|
34
48
|
const EMPTY_RESOLVE_OPTIONS = {};
|
|
35
49
|
|
|
36
|
-
|
|
50
|
+
class ContextModuleFactory extends ModuleFactory {
|
|
37
51
|
/**
|
|
38
52
|
* @param {ResolverFactory} resolverFactory resolverFactory
|
|
39
53
|
*/
|
|
@@ -45,9 +59,9 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
45
59
|
"options"
|
|
46
60
|
]);
|
|
47
61
|
this.hooks = Object.freeze({
|
|
48
|
-
/** @type {AsyncSeriesWaterfallHook<[
|
|
62
|
+
/** @type {AsyncSeriesWaterfallHook<[BeforeContextResolveData], BeforeContextResolveData | false | void>} */
|
|
49
63
|
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
|
|
50
|
-
/** @type {AsyncSeriesWaterfallHook<[
|
|
64
|
+
/** @type {AsyncSeriesWaterfallHook<[AfterContextResolveData], AfterContextResolveData | false | void>} */
|
|
51
65
|
afterResolve: new AsyncSeriesWaterfallHook(["data"]),
|
|
52
66
|
/** @type {SyncWaterfallHook<[string[]]>} */
|
|
53
67
|
contextModuleFiles: new SyncWaterfallHook(["files"]),
|
|
@@ -91,9 +105,9 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
91
105
|
*/
|
|
92
106
|
create(data, callback) {
|
|
93
107
|
const context = data.context;
|
|
94
|
-
const dependencies = data.dependencies;
|
|
108
|
+
const dependencies = /** @type {ContextDependency[]} */ (data.dependencies);
|
|
95
109
|
const resolveOptions = data.resolveOptions;
|
|
96
|
-
const dependency =
|
|
110
|
+
const dependency = dependencies[0];
|
|
97
111
|
const fileDependencies = new LazySet();
|
|
98
112
|
const missingDependencies = new LazySet();
|
|
99
113
|
const contextDependencies = new LazySet();
|
|
@@ -130,7 +144,9 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
130
144
|
const request = beforeResolveResult.request;
|
|
131
145
|
const resolveOptions = beforeResolveResult.resolveOptions;
|
|
132
146
|
|
|
147
|
+
/** @type {undefined | string[]} */
|
|
133
148
|
let loaders;
|
|
149
|
+
/** @type {undefined | string} */
|
|
134
150
|
let resource;
|
|
135
151
|
let loadersPrefix = "";
|
|
136
152
|
const idx = request.lastIndexOf("!");
|
|
@@ -170,7 +186,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
170
186
|
asyncLib.parallel(
|
|
171
187
|
[
|
|
172
188
|
(callback) => {
|
|
173
|
-
const results = /** @type ResolveRequest[] */ ([]);
|
|
189
|
+
const results = /** @type {ResolveRequest[]} */ ([]);
|
|
174
190
|
/**
|
|
175
191
|
* @param {ResolveRequest} obj obj
|
|
176
192
|
* @returns {void}
|
|
@@ -210,7 +226,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
210
226
|
},
|
|
211
227
|
(err, result) => {
|
|
212
228
|
if (err) return callback(err);
|
|
213
|
-
callback(null,
|
|
229
|
+
callback(null, result);
|
|
214
230
|
}
|
|
215
231
|
);
|
|
216
232
|
},
|
|
@@ -241,8 +257,8 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
241
257
|
(loaderResult.length > 0 ? "!" : ""),
|
|
242
258
|
resource:
|
|
243
259
|
contextResult.length > 1
|
|
244
|
-
? contextResult.map((r) => r.path)
|
|
245
|
-
: contextResult[0].path,
|
|
260
|
+
? /** @type {string[]} */ (contextResult.map((r) => r.path))
|
|
261
|
+
: /** @type {string} */ (contextResult[0].path),
|
|
246
262
|
resolveDependencies: this.resolveDependencies.bind(this),
|
|
247
263
|
resourceQuery: contextResult[0].query,
|
|
248
264
|
resourceFragment: contextResult[0].fragment,
|
|
@@ -337,6 +353,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
337
353
|
* @param {string} directory directory
|
|
338
354
|
* @param {(context: string, subResource: string, callback: () => void) => void} addSubDirectory addSubDirectoryFn
|
|
339
355
|
* @param {ResolveDependenciesCallback} callback callback
|
|
356
|
+
* @returns {void}
|
|
340
357
|
*/
|
|
341
358
|
const addDirectory = (ctx, directory, addSubDirectory, callback) => {
|
|
342
359
|
fs.readdir(directory, (err, files) => {
|
|
@@ -478,4 +495,6 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
|
478
495
|
});
|
|
479
496
|
}
|
|
480
497
|
}
|
|
481
|
-
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
module.exports = ContextModuleFactory;
|
|
@@ -10,6 +10,8 @@ const { join } = require("./util/fs");
|
|
|
10
10
|
|
|
11
11
|
/** @typedef {import("./Compiler")} Compiler */
|
|
12
12
|
/** @typedef {import("./ContextModule").ContextModuleOptions} ContextModuleOptions */
|
|
13
|
+
/** @typedef {import("./ContextModuleFactory").BeforeContextResolveData} BeforeContextResolveData */
|
|
14
|
+
/** @typedef {import("./ContextModuleFactory").AfterContextResolveData} AfterContextResolveData */
|
|
13
15
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
14
16
|
|
|
15
17
|
/** @typedef {Record<string, string>} NewContentCreateContextMap */
|
|
@@ -19,7 +21,7 @@ const PLUGIN_NAME = "ContextReplacementPlugin";
|
|
|
19
21
|
class ContextReplacementPlugin {
|
|
20
22
|
/**
|
|
21
23
|
* @param {RegExp} resourceRegExp A regular expression that determines which files will be selected
|
|
22
|
-
* @param {(string | ((context:
|
|
24
|
+
* @param {(string | ((context: BeforeContextResolveData | AfterContextResolveData) => void) | RegExp | boolean)=} newContentResource A new resource to replace the match
|
|
23
25
|
* @param {(boolean | NewContentCreateContextMap | RegExp)=} newContentRecursive If true, all subdirectories are searched for matches
|
|
24
26
|
* @param {RegExp=} newContentRegExp A regular expression that determines which files will be selected
|
|
25
27
|
*/
|
|
@@ -122,7 +124,14 @@ class ContextReplacementPlugin {
|
|
|
122
124
|
});
|
|
123
125
|
cmf.hooks.afterResolve.tap(PLUGIN_NAME, (result) => {
|
|
124
126
|
if (!result) return;
|
|
125
|
-
|
|
127
|
+
const isMatchResourceRegExp = () => {
|
|
128
|
+
if (Array.isArray(result.resource)) {
|
|
129
|
+
return result.resource.some((item) => resourceRegExp.test(item));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return resourceRegExp.test(result.resource);
|
|
133
|
+
};
|
|
134
|
+
if (isMatchResourceRegExp()) {
|
|
126
135
|
if (newContentResource !== undefined) {
|
|
127
136
|
if (
|
|
128
137
|
newContentResource.startsWith("/") ||
|
|
@@ -130,10 +139,15 @@ class ContextReplacementPlugin {
|
|
|
130
139
|
) {
|
|
131
140
|
result.resource = newContentResource;
|
|
132
141
|
} else {
|
|
142
|
+
const rootPath =
|
|
143
|
+
typeof result.resource === "string"
|
|
144
|
+
? result.resource
|
|
145
|
+
: /** @type {string} */
|
|
146
|
+
(result.resource.find((item) => resourceRegExp.test(item)));
|
|
133
147
|
result.resource = join(
|
|
134
148
|
/** @type {InputFileSystem} */
|
|
135
149
|
(compiler.inputFileSystem),
|
|
136
|
-
|
|
150
|
+
rootPath,
|
|
137
151
|
newContentResource
|
|
138
152
|
);
|
|
139
153
|
}
|
|
@@ -153,18 +167,27 @@ class ContextReplacementPlugin {
|
|
|
153
167
|
if (typeof newContentCallback === "function") {
|
|
154
168
|
const origResource = result.resource;
|
|
155
169
|
newContentCallback(result);
|
|
156
|
-
if (
|
|
157
|
-
result.resource
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
if (result.resource !== origResource) {
|
|
171
|
+
const newResource = Array.isArray(result.resource)
|
|
172
|
+
? result.resource
|
|
173
|
+
: [result.resource];
|
|
174
|
+
|
|
175
|
+
for (let i = 0; i < newResource.length; i++) {
|
|
176
|
+
if (
|
|
177
|
+
!newResource[i].startsWith("/") &&
|
|
178
|
+
(newResource[i].length <= 1 || newResource[i][1] !== ":")
|
|
179
|
+
) {
|
|
180
|
+
// When the function changed it to an relative path
|
|
181
|
+
newResource[i] = join(
|
|
182
|
+
/** @type {InputFileSystem} */
|
|
183
|
+
(compiler.inputFileSystem),
|
|
184
|
+
origResource[i],
|
|
185
|
+
newResource[i]
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
result.resource = newResource;
|
|
168
191
|
}
|
|
169
192
|
} else {
|
|
170
193
|
for (const d of result.dependencies) {
|