@shuvi/hook 1.0.0-rc.6 → 1.0.0-rc.9

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.
@@ -1,7 +1,7 @@
1
- import { SyncHook, SyncBailHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook, SyncHookHandler, SyncBailHookHandler, SyncWaterfallHookHandler, AsyncParallelHookHandler, AsyncSeriesWaterfallHookHandler } from './hooks';
1
+ import { SyncHook, SyncBailHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook, SyncHookHandler, SyncBailHookHandler, SyncWaterfallHookHandler, AsyncParallelHookHandler, AsyncSeriesWaterfallHookHandler, AsyncSeriesHook, AsyncSeriesBailHook, AsyncSeriesHookHandler, AsyncSeriesBailHookHandler } from './hooks';
2
2
  export declare type PatchPluginParameter<T, C> = RemoveManagerVoidParameter<AddContextParameter<T, C>>;
3
3
  export declare type AddContextParameter<T, C> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? (initalValue: I, extraArg: E, context: C) => R : T;
4
- export declare type AnyHook = SyncHook<any, any, any> | SyncBailHook<any, any, any> | SyncWaterfallHook<any, any> | AsyncParallelHook<any, any, any> | AsyncSeriesWaterfallHook<any, any>;
4
+ export declare 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
  }
@@ -26,14 +26,14 @@ export declare type RunnerType<HM> = {
26
26
  } & {
27
27
  setup: Setup;
28
28
  };
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;
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 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
30
  export declare type IPluginInstance<HM, C> = {
31
31
  handlers: IPluginHandlers<HM, C>;
32
32
  SYNC_PLUGIN_SYMBOL: 'SYNC_PLUGIN_SYMBOL';
33
33
  } & Required<PluginOptions>;
34
34
  export declare type IPluginHandlers<HM, C> = Partial<IPluginHandlersFullMap<HM, C>>;
35
35
  export declare type IPluginHandlersFullMap<HM, C> = {
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;
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
38
  export declare type PluginOptions = {
39
39
  name?: string;
package/esm/hookGroup.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createSyncHook, createSyncBailHook, createSyncWaterfallHook, createAsyncParallelHook, createAsyncSeriesWaterfallHook } from './hooks';
1
+ import { createSyncHook, createSyncBailHook, createSyncWaterfallHook, createAsyncParallelHook, createAsyncSeriesWaterfallHook, createAsyncSeriesBailHook, createAsyncSeriesHook } from './hooks';
2
2
  export const DEFAULT_OPTIONS = {
3
3
  name: 'untitled',
4
4
  pre: [],
@@ -99,6 +99,12 @@ const copyHookMap = (hookMap) => {
99
99
  case 'AsyncParallelHook':
100
100
  newHookMap[hookName] = createAsyncParallelHook();
101
101
  break;
102
+ case 'AsyncSeriesHook':
103
+ newHookMap[hookName] = createAsyncSeriesHook();
104
+ break;
105
+ case 'AsyncSeriesBailHook':
106
+ newHookMap[hookName] = createAsyncSeriesBailHook();
107
+ break;
102
108
  case 'AsyncSeriesWaterfallHook':
103
109
  newHookMap[hookName] = createAsyncSeriesWaterfallHook();
104
110
  break;
package/esm/hooks.d.ts CHANGED
@@ -5,6 +5,8 @@ export declare type Remove3VoidParameter<T> = T extends (initalValue: infer I, e
5
5
  export declare type SyncHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R;
6
6
  export declare type SyncBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R | undefined | void;
7
7
  export declare type SyncWaterfallHookHandler<I, E> = (initalValue: I, extraArgs: E) => I;
8
+ export declare type AsyncSeriesHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R> | R;
9
+ export declare type AsyncSeriesBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R | undefined | void> | R | undefined | void;
8
10
  export declare type AsyncSeriesWaterfallHookHandler<I, E> = (initalValue: I, extraArg: E) => Promise<I> | I;
9
11
  export declare type AsyncParallelHookHandler<I, E, R> = (initalValue: I, extraArgs: E) => Promise<R> | R;
10
12
  /** Normal hook. */
@@ -28,15 +30,19 @@ export declare type SyncWaterfallHook<I, E = void> = {
28
30
  clear: () => void;
29
31
  type: string;
30
32
  };
31
- /** Normal async hook. No return value
32
- *
33
- * RemoveVoidParameter<(
34
- null extends R ?
35
- (R extends void ? ((initalValue: I, extraArg: E) => Promise<R[]>) :
36
- ((initalValue: I, extraArg: E) => Promise<R[]>)) :
37
- ((initalValue: I, extraArg: E) => Promise<R[]>)
38
- )>
39
- */
33
+ export declare type AsyncSeriesHook<I = void, E = void, R = void> = {
34
+ use: (...handlers: RemoveVoidParameter<AsyncSeriesHookHandler<I, E, R>>[]) => void;
35
+ run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
36
+ clear: () => void;
37
+ type: string;
38
+ };
39
+ export declare type AsyncSeriesBailHook<I = void, E = void, R = I> = {
40
+ use: (...handlers: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>[]) => void;
41
+ run: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>;
42
+ clear: () => void;
43
+ type: string;
44
+ };
45
+ /** Normal async parallel hook */
40
46
  export declare type AsyncParallelHook<I = void, E = void, R = void> = {
41
47
  use: (...handlers: RemoveVoidParameter<AsyncParallelHookHandler<I, E, R>>[]) => void;
42
48
  run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
@@ -54,4 +60,6 @@ export declare const createSyncHook: <I = void, E = void, R = void>() => SyncHoo
54
60
  export declare const createSyncBailHook: <I = void, E = void, R = I>() => SyncBailHook<I, E, R>;
55
61
  export declare const createSyncWaterfallHook: <I = void, E = void>() => SyncWaterfallHook<I, E>;
56
62
  export declare const createAsyncParallelHook: <I = void, E = void, R = void>() => AsyncParallelHook<I, E, R>;
63
+ export declare const createAsyncSeriesHook: <I = void, E = void, R = void>() => AsyncSeriesHook<I, E, R>;
64
+ export declare const createAsyncSeriesBailHook: <I = void, E = void, R = I>() => AsyncSeriesBailHook<I, E, R>;
57
65
  export declare const createAsyncSeriesWaterfallHook: <I = void, E = void>() => AsyncSeriesWaterfallHook<I, E>;
package/esm/hooks.js CHANGED
@@ -97,6 +97,56 @@ export const createAsyncParallelHook = () => {
97
97
  type: 'AsyncParallelHook'
98
98
  };
99
99
  };
100
+ export const createAsyncSeriesHook = () => {
101
+ let _handlers = [];
102
+ const use = (...handlers) => {
103
+ _handlers.push(...handlers);
104
+ };
105
+ const run = (...args) => __awaiter(void 0, void 0, void 0, function* () {
106
+ const result = [];
107
+ for (let i = 0; i < _handlers.length; i++) {
108
+ const handler = _handlers[i];
109
+ // @ts-ignore
110
+ const currentResult = yield handler(...args);
111
+ result.push(currentResult);
112
+ }
113
+ return result;
114
+ });
115
+ const clear = () => {
116
+ _handlers = [];
117
+ };
118
+ return {
119
+ use,
120
+ run,
121
+ clear,
122
+ type: 'AsyncSeriesHook'
123
+ };
124
+ };
125
+ export const createAsyncSeriesBailHook = () => {
126
+ let _handlers = [];
127
+ const use = (...handlers) => {
128
+ _handlers.push(...handlers);
129
+ };
130
+ const run = (...args) => __awaiter(void 0, void 0, void 0, function* () {
131
+ for (let i = 0; i < _handlers.length; i++) {
132
+ const handler = _handlers[i];
133
+ // @ts-ignore
134
+ const result = yield handler(...args);
135
+ if (result !== undefined)
136
+ return result;
137
+ }
138
+ return undefined;
139
+ });
140
+ const clear = () => {
141
+ _handlers = [];
142
+ };
143
+ return {
144
+ use,
145
+ run,
146
+ clear,
147
+ type: 'AsyncSeriesHook'
148
+ };
149
+ };
100
150
  export const createAsyncSeriesWaterfallHook = () => {
101
151
  let _handlers = [];
102
152
  const use = (...handlers) => {
@@ -1,7 +1,7 @@
1
- import { SyncHook, SyncBailHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook, SyncHookHandler, SyncBailHookHandler, SyncWaterfallHookHandler, AsyncParallelHookHandler, AsyncSeriesWaterfallHookHandler } from './hooks';
1
+ import { SyncHook, SyncBailHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook, SyncHookHandler, SyncBailHookHandler, SyncWaterfallHookHandler, AsyncParallelHookHandler, AsyncSeriesWaterfallHookHandler, AsyncSeriesHook, AsyncSeriesBailHook, AsyncSeriesHookHandler, AsyncSeriesBailHookHandler } from './hooks';
2
2
  export declare type PatchPluginParameter<T, C> = RemoveManagerVoidParameter<AddContextParameter<T, C>>;
3
3
  export declare type AddContextParameter<T, C> = T extends (initalValue: infer I, extraArg: infer E) => infer R ? (initalValue: I, extraArg: E, context: C) => R : T;
4
- export declare type AnyHook = SyncHook<any, any, any> | SyncBailHook<any, any, any> | SyncWaterfallHook<any, any> | AsyncParallelHook<any, any, any> | AsyncSeriesWaterfallHook<any, any>;
4
+ export declare 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
  }
@@ -26,14 +26,14 @@ export declare type RunnerType<HM> = {
26
26
  } & {
27
27
  setup: Setup;
28
28
  };
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;
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 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
30
  export declare type IPluginInstance<HM, C> = {
31
31
  handlers: IPluginHandlers<HM, C>;
32
32
  SYNC_PLUGIN_SYMBOL: 'SYNC_PLUGIN_SYMBOL';
33
33
  } & Required<PluginOptions>;
34
34
  export declare type IPluginHandlers<HM, C> = Partial<IPluginHandlersFullMap<HM, C>>;
35
35
  export declare type IPluginHandlersFullMap<HM, C> = {
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;
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
38
  export declare type PluginOptions = {
39
39
  name?: string;
package/lib/hookGroup.js CHANGED
@@ -103,6 +103,12 @@ const copyHookMap = (hookMap) => {
103
103
  case 'AsyncParallelHook':
104
104
  newHookMap[hookName] = (0, hooks_1.createAsyncParallelHook)();
105
105
  break;
106
+ case 'AsyncSeriesHook':
107
+ newHookMap[hookName] = (0, hooks_1.createAsyncSeriesHook)();
108
+ break;
109
+ case 'AsyncSeriesBailHook':
110
+ newHookMap[hookName] = (0, hooks_1.createAsyncSeriesBailHook)();
111
+ break;
106
112
  case 'AsyncSeriesWaterfallHook':
107
113
  newHookMap[hookName] = (0, hooks_1.createAsyncSeriesWaterfallHook)();
108
114
  break;
package/lib/hooks.d.ts CHANGED
@@ -5,6 +5,8 @@ export declare type Remove3VoidParameter<T> = T extends (initalValue: infer I, e
5
5
  export declare type SyncHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R;
6
6
  export declare type SyncBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => R | undefined | void;
7
7
  export declare type SyncWaterfallHookHandler<I, E> = (initalValue: I, extraArgs: E) => I;
8
+ export declare type AsyncSeriesHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R> | R;
9
+ export declare type AsyncSeriesBailHookHandler<I, E, R> = (initalValue: I, extraArg: E) => Promise<R | undefined | void> | R | undefined | void;
8
10
  export declare type AsyncSeriesWaterfallHookHandler<I, E> = (initalValue: I, extraArg: E) => Promise<I> | I;
9
11
  export declare type AsyncParallelHookHandler<I, E, R> = (initalValue: I, extraArgs: E) => Promise<R> | R;
10
12
  /** Normal hook. */
@@ -28,15 +30,19 @@ export declare type SyncWaterfallHook<I, E = void> = {
28
30
  clear: () => void;
29
31
  type: string;
30
32
  };
31
- /** Normal async hook. No return value
32
- *
33
- * RemoveVoidParameter<(
34
- null extends R ?
35
- (R extends void ? ((initalValue: I, extraArg: E) => Promise<R[]>) :
36
- ((initalValue: I, extraArg: E) => Promise<R[]>)) :
37
- ((initalValue: I, extraArg: E) => Promise<R[]>)
38
- )>
39
- */
33
+ export declare type AsyncSeriesHook<I = void, E = void, R = void> = {
34
+ use: (...handlers: RemoveVoidParameter<AsyncSeriesHookHandler<I, E, R>>[]) => void;
35
+ run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
36
+ clear: () => void;
37
+ type: string;
38
+ };
39
+ export declare type AsyncSeriesBailHook<I = void, E = void, R = I> = {
40
+ use: (...handlers: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>[]) => void;
41
+ run: RemoveVoidParameter<AsyncSeriesBailHookHandler<I, E, R>>;
42
+ clear: () => void;
43
+ type: string;
44
+ };
45
+ /** Normal async parallel hook */
40
46
  export declare type AsyncParallelHook<I = void, E = void, R = void> = {
41
47
  use: (...handlers: RemoveVoidParameter<AsyncParallelHookHandler<I, E, R>>[]) => void;
42
48
  run: RemoveVoidParameter<(initalValue: I, extraArg: E) => Promise<R[]>>;
@@ -54,4 +60,6 @@ export declare const createSyncHook: <I = void, E = void, R = void>() => SyncHoo
54
60
  export declare const createSyncBailHook: <I = void, E = void, R = I>() => SyncBailHook<I, E, R>;
55
61
  export declare const createSyncWaterfallHook: <I = void, E = void>() => SyncWaterfallHook<I, E>;
56
62
  export declare const createAsyncParallelHook: <I = void, E = void, R = void>() => AsyncParallelHook<I, E, R>;
63
+ export declare const createAsyncSeriesHook: <I = void, E = void, R = void>() => AsyncSeriesHook<I, E, R>;
64
+ export declare const createAsyncSeriesBailHook: <I = void, E = void, R = I>() => AsyncSeriesBailHook<I, E, R>;
57
65
  export declare const createAsyncSeriesWaterfallHook: <I = void, E = void>() => AsyncSeriesWaterfallHook<I, E>;
package/lib/hooks.js CHANGED
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  });
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.createAsyncSeriesWaterfallHook = exports.createAsyncParallelHook = exports.createSyncWaterfallHook = exports.createSyncBailHook = exports.createSyncHook = void 0;
14
+ exports.createAsyncSeriesWaterfallHook = exports.createAsyncSeriesBailHook = exports.createAsyncSeriesHook = exports.createAsyncParallelHook = exports.createSyncWaterfallHook = exports.createSyncBailHook = exports.createSyncHook = void 0;
15
15
  const createSyncHook = () => {
16
16
  let _handlers = [];
17
17
  const use = (...handlers) => {
@@ -104,6 +104,58 @@ const createAsyncParallelHook = () => {
104
104
  };
105
105
  };
106
106
  exports.createAsyncParallelHook = createAsyncParallelHook;
107
+ const createAsyncSeriesHook = () => {
108
+ let _handlers = [];
109
+ const use = (...handlers) => {
110
+ _handlers.push(...handlers);
111
+ };
112
+ const run = (...args) => __awaiter(void 0, void 0, void 0, function* () {
113
+ const result = [];
114
+ for (let i = 0; i < _handlers.length; i++) {
115
+ const handler = _handlers[i];
116
+ // @ts-ignore
117
+ const currentResult = yield handler(...args);
118
+ result.push(currentResult);
119
+ }
120
+ return result;
121
+ });
122
+ const clear = () => {
123
+ _handlers = [];
124
+ };
125
+ return {
126
+ use,
127
+ run,
128
+ clear,
129
+ type: 'AsyncSeriesHook'
130
+ };
131
+ };
132
+ exports.createAsyncSeriesHook = createAsyncSeriesHook;
133
+ const createAsyncSeriesBailHook = () => {
134
+ let _handlers = [];
135
+ const use = (...handlers) => {
136
+ _handlers.push(...handlers);
137
+ };
138
+ const run = (...args) => __awaiter(void 0, void 0, void 0, function* () {
139
+ for (let i = 0; i < _handlers.length; i++) {
140
+ const handler = _handlers[i];
141
+ // @ts-ignore
142
+ const result = yield handler(...args);
143
+ if (result !== undefined)
144
+ return result;
145
+ }
146
+ return undefined;
147
+ });
148
+ const clear = () => {
149
+ _handlers = [];
150
+ };
151
+ return {
152
+ use,
153
+ run,
154
+ clear,
155
+ type: 'AsyncSeriesHook'
156
+ };
157
+ };
158
+ exports.createAsyncSeriesBailHook = createAsyncSeriesBailHook;
107
159
  const createAsyncSeriesWaterfallHook = () => {
108
160
  let _handlers = [];
109
161
  const use = (...handlers) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/hook",
3
- "version": "1.0.0-rc.6",
3
+ "version": "1.0.0-rc.9",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",