webpack 5.99.9 → 5.100.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/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -31
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +67 -45
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -2
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +11 -4
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -36
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +31 -44
- package/lib/NormalModuleFactory.js +34 -20
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RawModule.js +14 -0
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +33 -7
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +15 -11
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +4 -4
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependency.js +3 -1
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +117 -76
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +17 -9
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +3 -2
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
- package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
- package/lib/stats/StatsFactory.js +6 -3
- package/lib/stats/StatsPrinter.js +6 -7
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +95 -58
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +119 -113
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1243 -409
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Natsu @xiaoxiaojx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { NormalModule } = require("..");
|
|
9
|
+
const ModuleNotFoundError = require("../ModuleNotFoundError");
|
|
10
|
+
const { parseResourceWithoutFragment } = require("../util/identifier");
|
|
11
|
+
|
|
12
|
+
/** @typedef {import("../Compiler")} Compiler */
|
|
13
|
+
/** @typedef {import("../NormalModule")} NormalModule */
|
|
14
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
15
|
+
/** @typedef {import("../Module").ValueCacheVersions} ValueCacheVersions */
|
|
16
|
+
/** @typedef {string | Set<string>} ValueCacheVersion */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @template T
|
|
20
|
+
* @typedef {import("../../declarations/LoaderContext").LoaderContext<T>} LoaderContext
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const PLUGIN_NAME = "VirtualUrlPlugin";
|
|
24
|
+
const DEFAULT_SCHEME = "virtual";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {object} VirtualModuleConfig
|
|
28
|
+
* @property {string=} type - The module type
|
|
29
|
+
* @property {(loaderContext: LoaderContext<EXPECTED_ANY>) => Promise<string> | string} source - The source function
|
|
30
|
+
* @property {(() => string) | true | string=} version - Optional version function or value
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {string | ((loaderContext: LoaderContext<EXPECTED_ANY>) => Promise<string> | string) | VirtualModuleConfig} VirtualModuleInput
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/** @typedef {{[key: string]: VirtualModuleInput}} VirtualModules */
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Normalizes a virtual module definition into a standard format
|
|
41
|
+
* @param {VirtualModuleInput} virtualConfig The virtual module to normalize
|
|
42
|
+
* @returns {VirtualModuleConfig} The normalized virtual module
|
|
43
|
+
*/
|
|
44
|
+
function normalizeModule(virtualConfig) {
|
|
45
|
+
if (typeof virtualConfig === "string") {
|
|
46
|
+
return {
|
|
47
|
+
type: "",
|
|
48
|
+
source() {
|
|
49
|
+
return virtualConfig;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
} else if (typeof virtualConfig === "function") {
|
|
53
|
+
return {
|
|
54
|
+
type: "",
|
|
55
|
+
source: virtualConfig
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return virtualConfig;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Normalizes all virtual modules with the given scheme
|
|
63
|
+
* @param {VirtualModules} virtualConfigs The virtual modules to normalize
|
|
64
|
+
* @param {string} scheme The URL scheme to use
|
|
65
|
+
* @returns {{[key: string]: VirtualModuleConfig}} The normalized virtual modules
|
|
66
|
+
*/
|
|
67
|
+
function normalizeModules(virtualConfigs, scheme) {
|
|
68
|
+
return Object.keys(virtualConfigs).reduce((pre, id) => {
|
|
69
|
+
pre[toVid(id, scheme)] = normalizeModule(virtualConfigs[id]);
|
|
70
|
+
return pre;
|
|
71
|
+
}, /** @type {{[key: string]: VirtualModuleConfig}} */ ({}));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Converts a module id and scheme to a virtual module id
|
|
76
|
+
* @param {string} id The module id
|
|
77
|
+
* @param {string} scheme The URL scheme
|
|
78
|
+
* @returns {string} The virtual module id
|
|
79
|
+
*/
|
|
80
|
+
function toVid(id, scheme) {
|
|
81
|
+
return `${scheme}:${id}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const VALUE_DEP_VERSION = `webpack/${PLUGIN_NAME}/version`;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Converts a module id and scheme to a cache key
|
|
88
|
+
* @param {string} id The module id
|
|
89
|
+
* @param {string} scheme The URL scheme
|
|
90
|
+
* @returns {string} The cache key
|
|
91
|
+
*/
|
|
92
|
+
function toCacheKey(id, scheme) {
|
|
93
|
+
return `${VALUE_DEP_VERSION}/${toVid(id, scheme)}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @typedef {object} VirtualUrlPluginOptions
|
|
98
|
+
* @property {VirtualModules} modules - The virtual modules
|
|
99
|
+
* @property {string=} scheme - The URL scheme to use
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
class VirtualUrlPlugin {
|
|
103
|
+
/**
|
|
104
|
+
* @param {VirtualModules} modules The virtual modules
|
|
105
|
+
* @param {string=} scheme The URL scheme to use
|
|
106
|
+
*/
|
|
107
|
+
constructor(modules, scheme) {
|
|
108
|
+
this.scheme = scheme || DEFAULT_SCHEME;
|
|
109
|
+
this.modules = normalizeModules(modules, this.scheme);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Apply the plugin
|
|
114
|
+
* @param {Compiler} compiler the compiler instance
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
117
|
+
apply(compiler) {
|
|
118
|
+
const scheme = this.scheme;
|
|
119
|
+
const cachedParseResourceWithoutFragment =
|
|
120
|
+
parseResourceWithoutFragment.bindCache(compiler.root);
|
|
121
|
+
|
|
122
|
+
compiler.hooks.compilation.tap(
|
|
123
|
+
PLUGIN_NAME,
|
|
124
|
+
(compilation, { normalModuleFactory }) => {
|
|
125
|
+
normalModuleFactory.hooks.resolveForScheme
|
|
126
|
+
.for(scheme)
|
|
127
|
+
.tap(PLUGIN_NAME, resourceData => {
|
|
128
|
+
const virtualConfig = this.findVirtualModuleConfigById(
|
|
129
|
+
resourceData.resource
|
|
130
|
+
);
|
|
131
|
+
const url = cachedParseResourceWithoutFragment(
|
|
132
|
+
resourceData.resource
|
|
133
|
+
);
|
|
134
|
+
const path = url.path;
|
|
135
|
+
const type = virtualConfig.type;
|
|
136
|
+
resourceData.path = path + type;
|
|
137
|
+
resourceData.resource = path;
|
|
138
|
+
|
|
139
|
+
if (virtualConfig.version) {
|
|
140
|
+
const cacheKey = toCacheKey(resourceData.resource, scheme);
|
|
141
|
+
const cacheVersion = this.getCacheVersion(virtualConfig.version);
|
|
142
|
+
compilation.valueCacheVersions.set(
|
|
143
|
+
cacheKey,
|
|
144
|
+
/** @type {string} */ (cacheVersion)
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return true;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const hooks = NormalModule.getCompilationHooks(compilation);
|
|
152
|
+
hooks.readResource
|
|
153
|
+
.for(scheme)
|
|
154
|
+
.tapAsync(PLUGIN_NAME, async (loaderContext, callback) => {
|
|
155
|
+
const { resourcePath } = loaderContext;
|
|
156
|
+
const module = /** @type {NormalModule} */ (loaderContext._module);
|
|
157
|
+
const cacheKey = toCacheKey(resourcePath, scheme);
|
|
158
|
+
|
|
159
|
+
const addVersionValueDependency = () => {
|
|
160
|
+
if (!module || !module.buildInfo) return;
|
|
161
|
+
|
|
162
|
+
const buildInfo = module.buildInfo;
|
|
163
|
+
if (!buildInfo.valueDependencies) {
|
|
164
|
+
buildInfo.valueDependencies = new Map();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const cacheVersion = compilation.valueCacheVersions.get(cacheKey);
|
|
168
|
+
if (compilation.valueCacheVersions.has(cacheKey)) {
|
|
169
|
+
buildInfo.valueDependencies.set(
|
|
170
|
+
cacheKey,
|
|
171
|
+
/** @type {string} */ (cacheVersion)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
const virtualConfig =
|
|
178
|
+
this.findVirtualModuleConfigById(resourcePath);
|
|
179
|
+
const content = await virtualConfig.source(loaderContext);
|
|
180
|
+
addVersionValueDependency();
|
|
181
|
+
callback(null, content);
|
|
182
|
+
} catch (err) {
|
|
183
|
+
callback(/** @type {Error} */ (err));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @param {string} id The module id
|
|
192
|
+
* @returns {VirtualModuleConfig} The virtual module config
|
|
193
|
+
*/
|
|
194
|
+
findVirtualModuleConfigById(id) {
|
|
195
|
+
const config = this.modules[id];
|
|
196
|
+
if (!config) {
|
|
197
|
+
throw new ModuleNotFoundError(
|
|
198
|
+
null,
|
|
199
|
+
new Error(`Can't resolve virtual module ${id}`),
|
|
200
|
+
{
|
|
201
|
+
name: `virtual module ${id}`
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
return config;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get the cache version for a given version value
|
|
210
|
+
* @param {(() => string) | true | string} version The version value or function
|
|
211
|
+
* @returns {string | undefined} The cache version
|
|
212
|
+
*/
|
|
213
|
+
getCacheVersion(version) {
|
|
214
|
+
return version === true
|
|
215
|
+
? undefined
|
|
216
|
+
: (typeof version === "function" ? version() : version) || "unset";
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
VirtualUrlPlugin.DEFAULT_SCHEME = DEFAULT_SCHEME;
|
|
221
|
+
|
|
222
|
+
module.exports = VirtualUrlPlugin;
|
|
@@ -28,7 +28,7 @@ class AggregateErrorSerializer {
|
|
|
28
28
|
deserialize(context) {
|
|
29
29
|
const errors = context.read();
|
|
30
30
|
// @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers
|
|
31
|
-
// eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
|
|
31
|
+
// eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax, unicorn/error-message
|
|
32
32
|
const err = new AggregateError(errors);
|
|
33
33
|
|
|
34
34
|
err.message = context.read();
|
|
@@ -215,7 +215,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
215
215
|
(allocationScope.increaseCounter + 1) % 4) &&
|
|
216
216
|
allocationScope.allocationSize < 16777216
|
|
217
217
|
) {
|
|
218
|
-
allocationScope.allocationSize
|
|
218
|
+
allocationScope.allocationSize <<= 1;
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
};
|
|
@@ -281,8 +281,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
281
281
|
const thing = data[i];
|
|
282
282
|
switch (typeof thing) {
|
|
283
283
|
case "function": {
|
|
284
|
-
if (!SerializerMiddleware.isLazy(thing))
|
|
284
|
+
if (!SerializerMiddleware.isLazy(thing)) {
|
|
285
285
|
throw new Error(`Unexpected function ${thing}`);
|
|
286
|
+
}
|
|
286
287
|
/** @type {SerializedType | LazyFunction<SerializedType, DeserializedType> | undefined} */
|
|
287
288
|
let serializedData =
|
|
288
289
|
SerializerMiddleware.getLazySerializedValue(thing);
|
|
@@ -801,7 +802,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
801
802
|
let mask = 1;
|
|
802
803
|
while (n !== 0) {
|
|
803
804
|
result.push((data & mask) !== 0);
|
|
804
|
-
mask
|
|
805
|
+
mask <<= 1;
|
|
805
806
|
n--;
|
|
806
807
|
}
|
|
807
808
|
};
|
|
@@ -1155,5 +1156,5 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
|
1155
1156
|
|
|
1156
1157
|
module.exports = BinaryMiddleware;
|
|
1157
1158
|
|
|
1158
|
-
module.exports.MEASURE_START_OPERATION = MEASURE_START_OPERATION;
|
|
1159
1159
|
module.exports.MEASURE_END_OPERATION = MEASURE_END_OPERATION;
|
|
1160
|
+
module.exports.MEASURE_START_OPERATION = MEASURE_START_OPERATION;
|
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
const { constants } = require("buffer");
|
|
8
8
|
const { pipeline } = require("stream");
|
|
9
9
|
const {
|
|
10
|
+
constants: zConstants,
|
|
11
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
10
12
|
createBrotliCompress,
|
|
13
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
11
14
|
createBrotliDecompress,
|
|
12
|
-
createGzip,
|
|
13
15
|
createGunzip,
|
|
14
|
-
|
|
16
|
+
createGzip
|
|
15
17
|
} = require("zlib");
|
|
16
18
|
const { DEFAULTS } = require("../config/defaults");
|
|
17
19
|
const createHash = require("../util/createHash");
|
|
@@ -117,8 +119,9 @@ const serialize = async (
|
|
|
117
119
|
let lastBuffers;
|
|
118
120
|
for (const item of await data) {
|
|
119
121
|
if (typeof item === "function") {
|
|
120
|
-
if (!SerializerMiddleware.isLazy(item))
|
|
122
|
+
if (!SerializerMiddleware.isLazy(item)) {
|
|
121
123
|
throw new Error("Unexpected function");
|
|
124
|
+
}
|
|
122
125
|
if (!SerializerMiddleware.isLazy(item, middleware)) {
|
|
123
126
|
throw new Error(
|
|
124
127
|
"Unexpected lazy value with non-this target (can't pass through lazy values)"
|
|
@@ -551,7 +554,7 @@ class FileMiddleware extends SerializerMiddleware {
|
|
|
551
554
|
* @param {(value?: undefined) => void} resolve resolve
|
|
552
555
|
*/
|
|
553
556
|
resolve => {
|
|
554
|
-
this.fs.rename(filename, `${filename}.old`,
|
|
557
|
+
this.fs.rename(filename, `${filename}.old`, _err => {
|
|
555
558
|
resolve();
|
|
556
559
|
});
|
|
557
560
|
}
|
|
@@ -175,7 +175,7 @@ if (exports.constructor !== Object) {
|
|
|
175
175
|
// eslint-disable-next-line n/exports-style
|
|
176
176
|
const Obj = /** @type {ObjectConstructor} */ (exports.constructor);
|
|
177
177
|
const Fn = /** @type {FunctionConstructor} */ (Obj.constructor);
|
|
178
|
-
for (const [type, config] of
|
|
178
|
+
for (const [type, config] of jsTypes) {
|
|
179
179
|
if (type) {
|
|
180
180
|
const Type = new Fn(`return ${type.name};`)();
|
|
181
181
|
jsTypes.set(Type, config);
|
|
@@ -416,7 +416,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
416
416
|
* @returns {string} stack
|
|
417
417
|
*/
|
|
418
418
|
const stackToString = item => {
|
|
419
|
-
const arr =
|
|
419
|
+
const arr = [...cycleStack];
|
|
420
420
|
arr.push(item);
|
|
421
421
|
return arr
|
|
422
422
|
.map(item => {
|
|
@@ -439,11 +439,13 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
439
439
|
}
|
|
440
440
|
if (typeof item === "object" && item !== null) {
|
|
441
441
|
if (item.constructor) {
|
|
442
|
-
if (item.constructor === Object)
|
|
442
|
+
if (item.constructor === Object) {
|
|
443
443
|
return `Object { ${Object.keys(item).join(", ")} }`;
|
|
444
|
+
}
|
|
444
445
|
if (item.constructor === Map) return `Map { ${item.size} items }`;
|
|
445
|
-
if (item.constructor === Array)
|
|
446
|
+
if (item.constructor === Array) {
|
|
446
447
|
return `Array { ${item.length} items }`;
|
|
448
|
+
}
|
|
447
449
|
if (item.constructor === Set) return `Set { ${item.size} items }`;
|
|
448
450
|
if (item.constructor === RegExp) return item.toString();
|
|
449
451
|
return `${item.constructor.name}`;
|
|
@@ -472,8 +474,9 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
472
474
|
process(value);
|
|
473
475
|
} catch (err) {
|
|
474
476
|
if (err !== NOT_SERIALIZABLE) {
|
|
475
|
-
if (hasDebugInfoAttached === undefined)
|
|
477
|
+
if (hasDebugInfoAttached === undefined) {
|
|
476
478
|
hasDebugInfoAttached = new WeakSet();
|
|
479
|
+
}
|
|
477
480
|
if (!hasDebugInfoAttached.has(/** @type {Error} */ (err))) {
|
|
478
481
|
/** @type {Error} */
|
|
479
482
|
(err).message += `\nwhile serializing ${stackToString(value)}`;
|
|
@@ -596,8 +599,9 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
596
599
|
|
|
597
600
|
result.push(item);
|
|
598
601
|
} else if (typeof item === "function") {
|
|
599
|
-
if (!SerializerMiddleware.isLazy(item))
|
|
602
|
+
if (!SerializerMiddleware.isLazy(item)) {
|
|
600
603
|
throw new Error(`Unexpected function ${item}`);
|
|
604
|
+
}
|
|
601
605
|
|
|
602
606
|
/** @type {SerializedType | undefined} */
|
|
603
607
|
const serializedData =
|
|
@@ -658,14 +662,16 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
|
658
662
|
deserialize(data, context) {
|
|
659
663
|
let currentDataPos = 0;
|
|
660
664
|
const read = () => {
|
|
661
|
-
if (currentDataPos >= data.length)
|
|
665
|
+
if (currentDataPos >= data.length) {
|
|
662
666
|
throw new Error("Unexpected end of stream");
|
|
667
|
+
}
|
|
663
668
|
|
|
664
669
|
return data[currentDataPos++];
|
|
665
670
|
};
|
|
666
671
|
|
|
667
|
-
if (read() !== CURRENT_VERSION)
|
|
672
|
+
if (read() !== CURRENT_VERSION) {
|
|
668
673
|
throw new Error("Version mismatch, serializer changed");
|
|
674
|
+
}
|
|
669
675
|
|
|
670
676
|
let currentPos = 0;
|
|
671
677
|
/** @type {ReferenceableItem[]} */
|
|
@@ -20,8 +20,8 @@ class Serializer {
|
|
|
20
20
|
* @param {Context=} context context
|
|
21
21
|
*/
|
|
22
22
|
constructor(middlewares, context) {
|
|
23
|
-
this.serializeMiddlewares = middlewares
|
|
24
|
-
this.deserializeMiddlewares = middlewares.
|
|
23
|
+
this.serializeMiddlewares = [...middlewares];
|
|
24
|
+
this.deserializeMiddlewares = [...middlewares].reverse();
|
|
25
25
|
this.context = context;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -49,7 +49,9 @@ class Serializer {
|
|
|
49
49
|
} catch (err) {
|
|
50
50
|
current = Promise.reject(err);
|
|
51
51
|
}
|
|
52
|
-
} else
|
|
52
|
+
} else {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
return /** @type {Promise<SerializedValue>} */ (current);
|
|
55
57
|
}
|
|
@@ -35,6 +35,7 @@ class SerializerMiddleware {
|
|
|
35
35
|
*/
|
|
36
36
|
serialize(data, context) {
|
|
37
37
|
const AbstractMethodError = require("../AbstractMethodError");
|
|
38
|
+
|
|
38
39
|
throw new AbstractMethodError();
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -47,6 +48,7 @@ class SerializerMiddleware {
|
|
|
47
48
|
*/
|
|
48
49
|
deserialize(data, context) {
|
|
49
50
|
const AbstractMethodError = require("../AbstractMethodError");
|
|
51
|
+
|
|
50
52
|
throw new AbstractMethodError();
|
|
51
53
|
}
|
|
52
54
|
|
|
@@ -177,7 +177,7 @@ class ConsumeSharedModule extends Module {
|
|
|
177
177
|
* @param {CodeGenerationContext} context context for code generation
|
|
178
178
|
* @returns {CodeGenerationResult} result
|
|
179
179
|
*/
|
|
180
|
-
codeGeneration({ chunkGraph,
|
|
180
|
+
codeGeneration({ chunkGraph, runtimeTemplate }) {
|
|
181
181
|
const runtimeRequirements = new Set([RuntimeGlobals.shareScopeMap]);
|
|
182
182
|
const {
|
|
183
183
|
shareScope,
|
|
@@ -18,9 +18,9 @@ const ConsumeSharedRuntimeModule = require("./ConsumeSharedRuntimeModule");
|
|
|
18
18
|
const ProvideForSharedDependency = require("./ProvideForSharedDependency");
|
|
19
19
|
const { resolveMatchedConfigs } = require("./resolveMatchedConfigs");
|
|
20
20
|
const {
|
|
21
|
-
isRequiredVersion,
|
|
22
21
|
getDescriptionFile,
|
|
23
|
-
getRequiredVersionFromDescriptionFile
|
|
22
|
+
getRequiredVersionFromDescriptionFile,
|
|
23
|
+
isRequiredVersion
|
|
24
24
|
} = require("./utils");
|
|
25
25
|
|
|
26
26
|
/** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumeSharedPluginOptions} ConsumeSharedPluginOptions */
|
|
@@ -32,7 +32,7 @@ const {
|
|
|
32
32
|
/** @typedef {import("./utils").DescriptionFile} DescriptionFile */
|
|
33
33
|
|
|
34
34
|
const validate = createSchemaValidation(
|
|
35
|
-
require("../../schemas/plugins/sharing/ConsumeSharedPlugin.check
|
|
35
|
+
require("../../schemas/plugins/sharing/ConsumeSharedPlugin.check"),
|
|
36
36
|
() => require("../../schemas/plugins/sharing/ConsumeSharedPlugin.json"),
|
|
37
37
|
{
|
|
38
38
|
name: "Consume Shared Plugin",
|
|
@@ -10,9 +10,9 @@ const RuntimeModule = require("../RuntimeModule");
|
|
|
10
10
|
const Template = require("../Template");
|
|
11
11
|
const {
|
|
12
12
|
parseVersionRuntimeCode,
|
|
13
|
-
versionLtRuntimeCode,
|
|
14
13
|
rangeToStringRuntimeCode,
|
|
15
|
-
satisfyRuntimeCode
|
|
14
|
+
satisfyRuntimeCode,
|
|
15
|
+
versionLtRuntimeCode
|
|
16
16
|
} = require("../util/semver");
|
|
17
17
|
|
|
18
18
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
@@ -132,7 +132,7 @@ class ProvideSharedModule extends Module {
|
|
|
132
132
|
* @param {CodeGenerationContext} context context for code generation
|
|
133
133
|
* @returns {CodeGenerationResult} result
|
|
134
134
|
*/
|
|
135
|
-
codeGeneration({ runtimeTemplate,
|
|
135
|
+
codeGeneration({ runtimeTemplate, chunkGraph }) {
|
|
136
136
|
const runtimeRequirements = new Set([RuntimeGlobals.initializeSharing]);
|
|
137
137
|
const code = `register(${JSON.stringify(this._name)}, ${JSON.stringify(
|
|
138
138
|
this._version || "0"
|
|
@@ -18,7 +18,7 @@ const ProvideSharedModuleFactory = require("./ProvideSharedModuleFactory");
|
|
|
18
18
|
/** @typedef {import("../NormalModuleFactory").NormalModuleCreateData} NormalModuleCreateData */
|
|
19
19
|
|
|
20
20
|
const validate = createSchemaValidation(
|
|
21
|
-
require("../../schemas/plugins/sharing/ProvideSharedPlugin.check
|
|
21
|
+
require("../../schemas/plugins/sharing/ProvideSharedPlugin.check"),
|
|
22
22
|
() => require("../../schemas/plugins/sharing/ProvideSharedPlugin.json"),
|
|
23
23
|
{
|
|
24
24
|
name: "Provide Shared Plugin",
|
|
@@ -49,8 +49,9 @@ class ProvideSharedPlugin {
|
|
|
49
49
|
parseOptions(
|
|
50
50
|
options.provides,
|
|
51
51
|
item => {
|
|
52
|
-
if (Array.isArray(item))
|
|
52
|
+
if (Array.isArray(item)) {
|
|
53
53
|
throw new Error("Unexpected array of provides");
|
|
54
|
+
}
|
|
54
55
|
/** @type {ProvideOptions} */
|
|
55
56
|
const result = {
|
|
56
57
|
shareKey: item,
|
|
@@ -27,8 +27,9 @@ class SharePlugin {
|
|
|
27
27
|
const sharedOptions = parseOptions(
|
|
28
28
|
options.shared,
|
|
29
29
|
(item, key) => {
|
|
30
|
-
if (typeof item !== "string")
|
|
30
|
+
if (typeof item !== "string") {
|
|
31
31
|
throw new Error("Unexpected array in shared");
|
|
32
|
+
}
|
|
32
33
|
/** @type {SharedConfig} */
|
|
33
34
|
const config =
|
|
34
35
|
item === key || !isRequiredVersion(item)
|
|
@@ -121,17 +121,15 @@ class ShareRuntimeModule extends RuntimeModule {
|
|
|
121
121
|
])}`,
|
|
122
122
|
"var promises = [];",
|
|
123
123
|
"switch(name) {",
|
|
124
|
-
...
|
|
124
|
+
...[...initCodePerScope]
|
|
125
125
|
.sort(([a], [b]) => compareStrings(a, b))
|
|
126
126
|
.map(([name, stages]) =>
|
|
127
127
|
Template.indent([
|
|
128
128
|
`case ${JSON.stringify(name)}: {`,
|
|
129
129
|
Template.indent(
|
|
130
|
-
|
|
130
|
+
[...stages]
|
|
131
131
|
.sort(([a], [b]) => a - b)
|
|
132
|
-
.map(([, initCode]) =>
|
|
133
|
-
Template.asString(Array.from(initCode))
|
|
134
|
-
)
|
|
132
|
+
.map(([, initCode]) => Template.asString([...initCode]))
|
|
135
133
|
),
|
|
136
134
|
"}",
|
|
137
135
|
"break;"
|
package/lib/sharing/utils.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const {
|
|
8
|
+
const { dirname, join, readJson } = require("../util/fs");
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
|
11
11
|
/** @typedef {import("../util/fs").JsonObject} JsonObject */
|
|
@@ -292,34 +292,6 @@ function getGitUrlVersion(gitUrl) {
|
|
|
292
292
|
return getVersionFromHash(gitUrl);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
/**
|
|
296
|
-
* @param {string} str maybe required version
|
|
297
|
-
* @returns {boolean} true, if it looks like a version
|
|
298
|
-
*/
|
|
299
|
-
function isRequiredVersion(str) {
|
|
300
|
-
return VERSION_PATTERN_REGEXP.test(str);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
module.exports.isRequiredVersion = isRequiredVersion;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* @see https://docs.npmjs.com/cli/v7/configuring-npm/package-json#urls-as-dependencies
|
|
307
|
-
* @param {string} versionDesc version to be normalized
|
|
308
|
-
* @returns {string} normalized version
|
|
309
|
-
*/
|
|
310
|
-
function normalizeVersion(versionDesc) {
|
|
311
|
-
versionDesc = (versionDesc && versionDesc.trim()) || "";
|
|
312
|
-
|
|
313
|
-
if (isRequiredVersion(versionDesc)) {
|
|
314
|
-
return versionDesc;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// add handle for URL Dependencies
|
|
318
|
-
return getGitUrlVersion(versionDesc.toLowerCase());
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
module.exports.normalizeVersion = normalizeVersion;
|
|
322
|
-
|
|
323
295
|
/** @typedef {{ data: JsonObject, path: string }} DescriptionFile */
|
|
324
296
|
|
|
325
297
|
/**
|
|
@@ -349,11 +321,9 @@ const getDescriptionFile = (
|
|
|
349
321
|
if (i >= descriptionFiles.length) {
|
|
350
322
|
const parentDirectory = dirname(fs, directory);
|
|
351
323
|
if (!parentDirectory || parentDirectory === directory) {
|
|
352
|
-
return callback(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
Array.from(satisfiesDescriptionFileDataInternal.checkedFilePaths)
|
|
356
|
-
);
|
|
324
|
+
return callback(null, undefined, [
|
|
325
|
+
...satisfiesDescriptionFileDataInternal.checkedFilePaths
|
|
326
|
+
]);
|
|
357
327
|
}
|
|
358
328
|
return getDescriptionFile(
|
|
359
329
|
fs,
|
|
@@ -391,6 +361,7 @@ const getDescriptionFile = (
|
|
|
391
361
|
};
|
|
392
362
|
tryLoadCurrent();
|
|
393
363
|
};
|
|
364
|
+
|
|
394
365
|
module.exports.getDescriptionFile = getDescriptionFile;
|
|
395
366
|
|
|
396
367
|
/**
|
|
@@ -421,5 +392,34 @@ const getRequiredVersionFromDescriptionFile = (data, packageName) => {
|
|
|
421
392
|
}
|
|
422
393
|
}
|
|
423
394
|
};
|
|
395
|
+
|
|
424
396
|
module.exports.getRequiredVersionFromDescriptionFile =
|
|
425
397
|
getRequiredVersionFromDescriptionFile;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* @param {string} str maybe required version
|
|
401
|
+
* @returns {boolean} true, if it looks like a version
|
|
402
|
+
*/
|
|
403
|
+
function isRequiredVersion(str) {
|
|
404
|
+
return VERSION_PATTERN_REGEXP.test(str);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
module.exports.isRequiredVersion = isRequiredVersion;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* @see https://docs.npmjs.com/cli/v7/configuring-npm/package-json#urls-as-dependencies
|
|
411
|
+
* @param {string} versionDesc version to be normalized
|
|
412
|
+
* @returns {string} normalized version
|
|
413
|
+
*/
|
|
414
|
+
function normalizeVersion(versionDesc) {
|
|
415
|
+
versionDesc = (versionDesc && versionDesc.trim()) || "";
|
|
416
|
+
|
|
417
|
+
if (isRequiredVersion(versionDesc)) {
|
|
418
|
+
return versionDesc;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// add handle for URL Dependencies
|
|
422
|
+
return getGitUrlVersion(versionDesc.toLowerCase());
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
module.exports.normalizeVersion = normalizeVersion;
|