mirror of https://github.com/webpack/webpack.git
fix: types
This commit is contained in:
parent
e11f2eaab4
commit
5ac0434184
|
@ -3354,7 +3354,7 @@ export interface LazyCompilationOptions {
|
|||
| ((
|
||||
compiler: import("../lib/Compiler"),
|
||||
callback: (
|
||||
err?: Error,
|
||||
err: Error | null,
|
||||
api?: import("../lib/hmr/LazyCompilationPlugin").BackendApi
|
||||
) => void
|
||||
) => void)
|
||||
|
|
|
@ -167,6 +167,7 @@ const { isSourceEqual } = require("./util/source");
|
|||
*/
|
||||
|
||||
/** @typedef {new (...args: any[]) => Dependency} DepConstructor */
|
||||
|
||||
/** @typedef {Record<string, Source>} CompilationAssets */
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,6 +56,8 @@ const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin");
|
|||
const { cleverMerge } = require("./util/cleverMerge");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
||||
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
|
||||
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
||||
|
@ -598,9 +600,12 @@ class WebpackOptionsApply extends OptionsApply {
|
|||
}).apply(compiler);
|
||||
}
|
||||
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") {
|
||||
minimizer.call(compiler, compiler);
|
||||
/** @type {WebpackPluginFunction} */
|
||||
(minimizer).call(compiler, compiler);
|
||||
} else if (minimizer !== "..." && minimizer) {
|
||||
minimizer.apply(compiler);
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|||
const memoize = require("../util/memoize");
|
||||
const { forEachRuntime } = require("../util/runtime");
|
||||
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
|
||||
const getModuleFederationPlugin = memoize(() =>
|
||||
|
|
|
@ -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 {
|
||||
/**
|
||||
* @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.imports true, when import() modules are lazy compiled
|
||||
* @param {RegExp | string | (function(Module): boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules
|
||||
|
|
|
@ -16,13 +16,7 @@
|
|||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("./LazyCompilationPlugin").BackendApi} BackendApi */
|
||||
|
||||
/**
|
||||
* @callback BackendHandler
|
||||
* @param {Compiler} compiler compiler
|
||||
* @param {function(Error | null, BackendApi=): void} callback callback
|
||||
* @returns {void}
|
||||
*/
|
||||
/** @typedef {import("./LazyCompilationPlugin").BackendHandler} BackendHandler */
|
||||
|
||||
/**
|
||||
* @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
|
||||
const memoize = require("./memoize");
|
||||
|
||||
const getValidate = memoize(() => require("schema-utils").validate);
|
||||
|
||||
/** @typedef {import("schema-utils/declarations/validate").ValidationErrorConfiguration} ValidationErrorConfiguration */
|
||||
/** @typedef {import("./fs").JsonObject} JsonObject */
|
||||
|
||||
const getValidate = memoize(() => require("schema-utils").validate);
|
||||
|
||||
/**
|
||||
* @template {object | object[]} T
|
||||
* @param {(function(T): boolean) | undefined} check check
|
||||
|
|
|
@ -179,9 +179,21 @@ module.exports.arrayToSetDeprecation = (set, name) => {
|
|||
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 => {
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class SetDeprecatedArray extends Set {
|
||||
/**
|
||||
* @param {readonly T[] | null=} items items
|
||||
*/
|
||||
constructor(items) {
|
||||
super(items);
|
||||
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} code deprecation code
|
||||
* @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 = "") => {
|
||||
const message = `${name} will be frozen in future, all modifications are deprecated.${
|
||||
note && `\n${note}`
|
||||
}`;
|
||||
return new Proxy(obj, {
|
||||
set: util.deprecate(
|
||||
(target, property, value, receiver) =>
|
||||
Reflect.set(target, property, value, receiver),
|
||||
message,
|
||||
code
|
||||
),
|
||||
defineProperty: util.deprecate(
|
||||
(target, property, descriptor) =>
|
||||
Reflect.defineProperty(target, property, descriptor),
|
||||
message,
|
||||
code
|
||||
),
|
||||
deleteProperty: util.deprecate(
|
||||
(target, property) => Reflect.deleteProperty(target, property),
|
||||
message,
|
||||
code
|
||||
),
|
||||
setPrototypeOf: util.deprecate(
|
||||
(target, proto) => Reflect.setPrototypeOf(target, proto),
|
||||
message,
|
||||
code
|
||||
)
|
||||
});
|
||||
return /** @type {Proxy<T>} */ (
|
||||
new Proxy(/** @type {object} */ (obj), {
|
||||
set: util.deprecate(
|
||||
/**
|
||||
* @param {T} target target
|
||||
* @param {string | symbol} property property
|
||||
* @param {any} value value
|
||||
* @param {any} receiver receiver
|
||||
* @returns {boolean} result
|
||||
*/
|
||||
(target, property, value, receiver) =>
|
||||
Reflect.set(
|
||||
/** @type {object} */ (target),
|
||||
property,
|
||||
value,
|
||||
receiver
|
||||
),
|
||||
message,
|
||||
code
|
||||
),
|
||||
defineProperty: util.deprecate(
|
||||
/**
|
||||
* @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,
|
||||
get: util.deprecate(() => value, message, code),
|
||||
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
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2066,7 +2066,7 @@
|
|||
{
|
||||
"description": "A custom backend.",
|
||||
"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"
|
||||
|
|
|
@ -2310,8 +2310,8 @@ declare interface CompilationHooksJavascriptModulesPlugin {
|
|||
useSourceMap: SyncBailHook<[Chunk, RenderContext], boolean>;
|
||||
}
|
||||
declare interface CompilationHooksModuleFederationPlugin {
|
||||
addContainerEntryDependency: SyncHook<any>;
|
||||
addFederationRuntimeDependency: SyncHook<any>;
|
||||
addContainerEntryDependency: SyncHook<Dependency>;
|
||||
addFederationRuntimeDependency: SyncHook<Dependency>;
|
||||
}
|
||||
declare interface CompilationHooksRealContentHashPlugin {
|
||||
updateHash: SyncBailHook<[Buffer[], string], string>;
|
||||
|
@ -7512,7 +7512,7 @@ declare interface LazyCompilationOptions {
|
|||
backend?:
|
||||
| ((
|
||||
compiler: Compiler,
|
||||
callback: (err?: Error, api?: BackendApi) => void
|
||||
callback: (err: null | Error, api?: BackendApi) => void
|
||||
) => void)
|
||||
| ((compiler: Compiler) => Promise<BackendApi>)
|
||||
| LazyCompilationDefaultBackendOptions;
|
||||
|
|
Loading…
Reference in New Issue