webpack 5.90.3 → 5.92.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1826 -639
@@ -9,10 +9,11 @@ const Template = require("../Template");
|
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
12
13
|
|
13
14
|
class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
14
15
|
/**
|
15
|
-
* @param {
|
16
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
16
17
|
*/
|
17
18
|
constructor(runtimeRequirements) {
|
18
19
|
super("trusted types policy");
|
@@ -14,7 +14,7 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
14
14
|
/** @typedef {import("../Compiler")} Compiler */
|
15
15
|
|
16
16
|
/**
|
17
|
-
* @typedef {
|
17
|
+
* @typedef {object} LoadScriptCompilationHooks
|
18
18
|
* @property {SyncWaterfallHook<[string, Chunk]>} createScript
|
19
19
|
*/
|
20
20
|
|
@@ -13,7 +13,7 @@ const StartupEntrypointRuntimeModule = require("./StartupEntrypointRuntimeModule
|
|
13
13
|
/** @typedef {import("../Compiler")} Compiler */
|
14
14
|
|
15
15
|
/**
|
16
|
-
* @typedef {
|
16
|
+
* @typedef {object} Options
|
17
17
|
* @property {ChunkLoadingType} chunkLoading
|
18
18
|
* @property {boolean=} asyncChunkLoading
|
19
19
|
*/
|
@@ -151,7 +151,7 @@ const parseCacheControl = (cacheControl, requestTime) => {
|
|
151
151
|
};
|
152
152
|
|
153
153
|
/**
|
154
|
-
* @typedef {
|
154
|
+
* @typedef {object} LockfileEntry
|
155
155
|
* @property {string} resolved
|
156
156
|
* @property {string} integrity
|
157
157
|
* @property {string} contentType
|
@@ -143,7 +143,7 @@ const identifyBigInt = n => {
|
|
143
143
|
class BinaryMiddleware extends SerializerMiddleware {
|
144
144
|
/**
|
145
145
|
* @param {DeserializedType} data data
|
146
|
-
* @param {
|
146
|
+
* @param {object} context context object
|
147
147
|
* @returns {SerializedType|Promise<SerializedType>} serialized data
|
148
148
|
*/
|
149
149
|
serialize(data, context) {
|
@@ -158,7 +158,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
158
158
|
|
159
159
|
/**
|
160
160
|
* @param {DeserializedType} data data
|
161
|
-
* @param {
|
161
|
+
* @param {object} context context object
|
162
162
|
* @param {{ leftOverBuffer: Buffer | null, allocationSize: number, increaseCounter: number }} allocationScope allocation scope
|
163
163
|
* @returns {SerializedType} serialized data
|
164
164
|
*/
|
@@ -629,7 +629,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
629
629
|
|
630
630
|
/**
|
631
631
|
* @param {SerializedType} data data
|
632
|
-
* @param {
|
632
|
+
* @param {object} context context object
|
633
633
|
* @returns {DeserializedType|Promise<DeserializedType>} deserialized data
|
634
634
|
*/
|
635
635
|
deserialize(data, context) {
|
@@ -653,7 +653,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
653
653
|
|
654
654
|
/**
|
655
655
|
* @param {SerializedType} data data
|
656
|
-
* @param {
|
656
|
+
* @param {object} context context object
|
657
657
|
* @returns {DeserializedType} deserialized data
|
658
658
|
*/
|
659
659
|
_deserialize(data, context) {
|
@@ -79,7 +79,7 @@ const readUInt64LE = Buffer.prototype.readBigUInt64LE
|
|
79
79
|
};
|
80
80
|
|
81
81
|
/**
|
82
|
-
* @typedef {
|
82
|
+
* @typedef {object} SerializeResult
|
83
83
|
* @property {string | false} name
|
84
84
|
* @property {number} size
|
85
85
|
* @property {Promise=} backgroundJob
|
@@ -427,7 +427,7 @@ class FileMiddleware extends SerializerMiddleware {
|
|
427
427
|
}
|
428
428
|
/**
|
429
429
|
* @param {DeserializedType} data data
|
430
|
-
* @param {
|
430
|
+
* @param {object} context context object
|
431
431
|
* @returns {SerializedType|Promise<SerializedType>} serialized data
|
432
432
|
*/
|
433
433
|
serialize(data, context) {
|
@@ -555,7 +555,7 @@ class FileMiddleware extends SerializerMiddleware {
|
|
555
555
|
|
556
556
|
/**
|
557
557
|
* @param {SerializedType} data data
|
558
|
-
* @param {
|
558
|
+
* @param {object} context context object
|
559
559
|
* @returns {DeserializedType|Promise<DeserializedType>} deserialized data
|
560
560
|
*/
|
561
561
|
deserialize(data, context) {
|
@@ -576,6 +576,7 @@ class FileMiddleware extends SerializerMiddleware {
|
|
576
576
|
/** @type {number | undefined} */
|
577
577
|
let currentBufferUsed;
|
578
578
|
const buf = [];
|
579
|
+
/** @type {import("zlib").Zlib & import("stream").Transform | undefined} */
|
579
580
|
let decompression;
|
580
581
|
if (file.endsWith(".gz")) {
|
581
582
|
decompression = createGunzip({
|
@@ -9,7 +9,7 @@
|
|
9
9
|
|
10
10
|
class NullPrototypeObjectSerializer {
|
11
11
|
/**
|
12
|
-
* @template {
|
12
|
+
* @template {object} T
|
13
13
|
* @param {T} obj null object
|
14
14
|
* @param {ObjectSerializerContext} context context
|
15
15
|
*/
|
@@ -25,7 +25,7 @@ class NullPrototypeObjectSerializer {
|
|
25
25
|
}
|
26
26
|
}
|
27
27
|
/**
|
28
|
-
* @template {
|
28
|
+
* @template {object} T
|
29
29
|
* @param {ObjectDeserializerContext} context context
|
30
30
|
* @returns {T} null object
|
31
31
|
*/
|
@@ -44,19 +44,21 @@ Technically any value can be used.
|
|
44
44
|
*/
|
45
45
|
|
46
46
|
/**
|
47
|
-
* @typedef {
|
47
|
+
* @typedef {object} ObjectSerializerContext
|
48
48
|
* @property {function(any): void} write
|
49
|
+
* @property {(function(any): void)=} writeLazy
|
50
|
+
* @property {(function(any, object=): (() => Promise<any> | any))=} writeSeparate
|
49
51
|
* @property {function(any): void} setCircularReference
|
50
52
|
*/
|
51
53
|
|
52
54
|
/**
|
53
|
-
* @typedef {
|
55
|
+
* @typedef {object} ObjectDeserializerContext
|
54
56
|
* @property {function(): any} read
|
55
57
|
* @property {function(any): void} setCircularReference
|
56
58
|
*/
|
57
59
|
|
58
60
|
/**
|
59
|
-
* @typedef {
|
61
|
+
* @typedef {object} ObjectSerializer
|
60
62
|
* @property {function(any, ObjectSerializerContext): void} serialize
|
61
63
|
* @property {function(ObjectDeserializerContext): any} deserialize
|
62
64
|
*/
|
@@ -136,6 +138,7 @@ jsTypes.set(TypeError, new ErrorObjectSerializer(TypeError));
|
|
136
138
|
// real Object and Array types to. These types may occur in the wild too, e. g. when
|
137
139
|
// using Structured Clone in postMessage.
|
138
140
|
if (exports.constructor !== Object) {
|
141
|
+
// eslint-disable-next-line jsdoc/check-types
|
139
142
|
const Obj = /** @type {typeof Object} */ (exports.constructor);
|
140
143
|
const Fn = /** @type {typeof Function} */ (Obj.constructor);
|
141
144
|
for (const [type, config] of Array.from(jsTypes)) {
|
@@ -287,7 +290,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
287
290
|
|
288
291
|
/**
|
289
292
|
* @param {DeserializedType} data data
|
290
|
-
* @param {
|
293
|
+
* @param {object} context context object
|
291
294
|
* @returns {SerializedType|Promise<SerializedType>} serialized data
|
292
295
|
*/
|
293
296
|
serialize(data, context) {
|
@@ -591,7 +594,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
591
594
|
|
592
595
|
/**
|
593
596
|
* @param {SerializedType} data data
|
594
|
-
* @param {
|
597
|
+
* @param {object} context context object
|
595
598
|
* @returns {DeserializedType|Promise<DeserializedType>} deserialized data
|
596
599
|
*/
|
597
600
|
deserialize(data, context) {
|
@@ -45,7 +45,7 @@ const getCachedKeys = (keys, cacheAssoc) => {
|
|
45
45
|
|
46
46
|
class PlainObjectSerializer {
|
47
47
|
/**
|
48
|
-
* @param {
|
48
|
+
* @param {object} obj plain object
|
49
49
|
* @param {ObjectSerializerContext} context context
|
50
50
|
*/
|
51
51
|
serialize(obj, context) {
|
@@ -72,7 +72,7 @@ class PlainObjectSerializer {
|
|
72
72
|
}
|
73
73
|
/**
|
74
74
|
* @param {ObjectDeserializerContext} context context
|
75
|
-
* @returns {
|
75
|
+
* @returns {object} plain object
|
76
76
|
*/
|
77
77
|
deserialize(context) {
|
78
78
|
const keys = context.read();
|
@@ -4,13 +4,27 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/**
|
8
|
+
* @template T, K
|
9
|
+
* @typedef {import("./SerializerMiddleware")<T, K>} SerializerMiddleware
|
10
|
+
*/
|
11
|
+
|
7
12
|
class Serializer {
|
13
|
+
/**
|
14
|
+
* @param {SerializerMiddleware<any, any>[]} middlewares serializer middlewares
|
15
|
+
* @param {TODO=} context context
|
16
|
+
*/
|
8
17
|
constructor(middlewares, context) {
|
9
18
|
this.serializeMiddlewares = middlewares.slice();
|
10
19
|
this.deserializeMiddlewares = middlewares.slice().reverse();
|
11
20
|
this.context = context;
|
12
21
|
}
|
13
22
|
|
23
|
+
/**
|
24
|
+
* @param {any} obj object
|
25
|
+
* @param {TODO} context content
|
26
|
+
* @returns {Promise<any>} result
|
27
|
+
*/
|
14
28
|
serialize(obj, context) {
|
15
29
|
const ctx = { ...context, ...this.context };
|
16
30
|
let current = obj;
|
@@ -28,6 +42,11 @@ class Serializer {
|
|
28
42
|
return current;
|
29
43
|
}
|
30
44
|
|
45
|
+
/**
|
46
|
+
* @param {any} value value
|
47
|
+
* @param {TODO} context context
|
48
|
+
* @returns {Promise<any>} result
|
49
|
+
*/
|
31
50
|
deserialize(value, context) {
|
32
51
|
const ctx = { ...context, ...this.context };
|
33
52
|
/** @type {any} */
|
@@ -18,7 +18,7 @@ class SerializerMiddleware {
|
|
18
18
|
/**
|
19
19
|
* @abstract
|
20
20
|
* @param {DeserializedType} data data
|
21
|
-
* @param {
|
21
|
+
* @param {object} context context object
|
22
22
|
* @returns {SerializedType|Promise<SerializedType>} serialized data
|
23
23
|
*/
|
24
24
|
serialize(data, context) {
|
@@ -30,7 +30,7 @@ class SerializerMiddleware {
|
|
30
30
|
/**
|
31
31
|
* @abstract
|
32
32
|
* @param {SerializedType} data data
|
33
|
-
* @param {
|
33
|
+
* @param {object} context context object
|
34
34
|
* @returns {DeserializedType|Promise<DeserializedType>} deserialized data
|
35
35
|
*/
|
36
36
|
deserialize(data, context) {
|
@@ -14,7 +14,7 @@ const SerializerMiddleware = require("./SerializerMiddleware");
|
|
14
14
|
class SingleItemMiddleware extends SerializerMiddleware {
|
15
15
|
/**
|
16
16
|
* @param {DeserializedType} data data
|
17
|
-
* @param {
|
17
|
+
* @param {object} context context object
|
18
18
|
* @returns {SerializedType|Promise<SerializedType>} serialized data
|
19
19
|
*/
|
20
20
|
serialize(data, context) {
|
@@ -23,7 +23,7 @@ class SingleItemMiddleware extends SerializerMiddleware {
|
|
23
23
|
|
24
24
|
/**
|
25
25
|
* @param {SerializedType} data data
|
26
|
-
* @param {
|
26
|
+
* @param {object} context context object
|
27
27
|
* @returns {DeserializedType|Promise<DeserializedType>} deserialized data
|
28
28
|
*/
|
29
29
|
deserialize(data, context) {
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
/** @typedef {undefined|null|number|string|boolean|Buffer|
|
7
|
+
/** @typedef {undefined | null | number | string | boolean | Buffer | object | (() => ComplexSerializableType[] | Promise<ComplexSerializableType[]>)} ComplexSerializableType */
|
8
8
|
|
9
9
|
/** @typedef {undefined|null|number|bigint|string|boolean|Buffer|(() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>)} PrimitiveSerializableType */
|
10
10
|
|
@@ -36,13 +36,13 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
|
|
36
36
|
/** @typedef {import("../util/semver").SemVerRange} SemVerRange */
|
37
37
|
|
38
38
|
/**
|
39
|
-
* @typedef {
|
39
|
+
* @typedef {object} ConsumeOptions
|
40
40
|
* @property {string=} import fallback request
|
41
41
|
* @property {string=} importResolved resolved fallback request
|
42
42
|
* @property {string} shareKey global share key
|
43
43
|
* @property {string} shareScope share scope
|
44
44
|
* @property {SemVerRange | false | undefined} requiredVersion version requirement
|
45
|
-
* @property {string} packageName package name to determine required version automatically
|
45
|
+
* @property {string=} packageName package name to determine required version automatically
|
46
46
|
* @property {boolean} strictVersion don't use shared version even if version isn't valid
|
47
47
|
* @property {boolean} singleton use single global version
|
48
48
|
* @property {boolean} eager include the fallback module in a sync way
|
@@ -117,7 +117,12 @@ class ConsumeSharedPlugin {
|
|
117
117
|
normalModuleFactory
|
118
118
|
);
|
119
119
|
|
120
|
-
|
120
|
+
/** @type {Map<string, ConsumeOptions>} */
|
121
|
+
let unresolvedConsumes;
|
122
|
+
/** @type {Map<string, ConsumeOptions>} */
|
123
|
+
let resolvedConsumes;
|
124
|
+
/** @type {Map<string, ConsumeOptions>} */
|
125
|
+
let prefixedConsumes;
|
121
126
|
const promise = resolveMatchedConfigs(compilation, this._consumes).then(
|
122
127
|
({ resolved, unresolved, prefixed }) => {
|
123
128
|
resolvedConsumes = resolved;
|
@@ -138,6 +143,9 @@ class ConsumeSharedPlugin {
|
|
138
143
|
* @returns {Promise<ConsumeSharedModule>} create module
|
139
144
|
*/
|
140
145
|
const createConsumeSharedModule = (context, request, config) => {
|
146
|
+
/**
|
147
|
+
* @param {string} details details
|
148
|
+
*/
|
141
149
|
const requiredVersionWarning = details => {
|
142
150
|
const error = new WebpackError(
|
143
151
|
`No required version specified and unable to automatically determine one. ${details}`
|
@@ -293,9 +301,15 @@ class ConsumeSharedPlugin {
|
|
293
301
|
) {
|
294
302
|
return Promise.resolve();
|
295
303
|
}
|
296
|
-
const options = resolvedConsumes.get(
|
304
|
+
const options = resolvedConsumes.get(
|
305
|
+
/** @type {string} */ (resource)
|
306
|
+
);
|
297
307
|
if (options !== undefined) {
|
298
|
-
return createConsumeSharedModule(
|
308
|
+
return createConsumeSharedModule(
|
309
|
+
context,
|
310
|
+
/** @type {string} */ (resource),
|
311
|
+
options
|
312
|
+
);
|
299
313
|
}
|
300
314
|
return Promise.resolve();
|
301
315
|
}
|
@@ -17,14 +17,16 @@ const {
|
|
17
17
|
|
18
18
|
/** @typedef {import("webpack-sources").Source} Source */
|
19
19
|
/** @typedef {import("../Chunk")} Chunk */
|
20
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
20
21
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
21
22
|
/** @typedef {import("../Compilation")} Compilation */
|
22
23
|
/** @typedef {import("../Module")} Module */
|
24
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
23
25
|
/** @typedef {import("./ConsumeSharedModule")} ConsumeSharedModule */
|
24
26
|
|
25
27
|
class ConsumeSharedRuntimeModule extends RuntimeModule {
|
26
28
|
/**
|
27
|
-
* @param {
|
29
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
28
30
|
*/
|
29
31
|
constructor(runtimeRequirements) {
|
30
32
|
super("consumes", RuntimeModule.STAGE_ATTACH);
|
@@ -38,6 +40,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
38
40
|
const compilation = /** @type {Compilation} */ (this.compilation);
|
39
41
|
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
40
42
|
const { runtimeTemplate, codeGenerationResults } = compilation;
|
43
|
+
/** @type {Record<ChunkId, (string | number)[]>} */
|
41
44
|
const chunkToModuleMapping = {};
|
42
45
|
/** @type {Map<string | number, Source>} */
|
43
46
|
const moduleIdToSourceMapping = new Map();
|
@@ -70,7 +73,11 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
70
73
|
"consume-shared"
|
71
74
|
);
|
72
75
|
if (!modules) continue;
|
73
|
-
addModules(
|
76
|
+
addModules(
|
77
|
+
modules,
|
78
|
+
chunk,
|
79
|
+
(chunkToModuleMapping[/** @type {ChunkId} */ (chunk.id)] = [])
|
80
|
+
);
|
74
81
|
}
|
75
82
|
for (const chunk of /** @type {Chunk} */ (
|
76
83
|
this.chunk
|
@@ -15,6 +15,7 @@ const ProvideSharedModuleFactory = require("./ProvideSharedModuleFactory");
|
|
15
15
|
/** @typedef {import("../../declarations/plugins/sharing/ProvideSharedPlugin").ProvideSharedPluginOptions} ProvideSharedPluginOptions */
|
16
16
|
/** @typedef {import("../Compilation")} Compilation */
|
17
17
|
/** @typedef {import("../Compiler")} Compiler */
|
18
|
+
/** @typedef {import("../NormalModuleFactory").NormalModuleCreateData} NormalModuleCreateData */
|
18
19
|
|
19
20
|
const validate = createSchemaValidation(
|
20
21
|
require("../../schemas/plugins/sharing/ProvideSharedPlugin.check.js"),
|
@@ -26,7 +27,7 @@ const validate = createSchemaValidation(
|
|
26
27
|
);
|
27
28
|
|
28
29
|
/**
|
29
|
-
* @typedef {
|
30
|
+
* @typedef {object} ProvideOptions
|
30
31
|
* @property {string} shareKey
|
31
32
|
* @property {string} shareScope
|
32
33
|
* @property {string | undefined | false} version
|
@@ -112,6 +113,12 @@ class ProvideSharedPlugin {
|
|
112
113
|
}
|
113
114
|
}
|
114
115
|
compilationData.set(compilation, resolvedProvideMap);
|
116
|
+
/**
|
117
|
+
* @param {string} key key
|
118
|
+
* @param {ProvideOptions} config config
|
119
|
+
* @param {NormalModuleCreateData["resource"]} resource resource
|
120
|
+
* @param {NormalModuleCreateData["resourceResolveData"]} resourceResolveData resource resolve data
|
121
|
+
*/
|
115
122
|
const provideSharedModule = (
|
116
123
|
key,
|
117
124
|
config,
|
@@ -151,7 +158,7 @@ class ProvideSharedPlugin {
|
|
151
158
|
normalModuleFactory.hooks.module.tap(
|
152
159
|
"ProvideSharedPlugin",
|
153
160
|
(module, { resource, resourceResolveData }, resolveData) => {
|
154
|
-
if (resolvedProvideMap.has(resource)) {
|
161
|
+
if (resolvedProvideMap.has(/** @type {string} */ (resource))) {
|
155
162
|
return module;
|
156
163
|
}
|
157
164
|
const { request } = resolveData;
|
@@ -161,7 +168,7 @@ class ProvideSharedPlugin {
|
|
161
168
|
provideSharedModule(
|
162
169
|
request,
|
163
170
|
config,
|
164
|
-
resource,
|
171
|
+
/** @type {string} */ (resource),
|
165
172
|
resourceResolveData
|
166
173
|
);
|
167
174
|
resolveData.cacheable = false;
|
@@ -171,12 +178,12 @@ class ProvideSharedPlugin {
|
|
171
178
|
if (request.startsWith(prefix)) {
|
172
179
|
const remainder = request.slice(prefix.length);
|
173
180
|
provideSharedModule(
|
174
|
-
resource,
|
181
|
+
/** @type {string} */ (resource),
|
175
182
|
{
|
176
183
|
...config,
|
177
184
|
shareKey: config.shareKey + remainder
|
178
185
|
},
|
179
|
-
resource,
|
186
|
+
/** @type {string} */ (resource),
|
180
187
|
resourceResolveData
|
181
188
|
);
|
182
189
|
resolveData.cacheable = false;
|
@@ -209,7 +216,7 @@ class ProvideSharedPlugin {
|
|
209
216
|
},
|
210
217
|
err => {
|
211
218
|
if (err) return reject(err);
|
212
|
-
resolve();
|
219
|
+
resolve(null);
|
213
220
|
}
|
214
221
|
);
|
215
222
|
})
|
@@ -13,7 +13,7 @@ const LazySet = require("../util/LazySet");
|
|
13
13
|
|
14
14
|
/**
|
15
15
|
* @template T
|
16
|
-
* @typedef {
|
16
|
+
* @typedef {object} MatchedConfigs
|
17
17
|
* @property {Map<string, T>} resolved
|
18
18
|
* @property {Map<string, T>} unresolved
|
19
19
|
* @property {Map<string, T>} prefixed
|
@@ -64,10 +64,10 @@ exports.resolveMatchedConfigs = (compilation, configs) => {
|
|
64
64
|
name: `shared module ${request}`
|
65
65
|
})
|
66
66
|
);
|
67
|
-
return resolve();
|
67
|
+
return resolve(null);
|
68
68
|
}
|
69
69
|
resolved.set(/** @type {string} */ (result), config);
|
70
|
-
resolve();
|
70
|
+
resolve(null);
|
71
71
|
}
|
72
72
|
);
|
73
73
|
});
|
package/lib/sharing/utils.js
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
const { join, dirname, readJson } = require("../util/fs");
|
9
9
|
|
10
10
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
11
|
+
/** @typedef {import("../util/fs").JsonObject} JsonObject */
|
12
|
+
/** @typedef {import("../util/fs").JsonPrimitive} JsonPrimitive */
|
11
13
|
|
12
14
|
// Extreme shorthand only for github. eg: foo/bar
|
13
15
|
const RE_URL_GITHUB_EXTREME_SHORT = /^[^/@:.\s][^/@:\s]*\/[^@:\s]*[^/@:\s]#\S+/;
|
@@ -373,9 +375,9 @@ exports.getDescriptionFile = getDescriptionFile;
|
|
373
375
|
|
374
376
|
/**
|
375
377
|
*
|
376
|
-
* @param {
|
378
|
+
* @param {JsonObject} data description file data i.e.: package.json
|
377
379
|
* @param {string} packageName name of the dependency
|
378
|
-
* @returns {string} normalized version
|
380
|
+
* @returns {string | undefined} normalized version
|
379
381
|
*/
|
380
382
|
const getRequiredVersionFromDescriptionFile = (data, packageName) => {
|
381
383
|
const dependencyTypes = [
|
@@ -386,12 +388,17 @@ const getRequiredVersionFromDescriptionFile = (data, packageName) => {
|
|
386
388
|
];
|
387
389
|
|
388
390
|
for (const dependencyType of dependencyTypes) {
|
391
|
+
const dependency = /** @type {JsonObject} */ (data[dependencyType]);
|
389
392
|
if (
|
390
|
-
|
391
|
-
typeof
|
392
|
-
packageName in
|
393
|
+
dependency &&
|
394
|
+
typeof dependency === "object" &&
|
395
|
+
packageName in dependency
|
393
396
|
) {
|
394
|
-
return normalizeVersion(
|
397
|
+
return normalizeVersion(
|
398
|
+
/** @type {Exclude<JsonPrimitive, null | boolean| number>} */ (
|
399
|
+
dependency[packageName]
|
400
|
+
)
|
401
|
+
);
|
395
402
|
}
|
396
403
|
}
|
397
404
|
};
|