webpack 5.104.1 → 5.105.4
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 +2 -2
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +17 -2
- package/lib/AsyncDependencyToInitialChunkError.js +3 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +5 -1
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +9 -5
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +9 -2
- package/lib/CleanPlugin.js +5 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +294 -244
- package/lib/Compiler.js +4 -3
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +255 -112
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +15 -8
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +7 -2
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +8 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +2 -0
- package/lib/EvalDevToolModulePlugin.js +3 -0
- package/lib/EvalSourceMapDevToolPlugin.js +25 -14
- package/lib/ExportsInfo.js +8 -34
- package/lib/ExternalModule.js +18 -2
- package/lib/ExternalModuleFactoryPlugin.js +9 -2
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/IgnoreWarningsPlugin.js +5 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +8 -1
- package/lib/Module.js +51 -8
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +4 -1
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -10
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiStats.js +5 -5
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +28 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +28 -1
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +40 -25
- package/lib/Stats.js +3 -2
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +3 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +74 -44
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +18 -3
- package/lib/asset/AssetModulesPlugin.js +48 -2
- package/lib/asset/AssetParser.js +4 -0
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +9 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryDependency.js +3 -0
- package/lib/container/ContainerEntryModule.js +7 -0
- package/lib/container/ContainerExposedDependency.js +1 -0
- package/lib/container/FallbackDependency.js +1 -0
- package/lib/container/FallbackItemDependency.js +1 -0
- package/lib/container/FallbackModule.js +4 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/ModuleFederationPlugin.js +1 -1
- package/lib/container/RemoteModule.js +42 -1
- package/lib/css/CssGenerator.js +38 -4
- package/lib/css/CssModulesPlugin.js +33 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +5 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +315 -506
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +7 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -8
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependency.js +31 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -49
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +4 -0
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +8 -23
- package/lib/dependencies/ImportPhase.js +4 -0
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +3 -8
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/NamedChunkIdsPlugin.js +7 -5
- package/lib/ids/NamedModuleIdsPlugin.js +1 -0
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
- package/lib/ids/SyncModuleIdsPlugin.js +30 -20
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +104 -30
- package/lib/javascript/JavascriptParser.js +48 -15
- package/lib/json/JsonGenerator.js +1 -0
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/Logger.js +9 -5
- package/lib/logging/createConsoleLogger.js +4 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
- package/lib/node/NodeEnvironmentPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +10 -1
- package/lib/node/NodeTemplatePlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +6 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
- package/lib/optimize/ConcatenatedModule.js +36 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/LimitChunkCountPlugin.js +3 -2
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +23 -5
- package/lib/optimize/RealContentHashPlugin.js +37 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/RuntimeChunkPlugin.js +3 -5
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +23 -5
- package/lib/performance/AssetsOverSizeLimitWarning.js +7 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +7 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/performance/SizeLimitsPlugin.js +7 -6
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +6 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +14 -6
- package/lib/schemes/HttpUriPlugin.js +39 -20
- package/lib/schemes/VirtualUrlPlugin.js +28 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +78 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +5 -3
- package/lib/util/AppendOnlyStackedSet.js +78 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/findGraphRoots.js +79 -109
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +4 -0
- package/lib/util/hash/BulkUpdateHash.js +8 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +18 -2
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +16 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
- package/package.json +40 -40
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +121 -55
- package/schemas/plugins/BannerPlugin.json +2 -2
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ManifestPlugin.json +3 -3
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +677 -230
|
@@ -17,7 +17,9 @@ class ChunkPrefetchFunctionRuntimeModule extends RuntimeModule {
|
|
|
17
17
|
*/
|
|
18
18
|
constructor(type, runtimeFunction, runtimeHandlers) {
|
|
19
19
|
super(`chunk ${type} function`);
|
|
20
|
+
/** @type {string} */
|
|
20
21
|
this.runtimeFunction = runtimeFunction;
|
|
22
|
+
/** @type {string} */
|
|
21
23
|
this.runtimeHandlers = runtimeHandlers;
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -9,14 +9,16 @@ const RuntimeModule = require("../RuntimeModule");
|
|
|
9
9
|
const Template = require("../Template");
|
|
10
10
|
|
|
11
11
|
/** @typedef {import("../Chunk")} Chunk */
|
|
12
|
+
/** @typedef {import("../Chunk").ChunkChildOfTypeInOrder} ChunkChildOfTypeInOrder */
|
|
12
13
|
/** @typedef {import("../Compilation")} Compilation */
|
|
13
14
|
|
|
14
15
|
class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
|
|
15
16
|
/**
|
|
16
|
-
* @param {
|
|
17
|
+
* @param {ChunkChildOfTypeInOrder[]} startupChunks chunk ids to trigger when chunks are loaded
|
|
17
18
|
*/
|
|
18
19
|
constructor(startupChunks) {
|
|
19
20
|
super("startup prefetch", RuntimeModule.STAGE_TRIGGER);
|
|
21
|
+
/** @type {ChunkChildOfTypeInOrder[]} */
|
|
20
22
|
this.startupChunks = startupChunks;
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -24,7 +24,9 @@ class BasicEffectRulePlugin {
|
|
|
24
24
|
* @param {string=} effectType the effect type
|
|
25
25
|
*/
|
|
26
26
|
constructor(ruleProperty, effectType) {
|
|
27
|
+
/** @type {BasicEffectRuleKeys} */
|
|
27
28
|
this.ruleProperty = ruleProperty;
|
|
29
|
+
/** @type {string | BasicEffectRuleKeys} */
|
|
28
30
|
this.effectType = effectType || ruleProperty;
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -27,8 +27,11 @@ class BasicMatcherRulePlugin {
|
|
|
27
27
|
* @param {boolean=} invert if true, inverts the condition
|
|
28
28
|
*/
|
|
29
29
|
constructor(ruleProperty, dataProperty, invert) {
|
|
30
|
+
/** @type {BasicMatcherRuleKeys} */
|
|
30
31
|
this.ruleProperty = ruleProperty;
|
|
32
|
+
/** @type {string | BasicMatcherRuleKeys} */
|
|
31
33
|
this.dataProperty = dataProperty || ruleProperty;
|
|
34
|
+
/** @type {boolean} */
|
|
32
35
|
this.invert = invert || false;
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -18,18 +18,22 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
/** @typedef {KeysOfTypes<RuleSetRule, { [k: string]: RuleSetConditionOrConditions }>} ObjectMatcherRuleKeys */
|
|
21
|
+
/** @typedef {keyof EffectData} DataProperty */
|
|
21
22
|
|
|
22
23
|
const PLUGIN_NAME = "ObjectMatcherRulePlugin";
|
|
23
24
|
|
|
24
25
|
class ObjectMatcherRulePlugin {
|
|
25
26
|
/**
|
|
26
27
|
* @param {ObjectMatcherRuleKeys} ruleProperty the rule property
|
|
27
|
-
* @param {
|
|
28
|
+
* @param {DataProperty=} dataProperty the data property
|
|
28
29
|
* @param {RuleConditionFunction=} additionalConditionFunction need to check
|
|
29
30
|
*/
|
|
30
31
|
constructor(ruleProperty, dataProperty, additionalConditionFunction) {
|
|
32
|
+
/** @type {ObjectMatcherRuleKeys} */
|
|
31
33
|
this.ruleProperty = ruleProperty;
|
|
34
|
+
/** @type {DataProperty | ObjectMatcherRuleKeys} */
|
|
32
35
|
this.dataProperty = dataProperty || ruleProperty;
|
|
36
|
+
/** @type {RuleConditionFunction | undefined} */
|
|
33
37
|
this.additionalConditionFunction = additionalConditionFunction;
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -9,6 +9,7 @@ const { SyncHook } = require("tapable");
|
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
|
|
11
11
|
/** @typedef {import("../../declarations/WebpackOptions").Falsy} Falsy */
|
|
12
|
+
/** @typedef {import("../../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
|
|
12
13
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */
|
|
13
14
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
|
14
15
|
|
|
@@ -87,6 +88,9 @@ const { SyncHook } = require("tapable");
|
|
|
87
88
|
|
|
88
89
|
/** @typedef {Set<string>} UnhandledProperties */
|
|
89
90
|
|
|
91
|
+
/** @typedef {(data: EffectData) => (RuleSetUseItem | (Falsy | RuleSetUseItem)[])} RuleSetUseFn */
|
|
92
|
+
/** @typedef {(value: string) => boolean} RuleSetConditionFn */
|
|
93
|
+
|
|
90
94
|
/** @typedef {{ apply: (ruleSetCompiler: RuleSetCompiler) => void }} RuleSetPlugin */
|
|
91
95
|
|
|
92
96
|
class RuleSetCompiler {
|
|
@@ -116,6 +120,7 @@ class RuleSetCompiler {
|
|
|
116
120
|
* @returns {RuleSet} compiled RuleSet
|
|
117
121
|
*/
|
|
118
122
|
compile(ruleSet) {
|
|
123
|
+
/** @type {References} */
|
|
119
124
|
const refs = new Map();
|
|
120
125
|
const rules = this.compileRules("ruleSet", ruleSet, refs);
|
|
121
126
|
|
|
@@ -327,6 +332,7 @@ class RuleSetCompiler {
|
|
|
327
332
|
);
|
|
328
333
|
}
|
|
329
334
|
|
|
335
|
+
/** @type {Condition[]} */
|
|
330
336
|
const conditions = [];
|
|
331
337
|
for (const key of Object.keys(condition)) {
|
|
332
338
|
const value = condition[key];
|
|
@@ -26,10 +26,15 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
|
26
26
|
*/
|
|
27
27
|
constructor(contentType, name, global, getFilenameForChunk, allChunks) {
|
|
28
28
|
super(`get ${name} chunk filename`);
|
|
29
|
+
/** @type {string} */
|
|
29
30
|
this.contentType = contentType;
|
|
31
|
+
/** @type {string} */
|
|
30
32
|
this.global = global;
|
|
33
|
+
/** @type {(chunk: Chunk) => TemplatePath | false} */
|
|
31
34
|
this.getFilenameForChunk = getFilenameForChunk;
|
|
35
|
+
/** @type {boolean} */
|
|
32
36
|
this.allChunks = allChunks;
|
|
37
|
+
/** @type {boolean} */
|
|
33
38
|
this.dependentHash = true;
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -47,7 +47,9 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
|
47
47
|
*/
|
|
48
48
|
constructor(withCreateScriptUrl, withFetchPriority) {
|
|
49
49
|
super("load script");
|
|
50
|
+
/** @type {boolean | undefined} */
|
|
50
51
|
this._withCreateScriptUrl = withCreateScriptUrl;
|
|
52
|
+
/** @type {boolean | undefined} */
|
|
51
53
|
this._withFetchPriority = withFetchPriority;
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -17,11 +17,12 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
|
17
17
|
* @returns {string} mode
|
|
18
18
|
*/
|
|
19
19
|
function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
|
|
20
|
-
|
|
21
|
-
if (exportsType === "
|
|
20
|
+
// number is from createFakeNamespaceObject mode ^ 1
|
|
21
|
+
if (exportsType === "namespace") return `/* ${exportsType} */ 8`;
|
|
22
|
+
if (exportsType === "default-only") return `/* ${exportsType} */ 0`;
|
|
22
23
|
if (exportsType === "default-with-named") return `/* ${exportsType} */ 2`;
|
|
23
|
-
if (exportsType === "dynamic") return `/* ${exportsType} */
|
|
24
|
-
|
|
24
|
+
if (exportsType === "dynamic") return `/* ${exportsType} */ 6`;
|
|
25
|
+
throw new Error(`Unknown exports type: ${exportsType}`);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -52,6 +53,7 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
|
|
|
52
53
|
*/
|
|
53
54
|
constructor(hasAsyncRuntime) {
|
|
54
55
|
super("make optimized deferred namespace object");
|
|
56
|
+
/** @type {boolean} */
|
|
55
57
|
this.hasAsyncRuntime = hasAsyncRuntime;
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -66,10 +68,6 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
|
|
|
66
68
|
// Note: must be a function (not arrow), because this is used in body!
|
|
67
69
|
`${fn} = function(moduleId, mode${hasAsync ? ", asyncDeps" : ""}) {`,
|
|
68
70
|
Template.indent([
|
|
69
|
-
"// mode: 0 => namespace (esm)",
|
|
70
|
-
"// mode: 1 => default-only (esm strict cjs)",
|
|
71
|
-
"// mode: 2 => default-with-named (esm-cjs compat)",
|
|
72
|
-
"// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
|
|
73
71
|
"var r = this;",
|
|
74
72
|
hasAsync ? "var isAsync = asyncDeps && asyncDeps.length;" : "",
|
|
75
73
|
"var obj = {",
|
|
@@ -83,7 +81,7 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
|
|
|
83
81
|
// if exportsType is "namespace" we can generate the most optimized code,
|
|
84
82
|
// on the second access, we can avoid trigger the getter.
|
|
85
83
|
// we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
|
|
86
|
-
'if(mode
|
|
84
|
+
'if(mode & 8 || (mode & 4 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
|
|
87
85
|
"return exports;"
|
|
88
86
|
]),
|
|
89
87
|
"}"
|
|
@@ -105,6 +103,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
105
103
|
*/
|
|
106
104
|
constructor(hasAsyncRuntime) {
|
|
107
105
|
super("make deferred namespace object");
|
|
106
|
+
/** @type {boolean} */
|
|
108
107
|
this.hasAsyncRuntime = hasAsyncRuntime;
|
|
109
108
|
}
|
|
110
109
|
|
|
@@ -120,11 +119,6 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
120
119
|
? "init?.();"
|
|
121
120
|
: "if (init) init();";
|
|
122
121
|
return `${fn} = ${runtimeTemplate.basicFunction("moduleId, mode", [
|
|
123
|
-
"// mode: 0 => namespace (esm)",
|
|
124
|
-
"// mode: 1 => default-only (esm strict cjs)",
|
|
125
|
-
"// mode: 2 => default-with-named (esm-cjs compat)",
|
|
126
|
-
"// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
|
|
127
|
-
"",
|
|
128
122
|
"var cachedModule = __webpack_module_cache__[moduleId];",
|
|
129
123
|
"if (cachedModule && cachedModule.error === undefined) {",
|
|
130
124
|
Template.indent([
|
|
@@ -132,10 +126,8 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
132
126
|
hasAsync
|
|
133
127
|
? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
|
|
134
128
|
: "",
|
|
135
|
-
"if (mode
|
|
136
|
-
`
|
|
137
|
-
`if (mode == 2) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 2);`,
|
|
138
|
-
`if (mode == 3) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 6);` // 2 | 4
|
|
129
|
+
"if (mode & 8) return exports;",
|
|
130
|
+
`return ${RuntimeGlobals.createFakeNamespaceObject}(exports, mode);`
|
|
139
131
|
]),
|
|
140
132
|
"}",
|
|
141
133
|
"",
|
|
@@ -145,7 +137,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
145
137
|
? `if (${RuntimeGlobals.asyncModuleExportSymbol} in ns) ns = ns[${RuntimeGlobals.asyncModuleExportSymbol}];`
|
|
146
138
|
: "",
|
|
147
139
|
"init = null;",
|
|
148
|
-
"if (mode
|
|
140
|
+
"if (mode & 8 || mode & 4 && ns.__esModule && typeof ns === 'object') {",
|
|
149
141
|
Template.indent([
|
|
150
142
|
"delete handler.defineProperty;",
|
|
151
143
|
"delete handler.deleteProperty;",
|
|
@@ -155,17 +147,9 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
155
147
|
"delete handler.ownKeys;",
|
|
156
148
|
"delete handler.getOwnPropertyDescriptor;"
|
|
157
149
|
]),
|
|
158
|
-
"} else
|
|
159
|
-
Template.indent([
|
|
160
|
-
`ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns);`
|
|
161
|
-
]),
|
|
162
|
-
"} else if (mode == 2) {",
|
|
163
|
-
Template.indent([
|
|
164
|
-
`ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, 2);`
|
|
165
|
-
]),
|
|
166
|
-
"} else if (mode == 3) {",
|
|
150
|
+
"} else {",
|
|
167
151
|
Template.indent([
|
|
168
|
-
`ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns,
|
|
152
|
+
`ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, mode);`
|
|
169
153
|
]),
|
|
170
154
|
"}"
|
|
171
155
|
])};`,
|
|
@@ -211,14 +195,14 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
|
211
195
|
`getOwnPropertyDescriptor: ${runtimeTemplate.basicFunction("_, name", [
|
|
212
196
|
"switch (name) {",
|
|
213
197
|
Template.indent([
|
|
214
|
-
'case "__esModule": return { value: true, configurable:
|
|
215
|
-
'case Symbol.toStringTag: return { value: "Deferred Module", configurable:
|
|
198
|
+
'case "__esModule": return { value: true, configurable: !(mode & 8) };',
|
|
199
|
+
'case Symbol.toStringTag: return { value: "Deferred Module", configurable: !(mode & 8) };',
|
|
216
200
|
'case "then": return undefined;'
|
|
217
201
|
]),
|
|
218
202
|
"}",
|
|
219
203
|
init,
|
|
220
204
|
"var desc = Reflect.getOwnPropertyDescriptor(ns, name);",
|
|
221
|
-
'if (mode
|
|
205
|
+
'if (mode & 2 && name == "default" && !desc) {',
|
|
222
206
|
Template.indent("desc = { value: ns, configurable: true };"),
|
|
223
207
|
"}",
|
|
224
208
|
"return desc;"
|
|
@@ -25,7 +25,9 @@ class StartupChunkDependenciesPlugin {
|
|
|
25
25
|
* @param {Options} options options
|
|
26
26
|
*/
|
|
27
27
|
constructor(options) {
|
|
28
|
+
/** @type {ChunkLoadingType} */
|
|
28
29
|
this.chunkLoading = options.chunkLoading;
|
|
30
|
+
/** @type {boolean} */
|
|
29
31
|
this.asyncChunkLoading =
|
|
30
32
|
typeof options.asyncChunkLoading === "boolean"
|
|
31
33
|
? options.asyncChunkLoading
|
|
@@ -29,30 +29,38 @@ class ToBinaryRuntimeModule extends RuntimeModule {
|
|
|
29
29
|
const isNodePlatform = compilation.compiler.platform.node;
|
|
30
30
|
const isWebPlatform = compilation.compiler.platform.web;
|
|
31
31
|
const isNeutralPlatform = runtimeTemplate.isNeutralPlatform();
|
|
32
|
+
const toImmutableBytes = runtimeTemplate.basicFunction("value", [
|
|
33
|
+
runtimeTemplate.destructureObject(["buffer"], "value"),
|
|
34
|
+
`${runtimeTemplate.renderConst()} throwErr = ${runtimeTemplate.basicFunction("", ["throw new TypeError('ArrayBuffer is immutable');"])};`,
|
|
35
|
+
"Object.defineProperties(buffer, { immutable: { value: true }, resize: { value: throwErr }, transfer: { value: throwErr }, transferToFixedLength: { value: throwErr } });",
|
|
36
|
+
"Object.freeze(buffer);",
|
|
37
|
+
"return value;"
|
|
38
|
+
]);
|
|
32
39
|
|
|
33
40
|
return Template.asString([
|
|
34
41
|
"// define to binary helper",
|
|
42
|
+
`${runtimeTemplate.renderConst()} toImmutableBytes = ${toImmutableBytes}`,
|
|
35
43
|
`${fn} = ${isNeutralPlatform ? "typeof Buffer !== 'undefined' ? " : ""}${
|
|
36
44
|
isNodePlatform || isNeutralPlatform
|
|
37
|
-
? `${runtimeTemplate.returningFunction("new Uint8Array(Buffer.from(base64, 'base64'))", "base64")}`
|
|
45
|
+
? `${runtimeTemplate.returningFunction("toImmutableBytes(new Uint8Array(Buffer.from(base64, 'base64')))", "base64")}`
|
|
38
46
|
: ""
|
|
39
47
|
} ${isNeutralPlatform ? ": " : ""}${
|
|
40
48
|
isWebPlatform || isNeutralPlatform
|
|
41
49
|
? `(${runtimeTemplate.basicFunction("", [
|
|
42
|
-
|
|
50
|
+
`${runtimeTemplate.renderConst()} table = new Uint8Array(128);`,
|
|
43
51
|
"for (var i = 0; i < 64; i++) table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;",
|
|
44
52
|
`return ${runtimeTemplate.basicFunction("base64", [
|
|
45
|
-
|
|
53
|
+
`${runtimeTemplate.renderConst()} n = base64.length, bytes = new Uint8Array((n - (base64[n - 1] == '=') - (base64[n - 2] == '=')) * 3 / 4 | 0);`,
|
|
46
54
|
"for (var i = 0, j = 0; i < n;) {",
|
|
47
55
|
Template.indent([
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
`${runtimeTemplate.renderConst()} c0 = table[base64.charCodeAt(i++)], c1 = table[base64.charCodeAt(i++)];`,
|
|
57
|
+
`${runtimeTemplate.renderConst()} c2 = table[base64.charCodeAt(i++)], c3 = table[base64.charCodeAt(i++)];`,
|
|
50
58
|
"bytes[j++] = (c0 << 2) | (c1 >> 4);",
|
|
51
59
|
"bytes[j++] = (c1 << 4) | (c2 >> 2);",
|
|
52
60
|
"bytes[j++] = (c2 << 6) | c3;"
|
|
53
61
|
]),
|
|
54
62
|
"}",
|
|
55
|
-
"return bytes"
|
|
63
|
+
"return toImmutableBytes(bytes)"
|
|
56
64
|
])}`
|
|
57
65
|
])})();`
|
|
58
66
|
: ""
|
|
@@ -36,12 +36,20 @@ const getHttps = memoize(() => require("https"));
|
|
|
36
36
|
|
|
37
37
|
const MAX_REDIRECTS = 5;
|
|
38
38
|
|
|
39
|
+
/** @typedef {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} Fetch */
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {object} EventsMap
|
|
43
|
+
* @property {[Error]} error
|
|
44
|
+
*/
|
|
45
|
+
|
|
39
46
|
/**
|
|
40
47
|
* @param {typeof import("http") | typeof import("https")} request request
|
|
41
48
|
* @param {string | URL | undefined} proxy proxy
|
|
42
|
-
* @returns {
|
|
49
|
+
* @returns {Fetch} fn
|
|
43
50
|
*/
|
|
44
51
|
const proxyFetch = (request, proxy) => (url, options, callback) => {
|
|
52
|
+
/** @type {EventEmitter<EventsMap>} */
|
|
45
53
|
const eventEmitter = new EventEmitter();
|
|
46
54
|
|
|
47
55
|
/**
|
|
@@ -104,9 +112,7 @@ const validate = createSchemaValidation(
|
|
|
104
112
|
* @returns {string} safe path
|
|
105
113
|
*/
|
|
106
114
|
const toSafePath = (str) =>
|
|
107
|
-
str
|
|
108
|
-
.replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, "")
|
|
109
|
-
.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
115
|
+
str.replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi, "").replace(/[^a-z0-9._-]+/gi, "_");
|
|
110
116
|
|
|
111
117
|
/**
|
|
112
118
|
* @param {Buffer} content content
|
|
@@ -220,6 +226,7 @@ const sanitizeUrlForError = (href) => {
|
|
|
220
226
|
|
|
221
227
|
class Lockfile {
|
|
222
228
|
constructor() {
|
|
229
|
+
/** @type {number} */
|
|
223
230
|
this.version = 1;
|
|
224
231
|
/** @type {Map<string, LockfileEntry | "ignore" | "no-cache">} */
|
|
225
232
|
this.entries = new Map();
|
|
@@ -430,6 +437,8 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
|
430
437
|
/** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
|
|
431
438
|
/** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
|
|
432
439
|
|
|
440
|
+
/** @typedef {(uri: string) => boolean} AllowedUriFn */
|
|
441
|
+
|
|
433
442
|
const PLUGIN_NAME = "HttpUriPlugin";
|
|
434
443
|
|
|
435
444
|
class HttpUriPlugin {
|
|
@@ -438,12 +447,8 @@ class HttpUriPlugin {
|
|
|
438
447
|
*/
|
|
439
448
|
constructor(options) {
|
|
440
449
|
validate(options);
|
|
441
|
-
|
|
442
|
-
this.
|
|
443
|
-
this._upgrade = options.upgrade;
|
|
444
|
-
this._frozen = options.frozen;
|
|
445
|
-
this._allowedUris = options.allowedUris;
|
|
446
|
-
this._proxy = options.proxy;
|
|
450
|
+
/** @type {HttpUriPluginOptions} */
|
|
451
|
+
this.options = options;
|
|
447
452
|
}
|
|
448
453
|
|
|
449
454
|
/**
|
|
@@ -453,7 +458,10 @@ class HttpUriPlugin {
|
|
|
453
458
|
*/
|
|
454
459
|
apply(compiler) {
|
|
455
460
|
const proxy =
|
|
456
|
-
this.
|
|
461
|
+
this.options.proxy || process.env.http_proxy || process.env.HTTP_PROXY;
|
|
462
|
+
/**
|
|
463
|
+
* @type {{ scheme: "http" | "https", fetch: Fetch }[]}
|
|
464
|
+
*/
|
|
457
465
|
const schemes = [
|
|
458
466
|
{
|
|
459
467
|
scheme: "http",
|
|
@@ -477,7 +485,7 @@ class HttpUriPlugin {
|
|
|
477
485
|
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
|
|
478
486
|
/** @type {string} */
|
|
479
487
|
const lockfileLocation =
|
|
480
|
-
this.
|
|
488
|
+
this.options.lockfileLocation ||
|
|
481
489
|
join(
|
|
482
490
|
intermediateFs,
|
|
483
491
|
compiler.context,
|
|
@@ -487,15 +495,15 @@ class HttpUriPlugin {
|
|
|
487
495
|
);
|
|
488
496
|
/** @type {string | false} */
|
|
489
497
|
const cacheLocation =
|
|
490
|
-
this.
|
|
491
|
-
? this.
|
|
498
|
+
this.options.cacheLocation !== undefined
|
|
499
|
+
? this.options.cacheLocation
|
|
492
500
|
: `${lockfileLocation}.data`;
|
|
493
|
-
const upgrade = this.
|
|
494
|
-
const frozen = this.
|
|
501
|
+
const upgrade = this.options.upgrade || false;
|
|
502
|
+
const frozen = this.options.frozen || false;
|
|
495
503
|
const hashFunction = "sha512";
|
|
496
504
|
const hashDigest = "hex";
|
|
497
505
|
const hashDigestLength = 20;
|
|
498
|
-
const allowedUris = this.
|
|
506
|
+
const allowedUris = this.options.allowedUris;
|
|
499
507
|
|
|
500
508
|
let warnedAboutEol = false;
|
|
501
509
|
|
|
@@ -660,6 +668,7 @@ class HttpUriPlugin {
|
|
|
660
668
|
* @returns {string} absolute, validated redirect target
|
|
661
669
|
*/
|
|
662
670
|
const validateRedirectLocation = (location, base) => {
|
|
671
|
+
/** @type {URL} */
|
|
663
672
|
let nextUrl;
|
|
664
673
|
try {
|
|
665
674
|
nextUrl = new URL(location, base);
|
|
@@ -707,6 +716,7 @@ class HttpUriPlugin {
|
|
|
707
716
|
|
|
708
717
|
if ("location" in result) {
|
|
709
718
|
// Validate redirect target before following
|
|
719
|
+
/** @type {string} */
|
|
710
720
|
let absolute;
|
|
711
721
|
try {
|
|
712
722
|
absolute = validateRedirectLocation(result.location, url);
|
|
@@ -845,6 +855,7 @@ class HttpUriPlugin {
|
|
|
845
855
|
res.statusCode >= 301 &&
|
|
846
856
|
res.statusCode <= 308
|
|
847
857
|
) {
|
|
858
|
+
/** @type {string} */
|
|
848
859
|
let absolute;
|
|
849
860
|
try {
|
|
850
861
|
absolute = validateRedirectLocation(location, url);
|
|
@@ -891,9 +902,15 @@ class HttpUriPlugin {
|
|
|
891
902
|
stream = stream.pipe(createInflate());
|
|
892
903
|
}
|
|
893
904
|
|
|
894
|
-
stream.on(
|
|
895
|
-
|
|
896
|
-
|
|
905
|
+
stream.on(
|
|
906
|
+
"data",
|
|
907
|
+
/**
|
|
908
|
+
* @param {Buffer} chunk chunk
|
|
909
|
+
*/
|
|
910
|
+
(chunk) => {
|
|
911
|
+
bufferArr.push(chunk);
|
|
912
|
+
}
|
|
913
|
+
);
|
|
897
914
|
|
|
898
915
|
stream.on("end", () => {
|
|
899
916
|
if (!res.complete) {
|
|
@@ -953,6 +970,7 @@ class HttpUriPlugin {
|
|
|
953
970
|
* @returns {boolean} true when allowed, otherwise false
|
|
954
971
|
*/
|
|
955
972
|
const isAllowed = (uri) => {
|
|
973
|
+
/** @type {URL} */
|
|
956
974
|
let parsedUri;
|
|
957
975
|
try {
|
|
958
976
|
// Parse the URI to prevent userinfo bypass attacks
|
|
@@ -963,6 +981,7 @@ class HttpUriPlugin {
|
|
|
963
981
|
}
|
|
964
982
|
for (const allowed of allowedUris) {
|
|
965
983
|
if (typeof allowed === "string") {
|
|
984
|
+
/** @type {URL} */
|
|
966
985
|
let parsedAllowed;
|
|
967
986
|
try {
|
|
968
987
|
parsedAllowed = new URL(allowed);
|
|
@@ -58,17 +58,19 @@ function normalizeModule(virtualConfig) {
|
|
|
58
58
|
return virtualConfig;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/** @typedef {{ [key: string]: VirtualModuleConfig }} NormalizedModules */
|
|
62
|
+
|
|
61
63
|
/**
|
|
62
64
|
* Normalizes all virtual modules with the given scheme
|
|
63
65
|
* @param {VirtualModules} virtualConfigs The virtual modules to normalize
|
|
64
66
|
* @param {string} scheme The URL scheme to use
|
|
65
|
-
* @returns {
|
|
67
|
+
* @returns {NormalizedModules} The normalized virtual modules
|
|
66
68
|
*/
|
|
67
69
|
function normalizeModules(virtualConfigs, scheme) {
|
|
68
70
|
return Object.keys(virtualConfigs).reduce((pre, id) => {
|
|
69
71
|
pre[toVid(id, scheme)] = normalizeModule(virtualConfigs[id]);
|
|
70
72
|
return pre;
|
|
71
|
-
}, /** @type {
|
|
73
|
+
}, /** @type {NormalizedModules} */ ({}));
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
/**
|
|
@@ -105,7 +107,9 @@ class VirtualUrlPlugin {
|
|
|
105
107
|
* @param {string=} scheme The URL scheme to use
|
|
106
108
|
*/
|
|
107
109
|
constructor(modules, scheme) {
|
|
110
|
+
/** @type {string} */
|
|
108
111
|
this.scheme = scheme || DEFAULT_SCHEME;
|
|
112
|
+
/** @type {NormalizedModules} */
|
|
109
113
|
this.modules = normalizeModules(modules, this.scheme);
|
|
110
114
|
}
|
|
111
115
|
|
|
@@ -122,6 +126,27 @@ class VirtualUrlPlugin {
|
|
|
122
126
|
compiler.hooks.compilation.tap(
|
|
123
127
|
PLUGIN_NAME,
|
|
124
128
|
(compilation, { normalModuleFactory }) => {
|
|
129
|
+
compilation.hooks.assetPath.tap(
|
|
130
|
+
{ name: PLUGIN_NAME, before: "TemplatedPathPlugin" },
|
|
131
|
+
(path, data) => {
|
|
132
|
+
if (data.filename && this.modules[data.filename]) {
|
|
133
|
+
/**
|
|
134
|
+
* @param {string} str path
|
|
135
|
+
* @returns {string} safe path
|
|
136
|
+
*/
|
|
137
|
+
const toSafePath = (str) =>
|
|
138
|
+
`__${str
|
|
139
|
+
.replace(/:/g, "__")
|
|
140
|
+
.replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi, "")
|
|
141
|
+
.replace(/[^a-z0-9._-]+/gi, "_")}`;
|
|
142
|
+
|
|
143
|
+
// filename: virtual:logo.svg -> __virtual__logo.svg
|
|
144
|
+
data.filename = toSafePath(data.filename);
|
|
145
|
+
}
|
|
146
|
+
return path;
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
|
|
125
150
|
normalModuleFactory.hooks.resolveForScheme
|
|
126
151
|
.for(scheme)
|
|
127
152
|
.tap(PLUGIN_NAME, (resourceData) => {
|
|
@@ -135,6 +160,7 @@ class VirtualUrlPlugin {
|
|
|
135
160
|
const type = virtualConfig.type;
|
|
136
161
|
resourceData.path = path + type;
|
|
137
162
|
resourceData.resource = path;
|
|
163
|
+
resourceData.context = compiler.context;
|
|
138
164
|
|
|
139
165
|
if (virtualConfig.version) {
|
|
140
166
|
const cacheKey = toCacheKey(resourceData.resource, scheme);
|