@modern-js/plugin 1.3.6 → 1.4.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/js/modern/farrow-pipeline/context.js +14 -75
  3. package/dist/js/modern/farrow-pipeline/index.js +0 -14
  4. package/dist/js/modern/farrow-pipeline/pipeline.js +12 -29
  5. package/dist/js/modern/manager/async.js +9 -69
  6. package/dist/js/modern/manager/runner.js +1 -9
  7. package/dist/js/modern/manager/shared.js +44 -0
  8. package/dist/js/modern/manager/sync.js +12 -77
  9. package/dist/js/modern/waterfall/async.js +1 -3
  10. package/dist/js/modern/waterfall/sync.js +1 -3
  11. package/dist/js/modern/workflow/async.js +3 -3
  12. package/dist/js/modern/workflow/parallel.js +2 -2
  13. package/dist/js/modern/workflow/sync.js +3 -3
  14. package/dist/js/node/farrow-pipeline/context.js +15 -88
  15. package/dist/js/node/farrow-pipeline/pipeline.js +10 -45
  16. package/dist/js/node/manager/async.js +12 -72
  17. package/dist/js/node/manager/runner.js +1 -9
  18. package/dist/js/node/manager/shared.js +64 -0
  19. package/dist/js/node/manager/sync.js +19 -87
  20. package/dist/js/node/waterfall/async.js +0 -2
  21. package/dist/js/node/waterfall/sync.js +0 -2
  22. package/dist/js/node/workflow/async.js +3 -3
  23. package/dist/js/node/workflow/parallel.js +2 -2
  24. package/dist/js/node/workflow/sync.js +3 -3
  25. package/dist/js/treeshaking/farrow-pipeline/context.js +14 -75
  26. package/dist/js/treeshaking/farrow-pipeline/index.js +0 -14
  27. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +10 -29
  28. package/dist/js/treeshaking/manager/async.js +15 -160
  29. package/dist/js/treeshaking/manager/runner.js +1 -7
  30. package/dist/js/treeshaking/manager/shared.js +79 -0
  31. package/dist/js/treeshaking/manager/sync.js +12 -168
  32. package/dist/js/treeshaking/waterfall/async.js +1 -3
  33. package/dist/js/treeshaking/waterfall/sync.js +1 -3
  34. package/dist/js/treeshaking/workflow/async.js +6 -6
  35. package/dist/js/treeshaking/workflow/parallel.js +5 -5
  36. package/dist/js/treeshaking/workflow/sync.js +8 -28
  37. package/dist/types/farrow-pipeline/context.d.ts +5 -20
  38. package/dist/types/farrow-pipeline/index.d.ts +0 -14
  39. package/dist/types/farrow-pipeline/pipeline.d.ts +5 -14
  40. package/dist/types/manager/async.d.ts +4 -7
  41. package/dist/types/manager/shared.d.ts +12 -0
  42. package/dist/types/manager/sync.d.ts +5 -11
  43. package/dist/types/manager/types.d.ts +1 -6
  44. package/dist/types/waterfall/async.d.ts +1 -7
  45. package/dist/types/waterfall/sync.d.ts +0 -7
  46. package/dist/types/workflow/async.d.ts +1 -7
  47. package/dist/types/workflow/parallel.d.ts +2 -9
  48. package/dist/types/workflow/sync.d.ts +1 -10
  49. package/package.json +1 -12
  50. package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +0 -74
  51. package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
  52. package/dist/js/modern/farrow-pipeline/hook.js +0 -42
  53. package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -93
  54. package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
  55. package/dist/js/node/farrow-pipeline/hook.js +0 -52
  56. package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -74
  57. package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
  58. package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
  59. package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +0 -2
  60. package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +0 -19
  61. package/dist/types/farrow-pipeline/hook.d.ts +0 -9
@@ -3,47 +3,36 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useContainer = exports.runWithContainer = exports.runHooks = exports.fromContainer = exports.createContext = exports.createContainer = void 0;
7
-
8
- var _hook = require("./hook");
6
+ exports.createContext = void 0;
9
7
 
10
8
  /**
11
9
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
12
10
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
13
11
  */
14
- const ContextSymbol = Symbol.for('MODERN_CONTEXT');
15
-
16
12
  const createContext = value => {
17
- const id = Symbol('MODERN_CONTEXT_ID');
13
+ let currentValue;
18
14
 
19
15
  const create = value => {
20
- const use = () => {
21
- const container = useContainer();
22
- return Object.seal({
23
- get value() {
24
- return container.read(Context);
25
- },
16
+ currentValue = value;
26
17
 
27
- set value(v) {
28
- container.write(Context, v);
29
- }
18
+ const use = () => ({
19
+ get value() {
20
+ return currentValue;
21
+ },
30
22
 
31
- });
32
- };
23
+ set value(v) {
24
+ currentValue = v;
25
+ }
33
26
 
34
- const get = () => {
35
- const container = useContainer();
36
- return container.read(Context);
37
- };
27
+ });
28
+
29
+ const get = () => currentValue;
38
30
 
39
31
  const set = v => {
40
- const container = useContainer();
41
- container.write(Context, v);
32
+ currentValue = v;
42
33
  };
43
34
 
44
35
  const Context = {
45
- id,
46
- [ContextSymbol]: value,
47
36
  create,
48
37
  use,
49
38
  get,
@@ -55,66 +44,4 @@ const createContext = value => {
55
44
  return create(value);
56
45
  };
57
46
 
58
- exports.createContext = createContext;
59
-
60
- const createContextMap = storage => {
61
- const contextMap = new Map();
62
- const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
63
-
64
- for (let i = 0; i < contexts.length; i++) {
65
- contextMap.set(contexts[i].id, contexts[i]);
66
- }
67
-
68
- return contextMap;
69
- };
70
-
71
- const createContainer = (ContextStorage = {}) => {
72
- const contextMap = createContextMap(ContextStorage);
73
-
74
- const read = context => {
75
- const target = contextMap.get(context.id);
76
-
77
- if (target) {
78
- return target[ContextSymbol];
79
- }
80
-
81
- return context[ContextSymbol];
82
- };
83
-
84
- const write = (context, value) => {
85
- contextMap.set(context.id, context.create(value));
86
- };
87
-
88
- return Object.freeze({
89
- read,
90
- write
91
- });
92
- };
93
-
94
- exports.createContainer = createContainer;
95
- const {
96
- run,
97
- hooks
98
- } = (0, _hook.createHooks)({
99
- useContainer: () => {
100
- throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
101
- }
102
- });
103
- const runHooks = run;
104
- exports.runHooks = runHooks;
105
- const {
106
- useContainer
107
- } = hooks;
108
- exports.useContainer = useContainer;
109
-
110
- const fromContainer = container => ({
111
- useContainer: () => {
112
- return container;
113
- }
114
- });
115
-
116
- exports.fromContainer = fromContainer;
117
-
118
- const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
119
-
120
- exports.runWithContainer = runWithContainer;
47
+ exports.createContext = createContext;
@@ -4,12 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createAsyncPipeline = void 0;
7
- Object.defineProperty(exports, "createContainer", {
8
- enumerable: true,
9
- get: function () {
10
- return _context.createContainer;
11
- }
12
- });
13
7
  Object.defineProperty(exports, "createContext", {
14
8
  enumerable: true,
15
9
  get: function () {
@@ -17,18 +11,6 @@ Object.defineProperty(exports, "createContext", {
17
11
  }
18
12
  });
19
13
  exports.isPipeline = exports.createPipeline = void 0;
20
- Object.defineProperty(exports, "runWithContainer", {
21
- enumerable: true,
22
- get: function () {
23
- return _context.runWithContainer;
24
- }
25
- });
26
- Object.defineProperty(exports, "useContainer", {
27
- enumerable: true,
28
- get: function () {
29
- return _context.useContainer;
30
- }
31
- });
32
14
 
33
15
  var _context = require("./context");
34
16
 
@@ -55,9 +37,7 @@ const getMiddleware = input => {
55
37
  throw new Error(`${input} is not a Middleware`);
56
38
  };
57
39
 
58
- const createPipeline = options => {
59
- const config = _objectSpread({}, options);
60
-
40
+ const createPipeline = () => {
61
41
  const middlewares = [];
62
42
 
63
43
  const use = (...inputs) => {
@@ -65,50 +45,35 @@ const createPipeline = options => {
65
45
  return pipeline;
66
46
  };
67
47
 
68
- const createCurrentCounter = (hooks, onLast, onLastWithContext) => {
48
+ const createCurrentCounter = onLast => {
69
49
  return (0, _counter.createCounter)((index, input, next) => {
70
50
  if (index >= middlewares.length) {
71
51
  if (onLast) {
72
- if (onLastWithContext) {
73
- return (0, _context.runHooks)(() => onLast(input), hooks);
74
- }
75
-
76
52
  return onLast(input);
77
53
  }
78
54
 
79
55
  throw new Error(`Expect returning a value, but all middlewares just calling next()`);
80
56
  }
81
57
 
82
- return (0, _context.runHooks)(() => middlewares[index](input, next), hooks);
58
+ return middlewares[index](input, next);
83
59
  });
84
60
  };
85
61
 
86
- const currentContainer = (0, _context.createContainer)(config.contexts);
87
- const currentHooks = (0, _context.fromContainer)(currentContainer);
88
- const currentCounter = createCurrentCounter(currentHooks);
62
+ const currentCounter = createCurrentCounter();
89
63
 
90
64
  const getCounter = options => {
91
65
  if (!options) {
92
66
  return currentCounter;
93
67
  }
94
68
 
95
- if (options !== null && options !== void 0 && options.container) {
96
- const hooks = (0, _context.fromContainer)(options === null || options === void 0 ? void 0 : options.container);
97
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
98
- }
99
-
100
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
69
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
101
70
  };
102
71
 
103
72
  const run = (input, options) => getCounter(options).start(input);
104
73
 
105
- const middleware = (input, next) => {
106
- const container = (0, _context.useContainer)();
107
- return run(input, {
108
- container,
109
- onLast: next
110
- });
111
- };
74
+ const middleware = (input, next) => run(input, {
75
+ onLast: next
76
+ });
112
77
 
113
78
  const pipeline = {
114
79
  [PipelineSymbol]: true,
@@ -121,8 +86,8 @@ const createPipeline = options => {
121
86
 
122
87
  exports.createPipeline = createPipeline;
123
88
 
124
- const createAsyncPipeline = options => {
125
- const pipeline = createPipeline(options);
89
+ const createAsyncPipeline = () => {
90
+ const pipeline = createPipeline();
126
91
  return _objectSpread({}, pipeline);
127
92
  };
128
93
 
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createAsyncManager = void 0;
7
7
 
8
- var _farrowPipeline = require("../farrow-pipeline");
9
-
10
8
  var _sync = require("./sync");
11
9
 
12
10
  var _runner = require("./runner");
13
11
 
12
+ var _shared = require("./shared");
13
+
14
14
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
15
 
16
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -28,7 +28,7 @@ const createAsyncManager = (hooks, api) => {
28
28
  currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
29
29
  };
30
30
 
31
- const isPlugin = input => (0, _sync.isObject)(input) && (0, _sync.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
31
+ const isPlugin = input => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
32
32
 
33
33
  const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
34
34
  useHookRunners: _runner.useRunner
@@ -38,7 +38,7 @@ const createAsyncManager = (hooks, api) => {
38
38
  let plugins = [];
39
39
 
40
40
  const addPlugin = plugin => {
41
- if (!includeAsyncPlugin(plugins, plugin)) {
41
+ if (!(0, _shared.includePlugin)(plugins, plugin)) {
42
42
  plugins.push(_objectSpread({}, plugin));
43
43
  }
44
44
  };
@@ -53,7 +53,7 @@ const createAsyncManager = (hooks, api) => {
53
53
  const options = plugin();
54
54
  addPlugin(createPlugin(options.setup, options));
55
55
  } // plain plugin object
56
- else if ((0, _sync.isObject)(plugin)) {
56
+ else if ((0, _shared.isObject)(plugin)) {
57
57
  addPlugin(createPlugin(plugin.setup, plugin));
58
58
  } // unknown plugin
59
59
  else {
@@ -90,23 +90,17 @@ const createAsyncManager = (hooks, api) => {
90
90
  plugins = [];
91
91
  };
92
92
 
93
- const currentContainer = (0, _farrowPipeline.createContainer)();
94
-
95
- const init = async options => {
96
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
97
- const sortedPlugins = sortAsyncPlugins(plugins);
93
+ const init = async () => {
94
+ const sortedPlugins = (0, _shared.sortPlugins)(plugins);
98
95
 
99
96
  const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
100
97
 
101
- checkAsyncPlugins(sortedPlugins);
102
- const hooksList = await Promise.all(sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.setup(mergedPluginAPI), container)));
103
- return (0, _sync.generateRunner)(hooksList, container, currentHooks);
98
+ (0, _shared.checkPlugins)(sortedPlugins);
99
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI)));
100
+ return (0, _sync.generateRunner)(hooksList, currentHooks);
104
101
  };
105
102
 
106
- const run = (cb, options) => {
107
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
108
- return (0, _farrowPipeline.runWithContainer)(cb, container);
109
- };
103
+ const run = cb => cb();
110
104
 
111
105
  const manager = {
112
106
  createPlugin,
@@ -125,58 +119,4 @@ const createAsyncManager = (hooks, api) => {
125
119
  return clone();
126
120
  };
127
121
 
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
- };
122
+ exports.createAsyncManager = createAsyncManager;
@@ -10,14 +10,6 @@ var _farrowPipeline = require("../farrow-pipeline");
10
10
  const RunnerContext = (0, _farrowPipeline.createContext)(null);
11
11
  exports.RunnerContext = RunnerContext;
12
12
 
13
- const useRunner = () => {
14
- const runner = RunnerContext.use().value;
15
-
16
- if (!runner) {
17
- throw new Error(`Can't call useRunner out of scope, it should be placed in hooks of plugin`);
18
- }
19
-
20
- return runner;
21
- };
13
+ const useRunner = () => RunnerContext.get();
22
14
 
23
15
  exports.useRunner = useRunner;
@@ -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.isObject = exports.hasOwnProperty = exports.generateRunner = exports.createManager = exports.closeHooksMap = exports.cloneHook = exports.DEFAULT_OPTIONS = void 0;
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
- for (const plugin of input) {
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
 
@@ -102,23 +103,17 @@ const createManager = (hooks, api) => {
102
103
  plugins = [];
103
104
  };
104
105
 
105
- const currentContainer = (0, _farrowPipeline.createContainer)();
106
-
107
- const init = options => {
108
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
109
- const sortedPlugins = sortPlugins(plugins);
106
+ const init = () => {
107
+ const sortedPlugins = (0, _shared.sortPlugins)(plugins);
110
108
 
111
109
  const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
112
110
 
113
- checkPlugins(sortedPlugins);
114
- const hooksList = sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.setup(mergedPluginAPI), container));
115
- return generateRunner(hooksList, container, currentHooks);
111
+ (0, _shared.checkPlugins)(sortedPlugins);
112
+ const hooksList = sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI));
113
+ return generateRunner(hooksList, currentHooks);
116
114
  };
117
115
 
118
- const run = (cb, options) => {
119
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
120
- return (0, _farrowPipeline.runWithContainer)(cb, container);
121
- };
116
+ const run = cb => cb();
122
117
 
123
118
  const manager = {
124
119
  createPlugin,
@@ -139,7 +134,7 @@ const createManager = (hooks, api) => {
139
134
 
140
135
  exports.createManager = createManager;
141
136
 
142
- const generateRunner = (hooksList, container, hooksMap) => {
137
+ const generateRunner = (hooksList, hooksMap) => {
143
138
  const runner = {};
144
139
  const cloneShape = closeHooksMap(hooksMap);
145
140
 
@@ -157,13 +152,12 @@ const generateRunner = (hooksList, container, hooksMap) => {
157
152
  // @ts-expect-error
158
153
 
159
154
 
160
- runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({
161
- container
162
- }, options));
155
+ runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({}, options));
163
156
  }
164
157
  }
165
158
 
166
- container.write(_runner.RunnerContext, runner);
159
+ _runner.RunnerContext.set(runner);
160
+
167
161
  return runner;
168
162
  };
169
163
 
@@ -215,66 +209,4 @@ const closeHooksMap = record => {
215
209
  return result;
216
210
  };
217
211
 
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;
212
+ exports.closeHooksMap = closeHooksMap;
@@ -40,9 +40,7 @@ const createAsyncWaterfall = () => {
40
40
  }));
41
41
 
42
42
  const middleware = input => {
43
- const container = (0, _farrowPipeline.useContainer)();
44
43
  return pipeline.run(input, {
45
- container,
46
44
  onLast: input => input
47
45
  });
48
46
  };
@@ -40,9 +40,7 @@ const createWaterfall = () => {
40
40
  }));
41
41
 
42
42
  const middleware = input => {
43
- const container = (0, _farrowPipeline.useContainer)();
44
43
  return pipeline.run(input, {
45
- container,
46
44
  onLast: input => input
47
45
  });
48
46
  };
@@ -27,10 +27,10 @@ const createAsyncWorkflow = () => {
27
27
  return workflow;
28
28
  };
29
29
 
30
- const run = async (input, options) => {
31
- const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
30
+ const run = async input => {
31
+ const result = pipeline.run(input, {
32
32
  onLast: () => []
33
- }));
33
+ });
34
34
 
35
35
  if (isPromise(result)) {
36
36
  return result.then(result => result.filter(Boolean));
@@ -27,9 +27,9 @@ const createParallelWorkflow = () => {
27
27
  return workflow;
28
28
  };
29
29
 
30
- const run = async (input, options) => Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
30
+ const run = async input => Promise.all(pipeline.run(input, {
31
31
  onLast: () => []
32
- }))).then(result => result.filter(Boolean));
32
+ })).then(result => result.filter(Boolean));
33
33
 
34
34
  const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
35
35
  run,