webpack 5.93.0 → 5.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/bin/webpack.js +6 -7
- package/hot/log.js +1 -2
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +4 -3
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +12 -6
- package/lib/Cache.js +8 -10
- package/lib/CacheFacade.js +3 -3
- package/lib/CaseSensitiveModulesWarning.js +5 -7
- package/lib/Chunk.js +14 -11
- package/lib/ChunkGraph.js +58 -36
- package/lib/ChunkGroup.js +2 -3
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +10 -11
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/Compilation.js +223 -191
- package/lib/Compiler.js +81 -82
- package/lib/ConcatenationScope.js +3 -6
- package/lib/ConditionalInitFragment.js +6 -7
- package/lib/ConstPlugin.js +7 -15
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +33 -20
- package/lib/ContextModuleFactory.js +89 -44
- package/lib/ContextReplacementPlugin.js +10 -9
- package/lib/DefinePlugin.js +75 -68
- package/lib/DelegatedModule.js +7 -3
- package/lib/DelegatedModuleFactoryPlugin.js +36 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +0 -1
- package/lib/Dependency.js +10 -14
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllModuleFactory.js +1 -0
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +30 -15
- package/lib/EntryPlugin.js +1 -3
- package/lib/EnvironmentPlugin.js +5 -2
- package/lib/ErrorHelpers.js +11 -12
- package/lib/EvalDevToolModulePlugin.js +10 -12
- package/lib/EvalSourceMapDevToolPlugin.js +15 -13
- package/lib/ExportsInfo.js +185 -120
- package/lib/ExternalModule.js +104 -64
- package/lib/ExternalModuleFactoryPlugin.js +23 -10
- package/lib/FileSystemInfo.js +791 -422
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
- package/lib/FlagDependencyExportsPlugin.js +12 -11
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +2 -5
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +8 -10
- package/lib/HotModuleReplacementPlugin.js +78 -64
- package/lib/IgnoreErrorModuleFactory.js +3 -3
- package/lib/IgnorePlugin.js +1 -3
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +2 -3
- package/lib/LibManifestPlugin.js +4 -3
- package/lib/MainTemplate.js +72 -19
- package/lib/Module.js +25 -9
- package/lib/ModuleBuildError.js +4 -11
- package/lib/ModuleDependencyError.js +5 -5
- package/lib/ModuleDependencyWarning.js +5 -5
- package/lib/ModuleError.js +1 -5
- package/lib/ModuleFilenameHelpers.js +29 -46
- package/lib/ModuleGraph.js +7 -6
- package/lib/ModuleGraphConnection.js +6 -6
- package/lib/ModuleInfoHeaderPlugin.js +82 -30
- package/lib/ModuleParseError.js +8 -9
- package/lib/ModuleRestoreError.js +1 -1
- package/lib/ModuleStoreError.js +1 -1
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +21 -22
- package/lib/ModuleWarning.js +1 -5
- package/lib/MultiCompiler.js +24 -26
- package/lib/MultiStats.js +73 -31
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +126 -69
- package/lib/NormalModuleFactory.js +53 -49
- package/lib/OptimizationStages.js +3 -3
- package/lib/ProgressPlugin.js +9 -9
- package/lib/ProvidePlugin.js +4 -4
- package/lib/RuntimeGlobals.js +71 -70
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +24 -12
- package/lib/RuntimeTemplate.js +40 -44
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolPlugin.js +42 -34
- package/lib/Stats.js +5 -11
- package/lib/Template.js +18 -24
- package/lib/TemplatedPathPlugin.js +12 -10
- package/lib/WarnDeprecatedOptionPlugin.js +0 -1
- package/lib/WatchIgnorePlugin.js +26 -9
- package/lib/Watching.js +10 -5
- package/lib/WebpackOptionsApply.js +84 -62
- package/lib/asset/AssetGenerator.js +107 -42
- package/lib/asset/AssetModulesPlugin.js +29 -23
- package/lib/asset/AssetSourceGenerator.js +2 -7
- package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
- package/lib/buildChunkGraph.js +14 -19
- package/lib/cache/IdleFileCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +51 -50
- package/lib/cache/ResolverCachePlugin.js +6 -6
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +148 -104
- package/lib/config/browserslistTargetHandler.js +16 -13
- package/lib/config/defaults.js +31 -28
- package/lib/config/normalization.js +335 -344
- package/lib/config/target.js +42 -52
- package/lib/container/ContainerEntryModule.js +2 -2
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +11 -8
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +26 -24
- package/lib/css/CssGenerator.js +9 -4
- package/lib/css/CssLoadingRuntimeModule.js +10 -10
- package/lib/css/CssModulesPlugin.js +127 -47
- package/lib/css/CssParser.js +20 -18
- package/lib/css/walkCssTokens.js +80 -95
- package/lib/debug/ProfilingPlugin.js +19 -20
- package/lib/dependencies/AMDDefineDependency.js +1 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
- package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
- package/lib/dependencies/CommonJsExportsDependency.js +0 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
- package/lib/dependencies/ConstDependency.js +1 -1
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +31 -34
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssExportDependency.js +7 -7
- package/lib/dependencies/CssImportDependency.js +0 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +4 -5
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/ExportsInfoDependency.js +1 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
- package/lib/dependencies/HarmonyExports.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
- package/lib/dependencies/ImportDependency.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +11 -13
- package/lib/dependencies/ImportParserPlugin.js +39 -44
- package/lib/dependencies/JsonExportsDependency.js +22 -18
- package/lib/dependencies/LoaderPlugin.js +47 -36
- package/lib/dependencies/LocalModule.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +4 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
- package/lib/dependencies/ProvidedDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +6 -6
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLDependency.js +3 -3
- package/lib/dependencies/URLPlugin.js +66 -12
- package/lib/dependencies/WorkerPlugin.js +25 -24
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
- package/lib/hmr/LazyCompilationPlugin.js +27 -12
- package/lib/hmr/lazyCompilationBackend.js +64 -40
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +5 -1
- package/lib/ids/IdHelpers.js +29 -39
- package/lib/ids/SyncModuleIdsPlugin.js +7 -2
- package/lib/index.js +1 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
- package/lib/javascript/BasicEvaluatedExpression.js +4 -19
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
- package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
- package/lib/javascript/JavascriptGenerator.js +23 -7
- package/lib/javascript/JavascriptModulesPlugin.js +91 -69
- package/lib/javascript/JavascriptParser.js +179 -200
- package/lib/javascript/JavascriptParserHelpers.js +20 -21
- package/lib/javascript/StartupHelpers.js +41 -13
- package/lib/json/JsonGenerator.js +7 -13
- package/lib/json/JsonModulesPlugin.js +1 -4
- package/lib/json/JsonParser.js +5 -3
- package/lib/library/AmdLibraryPlugin.js +12 -16
- package/lib/library/AssignLibraryPlugin.js +8 -10
- package/lib/library/EnableLibraryPlugin.js +15 -14
- package/lib/library/JsonpLibraryPlugin.js +2 -1
- package/lib/library/ModernModuleLibraryPlugin.js +8 -6
- package/lib/library/ModuleLibraryPlugin.js +2 -1
- package/lib/library/SystemLibraryPlugin.js +2 -1
- package/lib/library/UmdLibraryPlugin.js +66 -92
- package/lib/logging/Logger.js +32 -4
- package/lib/logging/createConsoleLogger.js +12 -13
- package/lib/logging/runtime.js +7 -8
- package/lib/logging/truncateArgs.js +5 -8
- package/lib/node/NodeWatchFileSystem.js +3 -18
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/nodeConsole.js +22 -22
- package/lib/optimize/AggressiveMergingPlugin.js +2 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
- package/lib/optimize/ConcatenatedModule.js +80 -48
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
- package/lib/optimize/InnerGraph.js +17 -17
- package/lib/optimize/InnerGraphPlugin.js +8 -7
- package/lib/optimize/LimitChunkCountPlugin.js +2 -3
- package/lib/optimize/MangleExportsPlugin.js +1 -0
- package/lib/optimize/MinMaxSizeWarning.js +1 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
- package/lib/optimize/RealContentHashPlugin.js +7 -10
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
- package/lib/optimize/SplitChunksPlugin.js +34 -30
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
- package/lib/rules/BasicEffectRulePlugin.js +3 -1
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
- package/lib/rules/RuleSetCompiler.js +41 -22
- package/lib/rules/UseEffectRulePlugin.js +36 -32
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
- package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +241 -126
- package/lib/serialization/BinaryMiddleware.js +44 -28
- package/lib/serialization/DateObjectSerializer.js +1 -0
- package/lib/serialization/ErrorObjectSerializer.js +2 -0
- package/lib/serialization/FileMiddleware.js +154 -106
- package/lib/serialization/MapObjectSerializer.js +2 -1
- package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
- package/lib/serialization/ObjectMiddleware.js +52 -56
- package/lib/serialization/PlainObjectSerializer.js +32 -6
- package/lib/serialization/RegExpObjectSerializer.js +1 -0
- package/lib/serialization/Serializer.js +4 -5
- package/lib/serialization/SerializerMiddleware.js +6 -6
- package/lib/serialization/SetObjectSerializer.js +2 -1
- package/lib/sharing/ConsumeSharedPlugin.js +116 -97
- package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedPlugin.js +2 -2
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +15 -27
- package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
- package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
- package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
- package/lib/stats/StatsFactory.js +127 -56
- package/lib/stats/StatsPrinter.js +75 -44
- package/lib/util/ArrayHelpers.js +8 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +31 -12
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +1 -0
- package/lib/util/MapHelpers.js +1 -3
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Queue.js +1 -1
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +4 -3
- package/lib/util/StackedCacheMap.js +4 -6
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +0 -5
- package/lib/util/TupleQueue.js +1 -1
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +7 -7
- package/lib/util/WeakTupleMap.js +19 -21
- package/lib/util/binarySearchBounds.js +5 -12
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +21 -19
- package/lib/util/comparators.js +57 -52
- package/lib/util/compileBooleanMatcher.js +3 -6
- package/lib/util/conventions.js +8 -11
- package/lib/util/createHash.js +9 -6
- package/lib/util/deprecation.js +22 -12
- package/lib/util/deterministicGrouping.js +19 -26
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +31 -31
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +7 -7
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +81 -59
- package/lib/util/memoize.js +8 -10
- package/lib/util/mergeScope.js +6 -9
- package/lib/util/nonNumericOnlyHash.js +2 -2
- package/lib/util/numberHash.js +1 -6
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/propertyAccess.js +2 -5
- package/lib/util/propertyName.js +1 -3
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +103 -113
- package/lib/util/semver.js +29 -27
- package/lib/util/serialization.js +16 -1
- package/lib/util/smartGrouping.js +5 -5
- package/lib/util/source.js +1 -1
- package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
- package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +15 -14
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +1 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
- package/types.d.ts +667 -347
@@ -15,17 +15,37 @@ const createHash = require("../util/createHash");
|
|
15
15
|
const { mkdirp, dirname, join } = require("../util/fs");
|
16
16
|
const memoize = require("../util/memoize");
|
17
17
|
|
18
|
+
/** @typedef {import("http").IncomingMessage} IncomingMessage */
|
19
|
+
/** @typedef {import("http").RequestOptions} RequestOptions */
|
20
|
+
/** @typedef {import("net").Socket} Socket */
|
21
|
+
/** @typedef {import("stream").Readable} Readable */
|
18
22
|
/** @typedef {import("../../declarations/plugins/schemes/HttpUriPlugin").HttpUriPluginOptions} HttpUriPluginOptions */
|
19
23
|
/** @typedef {import("../Compiler")} Compiler */
|
24
|
+
/** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
|
25
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
26
|
+
/** @typedef {import("../NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
|
27
|
+
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
20
28
|
|
21
29
|
const getHttp = memoize(() => require("http"));
|
22
30
|
const getHttps = memoize(() => require("https"));
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @param {typeof import("http") | typeof import("https")} request request
|
34
|
+
* @param {string | { toString: () => string } | undefined} proxy proxy
|
35
|
+
* @returns {function(URL, RequestOptions, function(IncomingMessage): void): EventEmitter} fn
|
36
|
+
*/
|
23
37
|
const proxyFetch = (request, proxy) => (url, options, callback) => {
|
24
38
|
const eventEmitter = new EventEmitter();
|
25
|
-
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @param {Socket=} socket socket
|
42
|
+
* @returns {void}
|
43
|
+
*/
|
44
|
+
const doRequest = socket => {
|
26
45
|
request
|
27
46
|
.get(url, { ...options, ...(socket && { socket }) }, callback)
|
28
47
|
.on("error", eventEmitter.emit.bind(eventEmitter, "error"));
|
48
|
+
};
|
29
49
|
|
30
50
|
if (proxy) {
|
31
51
|
const { hostname: host, port } = new URL(proxy);
|
@@ -59,8 +79,9 @@ const proxyFetch = (request, proxy) => (url, options, callback) => {
|
|
59
79
|
return eventEmitter;
|
60
80
|
};
|
61
81
|
|
62
|
-
/** @
|
63
|
-
|
82
|
+
/** @typedef {() => void} InProgressWriteItem */
|
83
|
+
/** @type {InProgressWriteItem[] | undefined} */
|
84
|
+
let inProgressWrite;
|
64
85
|
|
65
86
|
const validate = createSchemaValidation(
|
66
87
|
require("../../schemas/plugins/schemes/HttpUriPlugin.check.js"),
|
@@ -87,7 +108,7 @@ const toSafePath = str =>
|
|
87
108
|
const computeIntegrity = content => {
|
88
109
|
const hash = createHash("sha512");
|
89
110
|
hash.update(content);
|
90
|
-
const integrity =
|
111
|
+
const integrity = `sha512-${hash.digest("base64")}`;
|
91
112
|
return integrity;
|
92
113
|
};
|
93
114
|
|
@@ -138,8 +159,8 @@ const parseCacheControl = (cacheControl, requestTime) => {
|
|
138
159
|
if (cacheControl) {
|
139
160
|
const parsed = parseKeyValuePairs(cacheControl);
|
140
161
|
if (parsed["no-cache"]) storeCache = storeLock = false;
|
141
|
-
if (parsed["max-age"] && !isNaN(
|
142
|
-
validUntil = requestTime +
|
162
|
+
if (parsed["max-age"] && !Number.isNaN(Number(parsed["max-age"]))) {
|
163
|
+
validUntil = requestTime + Number(parsed["max-age"]) * 1000;
|
143
164
|
}
|
144
165
|
if (parsed["must-revalidate"]) validUntil = 0;
|
145
166
|
}
|
@@ -157,21 +178,22 @@ const parseCacheControl = (cacheControl, requestTime) => {
|
|
157
178
|
* @property {string} contentType
|
158
179
|
*/
|
159
180
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
181
|
+
/**
|
182
|
+
* @param {LockfileEntry} a first lockfile entry
|
183
|
+
* @param {LockfileEntry} b second lockfile entry
|
184
|
+
* @returns {boolean} true when equal, otherwise false
|
185
|
+
*/
|
186
|
+
const areLockfileEntriesEqual = (a, b) =>
|
187
|
+
a.resolved === b.resolved &&
|
188
|
+
a.integrity === b.integrity &&
|
189
|
+
a.contentType === b.contentType;
|
167
190
|
|
168
191
|
/**
|
169
192
|
* @param {LockfileEntry} entry lockfile entry
|
170
193
|
* @returns {`resolved: ${string}, integrity: ${string}, contentType: ${*}`} stringified entry
|
171
194
|
*/
|
172
|
-
const entryToString = entry =>
|
173
|
-
|
174
|
-
};
|
195
|
+
const entryToString = entry =>
|
196
|
+
`resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
|
175
197
|
|
176
198
|
class Lockfile {
|
177
199
|
constructor() {
|
@@ -233,17 +255,17 @@ class Lockfile {
|
|
233
255
|
|
234
256
|
/**
|
235
257
|
* @template R
|
236
|
-
* @param {function(function(Error
|
237
|
-
* @returns {function(function(
|
258
|
+
* @param {function(function(Error | null, R=): void): void} fn function
|
259
|
+
* @returns {function(function(Error | null, R=): void): void} cached function
|
238
260
|
*/
|
239
261
|
const cachedWithoutKey = fn => {
|
240
262
|
let inFlight = false;
|
241
263
|
/** @type {Error | undefined} */
|
242
|
-
let cachedError
|
264
|
+
let cachedError;
|
243
265
|
/** @type {R | undefined} */
|
244
|
-
let cachedResult
|
245
|
-
/** @type {(function(Error
|
246
|
-
let cachedCallbacks
|
266
|
+
let cachedResult;
|
267
|
+
/** @type {(function(Error| null, R=): void)[] | undefined} */
|
268
|
+
let cachedCallbacks;
|
247
269
|
return callback => {
|
248
270
|
if (inFlight) {
|
249
271
|
if (cachedResult !== undefined) return callback(null, cachedResult);
|
@@ -267,14 +289,22 @@ const cachedWithoutKey = fn => {
|
|
267
289
|
/**
|
268
290
|
* @template T
|
269
291
|
* @template R
|
270
|
-
* @param {function(T, function(Error
|
271
|
-
* @param {function(T, function(Error
|
272
|
-
* @returns {(function(T, function(
|
292
|
+
* @param {function(T, function(Error | null, R=): void): void} fn function
|
293
|
+
* @param {function(T, function(Error | null, R=): void): void=} forceFn function for the second try
|
294
|
+
* @returns {(function(T, function(Error | null, R=): void): void) & { force: function(T, function(Error | null, R=): void): void }} cached function
|
273
295
|
*/
|
274
296
|
const cachedWithKey = (fn, forceFn = fn) => {
|
275
|
-
/**
|
276
|
-
|
297
|
+
/**
|
298
|
+
* @template R
|
299
|
+
* @typedef {{ result?: R, error?: Error, callbacks?: (function(Error | null, R=): void)[], force?: true }} CacheEntry
|
300
|
+
*/
|
301
|
+
/** @type {Map<T, CacheEntry<R>>} */
|
277
302
|
const cache = new Map();
|
303
|
+
/**
|
304
|
+
* @param {T} arg arg
|
305
|
+
* @param {function(Error | null, R=): void} callback callback
|
306
|
+
* @returns {void}
|
307
|
+
*/
|
278
308
|
const resultFn = (arg, callback) => {
|
279
309
|
const cacheEntry = cache.get(arg);
|
280
310
|
if (cacheEntry !== undefined) {
|
@@ -285,7 +315,7 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
285
315
|
else cacheEntry.callbacks.push(callback);
|
286
316
|
return;
|
287
317
|
}
|
288
|
-
/** @type {CacheEntry} */
|
318
|
+
/** @type {CacheEntry<R>} */
|
289
319
|
const newCacheEntry = {
|
290
320
|
result: undefined,
|
291
321
|
error: undefined,
|
@@ -301,6 +331,11 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
301
331
|
if (callbacks !== undefined) for (const cb of callbacks) cb(err, result);
|
302
332
|
});
|
303
333
|
};
|
334
|
+
/**
|
335
|
+
* @param {T} arg arg
|
336
|
+
* @param {function(Error | null, R=): void} callback callback
|
337
|
+
* @returns {void}
|
338
|
+
*/
|
304
339
|
resultFn.force = (arg, callback) => {
|
305
340
|
const cacheEntry = cache.get(arg);
|
306
341
|
if (cacheEntry !== undefined && cacheEntry.force) {
|
@@ -311,7 +346,7 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
311
346
|
else cacheEntry.callbacks.push(callback);
|
312
347
|
return;
|
313
348
|
}
|
314
|
-
/** @type {CacheEntry} */
|
349
|
+
/** @type {CacheEntry<R>} */
|
315
350
|
const newCacheEntry = {
|
316
351
|
result: undefined,
|
317
352
|
error: undefined,
|
@@ -331,6 +366,24 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
331
366
|
return resultFn;
|
332
367
|
};
|
333
368
|
|
369
|
+
/**
|
370
|
+
* @typedef {object} LockfileCache
|
371
|
+
* @property {Lockfile} lockfile lockfile
|
372
|
+
* @property {Snapshot} snapshot snapshot
|
373
|
+
*/
|
374
|
+
|
375
|
+
/**
|
376
|
+
* @typedef {object} ResolveContentResult
|
377
|
+
* @property {LockfileEntry} entry lockfile entry
|
378
|
+
* @property {Buffer} content content
|
379
|
+
* @property {boolean} storeLock need store lockfile
|
380
|
+
*/
|
381
|
+
|
382
|
+
/** @typedef {{ storeCache: boolean, storeLock: boolean, validUntil: number, etag: string | undefined, fresh: boolean }} FetchResultMeta */
|
383
|
+
/** @typedef {FetchResultMeta & { location: string }} RedirectFetchResult */
|
384
|
+
/** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
|
385
|
+
/** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
|
386
|
+
|
334
387
|
class HttpUriPlugin {
|
335
388
|
/**
|
336
389
|
* @param {HttpUriPluginOptions} options options
|
@@ -352,7 +405,7 @@ class HttpUriPlugin {
|
|
352
405
|
*/
|
353
406
|
apply(compiler) {
|
354
407
|
const proxy =
|
355
|
-
this._proxy || process.env
|
408
|
+
this._proxy || process.env.http_proxy || process.env.HTTP_PROXY;
|
356
409
|
const schemes = [
|
357
410
|
{
|
358
411
|
scheme: "http",
|
@@ -363,11 +416,14 @@ class HttpUriPlugin {
|
|
363
416
|
fetch: proxyFetch(getHttps(), proxy)
|
364
417
|
}
|
365
418
|
];
|
419
|
+
/** @type {LockfileCache} */
|
366
420
|
let lockfileCache;
|
367
421
|
compiler.hooks.compilation.tap(
|
368
422
|
"HttpUriPlugin",
|
369
423
|
(compilation, { normalModuleFactory }) => {
|
370
|
-
const intermediateFs =
|
424
|
+
const intermediateFs =
|
425
|
+
/** @type {IntermediateFileSystem} */
|
426
|
+
(compiler.intermediateFileSystem);
|
371
427
|
const fs = compilation.inputFileSystem;
|
372
428
|
const cache = compilation.getCache("webpack.HttpUriPlugin");
|
373
429
|
const logger = compilation.getLogger("webpack.HttpUriPlugin");
|
@@ -385,7 +441,7 @@ class HttpUriPlugin {
|
|
385
441
|
const cacheLocation =
|
386
442
|
this._cacheLocation !== undefined
|
387
443
|
? this._cacheLocation
|
388
|
-
: lockfileLocation
|
444
|
+
: `${lockfileLocation}.data`;
|
389
445
|
const upgrade = this._upgrade || false;
|
390
446
|
const frozen = this._frozen || false;
|
391
447
|
const hashFunction = "sha512";
|
@@ -431,7 +487,7 @@ class HttpUriPlugin {
|
|
431
487
|
|
432
488
|
const getLockfile = cachedWithoutKey(
|
433
489
|
/**
|
434
|
-
* @param {function(
|
490
|
+
* @param {function(Error | null, Lockfile=): void} callback callback
|
435
491
|
* @returns {void}
|
436
492
|
*/
|
437
493
|
callback => {
|
@@ -448,14 +504,14 @@ class HttpUriPlugin {
|
|
448
504
|
[],
|
449
505
|
buffer ? [] : [lockfileLocation],
|
450
506
|
{ timestamp: true },
|
451
|
-
(err,
|
507
|
+
(err, s) => {
|
452
508
|
if (err) return callback(err);
|
453
509
|
const lockfile = buffer
|
454
510
|
? Lockfile.parse(buffer.toString("utf-8"))
|
455
511
|
: new Lockfile();
|
456
512
|
lockfileCache = {
|
457
513
|
lockfile,
|
458
|
-
snapshot
|
514
|
+
snapshot: /** @type {Snapshot} */ (s)
|
459
515
|
};
|
460
516
|
callback(null, lockfile);
|
461
517
|
}
|
@@ -477,8 +533,10 @@ class HttpUriPlugin {
|
|
477
533
|
}
|
478
534
|
);
|
479
535
|
|
480
|
-
/** @
|
481
|
-
|
536
|
+
/** @typedef {Map<string, LockfileEntry | "ignore" | "no-cache">} LockfileUpdates */
|
537
|
+
|
538
|
+
/** @type {LockfileUpdates | undefined} */
|
539
|
+
let lockfileUpdates;
|
482
540
|
|
483
541
|
/**
|
484
542
|
* @param {Lockfile} lockfile lockfile instance
|
@@ -519,6 +577,13 @@ class HttpUriPlugin {
|
|
519
577
|
}
|
520
578
|
};
|
521
579
|
|
580
|
+
/**
|
581
|
+
* @param {Lockfile} lockfile lockfile
|
582
|
+
* @param {string} url url
|
583
|
+
* @param {ResolveContentResult} result result
|
584
|
+
* @param {function(Error | null, ResolveContentResult=): void} callback callback
|
585
|
+
* @returns {void}
|
586
|
+
*/
|
522
587
|
const storeResult = (lockfile, url, result, callback) => {
|
523
588
|
if (result.storeLock) {
|
524
589
|
storeLockEntry(lockfile, url, result.entry);
|
@@ -541,12 +606,16 @@ class HttpUriPlugin {
|
|
541
606
|
|
542
607
|
for (const { scheme, fetch } of schemes) {
|
543
608
|
/**
|
544
|
-
*
|
545
609
|
* @param {string} url URL
|
546
|
-
* @param {string} integrity integrity
|
547
|
-
* @param {function(
|
610
|
+
* @param {string | null} integrity integrity
|
611
|
+
* @param {function(Error | null, ResolveContentResult=): void} callback callback
|
548
612
|
*/
|
549
613
|
const resolveContent = (url, integrity, callback) => {
|
614
|
+
/**
|
615
|
+
* @param {Error | null} err error
|
616
|
+
* @param {TODO} result result result
|
617
|
+
* @returns {void}
|
618
|
+
*/
|
550
619
|
const handleResult = (err, result) => {
|
551
620
|
if (err) return callback(err);
|
552
621
|
if ("location" in result) {
|
@@ -555,41 +624,37 @@ class HttpUriPlugin {
|
|
555
624
|
integrity,
|
556
625
|
(err, innerResult) => {
|
557
626
|
if (err) return callback(err);
|
627
|
+
const { entry, content, storeLock } =
|
628
|
+
/** @type {ResolveContentResult} */ (innerResult);
|
558
629
|
callback(null, {
|
559
|
-
entry
|
560
|
-
content
|
561
|
-
storeLock:
|
630
|
+
entry,
|
631
|
+
content,
|
632
|
+
storeLock: storeLock && result.storeLock
|
562
633
|
});
|
563
634
|
}
|
564
635
|
);
|
565
|
-
} else {
|
566
|
-
if (
|
567
|
-
!result.fresh &&
|
568
|
-
integrity &&
|
569
|
-
result.entry.integrity !== integrity &&
|
570
|
-
!verifyIntegrity(result.content, integrity)
|
571
|
-
) {
|
572
|
-
return fetchContent.force(url, handleResult);
|
573
|
-
}
|
574
|
-
return callback(null, {
|
575
|
-
entry: result.entry,
|
576
|
-
content: result.content,
|
577
|
-
storeLock: result.storeLock
|
578
|
-
});
|
579
636
|
}
|
637
|
+
if (
|
638
|
+
!result.fresh &&
|
639
|
+
integrity &&
|
640
|
+
result.entry.integrity !== integrity &&
|
641
|
+
!verifyIntegrity(result.content, integrity)
|
642
|
+
) {
|
643
|
+
return fetchContent.force(url, handleResult);
|
644
|
+
}
|
645
|
+
return callback(null, {
|
646
|
+
entry: result.entry,
|
647
|
+
content: result.content,
|
648
|
+
storeLock: result.storeLock
|
649
|
+
});
|
580
650
|
};
|
581
651
|
fetchContent(url, handleResult);
|
582
652
|
};
|
583
653
|
|
584
|
-
/** @typedef {{ storeCache: boolean, storeLock: boolean, validUntil: number, etag: string | undefined, fresh: boolean }} FetchResultMeta */
|
585
|
-
/** @typedef {FetchResultMeta & { location: string }} RedirectFetchResult */
|
586
|
-
/** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
|
587
|
-
/** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
|
588
|
-
|
589
654
|
/**
|
590
655
|
* @param {string} url URL
|
591
|
-
* @param {FetchResult | RedirectFetchResult} cachedResult result from cache
|
592
|
-
* @param {function(
|
656
|
+
* @param {FetchResult | RedirectFetchResult | undefined} cachedResult result from cache
|
657
|
+
* @param {function(Error | null, FetchResult=): void} callback callback
|
593
658
|
* @returns {void}
|
594
659
|
*/
|
595
660
|
const fetchContentRaw = (url, cachedResult, callback) => {
|
@@ -600,14 +665,14 @@ class HttpUriPlugin {
|
|
600
665
|
headers: {
|
601
666
|
"accept-encoding": "gzip, deflate, br",
|
602
667
|
"user-agent": "webpack",
|
603
|
-
"if-none-match":
|
604
|
-
? cachedResult.etag || null
|
605
|
-
|
668
|
+
"if-none-match": /** @type {TODO} */ (
|
669
|
+
cachedResult ? cachedResult.etag || null : null
|
670
|
+
)
|
606
671
|
}
|
607
672
|
},
|
608
673
|
res => {
|
609
|
-
const etag = res.headers
|
610
|
-
const location = res.headers
|
674
|
+
const etag = res.headers.etag;
|
675
|
+
const location = res.headers.location;
|
611
676
|
const cacheControl = res.headers["cache-control"];
|
612
677
|
const { storeLock, storeCache, validUntil } = parseCacheControl(
|
613
678
|
cacheControl,
|
@@ -662,23 +727,21 @@ class HttpUriPlugin {
|
|
662
727
|
);
|
663
728
|
};
|
664
729
|
if (res.statusCode === 304) {
|
730
|
+
const result = /** @type {FetchResult} */ (cachedResult);
|
665
731
|
if (
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
732
|
+
result.validUntil < validUntil ||
|
733
|
+
result.storeLock !== storeLock ||
|
734
|
+
result.storeCache !== storeCache ||
|
735
|
+
result.etag !== etag
|
670
736
|
) {
|
671
|
-
return finishWith(
|
672
|
-
} else {
|
673
|
-
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
674
|
-
return callback(null, {
|
675
|
-
...cachedResult,
|
676
|
-
fresh: true
|
677
|
-
});
|
737
|
+
return finishWith(result);
|
678
738
|
}
|
739
|
+
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
740
|
+
return callback(null, { ...result, fresh: true });
|
679
741
|
}
|
680
742
|
if (
|
681
743
|
location &&
|
744
|
+
res.statusCode &&
|
682
745
|
res.statusCode >= 301 &&
|
683
746
|
res.statusCode <= 308
|
684
747
|
) {
|
@@ -695,22 +758,23 @@ class HttpUriPlugin {
|
|
695
758
|
cachedResult.etag !== etag
|
696
759
|
) {
|
697
760
|
return finishWith(result);
|
698
|
-
} else {
|
699
|
-
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
700
|
-
return callback(null, {
|
701
|
-
...result,
|
702
|
-
fresh: true,
|
703
|
-
storeLock,
|
704
|
-
storeCache,
|
705
|
-
validUntil,
|
706
|
-
etag
|
707
|
-
});
|
708
761
|
}
|
762
|
+
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
763
|
+
return callback(null, {
|
764
|
+
...result,
|
765
|
+
fresh: true,
|
766
|
+
storeLock,
|
767
|
+
storeCache,
|
768
|
+
validUntil,
|
769
|
+
etag
|
770
|
+
});
|
709
771
|
}
|
710
772
|
const contentType = res.headers["content-type"] || "";
|
773
|
+
/** @type {Buffer[]} */
|
711
774
|
const bufferArr = [];
|
712
775
|
|
713
776
|
const contentEncoding = res.headers["content-encoding"];
|
777
|
+
/** @type {Readable} */
|
714
778
|
let stream = res;
|
715
779
|
if (contentEncoding === "gzip") {
|
716
780
|
stream = stream.pipe(createGunzip());
|
@@ -762,9 +826,10 @@ class HttpUriPlugin {
|
|
762
826
|
const fetchContent = cachedWithKey(
|
763
827
|
/**
|
764
828
|
* @param {string} url URL
|
765
|
-
* @param {function(
|
829
|
+
* @param {function(Error | null, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback
|
766
830
|
* @returns {void}
|
767
|
-
*/
|
831
|
+
*/
|
832
|
+
(url, callback) => {
|
768
833
|
cache.get(url, null, (err, cachedResult) => {
|
769
834
|
if (err) return callback(err);
|
770
835
|
if (cachedResult) {
|
@@ -777,25 +842,32 @@ class HttpUriPlugin {
|
|
777
842
|
(url, callback) => fetchContentRaw(url, undefined, callback)
|
778
843
|
);
|
779
844
|
|
845
|
+
/**
|
846
|
+
* @param {string} uri uri
|
847
|
+
* @returns {boolean} true when allowed, otherwise false
|
848
|
+
*/
|
780
849
|
const isAllowed = uri => {
|
781
850
|
for (const allowed of allowedUris) {
|
782
851
|
if (typeof allowed === "string") {
|
783
852
|
if (uri.startsWith(allowed)) return true;
|
784
853
|
} else if (typeof allowed === "function") {
|
785
854
|
if (allowed(uri)) return true;
|
786
|
-
} else {
|
787
|
-
|
855
|
+
} else if (allowed.test(uri)) {
|
856
|
+
return true;
|
788
857
|
}
|
789
858
|
}
|
790
859
|
return false;
|
791
860
|
};
|
792
861
|
|
862
|
+
/** @typedef {{ entry: LockfileEntry, content: Buffer }} Info */
|
863
|
+
|
793
864
|
const getInfo = cachedWithKey(
|
794
865
|
/**
|
795
866
|
* @param {string} url the url
|
796
|
-
* @param {function(
|
867
|
+
* @param {function(Error | null, Info=): void} callback callback
|
797
868
|
* @returns {void}
|
798
869
|
*/
|
870
|
+
// eslint-disable-next-line no-loop-func
|
799
871
|
(url, callback) => {
|
800
872
|
if (!isAllowed(url)) {
|
801
873
|
return callback(
|
@@ -806,8 +878,9 @@ class HttpUriPlugin {
|
|
806
878
|
)
|
807
879
|
);
|
808
880
|
}
|
809
|
-
getLockfile((err,
|
881
|
+
getLockfile((err, _lockfile) => {
|
810
882
|
if (err) return callback(err);
|
883
|
+
const lockfile = /** @type {Lockfile} */ (_lockfile);
|
811
884
|
const entryOrString = lockfile.entries.get(url);
|
812
885
|
if (!entryOrString) {
|
813
886
|
if (frozen) {
|
@@ -819,14 +892,24 @@ class HttpUriPlugin {
|
|
819
892
|
}
|
820
893
|
resolveContent(url, null, (err, result) => {
|
821
894
|
if (err) return callback(err);
|
822
|
-
storeResult(
|
895
|
+
storeResult(
|
896
|
+
/** @type {Lockfile} */
|
897
|
+
(lockfile),
|
898
|
+
url,
|
899
|
+
/** @type {ResolveContentResult} */
|
900
|
+
(result),
|
901
|
+
callback
|
902
|
+
);
|
823
903
|
});
|
824
904
|
return;
|
825
905
|
}
|
826
906
|
if (typeof entryOrString === "string") {
|
827
907
|
const entryTag = entryOrString;
|
828
|
-
resolveContent(url, null, (err,
|
908
|
+
resolveContent(url, null, (err, _result) => {
|
829
909
|
if (err) return callback(err);
|
910
|
+
const result =
|
911
|
+
/** @type {ResolveContentResult} */
|
912
|
+
(_result);
|
830
913
|
if (!result.storeLock || entryTag === "ignore")
|
831
914
|
return callback(null, result);
|
832
915
|
if (frozen) {
|
@@ -850,8 +933,11 @@ Remove this line from the lockfile to force upgrading.`
|
|
850
933
|
return;
|
851
934
|
}
|
852
935
|
let entry = entryOrString;
|
936
|
+
/**
|
937
|
+
* @param {Buffer=} lockedContent locked content
|
938
|
+
*/
|
853
939
|
const doFetch = lockedContent => {
|
854
|
-
resolveContent(url, entry.integrity, (err,
|
940
|
+
resolveContent(url, entry.integrity, (err, _result) => {
|
855
941
|
if (err) {
|
856
942
|
if (lockedContent) {
|
857
943
|
logger.warn(
|
@@ -865,6 +951,9 @@ Remove this line from the lockfile to force upgrading.`
|
|
865
951
|
}
|
866
952
|
return callback(err);
|
867
953
|
}
|
954
|
+
const result =
|
955
|
+
/** @type {ResolveContentResult} */
|
956
|
+
(_result);
|
868
957
|
if (!result.storeLock) {
|
869
958
|
// When the lockfile entry should be no-cache
|
870
959
|
// we need to update the lockfile
|
@@ -919,12 +1008,16 @@ Remove this line from the lockfile to force upgrading.`
|
|
919
1008
|
const key = getCacheKey(entry.resolved);
|
920
1009
|
const filePath = join(intermediateFs, cacheLocation, key);
|
921
1010
|
fs.readFile(filePath, (err, result) => {
|
922
|
-
const content = /** @type {Buffer} */ (result);
|
923
1011
|
if (err) {
|
924
1012
|
if (err.code === "ENOENT") return doFetch();
|
925
1013
|
return callback(err);
|
926
1014
|
}
|
927
|
-
const
|
1015
|
+
const content = /** @type {Buffer} */ (result);
|
1016
|
+
/**
|
1017
|
+
* @param {Buffer | undefined} _result result
|
1018
|
+
* @returns {void}
|
1019
|
+
*/
|
1020
|
+
const continueWithCachedContent = _result => {
|
928
1021
|
if (!upgrade) {
|
929
1022
|
// When not in upgrade mode, we accept the result from the lockfile cache
|
930
1023
|
return callback(null, { entry, content });
|
@@ -932,6 +1025,7 @@ Remove this line from the lockfile to force upgrading.`
|
|
932
1025
|
return doFetch(content);
|
933
1026
|
};
|
934
1027
|
if (!verifyIntegrity(content, entry.integrity)) {
|
1028
|
+
/** @type {Buffer | undefined} */
|
935
1029
|
let contentWithChangedEol;
|
936
1030
|
let isEolChanged = false;
|
937
1031
|
try {
|
@@ -942,7 +1036,7 @@ Remove this line from the lockfile to force upgrading.`
|
|
942
1036
|
contentWithChangedEol,
|
943
1037
|
entry.integrity
|
944
1038
|
);
|
945
|
-
} catch (
|
1039
|
+
} catch (_err) {
|
946
1040
|
// ignore
|
947
1041
|
}
|
948
1042
|
if (isEolChanged) {
|
@@ -969,10 +1063,14 @@ This will avoid that the end of line sequence is changed by git on Windows.`;
|
|
969
1063
|
);
|
970
1064
|
intermediateFs.writeFile(
|
971
1065
|
filePath,
|
972
|
-
|
1066
|
+
/** @type {Buffer} */
|
1067
|
+
(contentWithChangedEol),
|
973
1068
|
err => {
|
974
1069
|
if (err) return callback(err);
|
975
|
-
continueWithCachedContent(
|
1070
|
+
continueWithCachedContent(
|
1071
|
+
/** @type {Buffer} */
|
1072
|
+
(contentWithChangedEol)
|
1073
|
+
);
|
976
1074
|
}
|
977
1075
|
);
|
978
1076
|
return;
|
@@ -994,15 +1092,14 @@ Lockfile corrupted (${
|
|
994
1092
|
Run build with un-frozen lockfile to automatically fix lockfile.`
|
995
1093
|
)
|
996
1094
|
);
|
997
|
-
} else {
|
998
|
-
// "fix" the lockfile entry to the correct integrity
|
999
|
-
// the content has priority over the integrity value
|
1000
|
-
entry = {
|
1001
|
-
...entry,
|
1002
|
-
integrity: computeIntegrity(content)
|
1003
|
-
};
|
1004
|
-
storeLockEntry(lockfile, url, entry);
|
1005
1095
|
}
|
1096
|
+
// "fix" the lockfile entry to the correct integrity
|
1097
|
+
// the content has priority over the integrity value
|
1098
|
+
entry = {
|
1099
|
+
...entry,
|
1100
|
+
integrity: computeIntegrity(content)
|
1101
|
+
};
|
1102
|
+
storeLockEntry(lockfile, url, entry);
|
1006
1103
|
}
|
1007
1104
|
continueWithCachedContent(result);
|
1008
1105
|
});
|
@@ -1013,9 +1110,15 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1013
1110
|
}
|
1014
1111
|
);
|
1015
1112
|
|
1113
|
+
/**
|
1114
|
+
* @param {URL} url url
|
1115
|
+
* @param {ResourceDataWithData} resourceData resource data
|
1116
|
+
* @param {function(Error | null, true | void): void} callback callback
|
1117
|
+
*/
|
1016
1118
|
const respondWithUrlModule = (url, resourceData, callback) => {
|
1017
|
-
getInfo(url.href, (err,
|
1119
|
+
getInfo(url.href, (err, _result) => {
|
1018
1120
|
if (err) return callback(err);
|
1121
|
+
const result = /** @type {Info} */ (_result);
|
1019
1122
|
resourceData.resource = url.href;
|
1020
1123
|
resourceData.path = url.origin + url.pathname;
|
1021
1124
|
resourceData.query = url.search;
|
@@ -1051,7 +1154,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1051
1154
|
return callback();
|
1052
1155
|
}
|
1053
1156
|
respondWithUrlModule(
|
1054
|
-
new URL(resourceData.resource, data.context
|
1157
|
+
new URL(resourceData.resource, `${data.context}/`),
|
1055
1158
|
resourceData,
|
1056
1159
|
callback
|
1057
1160
|
);
|
@@ -1059,13 +1162,15 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1059
1162
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
1060
1163
|
hooks.readResourceForScheme
|
1061
1164
|
.for(scheme)
|
1062
|
-
.tapAsync("HttpUriPlugin", (resource, module, callback) =>
|
1063
|
-
|
1165
|
+
.tapAsync("HttpUriPlugin", (resource, module, callback) =>
|
1166
|
+
getInfo(resource, (err, _result) => {
|
1064
1167
|
if (err) return callback(err);
|
1065
|
-
|
1168
|
+
const result = /** @type {Info} */ (_result);
|
1169
|
+
/** @type {BuildInfo} */
|
1170
|
+
(module.buildInfo).resourceIntegrity = result.entry.integrity;
|
1066
1171
|
callback(null, result.content);
|
1067
|
-
})
|
1068
|
-
|
1172
|
+
})
|
1173
|
+
);
|
1069
1174
|
hooks.needBuild.tapAsync(
|
1070
1175
|
"HttpUriPlugin",
|
1071
1176
|
(module, context, callback) => {
|
@@ -1073,11 +1178,13 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1073
1178
|
module.resource &&
|
1074
1179
|
module.resource.startsWith(`${scheme}://`)
|
1075
1180
|
) {
|
1076
|
-
getInfo(module.resource, (err,
|
1181
|
+
getInfo(module.resource, (err, _result) => {
|
1077
1182
|
if (err) return callback(err);
|
1183
|
+
const result = /** @type {Info} */ (_result);
|
1078
1184
|
if (
|
1079
1185
|
result.entry.integrity !==
|
1080
|
-
|
1186
|
+
/** @type {BuildInfo} */
|
1187
|
+
(module.buildInfo).resourceIntegrity
|
1081
1188
|
) {
|
1082
1189
|
return callback(null, true);
|
1083
1190
|
}
|
@@ -1103,7 +1210,9 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1103
1210
|
);
|
1104
1211
|
|
1105
1212
|
const writeDone = () => {
|
1106
|
-
const nextOperation =
|
1213
|
+
const nextOperation =
|
1214
|
+
/** @type {InProgressWriteItem[]} */
|
1215
|
+
(inProgressWrite).shift();
|
1107
1216
|
if (nextOperation) {
|
1108
1217
|
nextOperation();
|
1109
1218
|
} else {
|
@@ -1119,19 +1228,25 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1119
1228
|
const lockfile = buffer
|
1120
1229
|
? Lockfile.parse(buffer.toString("utf-8"))
|
1121
1230
|
: new Lockfile();
|
1122
|
-
for (const [key, value] of
|
1231
|
+
for (const [key, value] of /** @type {LockfileUpdates} */ (
|
1232
|
+
lockfileUpdates
|
1233
|
+
)) {
|
1123
1234
|
lockfile.entries.set(key, value);
|
1124
1235
|
}
|
1125
1236
|
intermediateFs.writeFile(tempFile, lockfile.toString(), err => {
|
1126
1237
|
if (err) {
|
1127
1238
|
writeDone();
|
1128
|
-
return
|
1239
|
+
return (
|
1240
|
+
/** @type {NonNullable<IntermediateFileSystem["unlink"]>} */
|
1241
|
+
(intermediateFs.unlink)(tempFile, () => callback(err))
|
1242
|
+
);
|
1129
1243
|
}
|
1130
1244
|
intermediateFs.rename(tempFile, lockfileLocation, err => {
|
1131
1245
|
if (err) {
|
1132
1246
|
writeDone();
|
1133
|
-
return
|
1134
|
-
|
1247
|
+
return (
|
1248
|
+
/** @type {NonNullable<IntermediateFileSystem["unlink"]>} */
|
1249
|
+
(intermediateFs.unlink)(tempFile, () => callback(err))
|
1135
1250
|
);
|
1136
1251
|
}
|
1137
1252
|
writeDone();
|