@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.
- package/CHANGELOG.md +22 -0
- package/dist/js/modern/manager/async.js +53 -26
- package/dist/js/modern/manager/index.js +2 -1
- package/dist/js/modern/manager/sync.js +73 -58
- package/dist/js/modern/manager/types.js +0 -0
- package/dist/js/modern/waterfall/async.js +6 -7
- package/dist/js/modern/waterfall/sync.js +2 -3
- package/dist/js/modern/workflow/async.js +3 -4
- package/dist/js/modern/workflow/parallel.js +2 -2
- package/dist/js/modern/workflow/sync.js +2 -3
- package/dist/js/node/manager/async.js +51 -23
- package/dist/js/node/manager/index.js +13 -0
- package/dist/js/node/manager/sync.js +78 -56
- package/dist/js/node/manager/types.js +0 -0
- package/dist/js/node/waterfall/async.js +6 -7
- package/dist/js/node/waterfall/sync.js +2 -3
- package/dist/js/node/workflow/async.js +3 -4
- package/dist/js/node/workflow/parallel.js +2 -2
- package/dist/js/node/workflow/sync.js +2 -3
- package/dist/js/treeshaking/manager/async.js +57 -32
- package/dist/js/treeshaking/manager/index.js +2 -1
- package/dist/js/treeshaking/manager/sync.js +79 -60
- package/dist/js/treeshaking/manager/types.js +0 -0
- package/dist/js/treeshaking/waterfall/async.js +6 -7
- package/dist/js/treeshaking/waterfall/sync.js +2 -3
- package/dist/js/treeshaking/workflow/async.js +4 -5
- package/dist/js/treeshaking/workflow/parallel.js +2 -2
- package/dist/js/treeshaking/workflow/sync.js +2 -3
- package/dist/types/manager/async.d.ts +60 -21
- package/dist/types/manager/index.d.ts +2 -1
- package/dist/types/manager/sync.d.ts +74 -43
- package/dist/types/manager/types.d.ts +41 -0
- package/dist/types/waterfall/async.d.ts +2 -2
- package/jest.config.js +8 -0
- package/modern.config.js +1 -9
- package/package.json +10 -5
- package/tests/async.test.ts +132 -14
- package/tests/fixtures/async/core/index.ts +12 -4
- package/tests/fixtures/async/dynamic/foo.ts +2 -2
- package/tests/fixtures/sync/core/index.ts +9 -4
- package/tests/fixtures/sync/dynamic/foo.ts +2 -2
- package/tests/pipeline.test.ts +2 -2
- package/tests/sync.test.ts +126 -13
- package/tests/tsconfig.json +1 -3
- package/tests/waterfall.test.ts +2 -2
- package/tests/workflow.test.ts +2 -2
- package/tsconfig.json +1 -3
- package/src/index.ts +0 -5
- package/src/manager/async.ts +0 -248
- package/src/manager/index.ts +0 -3
- package/src/manager/runner.ts +0 -15
- package/src/manager/sync.ts +0 -458
- package/src/waterfall/async.ts +0 -109
- package/src/waterfall/index.ts +0 -2
- package/src/waterfall/sync.ts +0 -110
- package/src/workflow/async.ts +0 -96
- package/src/workflow/index.ts +0 -3
- package/src/workflow/parallel.ts +0 -97
- 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);
|
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]
|
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";
|
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 =
|
11
|
+
export const createAsyncManager = (hooks, api) => {
|
13
12
|
let index = 0;
|
14
13
|
|
15
|
-
|
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
|
25
|
-
|
26
|
-
processes = _objectSpread(_objectSpread({}, extraProcesses), processes);
|
16
|
+
const registerHook = extraHooks => {
|
17
|
+
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
27
18
|
};
|
28
19
|
|
29
|
-
const
|
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
|
-
|
36
|
-
|
37
|
-
|
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.
|
61
|
-
return generateRunner(hooksList, container,
|
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
|
-
|
104
|
+
registerHook,
|
78
105
|
useRunner
|
79
106
|
};
|
80
107
|
return manager;
|
@@ -1,53 +1,54 @@
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
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]
|
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";
|
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 =
|
21
|
+
export const createManager = (hooks, api) => {
|
24
22
|
let index = 0;
|
25
23
|
|
26
|
-
|
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
|
36
|
-
|
37
|
-
processes = _objectSpread(_objectSpread({}, extraProcesses), processes);
|
26
|
+
const registerHook = extraHooks => {
|
27
|
+
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
38
28
|
};
|
39
29
|
|
40
|
-
const
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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.
|
82
|
-
return generateRunner(hooksList, container,
|
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
|
-
|
106
|
+
const manager = {
|
91
107
|
createPlugin,
|
92
108
|
isPlugin,
|
93
109
|
usePlugin,
|
94
110
|
init,
|
95
111
|
clear,
|
96
112
|
run,
|
97
|
-
|
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,
|
122
|
+
export const generateRunner = (hooksList, container, hooksMap) => {
|
106
123
|
const runner = {};
|
107
|
-
const cloneShape =
|
124
|
+
const cloneShape = closeHooksMap(hooksMap);
|
108
125
|
|
109
|
-
if (
|
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
|
135
|
-
if (isWaterfall(
|
149
|
+
export const cloneHook = hook => {
|
150
|
+
if (isWaterfall(hook)) {
|
136
151
|
return createWaterfall();
|
137
152
|
}
|
138
153
|
|
139
|
-
if (isAsyncWaterfall(
|
154
|
+
if (isAsyncWaterfall(hook)) {
|
140
155
|
return createAsyncWaterfall();
|
141
156
|
}
|
142
157
|
|
143
|
-
if (isWorkflow(
|
158
|
+
if (isWorkflow(hook)) {
|
144
159
|
return createWorkflow();
|
145
160
|
}
|
146
161
|
|
147
|
-
if (isAsyncWorkflow(
|
162
|
+
if (isAsyncWorkflow(hook)) {
|
148
163
|
return createAsyncWorkflow();
|
149
164
|
}
|
150
165
|
|
151
|
-
if (isParallelWorkflow(
|
166
|
+
if (isParallelWorkflow(hook)) {
|
152
167
|
return createParallelWorkflow();
|
153
168
|
}
|
154
169
|
|
155
|
-
if (isPipeline(
|
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
|
161
|
-
};
|
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] =
|
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);
|
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]
|
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.
|
13
|
-
return input.
|
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
|
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
|
-
|
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);
|
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]
|
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);
|
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]
|
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]);
|
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);
|
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]
|
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);
|
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]
|
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);
|
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]
|
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 =
|
22
|
+
const createAsyncManager = (hooks, api) => {
|
23
23
|
let index = 0;
|
24
24
|
|
25
|
-
|
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
|
35
|
-
|
36
|
-
processes = _objectSpread(_objectSpread({}, extraProcesses), processes);
|
27
|
+
const registerHook = extraHooks => {
|
28
|
+
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
37
29
|
};
|
38
30
|
|
39
|
-
const
|
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
|
-
|
46
|
-
|
47
|
-
|
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.
|
71
|
-
return (0, _sync.generateRunner)(hooksList, container,
|
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
|
-
|
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
|
});
|