@modern-js/plugin 1.2.1 → 1.3.2

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/js/modern/manager/async.js +59 -28
  3. package/dist/js/modern/manager/index.js +2 -1
  4. package/dist/js/modern/manager/sync.js +79 -60
  5. package/dist/js/modern/manager/types.js +0 -0
  6. package/dist/js/modern/waterfall/async.js +0 -1
  7. package/dist/js/modern/waterfall/sync.js +0 -1
  8. package/dist/js/modern/workflow/async.js +1 -2
  9. package/dist/js/modern/workflow/sync.js +0 -1
  10. package/dist/js/node/manager/async.js +57 -25
  11. package/dist/js/node/manager/index.js +13 -0
  12. package/dist/js/node/manager/sync.js +84 -58
  13. package/dist/js/node/manager/types.js +0 -0
  14. package/dist/js/node/waterfall/async.js +0 -1
  15. package/dist/js/node/waterfall/sync.js +0 -1
  16. package/dist/js/node/workflow/async.js +1 -2
  17. package/dist/js/node/workflow/sync.js +0 -1
  18. package/dist/js/treeshaking/manager/async.js +63 -34
  19. package/dist/js/treeshaking/manager/index.js +2 -1
  20. package/dist/js/treeshaking/manager/sync.js +85 -62
  21. package/dist/js/treeshaking/manager/types.js +0 -0
  22. package/dist/js/treeshaking/waterfall/async.js +0 -1
  23. package/dist/js/treeshaking/waterfall/sync.js +0 -1
  24. package/dist/js/treeshaking/workflow/async.js +1 -2
  25. package/dist/js/treeshaking/workflow/sync.js +0 -1
  26. package/dist/types/manager/async.d.ts +60 -21
  27. package/dist/types/manager/index.d.ts +2 -1
  28. package/dist/types/manager/sync.d.ts +74 -43
  29. package/dist/types/manager/types.d.ts +41 -0
  30. package/package.json +3 -3
  31. package/tests/async.test.ts +166 -22
  32. package/tests/fixtures/async/core/index.ts +12 -4
  33. package/tests/fixtures/async/dynamic/foo.ts +2 -2
  34. package/tests/fixtures/sync/core/index.ts +9 -4
  35. package/tests/fixtures/sync/dynamic/foo.ts +2 -2
  36. package/tests/sync.test.ts +158 -21
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 1.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - dc88abf9: fix: should allow to use plugin without setup function
8
+ - 0462ff77: feat: add compatible logic of plugin options with "setup" param
9
+
10
+ ## 1.3.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 80d8ddfe: feat: support `setup`, `registerHook`, `usePlugins` in plugin options.
15
+
16
+ ### Patch Changes
17
+
18
+ - 491145e3: feat: allow manger.clone to override pluginAPI
19
+
3
20
  ## 1.2.1
4
21
 
5
22
  ### Patch Changes
@@ -5,48 +5,76 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
7
  import { runWithContainer, createContainer } from 'farrow-pipeline';
8
- import { generateRunner, hasOwnProperty, DEFAULT_OPTIONS } from "./sync";
9
- import { useRunner } from "./runner"; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
10
-
8
+ import { isObject, generateRunner, hasOwnProperty, DEFAULT_OPTIONS } from "./sync";
9
+ import { useRunner } from "./runner";
11
10
  const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
12
- export const createAsyncManager = processes => {
11
+ export const createAsyncManager = (hooks, api) => {
13
12
  let index = 0;
14
13
 
15
- const createPlugin = (initializer, options = {}) => _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
16
- name: `No.${index++} plugin`
17
- }, options), {}, {
18
- ASYNC_PLUGIN_SYMBOL,
19
- initializer
20
- });
21
-
22
- const isPlugin = input => hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
14
+ let currentHooks = _objectSpread({}, hooks);
23
15
 
24
- const registe = extraProcesses => {
25
- // eslint-disable-next-line no-param-reassign
26
- processes = _objectSpread(_objectSpread({}, extraProcesses), processes);
16
+ const registerHook = extraHooks => {
17
+ currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
27
18
  };
28
19
 
29
- const clone = () => {
20
+ const isPlugin = input => isObject(input) && hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
21
+
22
+ const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
23
+ useHookRunners: useRunner
24
+ });
25
+
26
+ const clone = overrideAPI => {
30
27
  let plugins = [];
31
28
 
29
+ const addPlugin = plugin => {
30
+ if (!includeAsyncPlugin(plugins, plugin)) {
31
+ plugins.push(_objectSpread({}, plugin));
32
+ }
33
+ };
34
+
32
35
  const usePlugin = (...input) => {
33
36
  for (const plugin of input) {
37
+ // already created by createPlugin
34
38
  if (isPlugin(plugin)) {
35
- if (!includeAsyncPlugin(plugins, plugin)) {
36
- plugins.push(_objectSpread(_objectSpread({}, plugin), {}, {
37
- index: plugins.length
38
- }));
39
- }
40
- } else {
41
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
42
- // @ts-expect-error
43
- console.warn(`Unknown plugin: ${plugin.name}`);
39
+ addPlugin(plugin);
40
+ } // using function to return plugin options
41
+ else if (typeof plugin === 'function') {
42
+ const options = plugin();
43
+ addPlugin(createPlugin(options.setup, options));
44
+ } // plain plugin object
45
+ else if (isObject(plugin)) {
46
+ addPlugin(createPlugin(plugin.setup, plugin));
47
+ } // unknown plugin
48
+ else {
49
+ console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
44
50
  }
45
51
  }
46
52
 
47
53
  return manager;
48
54
  };
49
55
 
56
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
57
+ setup = () => {}, options = {}) => {
58
+ var _options$usePlugins;
59
+
60
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
61
+ options.usePlugins.forEach(plugin => {
62
+ usePlugin(createPlugin(plugin.setup, plugin));
63
+ });
64
+ }
65
+
66
+ if (options.registerHook) {
67
+ registerHook(options.registerHook);
68
+ }
69
+
70
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
71
+ name: `No.${index++} plugin`
72
+ }, options), {}, {
73
+ ASYNC_PLUGIN_SYMBOL,
74
+ setup
75
+ });
76
+ };
77
+
50
78
  const clear = () => {
51
79
  plugins = [];
52
80
  };
@@ -56,9 +84,12 @@ export const createAsyncManager = processes => {
56
84
  const init = async options => {
57
85
  const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
58
86
  const sortedPlugins = sortAsyncPlugins(plugins);
87
+
88
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
89
+
59
90
  checkAsyncPlugins(sortedPlugins);
60
- const hooksList = await Promise.all(sortedPlugins.map(plugin => runWithContainer(() => plugin.initializer(), container)));
61
- return generateRunner(hooksList, container, processes);
91
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container)));
92
+ return generateRunner(hooksList, container, currentHooks);
62
93
  };
63
94
 
64
95
  const run = (cb, options) => {
@@ -74,7 +105,7 @@ export const createAsyncManager = processes => {
74
105
  run,
75
106
  clear,
76
107
  clone,
77
- registe,
108
+ registerHook,
78
109
  useRunner
79
110
  };
80
111
  return manager;
@@ -1,3 +1,4 @@
1
1
  export * from "./sync";
2
2
  export * from "./async";
3
- export * from "./runner";
3
+ export * from "./runner";
4
+ export * from "./types";
@@ -4,68 +4,85 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- // eslint-disable-next-line eslint-comments/disable-enable-pair
8
-
9
- /* eslint-disable max-lines */
10
7
  import { isPipeline, createPipeline, runWithContainer, createContainer } from 'farrow-pipeline';
11
8
  import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
12
9
  import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
13
- import { RunnerContext, useRunner } from "./runner"; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
14
-
10
+ import { RunnerContext, useRunner } from "./runner";
15
11
  const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
16
12
  export const DEFAULT_OPTIONS = {
17
13
  name: 'untitled',
18
14
  pre: [],
19
15
  post: [],
20
16
  rivals: [],
21
- required: []
17
+ required: [],
18
+ usePlugins: [],
19
+ registerHook: {}
22
20
  };
23
- export const createManager = processes => {
21
+ export const createManager = (hooks, api) => {
24
22
  let index = 0;
25
23
 
26
- const createPlugin = (initializer, options = {}) => _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
27
- name: `No.${index++} plugin`
28
- }, options), {}, {
29
- SYNC_PLUGIN_SYMBOL,
30
- initializer
31
- });
32
-
33
- const isPlugin = input => hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
24
+ let currentHooks = _objectSpread({}, hooks);
34
25
 
35
- const registe = extraProcesses => {
36
- // eslint-disable-next-line no-param-reassign
37
- processes = _objectSpread(_objectSpread({}, extraProcesses), processes);
26
+ const registerHook = extraHooks => {
27
+ currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
38
28
  };
39
29
 
40
- const clone = () => {
30
+ const isPlugin = input => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
31
+
32
+ const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
33
+ useHookRunners: useRunner
34
+ });
35
+
36
+ const clone = overrideAPI => {
41
37
  let plugins = [];
42
38
 
39
+ const addPlugin = plugin => {
40
+ if (!includePlugin(plugins, plugin)) {
41
+ plugins.push(_objectSpread({}, plugin));
42
+ }
43
+ };
44
+
43
45
  const usePlugin = (...input) => {
44
46
  for (const plugin of input) {
47
+ // already created by createPlugin
45
48
  if (isPlugin(plugin)) {
46
- if (!includePlugin(plugins, plugin)) {
47
- plugins.push(_objectSpread(_objectSpread({}, plugin), {}, {
48
- index: plugins.length
49
- }));
50
- }
51
- } else {
52
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
53
- // @ts-expect-error
54
- console.warn(`Unknown plugin: ${plugin.name}`);
49
+ addPlugin(plugin);
50
+ } // using function to return plugin options
51
+ else if (typeof plugin === 'function') {
52
+ const options = plugin();
53
+ addPlugin(createPlugin(options.setup, options));
54
+ } // plain plugin object
55
+ else if (isObject(plugin)) {
56
+ addPlugin(createPlugin(plugin.setup, plugin));
57
+ } // unknown plugin
58
+ else {
59
+ console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
55
60
  }
56
61
  }
57
62
 
58
- return {
59
- createPlugin,
60
- isPlugin,
61
- usePlugin,
62
- init,
63
- run,
64
- clear,
65
- registe,
66
- useRunner,
67
- clone
68
- };
63
+ return manager;
64
+ };
65
+
66
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
67
+ setup = () => {}, options = {}) => {
68
+ var _options$usePlugins;
69
+
70
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
71
+ options.usePlugins.forEach(plugin => {
72
+ usePlugin(createPlugin(plugin.setup, plugin));
73
+ });
74
+ }
75
+
76
+ if (options.registerHook) {
77
+ registerHook(options.registerHook);
78
+ }
79
+
80
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
81
+ name: `No.${index++} plugin`
82
+ }, options), {}, {
83
+ SYNC_PLUGIN_SYMBOL,
84
+ setup
85
+ });
69
86
  };
70
87
 
71
88
  const clear = () => {
@@ -77,9 +94,12 @@ export const createManager = processes => {
77
94
  const init = options => {
78
95
  const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
79
96
  const sortedPlugins = sortPlugins(plugins);
97
+
98
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
99
+
80
100
  checkPlugins(sortedPlugins);
81
- const hooksList = sortedPlugins.map(plugin => runWithContainer(() => plugin.initializer(), container));
82
- return generateRunner(hooksList, container, processes);
101
+ const hooksList = sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container));
102
+ return generateRunner(hooksList, container, currentHooks);
83
103
  };
84
104
 
85
105
  const run = (cb, options) => {
@@ -87,26 +107,27 @@ export const createManager = processes => {
87
107
  return runWithContainer(cb, container);
88
108
  };
89
109
 
90
- return {
110
+ const manager = {
91
111
  createPlugin,
92
112
  isPlugin,
93
113
  usePlugin,
94
114
  init,
95
115
  clear,
96
116
  run,
97
- registe,
117
+ registerHook,
98
118
  useRunner,
99
119
  clone
100
120
  };
121
+ return manager;
101
122
  };
102
123
 
103
124
  return clone();
104
125
  };
105
- export const generateRunner = (hooksList, container, processes) => {
126
+ export const generateRunner = (hooksList, container, hooksMap) => {
106
127
  const runner = {};
107
- const cloneShape = cloneProgressRecord(processes);
128
+ const cloneShape = closeHooksMap(hooksMap);
108
129
 
109
- if (processes) {
130
+ if (hooksMap) {
110
131
  for (const key in cloneShape) {
111
132
  for (const hooks of hooksList) {
112
133
  if (!hooks) {
@@ -114,8 +135,6 @@ export const generateRunner = (hooksList, container, processes) => {
114
135
  }
115
136
 
116
137
  if (hooks[key]) {
117
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
118
- // @ts-expect-error
119
138
  cloneShape[key].use(hooks[key]);
120
139
  }
121
140
  } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -131,36 +150,35 @@ export const generateRunner = (hooksList, container, processes) => {
131
150
  container.write(RunnerContext, runner);
132
151
  return runner;
133
152
  };
134
- export const cloneProgress = progress => {
135
- if (isWaterfall(progress)) {
153
+ export const cloneHook = hook => {
154
+ if (isWaterfall(hook)) {
136
155
  return createWaterfall();
137
156
  }
138
157
 
139
- if (isAsyncWaterfall(progress)) {
158
+ if (isAsyncWaterfall(hook)) {
140
159
  return createAsyncWaterfall();
141
160
  }
142
161
 
143
- if (isWorkflow(progress)) {
162
+ if (isWorkflow(hook)) {
144
163
  return createWorkflow();
145
164
  }
146
165
 
147
- if (isAsyncWorkflow(progress)) {
166
+ if (isAsyncWorkflow(hook)) {
148
167
  return createAsyncWorkflow();
149
168
  }
150
169
 
151
- if (isParallelWorkflow(progress)) {
170
+ if (isParallelWorkflow(hook)) {
152
171
  return createParallelWorkflow();
153
172
  }
154
173
 
155
- if (isPipeline(progress)) {
174
+ if (isPipeline(hook)) {
156
175
  return createPipeline();
157
176
  } // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
158
177
 
159
178
 
160
- throw new Error(`Unknown progress: ${progress}`);
161
- }; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
162
-
163
- export const cloneProgressRecord = record => {
179
+ throw new Error(`Unknown hook: ${hook}`);
180
+ };
181
+ export const closeHooksMap = record => {
164
182
  if (!record) {
165
183
  return record;
166
184
  }
@@ -170,7 +188,7 @@ export const cloneProgressRecord = record => {
170
188
  for (const key in record) {
171
189
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
172
190
  // @ts-expect-error
173
- result[key] = cloneProgress(record[key]);
191
+ result[key] = cloneHook(record[key]);
174
192
  }
175
193
 
176
194
  return result;
@@ -230,4 +248,5 @@ const checkPlugins = plugins => {
230
248
  }
231
249
  };
232
250
 
251
+ export const isObject = obj => obj !== null && typeof obj === 'object';
233
252
  export const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
File without changes
@@ -16,7 +16,6 @@ export const getAsyncBrook = input => {
16
16
 
17
17
  throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
18
18
  };
19
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
20
19
  export const createAsyncWaterfall = () => {
21
20
  const pipeline = createAsyncPipeline();
22
21
 
@@ -16,7 +16,6 @@ export const getBrook = input => {
16
16
 
17
17
  throw new Error(`${input} is not a Brook or { brook: Brook }`);
18
18
  };
19
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
20
19
  export const createWaterfall = () => {
21
20
  const pipeline = createPipeline();
22
21
 
@@ -6,8 +6,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import { createAsyncPipeline } from 'farrow-pipeline';
8
8
  const ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
9
- export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]); // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
10
-
9
+ export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
11
10
  export const createAsyncWorkflow = () => {
12
11
  const pipeline = createAsyncPipeline();
13
12
 
@@ -6,7 +6,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import { createPipeline } from 'farrow-pipeline';
8
8
  const WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
9
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
10
9
  export const createWorkflow = () => {
11
10
  const pipeline = createPipeline();
12
11
 
@@ -19,44 +19,73 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
19
19
 
20
20
  const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
21
21
 
22
- const createAsyncManager = processes => {
22
+ const createAsyncManager = (hooks, api) => {
23
23
  let index = 0;
24
24
 
25
- const createPlugin = (initializer, options = {}) => _objectSpread(_objectSpread(_objectSpread({}, _sync.DEFAULT_OPTIONS), {}, {
26
- name: `No.${index++} plugin`
27
- }, options), {}, {
28
- ASYNC_PLUGIN_SYMBOL,
29
- initializer
30
- });
31
-
32
- const isPlugin = input => (0, _sync.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
25
+ let currentHooks = _objectSpread({}, hooks);
33
26
 
34
- const registe = extraProcesses => {
35
- // eslint-disable-next-line no-param-reassign
36
- processes = _objectSpread(_objectSpread({}, extraProcesses), processes);
27
+ const registerHook = extraHooks => {
28
+ currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
37
29
  };
38
30
 
39
- const clone = () => {
31
+ const isPlugin = input => (0, _sync.isObject)(input) && (0, _sync.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
32
+
33
+ const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
34
+ useHookRunners: _runner.useRunner
35
+ });
36
+
37
+ const clone = overrideAPI => {
40
38
  let plugins = [];
41
39
 
40
+ const addPlugin = plugin => {
41
+ if (!includeAsyncPlugin(plugins, plugin)) {
42
+ plugins.push(_objectSpread({}, plugin));
43
+ }
44
+ };
45
+
42
46
  const usePlugin = (...input) => {
43
47
  for (const plugin of input) {
48
+ // already created by createPlugin
44
49
  if (isPlugin(plugin)) {
45
- if (!includeAsyncPlugin(plugins, plugin)) {
46
- plugins.push(_objectSpread(_objectSpread({}, plugin), {}, {
47
- index: plugins.length
48
- }));
49
- }
50
- } else {
51
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
52
- // @ts-expect-error
53
- console.warn(`Unknown plugin: ${plugin.name}`);
50
+ addPlugin(plugin);
51
+ } // using function to return plugin options
52
+ else if (typeof plugin === 'function') {
53
+ const options = plugin();
54
+ addPlugin(createPlugin(options.setup, options));
55
+ } // plain plugin object
56
+ else if ((0, _sync.isObject)(plugin)) {
57
+ addPlugin(createPlugin(plugin.setup, plugin));
58
+ } // unknown plugin
59
+ else {
60
+ console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
54
61
  }
55
62
  }
56
63
 
57
64
  return manager;
58
65
  };
59
66
 
67
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
68
+ setup = () => {}, options = {}) => {
69
+ var _options$usePlugins;
70
+
71
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
72
+ options.usePlugins.forEach(plugin => {
73
+ usePlugin(createPlugin(plugin.setup, plugin));
74
+ });
75
+ }
76
+
77
+ if (options.registerHook) {
78
+ registerHook(options.registerHook);
79
+ }
80
+
81
+ return _objectSpread(_objectSpread(_objectSpread({}, _sync.DEFAULT_OPTIONS), {}, {
82
+ name: `No.${index++} plugin`
83
+ }, options), {}, {
84
+ ASYNC_PLUGIN_SYMBOL,
85
+ setup
86
+ });
87
+ };
88
+
60
89
  const clear = () => {
61
90
  plugins = [];
62
91
  };
@@ -66,9 +95,12 @@ const createAsyncManager = processes => {
66
95
  const init = async options => {
67
96
  const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
68
97
  const sortedPlugins = sortAsyncPlugins(plugins);
98
+
99
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
100
+
69
101
  checkAsyncPlugins(sortedPlugins);
70
- const hooksList = await Promise.all(sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.initializer(), container)));
71
- return (0, _sync.generateRunner)(hooksList, container, processes);
102
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.setup(mergedPluginAPI), container)));
103
+ return (0, _sync.generateRunner)(hooksList, container, currentHooks);
72
104
  };
73
105
 
74
106
  const run = (cb, options) => {
@@ -84,7 +116,7 @@ const createAsyncManager = processes => {
84
116
  run,
85
117
  clear,
86
118
  clone,
87
- registe,
119
+ registerHook,
88
120
  useRunner: _runner.useRunner
89
121
  };
90
122
  return manager;
@@ -41,4 +41,17 @@ Object.keys(_runner).forEach(function (key) {
41
41
  return _runner[key];
42
42
  }
43
43
  });
44
+ });
45
+
46
+ var _types = require("./types");
47
+
48
+ Object.keys(_types).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _types[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _types[key];
55
+ }
56
+ });
44
57
  });