@shuvi/hook 1.0.55 → 1.0.56
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/esm/hookGroup.d.ts +1 -1
- package/esm/hooks.d.ts +18 -18
- package/esm/types.d.ts +13 -13
- package/lib/hookGroup.d.ts +1 -1
- package/lib/hookGroup.js +2 -2
- package/lib/hooks.d.ts +18 -18
- package/lib/types.d.ts +13 -13
- package/package.json +5 -5
package/esm/hookGroup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IPluginHandlers, IPluginInstance, HookManager, HookMap, PluginOptions } from './types';
|
|
2
2
|
export declare const isPluginInstance: <T extends IPluginInstance<any, any> = IPluginInstance<any, any>>(plugin: any) => plugin is T;
|
|
3
|
-
export
|
|
3
|
+
export type ArrayElements<T extends {}> = {
|
|
4
4
|
[K in keyof T]: T[K][];
|
|
5
5
|
};
|
|
6
6
|
export declare function createPlugin<HM extends HookMap, C = void>(pluginHandlers: IPluginHandlers<HM, C>, options?: PluginOptions): IPluginInstance<HM, C>;
|
package/esm/hooks.d.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
1
|
+
export type HookRunnerFromHandler<T> = T extends (...args: infer A) => infer R ? void extends R ? (...args: A) => void : (...args: A) => R[] : T;
|
|
2
|
+
export type RemoveVoidParameter<T> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? null extends I ? null extends E ? (initialValue: I, extraArg: E) => R : void extends E ? (initialValue: I) => R : (initialValue: I, extraArg: E) => R : void extends I ? null extends E ? (extraArg: E) => R : void extends E ? () => R : (extraArg: E) => R : null extends E ? (initialValue: I, extraArg: E) => R : void extends E ? (initialValue: I) => R : (initialValue: I, extraArg: E) => R : T;
|
|
3
|
+
export type RemoveVoidParameterBackup<T> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? I extends void ? I extends void ? E extends void ? E extends void ? () => R : (extraArg: E) => R : (extraArg: E) => R : E extends void ? E extends void ? () => R : (initalValue: I, extraArg: E) => R : (initalValue: I, extraArg: E) => R : E extends void ? E extends void ? (initalValue: I) => R : (initalValue: I, extradddArg: E) => R : (initalValue: I, extraArg: E) => R : T;
|
|
4
|
+
export type Remove3VoidParameter<T> = T extends (initalValue: infer I, extraArg: infer E, context: infer C) => infer R ? I extends void ? I extends void ? E extends void ? E extends void ? C extends void ? C extends void ? 'C无' : 'C为any' : 'C有' : (extraArg: E) => R : (extraArg: E) => R : E extends void ? E extends void ? () => R : (initalValue: I, extraArg: E) => R : (initalValue: I, extraArg: E) => R : 'I有' : T;
|
|
5
|
+
export type SyncHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R;
|
|
6
|
+
export type SyncBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R | undefined | void;
|
|
7
|
+
export type SyncWaterfallHookHandler<I, E> = (initalValue: I, extraArgs: E) => I;
|
|
8
|
+
export type AsyncSeriesHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R> | R;
|
|
9
|
+
export type AsyncSeriesBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R | undefined | void> | R | undefined | void;
|
|
10
|
+
export type AsyncSeriesWaterfallHookHandler<I, E> = (initalValue: I, extraArg: E) => Promise<I> | I;
|
|
11
|
+
export type AsyncParallelHookHandler<I, E, R> = (initalValue: I, extraArgs: E) => Promise<R> | R;
|
|
12
12
|
/** Normal hook. */
|
|
13
|
-
export
|
|
13
|
+
export type SyncHook<I = void, E = void, R = void> = {
|
|
14
14
|
use: (...handlers: RemoveVoidParameter<SyncHookHandler<I, E, R>>[]) => void;
|
|
15
15
|
run: RemoveVoidParameter<(initalValue: I, extraArg: E) => R[]>;
|
|
16
16
|
clear: () => void;
|
|
17
17
|
type: string;
|
|
18
18
|
};
|
|
19
19
|
/** Has return value with `any` type */
|
|
20
|
-
export
|
|
20
|
+
export type SyncBailHook<I = void, E = void, R = I> = {
|
|
21
21
|
use: (...handlers: RemoveVoidParameter<SyncBailHookHandler<I, E, R>>[]) => void;
|
|
22
22
|
run: RemoveVoidParameter<SyncBailHookHandler<I, E, R>>;
|
|
23
23
|
clear: () => void;
|
|
24
24
|
type: string;
|
|
25
25
|
};
|
|
26
26
|
/** Has return value with given type */
|
|
27
|
-
export
|
|
27
|
+
export type SyncWaterfallHook<I, E = void> = {
|
|
28
28
|
use: (...handlers: RemoveVoidParameter<SyncWaterfallHookHandler<I, E>>[]) => void;
|
|
29
29
|
run: RemoveVoidParameter<SyncWaterfallHookHandler<I, E>>;
|
|
30
30
|
clear: () => void;
|
|
31
31
|
type: string;
|
|
32
32
|
};
|
|
33
|
-
export
|
|
33
|
+
export type AsyncSeriesHook<I = void, E = void, R = void> = {
|
|
34
34
|
use: (...handlers: RemoveVoidParameter<AsyncSeriesHookHandler<I, E, R>>[]) => void;
|
|
35
35
|
run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
|
|
36
36
|
clear: () => void;
|
|
37
37
|
type: string;
|
|
38
38
|
};
|
|
39
|
-
export
|
|
39
|
+
export type AsyncSeriesBailHook<I = void, E = void, R = I> = {
|
|
40
40
|
use: (...handlers: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>[]) => void;
|
|
41
41
|
run: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>;
|
|
42
42
|
clear: () => void;
|
|
43
43
|
type: string;
|
|
44
44
|
};
|
|
45
45
|
/** Normal async parallel hook */
|
|
46
|
-
export
|
|
46
|
+
export type AsyncParallelHook<I = void, E = void, R = void> = {
|
|
47
47
|
use: (...handlers: RemoveVoidParameter<AsyncParallelHookHandler<I, E, R>>[]) => void;
|
|
48
48
|
run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
|
|
49
49
|
clear: () => void;
|
|
50
50
|
type: string;
|
|
51
51
|
};
|
|
52
52
|
/** Has return value with given type */
|
|
53
|
-
export
|
|
53
|
+
export type AsyncSeriesWaterfallHook<I = void, E = void> = {
|
|
54
54
|
use: (...handlers: RemoveVoidParameter<AsyncSeriesWaterfallHookHandler<I, E>>[]) => void;
|
|
55
55
|
run: RemoveVoidParameter<(initalValue: I, extraArgs: E) => Promise<I>>;
|
|
56
56
|
clear: () => void;
|
package/esm/types.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { SyncHook, SyncBailHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook, SyncHookHandler, SyncBailHookHandler, SyncWaterfallHookHandler, AsyncParallelHookHandler, AsyncSeriesWaterfallHookHandler, AsyncSeriesHook, AsyncSeriesBailHook, AsyncSeriesHookHandler, AsyncSeriesBailHookHandler } from './hooks';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export type PatchPluginParameter<T, C> = RemoveManagerVoidParameter<AddContextParameter<T, C>>;
|
|
3
|
+
export type AddContextParameter<T, C> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? (initalValue: I, extraArg: E, context: C) => R : T;
|
|
4
|
+
export type AnyHook = SyncHook<any, any, any> | SyncBailHook<any, any, any> | SyncWaterfallHook<any, any> | AsyncParallelHook<any, any, any> | AsyncSeriesHook<any, any, any> | AsyncSeriesBailHook<any, any, any> | AsyncSeriesWaterfallHook<any, any>;
|
|
5
5
|
export interface HookMap {
|
|
6
6
|
[x: string]: AnyHook;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export type Setup<HM extends HookMap = {}> = (utils: {
|
|
9
9
|
addHooks: (hook: Partial<HM>) => void;
|
|
10
10
|
}) => void;
|
|
11
|
-
export
|
|
11
|
+
export type CreatePlugin<HM extends HookMap, C> = (pluginHandlers: IPluginHandlers<HM, C> & {
|
|
12
12
|
setup?: Setup;
|
|
13
13
|
}, options?: PluginOptions) => IPluginInstance<HM, C>;
|
|
14
|
-
export
|
|
14
|
+
export type HookManager<HM extends HookMap, C> = {
|
|
15
15
|
createPlugin: CreatePlugin<HM, C>;
|
|
16
16
|
usePlugin: (...plugins: IPluginInstance<HM, C>[]) => void;
|
|
17
17
|
runner: RunnerType<HM>;
|
|
@@ -21,21 +21,21 @@ export declare type HookManager<HM extends HookMap, C> = {
|
|
|
21
21
|
hooks: HM;
|
|
22
22
|
getPlugins: () => IPluginInstance<HM, C>[];
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type RunnerType<HM> = {
|
|
25
25
|
[K in keyof HM]: HookRunnerType<HM[K]>;
|
|
26
26
|
} & {
|
|
27
27
|
setup: Setup;
|
|
28
28
|
};
|
|
29
|
-
export
|
|
30
|
-
export
|
|
29
|
+
export type HookRunnerType<H> = H extends SyncHook<infer T, infer E, infer R> ? SyncHook<T, E, R>['run'] : H extends SyncBailHook<infer T, infer E, infer R> ? SyncBailHook<T, E, R>['run'] : H extends SyncWaterfallHook<infer T, infer E> ? SyncWaterfallHook<T, E>['run'] : H extends AsyncParallelHook<infer T, infer E, infer R> ? AsyncParallelHook<T, E, R>['run'] : H extends AsyncSeriesHook<infer T, infer E, infer R> ? AsyncSeriesHook<T, E, R>['run'] : H extends AsyncSeriesBailHook<infer T, infer E, infer R> ? AsyncSeriesBailHook<T, E, R>['run'] : H extends AsyncSeriesWaterfallHook<infer T, infer E> ? AsyncSeriesWaterfallHook<T, E>['run'] : never;
|
|
30
|
+
export type IPluginInstance<HM, C> = {
|
|
31
31
|
handlers: IPluginHandlers<HM, C>;
|
|
32
32
|
PLUGIN_SYMBOL: 'PLUGIN_SYMBOL';
|
|
33
33
|
} & Required<PluginOptions>;
|
|
34
|
-
export
|
|
35
|
-
export
|
|
34
|
+
export type IPluginHandlers<HM, C> = Partial<IPluginHandlersFullMap<HM, C>>;
|
|
35
|
+
export type IPluginHandlersFullMap<HM, C> = {
|
|
36
36
|
[K in keyof HM]: HM[K] extends SyncHook<infer T, infer E, infer R> ? PatchPluginParameter<SyncHookHandler<T, E, R>, C> : HM[K] extends SyncBailHook<infer T, infer E, infer R> ? PatchPluginParameter<SyncBailHookHandler<T, E, R>, C> : HM[K] extends SyncWaterfallHook<infer T, infer E> ? PatchPluginParameter<SyncWaterfallHookHandler<T, E>, C> : HM[K] extends AsyncParallelHook<infer T, infer E, infer R> ? PatchPluginParameter<AsyncParallelHookHandler<T, E, R>, C> : HM[K] extends AsyncSeriesHook<infer T, infer E, infer R> ? PatchPluginParameter<AsyncSeriesHookHandler<T, E, R>, C> : HM[K] extends AsyncSeriesBailHook<infer T, infer E, infer R> ? PatchPluginParameter<AsyncSeriesBailHookHandler<T, E, R>, C> : HM[K] extends AsyncSeriesWaterfallHook<infer T, infer E> ? PatchPluginParameter<AsyncSeriesWaterfallHookHandler<T, E>, C> : never;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type PluginOptions = {
|
|
39
39
|
name?: string;
|
|
40
40
|
/** current plugin should before these configured plugins.
|
|
41
41
|
* only works for same group
|
|
@@ -56,4 +56,4 @@ export declare type PluginOptions = {
|
|
|
56
56
|
group?: number;
|
|
57
57
|
[x: string]: any;
|
|
58
58
|
};
|
|
59
|
-
export
|
|
59
|
+
export type RemoveManagerVoidParameter<T> = T extends (initalValue: infer I, extraArg: infer E, context: infer C) => infer R ? null extends I ? null extends E ? null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : void extends E ? null extends C ? (initialValue: I, context: C) => R : void extends C ? (initialValue: I) => R : (initialValue: I, context: C) => R : null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : void extends I ? null extends E ? null extends C ? (extraArg: E, context: C) => R : void extends C ? (extraArg: E) => R : (extraArg: E, context: C) => R : void extends E ? null extends C ? (context: C) => R : void extends C ? () => R : (context: C) => R : null extends C ? (extraArg: E, context: C) => R : void extends C ? (extraArg: E) => R : (extraArg: E, context: C) => R : null extends E ? null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : void extends E ? null extends C ? (initialValue: I, context: C) => R : void extends C ? (initialValue: I) => R : (initialValue: I, context: C) => R : null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : T;
|
package/lib/hookGroup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IPluginHandlers, IPluginInstance, HookManager, HookMap, PluginOptions } from './types';
|
|
2
2
|
export declare const isPluginInstance: <T extends IPluginInstance<any, any> = IPluginInstance<any, any>>(plugin: any) => plugin is T;
|
|
3
|
-
export
|
|
3
|
+
export type ArrayElements<T extends {}> = {
|
|
4
4
|
[K in keyof T]: T[K][];
|
|
5
5
|
};
|
|
6
6
|
export declare function createPlugin<HM extends HookMap, C = void>(pluginHandlers: IPluginHandlers<HM, C>, options?: PluginOptions): IPluginInstance<HM, C>;
|
package/lib/hookGroup.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHookManager = exports.
|
|
3
|
+
exports.createHookManager = exports.isPluginInstance = void 0;
|
|
4
|
+
exports.createPlugin = createPlugin;
|
|
4
5
|
const hooks_1 = require("./hooks");
|
|
5
6
|
const utils_1 = require("./utils");
|
|
6
7
|
const DEFAULT_OPTIONS = {
|
|
@@ -56,7 +57,6 @@ const copyHookMap = (hookMap) => {
|
|
|
56
57
|
function createPlugin(pluginHandlers, options = {}) {
|
|
57
58
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, DEFAULT_OPTIONS), { name: `plugin-id-${uuid()}` }), options), { handlers: pluginHandlers, PLUGIN_SYMBOL });
|
|
58
59
|
}
|
|
59
|
-
exports.createPlugin = createPlugin;
|
|
60
60
|
const createHookManager = (hookMap, hasContext = true) => {
|
|
61
61
|
const setupHook = (0, hooks_1.createSyncHook)();
|
|
62
62
|
const _hookMap = Object.assign(Object.assign({}, copyHookMap(hookMap)), { setup: setupHook });
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
1
|
+
export type HookRunnerFromHandler<T> = T extends (...args: infer A) => infer R ? void extends R ? (...args: A) => void : (...args: A) => R[] : T;
|
|
2
|
+
export type RemoveVoidParameter<T> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? null extends I ? null extends E ? (initialValue: I, extraArg: E) => R : void extends E ? (initialValue: I) => R : (initialValue: I, extraArg: E) => R : void extends I ? null extends E ? (extraArg: E) => R : void extends E ? () => R : (extraArg: E) => R : null extends E ? (initialValue: I, extraArg: E) => R : void extends E ? (initialValue: I) => R : (initialValue: I, extraArg: E) => R : T;
|
|
3
|
+
export type RemoveVoidParameterBackup<T> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? I extends void ? I extends void ? E extends void ? E extends void ? () => R : (extraArg: E) => R : (extraArg: E) => R : E extends void ? E extends void ? () => R : (initalValue: I, extraArg: E) => R : (initalValue: I, extraArg: E) => R : E extends void ? E extends void ? (initalValue: I) => R : (initalValue: I, extradddArg: E) => R : (initalValue: I, extraArg: E) => R : T;
|
|
4
|
+
export type Remove3VoidParameter<T> = T extends (initalValue: infer I, extraArg: infer E, context: infer C) => infer R ? I extends void ? I extends void ? E extends void ? E extends void ? C extends void ? C extends void ? 'C无' : 'C为any' : 'C有' : (extraArg: E) => R : (extraArg: E) => R : E extends void ? E extends void ? () => R : (initalValue: I, extraArg: E) => R : (initalValue: I, extraArg: E) => R : 'I有' : T;
|
|
5
|
+
export type SyncHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R;
|
|
6
|
+
export type SyncBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R | undefined | void;
|
|
7
|
+
export type SyncWaterfallHookHandler<I, E> = (initalValue: I, extraArgs: E) => I;
|
|
8
|
+
export type AsyncSeriesHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R> | R;
|
|
9
|
+
export type AsyncSeriesBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R | undefined | void> | R | undefined | void;
|
|
10
|
+
export type AsyncSeriesWaterfallHookHandler<I, E> = (initalValue: I, extraArg: E) => Promise<I> | I;
|
|
11
|
+
export type AsyncParallelHookHandler<I, E, R> = (initalValue: I, extraArgs: E) => Promise<R> | R;
|
|
12
12
|
/** Normal hook. */
|
|
13
|
-
export
|
|
13
|
+
export type SyncHook<I = void, E = void, R = void> = {
|
|
14
14
|
use: (...handlers: RemoveVoidParameter<SyncHookHandler<I, E, R>>[]) => void;
|
|
15
15
|
run: RemoveVoidParameter<(initalValue: I, extraArg: E) => R[]>;
|
|
16
16
|
clear: () => void;
|
|
17
17
|
type: string;
|
|
18
18
|
};
|
|
19
19
|
/** Has return value with `any` type */
|
|
20
|
-
export
|
|
20
|
+
export type SyncBailHook<I = void, E = void, R = I> = {
|
|
21
21
|
use: (...handlers: RemoveVoidParameter<SyncBailHookHandler<I, E, R>>[]) => void;
|
|
22
22
|
run: RemoveVoidParameter<SyncBailHookHandler<I, E, R>>;
|
|
23
23
|
clear: () => void;
|
|
24
24
|
type: string;
|
|
25
25
|
};
|
|
26
26
|
/** Has return value with given type */
|
|
27
|
-
export
|
|
27
|
+
export type SyncWaterfallHook<I, E = void> = {
|
|
28
28
|
use: (...handlers: RemoveVoidParameter<SyncWaterfallHookHandler<I, E>>[]) => void;
|
|
29
29
|
run: RemoveVoidParameter<SyncWaterfallHookHandler<I, E>>;
|
|
30
30
|
clear: () => void;
|
|
31
31
|
type: string;
|
|
32
32
|
};
|
|
33
|
-
export
|
|
33
|
+
export type AsyncSeriesHook<I = void, E = void, R = void> = {
|
|
34
34
|
use: (...handlers: RemoveVoidParameter<AsyncSeriesHookHandler<I, E, R>>[]) => void;
|
|
35
35
|
run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
|
|
36
36
|
clear: () => void;
|
|
37
37
|
type: string;
|
|
38
38
|
};
|
|
39
|
-
export
|
|
39
|
+
export type AsyncSeriesBailHook<I = void, E = void, R = I> = {
|
|
40
40
|
use: (...handlers: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>[]) => void;
|
|
41
41
|
run: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>;
|
|
42
42
|
clear: () => void;
|
|
43
43
|
type: string;
|
|
44
44
|
};
|
|
45
45
|
/** Normal async parallel hook */
|
|
46
|
-
export
|
|
46
|
+
export type AsyncParallelHook<I = void, E = void, R = void> = {
|
|
47
47
|
use: (...handlers: RemoveVoidParameter<AsyncParallelHookHandler<I, E, R>>[]) => void;
|
|
48
48
|
run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
|
|
49
49
|
clear: () => void;
|
|
50
50
|
type: string;
|
|
51
51
|
};
|
|
52
52
|
/** Has return value with given type */
|
|
53
|
-
export
|
|
53
|
+
export type AsyncSeriesWaterfallHook<I = void, E = void> = {
|
|
54
54
|
use: (...handlers: RemoveVoidParameter<AsyncSeriesWaterfallHookHandler<I, E>>[]) => void;
|
|
55
55
|
run: RemoveVoidParameter<(initalValue: I, extraArgs: E) => Promise<I>>;
|
|
56
56
|
clear: () => void;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { SyncHook, SyncBailHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook, SyncHookHandler, SyncBailHookHandler, SyncWaterfallHookHandler, AsyncParallelHookHandler, AsyncSeriesWaterfallHookHandler, AsyncSeriesHook, AsyncSeriesBailHook, AsyncSeriesHookHandler, AsyncSeriesBailHookHandler } from './hooks';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export type PatchPluginParameter<T, C> = RemoveManagerVoidParameter<AddContextParameter<T, C>>;
|
|
3
|
+
export type AddContextParameter<T, C> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? (initalValue: I, extraArg: E, context: C) => R : T;
|
|
4
|
+
export type AnyHook = SyncHook<any, any, any> | SyncBailHook<any, any, any> | SyncWaterfallHook<any, any> | AsyncParallelHook<any, any, any> | AsyncSeriesHook<any, any, any> | AsyncSeriesBailHook<any, any, any> | AsyncSeriesWaterfallHook<any, any>;
|
|
5
5
|
export interface HookMap {
|
|
6
6
|
[x: string]: AnyHook;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export type Setup<HM extends HookMap = {}> = (utils: {
|
|
9
9
|
addHooks: (hook: Partial<HM>) => void;
|
|
10
10
|
}) => void;
|
|
11
|
-
export
|
|
11
|
+
export type CreatePlugin<HM extends HookMap, C> = (pluginHandlers: IPluginHandlers<HM, C> & {
|
|
12
12
|
setup?: Setup;
|
|
13
13
|
}, options?: PluginOptions) => IPluginInstance<HM, C>;
|
|
14
|
-
export
|
|
14
|
+
export type HookManager<HM extends HookMap, C> = {
|
|
15
15
|
createPlugin: CreatePlugin<HM, C>;
|
|
16
16
|
usePlugin: (...plugins: IPluginInstance<HM, C>[]) => void;
|
|
17
17
|
runner: RunnerType<HM>;
|
|
@@ -21,21 +21,21 @@ export declare type HookManager<HM extends HookMap, C> = {
|
|
|
21
21
|
hooks: HM;
|
|
22
22
|
getPlugins: () => IPluginInstance<HM, C>[];
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type RunnerType<HM> = {
|
|
25
25
|
[K in keyof HM]: HookRunnerType<HM[K]>;
|
|
26
26
|
} & {
|
|
27
27
|
setup: Setup;
|
|
28
28
|
};
|
|
29
|
-
export
|
|
30
|
-
export
|
|
29
|
+
export type HookRunnerType<H> = H extends SyncHook<infer T, infer E, infer R> ? SyncHook<T, E, R>['run'] : H extends SyncBailHook<infer T, infer E, infer R> ? SyncBailHook<T, E, R>['run'] : H extends SyncWaterfallHook<infer T, infer E> ? SyncWaterfallHook<T, E>['run'] : H extends AsyncParallelHook<infer T, infer E, infer R> ? AsyncParallelHook<T, E, R>['run'] : H extends AsyncSeriesHook<infer T, infer E, infer R> ? AsyncSeriesHook<T, E, R>['run'] : H extends AsyncSeriesBailHook<infer T, infer E, infer R> ? AsyncSeriesBailHook<T, E, R>['run'] : H extends AsyncSeriesWaterfallHook<infer T, infer E> ? AsyncSeriesWaterfallHook<T, E>['run'] : never;
|
|
30
|
+
export type IPluginInstance<HM, C> = {
|
|
31
31
|
handlers: IPluginHandlers<HM, C>;
|
|
32
32
|
PLUGIN_SYMBOL: 'PLUGIN_SYMBOL';
|
|
33
33
|
} & Required<PluginOptions>;
|
|
34
|
-
export
|
|
35
|
-
export
|
|
34
|
+
export type IPluginHandlers<HM, C> = Partial<IPluginHandlersFullMap<HM, C>>;
|
|
35
|
+
export type IPluginHandlersFullMap<HM, C> = {
|
|
36
36
|
[K in keyof HM]: HM[K] extends SyncHook<infer T, infer E, infer R> ? PatchPluginParameter<SyncHookHandler<T, E, R>, C> : HM[K] extends SyncBailHook<infer T, infer E, infer R> ? PatchPluginParameter<SyncBailHookHandler<T, E, R>, C> : HM[K] extends SyncWaterfallHook<infer T, infer E> ? PatchPluginParameter<SyncWaterfallHookHandler<T, E>, C> : HM[K] extends AsyncParallelHook<infer T, infer E, infer R> ? PatchPluginParameter<AsyncParallelHookHandler<T, E, R>, C> : HM[K] extends AsyncSeriesHook<infer T, infer E, infer R> ? PatchPluginParameter<AsyncSeriesHookHandler<T, E, R>, C> : HM[K] extends AsyncSeriesBailHook<infer T, infer E, infer R> ? PatchPluginParameter<AsyncSeriesBailHookHandler<T, E, R>, C> : HM[K] extends AsyncSeriesWaterfallHook<infer T, infer E> ? PatchPluginParameter<AsyncSeriesWaterfallHookHandler<T, E>, C> : never;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type PluginOptions = {
|
|
39
39
|
name?: string;
|
|
40
40
|
/** current plugin should before these configured plugins.
|
|
41
41
|
* only works for same group
|
|
@@ -56,4 +56,4 @@ export declare type PluginOptions = {
|
|
|
56
56
|
group?: number;
|
|
57
57
|
[x: string]: any;
|
|
58
58
|
};
|
|
59
|
-
export
|
|
59
|
+
export type RemoveManagerVoidParameter<T> = T extends (initalValue: infer I, extraArg: infer E, context: infer C) => infer R ? null extends I ? null extends E ? null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : void extends E ? null extends C ? (initialValue: I, context: C) => R : void extends C ? (initialValue: I) => R : (initialValue: I, context: C) => R : null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : void extends I ? null extends E ? null extends C ? (extraArg: E, context: C) => R : void extends C ? (extraArg: E) => R : (extraArg: E, context: C) => R : void extends E ? null extends C ? (context: C) => R : void extends C ? () => R : (context: C) => R : null extends C ? (extraArg: E, context: C) => R : void extends C ? (extraArg: E) => R : (extraArg: E, context: C) => R : null extends E ? null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : void extends E ? null extends C ? (initialValue: I, context: C) => R : void extends C ? (initialValue: I) => R : (initialValue: I, context: C) => R : null extends C ? (initialValue: I, extraArg: E, context: C) => R : void extends C ? (initialValue: I, extraArg: E) => R : (initialValue: I, extraArg: E, context: C) => R : T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/hook",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "run-p watch:*",
|
|
17
|
-
"watch:esm": "tsc -p tsconfig.build.json -
|
|
18
|
-
"watch:cjs": "tsc -p tsconfig.build.json -
|
|
17
|
+
"watch:esm": "tsc -p tsconfig.build.esm.json -w",
|
|
18
|
+
"watch:cjs": "tsc -p tsconfig.build.cjs.json -w",
|
|
19
19
|
"prebuild": "rimraf lib esm",
|
|
20
20
|
"build": "run-p build:*",
|
|
21
|
-
"build:esm": "tsc -p tsconfig.build.json
|
|
22
|
-
"build:cjs": "tsc -p tsconfig.build.json
|
|
21
|
+
"build:esm": "tsc -p tsconfig.build.esm.json",
|
|
22
|
+
"build:cjs": "tsc -p tsconfig.build.cjs.json"
|
|
23
23
|
},
|
|
24
24
|
"author": "Zheng Yu Tay"
|
|
25
25
|
}
|