@shuvi/hook 1.0.0-rc.5 → 1.0.0-rc.8
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 +18 -19
- package/esm/hookGroup.js +11 -2
- package/lib/hookGroup.d.ts +18 -19
- package/lib/hookGroup.js +11 -2
- package/package.json +1 -1
package/esm/hookGroup.d.ts
CHANGED
|
@@ -5,34 +5,32 @@ export declare type AnyHook = SyncHook<any, any, any> | SyncBailHook<any, any, a
|
|
|
5
5
|
export interface HookMap {
|
|
6
6
|
[x: string]: AnyHook;
|
|
7
7
|
}
|
|
8
|
-
export declare type Setup<
|
|
9
|
-
addHooks: (hook: Partial<
|
|
8
|
+
export declare type Setup<HM extends HookMap = {}> = (utils: {
|
|
9
|
+
addHooks: (hook: Partial<HM>) => void;
|
|
10
10
|
}) => void;
|
|
11
|
-
export declare type CreatePlugin<HM extends HookMap, C
|
|
12
|
-
setup?: Setup
|
|
13
|
-
}, options?: PluginOptions) => IPluginInstance<HM
|
|
14
|
-
export declare type HookManager<HM extends HookMap, C
|
|
15
|
-
createPlugin:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
usePlugin: (...plugins: IPluginInstance<HM & EHM, C>[]) => void;
|
|
19
|
-
runner: RunnerType<HM, EHM>;
|
|
11
|
+
export declare type CreatePlugin<HM extends HookMap, C> = (pluginHandlers: IPluginHandlers<HM, C> & {
|
|
12
|
+
setup?: Setup;
|
|
13
|
+
}, options?: PluginOptions) => IPluginInstance<HM, C>;
|
|
14
|
+
export declare type HookManager<HM extends HookMap, C> = {
|
|
15
|
+
createPlugin: CreatePlugin<HM, C>;
|
|
16
|
+
usePlugin: (...plugins: IPluginInstance<HM, C>[]) => void;
|
|
17
|
+
runner: RunnerType<HM>;
|
|
20
18
|
setContext: (context: C) => void;
|
|
21
19
|
clear: () => void;
|
|
22
|
-
addHooks: (hook: Partial<EHM>) => void;
|
|
23
|
-
hooks: HM
|
|
24
|
-
getPlugins: () => IPluginInstance<HM
|
|
20
|
+
addHooks: <EHM extends HookMap>(hook: Partial<EHM>) => void;
|
|
21
|
+
hooks: HM;
|
|
22
|
+
getPlugins: () => IPluginInstance<HM, C>[];
|
|
25
23
|
};
|
|
26
|
-
export declare type RunnerType<HM
|
|
27
|
-
[K in keyof
|
|
24
|
+
export declare type RunnerType<HM> = {
|
|
25
|
+
[K in keyof HM]: HookRunnerType<HM[K]>;
|
|
28
26
|
} & {
|
|
29
|
-
setup: Setup
|
|
27
|
+
setup: Setup;
|
|
30
28
|
};
|
|
31
29
|
export declare 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 AsyncSeriesWaterfallHook<infer T, infer E> ? AsyncSeriesWaterfallHook<T, E>['run'] : never;
|
|
32
30
|
export declare type IPluginInstance<HM, C> = {
|
|
33
31
|
handlers: IPluginHandlers<HM, C>;
|
|
34
32
|
SYNC_PLUGIN_SYMBOL: 'SYNC_PLUGIN_SYMBOL';
|
|
35
|
-
} & PluginOptions
|
|
33
|
+
} & Required<PluginOptions>;
|
|
36
34
|
export declare type IPluginHandlers<HM, C> = Partial<IPluginHandlersFullMap<HM, C>>;
|
|
37
35
|
export declare type IPluginHandlersFullMap<HM, C> = {
|
|
38
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 AsyncSeriesWaterfallHook<infer T, infer E> ? PatchPluginParameter<AsyncSeriesWaterfallHookHandler<T, E>, C> : never;
|
|
@@ -44,6 +42,7 @@ export declare type PluginOptions = {
|
|
|
44
42
|
rivals?: string[];
|
|
45
43
|
required?: string[];
|
|
46
44
|
order?: number;
|
|
45
|
+
group?: number;
|
|
47
46
|
[x: string]: any;
|
|
48
47
|
};
|
|
49
48
|
export declare const DEFAULT_OPTIONS: Required<PluginOptions>;
|
|
@@ -52,5 +51,5 @@ export declare const isPluginInstance: (plugin: any) => any;
|
|
|
52
51
|
export declare type ArrayElements<T extends {}> = {
|
|
53
52
|
[K in keyof T]: T[K][];
|
|
54
53
|
};
|
|
55
|
-
export declare const createHookManager: <HM extends HookMap, C = void
|
|
54
|
+
export declare const createHookManager: <HM extends HookMap, C = void>(hookMap: HM, hasContext?: boolean) => HookManager<HM, C>;
|
|
56
55
|
export declare 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/esm/hookGroup.js
CHANGED
|
@@ -5,7 +5,8 @@ export const DEFAULT_OPTIONS = {
|
|
|
5
5
|
post: [],
|
|
6
6
|
rivals: [],
|
|
7
7
|
required: [],
|
|
8
|
-
order: 0
|
|
8
|
+
order: 0,
|
|
9
|
+
group: 0
|
|
9
10
|
};
|
|
10
11
|
export const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
|
11
12
|
export const isPluginInstance = (plugin) => plugin &&
|
|
@@ -13,7 +14,15 @@ export const isPluginInstance = (plugin) => plugin &&
|
|
|
13
14
|
plugin.SYNC_PLUGIN_SYMBOL === SYNC_PLUGIN_SYMBOL;
|
|
14
15
|
const sortPlugins = (input) => {
|
|
15
16
|
let plugins = input.slice();
|
|
16
|
-
plugins.sort((a, b) =>
|
|
17
|
+
plugins.sort((a, b) => {
|
|
18
|
+
// sort by group first
|
|
19
|
+
if (a.group === b.group) {
|
|
20
|
+
return a.order - b.order;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return a.group - b.group;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
17
26
|
for (let i = 0; i < plugins.length; i++) {
|
|
18
27
|
let plugin = plugins[i];
|
|
19
28
|
if (plugin.pre) {
|
package/lib/hookGroup.d.ts
CHANGED
|
@@ -5,34 +5,32 @@ export declare type AnyHook = SyncHook<any, any, any> | SyncBailHook<any, any, a
|
|
|
5
5
|
export interface HookMap {
|
|
6
6
|
[x: string]: AnyHook;
|
|
7
7
|
}
|
|
8
|
-
export declare type Setup<
|
|
9
|
-
addHooks: (hook: Partial<
|
|
8
|
+
export declare type Setup<HM extends HookMap = {}> = (utils: {
|
|
9
|
+
addHooks: (hook: Partial<HM>) => void;
|
|
10
10
|
}) => void;
|
|
11
|
-
export declare type CreatePlugin<HM extends HookMap, C
|
|
12
|
-
setup?: Setup
|
|
13
|
-
}, options?: PluginOptions) => IPluginInstance<HM
|
|
14
|
-
export declare type HookManager<HM extends HookMap, C
|
|
15
|
-
createPlugin:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
usePlugin: (...plugins: IPluginInstance<HM & EHM, C>[]) => void;
|
|
19
|
-
runner: RunnerType<HM, EHM>;
|
|
11
|
+
export declare type CreatePlugin<HM extends HookMap, C> = (pluginHandlers: IPluginHandlers<HM, C> & {
|
|
12
|
+
setup?: Setup;
|
|
13
|
+
}, options?: PluginOptions) => IPluginInstance<HM, C>;
|
|
14
|
+
export declare type HookManager<HM extends HookMap, C> = {
|
|
15
|
+
createPlugin: CreatePlugin<HM, C>;
|
|
16
|
+
usePlugin: (...plugins: IPluginInstance<HM, C>[]) => void;
|
|
17
|
+
runner: RunnerType<HM>;
|
|
20
18
|
setContext: (context: C) => void;
|
|
21
19
|
clear: () => void;
|
|
22
|
-
addHooks: (hook: Partial<EHM>) => void;
|
|
23
|
-
hooks: HM
|
|
24
|
-
getPlugins: () => IPluginInstance<HM
|
|
20
|
+
addHooks: <EHM extends HookMap>(hook: Partial<EHM>) => void;
|
|
21
|
+
hooks: HM;
|
|
22
|
+
getPlugins: () => IPluginInstance<HM, C>[];
|
|
25
23
|
};
|
|
26
|
-
export declare type RunnerType<HM
|
|
27
|
-
[K in keyof
|
|
24
|
+
export declare type RunnerType<HM> = {
|
|
25
|
+
[K in keyof HM]: HookRunnerType<HM[K]>;
|
|
28
26
|
} & {
|
|
29
|
-
setup: Setup
|
|
27
|
+
setup: Setup;
|
|
30
28
|
};
|
|
31
29
|
export declare 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 AsyncSeriesWaterfallHook<infer T, infer E> ? AsyncSeriesWaterfallHook<T, E>['run'] : never;
|
|
32
30
|
export declare type IPluginInstance<HM, C> = {
|
|
33
31
|
handlers: IPluginHandlers<HM, C>;
|
|
34
32
|
SYNC_PLUGIN_SYMBOL: 'SYNC_PLUGIN_SYMBOL';
|
|
35
|
-
} & PluginOptions
|
|
33
|
+
} & Required<PluginOptions>;
|
|
36
34
|
export declare type IPluginHandlers<HM, C> = Partial<IPluginHandlersFullMap<HM, C>>;
|
|
37
35
|
export declare type IPluginHandlersFullMap<HM, C> = {
|
|
38
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 AsyncSeriesWaterfallHook<infer T, infer E> ? PatchPluginParameter<AsyncSeriesWaterfallHookHandler<T, E>, C> : never;
|
|
@@ -44,6 +42,7 @@ export declare type PluginOptions = {
|
|
|
44
42
|
rivals?: string[];
|
|
45
43
|
required?: string[];
|
|
46
44
|
order?: number;
|
|
45
|
+
group?: number;
|
|
47
46
|
[x: string]: any;
|
|
48
47
|
};
|
|
49
48
|
export declare const DEFAULT_OPTIONS: Required<PluginOptions>;
|
|
@@ -52,5 +51,5 @@ export declare const isPluginInstance: (plugin: any) => any;
|
|
|
52
51
|
export declare type ArrayElements<T extends {}> = {
|
|
53
52
|
[K in keyof T]: T[K][];
|
|
54
53
|
};
|
|
55
|
-
export declare const createHookManager: <HM extends HookMap, C = void
|
|
54
|
+
export declare const createHookManager: <HM extends HookMap, C = void>(hookMap: HM, hasContext?: boolean) => HookManager<HM, C>;
|
|
56
55
|
export declare 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.js
CHANGED
|
@@ -8,7 +8,8 @@ exports.DEFAULT_OPTIONS = {
|
|
|
8
8
|
post: [],
|
|
9
9
|
rivals: [],
|
|
10
10
|
required: [],
|
|
11
|
-
order: 0
|
|
11
|
+
order: 0,
|
|
12
|
+
group: 0
|
|
12
13
|
};
|
|
13
14
|
exports.SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
|
14
15
|
const isPluginInstance = (plugin) => plugin &&
|
|
@@ -17,7 +18,15 @@ const isPluginInstance = (plugin) => plugin &&
|
|
|
17
18
|
exports.isPluginInstance = isPluginInstance;
|
|
18
19
|
const sortPlugins = (input) => {
|
|
19
20
|
let plugins = input.slice();
|
|
20
|
-
plugins.sort((a, b) =>
|
|
21
|
+
plugins.sort((a, b) => {
|
|
22
|
+
// sort by group first
|
|
23
|
+
if (a.group === b.group) {
|
|
24
|
+
return a.order - b.order;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return a.group - b.group;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
21
30
|
for (let i = 0; i < plugins.length; i++) {
|
|
22
31
|
let plugin = plugins[i];
|
|
23
32
|
if (plugin.pre) {
|