webpack 5.99.6 → 5.99.8
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/lib/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +21 -15
- package/lib/Compiler.js +2 -1
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +1 -1
- package/lib/ContextModuleFactory.js +1 -2
- package/lib/ContextReplacementPlugin.js +7 -4
- package/lib/DefinePlugin.js +2 -2
- package/lib/DelegatedModule.js +18 -8
- package/lib/DelegatedModuleFactoryPlugin.js +9 -7
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllPlugin.js +5 -3
- package/lib/DllReferencePlugin.js +56 -60
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryOptionPlugin.js +3 -1
- package/lib/EntryPlugin.js +4 -2
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/EvalDevToolModulePlugin.js +9 -7
- package/lib/EvalSourceMapDevToolPlugin.js +138 -139
- package/lib/ExportsInfo.js +35 -16
- package/lib/ExternalModule.js +6 -5
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FileSystemInfo.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +5 -6
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +19 -12
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +13 -8
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +4 -2
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +72 -102
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +9 -8
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +3 -1
- package/lib/WebpackError.js +11 -3
- package/lib/WebpackOptionsApply.js +6 -7
- package/lib/asset/AssetGenerator.js +2 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/cache/IdleFileCachePlugin.js +11 -12
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
- package/lib/cache/ResolverCachePlugin.js +8 -6
- package/lib/cli.js +5 -1
- package/lib/config/defaults.js +10 -6
- package/lib/config/normalization.js +14 -8
- package/lib/container/ContainerReferencePlugin.js +24 -26
- package/lib/container/ModuleFederationPlugin.js +2 -1
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssModulesPlugin.js +8 -6
- package/lib/debug/ProfilingPlugin.js +18 -21
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +4 -2
- package/lib/ids/NamedModuleIdsPlugin.js +4 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
- package/lib/index.js +11 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -2
- package/lib/javascript/JavascriptParser.js +634 -656
- package/lib/json/JsonModulesPlugin.js +4 -4
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +60 -42
- package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- package/lib/node/nodeConsole.js +3 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +15 -16
- package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +15 -16
- package/lib/optimize/MinChunkSizePlugin.js +4 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
- package/lib/optimize/RealContentHashPlugin.js +4 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
- package/lib/optimize/RuntimeChunkPlugin.js +21 -23
- package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
- package/lib/optimize/SplitChunksPlugin.js +9 -7
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/rules/BasicEffectRulePlugin.js +1 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +4 -6
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/schemes/DataUriPlugin.js +5 -3
- package/lib/schemes/FileUriPlugin.js +5 -3
- package/lib/schemes/HttpUriPlugin.js +186 -188
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/ObjectMiddleware.js +13 -0
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
- package/lib/util/concatenate.js +4 -2
- package/lib/util/createHash.js +3 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +35 -30
- package/schemas/WebpackOptions.check.d.ts +1 -1
- package/schemas/WebpackOptions.check.js +2 -2
- package/schemas/WebpackOptions.json +267 -26
- package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/DllPlugin.check.d.ts +1 -1
- package/schemas/plugins/DllPlugin.check.js +1 -1
- package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +587 -207
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
- package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -16,6 +16,7 @@ const { mkdirp, dirname, join } = require("../util/fs");
|
|
16
16
|
const memoize = require("../util/memoize");
|
17
17
|
|
18
18
|
/** @typedef {import("http").IncomingMessage} IncomingMessage */
|
19
|
+
/** @typedef {import("http").OutgoingHttpHeaders} OutgoingHttpHeaders */
|
19
20
|
/** @typedef {import("http").RequestOptions} RequestOptions */
|
20
21
|
/** @typedef {import("net").Socket} Socket */
|
21
22
|
/** @typedef {import("stream").Readable} Readable */
|
@@ -147,7 +148,7 @@ const parseKeyValuePairs = str => {
|
|
147
148
|
/**
|
148
149
|
* @param {string | undefined} cacheControl Cache-Control header
|
149
150
|
* @param {number} requestTime timestamp of request
|
150
|
-
* @returns {{storeCache: boolean, storeLock: boolean, validUntil: number}} Logic for storing in cache and lockfile cache
|
151
|
+
* @returns {{ storeCache: boolean, storeLock: boolean, validUntil: number }} Logic for storing in cache and lockfile cache
|
151
152
|
*/
|
152
153
|
const parseCacheControl = (cacheControl, requestTime) => {
|
153
154
|
// When false resource is not stored in cache
|
@@ -190,7 +191,7 @@ const areLockfileEntriesEqual = (a, b) =>
|
|
190
191
|
|
191
192
|
/**
|
192
193
|
* @param {LockfileEntry} entry lockfile entry
|
193
|
-
* @returns {`resolved: ${string}, integrity: ${string}, contentType: ${
|
194
|
+
* @returns {`resolved: ${string}, integrity: ${string}, contentType: ${string}`} stringified entry
|
194
195
|
*/
|
195
196
|
const entryToString = entry =>
|
196
197
|
`resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
|
@@ -405,6 +406,8 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
405
406
|
/** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
|
406
407
|
/** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
|
407
408
|
|
409
|
+
const PLUGIN_NAME = "HttpUriPlugin";
|
410
|
+
|
408
411
|
class HttpUriPlugin {
|
409
412
|
/**
|
410
413
|
* @param {HttpUriPluginOptions} options options
|
@@ -440,14 +443,14 @@ class HttpUriPlugin {
|
|
440
443
|
/** @type {LockfileCache} */
|
441
444
|
let lockfileCache;
|
442
445
|
compiler.hooks.compilation.tap(
|
443
|
-
|
446
|
+
PLUGIN_NAME,
|
444
447
|
(compilation, { normalModuleFactory }) => {
|
445
448
|
const intermediateFs =
|
446
449
|
/** @type {IntermediateFileSystem} */
|
447
450
|
(compiler.intermediateFileSystem);
|
448
451
|
const fs = compilation.inputFileSystem;
|
449
|
-
const cache = compilation.getCache(
|
450
|
-
const logger = compilation.getLogger(
|
452
|
+
const cache = compilation.getCache(`webpack.${PLUGIN_NAME}`);
|
453
|
+
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
|
451
454
|
/** @type {string} */
|
452
455
|
const lockfileLocation =
|
453
456
|
this._lockfileLocation ||
|
@@ -634,11 +637,14 @@ class HttpUriPlugin {
|
|
634
637
|
const resolveContent = (url, integrity, callback) => {
|
635
638
|
/**
|
636
639
|
* @param {Error | null} err error
|
637
|
-
* @param {
|
640
|
+
* @param {FetchResult=} _result fetch result
|
638
641
|
* @returns {void}
|
639
642
|
*/
|
640
|
-
const handleResult = (err,
|
643
|
+
const handleResult = (err, _result) => {
|
641
644
|
if (err) return callback(err);
|
645
|
+
|
646
|
+
const result = /** @type {FetchResult} */ (_result);
|
647
|
+
|
642
648
|
if ("location" in result) {
|
643
649
|
return resolveContent(
|
644
650
|
result.location,
|
@@ -655,6 +661,7 @@ class HttpUriPlugin {
|
|
655
661
|
}
|
656
662
|
);
|
657
663
|
}
|
664
|
+
|
658
665
|
if (
|
659
666
|
!result.fresh &&
|
660
667
|
integrity &&
|
@@ -663,12 +670,14 @@ class HttpUriPlugin {
|
|
663
670
|
) {
|
664
671
|
return fetchContent.force(url, handleResult);
|
665
672
|
}
|
673
|
+
|
666
674
|
return callback(null, {
|
667
675
|
entry: result.entry,
|
668
676
|
content: result.content,
|
669
677
|
storeLock: result.storeLock
|
670
678
|
});
|
671
679
|
};
|
680
|
+
|
672
681
|
fetchContent(url, handleResult);
|
673
682
|
};
|
674
683
|
|
@@ -680,164 +689,162 @@ class HttpUriPlugin {
|
|
680
689
|
*/
|
681
690
|
const fetchContentRaw = (url, cachedResult, callback) => {
|
682
691
|
const requestTime = Date.now();
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
)} kB${!storeLock ? " no-cache" : ""}`
|
716
|
-
);
|
717
|
-
}
|
718
|
-
const result = {
|
719
|
-
...partialResult,
|
720
|
-
fresh: true,
|
721
|
-
storeLock,
|
722
|
-
storeCache,
|
723
|
-
validUntil,
|
724
|
-
etag
|
725
|
-
};
|
726
|
-
if (!storeCache) {
|
727
|
-
logger.log(
|
728
|
-
`${url} can't be stored in cache, due to Cache-Control header: ${cacheControl}`
|
729
|
-
);
|
730
|
-
return callback(null, result);
|
731
|
-
}
|
732
|
-
cache.store(
|
733
|
-
url,
|
734
|
-
null,
|
735
|
-
{
|
736
|
-
...result,
|
737
|
-
fresh: false
|
738
|
-
},
|
739
|
-
err => {
|
740
|
-
if (err) {
|
741
|
-
logger.warn(
|
742
|
-
`${url} can't be stored in cache: ${err.message}`
|
743
|
-
);
|
744
|
-
logger.debug(err.stack);
|
745
|
-
}
|
746
|
-
callback(null, result);
|
747
|
-
}
|
692
|
+
/** @type {OutgoingHttpHeaders} */
|
693
|
+
const headers = {
|
694
|
+
"accept-encoding": "gzip, deflate, br",
|
695
|
+
"user-agent": "webpack"
|
696
|
+
};
|
697
|
+
|
698
|
+
if (cachedResult && cachedResult.etag) {
|
699
|
+
headers["if-none-match"] = cachedResult.etag;
|
700
|
+
}
|
701
|
+
|
702
|
+
fetch(new URL(url), { headers }, res => {
|
703
|
+
const etag = res.headers.etag;
|
704
|
+
const location = res.headers.location;
|
705
|
+
const cacheControl = res.headers["cache-control"];
|
706
|
+
const { storeLock, storeCache, validUntil } = parseCacheControl(
|
707
|
+
cacheControl,
|
708
|
+
requestTime
|
709
|
+
);
|
710
|
+
/**
|
711
|
+
* @param {Partial<Pick<FetchResultMeta, "fresh">> & (Pick<RedirectFetchResult, "location"> | Pick<ContentFetchResult, "content" | "entry">)} partialResult result
|
712
|
+
* @returns {void}
|
713
|
+
*/
|
714
|
+
const finishWith = partialResult => {
|
715
|
+
if ("location" in partialResult) {
|
716
|
+
logger.debug(
|
717
|
+
`GET ${url} [${res.statusCode}] -> ${partialResult.location}`
|
718
|
+
);
|
719
|
+
} else {
|
720
|
+
logger.debug(
|
721
|
+
`GET ${url} [${res.statusCode}] ${Math.ceil(
|
722
|
+
partialResult.content.length / 1024
|
723
|
+
)} kB${!storeLock ? " no-cache" : ""}`
|
748
724
|
);
|
725
|
+
}
|
726
|
+
const result = {
|
727
|
+
...partialResult,
|
728
|
+
fresh: true,
|
729
|
+
storeLock,
|
730
|
+
storeCache,
|
731
|
+
validUntil,
|
732
|
+
etag
|
749
733
|
};
|
750
|
-
if (
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
result.storeCache !== storeCache ||
|
756
|
-
result.etag !== etag
|
757
|
-
) {
|
758
|
-
return finishWith(result);
|
759
|
-
}
|
760
|
-
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
761
|
-
return callback(null, { ...result, fresh: true });
|
734
|
+
if (!storeCache) {
|
735
|
+
logger.log(
|
736
|
+
`${url} can't be stored in cache, due to Cache-Control header: ${cacheControl}`
|
737
|
+
);
|
738
|
+
return callback(null, result);
|
762
739
|
}
|
740
|
+
cache.store(
|
741
|
+
url,
|
742
|
+
null,
|
743
|
+
{
|
744
|
+
...result,
|
745
|
+
fresh: false
|
746
|
+
},
|
747
|
+
err => {
|
748
|
+
if (err) {
|
749
|
+
logger.warn(
|
750
|
+
`${url} can't be stored in cache: ${err.message}`
|
751
|
+
);
|
752
|
+
logger.debug(err.stack);
|
753
|
+
}
|
754
|
+
callback(null, result);
|
755
|
+
}
|
756
|
+
);
|
757
|
+
};
|
758
|
+
if (res.statusCode === 304) {
|
759
|
+
const result = /** @type {FetchResult} */ (cachedResult);
|
763
760
|
if (
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
761
|
+
result.validUntil < validUntil ||
|
762
|
+
result.storeLock !== storeLock ||
|
763
|
+
result.storeCache !== storeCache ||
|
764
|
+
result.etag !== etag
|
768
765
|
) {
|
769
|
-
|
770
|
-
location: new URL(location, url).href
|
771
|
-
};
|
772
|
-
if (
|
773
|
-
!cachedResult ||
|
774
|
-
!("location" in cachedResult) ||
|
775
|
-
cachedResult.location !== result.location ||
|
776
|
-
cachedResult.validUntil < validUntil ||
|
777
|
-
cachedResult.storeLock !== storeLock ||
|
778
|
-
cachedResult.storeCache !== storeCache ||
|
779
|
-
cachedResult.etag !== etag
|
780
|
-
) {
|
781
|
-
return finishWith(result);
|
782
|
-
}
|
783
|
-
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
784
|
-
return callback(null, {
|
785
|
-
...result,
|
786
|
-
fresh: true,
|
787
|
-
storeLock,
|
788
|
-
storeCache,
|
789
|
-
validUntil,
|
790
|
-
etag
|
791
|
-
});
|
766
|
+
return finishWith(result);
|
792
767
|
}
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
}
|
805
|
-
|
768
|
+
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
769
|
+
return callback(null, { ...result, fresh: true });
|
770
|
+
}
|
771
|
+
if (
|
772
|
+
location &&
|
773
|
+
res.statusCode &&
|
774
|
+
res.statusCode >= 301 &&
|
775
|
+
res.statusCode <= 308
|
776
|
+
) {
|
777
|
+
const result = {
|
778
|
+
location: new URL(location, url).href
|
779
|
+
};
|
780
|
+
if (
|
781
|
+
!cachedResult ||
|
782
|
+
!("location" in cachedResult) ||
|
783
|
+
cachedResult.location !== result.location ||
|
784
|
+
cachedResult.validUntil < validUntil ||
|
785
|
+
cachedResult.storeLock !== storeLock ||
|
786
|
+
cachedResult.storeCache !== storeCache ||
|
787
|
+
cachedResult.etag !== etag
|
788
|
+
) {
|
789
|
+
return finishWith(result);
|
806
790
|
}
|
807
|
-
|
808
|
-
|
809
|
-
|
791
|
+
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
792
|
+
return callback(null, {
|
793
|
+
...result,
|
794
|
+
fresh: true,
|
795
|
+
storeLock,
|
796
|
+
storeCache,
|
797
|
+
validUntil,
|
798
|
+
etag
|
810
799
|
});
|
800
|
+
}
|
801
|
+
const contentType = res.headers["content-type"] || "";
|
802
|
+
/** @type {Buffer[]} */
|
803
|
+
const bufferArr = [];
|
811
804
|
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
805
|
+
const contentEncoding = res.headers["content-encoding"];
|
806
|
+
/** @type {Readable} */
|
807
|
+
let stream = res;
|
808
|
+
if (contentEncoding === "gzip") {
|
809
|
+
stream = stream.pipe(createGunzip());
|
810
|
+
} else if (contentEncoding === "br") {
|
811
|
+
stream = stream.pipe(createBrotliDecompress());
|
812
|
+
} else if (contentEncoding === "deflate") {
|
813
|
+
stream = stream.pipe(createInflate());
|
814
|
+
}
|
817
815
|
|
818
|
-
|
816
|
+
stream.on("data", chunk => {
|
817
|
+
bufferArr.push(chunk);
|
818
|
+
});
|
819
819
|
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
res.statusCode
|
826
|
-
}\n${content.toString("utf-8")}`
|
827
|
-
)
|
828
|
-
);
|
829
|
-
}
|
820
|
+
stream.on("end", () => {
|
821
|
+
if (!res.complete) {
|
822
|
+
logger.log(`GET ${url} [${res.statusCode}] (terminated)`);
|
823
|
+
return callback(new Error(`${url} request was terminated`));
|
824
|
+
}
|
830
825
|
|
831
|
-
|
832
|
-
const entry = { resolved: url, integrity, contentType };
|
826
|
+
const content = Buffer.concat(bufferArr);
|
833
827
|
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
828
|
+
if (res.statusCode !== 200) {
|
829
|
+
logger.log(`GET ${url} [${res.statusCode}]`);
|
830
|
+
return callback(
|
831
|
+
new Error(
|
832
|
+
`${url} request status code = ${
|
833
|
+
res.statusCode
|
834
|
+
}\n${content.toString("utf-8")}`
|
835
|
+
)
|
836
|
+
);
|
837
|
+
}
|
838
|
+
|
839
|
+
const integrity = computeIntegrity(content);
|
840
|
+
const entry = { resolved: url, integrity, contentType };
|
841
|
+
|
842
|
+
finishWith({
|
843
|
+
entry,
|
844
|
+
content
|
838
845
|
});
|
839
|
-
}
|
840
|
-
).on("error", err => {
|
846
|
+
});
|
847
|
+
}).on("error", err => {
|
841
848
|
logger.log(`GET ${url} (error)`);
|
842
849
|
err.message += `\nwhile fetching ${url}`;
|
843
850
|
callback(err);
|
@@ -847,7 +854,7 @@ class HttpUriPlugin {
|
|
847
854
|
const fetchContent = cachedWithKey(
|
848
855
|
/**
|
849
856
|
* @param {string} url URL
|
850
|
-
* @param {(err: Error | null, result?:
|
857
|
+
* @param {(err: Error | null, result?: FetchResult) => void} callback callback
|
851
858
|
* @returns {void}
|
852
859
|
*/
|
853
860
|
(url, callback) => {
|
@@ -1154,19 +1161,16 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1154
1161
|
};
|
1155
1162
|
normalModuleFactory.hooks.resolveForScheme
|
1156
1163
|
.for(scheme)
|
1157
|
-
.tapAsync(
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
);
|
1165
|
-
}
|
1166
|
-
);
|
1164
|
+
.tapAsync(PLUGIN_NAME, (resourceData, resolveData, callback) => {
|
1165
|
+
respondWithUrlModule(
|
1166
|
+
new URL(resourceData.resource),
|
1167
|
+
resourceData,
|
1168
|
+
callback
|
1169
|
+
);
|
1170
|
+
});
|
1167
1171
|
normalModuleFactory.hooks.resolveInScheme
|
1168
1172
|
.for(scheme)
|
1169
|
-
.tapAsync(
|
1173
|
+
.tapAsync(PLUGIN_NAME, (resourceData, data, callback) => {
|
1170
1174
|
// Only handle relative urls (./xxx, ../xxx, /xxx, //xxx)
|
1171
1175
|
if (
|
1172
1176
|
data.dependencyType !== "url" &&
|
@@ -1183,7 +1187,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1183
1187
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
1184
1188
|
hooks.readResourceForScheme
|
1185
1189
|
.for(scheme)
|
1186
|
-
.tapAsync(
|
1190
|
+
.tapAsync(PLUGIN_NAME, (resource, module, callback) =>
|
1187
1191
|
getInfo(resource, (err, _result) => {
|
1188
1192
|
if (err) return callback(err);
|
1189
1193
|
const result = /** @type {Info} */ (_result);
|
@@ -1192,33 +1196,27 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1192
1196
|
callback(null, result.content);
|
1193
1197
|
})
|
1194
1198
|
);
|
1195
|
-
hooks.needBuild.tapAsync(
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
}
|
1212
|
-
callback();
|
1213
|
-
});
|
1214
|
-
} else {
|
1215
|
-
return callback();
|
1216
|
-
}
|
1199
|
+
hooks.needBuild.tapAsync(PLUGIN_NAME, (module, context, callback) => {
|
1200
|
+
if (module.resource && module.resource.startsWith(`${scheme}://`)) {
|
1201
|
+
getInfo(module.resource, (err, _result) => {
|
1202
|
+
if (err) return callback(err);
|
1203
|
+
const result = /** @type {Info} */ (_result);
|
1204
|
+
if (
|
1205
|
+
result.entry.integrity !==
|
1206
|
+
/** @type {BuildInfo} */
|
1207
|
+
(module.buildInfo).resourceIntegrity
|
1208
|
+
) {
|
1209
|
+
return callback(null, true);
|
1210
|
+
}
|
1211
|
+
callback();
|
1212
|
+
});
|
1213
|
+
} else {
|
1214
|
+
return callback();
|
1217
1215
|
}
|
1218
|
-
);
|
1216
|
+
});
|
1219
1217
|
}
|
1220
1218
|
compilation.hooks.finishModules.tapAsync(
|
1221
|
-
|
1219
|
+
PLUGIN_NAME,
|
1222
1220
|
(modules, callback) => {
|
1223
1221
|
if (!lockfileUpdates) return callback();
|
1224
1222
|
const ext = extname(lockfileLocation);
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
10
|
+
/** @typedef {Error & { cause: unknown, errors: EXPECTED_ANY[] }} AggregateError */
|
11
|
+
|
12
|
+
class AggregateErrorSerializer {
|
13
|
+
/**
|
14
|
+
* @param {AggregateError} obj error
|
15
|
+
* @param {ObjectSerializerContext} context context
|
16
|
+
*/
|
17
|
+
serialize(obj, context) {
|
18
|
+
context.write(obj.errors);
|
19
|
+
context.write(obj.message);
|
20
|
+
context.write(obj.stack);
|
21
|
+
context.write(obj.cause);
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @param {ObjectDeserializerContext} context context
|
26
|
+
* @returns {AggregateError} error
|
27
|
+
*/
|
28
|
+
deserialize(context) {
|
29
|
+
const errors = context.read();
|
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
|
32
|
+
const err = new AggregateError(errors);
|
33
|
+
|
34
|
+
err.message = context.read();
|
35
|
+
err.stack = context.read();
|
36
|
+
err.cause = context.read();
|
37
|
+
|
38
|
+
return err;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
module.exports = AggregateErrorSerializer;
|
@@ -7,6 +7,8 @@
|
|
7
7
|
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
8
|
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
9
|
|
10
|
+
/** @typedef {Error & { cause?: unknown }} ErrorWithCause */
|
11
|
+
|
10
12
|
class ErrorObjectSerializer {
|
11
13
|
/**
|
12
14
|
* @param {ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor} Type error type
|
@@ -22,7 +24,10 @@ class ErrorObjectSerializer {
|
|
22
24
|
serialize(obj, context) {
|
23
25
|
context.write(obj.message);
|
24
26
|
context.write(obj.stack);
|
25
|
-
context.write(
|
27
|
+
context.write(
|
28
|
+
/** @type {ErrorWithCause} */
|
29
|
+
(obj).cause
|
30
|
+
);
|
26
31
|
}
|
27
32
|
|
28
33
|
/**
|
@@ -34,7 +39,7 @@ class ErrorObjectSerializer {
|
|
34
39
|
|
35
40
|
err.message = context.read();
|
36
41
|
err.stack = context.read();
|
37
|
-
/** @type {
|
42
|
+
/** @type {ErrorWithCause} */
|
38
43
|
(err).cause = context.read();
|
39
44
|
|
40
45
|
return err;
|
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
const { DEFAULTS } = require("../config/defaults");
|
8
8
|
const createHash = require("../util/createHash");
|
9
|
+
const AggregateErrorSerializer = require("./AggregateErrorSerializer");
|
9
10
|
const ArraySerializer = require("./ArraySerializer");
|
10
11
|
const DateObjectSerializer = require("./DateObjectSerializer");
|
11
12
|
const ErrorObjectSerializer = require("./ErrorObjectSerializer");
|
@@ -140,6 +141,7 @@ const loadedRequests = new Set();
|
|
140
141
|
const NOT_SERIALIZABLE = {};
|
141
142
|
|
142
143
|
const jsTypes = new Map();
|
144
|
+
|
143
145
|
jsTypes.set(Object, new PlainObjectSerializer());
|
144
146
|
jsTypes.set(Array, new ArraySerializer());
|
145
147
|
jsTypes.set(null, new NullPrototypeObjectSerializer());
|
@@ -154,6 +156,17 @@ jsTypes.set(ReferenceError, new ErrorObjectSerializer(ReferenceError));
|
|
154
156
|
jsTypes.set(SyntaxError, new ErrorObjectSerializer(SyntaxError));
|
155
157
|
jsTypes.set(TypeError, new ErrorObjectSerializer(TypeError));
|
156
158
|
|
159
|
+
// @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers
|
160
|
+
// eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
|
161
|
+
if (typeof AggregateError !== "undefined") {
|
162
|
+
jsTypes.set(
|
163
|
+
// @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers
|
164
|
+
// eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
|
165
|
+
AggregateError,
|
166
|
+
new AggregateErrorSerializer()
|
167
|
+
);
|
168
|
+
}
|
169
|
+
|
157
170
|
// If in a sandboxed environment (e.g. jest), this escapes the sandbox and registers
|
158
171
|
// real Object and Array types to. These types may occur in the wild too, e.g. when
|
159
172
|
// using Structured Clone in postMessage.
|
@@ -36,6 +36,8 @@ const validate = createSchemaValidation(
|
|
36
36
|
|
37
37
|
/** @typedef {Map<string, { config: ProvideOptions, version: string | undefined | false }>} ResolvedProvideMap */
|
38
38
|
|
39
|
+
const PLUGIN_NAME = "ProvideSharedPlugin";
|
40
|
+
|
39
41
|
class ProvideSharedPlugin {
|
40
42
|
/**
|
41
43
|
* @param {ProvideSharedPluginOptions} options options
|
@@ -83,7 +85,7 @@ class ProvideSharedPlugin {
|
|
83
85
|
const compilationData = new WeakMap();
|
84
86
|
|
85
87
|
compiler.hooks.compilation.tap(
|
86
|
-
|
88
|
+
PLUGIN_NAME,
|
87
89
|
(compilation, { normalModuleFactory }) => {
|
88
90
|
/** @type {ResolvedProvideMap} */
|
89
91
|
const resolvedProvideMap = new Map();
|
@@ -156,7 +158,7 @@ class ProvideSharedPlugin {
|
|
156
158
|
});
|
157
159
|
};
|
158
160
|
normalModuleFactory.hooks.module.tap(
|
159
|
-
|
161
|
+
PLUGIN_NAME,
|
160
162
|
(module, { resource, resourceResolveData }, resolveData) => {
|
161
163
|
if (resolvedProvideMap.has(/** @type {string} */ (resource))) {
|
162
164
|
return module;
|
@@ -194,7 +196,7 @@ class ProvideSharedPlugin {
|
|
194
196
|
);
|
195
197
|
}
|
196
198
|
);
|
197
|
-
compiler.hooks.finishMake.tapPromise(
|
199
|
+
compiler.hooks.finishMake.tapPromise(PLUGIN_NAME, compilation => {
|
198
200
|
const resolvedProvideMap = compilationData.get(compilation);
|
199
201
|
if (!resolvedProvideMap) return Promise.resolve();
|
200
202
|
return Promise.all(
|
@@ -225,7 +227,7 @@ class ProvideSharedPlugin {
|
|
225
227
|
});
|
226
228
|
|
227
229
|
compiler.hooks.compilation.tap(
|
228
|
-
|
230
|
+
PLUGIN_NAME,
|
229
231
|
(compilation, { normalModuleFactory }) => {
|
230
232
|
compilation.dependencyFactories.set(
|
231
233
|
ProvideForSharedDependency,
|