webpack 5.98.0 → 5.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +326 -152
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +40 -17
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +13 -13
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +50 -8
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +93 -26
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssModulesPlugin.js +30 -5
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +24 -8
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +51 -31
- package/lib/javascript/JavascriptParser.js +272 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -2
- package/lib/json/JsonParser.js +8 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +87 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -7,9 +7,12 @@
|
|
7
7
|
|
8
8
|
const util = require("util");
|
9
9
|
|
10
|
+
/** @typedef {import("../../declarations/WebpackOptions").Falsy} Falsy */
|
10
11
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetLoader} RuleSetLoader */
|
11
12
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */
|
12
13
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
14
|
+
/** @typedef {import("../../declarations/WebpackOptions").RuleSetUse} RuleSetUse */
|
15
|
+
/** @typedef {import("../../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
|
13
16
|
/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
|
14
17
|
/** @typedef {import("./RuleSetCompiler").Effect} Effect */
|
15
18
|
|
@@ -43,7 +46,7 @@ class UseEffectRulePlugin {
|
|
43
46
|
conflictWith("loader", "use");
|
44
47
|
conflictWith("options", "use");
|
45
48
|
|
46
|
-
const use = rule.use;
|
49
|
+
const use = /** @type {RuleSetUse} */ (rule.use);
|
47
50
|
const enforce = rule.enforce;
|
48
51
|
|
49
52
|
const type = enforce ? `use-${enforce}` : "use";
|
@@ -51,12 +54,17 @@ class UseEffectRulePlugin {
|
|
51
54
|
/**
|
52
55
|
* @param {string} path options path
|
53
56
|
* @param {string} defaultIdent default ident when none is provided
|
54
|
-
* @param {
|
55
|
-
* @returns {Effect|
|
57
|
+
* @param {RuleSetUseItem} item user provided use value
|
58
|
+
* @returns {Effect | ((value: TODO) => Effect[])} effect
|
56
59
|
*/
|
57
60
|
const useToEffect = (path, defaultIdent, item) => {
|
58
61
|
if (typeof item === "function") {
|
59
|
-
return data =>
|
62
|
+
return data =>
|
63
|
+
useToEffectsWithoutIdent(
|
64
|
+
path,
|
65
|
+
/** @type {RuleSetUseItem | RuleSetUseItem[]} */
|
66
|
+
(item(data))
|
67
|
+
);
|
60
68
|
}
|
61
69
|
return useToEffectRaw(path, defaultIdent, item);
|
62
70
|
};
|
@@ -64,7 +72,7 @@ class UseEffectRulePlugin {
|
|
64
72
|
/**
|
65
73
|
* @param {string} path options path
|
66
74
|
* @param {string} defaultIdent default ident when none is provided
|
67
|
-
* @param {
|
75
|
+
* @param {Exclude<NonNullable<RuleSetUseItem>, EXPECTED_FUNCTION>} item user provided use value
|
68
76
|
* @returns {Effect} effect
|
69
77
|
*/
|
70
78
|
const useToEffectRaw = (path, defaultIdent, item) => {
|
@@ -104,33 +112,50 @@ class UseEffectRulePlugin {
|
|
104
112
|
|
105
113
|
/**
|
106
114
|
* @param {string} path options path
|
107
|
-
* @param {
|
115
|
+
* @param {RuleSetUseItem | (Falsy | RuleSetUseItem)[]} items user provided use value
|
108
116
|
* @returns {Effect[]} effects
|
109
117
|
*/
|
110
118
|
const useToEffectsWithoutIdent = (path, items) => {
|
111
119
|
if (Array.isArray(items)) {
|
112
|
-
return items
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
120
|
+
return items.filter(Boolean).map((item, idx) =>
|
121
|
+
useToEffectRaw(
|
122
|
+
`${path}[${idx}]`,
|
123
|
+
"[[missing ident]]",
|
124
|
+
/** @type {Exclude<RuleSetUseItem, EXPECTED_FUNCTION>} */
|
125
|
+
(item)
|
126
|
+
)
|
127
|
+
);
|
117
128
|
}
|
118
|
-
return [
|
129
|
+
return [
|
130
|
+
useToEffectRaw(
|
131
|
+
path,
|
132
|
+
"[[missing ident]]",
|
133
|
+
/** @type {Exclude<RuleSetUseItem, EXPECTED_FUNCTION>} */
|
134
|
+
(items)
|
135
|
+
)
|
136
|
+
];
|
119
137
|
};
|
120
138
|
|
121
139
|
/**
|
122
140
|
* @param {string} path current path
|
123
|
-
* @param {
|
124
|
-
* @returns {(Effect|
|
141
|
+
* @param {RuleSetUse} items user provided use value
|
142
|
+
* @returns {(Effect | ((value: TODO) => Effect[]))[]} effects
|
125
143
|
*/
|
126
144
|
const useToEffects = (path, items) => {
|
127
145
|
if (Array.isArray(items)) {
|
128
146
|
return items.filter(Boolean).map((item, idx) => {
|
129
147
|
const subPath = `${path}[${idx}]`;
|
130
|
-
return useToEffect(
|
148
|
+
return useToEffect(
|
149
|
+
subPath,
|
150
|
+
subPath,
|
151
|
+
/** @type {RuleSetUseItem} */
|
152
|
+
(item)
|
153
|
+
);
|
131
154
|
});
|
132
155
|
}
|
133
|
-
return [
|
156
|
+
return [
|
157
|
+
useToEffect(path, path, /** @type {RuleSetUseItem} */ (items))
|
158
|
+
];
|
134
159
|
};
|
135
160
|
|
136
161
|
if (typeof use === "function") {
|
@@ -182,7 +207,12 @@ class UseEffectRulePlugin {
|
|
182
207
|
|
183
208
|
const ident =
|
184
209
|
options && typeof options === "object" ? path : undefined;
|
185
|
-
references.set(
|
210
|
+
references.set(
|
211
|
+
/** @type {TODO} */
|
212
|
+
(ident),
|
213
|
+
/** @type {RuleSetLoaderOptions} */
|
214
|
+
(options)
|
215
|
+
);
|
186
216
|
result.effects.push({
|
187
217
|
type: enforce ? `use-${enforce}` : "use",
|
188
218
|
value: {
|
@@ -20,7 +20,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
20
20
|
* @param {string} contentType the contentType to use the content hash for
|
21
21
|
* @param {string} name kind of filename
|
22
22
|
* @param {string} global function name to be assigned
|
23
|
-
* @param {
|
23
|
+
* @param {(chunk: Chunk) => TemplatePath | false} getFilenameForChunk functor to get the filename or function
|
24
24
|
* @param {boolean} allChunks when false, only async chunks are included
|
25
25
|
*/
|
26
26
|
constructor(contentType, name, global, getFilenameForChunk, allChunks) {
|
@@ -138,7 +138,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
138
138
|
};
|
139
139
|
/**
|
140
140
|
* @param {string} value string
|
141
|
-
* @returns {
|
141
|
+
* @returns {(length: number) => string} string to put in quotes with length
|
142
142
|
*/
|
143
143
|
const unquotedStringifyWithLength = value => length =>
|
144
144
|
unquotedStringify(`${value}`.slice(0, length));
|
@@ -191,7 +191,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
191
191
|
}
|
192
192
|
|
193
193
|
/**
|
194
|
-
* @param {
|
194
|
+
* @param {(chunk: Chunk) => string | number} fn function from chunk to value
|
195
195
|
* @returns {string} code with static mapping of results of fn
|
196
196
|
*/
|
197
197
|
const createMap = fn => {
|
@@ -225,14 +225,14 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
225
225
|
};
|
226
226
|
|
227
227
|
/**
|
228
|
-
* @param {
|
228
|
+
* @param {(chunk: Chunk) => string | number} fn function from chunk to value
|
229
229
|
* @returns {string} code with static mapping of results of fn for including in quoted string
|
230
230
|
*/
|
231
231
|
const mapExpr = fn => `" + ${createMap(fn)} + "`;
|
232
232
|
|
233
233
|
/**
|
234
|
-
* @param {
|
235
|
-
* @returns {
|
234
|
+
* @param {(chunk: Chunk) => string | number} fn function from chunk to value
|
235
|
+
* @returns {(length: number) => string} function which generates code with static mapping of results of fn for including in quoted string for specific length
|
236
236
|
*/
|
237
237
|
const mapExprWithLength = fn => length =>
|
238
238
|
`" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
|
@@ -32,7 +32,7 @@ const getHttps = memoize(() => require("https"));
|
|
32
32
|
/**
|
33
33
|
* @param {typeof import("http") | typeof import("https")} request request
|
34
34
|
* @param {string | { toString: () => string } | undefined} proxy proxy
|
35
|
-
* @returns {
|
35
|
+
* @returns {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} fn
|
36
36
|
*/
|
37
37
|
const proxyFetch = (request, proxy) => (url, options, callback) => {
|
38
38
|
const eventEmitter = new EventEmitter();
|
@@ -255,8 +255,18 @@ class Lockfile {
|
|
255
255
|
|
256
256
|
/**
|
257
257
|
* @template R
|
258
|
-
* @
|
259
|
-
|
258
|
+
* @typedef {(err: Error | null, result?: R) => void} FnWithoutKeyCallback
|
259
|
+
*/
|
260
|
+
|
261
|
+
/**
|
262
|
+
* @template R
|
263
|
+
* @typedef {(callback: FnWithoutKeyCallback<R>) => void} FnWithoutKey
|
264
|
+
*/
|
265
|
+
|
266
|
+
/**
|
267
|
+
* @template R
|
268
|
+
* @param {FnWithoutKey<R>} fn function
|
269
|
+
* @returns {FnWithoutKey<R>} cached function
|
260
270
|
*/
|
261
271
|
const cachedWithoutKey = fn => {
|
262
272
|
let inFlight = false;
|
@@ -264,7 +274,7 @@ const cachedWithoutKey = fn => {
|
|
264
274
|
let cachedError;
|
265
275
|
/** @type {R | undefined} */
|
266
276
|
let cachedResult;
|
267
|
-
/** @type {
|
277
|
+
/** @type {FnWithoutKeyCallback<R>[] | undefined} */
|
268
278
|
let cachedCallbacks;
|
269
279
|
return callback => {
|
270
280
|
if (inFlight) {
|
@@ -286,23 +296,34 @@ const cachedWithoutKey = fn => {
|
|
286
296
|
};
|
287
297
|
};
|
288
298
|
|
299
|
+
/**
|
300
|
+
* @template R
|
301
|
+
* @typedef {(err: Error | null, result?: R) => void} FnWithKeyCallback
|
302
|
+
*/
|
303
|
+
|
304
|
+
/**
|
305
|
+
* @template T
|
306
|
+
* @template R
|
307
|
+
* @typedef {(item: T, callback: FnWithKeyCallback<R>) => void} FnWithKey
|
308
|
+
*/
|
309
|
+
|
289
310
|
/**
|
290
311
|
* @template T
|
291
312
|
* @template R
|
292
|
-
* @param {
|
293
|
-
* @param {
|
294
|
-
* @returns {(
|
313
|
+
* @param {FnWithKey<T, R>} fn function
|
314
|
+
* @param {FnWithKey<T, R>=} forceFn function for the second try
|
315
|
+
* @returns {(FnWithKey<T, R>) & { force: FnWithKey<T, R> }} cached function
|
295
316
|
*/
|
296
317
|
const cachedWithKey = (fn, forceFn = fn) => {
|
297
318
|
/**
|
298
319
|
* @template R
|
299
|
-
* @typedef {{ result?: R, error?: Error, callbacks?:
|
320
|
+
* @typedef {{ result?: R, error?: Error, callbacks?: FnWithKeyCallback<R>[], force?: true }} CacheEntry
|
300
321
|
*/
|
301
322
|
/** @type {Map<T, CacheEntry<R>>} */
|
302
323
|
const cache = new Map();
|
303
324
|
/**
|
304
325
|
* @param {T} arg arg
|
305
|
-
* @param {
|
326
|
+
* @param {FnWithKeyCallback<R>} callback callback
|
306
327
|
* @returns {void}
|
307
328
|
*/
|
308
329
|
const resultFn = (arg, callback) => {
|
@@ -333,7 +354,7 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
333
354
|
};
|
334
355
|
/**
|
335
356
|
* @param {T} arg arg
|
336
|
-
* @param {
|
357
|
+
* @param {FnWithKeyCallback<R>} callback callback
|
337
358
|
* @returns {void}
|
338
359
|
*/
|
339
360
|
resultFn.force = (arg, callback) => {
|
@@ -487,7 +508,7 @@ class HttpUriPlugin {
|
|
487
508
|
|
488
509
|
const getLockfile = cachedWithoutKey(
|
489
510
|
/**
|
490
|
-
* @param {
|
511
|
+
* @param {(err: Error | null, lockfile?: Lockfile) => void} callback callback
|
491
512
|
* @returns {void}
|
492
513
|
*/
|
493
514
|
callback => {
|
@@ -581,7 +602,7 @@ class HttpUriPlugin {
|
|
581
602
|
* @param {Lockfile} lockfile lockfile
|
582
603
|
* @param {string} url url
|
583
604
|
* @param {ResolveContentResult} result result
|
584
|
-
* @param {
|
605
|
+
* @param {(err: Error | null, result?: ResolveContentResult) => void} callback callback
|
585
606
|
* @returns {void}
|
586
607
|
*/
|
587
608
|
const storeResult = (lockfile, url, result, callback) => {
|
@@ -608,7 +629,7 @@ class HttpUriPlugin {
|
|
608
629
|
/**
|
609
630
|
* @param {string} url URL
|
610
631
|
* @param {string | null} integrity integrity
|
611
|
-
* @param {
|
632
|
+
* @param {(err: Error | null, resolveContentResult?: ResolveContentResult) => void} callback callback
|
612
633
|
*/
|
613
634
|
const resolveContent = (url, integrity, callback) => {
|
614
635
|
/**
|
@@ -654,7 +675,7 @@ class HttpUriPlugin {
|
|
654
675
|
/**
|
655
676
|
* @param {string} url URL
|
656
677
|
* @param {FetchResult | RedirectFetchResult | undefined} cachedResult result from cache
|
657
|
-
* @param {
|
678
|
+
* @param {(err: Error | null, fetchResult?: FetchResult) => void} callback callback
|
658
679
|
* @returns {void}
|
659
680
|
*/
|
660
681
|
const fetchContentRaw = (url, cachedResult, callback) => {
|
@@ -826,7 +847,7 @@ class HttpUriPlugin {
|
|
826
847
|
const fetchContent = cachedWithKey(
|
827
848
|
/**
|
828
849
|
* @param {string} url URL
|
829
|
-
* @param {
|
850
|
+
* @param {(err: Error | null, result?: { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }) => void} callback callback
|
830
851
|
* @returns {void}
|
831
852
|
*/
|
832
853
|
(url, callback) => {
|
@@ -864,7 +885,7 @@ class HttpUriPlugin {
|
|
864
885
|
const getInfo = cachedWithKey(
|
865
886
|
/**
|
866
887
|
* @param {string} url the url
|
867
|
-
* @param {
|
888
|
+
* @param {(err: Error | null, info?: Info) => void} callback callback
|
868
889
|
* @returns {void}
|
869
890
|
*/
|
870
891
|
// eslint-disable-next-line no-loop-func
|
@@ -1113,7 +1134,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1113
1134
|
/**
|
1114
1135
|
* @param {URL} url url
|
1115
1136
|
* @param {ResourceDataWithData} resourceData resource data
|
1116
|
-
* @param {
|
1137
|
+
* @param {(err: Error | null, result: true | void) => void} callback callback
|
1117
1138
|
*/
|
1118
1139
|
const respondWithUrlModule = (url, resourceData, callback) => {
|
1119
1140
|
getInfo(url.href, (err, _result) => {
|
@@ -7,9 +7,15 @@
|
|
7
7
|
const memoize = require("../util/memoize");
|
8
8
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
9
9
|
|
10
|
+
/** @typedef {import("./SerializerMiddleware").Context} Context */
|
10
11
|
/** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
|
11
12
|
/** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
|
12
13
|
|
14
|
+
/**
|
15
|
+
* @template LAZY_RESULT
|
16
|
+
* @typedef {import("./SerializerMiddleware").LazyFunction<LAZY_RESULT>} LazyFunction
|
17
|
+
*/
|
18
|
+
|
13
19
|
/*
|
14
20
|
Format:
|
15
21
|
|
@@ -135,8 +141,6 @@ const identifyBigInt = n => {
|
|
135
141
|
return 2;
|
136
142
|
};
|
137
143
|
|
138
|
-
/** @typedef {TODO} Context */
|
139
|
-
|
140
144
|
/**
|
141
145
|
* @typedef {PrimitiveSerializableType[]} DeserializedType
|
142
146
|
* @typedef {BufferSerializableType[]} SerializedType
|
@@ -145,17 +149,17 @@ const identifyBigInt = n => {
|
|
145
149
|
class BinaryMiddleware extends SerializerMiddleware {
|
146
150
|
/**
|
147
151
|
* @param {DeserializedType} data data
|
148
|
-
* @param {
|
149
|
-
* @returns {SerializedType|Promise<SerializedType>} serialized data
|
152
|
+
* @param {Context} context context object
|
153
|
+
* @returns {SerializedType | Promise<SerializedType> | null} serialized data
|
150
154
|
*/
|
151
155
|
serialize(data, context) {
|
152
156
|
return this._serialize(data, context);
|
153
157
|
}
|
154
158
|
|
155
159
|
/**
|
156
|
-
* @param {
|
157
|
-
* @param {
|
158
|
-
* @returns {
|
160
|
+
* @param {LazyFunction<DeserializedType>} fn lazy function
|
161
|
+
* @param {Context} context serialize function
|
162
|
+
* @returns {LazyFunction<SerializedType>} new lazy
|
159
163
|
*/
|
160
164
|
_serializeLazy(fn, context) {
|
161
165
|
return SerializerMiddleware.serializeLazy(fn, data =>
|
@@ -165,7 +169,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
165
169
|
|
166
170
|
/**
|
167
171
|
* @param {DeserializedType} data data
|
168
|
-
* @param {
|
172
|
+
* @param {Context} context context object
|
169
173
|
* @param {{ leftOverBuffer: Buffer | null, allocationSize: number, increaseCounter: number }} allocationScope allocation scope
|
170
174
|
* @returns {SerializedType} serialized data
|
171
175
|
*/
|
@@ -277,7 +281,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
277
281
|
case "function": {
|
278
282
|
if (!SerializerMiddleware.isLazy(thing))
|
279
283
|
throw new Error(`Unexpected function ${thing}`);
|
280
|
-
/** @type {SerializedType |
|
284
|
+
/** @type {SerializedType | LazyFunction<SerializedType>} */
|
281
285
|
let serializedData =
|
282
286
|
SerializerMiddleware.getLazySerializedValue(thing);
|
283
287
|
if (serializedData === undefined) {
|
@@ -285,16 +289,23 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
285
289
|
flush();
|
286
290
|
allocationScope.leftOverBuffer = leftOverBuffer;
|
287
291
|
const result =
|
288
|
-
/** @type {
|
289
|
-
|
290
|
-
);
|
292
|
+
/** @type {PrimitiveSerializableType[]} */
|
293
|
+
(thing());
|
291
294
|
const data = this._serialize(result, context, allocationScope);
|
292
295
|
leftOverBuffer = allocationScope.leftOverBuffer;
|
293
296
|
allocationScope.leftOverBuffer = null;
|
294
|
-
SerializerMiddleware.setLazySerializedValue(
|
297
|
+
SerializerMiddleware.setLazySerializedValue(
|
298
|
+
/** @type {LazyFunction<DeserializedType>} */
|
299
|
+
(thing),
|
300
|
+
data
|
301
|
+
);
|
295
302
|
serializedData = data;
|
296
303
|
} else {
|
297
|
-
serializedData = this._serializeLazy(
|
304
|
+
serializedData = this._serializeLazy(
|
305
|
+
/** @type {LazyFunction<DeserializedType>} */
|
306
|
+
(thing),
|
307
|
+
context
|
308
|
+
);
|
298
309
|
flush();
|
299
310
|
buffers.push(serializedData);
|
300
311
|
break;
|
@@ -644,13 +655,19 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
644
655
|
|
645
656
|
/**
|
646
657
|
* @param {SerializedType} data data
|
647
|
-
* @param {
|
648
|
-
* @returns {DeserializedType|Promise<DeserializedType>} deserialized data
|
658
|
+
* @param {Context} context context object
|
659
|
+
* @returns {DeserializedType | Promise<DeserializedType>} deserialized data
|
649
660
|
*/
|
650
661
|
deserialize(data, context) {
|
651
662
|
return this._deserialize(data, context);
|
652
663
|
}
|
653
664
|
|
665
|
+
/**
|
666
|
+
* @private
|
667
|
+
* @param {SerializedType} content content
|
668
|
+
* @param {Context} context context object
|
669
|
+
* @returns {LazyFunction<DeserializedType>} lazy function
|
670
|
+
*/
|
654
671
|
_createLazyDeserialized(content, context) {
|
655
672
|
return SerializerMiddleware.createLazy(
|
656
673
|
memoize(() => this._deserialize(content, context)),
|
@@ -660,6 +677,12 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
660
677
|
);
|
661
678
|
}
|
662
679
|
|
680
|
+
/**
|
681
|
+
* @private
|
682
|
+
* @param {LazyFunction<SerializedType>} fn lazy function
|
683
|
+
* @param {Context} context context object
|
684
|
+
* @returns {LazyFunction<DeserializedType>} new lazy
|
685
|
+
*/
|
663
686
|
_deserializeLazy(fn, context) {
|
664
687
|
return SerializerMiddleware.deserializeLazy(fn, data =>
|
665
688
|
this._deserialize(data, context)
|
@@ -668,7 +691,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
668
691
|
|
669
692
|
/**
|
670
693
|
* @param {SerializedType} data data
|
671
|
-
* @param {
|
694
|
+
* @param {Context} context context object
|
672
695
|
* @returns {DeserializedType} deserialized data
|
673
696
|
*/
|
674
697
|
_deserialize(data, context) {
|
@@ -795,13 +818,17 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
795
818
|
return () => {
|
796
819
|
const count = readU32();
|
797
820
|
const lengths = Array.from({ length: count }).map(() => readU32());
|
821
|
+
/** @type {(Buffer | LazyFunction<BufferSerializableType[]>)[]} */
|
798
822
|
const content = [];
|
799
823
|
for (let l of lengths) {
|
800
824
|
if (l === 0) {
|
801
825
|
if (typeof currentBuffer !== "function") {
|
802
826
|
throw new Error("Unexpected non-lazy element in stream");
|
803
827
|
}
|
804
|
-
content.push(
|
828
|
+
content.push(
|
829
|
+
/** @type {LazyFunction<BufferSerializableType[]>} */
|
830
|
+
(currentBuffer)
|
831
|
+
);
|
805
832
|
currentDataItem++;
|
806
833
|
currentBuffer =
|
807
834
|
currentDataItem < data.length ? data[currentDataItem] : null;
|
@@ -1117,7 +1144,13 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
1117
1144
|
let result = [];
|
1118
1145
|
while (currentBuffer !== null) {
|
1119
1146
|
if (typeof currentBuffer === "function") {
|
1120
|
-
result.push(
|
1147
|
+
result.push(
|
1148
|
+
this._deserializeLazy(
|
1149
|
+
/** @type {LazyFunction<SerializedType>} */
|
1150
|
+
(currentBuffer),
|
1151
|
+
context
|
1152
|
+
)
|
1153
|
+
);
|
1121
1154
|
currentDataItem++;
|
1122
1155
|
currentBuffer =
|
1123
1156
|
currentDataItem < data.length ? data[currentDataItem] : null;
|