fix: types

This commit is contained in:
alexander.akait 2024-10-24 00:41:15 +03:00
parent e11f2eaab4
commit 5ac0434184
10 changed files with 117 additions and 46 deletions

View File

@ -3354,7 +3354,7 @@ export interface LazyCompilationOptions {
| (( | ((
compiler: import("../lib/Compiler"), compiler: import("../lib/Compiler"),
callback: ( callback: (
err?: Error, err: Error | null,
api?: import("../lib/hmr/LazyCompilationPlugin").BackendApi api?: import("../lib/hmr/LazyCompilationPlugin").BackendApi
) => void ) => void
) => void) ) => void)

View File

@ -167,6 +167,7 @@ const { isSourceEqual } = require("./util/source");
*/ */
/** @typedef {new (...args: any[]) => Dependency} DepConstructor */ /** @typedef {new (...args: any[]) => Dependency} DepConstructor */
/** @typedef {Record<string, Source>} CompilationAssets */ /** @typedef {Record<string, Source>} CompilationAssets */
/** /**

View File

@ -56,6 +56,8 @@ const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin");
const { cleverMerge } = require("./util/cleverMerge"); const { cleverMerge } = require("./util/cleverMerge");
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */ /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
/** @typedef {import("./Compiler")} Compiler */ /** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */ /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
@ -598,9 +600,12 @@ class WebpackOptionsApply extends OptionsApply {
}).apply(compiler); }).apply(compiler);
} }
if (options.optimization.minimize) { if (options.optimization.minimize) {
for (const minimizer of options.optimization.minimizer) { for (const minimizer of /** @type {(WebpackPluginInstance | WebpackPluginFunction | "...")[]} */ (
options.optimization.minimizer
)) {
if (typeof minimizer === "function") { if (typeof minimizer === "function") {
minimizer.call(compiler, compiler); /** @type {WebpackPluginFunction} */
(minimizer).call(compiler, compiler);
} else if (minimizer !== "..." && minimizer) { } else if (minimizer !== "..." && minimizer) {
minimizer.apply(compiler); minimizer.apply(compiler);
} }

View File

@ -11,9 +11,9 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
const memoize = require("../util/memoize"); const memoize = require("../util/memoize");
const { forEachRuntime } = require("../util/runtime"); const { forEachRuntime } = require("../util/runtime");
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Compilation")} Compilation */ /** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../Module")} Module */ /** @typedef {import("../Module")} Module */
const getModuleFederationPlugin = memoize(() => const getModuleFederationPlugin = memoize(() =>

View File

@ -329,10 +329,23 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
} }
} }
/**
* @callback BackendHandler
* @param {Compiler} compiler compiler
* @param {function(Error | null, BackendApi=): void} callback callback
* @returns {void}
*/
/**
* @callback PromiseBackendHandler
* @param {Compiler} compiler compiler
* @returns {Promise<BackendApi>} backend
*/
class LazyCompilationPlugin { class LazyCompilationPlugin {
/** /**
* @param {object} options options * @param {object} options options
* @param {(function(Compiler, function(Error=, BackendApi?): void): void) | function(Compiler): Promise<BackendApi>} options.backend the backend * @param {BackendHandler | PromiseBackendHandler} options.backend the backend
* @param {boolean} options.entries true, when entries are lazy compiled * @param {boolean} options.entries true, when entries are lazy compiled
* @param {boolean} options.imports true, when import() modules are lazy compiled * @param {boolean} options.imports true, when import() modules are lazy compiled
* @param {RegExp | string | (function(Module): boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules * @param {RegExp | string | (function(Module): boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules

View File

@ -16,13 +16,7 @@
/** @typedef {import("../Compiler")} Compiler */ /** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */ /** @typedef {import("../Module")} Module */
/** @typedef {import("./LazyCompilationPlugin").BackendApi} BackendApi */ /** @typedef {import("./LazyCompilationPlugin").BackendApi} BackendApi */
/** @typedef {import("./LazyCompilationPlugin").BackendHandler} BackendHandler */
/**
* @callback BackendHandler
* @param {Compiler} compiler compiler
* @param {function(Error | null, BackendApi=): void} callback callback
* @returns {void}
*/
/** /**
* @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend * @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend

View File

@ -7,11 +7,11 @@
const memoize = require("./memoize"); const memoize = require("./memoize");
const getValidate = memoize(() => require("schema-utils").validate);
/** @typedef {import("schema-utils/declarations/validate").ValidationErrorConfiguration} ValidationErrorConfiguration */ /** @typedef {import("schema-utils/declarations/validate").ValidationErrorConfiguration} ValidationErrorConfiguration */
/** @typedef {import("./fs").JsonObject} JsonObject */ /** @typedef {import("./fs").JsonObject} JsonObject */
const getValidate = memoize(() => require("schema-utils").validate);
/** /**
* @template {object | object[]} T * @template {object | object[]} T
* @param {(function(T): boolean) | undefined} check check * @param {(function(T): boolean) | undefined} check check

View File

@ -179,9 +179,21 @@ module.exports.arrayToSetDeprecation = (set, name) => {
set[Symbol.isConcatSpreadable] = true; set[Symbol.isConcatSpreadable] = true;
}; };
/**
* @template T
* @param {string} name name
* @returns {{ new <T = any>(values?: readonly T[] | null): SetDeprecatedArray<T> }} SetDeprecatedArray
*/
module.exports.createArrayToSetDeprecationSet = name => { module.exports.createArrayToSetDeprecationSet = name => {
let initialized = false; let initialized = false;
/**
* @template T
*/
class SetDeprecatedArray extends Set { class SetDeprecatedArray extends Set {
/**
* @param {readonly T[] | null=} items items
*/
constructor(items) { constructor(items) {
super(items); super(items);
if (!initialized) { if (!initialized) {
@ -197,40 +209,77 @@ module.exports.createArrayToSetDeprecationSet = name => {
}; };
/** /**
* @param {object} obj object * @template {object} T
* @param {T} obj object
* @param {string} name property name * @param {string} name property name
* @param {string} code deprecation code * @param {string} code deprecation code
* @param {string} note additional note * @param {string} note additional note
* @returns {Proxy<object>} frozen object with deprecation when modifying * @returns {Proxy<T>} frozen object with deprecation when modifying
*/ */
module.exports.soonFrozenObjectDeprecation = (obj, name, code, note = "") => { module.exports.soonFrozenObjectDeprecation = (obj, name, code, note = "") => {
const message = `${name} will be frozen in future, all modifications are deprecated.${ const message = `${name} will be frozen in future, all modifications are deprecated.${
note && `\n${note}` note && `\n${note}`
}`; }`;
return new Proxy(obj, { return /** @type {Proxy<T>} */ (
set: util.deprecate( new Proxy(/** @type {object} */ (obj), {
(target, property, value, receiver) => set: util.deprecate(
Reflect.set(target, property, value, receiver), /**
message, * @param {T} target target
code * @param {string | symbol} property property
), * @param {any} value value
defineProperty: util.deprecate( * @param {any} receiver receiver
(target, property, descriptor) => * @returns {boolean} result
Reflect.defineProperty(target, property, descriptor), */
message, (target, property, value, receiver) =>
code Reflect.set(
), /** @type {object} */ (target),
deleteProperty: util.deprecate( property,
(target, property) => Reflect.deleteProperty(target, property), value,
message, receiver
code ),
), message,
setPrototypeOf: util.deprecate( code
(target, proto) => Reflect.setPrototypeOf(target, proto), ),
message, defineProperty: util.deprecate(
code /**
) * @param {T} target target
}); * @param {string | symbol} property property
* @param {PropertyDescriptor} descriptor descriptor
* @returns {boolean} result
*/
(target, property, descriptor) =>
Reflect.defineProperty(
/** @type {object} */ (target),
property,
descriptor
),
message,
code
),
deleteProperty: util.deprecate(
/**
* @param {T} target target
* @param {string | symbol} property property
* @returns {boolean} result
*/
(target, property) =>
Reflect.deleteProperty(/** @type {object} */ (target), property),
message,
code
),
setPrototypeOf: util.deprecate(
/**
* @param {T} target target
* @param {object | null} proto proto
* @returns {boolean} result
*/
(target, proto) =>
Reflect.setPrototypeOf(/** @type {object} */ (target), proto),
message,
code
)
})
);
}; };
/** /**
@ -263,7 +312,16 @@ const deprecateAllProperties = (obj, message, code) => {
enumerable: descriptor.enumerable, enumerable: descriptor.enumerable,
get: util.deprecate(() => value, message, code), get: util.deprecate(() => value, message, code),
set: descriptor.writable set: descriptor.writable
? util.deprecate(v => (value = v), message, code) ? util.deprecate(
/**
* @template T
* @param {T} v value
* @returns {T} result
*/
v => (value = v),
message,
code
)
: undefined : undefined
}); });
} }

View File

@ -2066,7 +2066,7 @@
{ {
"description": "A custom backend.", "description": "A custom backend.",
"instanceof": "Function", "instanceof": "Function",
"tsType": "(((compiler: import('../lib/Compiler'), callback: (err?: Error, api?: import(\"../lib/hmr/LazyCompilationPlugin\").BackendApi) => void) => void) | ((compiler: import('../lib/Compiler')) => Promise<import(\"../lib/hmr/LazyCompilationPlugin\").BackendApi>))" "tsType": "(((compiler: import('../lib/Compiler'), callback: (err: Error | null, api?: import(\"../lib/hmr/LazyCompilationPlugin\").BackendApi) => void) => void) | ((compiler: import('../lib/Compiler')) => Promise<import(\"../lib/hmr/LazyCompilationPlugin\").BackendApi>))"
}, },
{ {
"$ref": "#/definitions/LazyCompilationDefaultBackendOptions" "$ref": "#/definitions/LazyCompilationDefaultBackendOptions"

6
types.d.ts vendored
View File

@ -2310,8 +2310,8 @@ declare interface CompilationHooksJavascriptModulesPlugin {
useSourceMap: SyncBailHook<[Chunk, RenderContext], boolean>; useSourceMap: SyncBailHook<[Chunk, RenderContext], boolean>;
} }
declare interface CompilationHooksModuleFederationPlugin { declare interface CompilationHooksModuleFederationPlugin {
addContainerEntryDependency: SyncHook<any>; addContainerEntryDependency: SyncHook<Dependency>;
addFederationRuntimeDependency: SyncHook<any>; addFederationRuntimeDependency: SyncHook<Dependency>;
} }
declare interface CompilationHooksRealContentHashPlugin { declare interface CompilationHooksRealContentHashPlugin {
updateHash: SyncBailHook<[Buffer[], string], string>; updateHash: SyncBailHook<[Buffer[], string], string>;
@ -7512,7 +7512,7 @@ declare interface LazyCompilationOptions {
backend?: backend?:
| (( | ((
compiler: Compiler, compiler: Compiler,
callback: (err?: Error, api?: BackendApi) => void callback: (err: null | Error, api?: BackendApi) => void
) => void) ) => void)
| ((compiler: Compiler) => Promise<BackendApi>) | ((compiler: Compiler) => Promise<BackendApi>)
| LazyCompilationDefaultBackendOptions; | LazyCompilationDefaultBackendOptions;