@modern-js/plugin 2.0.0-beta.3 → 2.0.0-beta.4
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 +8 -10
- package/dist/js/modern/farrow-pipeline/counter.js +6 -8
- package/dist/js/modern/farrow-pipeline/index.js +1 -5
- package/dist/js/modern/farrow-pipeline/pipeline.js +37 -21
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/manager/async.js +77 -38
- package/dist/js/modern/manager/index.js +1 -1
- package/dist/js/modern/manager/shared.js +20 -11
- package/dist/js/modern/manager/sync.js +80 -49
- package/dist/js/modern/utils/pluginDagSort.js +28 -21
- package/dist/js/modern/waterfall/async.js +63 -20
- package/dist/js/modern/waterfall/index.js +1 -1
- package/dist/js/modern/waterfall/sync.js +35 -18
- package/dist/js/modern/workflow/async.js +59 -17
- package/dist/js/modern/workflow/index.js +1 -1
- package/dist/js/modern/workflow/parallel.js +53 -11
- package/dist/js/modern/workflow/sync.js +30 -12
- package/dist/js/node/farrow-pipeline/context.js +25 -15
- package/dist/js/node/farrow-pipeline/counter.js +23 -13
- package/dist/js/node/farrow-pipeline/index.js +17 -16
- package/dist/js/node/farrow-pipeline/pipeline.js +54 -30
- package/dist/js/node/index.js +20 -49
- package/dist/js/node/manager/async.js +92 -47
- package/dist/js/node/manager/index.js +19 -38
- package/dist/js/node/manager/shared.js +38 -21
- package/dist/js/node/manager/sync.js +92 -71
- package/dist/js/node/utils/pluginDagSort.js +45 -26
- package/dist/js/node/waterfall/async.js +79 -28
- package/dist/js/node/waterfall/index.js +18 -27
- package/dist/js/node/waterfall/sync.js +54 -27
- package/dist/js/node/workflow/async.js +75 -24
- package/dist/js/node/workflow/index.js +19 -38
- package/dist/js/node/workflow/parallel.js +72 -19
- package/dist/js/node/workflow/sync.js +49 -20
- package/dist/js/treeshaking/farrow-pipeline/context.js +30 -34
- package/dist/js/treeshaking/farrow-pipeline/counter.js +16 -20
- package/dist/js/treeshaking/farrow-pipeline/index.js +1 -5
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +106 -59
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/manager/async.js +297 -115
- package/dist/js/treeshaking/manager/index.js +1 -1
- package/dist/js/treeshaking/manager/shared.js +29 -29
- package/dist/js/treeshaking/manager/sync.js +213 -168
- package/dist/js/treeshaking/manager/types.js +1 -0
- package/dist/js/treeshaking/utils/pluginDagSort.js +67 -72
- package/dist/js/treeshaking/waterfall/async.js +266 -68
- package/dist/js/treeshaking/waterfall/index.js +1 -1
- package/dist/js/treeshaking/waterfall/sync.js +122 -46
- package/dist/js/treeshaking/workflow/async.js +285 -84
- package/dist/js/treeshaking/workflow/index.js +1 -1
- package/dist/js/treeshaking/workflow/parallel.js +244 -49
- package/dist/js/treeshaking/workflow/sync.js +110 -32
- package/dist/types/manager/async.d.ts +9 -0
- package/dist/types/manager/sync.d.ts +9 -0
- package/dist/types/manager/types.d.ts +9 -2
- package/package.json +3 -3
@@ -1,35 +1,35 @@
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
2
1
|
import { dagSort } from "../utils/pluginDagSort";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
var checkPlugins = function(plugins) {
|
3
|
+
plugins.forEach(function(origin) {
|
4
|
+
origin.rivals.forEach(function(rival) {
|
5
|
+
plugins.forEach(function(plugin) {
|
6
|
+
if (rival === plugin.name) {
|
7
|
+
throw new Error("".concat(origin.name, " has rival ").concat(plugin.name));
|
8
|
+
}
|
9
|
+
});
|
10
|
+
});
|
11
|
+
origin.required.forEach(function(required) {
|
12
|
+
if (!plugins.some(function(plugin) {
|
13
|
+
return plugin.name === required;
|
14
|
+
})) {
|
15
|
+
throw new Error("The plugin: ".concat(required, " is required when plugin: ").concat(origin.name, " is exist."));
|
16
|
+
}
|
17
|
+
});
|
11
18
|
});
|
12
|
-
origin.required.forEach(function (required) {
|
13
|
-
if (!plugins.some(function (plugin) {
|
14
|
-
return plugin.name === required;
|
15
|
-
})) {
|
16
|
-
throw new Error("The plugin: ".concat(required, " is required when plugin: ").concat(origin.name, " is exist."));
|
17
|
-
}
|
18
|
-
});
|
19
|
-
});
|
20
19
|
};
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
function sortPlugins(input) {
|
21
|
+
var plugins = input.slice();
|
22
|
+
return dagSort(plugins);
|
24
23
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
var includePlugin = function(plugins, input) {
|
25
|
+
return plugins.some(function(plugin) {
|
26
|
+
return plugin.name === input.name;
|
27
|
+
});
|
28
|
+
};
|
29
|
+
var isObject = function(obj) {
|
30
|
+
return obj !== null && typeof obj === "object";
|
29
31
|
};
|
30
|
-
|
31
|
-
|
32
|
+
var hasOwnProperty = function(obj, prop) {
|
33
|
+
return obj.hasOwnProperty(prop);
|
32
34
|
};
|
33
|
-
export
|
34
|
-
return obj.hasOwnProperty(prop);
|
35
|
-
};
|
35
|
+
export { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins };
|
@@ -1,181 +1,226 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
function _defineProperty(obj, key, value) {
|
2
|
+
if (key in obj) {
|
3
|
+
Object.defineProperty(obj, key, {
|
4
|
+
value: value,
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true
|
8
|
+
});
|
9
|
+
} else {
|
10
|
+
obj[key] = value;
|
11
|
+
}
|
12
|
+
return obj;
|
13
|
+
}
|
14
|
+
function _objectSpread(target) {
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
17
|
+
var ownKeys = Object.keys(source);
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
21
|
+
}));
|
22
|
+
}
|
23
|
+
ownKeys.forEach(function(key) {
|
24
|
+
_defineProperty(target, key, source[key]);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
return target;
|
28
|
+
}
|
29
|
+
function ownKeys(object, enumerableOnly) {
|
30
|
+
var keys = Object.keys(object);
|
31
|
+
if (Object.getOwnPropertySymbols) {
|
32
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
33
|
+
if (enumerableOnly) {
|
34
|
+
symbols = symbols.filter(function(sym) {
|
35
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
36
|
+
});
|
37
|
+
}
|
38
|
+
keys.push.apply(keys, symbols);
|
39
|
+
}
|
40
|
+
return keys;
|
41
|
+
}
|
42
|
+
function _objectSpreadProps(target, source) {
|
43
|
+
source = source != null ? source : {};
|
44
|
+
if (Object.getOwnPropertyDescriptors) {
|
45
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
46
|
+
} else {
|
47
|
+
ownKeys(Object(source)).forEach(function(key) {
|
48
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
49
|
+
});
|
50
|
+
}
|
51
|
+
return target;
|
52
|
+
}
|
3
53
|
import { isPipeline, createPipeline } from "../farrow-pipeline";
|
4
54
|
import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
|
5
55
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
6
56
|
import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
|
7
|
-
var SYNC_PLUGIN_SYMBOL =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
57
|
+
var SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
58
|
+
var DEFAULT_OPTIONS = {
|
59
|
+
name: "untitled",
|
60
|
+
pre: [],
|
61
|
+
post: [],
|
62
|
+
rivals: [],
|
63
|
+
required: [],
|
64
|
+
usePlugins: [],
|
65
|
+
registerHook: {}
|
16
66
|
};
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
};
|
24
|
-
var registerHook = function registerHook(extraHooks) {
|
25
|
-
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
26
|
-
};
|
27
|
-
var isPlugin = function isPlugin(input) {
|
28
|
-
return isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
29
|
-
};
|
30
|
-
var pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
31
|
-
useHookRunners: useRunner
|
32
|
-
});
|
33
|
-
var clone = function clone(overrideAPI) {
|
34
|
-
var plugins = [];
|
35
|
-
var addPlugin = function addPlugin(plugin) {
|
36
|
-
if (!includePlugin(plugins, plugin)) {
|
37
|
-
plugins.push(_objectSpread({}, plugin));
|
38
|
-
}
|
39
|
-
};
|
40
|
-
var usePlugin = function usePlugin() {
|
41
|
-
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
42
|
-
input[_key] = arguments[_key];
|
43
|
-
}
|
44
|
-
input.forEach(function (plugin) {
|
45
|
-
// already created by createPlugin
|
46
|
-
if (isPlugin(plugin)) {
|
47
|
-
addPlugin(plugin);
|
48
|
-
}
|
49
|
-
// using function to return plugin options
|
50
|
-
else if (typeof plugin === 'function') {
|
51
|
-
var _options = plugin();
|
52
|
-
addPlugin(createPlugin(_options.setup, _options));
|
53
|
-
}
|
54
|
-
// plain plugin object
|
55
|
-
else if (isObject(plugin)) {
|
56
|
-
addPlugin(createPlugin(plugin.setup, plugin));
|
57
|
-
}
|
58
|
-
// unknown plugin
|
59
|
-
else {
|
60
|
-
console.warn("Unknown plugin: ".concat(JSON.stringify(plugin)));
|
61
|
-
}
|
62
|
-
});
|
63
|
-
return manager;
|
67
|
+
var createManager = function(hooks, api) {
|
68
|
+
var index = 0;
|
69
|
+
var runners;
|
70
|
+
var currentHooks = _objectSpread({}, hooks);
|
71
|
+
var useRunner = function() {
|
72
|
+
return runners;
|
64
73
|
};
|
65
|
-
var
|
66
|
-
|
67
|
-
var setup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
68
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
69
|
-
if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
|
70
|
-
options.usePlugins.forEach(function (plugin) {
|
71
|
-
usePlugin(createPlugin(plugin.setup, plugin));
|
72
|
-
});
|
73
|
-
}
|
74
|
-
if (options.registerHook) {
|
75
|
-
registerHook(options.registerHook);
|
76
|
-
}
|
77
|
-
return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
|
78
|
-
name: "No.".concat(index++, " plugin")
|
79
|
-
}, options), {}, {
|
80
|
-
SYNC_PLUGIN_SYMBOL: SYNC_PLUGIN_SYMBOL,
|
81
|
-
setup: setup
|
82
|
-
});
|
83
|
-
};
|
84
|
-
var clear = function clear() {
|
85
|
-
plugins = [];
|
74
|
+
var registerHook = function(extraHooks) {
|
75
|
+
currentHooks = _objectSpread({}, extraHooks, currentHooks);
|
86
76
|
};
|
87
|
-
var
|
88
|
-
|
89
|
-
var mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
90
|
-
checkPlugins(sortedPlugins);
|
91
|
-
var hooksList = sortedPlugins.map(function (plugin) {
|
92
|
-
return plugin.setup(mergedPluginAPI);
|
93
|
-
});
|
94
|
-
runners = generateRunner(hooksList, currentHooks);
|
95
|
-
return runners;
|
77
|
+
var isPlugin = function(input) {
|
78
|
+
return isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
96
79
|
};
|
97
|
-
var
|
98
|
-
|
80
|
+
var pluginAPI = _objectSpreadProps(_objectSpread({}, api), {
|
81
|
+
useHookRunners: useRunner
|
82
|
+
});
|
83
|
+
var clone = function(overrideAPI) {
|
84
|
+
var plugins = [];
|
85
|
+
var addPlugin = function(plugin) {
|
86
|
+
if (!includePlugin(plugins, plugin)) {
|
87
|
+
plugins.push(_objectSpread({}, plugin));
|
88
|
+
}
|
89
|
+
};
|
90
|
+
var usePlugin = function() {
|
91
|
+
for(var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++){
|
92
|
+
input[_key] = arguments[_key];
|
93
|
+
}
|
94
|
+
input.forEach(function(plugin) {
|
95
|
+
if (isPlugin(plugin)) {
|
96
|
+
addPlugin(plugin);
|
97
|
+
} else if (typeof plugin === "function") {
|
98
|
+
var options = plugin();
|
99
|
+
addPlugin(createPlugin(options.setup, options));
|
100
|
+
} else if (isObject(plugin)) {
|
101
|
+
addPlugin(createPlugin(plugin.setup, plugin));
|
102
|
+
} else {
|
103
|
+
console.warn("Unknown plugin: ".concat(JSON.stringify(plugin)));
|
104
|
+
}
|
105
|
+
});
|
106
|
+
return manager;
|
107
|
+
};
|
108
|
+
var createPlugin = function() {
|
109
|
+
var setup = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function() {}, options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
110
|
+
var ref;
|
111
|
+
if ((ref = options.usePlugins) === null || ref === void 0 ? void 0 : ref.length) {
|
112
|
+
options.usePlugins.forEach(function(plugin) {
|
113
|
+
usePlugin(createPlugin(plugin.setup, plugin));
|
114
|
+
});
|
115
|
+
}
|
116
|
+
if (options.registerHook) {
|
117
|
+
registerHook(options.registerHook);
|
118
|
+
}
|
119
|
+
return _objectSpreadProps(_objectSpread(_objectSpreadProps(_objectSpread({}, DEFAULT_OPTIONS), {
|
120
|
+
name: "No.".concat(index++, " plugin")
|
121
|
+
}), options), {
|
122
|
+
SYNC_PLUGIN_SYMBOL: SYNC_PLUGIN_SYMBOL,
|
123
|
+
setup: setup
|
124
|
+
});
|
125
|
+
};
|
126
|
+
var clear = function() {
|
127
|
+
plugins = [];
|
128
|
+
};
|
129
|
+
var init = function() {
|
130
|
+
var sortedPlugins = sortPlugins(plugins);
|
131
|
+
var mergedPluginAPI = _objectSpread({}, pluginAPI, overrideAPI);
|
132
|
+
checkPlugins(sortedPlugins);
|
133
|
+
var hooksList = sortedPlugins.map(function(plugin) {
|
134
|
+
return plugin.setup(mergedPluginAPI);
|
135
|
+
});
|
136
|
+
runners = generateRunner(hooksList, currentHooks);
|
137
|
+
return runners;
|
138
|
+
};
|
139
|
+
var run = function(cb) {
|
140
|
+
return cb();
|
141
|
+
};
|
142
|
+
var manager = {
|
143
|
+
createPlugin: createPlugin,
|
144
|
+
isPlugin: isPlugin,
|
145
|
+
usePlugin: usePlugin,
|
146
|
+
init: init,
|
147
|
+
clear: clear,
|
148
|
+
run: run,
|
149
|
+
registerHook: registerHook,
|
150
|
+
useRunner: useRunner,
|
151
|
+
clone: clone
|
152
|
+
};
|
153
|
+
return manager;
|
99
154
|
};
|
100
|
-
|
101
|
-
createPlugin: createPlugin,
|
102
|
-
isPlugin: isPlugin,
|
103
|
-
usePlugin: usePlugin,
|
104
|
-
init: init,
|
105
|
-
clear: clear,
|
106
|
-
run: run,
|
107
|
-
registerHook: registerHook,
|
108
|
-
useRunner: useRunner,
|
109
|
-
clone: clone
|
110
|
-
};
|
111
|
-
return manager;
|
112
|
-
};
|
113
|
-
return clone();
|
155
|
+
return clone();
|
114
156
|
};
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
157
|
+
var generateRunner = function(hooksList, hooksMap) {
|
158
|
+
var runner = {};
|
159
|
+
var cloneShape = cloneHooksMap(hooksMap);
|
160
|
+
if (hooksMap) {
|
161
|
+
var _loop = function(key) {
|
162
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
163
|
+
try {
|
164
|
+
for(var _iterator = hooksList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
165
|
+
var hooks = _step.value;
|
166
|
+
if (!hooks) {
|
167
|
+
continue;
|
168
|
+
}
|
169
|
+
if (hooks[key]) {
|
170
|
+
cloneShape[key].use(hooks[key]);
|
171
|
+
}
|
172
|
+
}
|
173
|
+
} catch (err) {
|
174
|
+
_didIteratorError = true;
|
175
|
+
_iteratorError = err;
|
176
|
+
} finally{
|
177
|
+
try {
|
178
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
179
|
+
_iterator.return();
|
180
|
+
}
|
181
|
+
} finally{
|
182
|
+
if (_didIteratorError) {
|
183
|
+
throw _iteratorError;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
runner[key] = function(input, options) {
|
188
|
+
return cloneShape[key].run(input, _objectSpread({}, options));
|
189
|
+
};
|
190
|
+
};
|
191
|
+
for(var key in cloneShape)_loop(key);
|
192
|
+
}
|
193
|
+
return runner;
|
194
|
+
};
|
195
|
+
var cloneHook = function(hook) {
|
196
|
+
if (isWaterfall(hook)) {
|
197
|
+
return createWaterfall();
|
145
198
|
}
|
146
|
-
|
147
|
-
|
199
|
+
if (isAsyncWaterfall(hook)) {
|
200
|
+
return createAsyncWaterfall();
|
201
|
+
}
|
202
|
+
if (isWorkflow(hook)) {
|
203
|
+
return createWorkflow();
|
204
|
+
}
|
205
|
+
if (isAsyncWorkflow(hook)) {
|
206
|
+
return createAsyncWorkflow();
|
207
|
+
}
|
208
|
+
if (isParallelWorkflow(hook)) {
|
209
|
+
return createParallelWorkflow();
|
210
|
+
}
|
211
|
+
if (isPipeline(hook)) {
|
212
|
+
return createPipeline();
|
213
|
+
}
|
214
|
+
throw new Error("Unknown hook: ".concat(hook));
|
148
215
|
};
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
return
|
158
|
-
}
|
159
|
-
if (isAsyncWorkflow(hook)) {
|
160
|
-
return createAsyncWorkflow();
|
161
|
-
}
|
162
|
-
if (isParallelWorkflow(hook)) {
|
163
|
-
return createParallelWorkflow();
|
164
|
-
}
|
165
|
-
if (isPipeline(hook)) {
|
166
|
-
return createPipeline();
|
167
|
-
}
|
168
|
-
throw new Error("Unknown hook: ".concat(hook));
|
216
|
+
var cloneHooksMap = function(record) {
|
217
|
+
if (!record) {
|
218
|
+
return record;
|
219
|
+
}
|
220
|
+
var result = {};
|
221
|
+
for(var key in record){
|
222
|
+
result[key] = cloneHook(record[key]);
|
223
|
+
}
|
224
|
+
return result;
|
169
225
|
};
|
170
|
-
export
|
171
|
-
if (!record) {
|
172
|
-
return record;
|
173
|
-
}
|
174
|
-
var result = {};
|
175
|
-
for (var key in record) {
|
176
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
177
|
-
// @ts-expect-error
|
178
|
-
result[key] = cloneHook(record[key]);
|
179
|
-
}
|
180
|
-
return result;
|
181
|
-
};
|
226
|
+
export { DEFAULT_OPTIONS, cloneHook, cloneHooksMap, createManager, generateRunner };
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
@@ -1,74 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
var dagSort = function(plugins) {
|
2
|
+
var _loop = function() {
|
3
|
+
var zep = zeroEndPoints.shift();
|
4
|
+
sortedPoint.push(getPluginByAny(zep));
|
5
|
+
allLines = allLines.filter(function(l) {
|
6
|
+
return l[0] !== getPluginByAny(zep)[key];
|
7
|
+
});
|
8
|
+
var restPoints = plugins.filter(function(item) {
|
9
|
+
return !sortedPoint.find(function(sp) {
|
10
|
+
return sp[key] === item[key];
|
11
|
+
});
|
12
|
+
});
|
13
|
+
zeroEndPoints = restPoints.filter(function(item) {
|
14
|
+
return !allLines.find(function(l) {
|
15
|
+
return l[1] === item[key];
|
16
|
+
});
|
17
|
+
});
|
18
|
+
};
|
19
|
+
var key = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "name", preKey = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "pre", postKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "post";
|
20
|
+
var getPluginByAny = function getPluginByAny(q) {
|
21
|
+
var target = plugins.find(function(item) {
|
22
|
+
return typeof q === "string" ? item[key] === q : item[key] === q[key];
|
23
|
+
});
|
24
|
+
if (!target) {
|
25
|
+
throw new Error("plugin ".concat(q, " not existed"));
|
26
|
+
}
|
27
|
+
return target;
|
28
|
+
};
|
29
|
+
var allLines = [];
|
30
|
+
plugins.forEach(function(item) {
|
31
|
+
item[preKey].forEach(function(p) {
|
32
|
+
if (plugins.find(function(ap) {
|
33
|
+
return ap.name === p;
|
34
|
+
})) {
|
35
|
+
allLines.push([
|
36
|
+
getPluginByAny(p)[key],
|
37
|
+
getPluginByAny(item)[key]
|
38
|
+
]);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
item[postKey].forEach(function(pt) {
|
42
|
+
if (plugins.find(function(ap) {
|
43
|
+
return ap.name === pt;
|
44
|
+
})) {
|
45
|
+
allLines.push([
|
46
|
+
getPluginByAny(item)[key],
|
47
|
+
getPluginByAny(pt)[key]
|
48
|
+
]);
|
49
|
+
}
|
50
|
+
});
|
9
51
|
});
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return target;
|
15
|
-
}
|
16
|
-
plugins.forEach(function (item) {
|
17
|
-
item[preKey].forEach(function (p) {
|
18
|
-
// compatibility: do not add the plugin-name that plugins not have
|
19
|
-
if (plugins.find(function (ap) {
|
20
|
-
return ap.name === p;
|
21
|
-
})) {
|
22
|
-
allLines.push([getPluginByAny(p)[key], getPluginByAny(item)[key]]);
|
23
|
-
}
|
24
|
-
});
|
25
|
-
item[postKey].forEach(function (pt) {
|
26
|
-
// compatibility: do not add the plugin-name that plugins not have
|
27
|
-
if (plugins.find(function (ap) {
|
28
|
-
return ap.name === pt;
|
29
|
-
})) {
|
30
|
-
allLines.push([getPluginByAny(item)[key], getPluginByAny(pt)[key]]);
|
31
|
-
}
|
32
|
-
});
|
33
|
-
});
|
34
|
-
|
35
|
-
// search the zero input plugin
|
36
|
-
var zeroEndPoints = plugins.filter(function (item) {
|
37
|
-
return !allLines.find(function (l) {
|
38
|
-
return l[1] === item[key];
|
39
|
-
});
|
40
|
-
});
|
41
|
-
var sortedPoint = [];
|
42
|
-
var _loop = function _loop() {
|
43
|
-
var zep = zeroEndPoints.shift();
|
44
|
-
sortedPoint.push(getPluginByAny(zep));
|
45
|
-
allLines = allLines.filter(function (l) {
|
46
|
-
return l[0] !== getPluginByAny(zep)[key];
|
52
|
+
var zeroEndPoints = plugins.filter(function(item) {
|
53
|
+
return !allLines.find(function(l) {
|
54
|
+
return l[1] === item[key];
|
55
|
+
});
|
47
56
|
});
|
48
|
-
var
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
while (zeroEndPoints.length) {
|
62
|
-
_loop();
|
63
|
-
}
|
64
|
-
// if has ring, throw error
|
65
|
-
if (allLines.length) {
|
66
|
-
var restInRingPoints = {};
|
67
|
-
allLines.forEach(function (l) {
|
68
|
-
restInRingPoints[l[0]] = true;
|
69
|
-
restInRingPoints[l[1]] = true;
|
70
|
-
});
|
71
|
-
throw new Error("plugins dependences has loop: ".concat(Object.keys(restInRingPoints).join(',')));
|
72
|
-
}
|
73
|
-
return sortedPoint;
|
74
|
-
};
|
57
|
+
var sortedPoint = [];
|
58
|
+
while(zeroEndPoints.length)_loop();
|
59
|
+
if (allLines.length) {
|
60
|
+
var restInRingPoints = {};
|
61
|
+
allLines.forEach(function(l) {
|
62
|
+
restInRingPoints[l[0]] = true;
|
63
|
+
restInRingPoints[l[1]] = true;
|
64
|
+
});
|
65
|
+
throw new Error("plugins dependences has loop: ".concat(Object.keys(restInRingPoints).join(",")));
|
66
|
+
}
|
67
|
+
return sortedPoint;
|
68
|
+
};
|
69
|
+
export { dagSort };
|