fix: resolve's plugins types

This commit is contained in:
alexander.akait 2024-03-04 19:59:16 +03:00
parent bf95762d16
commit cf891a4164
7 changed files with 79 additions and 32 deletions

View File

@ -333,6 +333,21 @@ export type ResolveAlias =
*/ */
[k: string]: string[] | false | string; [k: string]: string[] | false | string;
}; };
/**
* Plugin instance.
*/
export type ResolvePluginInstance =
| {
/**
* The run point of the plugin, required method.
*/
apply: (arg0: import("enhanced-resolve").Resolver) => void;
[k: string]: any;
}
| ((
this: import("enhanced-resolve").Resolver,
arg1: import("enhanced-resolve").Resolver
) => void);
/** /**
* A list of descriptions of loaders applied. * A list of descriptions of loaders applied.
*/ */
@ -1643,16 +1658,6 @@ export interface ResolveOptions {
*/ */
useSyncFileSystemCalls?: boolean; useSyncFileSystemCalls?: boolean;
} }
/**
* Plugin instance.
*/
export interface ResolvePluginInstance {
/**
* The run point of the plugin, required method.
*/
apply: (resolver: import("enhanced-resolve").Resolver) => void;
[k: string]: any;
}
/** /**
* Options object for node compatibility features. * Options object for node compatibility features.
*/ */

File diff suppressed because one or more lines are too long

View File

@ -4154,17 +4154,25 @@
}, },
"ResolvePluginInstance": { "ResolvePluginInstance": {
"description": "Plugin instance.", "description": "Plugin instance.",
"anyOf": [
{
"type": "object", "type": "object",
"additionalProperties": true, "additionalProperties": true,
"properties": { "properties": {
"apply": { "apply": {
"description": "The run point of the plugin, required method.", "description": "The run point of the plugin, required method.",
"instanceof": "Function", "instanceof": "Function",
"tsType": "(resolver: import('enhanced-resolve').Resolver) => void" "tsType": "(arg0: import('enhanced-resolve').Resolver) => void"
} }
}, },
"required": ["apply"] "required": ["apply"]
}, },
{
"instanceof": "Function",
"tsType": "((this: import('enhanced-resolve').Resolver, arg1: import('enhanced-resolve').Resolver) => void)"
}
]
},
"RuleSetCondition": { "RuleSetCondition": {
"description": "A condition matcher.", "description": "A condition matcher.",
"cli": { "cli": {

View File

@ -0,0 +1 @@
export default 1;

View File

@ -0,0 +1,3 @@
it("should compile", async () => {
expect(1).toBe(1);
});

View File

@ -0,0 +1,26 @@
let pluginExecutionCounter = 0;
/** @type {import("../../../../").Configuration} */
module.exports = {
plugins: [
{
apply(compiler) {
compiler.hooks.done.tap("TestPlugin", () => {
expect(pluginExecutionCounter).toBe(4);
});
}
}
],
resolve: {
plugins: [
{
apply() {
pluginExecutionCounter += 1;
}
},
() => {
pluginExecutionCounter += 1;
}
]
}
};

22
types.d.ts vendored
View File

@ -10837,7 +10837,14 @@ declare interface ResolveOptionsWebpackOptions {
| false | false
| "" | ""
| 0 | 0
| ResolvePluginInstance | {
[index: string]: any;
/**
* The run point of the plugin, required method.
*/
apply: (arg0: Resolver) => void;
}
| ((this: Resolver, arg1: Resolver) => void)
| "..." | "..."
)[]; )[];
@ -10885,18 +10892,15 @@ type ResolveOptionsWithDependencyType = ResolveOptionsWebpackOptions & {
dependencyType?: string; dependencyType?: string;
resolveToContext?: boolean; resolveToContext?: boolean;
}; };
type ResolvePluginInstance =
/** | {
* Plugin instance.
*/
declare interface ResolvePluginInstance {
[index: string]: any; [index: string]: any;
/** /**
* The run point of the plugin, required method. * The run point of the plugin, required method.
*/ */
apply: (resolver: Resolver) => void; apply: (arg0: Resolver) => void;
} }
| ((this: Resolver, arg1: Resolver) => void);
type ResolveRequest = BaseResolveRequest & Partial<ParsedIdentifier>; type ResolveRequest = BaseResolveRequest & Partial<ParsedIdentifier>;
declare interface ResolvedContextFileSystemInfoEntry { declare interface ResolvedContextFileSystemInfoEntry {
safeTime: number; safeTime: number;