@modern-js/plugin 1.3.5 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +7 -1
- package/dist/js/modern/manager/async.js +5 -58
- package/dist/js/modern/manager/shared.js +44 -0
- package/dist/js/modern/manager/sync.js +4 -61
- package/dist/js/modern/workflow/sync.js +1 -1
- package/dist/js/node/farrow-pipeline/asyncHooks.node.js +8 -1
- package/dist/js/node/manager/async.js +8 -60
- package/dist/js/node/manager/shared.js +64 -0
- package/dist/js/node/manager/sync.js +11 -72
- package/dist/js/node/workflow/sync.js +1 -1
- package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +7 -1
- package/dist/js/treeshaking/manager/async.js +8 -146
- package/dist/js/treeshaking/manager/shared.js +79 -0
- package/dist/js/treeshaking/manager/sync.js +3 -151
- package/dist/js/treeshaking/waterfall/async.js +3 -3
- package/dist/js/treeshaking/workflow/async.js +5 -5
- package/dist/js/treeshaking/workflow/parallel.js +3 -3
- package/dist/js/treeshaking/workflow/sync.js +7 -27
- package/dist/types/farrow-pipeline/context.d.ts +2 -2
- package/dist/types/manager/runner.d.ts +1 -0
- package/dist/types/manager/shared.d.ts +12 -0
- package/dist/types/manager/sync.d.ts +0 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# @modern-js/plugin
|
2
2
|
|
3
|
+
## 1.3.8
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- b7302f781: Export some required types
|
8
|
+
- e0e708f83: perf(app-tools): speed up modern start command
|
9
|
+
|
10
|
+
## 1.3.7
|
11
|
+
|
12
|
+
### Patch Changes
|
13
|
+
|
14
|
+
- 1ac68424f: chore(plugin): extract same utils to shared
|
15
|
+
|
16
|
+
## 1.3.6
|
17
|
+
|
18
|
+
### Patch Changes
|
19
|
+
|
20
|
+
- a1198d509: feat: bump babel 7.18.0
|
21
|
+
|
3
22
|
## 1.3.5
|
4
23
|
|
5
24
|
### Patch Changes
|
@@ -60,15 +60,21 @@ const createAsyncHooks = () => {
|
|
60
60
|
};
|
61
61
|
};
|
62
62
|
|
63
|
+
let enabled = false;
|
63
64
|
export const enable = () => {
|
65
|
+
if (enabled) {
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
|
69
|
+
enabled = true;
|
64
70
|
const hooks = createAsyncHooks();
|
65
|
-
disable();
|
66
71
|
asyncHooksInterface.impl(hooks);
|
67
72
|
hooks.enable();
|
68
73
|
};
|
69
74
|
export const disable = () => {
|
70
75
|
var _asyncHooksInterface$;
|
71
76
|
|
77
|
+
enabled = false;
|
72
78
|
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
73
79
|
asyncHooksInterface.reset();
|
74
80
|
};
|
@@ -5,8 +5,9 @@ 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 {
|
8
|
+
import { generateRunner, DEFAULT_OPTIONS } from "./sync";
|
9
9
|
import { useRunner } from "./runner";
|
10
|
+
import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
|
10
11
|
const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
|
11
12
|
export const createAsyncManager = (hooks, api) => {
|
12
13
|
let index = 0;
|
@@ -27,7 +28,7 @@ export const createAsyncManager = (hooks, api) => {
|
|
27
28
|
let plugins = [];
|
28
29
|
|
29
30
|
const addPlugin = plugin => {
|
30
|
-
if (!
|
31
|
+
if (!includePlugin(plugins, plugin)) {
|
31
32
|
plugins.push(_objectSpread({}, plugin));
|
32
33
|
}
|
33
34
|
};
|
@@ -83,11 +84,11 @@ export const createAsyncManager = (hooks, api) => {
|
|
83
84
|
|
84
85
|
const init = async options => {
|
85
86
|
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
86
|
-
const sortedPlugins =
|
87
|
+
const sortedPlugins = sortPlugins(plugins);
|
87
88
|
|
88
89
|
const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
89
90
|
|
90
|
-
|
91
|
+
checkPlugins(sortedPlugins);
|
91
92
|
const hooksList = await Promise.all(sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container)));
|
92
93
|
return generateRunner(hooksList, container, currentHooks);
|
93
94
|
};
|
@@ -112,58 +113,4 @@ export const createAsyncManager = (hooks, api) => {
|
|
112
113
|
};
|
113
114
|
|
114
115
|
return clone();
|
115
|
-
};
|
116
|
-
|
117
|
-
const includeAsyncPlugin = (plugins, input) => {
|
118
|
-
for (const plugin of plugins) {
|
119
|
-
if (plugin.name === input.name) {
|
120
|
-
return true;
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
return false;
|
125
|
-
};
|
126
|
-
|
127
|
-
const sortAsyncPlugins = input => {
|
128
|
-
let plugins = input.slice();
|
129
|
-
|
130
|
-
for (let i = 0; i < plugins.length; i++) {
|
131
|
-
const plugin = plugins[i];
|
132
|
-
|
133
|
-
for (const pre of plugin.pre) {
|
134
|
-
for (let j = i + 1; j < plugins.length; j++) {
|
135
|
-
if (plugins[j].name === pre) {
|
136
|
-
plugins = [...plugins.slice(0, i), plugins[j], ...plugins.slice(i, j), ...plugins.slice(j + 1, plugins.length)];
|
137
|
-
}
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
for (const post of plugin.post) {
|
142
|
-
for (let j = 0; j < i; j++) {
|
143
|
-
if (plugins[j].name === post) {
|
144
|
-
plugins = [...plugins.slice(0, j), ...plugins.slice(j + 1, i + 1), plugins[j], ...plugins.slice(i + 1, plugins.length)];
|
145
|
-
}
|
146
|
-
}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
return plugins;
|
151
|
-
};
|
152
|
-
|
153
|
-
const checkAsyncPlugins = plugins => {
|
154
|
-
for (const origin of plugins) {
|
155
|
-
for (const rival of origin.rivals) {
|
156
|
-
for (const plugin of plugins) {
|
157
|
-
if (rival === plugin.name) {
|
158
|
-
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
163
|
-
for (const required of origin.required) {
|
164
|
-
if (!plugins.some(plugin => plugin.name === required)) {
|
165
|
-
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
}
|
169
116
|
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
export const checkPlugins = plugins => {
|
2
|
+
plugins.forEach(origin => {
|
3
|
+
origin.rivals.forEach(rival => {
|
4
|
+
plugins.forEach(plugin => {
|
5
|
+
if (rival === plugin.name) {
|
6
|
+
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
7
|
+
}
|
8
|
+
});
|
9
|
+
});
|
10
|
+
origin.required.forEach(required => {
|
11
|
+
if (!plugins.some(plugin => plugin.name === required)) {
|
12
|
+
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
13
|
+
}
|
14
|
+
});
|
15
|
+
});
|
16
|
+
};
|
17
|
+
export function sortPlugins(input) {
|
18
|
+
let plugins = input.slice();
|
19
|
+
|
20
|
+
for (let i = 0; i < plugins.length; i++) {
|
21
|
+
const plugin = plugins[i];
|
22
|
+
|
23
|
+
for (const pre of plugin.pre) {
|
24
|
+
for (let j = i + 1; j < plugins.length; j++) {
|
25
|
+
if (plugins[j].name === pre) {
|
26
|
+
plugins = [...plugins.slice(0, i), plugins[j], ...plugins.slice(i, j), ...plugins.slice(j + 1, plugins.length)];
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
for (const post of plugin.post) {
|
32
|
+
for (let j = 0; j < i; j++) {
|
33
|
+
if (plugins[j].name === post) {
|
34
|
+
plugins = [...plugins.slice(0, j), ...plugins.slice(j + 1, i + 1), plugins[j], ...plugins.slice(i + 1, plugins.length)];
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
return plugins;
|
41
|
+
}
|
42
|
+
export const includePlugin = (plugins, input) => plugins.some(plugin => plugin.name === input.name);
|
43
|
+
export const isObject = obj => obj !== null && typeof obj === 'object';
|
44
|
+
export const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
@@ -8,6 +8,7 @@ import { isPipeline, createPipeline, runWithContainer, createContainer } from ".
|
|
8
8
|
import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
|
9
9
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
10
10
|
import { RunnerContext, useRunner } from "./runner";
|
11
|
+
import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
|
11
12
|
const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
12
13
|
export const DEFAULT_OPTIONS = {
|
13
14
|
name: 'untitled',
|
@@ -43,7 +44,7 @@ export const createManager = (hooks, api) => {
|
|
43
44
|
};
|
44
45
|
|
45
46
|
const usePlugin = (...input) => {
|
46
|
-
|
47
|
+
input.forEach(plugin => {
|
47
48
|
// already created by createPlugin
|
48
49
|
if (isPlugin(plugin)) {
|
49
50
|
addPlugin(plugin);
|
@@ -58,8 +59,7 @@ export const createManager = (hooks, api) => {
|
|
58
59
|
else {
|
59
60
|
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
60
61
|
}
|
61
|
-
}
|
62
|
-
|
62
|
+
});
|
63
63
|
return manager;
|
64
64
|
};
|
65
65
|
|
@@ -191,61 +191,4 @@ export const closeHooksMap = record => {
|
|
191
191
|
}
|
192
192
|
|
193
193
|
return result;
|
194
|
-
};
|
195
|
-
|
196
|
-
const includePlugin = (plugins, input) => {
|
197
|
-
for (const plugin of plugins) {
|
198
|
-
if (plugin.name === input.name) {
|
199
|
-
return true;
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
return false;
|
204
|
-
};
|
205
|
-
|
206
|
-
const sortPlugins = input => {
|
207
|
-
let plugins = input.slice();
|
208
|
-
|
209
|
-
for (let i = 0; i < plugins.length; i++) {
|
210
|
-
const plugin = plugins[i];
|
211
|
-
|
212
|
-
for (const pre of plugin.pre) {
|
213
|
-
for (let j = i + 1; j < plugins.length; j++) {
|
214
|
-
if (plugins[j].name === pre) {
|
215
|
-
plugins = [...plugins.slice(0, i), plugins[j], ...plugins.slice(i, j), ...plugins.slice(j + 1, plugins.length)];
|
216
|
-
}
|
217
|
-
}
|
218
|
-
}
|
219
|
-
|
220
|
-
for (const post of plugin.post) {
|
221
|
-
for (let j = 0; j < i; j++) {
|
222
|
-
if (plugins[j].name === post) {
|
223
|
-
plugins = [...plugins.slice(0, j), ...plugins.slice(j + 1, i + 1), plugins[j], ...plugins.slice(i + 1, plugins.length)];
|
224
|
-
}
|
225
|
-
}
|
226
|
-
}
|
227
|
-
}
|
228
|
-
|
229
|
-
return plugins;
|
230
|
-
};
|
231
|
-
|
232
|
-
const checkPlugins = plugins => {
|
233
|
-
for (const origin of plugins) {
|
234
|
-
for (const rival of origin.rivals) {
|
235
|
-
for (const plugin of plugins) {
|
236
|
-
if (rival === plugin.name) {
|
237
|
-
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
238
|
-
}
|
239
|
-
}
|
240
|
-
}
|
241
|
-
|
242
|
-
for (const required of origin.required) {
|
243
|
-
if (!plugins.some(plugin => plugin.name === required)) {
|
244
|
-
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
245
|
-
}
|
246
|
-
}
|
247
|
-
}
|
248
|
-
};
|
249
|
-
|
250
|
-
export const isObject = obj => obj !== null && typeof obj === 'object';
|
251
|
-
export const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
194
|
+
};
|
@@ -14,7 +14,7 @@ export const createWorkflow = () => {
|
|
14
14
|
return workflow;
|
15
15
|
};
|
16
16
|
|
17
|
-
const run =
|
17
|
+
const run = (input, options) => {
|
18
18
|
const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
19
19
|
onLast: () => []
|
20
20
|
}));
|
@@ -74,9 +74,15 @@ const createAsyncHooks = () => {
|
|
74
74
|
};
|
75
75
|
};
|
76
76
|
|
77
|
+
let enabled = false;
|
78
|
+
|
77
79
|
const enable = () => {
|
80
|
+
if (enabled) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
|
84
|
+
enabled = true;
|
78
85
|
const hooks = createAsyncHooks();
|
79
|
-
disable();
|
80
86
|
asyncHooksInterface.impl(hooks);
|
81
87
|
hooks.enable();
|
82
88
|
};
|
@@ -86,6 +92,7 @@ exports.enable = enable;
|
|
86
92
|
const disable = () => {
|
87
93
|
var _asyncHooksInterface$;
|
88
94
|
|
95
|
+
enabled = false;
|
89
96
|
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
90
97
|
asyncHooksInterface.reset();
|
91
98
|
};
|
@@ -11,6 +11,8 @@ var _sync = require("./sync");
|
|
11
11
|
|
12
12
|
var _runner = require("./runner");
|
13
13
|
|
14
|
+
var _shared = require("./shared");
|
15
|
+
|
14
16
|
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
17
|
|
16
18
|
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; }
|
@@ -28,7 +30,7 @@ const createAsyncManager = (hooks, api) => {
|
|
28
30
|
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
29
31
|
};
|
30
32
|
|
31
|
-
const isPlugin = input => (0,
|
33
|
+
const isPlugin = input => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
|
32
34
|
|
33
35
|
const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
34
36
|
useHookRunners: _runner.useRunner
|
@@ -38,7 +40,7 @@ const createAsyncManager = (hooks, api) => {
|
|
38
40
|
let plugins = [];
|
39
41
|
|
40
42
|
const addPlugin = plugin => {
|
41
|
-
if (!
|
43
|
+
if (!(0, _shared.includePlugin)(plugins, plugin)) {
|
42
44
|
plugins.push(_objectSpread({}, plugin));
|
43
45
|
}
|
44
46
|
};
|
@@ -53,7 +55,7 @@ const createAsyncManager = (hooks, api) => {
|
|
53
55
|
const options = plugin();
|
54
56
|
addPlugin(createPlugin(options.setup, options));
|
55
57
|
} // plain plugin object
|
56
|
-
else if ((0,
|
58
|
+
else if ((0, _shared.isObject)(plugin)) {
|
57
59
|
addPlugin(createPlugin(plugin.setup, plugin));
|
58
60
|
} // unknown plugin
|
59
61
|
else {
|
@@ -94,11 +96,11 @@ const createAsyncManager = (hooks, api) => {
|
|
94
96
|
|
95
97
|
const init = async options => {
|
96
98
|
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
97
|
-
const sortedPlugins =
|
99
|
+
const sortedPlugins = (0, _shared.sortPlugins)(plugins);
|
98
100
|
|
99
101
|
const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
100
102
|
|
101
|
-
|
103
|
+
(0, _shared.checkPlugins)(sortedPlugins);
|
102
104
|
const hooksList = await Promise.all(sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.setup(mergedPluginAPI), container)));
|
103
105
|
return (0, _sync.generateRunner)(hooksList, container, currentHooks);
|
104
106
|
};
|
@@ -125,58 +127,4 @@ const createAsyncManager = (hooks, api) => {
|
|
125
127
|
return clone();
|
126
128
|
};
|
127
129
|
|
128
|
-
exports.createAsyncManager = createAsyncManager;
|
129
|
-
|
130
|
-
const includeAsyncPlugin = (plugins, input) => {
|
131
|
-
for (const plugin of plugins) {
|
132
|
-
if (plugin.name === input.name) {
|
133
|
-
return true;
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
return false;
|
138
|
-
};
|
139
|
-
|
140
|
-
const sortAsyncPlugins = input => {
|
141
|
-
let plugins = input.slice();
|
142
|
-
|
143
|
-
for (let i = 0; i < plugins.length; i++) {
|
144
|
-
const plugin = plugins[i];
|
145
|
-
|
146
|
-
for (const pre of plugin.pre) {
|
147
|
-
for (let j = i + 1; j < plugins.length; j++) {
|
148
|
-
if (plugins[j].name === pre) {
|
149
|
-
plugins = [...plugins.slice(0, i), plugins[j], ...plugins.slice(i, j), ...plugins.slice(j + 1, plugins.length)];
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
for (const post of plugin.post) {
|
155
|
-
for (let j = 0; j < i; j++) {
|
156
|
-
if (plugins[j].name === post) {
|
157
|
-
plugins = [...plugins.slice(0, j), ...plugins.slice(j + 1, i + 1), plugins[j], ...plugins.slice(i + 1, plugins.length)];
|
158
|
-
}
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
163
|
-
return plugins;
|
164
|
-
};
|
165
|
-
|
166
|
-
const checkAsyncPlugins = plugins => {
|
167
|
-
for (const origin of plugins) {
|
168
|
-
for (const rival of origin.rivals) {
|
169
|
-
for (const plugin of plugins) {
|
170
|
-
if (rival === plugin.name) {
|
171
|
-
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
172
|
-
}
|
173
|
-
}
|
174
|
-
}
|
175
|
-
|
176
|
-
for (const required of origin.required) {
|
177
|
-
if (!plugins.some(plugin => plugin.name === required)) {
|
178
|
-
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
182
|
-
};
|
130
|
+
exports.createAsyncManager = createAsyncManager;
|
@@ -0,0 +1,64 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.isObject = exports.includePlugin = exports.hasOwnProperty = exports.checkPlugins = void 0;
|
7
|
+
exports.sortPlugins = sortPlugins;
|
8
|
+
|
9
|
+
const checkPlugins = plugins => {
|
10
|
+
plugins.forEach(origin => {
|
11
|
+
origin.rivals.forEach(rival => {
|
12
|
+
plugins.forEach(plugin => {
|
13
|
+
if (rival === plugin.name) {
|
14
|
+
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
15
|
+
}
|
16
|
+
});
|
17
|
+
});
|
18
|
+
origin.required.forEach(required => {
|
19
|
+
if (!plugins.some(plugin => plugin.name === required)) {
|
20
|
+
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
21
|
+
}
|
22
|
+
});
|
23
|
+
});
|
24
|
+
};
|
25
|
+
|
26
|
+
exports.checkPlugins = checkPlugins;
|
27
|
+
|
28
|
+
function sortPlugins(input) {
|
29
|
+
let plugins = input.slice();
|
30
|
+
|
31
|
+
for (let i = 0; i < plugins.length; i++) {
|
32
|
+
const plugin = plugins[i];
|
33
|
+
|
34
|
+
for (const pre of plugin.pre) {
|
35
|
+
for (let j = i + 1; j < plugins.length; j++) {
|
36
|
+
if (plugins[j].name === pre) {
|
37
|
+
plugins = [...plugins.slice(0, i), plugins[j], ...plugins.slice(i, j), ...plugins.slice(j + 1, plugins.length)];
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
for (const post of plugin.post) {
|
43
|
+
for (let j = 0; j < i; j++) {
|
44
|
+
if (plugins[j].name === post) {
|
45
|
+
plugins = [...plugins.slice(0, j), ...plugins.slice(j + 1, i + 1), plugins[j], ...plugins.slice(i + 1, plugins.length)];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
return plugins;
|
52
|
+
}
|
53
|
+
|
54
|
+
const includePlugin = (plugins, input) => plugins.some(plugin => plugin.name === input.name);
|
55
|
+
|
56
|
+
exports.includePlugin = includePlugin;
|
57
|
+
|
58
|
+
const isObject = obj => obj !== null && typeof obj === 'object';
|
59
|
+
|
60
|
+
exports.isObject = isObject;
|
61
|
+
|
62
|
+
const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
63
|
+
|
64
|
+
exports.hasOwnProperty = hasOwnProperty;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.generateRunner = exports.createManager = exports.closeHooksMap = exports.cloneHook = exports.DEFAULT_OPTIONS = void 0;
|
7
7
|
|
8
8
|
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
@@ -13,6 +13,8 @@ var _workflow = require("../workflow");
|
|
13
13
|
|
14
14
|
var _runner = require("./runner");
|
15
15
|
|
16
|
+
var _shared = require("./shared");
|
17
|
+
|
16
18
|
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; }
|
17
19
|
|
18
20
|
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; }
|
@@ -40,7 +42,7 @@ const createManager = (hooks, api) => {
|
|
40
42
|
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
41
43
|
};
|
42
44
|
|
43
|
-
const isPlugin = input => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
45
|
+
const isPlugin = input => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
44
46
|
|
45
47
|
const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
46
48
|
useHookRunners: _runner.useRunner
|
@@ -50,13 +52,13 @@ const createManager = (hooks, api) => {
|
|
50
52
|
let plugins = [];
|
51
53
|
|
52
54
|
const addPlugin = plugin => {
|
53
|
-
if (!includePlugin(plugins, plugin)) {
|
55
|
+
if (!(0, _shared.includePlugin)(plugins, plugin)) {
|
54
56
|
plugins.push(_objectSpread({}, plugin));
|
55
57
|
}
|
56
58
|
};
|
57
59
|
|
58
60
|
const usePlugin = (...input) => {
|
59
|
-
|
61
|
+
input.forEach(plugin => {
|
60
62
|
// already created by createPlugin
|
61
63
|
if (isPlugin(plugin)) {
|
62
64
|
addPlugin(plugin);
|
@@ -65,14 +67,13 @@ const createManager = (hooks, api) => {
|
|
65
67
|
const options = plugin();
|
66
68
|
addPlugin(createPlugin(options.setup, options));
|
67
69
|
} // plain plugin object
|
68
|
-
else if (isObject(plugin)) {
|
70
|
+
else if ((0, _shared.isObject)(plugin)) {
|
69
71
|
addPlugin(createPlugin(plugin.setup, plugin));
|
70
72
|
} // unknown plugin
|
71
73
|
else {
|
72
74
|
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
73
75
|
}
|
74
|
-
}
|
75
|
-
|
76
|
+
});
|
76
77
|
return manager;
|
77
78
|
};
|
78
79
|
|
@@ -106,11 +107,11 @@ const createManager = (hooks, api) => {
|
|
106
107
|
|
107
108
|
const init = options => {
|
108
109
|
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
109
|
-
const sortedPlugins = sortPlugins(plugins);
|
110
|
+
const sortedPlugins = (0, _shared.sortPlugins)(plugins);
|
110
111
|
|
111
112
|
const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
112
113
|
|
113
|
-
checkPlugins(sortedPlugins);
|
114
|
+
(0, _shared.checkPlugins)(sortedPlugins);
|
114
115
|
const hooksList = sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.setup(mergedPluginAPI), container));
|
115
116
|
return generateRunner(hooksList, container, currentHooks);
|
116
117
|
};
|
@@ -215,66 +216,4 @@ const closeHooksMap = record => {
|
|
215
216
|
return result;
|
216
217
|
};
|
217
218
|
|
218
|
-
exports.closeHooksMap = closeHooksMap;
|
219
|
-
|
220
|
-
const includePlugin = (plugins, input) => {
|
221
|
-
for (const plugin of plugins) {
|
222
|
-
if (plugin.name === input.name) {
|
223
|
-
return true;
|
224
|
-
}
|
225
|
-
}
|
226
|
-
|
227
|
-
return false;
|
228
|
-
};
|
229
|
-
|
230
|
-
const sortPlugins = input => {
|
231
|
-
let plugins = input.slice();
|
232
|
-
|
233
|
-
for (let i = 0; i < plugins.length; i++) {
|
234
|
-
const plugin = plugins[i];
|
235
|
-
|
236
|
-
for (const pre of plugin.pre) {
|
237
|
-
for (let j = i + 1; j < plugins.length; j++) {
|
238
|
-
if (plugins[j].name === pre) {
|
239
|
-
plugins = [...plugins.slice(0, i), plugins[j], ...plugins.slice(i, j), ...plugins.slice(j + 1, plugins.length)];
|
240
|
-
}
|
241
|
-
}
|
242
|
-
}
|
243
|
-
|
244
|
-
for (const post of plugin.post) {
|
245
|
-
for (let j = 0; j < i; j++) {
|
246
|
-
if (plugins[j].name === post) {
|
247
|
-
plugins = [...plugins.slice(0, j), ...plugins.slice(j + 1, i + 1), plugins[j], ...plugins.slice(i + 1, plugins.length)];
|
248
|
-
}
|
249
|
-
}
|
250
|
-
}
|
251
|
-
}
|
252
|
-
|
253
|
-
return plugins;
|
254
|
-
};
|
255
|
-
|
256
|
-
const checkPlugins = plugins => {
|
257
|
-
for (const origin of plugins) {
|
258
|
-
for (const rival of origin.rivals) {
|
259
|
-
for (const plugin of plugins) {
|
260
|
-
if (rival === plugin.name) {
|
261
|
-
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
262
|
-
}
|
263
|
-
}
|
264
|
-
}
|
265
|
-
|
266
|
-
for (const required of origin.required) {
|
267
|
-
if (!plugins.some(plugin => plugin.name === required)) {
|
268
|
-
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
269
|
-
}
|
270
|
-
}
|
271
|
-
}
|
272
|
-
};
|
273
|
-
|
274
|
-
const isObject = obj => obj !== null && typeof obj === 'object';
|
275
|
-
|
276
|
-
exports.isObject = isObject;
|
277
|
-
|
278
|
-
const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
279
|
-
|
280
|
-
exports.hasOwnProperty = hasOwnProperty;
|
219
|
+
exports.closeHooksMap = closeHooksMap;
|
@@ -60,15 +60,21 @@ var createAsyncHooks = function createAsyncHooks() {
|
|
60
60
|
};
|
61
61
|
};
|
62
62
|
|
63
|
+
var enabled = false;
|
63
64
|
export var enable = function enable() {
|
65
|
+
if (enabled) {
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
|
69
|
+
enabled = true;
|
64
70
|
var hooks = createAsyncHooks();
|
65
|
-
disable();
|
66
71
|
asyncHooksInterface.impl(hooks);
|
67
72
|
hooks.enable();
|
68
73
|
};
|
69
74
|
export var disable = function disable() {
|
70
75
|
var _asyncHooksInterface$;
|
71
76
|
|
77
|
+
enabled = false;
|
72
78
|
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
73
79
|
asyncHooksInterface.reset();
|
74
80
|
};
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import
|
2
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
3
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
4
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
6
4
|
import { runWithContainer, createContainer } from "../farrow-pipeline";
|
7
|
-
import {
|
5
|
+
import { generateRunner, DEFAULT_OPTIONS } from "./sync";
|
8
6
|
import { useRunner } from "./runner";
|
7
|
+
import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
|
9
8
|
var ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
|
10
9
|
export var createAsyncManager = function createAsyncManager(hooks, api) {
|
11
10
|
var index = 0;
|
@@ -28,7 +27,7 @@ export var createAsyncManager = function createAsyncManager(hooks, api) {
|
|
28
27
|
var plugins = [];
|
29
28
|
|
30
29
|
var addPlugin = function addPlugin(plugin) {
|
31
|
-
if (!
|
30
|
+
if (!includePlugin(plugins, plugin)) {
|
32
31
|
plugins.push(_objectSpread({}, plugin));
|
33
32
|
}
|
34
33
|
};
|
@@ -92,16 +91,16 @@ export var createAsyncManager = function createAsyncManager(hooks, api) {
|
|
92
91
|
var currentContainer = createContainer();
|
93
92
|
|
94
93
|
var init = /*#__PURE__*/function () {
|
95
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
94
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
96
95
|
var container, sortedPlugins, mergedPluginAPI, hooksList;
|
97
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
96
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
98
97
|
while (1) {
|
99
98
|
switch (_context.prev = _context.next) {
|
100
99
|
case 0:
|
101
100
|
container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
102
|
-
sortedPlugins =
|
101
|
+
sortedPlugins = sortPlugins(plugins);
|
103
102
|
mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
104
|
-
|
103
|
+
checkPlugins(sortedPlugins);
|
105
104
|
_context.next = 6;
|
106
105
|
return Promise.all(sortedPlugins.map(function (plugin) {
|
107
106
|
return runWithContainer(function () {
|
@@ -146,141 +145,4 @@ export var createAsyncManager = function createAsyncManager(hooks, api) {
|
|
146
145
|
};
|
147
146
|
|
148
147
|
return clone();
|
149
|
-
};
|
150
|
-
|
151
|
-
var includeAsyncPlugin = function includeAsyncPlugin(plugins, input) {
|
152
|
-
var _iterator = _createForOfIteratorHelper(plugins),
|
153
|
-
_step;
|
154
|
-
|
155
|
-
try {
|
156
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
157
|
-
var plugin = _step.value;
|
158
|
-
|
159
|
-
if (plugin.name === input.name) {
|
160
|
-
return true;
|
161
|
-
}
|
162
|
-
}
|
163
|
-
} catch (err) {
|
164
|
-
_iterator.e(err);
|
165
|
-
} finally {
|
166
|
-
_iterator.f();
|
167
|
-
}
|
168
|
-
|
169
|
-
return false;
|
170
|
-
};
|
171
|
-
|
172
|
-
var sortAsyncPlugins = function sortAsyncPlugins(input) {
|
173
|
-
var plugins = input.slice();
|
174
|
-
|
175
|
-
for (var i = 0; i < plugins.length; i++) {
|
176
|
-
var plugin = plugins[i];
|
177
|
-
|
178
|
-
var _iterator2 = _createForOfIteratorHelper(plugin.pre),
|
179
|
-
_step2;
|
180
|
-
|
181
|
-
try {
|
182
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
183
|
-
var pre = _step2.value;
|
184
|
-
|
185
|
-
for (var j = i + 1; j < plugins.length; j++) {
|
186
|
-
if (plugins[j].name === pre) {
|
187
|
-
plugins = [].concat(_toConsumableArray(plugins.slice(0, i)), [plugins[j]], _toConsumableArray(plugins.slice(i, j)), _toConsumableArray(plugins.slice(j + 1, plugins.length)));
|
188
|
-
}
|
189
|
-
}
|
190
|
-
}
|
191
|
-
} catch (err) {
|
192
|
-
_iterator2.e(err);
|
193
|
-
} finally {
|
194
|
-
_iterator2.f();
|
195
|
-
}
|
196
|
-
|
197
|
-
var _iterator3 = _createForOfIteratorHelper(plugin.post),
|
198
|
-
_step3;
|
199
|
-
|
200
|
-
try {
|
201
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
202
|
-
var post = _step3.value;
|
203
|
-
|
204
|
-
for (var _j = 0; _j < i; _j++) {
|
205
|
-
if (plugins[_j].name === post) {
|
206
|
-
plugins = [].concat(_toConsumableArray(plugins.slice(0, _j)), _toConsumableArray(plugins.slice(_j + 1, i + 1)), [plugins[_j]], _toConsumableArray(plugins.slice(i + 1, plugins.length)));
|
207
|
-
}
|
208
|
-
}
|
209
|
-
}
|
210
|
-
} catch (err) {
|
211
|
-
_iterator3.e(err);
|
212
|
-
} finally {
|
213
|
-
_iterator3.f();
|
214
|
-
}
|
215
|
-
}
|
216
|
-
|
217
|
-
return plugins;
|
218
|
-
};
|
219
|
-
|
220
|
-
var checkAsyncPlugins = function checkAsyncPlugins(plugins) {
|
221
|
-
var _iterator4 = _createForOfIteratorHelper(plugins),
|
222
|
-
_step4;
|
223
|
-
|
224
|
-
try {
|
225
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
226
|
-
var origin = _step4.value;
|
227
|
-
|
228
|
-
var _iterator5 = _createForOfIteratorHelper(origin.rivals),
|
229
|
-
_step5;
|
230
|
-
|
231
|
-
try {
|
232
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
233
|
-
var rival = _step5.value;
|
234
|
-
|
235
|
-
var _iterator7 = _createForOfIteratorHelper(plugins),
|
236
|
-
_step7;
|
237
|
-
|
238
|
-
try {
|
239
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
240
|
-
var plugin = _step7.value;
|
241
|
-
|
242
|
-
if (rival === plugin.name) {
|
243
|
-
throw new Error("".concat(origin.name, " has rival ").concat(plugin.name));
|
244
|
-
}
|
245
|
-
}
|
246
|
-
} catch (err) {
|
247
|
-
_iterator7.e(err);
|
248
|
-
} finally {
|
249
|
-
_iterator7.f();
|
250
|
-
}
|
251
|
-
}
|
252
|
-
} catch (err) {
|
253
|
-
_iterator5.e(err);
|
254
|
-
} finally {
|
255
|
-
_iterator5.f();
|
256
|
-
}
|
257
|
-
|
258
|
-
var _iterator6 = _createForOfIteratorHelper(origin.required),
|
259
|
-
_step6;
|
260
|
-
|
261
|
-
try {
|
262
|
-
var _loop = function _loop() {
|
263
|
-
var required = _step6.value;
|
264
|
-
|
265
|
-
if (!plugins.some(function (plugin) {
|
266
|
-
return plugin.name === required;
|
267
|
-
})) {
|
268
|
-
throw new Error("The plugin: ".concat(required, " is required when plugin: ").concat(origin.name, " is exist."));
|
269
|
-
}
|
270
|
-
};
|
271
|
-
|
272
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
273
|
-
_loop();
|
274
|
-
}
|
275
|
-
} catch (err) {
|
276
|
-
_iterator6.e(err);
|
277
|
-
} finally {
|
278
|
-
_iterator6.f();
|
279
|
-
}
|
280
|
-
}
|
281
|
-
} catch (err) {
|
282
|
-
_iterator4.e(err);
|
283
|
-
} finally {
|
284
|
-
_iterator4.f();
|
285
|
-
}
|
286
148
|
};
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
3
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
4
|
+
export var checkPlugins = function checkPlugins(plugins) {
|
5
|
+
plugins.forEach(function (origin) {
|
6
|
+
origin.rivals.forEach(function (rival) {
|
7
|
+
plugins.forEach(function (plugin) {
|
8
|
+
if (rival === plugin.name) {
|
9
|
+
throw new Error("".concat(origin.name, " has rival ").concat(plugin.name));
|
10
|
+
}
|
11
|
+
});
|
12
|
+
});
|
13
|
+
origin.required.forEach(function (required) {
|
14
|
+
if (!plugins.some(function (plugin) {
|
15
|
+
return plugin.name === required;
|
16
|
+
})) {
|
17
|
+
throw new Error("The plugin: ".concat(required, " is required when plugin: ").concat(origin.name, " is exist."));
|
18
|
+
}
|
19
|
+
});
|
20
|
+
});
|
21
|
+
};
|
22
|
+
export function sortPlugins(input) {
|
23
|
+
var plugins = input.slice();
|
24
|
+
|
25
|
+
for (var i = 0; i < plugins.length; i++) {
|
26
|
+
var plugin = plugins[i];
|
27
|
+
|
28
|
+
var _iterator = _createForOfIteratorHelper(plugin.pre),
|
29
|
+
_step;
|
30
|
+
|
31
|
+
try {
|
32
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
33
|
+
var pre = _step.value;
|
34
|
+
|
35
|
+
for (var j = i + 1; j < plugins.length; j++) {
|
36
|
+
if (plugins[j].name === pre) {
|
37
|
+
plugins = [].concat(_toConsumableArray(plugins.slice(0, i)), [plugins[j]], _toConsumableArray(plugins.slice(i, j)), _toConsumableArray(plugins.slice(j + 1, plugins.length)));
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
} catch (err) {
|
42
|
+
_iterator.e(err);
|
43
|
+
} finally {
|
44
|
+
_iterator.f();
|
45
|
+
}
|
46
|
+
|
47
|
+
var _iterator2 = _createForOfIteratorHelper(plugin.post),
|
48
|
+
_step2;
|
49
|
+
|
50
|
+
try {
|
51
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
52
|
+
var post = _step2.value;
|
53
|
+
|
54
|
+
for (var _j = 0; _j < i; _j++) {
|
55
|
+
if (plugins[_j].name === post) {
|
56
|
+
plugins = [].concat(_toConsumableArray(plugins.slice(0, _j)), _toConsumableArray(plugins.slice(_j + 1, i + 1)), [plugins[_j]], _toConsumableArray(plugins.slice(i + 1, plugins.length)));
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
} catch (err) {
|
61
|
+
_iterator2.e(err);
|
62
|
+
} finally {
|
63
|
+
_iterator2.f();
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
return plugins;
|
68
|
+
}
|
69
|
+
export var includePlugin = function includePlugin(plugins, input) {
|
70
|
+
return plugins.some(function (plugin) {
|
71
|
+
return plugin.name === input.name;
|
72
|
+
});
|
73
|
+
};
|
74
|
+
export var isObject = function isObject(obj) {
|
75
|
+
return obj !== null && _typeof(obj) === 'object';
|
76
|
+
};
|
77
|
+
export var hasOwnProperty = function hasOwnProperty(obj, prop) {
|
78
|
+
return obj.hasOwnProperty(prop);
|
79
|
+
};
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
3
1
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
4
2
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
5
3
|
import { isPipeline, createPipeline, runWithContainer, createContainer } from "../farrow-pipeline";
|
6
4
|
import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
|
7
5
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
8
6
|
import { RunnerContext, useRunner } from "./runner";
|
7
|
+
import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
|
9
8
|
var SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
10
9
|
export var DEFAULT_OPTIONS = {
|
11
10
|
name: 'untitled',
|
@@ -47,9 +46,7 @@ export var createManager = function createManager(hooks, api) {
|
|
47
46
|
input[_key] = arguments[_key];
|
48
47
|
}
|
49
48
|
|
50
|
-
|
51
|
-
var plugin = _input[_i];
|
52
|
-
|
49
|
+
input.forEach(function (plugin) {
|
53
50
|
// already created by createPlugin
|
54
51
|
if (isPlugin(plugin)) {
|
55
52
|
addPlugin(plugin);
|
@@ -65,8 +62,7 @@ export var createManager = function createManager(hooks, api) {
|
|
65
62
|
else {
|
66
63
|
console.warn("Unknown plugin: ".concat(JSON.stringify(plugin)));
|
67
64
|
}
|
68
|
-
}
|
69
|
-
|
65
|
+
});
|
70
66
|
return manager;
|
71
67
|
};
|
72
68
|
|
@@ -221,148 +217,4 @@ export var closeHooksMap = function closeHooksMap(record) {
|
|
221
217
|
}
|
222
218
|
|
223
219
|
return result;
|
224
|
-
};
|
225
|
-
|
226
|
-
var includePlugin = function includePlugin(plugins, input) {
|
227
|
-
var _iterator2 = _createForOfIteratorHelper(plugins),
|
228
|
-
_step2;
|
229
|
-
|
230
|
-
try {
|
231
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
232
|
-
var plugin = _step2.value;
|
233
|
-
|
234
|
-
if (plugin.name === input.name) {
|
235
|
-
return true;
|
236
|
-
}
|
237
|
-
}
|
238
|
-
} catch (err) {
|
239
|
-
_iterator2.e(err);
|
240
|
-
} finally {
|
241
|
-
_iterator2.f();
|
242
|
-
}
|
243
|
-
|
244
|
-
return false;
|
245
|
-
};
|
246
|
-
|
247
|
-
var sortPlugins = function sortPlugins(input) {
|
248
|
-
var plugins = input.slice();
|
249
|
-
|
250
|
-
for (var i = 0; i < plugins.length; i++) {
|
251
|
-
var plugin = plugins[i];
|
252
|
-
|
253
|
-
var _iterator3 = _createForOfIteratorHelper(plugin.pre),
|
254
|
-
_step3;
|
255
|
-
|
256
|
-
try {
|
257
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
258
|
-
var pre = _step3.value;
|
259
|
-
|
260
|
-
for (var j = i + 1; j < plugins.length; j++) {
|
261
|
-
if (plugins[j].name === pre) {
|
262
|
-
plugins = [].concat(_toConsumableArray(plugins.slice(0, i)), [plugins[j]], _toConsumableArray(plugins.slice(i, j)), _toConsumableArray(plugins.slice(j + 1, plugins.length)));
|
263
|
-
}
|
264
|
-
}
|
265
|
-
}
|
266
|
-
} catch (err) {
|
267
|
-
_iterator3.e(err);
|
268
|
-
} finally {
|
269
|
-
_iterator3.f();
|
270
|
-
}
|
271
|
-
|
272
|
-
var _iterator4 = _createForOfIteratorHelper(plugin.post),
|
273
|
-
_step4;
|
274
|
-
|
275
|
-
try {
|
276
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
277
|
-
var post = _step4.value;
|
278
|
-
|
279
|
-
for (var _j = 0; _j < i; _j++) {
|
280
|
-
if (plugins[_j].name === post) {
|
281
|
-
plugins = [].concat(_toConsumableArray(plugins.slice(0, _j)), _toConsumableArray(plugins.slice(_j + 1, i + 1)), [plugins[_j]], _toConsumableArray(plugins.slice(i + 1, plugins.length)));
|
282
|
-
}
|
283
|
-
}
|
284
|
-
}
|
285
|
-
} catch (err) {
|
286
|
-
_iterator4.e(err);
|
287
|
-
} finally {
|
288
|
-
_iterator4.f();
|
289
|
-
}
|
290
|
-
}
|
291
|
-
|
292
|
-
return plugins;
|
293
|
-
};
|
294
|
-
|
295
|
-
var checkPlugins = function checkPlugins(plugins) {
|
296
|
-
var _iterator5 = _createForOfIteratorHelper(plugins),
|
297
|
-
_step5;
|
298
|
-
|
299
|
-
try {
|
300
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
301
|
-
var origin = _step5.value;
|
302
|
-
|
303
|
-
var _iterator6 = _createForOfIteratorHelper(origin.rivals),
|
304
|
-
_step6;
|
305
|
-
|
306
|
-
try {
|
307
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
308
|
-
var rival = _step6.value;
|
309
|
-
|
310
|
-
var _iterator8 = _createForOfIteratorHelper(plugins),
|
311
|
-
_step8;
|
312
|
-
|
313
|
-
try {
|
314
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
315
|
-
var plugin = _step8.value;
|
316
|
-
|
317
|
-
if (rival === plugin.name) {
|
318
|
-
throw new Error("".concat(origin.name, " has rival ").concat(plugin.name));
|
319
|
-
}
|
320
|
-
}
|
321
|
-
} catch (err) {
|
322
|
-
_iterator8.e(err);
|
323
|
-
} finally {
|
324
|
-
_iterator8.f();
|
325
|
-
}
|
326
|
-
}
|
327
|
-
} catch (err) {
|
328
|
-
_iterator6.e(err);
|
329
|
-
} finally {
|
330
|
-
_iterator6.f();
|
331
|
-
}
|
332
|
-
|
333
|
-
var _iterator7 = _createForOfIteratorHelper(origin.required),
|
334
|
-
_step7;
|
335
|
-
|
336
|
-
try {
|
337
|
-
var _loop2 = function _loop2() {
|
338
|
-
var required = _step7.value;
|
339
|
-
|
340
|
-
if (!plugins.some(function (plugin) {
|
341
|
-
return plugin.name === required;
|
342
|
-
})) {
|
343
|
-
throw new Error("The plugin: ".concat(required, " is required when plugin: ").concat(origin.name, " is exist."));
|
344
|
-
}
|
345
|
-
};
|
346
|
-
|
347
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
348
|
-
_loop2();
|
349
|
-
}
|
350
|
-
} catch (err) {
|
351
|
-
_iterator7.e(err);
|
352
|
-
} finally {
|
353
|
-
_iterator7.f();
|
354
|
-
}
|
355
|
-
}
|
356
|
-
} catch (err) {
|
357
|
-
_iterator5.e(err);
|
358
|
-
} finally {
|
359
|
-
_iterator5.f();
|
360
|
-
}
|
361
|
-
};
|
362
|
-
|
363
|
-
export var isObject = function isObject(obj) {
|
364
|
-
return obj !== null && _typeof(obj) === 'object';
|
365
|
-
};
|
366
|
-
export var hasOwnProperty = function hasOwnProperty(obj, prop) {
|
367
|
-
return obj.hasOwnProperty(prop);
|
368
220
|
};
|
@@ -1,8 +1,8 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
1
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
2
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3
4
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4
5
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
6
6
|
import { createAsyncPipeline, useContainer } from "../farrow-pipeline";
|
7
7
|
var ASYNC_WATERFALL_SYMBOL = Symbol["for"]('MODERN_ASYNC_WATERFALL');
|
8
8
|
export var getAsyncBrook = function getAsyncBrook(input) {
|
@@ -58,8 +58,8 @@ export var isAsyncWaterfall = function isAsyncWaterfall(input) {
|
|
58
58
|
|
59
59
|
var mapAsyncBrookToAsyncMiddleware = function mapAsyncBrookToAsyncMiddleware(brook) {
|
60
60
|
return /*#__PURE__*/function () {
|
61
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, next) {
|
62
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
61
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, next) {
|
62
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
63
63
|
while (1) {
|
64
64
|
switch (_context.prev = _context.next) {
|
65
65
|
case 0:
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
3
4
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4
5
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
5
6
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
6
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
7
7
|
import { createAsyncPipeline } from "../farrow-pipeline";
|
8
8
|
var ASYNC_WORKFLOW_SYMBOL = Symbol["for"]('MODERN_ASYNC_WORKFLOW');
|
9
9
|
export var isAsyncWorkflow = function isAsyncWorkflow(input) {
|
@@ -22,9 +22,9 @@ export var createAsyncWorkflow = function createAsyncWorkflow() {
|
|
22
22
|
};
|
23
23
|
|
24
24
|
var run = /*#__PURE__*/function () {
|
25
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, options) {
|
25
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, options) {
|
26
26
|
var result;
|
27
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
27
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
28
28
|
while (1) {
|
29
29
|
switch (_context.prev = _context.next) {
|
30
30
|
case 0:
|
@@ -69,8 +69,8 @@ export var createAsyncWorkflow = function createAsyncWorkflow() {
|
|
69
69
|
|
70
70
|
var mapAsyncWorkerToAsyncMiddleware = function mapAsyncWorkerToAsyncMiddleware(worker) {
|
71
71
|
return /*#__PURE__*/function () {
|
72
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(input, next) {
|
73
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
72
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input, next) {
|
73
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
74
74
|
while (1) {
|
75
75
|
switch (_context2.prev = _context2.next) {
|
76
76
|
case 0:
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
2
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
4
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
4
5
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
6
6
|
import { createPipeline } from "../farrow-pipeline";
|
7
7
|
var PARALLEL_WORKFLOW_SYMBOL = Symbol["for"]('MODERN_PARALLEL_WORKFLOW');
|
8
8
|
export var isParallelWorkflow = function isParallelWorkflow(input) {
|
@@ -21,8 +21,8 @@ export var createParallelWorkflow = function createParallelWorkflow() {
|
|
21
21
|
};
|
22
22
|
|
23
23
|
var run = /*#__PURE__*/function () {
|
24
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, options) {
|
25
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
24
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, options) {
|
25
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
26
26
|
while (1) {
|
27
27
|
switch (_context.prev = _context.next) {
|
28
28
|
case 0:
|
@@ -1,8 +1,6 @@
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
2
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
4
3
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
6
4
|
import { createPipeline } from "../farrow-pipeline";
|
7
5
|
var WORKFLOW_SYMBOL = Symbol["for"]('MODERN_WORKFLOW');
|
8
6
|
export var createWorkflow = function createWorkflow() {
|
@@ -17,32 +15,14 @@ export var createWorkflow = function createWorkflow() {
|
|
17
15
|
return workflow;
|
18
16
|
};
|
19
17
|
|
20
|
-
var run =
|
21
|
-
var
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
switch (_context.prev = _context.next) {
|
26
|
-
case 0:
|
27
|
-
result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
28
|
-
onLast: function onLast() {
|
29
|
-
return [];
|
30
|
-
}
|
31
|
-
}));
|
32
|
-
return _context.abrupt("return", result.filter(Boolean));
|
33
|
-
|
34
|
-
case 2:
|
35
|
-
case "end":
|
36
|
-
return _context.stop();
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}, _callee);
|
18
|
+
var run = function run(input, options) {
|
19
|
+
var result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
20
|
+
onLast: function onLast() {
|
21
|
+
return [];
|
22
|
+
}
|
40
23
|
}));
|
41
|
-
|
42
|
-
|
43
|
-
return _ref.apply(this, arguments);
|
44
|
-
};
|
45
|
-
}();
|
24
|
+
return result.filter(Boolean);
|
25
|
+
};
|
46
26
|
|
47
27
|
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
48
28
|
use: use,
|
@@ -21,8 +21,8 @@ export declare const createContainer: (ContextStorage?: ContextStorage) => Conta
|
|
21
21
|
export declare type Hooks = {
|
22
22
|
useContainer: () => Container;
|
23
23
|
};
|
24
|
+
export type { AnyFn } from './asyncHooksInterface';
|
24
25
|
export declare const runHooks: <F extends import("./asyncHooksInterface").AnyFn>(f: F, implementations: Hooks) => ReturnType<F>;
|
25
26
|
export declare const useContainer: () => Container;
|
26
27
|
export declare const fromContainer: (container: Container) => Hooks;
|
27
|
-
export declare const runWithContainer: <F extends (...args: any) => any>(f: F, container: Container) => ReturnType<F>;
|
28
|
-
export {};
|
28
|
+
export declare const runWithContainer: <F extends (...args: any) => any>(f: F, container: Container) => ReturnType<F>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { AsyncPlugin } from './async';
|
2
|
+
import type { Plugin } from './sync';
|
3
|
+
export declare const checkPlugins: <Hooks, API>(plugins: Plugin<Hooks, API>[] | AsyncPlugin<Hooks, API>[]) => void;
|
4
|
+
export declare function sortPlugins<Hooks, API>(input: Plugin<Hooks, API>[]): Plugin<Hooks, API>[];
|
5
|
+
export declare function sortPlugins<Hooks, API>(input: AsyncPlugin<Hooks, API>[]): AsyncPlugin<Hooks, API>[];
|
6
|
+
export declare const includePlugin: <P extends {
|
7
|
+
name: string;
|
8
|
+
}, I extends {
|
9
|
+
name: string;
|
10
|
+
}>(plugins: P[], input: I) => boolean;
|
11
|
+
export declare const isObject: (obj: unknown) => obj is Record<string, any>;
|
12
|
+
export declare const hasOwnProperty: <X extends Record<string, unknown>, Y extends PropertyKey>(obj: X, prop: Y) => obj is X & Record<Y, unknown>;
|
@@ -76,6 +76,4 @@ export declare const createManager: <Hooks, API extends Record<string, any> = Re
|
|
76
76
|
export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[], container: Container, hooksMap?: Hooks | undefined) => ToRunners<Hooks>;
|
77
77
|
export declare const cloneHook: (hook: Hook) => Hook;
|
78
78
|
export declare const closeHooksMap: <Hooks>(record: Hooks) => Hooks;
|
79
|
-
export declare const isObject: (obj: unknown) => obj is Record<string, any>;
|
80
|
-
export declare const hasOwnProperty: <X extends Record<string, unknown>, Y extends PropertyKey>(obj: X, prop: Y) => obj is X & Record<Y, unknown>;
|
81
79
|
export {};
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.3.
|
14
|
+
"version": "1.3.8",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -39,7 +39,7 @@
|
|
39
39
|
}
|
40
40
|
},
|
41
41
|
"dependencies": {
|
42
|
-
"@babel/runtime": "^7"
|
42
|
+
"@babel/runtime": "^7.18.0"
|
43
43
|
},
|
44
44
|
"devDependencies": {
|
45
45
|
"@types/jest": "^27",
|