@modern-js/plugin 1.1.2 → 1.3.0

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 (59) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/js/modern/manager/async.js +53 -26
  3. package/dist/js/modern/manager/index.js +2 -1
  4. package/dist/js/modern/manager/sync.js +73 -58
  5. package/dist/js/modern/manager/types.js +0 -0
  6. package/dist/js/modern/waterfall/async.js +6 -7
  7. package/dist/js/modern/waterfall/sync.js +2 -3
  8. package/dist/js/modern/workflow/async.js +3 -4
  9. package/dist/js/modern/workflow/parallel.js +2 -2
  10. package/dist/js/modern/workflow/sync.js +2 -3
  11. package/dist/js/node/manager/async.js +51 -23
  12. package/dist/js/node/manager/index.js +13 -0
  13. package/dist/js/node/manager/sync.js +78 -56
  14. package/dist/js/node/manager/types.js +0 -0
  15. package/dist/js/node/waterfall/async.js +6 -7
  16. package/dist/js/node/waterfall/sync.js +2 -3
  17. package/dist/js/node/workflow/async.js +3 -4
  18. package/dist/js/node/workflow/parallel.js +2 -2
  19. package/dist/js/node/workflow/sync.js +2 -3
  20. package/dist/js/treeshaking/manager/async.js +57 -32
  21. package/dist/js/treeshaking/manager/index.js +2 -1
  22. package/dist/js/treeshaking/manager/sync.js +79 -60
  23. package/dist/js/treeshaking/manager/types.js +0 -0
  24. package/dist/js/treeshaking/waterfall/async.js +6 -7
  25. package/dist/js/treeshaking/waterfall/sync.js +2 -3
  26. package/dist/js/treeshaking/workflow/async.js +4 -5
  27. package/dist/js/treeshaking/workflow/parallel.js +2 -2
  28. package/dist/js/treeshaking/workflow/sync.js +2 -3
  29. package/dist/types/manager/async.d.ts +60 -21
  30. package/dist/types/manager/index.d.ts +2 -1
  31. package/dist/types/manager/sync.d.ts +74 -43
  32. package/dist/types/manager/types.d.ts +41 -0
  33. package/dist/types/waterfall/async.d.ts +2 -2
  34. package/jest.config.js +8 -0
  35. package/modern.config.js +1 -9
  36. package/package.json +10 -5
  37. package/tests/async.test.ts +132 -14
  38. package/tests/fixtures/async/core/index.ts +12 -4
  39. package/tests/fixtures/async/dynamic/foo.ts +2 -2
  40. package/tests/fixtures/sync/core/index.ts +9 -4
  41. package/tests/fixtures/sync/dynamic/foo.ts +2 -2
  42. package/tests/pipeline.test.ts +2 -2
  43. package/tests/sync.test.ts +126 -13
  44. package/tests/tsconfig.json +1 -3
  45. package/tests/waterfall.test.ts +2 -2
  46. package/tests/workflow.test.ts +2 -2
  47. package/tsconfig.json +1 -3
  48. package/src/index.ts +0 -5
  49. package/src/manager/async.ts +0 -248
  50. package/src/manager/index.ts +0 -3
  51. package/src/manager/runner.ts +0 -15
  52. package/src/manager/sync.ts +0 -458
  53. package/src/waterfall/async.ts +0 -109
  54. package/src/waterfall/index.ts +0 -2
  55. package/src/waterfall/sync.ts +0 -110
  56. package/src/workflow/async.ts +0 -96
  57. package/src/workflow/index.ts +0 -3
  58. package/src/workflow/parallel.ts +0 -97
  59. package/src/workflow/sync.ts +0 -82
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 80d8ddfe: feat: support `setup`, `registerHook`, `usePlugins` in plugin options.
8
+
9
+ ### Patch Changes
10
+
11
+ - 491145e3: feat: allow manger.clone to override pluginAPI
12
+
13
+ ## 1.2.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 83166714: change .npmignore
18
+
19
+ ## 1.2.0
20
+
21
+ ### Minor Changes
22
+
23
+ - cfe11628: Make Modern.js self bootstraping
24
+
3
25
  ## 1.1.2
4
26
 
5
27
  ### Patch Changes
@@ -1,42 +1,44 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
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) {
34
37
  if (isPlugin(plugin)) {
35
- if (!includeAsyncPlugin(plugins, plugin)) {
36
- plugins.push(_objectSpread(_objectSpread({}, plugin), {}, {
37
- index: plugins.length
38
- }));
39
- }
38
+ addPlugin(plugin);
39
+ } else if (typeof plugin === 'function') {
40
+ const options = plugin();
41
+ addPlugin(createPlugin(options.setup, options));
40
42
  } else {
41
43
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
42
44
  // @ts-expect-error
@@ -47,6 +49,28 @@ export const createAsyncManager = processes => {
47
49
  return manager;
48
50
  };
49
51
 
52
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
53
+ setup = () => {}, options = {}) => {
54
+ var _options$usePlugins;
55
+
56
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
57
+ options.usePlugins.forEach(plugin => {
58
+ usePlugin(createPlugin(plugin.setup, plugin));
59
+ });
60
+ }
61
+
62
+ if (options.registerHook) {
63
+ registerHook(options.registerHook);
64
+ }
65
+
66
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
67
+ name: `No.${index++} plugin`
68
+ }, options), {}, {
69
+ ASYNC_PLUGIN_SYMBOL,
70
+ setup
71
+ });
72
+ };
73
+
50
74
  const clear = () => {
51
75
  plugins = [];
52
76
  };
@@ -56,9 +80,12 @@ export const createAsyncManager = processes => {
56
80
  const init = async options => {
57
81
  const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
58
82
  const sortedPlugins = sortAsyncPlugins(plugins);
83
+
84
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
85
+
59
86
  checkAsyncPlugins(sortedPlugins);
60
- const hooksList = await Promise.all(sortedPlugins.map(plugin => runWithContainer(() => plugin.initializer(), container)));
61
- return generateRunner(hooksList, container, processes);
87
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container)));
88
+ return generateRunner(hooksList, container, currentHooks);
62
89
  };
63
90
 
64
91
  const run = (cb, options) => {
@@ -74,7 +101,7 @@ export const createAsyncManager = processes => {
74
101
  run,
75
102
  clear,
76
103
  clone,
77
- registe,
104
+ registerHook,
78
105
  useRunner
79
106
  };
80
107
  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";
@@ -1,53 +1,54 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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) {
45
47
  if (isPlugin(plugin)) {
46
- if (!includePlugin(plugins, plugin)) {
47
- plugins.push(_objectSpread(_objectSpread({}, plugin), {}, {
48
- index: plugins.length
49
- }));
50
- }
48
+ addPlugin(plugin);
49
+ } else if (typeof plugin === 'function') {
50
+ const options = plugin();
51
+ addPlugin(createPlugin(options.setup, options));
51
52
  } else {
52
53
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
53
54
  // @ts-expect-error
@@ -55,17 +56,29 @@ export const createManager = processes => {
55
56
  }
56
57
  }
57
58
 
58
- return {
59
- createPlugin,
60
- isPlugin,
61
- usePlugin,
62
- init,
63
- run,
64
- clear,
65
- registe,
66
- useRunner,
67
- clone
68
- };
59
+ return manager;
60
+ };
61
+
62
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
63
+ setup = () => {}, options = {}) => {
64
+ var _options$usePlugins;
65
+
66
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
67
+ options.usePlugins.forEach(plugin => {
68
+ usePlugin(createPlugin(plugin.setup, plugin));
69
+ });
70
+ }
71
+
72
+ if (options.registerHook) {
73
+ registerHook(options.registerHook);
74
+ }
75
+
76
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
77
+ name: `No.${index++} plugin`
78
+ }, options), {}, {
79
+ SYNC_PLUGIN_SYMBOL,
80
+ setup
81
+ });
69
82
  };
70
83
 
71
84
  const clear = () => {
@@ -77,9 +90,12 @@ export const createManager = processes => {
77
90
  const init = options => {
78
91
  const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
79
92
  const sortedPlugins = sortPlugins(plugins);
93
+
94
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
95
+
80
96
  checkPlugins(sortedPlugins);
81
- const hooksList = sortedPlugins.map(plugin => runWithContainer(() => plugin.initializer(), container));
82
- return generateRunner(hooksList, container, processes);
97
+ const hooksList = sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container));
98
+ return generateRunner(hooksList, container, currentHooks);
83
99
  };
84
100
 
85
101
  const run = (cb, options) => {
@@ -87,26 +103,27 @@ export const createManager = processes => {
87
103
  return runWithContainer(cb, container);
88
104
  };
89
105
 
90
- return {
106
+ const manager = {
91
107
  createPlugin,
92
108
  isPlugin,
93
109
  usePlugin,
94
110
  init,
95
111
  clear,
96
112
  run,
97
- registe,
113
+ registerHook,
98
114
  useRunner,
99
115
  clone
100
116
  };
117
+ return manager;
101
118
  };
102
119
 
103
120
  return clone();
104
121
  };
105
- export const generateRunner = (hooksList, container, processes) => {
122
+ export const generateRunner = (hooksList, container, hooksMap) => {
106
123
  const runner = {};
107
- const cloneShape = cloneProgressRecord(processes);
124
+ const cloneShape = closeHooksMap(hooksMap);
108
125
 
109
- if (processes) {
126
+ if (hooksMap) {
110
127
  for (const key in cloneShape) {
111
128
  for (const hooks of hooksList) {
112
129
  if (!hooks) {
@@ -114,8 +131,6 @@ export const generateRunner = (hooksList, container, processes) => {
114
131
  }
115
132
 
116
133
  if (hooks[key]) {
117
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
118
- // @ts-expect-error
119
134
  cloneShape[key].use(hooks[key]);
120
135
  }
121
136
  } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -131,36 +146,35 @@ export const generateRunner = (hooksList, container, processes) => {
131
146
  container.write(RunnerContext, runner);
132
147
  return runner;
133
148
  };
134
- export const cloneProgress = progress => {
135
- if (isWaterfall(progress)) {
149
+ export const cloneHook = hook => {
150
+ if (isWaterfall(hook)) {
136
151
  return createWaterfall();
137
152
  }
138
153
 
139
- if (isAsyncWaterfall(progress)) {
154
+ if (isAsyncWaterfall(hook)) {
140
155
  return createAsyncWaterfall();
141
156
  }
142
157
 
143
- if (isWorkflow(progress)) {
158
+ if (isWorkflow(hook)) {
144
159
  return createWorkflow();
145
160
  }
146
161
 
147
- if (isAsyncWorkflow(progress)) {
162
+ if (isAsyncWorkflow(hook)) {
148
163
  return createAsyncWorkflow();
149
164
  }
150
165
 
151
- if (isParallelWorkflow(progress)) {
166
+ if (isParallelWorkflow(hook)) {
152
167
  return createParallelWorkflow();
153
168
  }
154
169
 
155
- if (isPipeline(progress)) {
170
+ if (isPipeline(hook)) {
156
171
  return createPipeline();
157
172
  } // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
158
173
 
159
174
 
160
- throw new Error(`Unknown progress: ${progress}`);
161
- }; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
162
-
163
- export const cloneProgressRecord = record => {
175
+ throw new Error(`Unknown hook: ${hook}`);
176
+ };
177
+ export const closeHooksMap = record => {
164
178
  if (!record) {
165
179
  return record;
166
180
  }
@@ -170,7 +184,7 @@ export const cloneProgressRecord = record => {
170
184
  for (const key in record) {
171
185
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
172
186
  // @ts-expect-error
173
- result[key] = cloneProgress(record[key]);
187
+ result[key] = cloneHook(record[key]);
174
188
  }
175
189
 
176
190
  return result;
@@ -230,4 +244,5 @@ const checkPlugins = plugins => {
230
244
  }
231
245
  };
232
246
 
247
+ export const isObject = obj => obj !== null && typeof obj === 'object';
233
248
  export const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
File without changes
@@ -1,6 +1,6 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
 
@@ -9,14 +9,13 @@ const ASYNC_WATERFALL_SYMBOL = Symbol('ASYNC_WATERFALL_SYMBOL');
9
9
  export const getAsyncBrook = input => {
10
10
  if (typeof input === 'function') {
11
11
  return input;
12
- } else if (input && typeof input.middlware === 'function') {
13
- return input.middlware;
12
+ } else if (input && typeof input.middleware === 'function') {
13
+ return input.middleware;
14
14
  } // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
15
15
 
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
 
@@ -30,7 +29,7 @@ export const createAsyncWaterfall = () => {
30
29
  onLast: input => input
31
30
  }));
32
31
 
33
- const middlware = input => {
32
+ const middleware = input => {
34
33
  // eslint-disable-next-line react-hooks/rules-of-hooks
35
34
  const container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
36
35
 
@@ -43,7 +42,7 @@ export const createAsyncWaterfall = () => {
43
42
  const waterfall = _objectSpread(_objectSpread({}, pipeline), {}, {
44
43
  use,
45
44
  run,
46
- middlware,
45
+ middleware,
47
46
  [ASYNC_WATERFALL_SYMBOL]: true
48
47
  });
49
48
 
@@ -1,6 +1,6 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
 
@@ -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
 
@@ -1,13 +1,12 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
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
 
@@ -1,6 +1,6 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
 
@@ -1,12 +1,11 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
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
 
@@ -11,42 +11,45 @@ var _sync = require("./sync");
11
11
 
12
12
  var _runner = require("./runner");
13
13
 
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
15
 
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
17
 
18
18
  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; }
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) {
44
48
  if (isPlugin(plugin)) {
45
- if (!includeAsyncPlugin(plugins, plugin)) {
46
- plugins.push(_objectSpread(_objectSpread({}, plugin), {}, {
47
- index: plugins.length
48
- }));
49
- }
49
+ addPlugin(plugin);
50
+ } else if (typeof plugin === 'function') {
51
+ const options = plugin();
52
+ addPlugin(createPlugin(options.setup, options));
50
53
  } else {
51
54
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
52
55
  // @ts-expect-error
@@ -57,6 +60,28 @@ const createAsyncManager = processes => {
57
60
  return manager;
58
61
  };
59
62
 
63
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
64
+ setup = () => {}, options = {}) => {
65
+ var _options$usePlugins;
66
+
67
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
68
+ options.usePlugins.forEach(plugin => {
69
+ usePlugin(createPlugin(plugin.setup, plugin));
70
+ });
71
+ }
72
+
73
+ if (options.registerHook) {
74
+ registerHook(options.registerHook);
75
+ }
76
+
77
+ return _objectSpread(_objectSpread(_objectSpread({}, _sync.DEFAULT_OPTIONS), {}, {
78
+ name: `No.${index++} plugin`
79
+ }, options), {}, {
80
+ ASYNC_PLUGIN_SYMBOL,
81
+ setup
82
+ });
83
+ };
84
+
60
85
  const clear = () => {
61
86
  plugins = [];
62
87
  };
@@ -66,9 +91,12 @@ const createAsyncManager = processes => {
66
91
  const init = async options => {
67
92
  const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
68
93
  const sortedPlugins = sortAsyncPlugins(plugins);
94
+
95
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
96
+
69
97
  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);
98
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.setup(mergedPluginAPI), container)));
99
+ return (0, _sync.generateRunner)(hooksList, container, currentHooks);
72
100
  };
73
101
 
74
102
  const run = (cb, options) => {
@@ -84,7 +112,7 @@ const createAsyncManager = processes => {
84
112
  run,
85
113
  clear,
86
114
  clone,
87
- registe,
115
+ registerHook,
88
116
  useRunner: _runner.useRunner
89
117
  };
90
118
  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
  });