@modern-js/plugin 2.0.0-beta.0 → 2.0.0-beta.1
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 +14 -0
- package/dist/js/modern/farrow-pipeline/context.js +1 -8
- package/dist/js/modern/farrow-pipeline/counter.js +1 -3
- package/dist/js/modern/farrow-pipeline/pipeline.js +0 -16
- package/dist/js/modern/manager/async.js +8 -27
- package/dist/js/modern/manager/shared.js +3 -23
- package/dist/js/modern/manager/sync.js +10 -41
- package/dist/js/modern/utils/pluginDagSort.js +48 -0
- package/dist/js/modern/waterfall/async.js +0 -10
- package/dist/js/modern/waterfall/sync.js +0 -10
- package/dist/js/modern/workflow/async.js +0 -10
- package/dist/js/modern/workflow/parallel.js +0 -8
- package/dist/js/modern/workflow/sync.js +0 -8
- package/dist/js/node/farrow-pipeline/context.js +1 -10
- package/dist/js/node/farrow-pipeline/counter.js +1 -5
- package/dist/js/node/farrow-pipeline/index.js +0 -2
- package/dist/js/node/farrow-pipeline/pipeline.js +0 -23
- package/dist/js/node/index.js +0 -8
- package/dist/js/node/manager/async.js +8 -32
- package/dist/js/node/manager/index.js +0 -6
- package/dist/js/node/manager/shared.js +3 -32
- package/dist/js/node/manager/sync.js +10 -54
- package/dist/js/node/utils/pluginDagSort.js +55 -0
- package/dist/js/node/waterfall/async.js +0 -18
- package/dist/js/node/waterfall/index.js +0 -4
- package/dist/js/node/waterfall/sync.js +0 -18
- package/dist/js/node/workflow/async.js +0 -16
- package/dist/js/node/workflow/index.js +0 -6
- package/dist/js/node/workflow/parallel.js +0 -14
- package/dist/js/node/workflow/sync.js +0 -14
- package/dist/js/treeshaking/farrow-pipeline/context.js +1 -8
- package/dist/js/treeshaking/farrow-pipeline/counter.js +1 -3
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +0 -16
- package/dist/js/treeshaking/manager/async.js +6 -28
- package/dist/js/treeshaking/manager/shared.js +2 -46
- package/dist/js/treeshaking/manager/sync.js +9 -44
- package/dist/js/treeshaking/utils/pluginDagSort.js +74 -0
- package/dist/js/treeshaking/waterfall/async.js +0 -11
- package/dist/js/treeshaking/waterfall/sync.js +0 -8
- package/dist/js/treeshaking/workflow/async.js +0 -16
- package/dist/js/treeshaking/workflow/parallel.js +0 -8
- package/dist/js/treeshaking/workflow/sync.js +0 -6
- package/dist/types/manager/async.d.ts +0 -9
- package/dist/types/manager/sync.d.ts +0 -9
- package/dist/types/manager/types.d.ts +0 -7
- package/dist/types/utils/pluginDagSort.d.ts +1 -0
- package/package.json +3 -3
@@ -1,31 +1,23 @@
|
|
1
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
|
-
|
3
2
|
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
|
-
|
5
3
|
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
|
-
|
7
4
|
import { createPipeline } from "../farrow-pipeline";
|
8
5
|
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for('MODERN_PARALLEL_WORKFLOW');
|
9
6
|
export const isParallelWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
10
7
|
export const createParallelWorkflow = () => {
|
11
8
|
const pipeline = createPipeline();
|
12
|
-
|
13
9
|
const use = (...input) => {
|
14
10
|
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
15
11
|
return workflow;
|
16
12
|
};
|
17
|
-
|
18
13
|
const run = async input => Promise.all(pipeline.run(input, {
|
19
14
|
onLast: () => []
|
20
15
|
})).then(result => result.filter(Boolean));
|
21
|
-
|
22
16
|
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
23
17
|
run,
|
24
18
|
use,
|
25
19
|
[PARALLEL_WORKFLOW_SYMBOL]: true
|
26
20
|
});
|
27
|
-
|
28
21
|
return workflow;
|
29
22
|
};
|
30
|
-
|
31
23
|
const mapParallelWorkerToAsyncMiddleware = worker => (input, next) => [worker(input), ...next(input)];
|
@@ -1,34 +1,26 @@
|
|
1
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
|
-
|
3
2
|
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
|
-
|
5
3
|
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
|
-
|
7
4
|
import { createPipeline } from "../farrow-pipeline";
|
8
5
|
const WORKFLOW_SYMBOL = Symbol.for('MODERN_WORKFLOW');
|
9
6
|
export const createWorkflow = () => {
|
10
7
|
const pipeline = createPipeline();
|
11
|
-
|
12
8
|
const use = (...input) => {
|
13
9
|
pipeline.use(...input.map(mapWorkerToMiddleware));
|
14
10
|
return workflow;
|
15
11
|
};
|
16
|
-
|
17
12
|
const run = input => {
|
18
13
|
const result = pipeline.run(input, {
|
19
14
|
onLast: () => []
|
20
15
|
});
|
21
16
|
return result.filter(Boolean);
|
22
17
|
};
|
23
|
-
|
24
18
|
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
25
19
|
use,
|
26
20
|
run,
|
27
21
|
[WORKFLOW_SYMBOL]: true
|
28
22
|
});
|
29
|
-
|
30
23
|
return workflow;
|
31
24
|
};
|
32
25
|
export const isWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
33
|
-
|
34
26
|
const mapWorkerToMiddleware = worker => (input, next) => [worker(input), ...next(input)];
|
@@ -4,34 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createContext = void 0;
|
7
|
-
|
8
7
|
/**
|
9
8
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
10
9
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
11
10
|
*/
|
11
|
+
|
12
12
|
const createContext = value => {
|
13
13
|
let currentValue;
|
14
|
-
|
15
14
|
const create = value => {
|
16
15
|
currentValue = value;
|
17
|
-
|
18
16
|
const use = () => ({
|
19
17
|
get value() {
|
20
18
|
return currentValue;
|
21
19
|
},
|
22
|
-
|
23
20
|
set value(v) {
|
24
21
|
currentValue = v;
|
25
22
|
}
|
26
|
-
|
27
23
|
});
|
28
|
-
|
29
24
|
const get = () => currentValue;
|
30
|
-
|
31
25
|
const set = v => {
|
32
26
|
currentValue = v;
|
33
27
|
};
|
34
|
-
|
35
28
|
const Context = {
|
36
29
|
create,
|
37
30
|
use,
|
@@ -40,8 +33,6 @@ const createContext = value => {
|
|
40
33
|
};
|
41
34
|
return Context;
|
42
35
|
};
|
43
|
-
|
44
36
|
return create(value);
|
45
37
|
};
|
46
|
-
|
47
38
|
exports.createContext = createContext;
|
@@ -4,24 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createCounter = void 0;
|
7
|
-
|
8
7
|
/**
|
9
8
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
10
9
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
11
10
|
*/
|
11
|
+
|
12
12
|
const createCounter = callback => {
|
13
13
|
const dispatch = (index, input) => {
|
14
14
|
const next = (nextInput = input) => dispatch(index + 1, nextInput);
|
15
|
-
|
16
15
|
return callback(index, input, next);
|
17
16
|
};
|
18
|
-
|
19
17
|
const start = input => dispatch(0, input);
|
20
|
-
|
21
18
|
return {
|
22
19
|
start,
|
23
20
|
dispatch
|
24
21
|
};
|
25
22
|
};
|
26
|
-
|
27
23
|
exports.createCounter = createCounter;
|
@@ -3,9 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
|
7
6
|
var _pipeline = require("./pipeline");
|
8
|
-
|
9
7
|
Object.keys(_pipeline).forEach(function (key) {
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
11
9
|
if (key in exports && exports[key] === _pipeline[key]) return;
|
@@ -11,70 +11,50 @@ Object.defineProperty(exports, "createContext", {
|
|
11
11
|
}
|
12
12
|
});
|
13
13
|
exports.isPipeline = exports.createPipeline = void 0;
|
14
|
-
|
15
14
|
var _context = require("./context");
|
16
|
-
|
17
15
|
var _counter = require("./counter");
|
18
|
-
|
19
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; }
|
20
|
-
|
21
17
|
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; }
|
22
|
-
|
23
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; }
|
24
|
-
|
25
19
|
const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
26
|
-
|
27
20
|
exports.isPipeline = isPipeline;
|
28
21
|
const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
|
29
|
-
|
30
22
|
const getMiddleware = input => {
|
31
23
|
if (typeof input === 'function') {
|
32
24
|
return input;
|
33
25
|
} else if (input && typeof input.middleware === 'function') {
|
34
26
|
return input.middleware;
|
35
27
|
}
|
36
|
-
|
37
28
|
throw new Error(`${input} is not a Middleware`);
|
38
29
|
};
|
39
|
-
|
40
30
|
const createPipeline = () => {
|
41
31
|
const middlewares = [];
|
42
|
-
|
43
32
|
const use = (...inputs) => {
|
44
33
|
middlewares.push(...inputs.map(getMiddleware));
|
45
34
|
return pipeline;
|
46
35
|
};
|
47
|
-
|
48
36
|
const createCurrentCounter = onLast => {
|
49
37
|
return (0, _counter.createCounter)((index, input, next) => {
|
50
38
|
if (index >= middlewares.length) {
|
51
39
|
if (onLast) {
|
52
40
|
return onLast(input);
|
53
41
|
}
|
54
|
-
|
55
42
|
throw new Error(`Expect returning a value, but all middlewares just calling next()`);
|
56
43
|
}
|
57
|
-
|
58
44
|
return middlewares[index](input, next);
|
59
45
|
});
|
60
46
|
};
|
61
|
-
|
62
47
|
const currentCounter = createCurrentCounter();
|
63
|
-
|
64
48
|
const getCounter = options => {
|
65
49
|
if (!options) {
|
66
50
|
return currentCounter;
|
67
51
|
}
|
68
|
-
|
69
52
|
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
70
53
|
};
|
71
|
-
|
72
54
|
const run = (input, options) => getCounter(options).start(input);
|
73
|
-
|
74
55
|
const middleware = (input, next) => run(input, {
|
75
56
|
onLast: next
|
76
57
|
});
|
77
|
-
|
78
58
|
const pipeline = {
|
79
59
|
[PipelineSymbol]: true,
|
80
60
|
use,
|
@@ -83,12 +63,9 @@ const createPipeline = () => {
|
|
83
63
|
};
|
84
64
|
return pipeline;
|
85
65
|
};
|
86
|
-
|
87
66
|
exports.createPipeline = createPipeline;
|
88
|
-
|
89
67
|
const createAsyncPipeline = () => {
|
90
68
|
const pipeline = createPipeline();
|
91
69
|
return _objectSpread({}, pipeline);
|
92
70
|
};
|
93
|
-
|
94
71
|
exports.createAsyncPipeline = createAsyncPipeline;
|
package/dist/js/node/index.js
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
|
7
6
|
var _farrowPipeline = require("./farrow-pipeline");
|
8
|
-
|
9
7
|
Object.keys(_farrowPipeline).forEach(function (key) {
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
11
9
|
if (key in exports && exports[key] === _farrowPipeline[key]) return;
|
@@ -16,9 +14,7 @@ Object.keys(_farrowPipeline).forEach(function (key) {
|
|
16
14
|
}
|
17
15
|
});
|
18
16
|
});
|
19
|
-
|
20
17
|
var _waterfall = require("./waterfall");
|
21
|
-
|
22
18
|
Object.keys(_waterfall).forEach(function (key) {
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
24
20
|
if (key in exports && exports[key] === _waterfall[key]) return;
|
@@ -29,9 +25,7 @@ Object.keys(_waterfall).forEach(function (key) {
|
|
29
25
|
}
|
30
26
|
});
|
31
27
|
});
|
32
|
-
|
33
28
|
var _workflow = require("./workflow");
|
34
|
-
|
35
29
|
Object.keys(_workflow).forEach(function (key) {
|
36
30
|
if (key === "default" || key === "__esModule") return;
|
37
31
|
if (key in exports && exports[key] === _workflow[key]) return;
|
@@ -42,9 +36,7 @@ Object.keys(_workflow).forEach(function (key) {
|
|
42
36
|
}
|
43
37
|
});
|
44
38
|
});
|
45
|
-
|
46
39
|
var _manager = require("./manager");
|
47
|
-
|
48
40
|
Object.keys(_manager).forEach(function (key) {
|
49
41
|
if (key === "default" || key === "__esModule") return;
|
50
42
|
if (key in exports && exports[key] === _manager[key]) return;
|
@@ -4,81 +4,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createAsyncManager = void 0;
|
7
|
-
|
8
7
|
var _sync = require("./sync");
|
9
|
-
|
10
8
|
var _shared = require("./shared");
|
11
|
-
|
12
9
|
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; }
|
13
|
-
|
14
10
|
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; }
|
15
|
-
|
16
11
|
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; }
|
17
|
-
|
18
12
|
const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
|
19
|
-
|
20
13
|
const createAsyncManager = (hooks, api) => {
|
21
14
|
let index = 0;
|
22
15
|
let runners;
|
23
|
-
|
24
16
|
let currentHooks = _objectSpread({}, hooks);
|
25
|
-
|
26
17
|
const useRunner = () => runners;
|
27
|
-
|
28
18
|
const registerHook = extraHooks => {
|
29
19
|
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
30
20
|
};
|
31
|
-
|
32
21
|
const isPlugin = input => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
|
33
|
-
|
34
22
|
const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
35
23
|
useHookRunners: useRunner
|
36
24
|
});
|
37
|
-
|
38
25
|
const clone = overrideAPI => {
|
39
26
|
let plugins = [];
|
40
|
-
|
41
27
|
const addPlugin = plugin => {
|
42
28
|
if (!(0, _shared.includePlugin)(plugins, plugin)) {
|
43
29
|
plugins.push(_objectSpread({}, plugin));
|
44
30
|
}
|
45
31
|
};
|
46
|
-
|
47
32
|
const usePlugin = (...input) => {
|
48
33
|
for (const plugin of input) {
|
49
34
|
// already created by createPlugin
|
50
35
|
if (isPlugin(plugin)) {
|
51
36
|
addPlugin(plugin);
|
52
|
-
}
|
37
|
+
}
|
38
|
+
// using function to return plugin options
|
53
39
|
else if (typeof plugin === 'function') {
|
54
40
|
const options = plugin();
|
55
41
|
addPlugin(createPlugin(options.setup, options));
|
56
|
-
}
|
42
|
+
}
|
43
|
+
// plain plugin object
|
57
44
|
else if ((0, _shared.isObject)(plugin)) {
|
58
45
|
addPlugin(createPlugin(plugin.setup, plugin));
|
59
|
-
}
|
46
|
+
}
|
47
|
+
// unknown plugin
|
60
48
|
else {
|
61
49
|
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
62
50
|
}
|
63
51
|
}
|
64
|
-
|
65
52
|
return manager;
|
66
53
|
};
|
67
|
-
|
68
|
-
|
54
|
+
const createPlugin = (
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
69
56
|
setup = () => {}, options = {}) => {
|
70
57
|
var _options$usePlugins;
|
71
|
-
|
72
58
|
if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
|
73
59
|
options.usePlugins.forEach(plugin => {
|
74
60
|
usePlugin(createPlugin(plugin.setup, plugin));
|
75
61
|
});
|
76
62
|
}
|
77
|
-
|
78
63
|
if (options.registerHook) {
|
79
64
|
registerHook(options.registerHook);
|
80
65
|
}
|
81
|
-
|
82
66
|
return _objectSpread(_objectSpread(_objectSpread({}, _sync.DEFAULT_OPTIONS), {}, {
|
83
67
|
name: `No.${index++} plugin`
|
84
68
|
}, options), {}, {
|
@@ -86,24 +70,18 @@ const createAsyncManager = (hooks, api) => {
|
|
86
70
|
setup
|
87
71
|
});
|
88
72
|
};
|
89
|
-
|
90
73
|
const clear = () => {
|
91
74
|
plugins = [];
|
92
75
|
};
|
93
|
-
|
94
76
|
const init = async () => {
|
95
77
|
const sortedPlugins = (0, _shared.sortPlugins)(plugins);
|
96
|
-
|
97
78
|
const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
98
|
-
|
99
79
|
(0, _shared.checkPlugins)(sortedPlugins);
|
100
80
|
const hooksList = await Promise.all(sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI)));
|
101
81
|
runners = (0, _sync.generateRunner)(hooksList, currentHooks);
|
102
82
|
return runners;
|
103
83
|
};
|
104
|
-
|
105
84
|
const run = cb => cb();
|
106
|
-
|
107
85
|
const manager = {
|
108
86
|
createPlugin,
|
109
87
|
isPlugin,
|
@@ -117,8 +95,6 @@ const createAsyncManager = (hooks, api) => {
|
|
117
95
|
};
|
118
96
|
return manager;
|
119
97
|
};
|
120
|
-
|
121
98
|
return clone();
|
122
99
|
};
|
123
|
-
|
124
100
|
exports.createAsyncManager = createAsyncManager;
|
@@ -3,9 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
|
7
6
|
var _sync = require("./sync");
|
8
|
-
|
9
7
|
Object.keys(_sync).forEach(function (key) {
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
11
9
|
if (key in exports && exports[key] === _sync[key]) return;
|
@@ -16,9 +14,7 @@ Object.keys(_sync).forEach(function (key) {
|
|
16
14
|
}
|
17
15
|
});
|
18
16
|
});
|
19
|
-
|
20
17
|
var _async = require("./async");
|
21
|
-
|
22
18
|
Object.keys(_async).forEach(function (key) {
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
24
20
|
if (key in exports && exports[key] === _async[key]) return;
|
@@ -29,9 +25,7 @@ Object.keys(_async).forEach(function (key) {
|
|
29
25
|
}
|
30
26
|
});
|
31
27
|
});
|
32
|
-
|
33
28
|
var _types = require("./types");
|
34
|
-
|
35
29
|
Object.keys(_types).forEach(function (key) {
|
36
30
|
if (key === "default" || key === "__esModule") return;
|
37
31
|
if (key in exports && exports[key] === _types[key]) return;
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isObject = exports.includePlugin = exports.hasOwnProperty = exports.checkPlugins = void 0;
|
7
7
|
exports.sortPlugins = sortPlugins;
|
8
|
-
|
8
|
+
var _pluginDagSort = require("../utils/pluginDagSort");
|
9
9
|
const checkPlugins = plugins => {
|
10
10
|
plugins.forEach(origin => {
|
11
11
|
origin.rivals.forEach(rival => {
|
@@ -22,43 +22,14 @@ const checkPlugins = plugins => {
|
|
22
22
|
});
|
23
23
|
});
|
24
24
|
};
|
25
|
-
|
26
25
|
exports.checkPlugins = checkPlugins;
|
27
|
-
|
28
26
|
function sortPlugins(input) {
|
29
|
-
|
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;
|
27
|
+
const plugins = input.slice();
|
28
|
+
return (0, _pluginDagSort.dagSort)(plugins);
|
52
29
|
}
|
53
|
-
|
54
30
|
const includePlugin = (plugins, input) => plugins.some(plugin => plugin.name === input.name);
|
55
|
-
|
56
31
|
exports.includePlugin = includePlugin;
|
57
|
-
|
58
32
|
const isObject = obj => obj !== null && typeof obj === 'object';
|
59
|
-
|
60
33
|
exports.isObject = isObject;
|
61
|
-
|
62
34
|
const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
63
|
-
|
64
35
|
exports.hasOwnProperty = hasOwnProperty;
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.generateRunner = exports.createManager = exports.cloneHooksMap = exports.cloneHook = exports.DEFAULT_OPTIONS = void 0;
|
7
|
-
|
8
7
|
var _farrowPipeline = require("../farrow-pipeline");
|
9
|
-
|
10
8
|
var _waterfall = require("../waterfall");
|
11
|
-
|
12
9
|
var _workflow = require("../workflow");
|
13
|
-
|
14
10
|
var _shared = require("./shared");
|
15
|
-
|
16
11
|
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
|
-
|
18
12
|
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; }
|
19
|
-
|
20
13
|
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; }
|
21
|
-
|
22
14
|
const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
23
15
|
const DEFAULT_OPTIONS = {
|
24
16
|
name: 'untitled',
|
@@ -30,68 +22,59 @@ const DEFAULT_OPTIONS = {
|
|
30
22
|
registerHook: {}
|
31
23
|
};
|
32
24
|
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
33
|
-
|
34
25
|
const createManager = (hooks, api) => {
|
35
26
|
let index = 0;
|
36
27
|
let runners;
|
37
|
-
|
38
28
|
let currentHooks = _objectSpread({}, hooks);
|
39
|
-
|
40
29
|
const useRunner = () => runners;
|
41
|
-
|
42
30
|
const registerHook = extraHooks => {
|
43
31
|
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
44
32
|
};
|
45
|
-
|
46
33
|
const isPlugin = input => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
47
|
-
|
48
34
|
const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
49
35
|
useHookRunners: useRunner
|
50
36
|
});
|
51
|
-
|
52
37
|
const clone = overrideAPI => {
|
53
38
|
let plugins = [];
|
54
|
-
|
55
39
|
const addPlugin = plugin => {
|
56
40
|
if (!(0, _shared.includePlugin)(plugins, plugin)) {
|
57
41
|
plugins.push(_objectSpread({}, plugin));
|
58
42
|
}
|
59
43
|
};
|
60
|
-
|
61
44
|
const usePlugin = (...input) => {
|
62
45
|
input.forEach(plugin => {
|
63
46
|
// already created by createPlugin
|
64
47
|
if (isPlugin(plugin)) {
|
65
48
|
addPlugin(plugin);
|
66
|
-
}
|
49
|
+
}
|
50
|
+
// using function to return plugin options
|
67
51
|
else if (typeof plugin === 'function') {
|
68
52
|
const options = plugin();
|
69
53
|
addPlugin(createPlugin(options.setup, options));
|
70
|
-
}
|
54
|
+
}
|
55
|
+
// plain plugin object
|
71
56
|
else if ((0, _shared.isObject)(plugin)) {
|
72
57
|
addPlugin(createPlugin(plugin.setup, plugin));
|
73
|
-
}
|
58
|
+
}
|
59
|
+
// unknown plugin
|
74
60
|
else {
|
75
61
|
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
76
62
|
}
|
77
63
|
});
|
78
64
|
return manager;
|
79
65
|
};
|
80
|
-
|
81
|
-
|
66
|
+
const createPlugin = (
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
82
68
|
setup = () => {}, options = {}) => {
|
83
69
|
var _options$usePlugins;
|
84
|
-
|
85
70
|
if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
|
86
71
|
options.usePlugins.forEach(plugin => {
|
87
72
|
usePlugin(createPlugin(plugin.setup, plugin));
|
88
73
|
});
|
89
74
|
}
|
90
|
-
|
91
75
|
if (options.registerHook) {
|
92
76
|
registerHook(options.registerHook);
|
93
77
|
}
|
94
|
-
|
95
78
|
return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
|
96
79
|
name: `No.${index++} plugin`
|
97
80
|
}, options), {}, {
|
@@ -99,24 +82,18 @@ const createManager = (hooks, api) => {
|
|
99
82
|
setup
|
100
83
|
});
|
101
84
|
};
|
102
|
-
|
103
85
|
const clear = () => {
|
104
86
|
plugins = [];
|
105
87
|
};
|
106
|
-
|
107
88
|
const init = () => {
|
108
89
|
const sortedPlugins = (0, _shared.sortPlugins)(plugins);
|
109
|
-
|
110
90
|
const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
111
|
-
|
112
91
|
(0, _shared.checkPlugins)(sortedPlugins);
|
113
92
|
const hooksList = sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI));
|
114
93
|
runners = generateRunner(hooksList, currentHooks);
|
115
94
|
return runners;
|
116
95
|
};
|
117
|
-
|
118
96
|
const run = cb => cb();
|
119
|
-
|
120
97
|
const manager = {
|
121
98
|
createPlugin,
|
122
99
|
isPlugin,
|
@@ -130,83 +107,62 @@ const createManager = (hooks, api) => {
|
|
130
107
|
};
|
131
108
|
return manager;
|
132
109
|
};
|
133
|
-
|
134
110
|
return clone();
|
135
111
|
};
|
136
|
-
|
137
112
|
exports.createManager = createManager;
|
138
|
-
|
139
113
|
const generateRunner = (hooksList, hooksMap) => {
|
140
114
|
const runner = {};
|
141
115
|
const cloneShape = cloneHooksMap(hooksMap);
|
142
|
-
|
143
116
|
if (hooksMap) {
|
144
117
|
for (const key in cloneShape) {
|
145
118
|
for (const hooks of hooksList) {
|
146
119
|
if (!hooks) {
|
147
120
|
continue;
|
148
121
|
}
|
149
|
-
|
150
122
|
if (hooks[key]) {
|
151
123
|
cloneShape[key].use(hooks[key]);
|
152
124
|
}
|
153
|
-
}
|
125
|
+
}
|
126
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
154
127
|
// @ts-expect-error
|
155
|
-
|
156
|
-
|
157
128
|
runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({}, options));
|
158
129
|
}
|
159
130
|
}
|
160
|
-
|
161
131
|
return runner;
|
162
132
|
};
|
163
|
-
|
164
133
|
exports.generateRunner = generateRunner;
|
165
|
-
|
166
134
|
const cloneHook = hook => {
|
167
135
|
if ((0, _waterfall.isWaterfall)(hook)) {
|
168
136
|
return (0, _waterfall.createWaterfall)();
|
169
137
|
}
|
170
|
-
|
171
138
|
if ((0, _waterfall.isAsyncWaterfall)(hook)) {
|
172
139
|
return (0, _waterfall.createAsyncWaterfall)();
|
173
140
|
}
|
174
|
-
|
175
141
|
if ((0, _workflow.isWorkflow)(hook)) {
|
176
142
|
return (0, _workflow.createWorkflow)();
|
177
143
|
}
|
178
|
-
|
179
144
|
if ((0, _workflow.isAsyncWorkflow)(hook)) {
|
180
145
|
return (0, _workflow.createAsyncWorkflow)();
|
181
146
|
}
|
182
|
-
|
183
147
|
if ((0, _workflow.isParallelWorkflow)(hook)) {
|
184
148
|
return (0, _workflow.createParallelWorkflow)();
|
185
149
|
}
|
186
|
-
|
187
150
|
if ((0, _farrowPipeline.isPipeline)(hook)) {
|
188
151
|
return (0, _farrowPipeline.createPipeline)();
|
189
152
|
}
|
190
|
-
|
191
153
|
throw new Error(`Unknown hook: ${hook}`);
|
192
154
|
};
|
193
|
-
|
194
155
|
exports.cloneHook = cloneHook;
|
195
|
-
|
196
156
|
const cloneHooksMap = record => {
|
197
157
|
if (!record) {
|
198
158
|
return record;
|
199
159
|
}
|
200
|
-
|
201
160
|
const result = {};
|
202
|
-
|
203
161
|
for (const key in record) {
|
204
162
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
205
163
|
// @ts-expect-error
|
206
164
|
result[key] = cloneHook(record[key]);
|
207
165
|
}
|
208
|
-
|
209
166
|
return result;
|
210
167
|
};
|
211
|
-
|
212
168
|
exports.cloneHooksMap = cloneHooksMap;
|