webpack 5.83.1 → 5.85.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 +2 -2
- package/lib/AsyncDependenciesBlock.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +4 -0
- package/lib/CacheFacade.js +4 -0
- package/lib/ChunkGroup.js +5 -1
- package/lib/CleanPlugin.js +30 -7
- package/lib/CompatibilityPlugin.js +4 -3
- package/lib/Compilation.js +3 -3
- package/lib/Compiler.js +1 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +11 -2
- package/lib/DllEntryPlugin.js +5 -0
- package/lib/DllModule.js +1 -1
- package/lib/DllModuleFactory.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/HookWebpackError.js +1 -1
- package/lib/IgnoreErrorModuleFactory.js +1 -1
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -9
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleTypeConstants.js +2 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +4 -2
- package/lib/NullFactory.js +1 -1
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/RuntimeModule.js +5 -5
- package/lib/RuntimePlugin.js +4 -0
- package/lib/RuntimeTemplate.js +7 -7
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SourceMapDevToolPlugin.js +9 -2
- package/lib/Template.js +3 -2
- package/lib/UseStrictPlugin.js +4 -0
- package/lib/WarnDeprecatedOptionPlugin.js +7 -0
- package/lib/WatchIgnorePlugin.js +4 -0
- package/lib/WebpackOptionsApply.js +2 -1
- package/lib/asset/AssetGenerator.js +7 -2
- package/lib/asset/AssetModulesPlugin.js +7 -1
- package/lib/asset/AssetParser.js +4 -1
- package/lib/asset/RawDataUrlModule.js +5 -3
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +7 -1
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +240 -73
- package/lib/config/normalization.js +104 -71
- package/lib/config/target.js +37 -10
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/FallbackDependency.js +7 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +5 -1
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/RemoteModule.js +4 -0
- package/lib/container/RemoteRuntimeModule.js +2 -1
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/css/CssParser.js +168 -73
- package/lib/debug/ProfilingPlugin.js +11 -0
- package/lib/dependencies/AMDDefineDependency.js +12 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
- package/lib/dependencies/AMDPlugin.js +7 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
- package/lib/dependencies/AMDRequireContextDependency.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
- package/lib/dependencies/AMDRequireDependency.js +8 -1
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/CachedConstDependency.js +6 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
- package/lib/dependencies/CommonJsExportsDependency.js +8 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
- package/lib/dependencies/CommonJsPlugin.js +28 -12
- package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
- package/lib/dependencies/CommonJsRequireDependency.js +7 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
- package/lib/dependencies/ConstDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
- package/lib/dependencies/CriticalDependencyWarning.js +3 -0
- package/lib/dependencies/CssImportDependency.js +2 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +12 -2
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyExports.js +3 -1
- package/lib/dependencies/HarmonyImportDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +18 -5
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +86 -6
- package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
- package/lib/dependencies/ImportContextDependency.js +6 -0
- package/lib/dependencies/ImportDependency.js +2 -1
- package/lib/dependencies/ImportEagerDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportParserPlugin.js +5 -0
- package/lib/dependencies/ImportPlugin.js +7 -0
- package/lib/dependencies/ImportWeakDependency.js +2 -1
- package/lib/dependencies/LocalModule.js +16 -0
- package/lib/dependencies/LocalModuleDependency.js +7 -0
- package/lib/dependencies/LocalModulesHelpers.js +18 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +2 -1
- package/lib/dependencies/PureExpressionDependency.js +2 -1
- package/lib/dependencies/RequireContextDependency.js +6 -0
- package/lib/dependencies/RequireContextPlugin.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
- package/lib/dependencies/RequireEnsureDependency.js +8 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +14 -0
- package/lib/dependencies/RequireHeaderDependency.js +5 -1
- package/lib/dependencies/RequireIncludeDependency.js +5 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireIncludePlugin.js +14 -0
- package/lib/dependencies/RequireResolveContextDependency.js +8 -0
- package/lib/dependencies/RequireResolveDependency.js +6 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
- package/lib/dependencies/SystemPlugin.js +10 -1
- package/lib/dependencies/URLDependency.js +3 -2
- package/lib/dependencies/URLPlugin.js +7 -5
- package/lib/dependencies/UnsupportedDependency.js +5 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
- package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
- package/lib/dependencies/WorkerDependency.js +2 -1
- package/lib/dependencies/WorkerPlugin.js +30 -3
- package/lib/dependencies/getFunctionExpression.js +7 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +15 -7
- package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +14 -9
- package/lib/hmr/LazyCompilationPlugin.js +1 -1
- package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
- package/lib/ids/HashedModuleIdsPlugin.js +8 -1
- package/lib/ids/IdHelpers.js +6 -0
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +14 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +11 -1
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +36 -31
- package/lib/javascript/JavascriptParser.js +586 -192
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +7 -5
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +4 -0
- package/lib/library/AssignLibraryPlugin.js +6 -4
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +6 -3
- package/lib/library/SystemLibraryPlugin.js +1 -0
- package/lib/library/UmdLibraryPlugin.js +4 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +6 -3
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -3
- package/lib/optimize/ConcatenatedModule.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
- package/lib/runtime/BaseUriRuntimeModule.js +5 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +5 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +4 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +8 -5
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +21 -0
- package/lib/serialization/DateObjectSerializer.js +15 -4
- package/lib/serialization/ErrorObjectSerializer.js +20 -8
- package/lib/serialization/FileMiddleware.js +17 -0
- package/lib/serialization/MapObjectSerializer.js +24 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
- package/lib/serialization/ObjectMiddleware.js +23 -0
- package/lib/serialization/PlainObjectSerializer.js +23 -12
- package/lib/serialization/RegExpObjectSerializer.js +16 -5
- package/lib/serialization/SetObjectSerializer.js +21 -6
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/serialization.js +10 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
- package/lib/wasm-sync/WebAssemblyParser.js +9 -2
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
- package/lib/web/FetchCompileWasmPlugin.js +19 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -2
- package/package.json +3 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/types.d.ts +655 -290
@@ -7,7 +7,12 @@
|
|
7
7
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
|
10
|
+
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
11
|
+
|
10
12
|
class PublicPathRuntimeModule extends RuntimeModule {
|
13
|
+
/**
|
14
|
+
* @param {OutputOptions["publicPath"]} publicPath public path
|
15
|
+
*/
|
11
16
|
constructor(publicPath) {
|
12
17
|
super("publicPath", RuntimeModule.STAGE_BASIC);
|
13
18
|
this.publicPath = publicPath;
|
@@ -8,9 +8,20 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const StartupChunkDependenciesRuntimeModule = require("./StartupChunkDependenciesRuntimeModule");
|
9
9
|
const StartupEntrypointRuntimeModule = require("./StartupEntrypointRuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../../declarations/WebpackOptions").ChunkLoadingType} ChunkLoadingType */
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
13
|
/** @typedef {import("../Compiler")} Compiler */
|
12
14
|
|
15
|
+
/**
|
16
|
+
* @typedef {Object} Options
|
17
|
+
* @property {ChunkLoadingType} chunkLoading
|
18
|
+
* @property {boolean=} asyncChunkLoading
|
19
|
+
*/
|
20
|
+
|
13
21
|
class StartupChunkDependenciesPlugin {
|
22
|
+
/**
|
23
|
+
* @param {Options} options options
|
24
|
+
*/
|
14
25
|
constructor(options) {
|
15
26
|
this.chunkLoading = options.chunkLoading;
|
16
27
|
this.asyncChunkLoading =
|
@@ -29,6 +40,10 @@ class StartupChunkDependenciesPlugin {
|
|
29
40
|
"StartupChunkDependenciesPlugin",
|
30
41
|
compilation => {
|
31
42
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
43
|
+
/**
|
44
|
+
* @param {Chunk} chunk chunk to check
|
45
|
+
* @returns {boolean} true, when the plugin is enabled for the chunk
|
46
|
+
*/
|
32
47
|
const isEnabledForChunk = chunk => {
|
33
48
|
const options = chunk.getEntryOptions();
|
34
49
|
const chunkLoading =
|
@@ -10,6 +10,9 @@ const RuntimeModule = require("../RuntimeModule");
|
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
12
|
class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
13
|
+
/**
|
14
|
+
* @param {boolean} asyncChunkLoading use async chunk loading
|
15
|
+
*/
|
13
16
|
constructor(asyncChunkLoading) {
|
14
17
|
super("startup chunk dependencies", RuntimeModule.STAGE_TRIGGER);
|
15
18
|
this.asyncChunkLoading = asyncChunkLoading;
|
@@ -45,7 +48,7 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
|
45
48
|
// using map is shorter for 3 or more chunks
|
46
49
|
`return Promise.all(${JSON.stringify(chunkIds)}.map(${
|
47
50
|
RuntimeGlobals.ensureChunk
|
48
|
-
},
|
51
|
+
}, ${RuntimeGlobals.require})).then(next);`
|
49
52
|
]
|
50
53
|
: [
|
51
54
|
// calling ensureChunk directly is shorter for 0 - 2 chunks
|
@@ -10,6 +10,9 @@ const RuntimeModule = require("../RuntimeModule");
|
|
10
10
|
/** @typedef {import("../MainTemplate")} MainTemplate */
|
11
11
|
|
12
12
|
class StartupEntrypointRuntimeModule extends RuntimeModule {
|
13
|
+
/**
|
14
|
+
* @param {boolean} asyncChunkLoading use async chunk loading
|
15
|
+
*/
|
13
16
|
constructor(asyncChunkLoading) {
|
14
17
|
super("startup entrypoint");
|
15
18
|
this.asyncChunkLoading = asyncChunkLoading;
|
@@ -27,19 +30,19 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
|
|
27
30
|
"// arguments: chunkIds, moduleId are deprecated",
|
28
31
|
"var moduleId = chunkIds;",
|
29
32
|
`if(!fn) chunkIds = result, fn = ${runtimeTemplate.returningFunction(
|
30
|
-
|
33
|
+
`${RuntimeGlobals.require}(${RuntimeGlobals.entryModuleId} = moduleId)`
|
31
34
|
)};`,
|
32
35
|
...(this.asyncChunkLoading
|
33
36
|
? [
|
34
|
-
`return Promise.all(chunkIds.map(${
|
35
|
-
RuntimeGlobals.
|
36
|
-
}
|
37
|
+
`return Promise.all(chunkIds.map(${RuntimeGlobals.ensureChunk}, ${
|
38
|
+
RuntimeGlobals.require
|
39
|
+
})).then(${runtimeTemplate.basicFunction("", [
|
37
40
|
"var r = fn();",
|
38
41
|
"return r === undefined ? result : r;"
|
39
42
|
])})`
|
40
43
|
]
|
41
44
|
: [
|
42
|
-
`chunkIds.map(${RuntimeGlobals.ensureChunk},
|
45
|
+
`chunkIds.map(${RuntimeGlobals.ensureChunk}, ${RuntimeGlobals.require})`,
|
43
46
|
"var r = fn();",
|
44
47
|
"return r === undefined ? result : r;"
|
45
48
|
])
|
@@ -4,16 +4,32 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class ArraySerializer {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
/**
|
12
|
+
* @template T
|
13
|
+
* @param {T[]} array array
|
14
|
+
* @param {ObjectSerializerContext} context context
|
15
|
+
*/
|
16
|
+
serialize(array, context) {
|
17
|
+
context.write(array.length);
|
18
|
+
for (const item of array) context.write(item);
|
11
19
|
}
|
12
|
-
|
13
|
-
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @template T
|
23
|
+
* @param {ObjectDeserializerContext} context context
|
24
|
+
* @returns {T[]} array
|
25
|
+
*/
|
26
|
+
deserialize(context) {
|
27
|
+
/** @type {number} */
|
28
|
+
const length = context.read();
|
29
|
+
/** @type {T[]} */
|
14
30
|
const array = [];
|
15
31
|
for (let i = 0; i < length; i++) {
|
16
|
-
array.push(read());
|
32
|
+
array.push(context.read());
|
17
33
|
}
|
18
34
|
return array;
|
19
35
|
}
|
@@ -101,6 +101,10 @@ const MEASURE_END_OPERATION = Symbol("MEASURE_END_OPERATION");
|
|
101
101
|
/** @typedef {typeof MEASURE_START_OPERATION} MEASURE_START_OPERATION_TYPE */
|
102
102
|
/** @typedef {typeof MEASURE_END_OPERATION} MEASURE_END_OPERATION_TYPE */
|
103
103
|
|
104
|
+
/**
|
105
|
+
* @param {number} n number
|
106
|
+
* @returns {0 | 1 | 2} type of number for serialization
|
107
|
+
*/
|
104
108
|
const identifyNumber = n => {
|
105
109
|
if (n === (n | 0)) {
|
106
110
|
if (n <= 127 && n >= -128) return 0;
|
@@ -203,17 +207,27 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
203
207
|
currentPosition = 0;
|
204
208
|
}
|
205
209
|
};
|
210
|
+
/**
|
211
|
+
* @param {number} byte byte
|
212
|
+
*/
|
206
213
|
const writeU8 = byte => {
|
207
214
|
currentBuffer.writeUInt8(byte, currentPosition++);
|
208
215
|
};
|
216
|
+
/**
|
217
|
+
* @param {number} ui32 ui32
|
218
|
+
*/
|
209
219
|
const writeU32 = ui32 => {
|
210
220
|
currentBuffer.writeUInt32LE(ui32, currentPosition);
|
211
221
|
currentPosition += 4;
|
212
222
|
};
|
223
|
+
/** @type {number[]} */
|
213
224
|
const measureStack = [];
|
214
225
|
const measureStart = () => {
|
215
226
|
measureStack.push(buffers.length, currentPosition);
|
216
227
|
};
|
228
|
+
/**
|
229
|
+
* @returns {number} size
|
230
|
+
*/
|
217
231
|
const measureEnd = () => {
|
218
232
|
const oldPos = measureStack.pop();
|
219
233
|
const buffersIndex = measureStack.pop();
|
@@ -258,6 +272,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
258
272
|
break;
|
259
273
|
}
|
260
274
|
}
|
275
|
+
/** @type {number[]} */
|
261
276
|
const lengths = [];
|
262
277
|
for (const item of serializedData) {
|
263
278
|
let last;
|
@@ -640,6 +655,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
640
655
|
checkOverflow();
|
641
656
|
return res;
|
642
657
|
};
|
658
|
+
/**
|
659
|
+
* @returns {number} U8
|
660
|
+
*/
|
643
661
|
const readU8 = () => {
|
644
662
|
ensureBuffer();
|
645
663
|
/**
|
@@ -653,6 +671,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
653
671
|
checkOverflow();
|
654
672
|
return byte;
|
655
673
|
};
|
674
|
+
/**
|
675
|
+
* @returns {number} U32
|
676
|
+
*/
|
656
677
|
const readU32 = () => {
|
657
678
|
return read(I32_SIZE).readUInt32LE(0);
|
658
679
|
};
|
@@ -4,12 +4,23 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class DateObjectSerializer {
|
8
|
-
|
9
|
-
|
11
|
+
/**
|
12
|
+
* @param {Date} obj date
|
13
|
+
* @param {ObjectSerializerContext} context context
|
14
|
+
*/
|
15
|
+
serialize(obj, context) {
|
16
|
+
context.write(obj.getTime());
|
10
17
|
}
|
11
|
-
|
12
|
-
|
18
|
+
/**
|
19
|
+
* @param {ObjectDeserializerContext} context context
|
20
|
+
* @returns {Date} date
|
21
|
+
*/
|
22
|
+
deserialize(context) {
|
23
|
+
return new Date(context.read());
|
13
24
|
}
|
14
25
|
}
|
15
26
|
|
@@ -4,21 +4,33 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class ErrorObjectSerializer {
|
11
|
+
/**
|
12
|
+
* @param {ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor} Type error type
|
13
|
+
*/
|
8
14
|
constructor(Type) {
|
9
15
|
this.Type = Type;
|
10
16
|
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
/**
|
18
|
+
* @param {Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError} obj error
|
19
|
+
* @param {ObjectSerializerContext} context context
|
20
|
+
*/
|
21
|
+
serialize(obj, context) {
|
22
|
+
context.write(obj.message);
|
23
|
+
context.write(obj.stack);
|
15
24
|
}
|
16
|
-
|
17
|
-
|
25
|
+
/**
|
26
|
+
* @param {ObjectDeserializerContext} context context
|
27
|
+
* @returns {Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError} error
|
28
|
+
*/
|
29
|
+
deserialize(context) {
|
18
30
|
const err = new this.Type();
|
19
31
|
|
20
|
-
err.message = read();
|
21
|
-
err.stack = read();
|
32
|
+
err.message = context.read();
|
33
|
+
err.stack = context.read();
|
22
34
|
|
23
35
|
return err;
|
24
36
|
}
|
@@ -181,6 +181,7 @@ const serialize = async (
|
|
181
181
|
SerializerMiddleware.setLazySerializedValue(lazy, buf);
|
182
182
|
return buf;
|
183
183
|
});
|
184
|
+
/** @type {number[]} */
|
184
185
|
const lengths = [];
|
185
186
|
for (const item of resolvedData) {
|
186
187
|
if (Array.isArray(item)) {
|
@@ -203,6 +204,7 @@ const serialize = async (
|
|
203
204
|
for (let i = 0; i < lengths.length; i++) {
|
204
205
|
header.writeInt32LE(lengths[i], 8 + i * 4);
|
205
206
|
}
|
207
|
+
/** @type {Buffer[]} */
|
206
208
|
const buf = [header];
|
207
209
|
for (const item of resolvedData) {
|
208
210
|
if (Array.isArray(item)) {
|
@@ -247,6 +249,9 @@ const deserialize = async (middleware, name, readFile) => {
|
|
247
249
|
contentItemLength = contentItem.length;
|
248
250
|
contentPosition = 0;
|
249
251
|
};
|
252
|
+
/**
|
253
|
+
* @param {number} n number of bytes to ensure
|
254
|
+
*/
|
250
255
|
const ensureData = n => {
|
251
256
|
if (contentPosition === contentItemLength) {
|
252
257
|
nextContent();
|
@@ -274,18 +279,28 @@ const deserialize = async (middleware, name, readFile) => {
|
|
274
279
|
contentPosition = 0;
|
275
280
|
}
|
276
281
|
};
|
282
|
+
/**
|
283
|
+
* @returns {number} value value
|
284
|
+
*/
|
277
285
|
const readUInt32LE = () => {
|
278
286
|
ensureData(4);
|
279
287
|
const value = contentItem.readUInt32LE(contentPosition);
|
280
288
|
contentPosition += 4;
|
281
289
|
return value;
|
282
290
|
};
|
291
|
+
/**
|
292
|
+
* @returns {number} value value
|
293
|
+
*/
|
283
294
|
const readInt32LE = () => {
|
284
295
|
ensureData(4);
|
285
296
|
const value = contentItem.readInt32LE(contentPosition);
|
286
297
|
contentPosition += 4;
|
287
298
|
return value;
|
288
299
|
};
|
300
|
+
/**
|
301
|
+
* @param {number} l length
|
302
|
+
* @returns {Buffer} buffer
|
303
|
+
*/
|
289
304
|
const readSlice = l => {
|
290
305
|
ensureData(l);
|
291
306
|
if (contentPosition === 0 && contentItemLength === l) {
|
@@ -556,7 +571,9 @@ class FileMiddleware extends SerializerMiddleware {
|
|
556
571
|
return;
|
557
572
|
}
|
558
573
|
let remaining = /** @type {number} */ (stats.size);
|
574
|
+
/** @type {Buffer | undefined} */
|
559
575
|
let currentBuffer;
|
576
|
+
/** @type {number | undefined} */
|
560
577
|
let currentBufferUsed;
|
561
578
|
const buf = [];
|
562
579
|
let decompression;
|
@@ -4,25 +4,41 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class MapObjectSerializer {
|
8
|
-
|
9
|
-
|
11
|
+
/**
|
12
|
+
* @template K, V
|
13
|
+
* @param {Map<K, V>} obj map
|
14
|
+
* @param {ObjectSerializerContext} context context
|
15
|
+
*/
|
16
|
+
serialize(obj, context) {
|
17
|
+
context.write(obj.size);
|
10
18
|
for (const key of obj.keys()) {
|
11
|
-
write(key);
|
19
|
+
context.write(key);
|
12
20
|
}
|
13
21
|
for (const value of obj.values()) {
|
14
|
-
write(value);
|
22
|
+
context.write(value);
|
15
23
|
}
|
16
24
|
}
|
17
|
-
|
18
|
-
|
25
|
+
/**
|
26
|
+
* @template K, V
|
27
|
+
* @param {ObjectDeserializerContext} context context
|
28
|
+
* @returns {Map<K, V>} map
|
29
|
+
*/
|
30
|
+
deserialize(context) {
|
31
|
+
/** @type {number} */
|
32
|
+
let size = context.read();
|
33
|
+
/** @type {Map<K, V>} */
|
19
34
|
const map = new Map();
|
35
|
+
/** @type {K[]} */
|
20
36
|
const keys = [];
|
21
37
|
for (let i = 0; i < size; i++) {
|
22
|
-
keys.push(read());
|
38
|
+
keys.push(context.read());
|
23
39
|
}
|
24
40
|
for (let i = 0; i < size; i++) {
|
25
|
-
map.set(keys[i], read());
|
41
|
+
map.set(keys[i], context.read());
|
26
42
|
}
|
27
43
|
return map;
|
28
44
|
}
|
@@ -4,27 +4,44 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class NullPrototypeObjectSerializer {
|
8
|
-
|
11
|
+
/**
|
12
|
+
* @template {Object} T
|
13
|
+
* @param {T} obj null object
|
14
|
+
* @param {ObjectSerializerContext} context context
|
15
|
+
*/
|
16
|
+
serialize(obj, context) {
|
17
|
+
/** @type {string[]} */
|
9
18
|
const keys = Object.keys(obj);
|
10
19
|
for (const key of keys) {
|
11
|
-
write(key);
|
20
|
+
context.write(key);
|
12
21
|
}
|
13
|
-
write(null);
|
22
|
+
context.write(null);
|
14
23
|
for (const key of keys) {
|
15
|
-
write(obj[key]);
|
24
|
+
context.write(obj[key]);
|
16
25
|
}
|
17
26
|
}
|
18
|
-
|
27
|
+
/**
|
28
|
+
* @template {Object} T
|
29
|
+
* @param {ObjectDeserializerContext} context context
|
30
|
+
* @returns {T} null object
|
31
|
+
*/
|
32
|
+
deserialize(context) {
|
33
|
+
/** @type {T} */
|
19
34
|
const obj = Object.create(null);
|
35
|
+
/** @type {string[]} */
|
20
36
|
const keys = [];
|
21
|
-
|
37
|
+
/** @type {string | null} */
|
38
|
+
let key = context.read();
|
22
39
|
while (key !== null) {
|
23
40
|
keys.push(key);
|
24
|
-
key = read();
|
41
|
+
key = context.read();
|
25
42
|
}
|
26
43
|
for (const key of keys) {
|
27
|
-
obj[key] = read();
|
44
|
+
obj[key] = context.read();
|
28
45
|
}
|
29
46
|
return obj;
|
30
47
|
}
|
@@ -61,6 +61,11 @@ Technically any value can be used.
|
|
61
61
|
* @property {function(ObjectDeserializerContext): any} deserialize
|
62
62
|
*/
|
63
63
|
|
64
|
+
/**
|
65
|
+
* @template T
|
66
|
+
* @param {Set<T>} set set
|
67
|
+
* @param {number} size count of items to keep
|
68
|
+
*/
|
64
69
|
const setSetSize = (set, size) => {
|
65
70
|
let i = 0;
|
66
71
|
for (const item of set) {
|
@@ -70,6 +75,11 @@ const setSetSize = (set, size) => {
|
|
70
75
|
}
|
71
76
|
};
|
72
77
|
|
78
|
+
/**
|
79
|
+
* @template K, X
|
80
|
+
* @param {Map<K, X>} map map
|
81
|
+
* @param {number} size count of items to keep
|
82
|
+
*/
|
73
83
|
const setMapSize = (map, size) => {
|
74
84
|
let i = 0;
|
75
85
|
for (const item of map.keys()) {
|
@@ -97,9 +107,12 @@ const ESCAPE_UNDEFINED = false;
|
|
97
107
|
|
98
108
|
const CURRENT_VERSION = 2;
|
99
109
|
|
110
|
+
/** @type {Map<Constructor, { request?: string, name?: string | number , serializer?: ObjectSerializer }>} */
|
100
111
|
const serializers = new Map();
|
112
|
+
/** @type {Map<string | number, ObjectSerializer>} */
|
101
113
|
const serializerInversed = new Map();
|
102
114
|
|
115
|
+
/** @type {Set<string>} */
|
103
116
|
const loadedRequests = new Set();
|
104
117
|
|
105
118
|
const NOT_SERIALIZABLE = {};
|
@@ -242,6 +255,11 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
242
255
|
return config;
|
243
256
|
}
|
244
257
|
|
258
|
+
/**
|
259
|
+
* @param {string} request request
|
260
|
+
* @param {TODO} name name
|
261
|
+
* @returns {ObjectSerializer} serializer
|
262
|
+
*/
|
245
263
|
static getDeserializerFor(request, name) {
|
246
264
|
const key = request + "/" + name;
|
247
265
|
const serializer = serializerInversed.get(key);
|
@@ -253,6 +271,11 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
253
271
|
return serializer;
|
254
272
|
}
|
255
273
|
|
274
|
+
/**
|
275
|
+
* @param {string} request request
|
276
|
+
* @param {TODO} name name
|
277
|
+
* @returns {ObjectSerializer} serializer
|
278
|
+
*/
|
256
279
|
static _getDeserializerForWithoutError(request, name) {
|
257
280
|
const key = request + "/" + name;
|
258
281
|
const serializer = serializerInversed.get(key);
|
@@ -4,6 +4,9 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
const cache = new WeakMap();
|
8
11
|
|
9
12
|
class ObjectStructure {
|
@@ -41,37 +44,45 @@ const getCachedKeys = (keys, cacheAssoc) => {
|
|
41
44
|
};
|
42
45
|
|
43
46
|
class PlainObjectSerializer {
|
44
|
-
|
47
|
+
/**
|
48
|
+
* @param {Object} obj plain object
|
49
|
+
* @param {ObjectSerializerContext} context context
|
50
|
+
*/
|
51
|
+
serialize(obj, context) {
|
45
52
|
const keys = Object.keys(obj);
|
46
53
|
if (keys.length > 128) {
|
47
54
|
// Objects with so many keys are unlikely to share structure
|
48
55
|
// with other objects
|
49
|
-
write(keys);
|
56
|
+
context.write(keys);
|
50
57
|
for (const key of keys) {
|
51
|
-
write(obj[key]);
|
58
|
+
context.write(obj[key]);
|
52
59
|
}
|
53
60
|
} else if (keys.length > 1) {
|
54
|
-
write(getCachedKeys(keys, write));
|
61
|
+
context.write(getCachedKeys(keys, context.write));
|
55
62
|
for (const key of keys) {
|
56
|
-
write(obj[key]);
|
63
|
+
context.write(obj[key]);
|
57
64
|
}
|
58
65
|
} else if (keys.length === 1) {
|
59
66
|
const key = keys[0];
|
60
|
-
write(key);
|
61
|
-
write(obj[key]);
|
67
|
+
context.write(key);
|
68
|
+
context.write(obj[key]);
|
62
69
|
} else {
|
63
|
-
write(null);
|
70
|
+
context.write(null);
|
64
71
|
}
|
65
72
|
}
|
66
|
-
|
67
|
-
|
73
|
+
/**
|
74
|
+
* @param {ObjectDeserializerContext} context context
|
75
|
+
* @returns {Object} plain object
|
76
|
+
*/
|
77
|
+
deserialize(context) {
|
78
|
+
const keys = context.read();
|
68
79
|
const obj = {};
|
69
80
|
if (Array.isArray(keys)) {
|
70
81
|
for (const key of keys) {
|
71
|
-
obj[key] = read();
|
82
|
+
obj[key] = context.read();
|
72
83
|
}
|
73
84
|
} else if (keys !== null) {
|
74
|
-
obj[keys] = read();
|
85
|
+
obj[keys] = context.read();
|
75
86
|
}
|
76
87
|
return obj;
|
77
88
|
}
|
@@ -4,13 +4,24 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class RegExpObjectSerializer {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
/**
|
12
|
+
* @param {RegExp} obj regexp
|
13
|
+
* @param {ObjectSerializerContext} context context
|
14
|
+
*/
|
15
|
+
serialize(obj, context) {
|
16
|
+
context.write(obj.source);
|
17
|
+
context.write(obj.flags);
|
11
18
|
}
|
12
|
-
|
13
|
-
|
19
|
+
/**
|
20
|
+
* @param {ObjectDeserializerContext} context context
|
21
|
+
* @returns {RegExp} regexp
|
22
|
+
*/
|
23
|
+
deserialize(context) {
|
24
|
+
return new RegExp(context.read(), context.read());
|
14
25
|
}
|
15
26
|
}
|
16
27
|
|
@@ -4,18 +4,33 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class SetObjectSerializer {
|
8
|
-
|
9
|
-
|
11
|
+
/**
|
12
|
+
* @template T
|
13
|
+
* @param {Set<T>} obj set
|
14
|
+
* @param {ObjectSerializerContext} context context
|
15
|
+
*/
|
16
|
+
serialize(obj, context) {
|
17
|
+
context.write(obj.size);
|
10
18
|
for (const value of obj) {
|
11
|
-
write(value);
|
19
|
+
context.write(value);
|
12
20
|
}
|
13
21
|
}
|
14
|
-
|
15
|
-
|
22
|
+
/**
|
23
|
+
* @template T
|
24
|
+
* @param {ObjectDeserializerContext} context context
|
25
|
+
* @returns {Set<T>} date
|
26
|
+
*/
|
27
|
+
deserialize(context) {
|
28
|
+
/** @type {number} */
|
29
|
+
let size = context.read();
|
30
|
+
/** @type {Set<T>} */
|
16
31
|
const set = new Set();
|
17
32
|
for (let i = 0; i < size; i++) {
|
18
|
-
set.add(read());
|
33
|
+
set.add(context.read());
|
19
34
|
}
|
20
35
|
return set;
|
21
36
|
}
|
@@ -15,7 +15,7 @@ const ProvideSharedModule = require("./ProvideSharedModule");
|
|
15
15
|
class ProvideSharedModuleFactory extends ModuleFactory {
|
16
16
|
/**
|
17
17
|
* @param {ModuleFactoryCreateData} data data object
|
18
|
-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
|
18
|
+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
|
19
19
|
* @returns {void}
|
20
20
|
*/
|
21
21
|
create(data, callback) {
|
@@ -100,7 +100,7 @@ class ShareRuntimeModule extends RuntimeModule {
|
|
100
100
|
)};`,
|
101
101
|
"try {",
|
102
102
|
Template.indent([
|
103
|
-
|
103
|
+
`var module = ${RuntimeGlobals.require}(id);`,
|
104
104
|
"if(!module) return;",
|
105
105
|
`var initFn = ${runtimeTemplate.returningFunction(
|
106
106
|
`module && module.init && module.init(${RuntimeGlobals.shareScopeMap}[name], initScope)`,
|
package/lib/util/createHash.js
CHANGED
@@ -132,7 +132,7 @@ let BatchedHash = undefined;
|
|
132
132
|
|
133
133
|
/**
|
134
134
|
* Creates a hash by name or function
|
135
|
-
* @param {string | typeof Hash} algorithm the algorithm name or a constructor creating a hash
|
135
|
+
* @param {string | typeof Hash | undefined} algorithm the algorithm name or a constructor creating a hash
|
136
136
|
* @returns {Hash} the hash
|
137
137
|
*/
|
138
138
|
module.exports = algorithm => {
|