@modern-js/plugin 1.3.4 → 1.3.7
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 +18 -0
- package/dist/js/modern/farrow-pipeline/context.js +2 -2
- package/dist/js/modern/farrow-pipeline/pipeline.js +1 -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/waterfall/async.js +1 -1
- package/dist/js/modern/waterfall/sync.js +1 -1
- package/dist/js/modern/workflow/async.js +1 -1
- package/dist/js/modern/workflow/parallel.js +1 -1
- package/dist/js/modern/workflow/sync.js +2 -2
- package/dist/js/node/farrow-pipeline/context.js +2 -2
- package/dist/js/node/farrow-pipeline/pipeline.js +1 -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/waterfall/async.js +1 -1
- package/dist/js/node/waterfall/sync.js +1 -1
- package/dist/js/node/workflow/async.js +1 -1
- package/dist/js/node/workflow/parallel.js +1 -1
- package/dist/js/node/workflow/sync.js +2 -2
- package/dist/js/treeshaking/farrow-pipeline/context.js +2 -2
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +1 -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 +4 -4
- package/dist/js/treeshaking/waterfall/sync.js +1 -1
- package/dist/js/treeshaking/workflow/async.js +6 -6
- package/dist/js/treeshaking/workflow/parallel.js +4 -4
- package/dist/js/treeshaking/workflow/sync.js +8 -28
- package/dist/types/manager/shared.d.ts +12 -0
- package/dist/types/manager/sync.d.ts +0 -2
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# @modern-js/plugin
|
2
2
|
|
3
|
+
## 1.3.7
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 1ac68424f: chore(plugin): extract same utils to shared
|
8
|
+
|
9
|
+
## 1.3.6
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- a1198d509: feat: bump babel 7.18.0
|
14
|
+
|
15
|
+
## 1.3.5
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- 54fa1dbd6: fix(plugin): allow multiple versions to be installed
|
20
|
+
|
3
21
|
## 1.3.4
|
4
22
|
|
5
23
|
### Patch Changes
|
@@ -3,9 +3,9 @@
|
|
3
3
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
4
|
*/
|
5
5
|
import { createHooks } from "./hook";
|
6
|
-
const ContextSymbol = Symbol('
|
6
|
+
const ContextSymbol = Symbol.for('MODERN_CONTEXT');
|
7
7
|
export const createContext = value => {
|
8
|
-
const id = Symbol('
|
8
|
+
const id = Symbol('MODERN_CONTEXT_ID');
|
9
9
|
|
10
10
|
const create = value => {
|
11
11
|
const use = () => {
|
@@ -12,7 +12,7 @@ import { createContext, createContainer, fromContainer, runHooks, useContainer,
|
|
12
12
|
import { createCounter } from "./counter";
|
13
13
|
export { createContext, createContainer, useContainer, runWithContainer };
|
14
14
|
export const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
15
|
-
const PipelineSymbol = Symbol('
|
15
|
+
const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
|
16
16
|
|
17
17
|
const getMiddleware = input => {
|
18
18
|
if (typeof input === 'function') {
|
@@ -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
|
+
};
|
@@ -5,7 +5,7 @@ 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 { createAsyncPipeline, useContainer } from "../farrow-pipeline";
|
8
|
-
const ASYNC_WATERFALL_SYMBOL = Symbol('
|
8
|
+
const ASYNC_WATERFALL_SYMBOL = Symbol.for('MODERN_ASYNC_WATERFALL');
|
9
9
|
export const getAsyncBrook = input => {
|
10
10
|
if (typeof input === 'function') {
|
11
11
|
return input;
|
@@ -5,7 +5,7 @@ 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 { useContainer, createPipeline } from "../farrow-pipeline";
|
8
|
-
const WATERFALL_SYMBOL = Symbol('
|
8
|
+
const WATERFALL_SYMBOL = Symbol.for('MODERN_WATERFALL');
|
9
9
|
export const getBrook = input => {
|
10
10
|
if (typeof input === 'function') {
|
11
11
|
return input;
|
@@ -5,7 +5,7 @@ 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 { createAsyncPipeline } from "../farrow-pipeline";
|
8
|
-
const ASYNC_WORKFLOW_SYMBOL = Symbol('
|
8
|
+
const ASYNC_WORKFLOW_SYMBOL = Symbol.for('MODERN_ASYNC_WORKFLOW');
|
9
9
|
export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
10
10
|
export const createAsyncWorkflow = () => {
|
11
11
|
const pipeline = createAsyncPipeline();
|
@@ -5,7 +5,7 @@ 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 { createPipeline } from "../farrow-pipeline";
|
8
|
-
const PARALLEL_WORKFLOW_SYMBOL = Symbol('
|
8
|
+
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for('MODERN_PARALLEL_WORKFLOW');
|
9
9
|
export const isParallelWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
10
10
|
export const createParallelWorkflow = () => {
|
11
11
|
const pipeline = createPipeline();
|
@@ -5,7 +5,7 @@ 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 { createPipeline } from "../farrow-pipeline";
|
8
|
-
const WORKFLOW_SYMBOL = Symbol('
|
8
|
+
const WORKFLOW_SYMBOL = Symbol.for('MODERN_WORKFLOW');
|
9
9
|
export const createWorkflow = () => {
|
10
10
|
const pipeline = createPipeline();
|
11
11
|
|
@@ -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
|
}));
|
@@ -11,10 +11,10 @@ var _hook = require("./hook");
|
|
11
11
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
12
12
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
13
13
|
*/
|
14
|
-
const ContextSymbol = Symbol('
|
14
|
+
const ContextSymbol = Symbol.for('MODERN_CONTEXT');
|
15
15
|
|
16
16
|
const createContext = value => {
|
17
|
-
const id = Symbol('
|
17
|
+
const id = Symbol('MODERN_CONTEXT_ID');
|
18
18
|
|
19
19
|
const create = value => {
|
20
20
|
const use = () => {
|
@@ -43,7 +43,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
43
43
|
const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
44
44
|
|
45
45
|
exports.isPipeline = isPipeline;
|
46
|
-
const PipelineSymbol = Symbol('
|
46
|
+
const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
|
47
47
|
|
48
48
|
const getMiddleware = input => {
|
49
49
|
if (typeof input === 'function') {
|
@@ -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;
|