@modern-js/plugin 2.0.0-beta.3 → 2.0.0-beta.6

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 (58) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/js/modern/farrow-pipeline/context.js +8 -10
  3. package/dist/js/modern/farrow-pipeline/counter.js +6 -8
  4. package/dist/js/modern/farrow-pipeline/index.js +1 -5
  5. package/dist/js/modern/farrow-pipeline/pipeline.js +37 -21
  6. package/dist/js/modern/index.js +1 -1
  7. package/dist/js/modern/manager/async.js +77 -38
  8. package/dist/js/modern/manager/index.js +1 -1
  9. package/dist/js/modern/manager/shared.js +20 -11
  10. package/dist/js/modern/manager/sync.js +80 -49
  11. package/dist/js/modern/utils/pluginDagSort.js +28 -21
  12. package/dist/js/modern/waterfall/async.js +63 -20
  13. package/dist/js/modern/waterfall/index.js +1 -1
  14. package/dist/js/modern/waterfall/sync.js +35 -18
  15. package/dist/js/modern/workflow/async.js +59 -17
  16. package/dist/js/modern/workflow/index.js +1 -1
  17. package/dist/js/modern/workflow/parallel.js +53 -11
  18. package/dist/js/modern/workflow/sync.js +30 -12
  19. package/dist/js/node/farrow-pipeline/context.js +29 -15
  20. package/dist/js/node/farrow-pipeline/counter.js +27 -13
  21. package/dist/js/node/farrow-pipeline/index.js +17 -16
  22. package/dist/js/node/farrow-pipeline/pipeline.js +59 -30
  23. package/dist/js/node/index.js +20 -49
  24. package/dist/js/node/manager/async.js +94 -47
  25. package/dist/js/node/manager/index.js +19 -38
  26. package/dist/js/node/manager/shared.js +46 -21
  27. package/dist/js/node/manager/sync.js +98 -71
  28. package/dist/js/node/manager/types.js +15 -0
  29. package/dist/js/node/utils/pluginDagSort.js +49 -26
  30. package/dist/js/node/waterfall/async.js +83 -28
  31. package/dist/js/node/waterfall/index.js +18 -27
  32. package/dist/js/node/waterfall/sync.js +58 -27
  33. package/dist/js/node/workflow/async.js +78 -24
  34. package/dist/js/node/workflow/index.js +19 -38
  35. package/dist/js/node/workflow/parallel.js +75 -19
  36. package/dist/js/node/workflow/sync.js +52 -20
  37. package/dist/js/treeshaking/farrow-pipeline/context.js +30 -34
  38. package/dist/js/treeshaking/farrow-pipeline/counter.js +16 -20
  39. package/dist/js/treeshaking/farrow-pipeline/index.js +1 -5
  40. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +106 -59
  41. package/dist/js/treeshaking/index.js +1 -1
  42. package/dist/js/treeshaking/manager/async.js +297 -115
  43. package/dist/js/treeshaking/manager/index.js +1 -1
  44. package/dist/js/treeshaking/manager/shared.js +29 -29
  45. package/dist/js/treeshaking/manager/sync.js +213 -168
  46. package/dist/js/treeshaking/manager/types.js +1 -0
  47. package/dist/js/treeshaking/utils/pluginDagSort.js +67 -72
  48. package/dist/js/treeshaking/waterfall/async.js +266 -68
  49. package/dist/js/treeshaking/waterfall/index.js +1 -1
  50. package/dist/js/treeshaking/waterfall/sync.js +122 -46
  51. package/dist/js/treeshaking/workflow/async.js +285 -84
  52. package/dist/js/treeshaking/workflow/index.js +1 -1
  53. package/dist/js/treeshaking/workflow/parallel.js +244 -49
  54. package/dist/js/treeshaking/workflow/sync.js +110 -32
  55. package/dist/types/manager/async.d.ts +9 -0
  56. package/dist/types/manager/sync.d.ts +9 -0
  57. package/dist/types/manager/types.d.ts +9 -2
  58. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 2.0.0-beta.6
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - b8bbe036c7: feat: change type logic
12
+ feat: 修改类型相关的逻辑
13
+ - f179749375: fix: the sortPlugins api not work
14
+
15
+ fix: sortPlugins 没有真实生效
16
+
17
+ ## 2.0.0-beta.4
18
+
19
+ ### Major Changes
20
+
21
+ - dda38c9c3e: chore: v2
22
+
23
+ ### Patch Changes
24
+
25
+ - b8bbe036c7: feat: change type logic
26
+ feat: 修改类型相关的逻辑
27
+ - f179749375: fix: the sortPlugins api not work
28
+
29
+ fix: sortPlugins 没有真实生效
30
+
3
31
  ## 2.0.0-beta.3
4
32
 
5
33
  ### Major Changes
@@ -1,12 +1,7 @@
1
- /**
2
- * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
- * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
- */
5
-
6
- export const createContext = value => {
1
+ const createContext = (value) => {
7
2
  let currentValue;
8
- const create = value => {
9
- currentValue = value;
3
+ const create = (value2) => {
4
+ currentValue = value2;
10
5
  const use = () => ({
11
6
  get value() {
12
7
  return currentValue;
@@ -16,7 +11,7 @@ export const createContext = value => {
16
11
  }
17
12
  });
18
13
  const get = () => currentValue;
19
- const set = v => {
14
+ const set = (v) => {
20
15
  currentValue = v;
21
16
  };
22
17
  const Context = {
@@ -28,4 +23,7 @@ export const createContext = value => {
28
23
  return Context;
29
24
  };
30
25
  return create(value);
31
- };
26
+ };
27
+ export {
28
+ createContext
29
+ };
@@ -1,16 +1,14 @@
1
- /**
2
- * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
- * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
- */
5
-
6
- export const createCounter = callback => {
1
+ const createCounter = (callback) => {
7
2
  const dispatch = (index, input) => {
8
3
  const next = (nextInput = input) => dispatch(index + 1, nextInput);
9
4
  return callback(index, input, next);
10
5
  };
11
- const start = input => dispatch(0, input);
6
+ const start = (input) => dispatch(0, input);
12
7
  return {
13
8
  start,
14
9
  dispatch
15
10
  };
16
- };
11
+ };
12
+ export {
13
+ createCounter
14
+ };
@@ -1,5 +1 @@
1
- /**
2
- * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
- * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
- */
5
- export * from "./pipeline";
1
+ export * from "./pipeline";
@@ -1,46 +1,56 @@
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
- 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; }
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; }
4
- /**
5
- * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
6
- * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
7
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
8
17
  import { createContext } from "./context";
9
18
  import { createCounter } from "./counter";
10
- export { createContext };
11
- export const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
12
- const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
13
- const getMiddleware = input => {
14
- if (typeof input === 'function') {
19
+ const isPipeline = (input) => Boolean(input == null ? void 0 : input[PipelineSymbol]);
20
+ const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
21
+ const getMiddleware = (input) => {
22
+ if (typeof input === "function") {
15
23
  return input;
16
- } else if (input && typeof input.middleware === 'function') {
24
+ } else if (input && typeof input.middleware === "function") {
17
25
  return input.middleware;
18
26
  }
19
27
  throw new Error(`${input} is not a Middleware`);
20
28
  };
21
- export const createPipeline = () => {
29
+ const createPipeline = () => {
22
30
  const middlewares = [];
23
31
  const use = (...inputs) => {
24
32
  middlewares.push(...inputs.map(getMiddleware));
25
33
  return pipeline;
26
34
  };
27
- const createCurrentCounter = onLast => {
35
+ const createCurrentCounter = (onLast) => {
28
36
  return createCounter((index, input, next) => {
29
37
  if (index >= middlewares.length) {
30
38
  if (onLast) {
31
39
  return onLast(input);
32
40
  }
33
- throw new Error(`Expect returning a value, but all middlewares just calling next()`);
41
+ throw new Error(
42
+ `Expect returning a value, but all middlewares just calling next()`
43
+ );
34
44
  }
35
45
  return middlewares[index](input, next);
36
46
  });
37
47
  };
38
48
  const currentCounter = createCurrentCounter();
39
- const getCounter = options => {
49
+ const getCounter = (options) => {
40
50
  if (!options) {
41
51
  return currentCounter;
42
52
  }
43
- return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
53
+ return createCurrentCounter(options == null ? void 0 : options.onLast);
44
54
  };
45
55
  const run = (input, options) => getCounter(options).start(input);
46
56
  const middleware = (input, next) => run(input, {
@@ -54,7 +64,13 @@ export const createPipeline = () => {
54
64
  };
55
65
  return pipeline;
56
66
  };
57
- export const createAsyncPipeline = () => {
67
+ const createAsyncPipeline = () => {
58
68
  const pipeline = createPipeline();
59
- return _objectSpread({}, pipeline);
60
- };
69
+ return __spreadValues({}, pipeline);
70
+ };
71
+ export {
72
+ createAsyncPipeline,
73
+ createContext,
74
+ createPipeline,
75
+ isPipeline
76
+ };
@@ -1,4 +1,4 @@
1
1
  export * from "./farrow-pipeline";
2
2
  export * from "./waterfall";
3
3
  export * from "./workflow";
4
- export * from "./manager";
4
+ export * from "./manager";
@@ -1,65 +1,99 @@
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
- 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; }
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; }
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
4
40
  import { generateRunner, DEFAULT_OPTIONS } from "./sync";
5
- import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
6
- const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
7
- export const createAsyncManager = (hooks, api) => {
41
+ import {
42
+ checkPlugins,
43
+ isObject,
44
+ hasOwnProperty,
45
+ sortPlugins,
46
+ includePlugin
47
+ } from "./shared";
48
+ const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
49
+ const createAsyncManager = (hooks, api) => {
8
50
  let index = 0;
9
51
  let runners;
10
- let currentHooks = _objectSpread({}, hooks);
52
+ let currentHooks = __spreadValues({}, hooks);
11
53
  const useRunner = () => runners;
12
- const registerHook = extraHooks => {
13
- currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
54
+ const registerHook = (extraHooks) => {
55
+ currentHooks = __spreadValues(__spreadValues({}, extraHooks), currentHooks);
14
56
  };
15
- const isPlugin = input => isObject(input) && hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
16
- const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
57
+ const isPlugin = (input) => isObject(input) && hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
58
+ const pluginAPI = __spreadProps(__spreadValues({}, api), {
17
59
  useHookRunners: useRunner
18
60
  });
19
- const clone = overrideAPI => {
61
+ const clone = (overrideAPI) => {
20
62
  let plugins = [];
21
- const addPlugin = plugin => {
63
+ const addPlugin = (plugin) => {
22
64
  if (!includePlugin(plugins, plugin)) {
23
- plugins.push(_objectSpread({}, plugin));
65
+ plugins.push(__spreadValues({}, plugin));
24
66
  }
25
67
  };
26
68
  const usePlugin = (...input) => {
27
69
  for (const plugin of input) {
28
- // already created by createPlugin
29
70
  if (isPlugin(plugin)) {
30
71
  addPlugin(plugin);
31
- }
32
- // using function to return plugin options
33
- else if (typeof plugin === 'function') {
72
+ } else if (typeof plugin === "function") {
34
73
  const options = plugin();
35
74
  addPlugin(createPlugin(options.setup, options));
36
- }
37
- // plain plugin object
38
- else if (isObject(plugin)) {
75
+ } else if (isObject(plugin)) {
39
76
  addPlugin(createPlugin(plugin.setup, plugin));
40
- }
41
- // unknown plugin
42
- else {
77
+ } else {
43
78
  console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
44
79
  }
45
80
  }
46
81
  return manager;
47
82
  };
48
- const createPlugin = (
49
- // eslint-disable-next-line @typescript-eslint/no-empty-function
50
- setup = () => {}, options = {}) => {
51
- var _options$usePlugins;
52
- if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
53
- options.usePlugins.forEach(plugin => {
83
+ const createPlugin = (setup = () => {
84
+ }, options = {}) => {
85
+ var _a;
86
+ if ((_a = options.usePlugins) == null ? void 0 : _a.length) {
87
+ options.usePlugins.forEach((plugin) => {
54
88
  usePlugin(createPlugin(plugin.setup, plugin));
55
89
  });
56
90
  }
57
91
  if (options.registerHook) {
58
92
  registerHook(options.registerHook);
59
93
  }
60
- return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
94
+ return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, DEFAULT_OPTIONS), {
61
95
  name: `No.${index++} plugin`
62
- }, options), {}, {
96
+ }), options), {
63
97
  ASYNC_PLUGIN_SYMBOL,
64
98
  setup
65
99
  });
@@ -67,15 +101,17 @@ export const createAsyncManager = (hooks, api) => {
67
101
  const clear = () => {
68
102
  plugins = [];
69
103
  };
70
- const init = async () => {
104
+ const init = () => __async(void 0, null, function* () {
71
105
  const sortedPlugins = sortPlugins(plugins);
72
- const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
106
+ const mergedPluginAPI = __spreadValues(__spreadValues({}, pluginAPI), overrideAPI);
73
107
  checkPlugins(sortedPlugins);
74
- const hooksList = await Promise.all(sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI)));
108
+ const hooksList = yield Promise.all(
109
+ sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))
110
+ );
75
111
  runners = generateRunner(hooksList, currentHooks);
76
112
  return runners;
77
- };
78
- const run = cb => cb();
113
+ });
114
+ const run = (cb) => cb();
79
115
  const manager = {
80
116
  createPlugin,
81
117
  isPlugin,
@@ -90,4 +126,7 @@ export const createAsyncManager = (hooks, api) => {
90
126
  return manager;
91
127
  };
92
128
  return clone();
93
- };
129
+ };
130
+ export {
131
+ createAsyncManager
132
+ };
@@ -1,3 +1,3 @@
1
1
  export * from "./sync";
2
2
  export * from "./async";
3
- export * from "./types";
3
+ export * from "./types";
@@ -1,24 +1,33 @@
1
1
  import { dagSort } from "../utils/pluginDagSort";
2
- export const checkPlugins = plugins => {
3
- plugins.forEach(origin => {
4
- origin.rivals.forEach(rival => {
5
- plugins.forEach(plugin => {
2
+ const checkPlugins = (plugins) => {
3
+ plugins.forEach((origin) => {
4
+ origin.rivals.forEach((rival) => {
5
+ plugins.forEach((plugin) => {
6
6
  if (rival === plugin.name) {
7
7
  throw new Error(`${origin.name} has rival ${plugin.name}`);
8
8
  }
9
9
  });
10
10
  });
11
- origin.required.forEach(required => {
12
- if (!plugins.some(plugin => plugin.name === required)) {
13
- throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
11
+ origin.required.forEach((required) => {
12
+ if (!plugins.some((plugin) => plugin.name === required)) {
13
+ throw new Error(
14
+ `The plugin: ${required} is required when plugin: ${origin.name} is exist.`
15
+ );
14
16
  }
15
17
  });
16
18
  });
17
19
  };
18
- export function sortPlugins(input) {
20
+ function sortPlugins(input) {
19
21
  const plugins = input.slice();
20
22
  return dagSort(plugins);
21
23
  }
22
- export const includePlugin = (plugins, input) => plugins.some(plugin => plugin.name === input.name);
23
- export const isObject = obj => obj !== null && typeof obj === 'object';
24
- export const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
24
+ const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
25
+ const isObject = (obj) => obj !== null && typeof obj === "object";
26
+ const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
27
+ export {
28
+ checkPlugins,
29
+ hasOwnProperty,
30
+ includePlugin,
31
+ isObject,
32
+ sortPlugins
33
+ };
@@ -1,13 +1,47 @@
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
- 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; }
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; }
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
4
20
  import { isPipeline, createPipeline } from "../farrow-pipeline";
5
- import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
6
- import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
7
- import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
8
- const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
9
- export const DEFAULT_OPTIONS = {
10
- name: 'untitled',
21
+ import {
22
+ isWaterfall,
23
+ createWaterfall,
24
+ isAsyncWaterfall,
25
+ createAsyncWaterfall
26
+ } from "../waterfall";
27
+ import {
28
+ isWorkflow,
29
+ createWorkflow,
30
+ isAsyncWorkflow,
31
+ createAsyncWorkflow,
32
+ isParallelWorkflow,
33
+ createParallelWorkflow
34
+ } from "../workflow";
35
+ import {
36
+ checkPlugins,
37
+ hasOwnProperty,
38
+ includePlugin,
39
+ isObject,
40
+ sortPlugins
41
+ } from "./shared";
42
+ const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
43
+ const DEFAULT_OPTIONS = {
44
+ name: "untitled",
11
45
  pre: [],
12
46
  post: [],
13
47
  rivals: [],
@@ -15,62 +49,54 @@ export const DEFAULT_OPTIONS = {
15
49
  usePlugins: [],
16
50
  registerHook: {}
17
51
  };
18
- export const createManager = (hooks, api) => {
52
+ const createManager = (hooks, api) => {
19
53
  let index = 0;
20
54
  let runners;
21
- let currentHooks = _objectSpread({}, hooks);
55
+ let currentHooks = __spreadValues({}, hooks);
22
56
  const useRunner = () => runners;
23
- const registerHook = extraHooks => {
24
- currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
57
+ const registerHook = (extraHooks) => {
58
+ currentHooks = __spreadValues(__spreadValues({}, extraHooks), currentHooks);
25
59
  };
26
- const isPlugin = input => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
27
- const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
60
+ const isPlugin = (input) => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
61
+ const pluginAPI = __spreadProps(__spreadValues({}, api), {
28
62
  useHookRunners: useRunner
29
63
  });
30
- const clone = overrideAPI => {
64
+ const clone = (overrideAPI) => {
31
65
  let plugins = [];
32
- const addPlugin = plugin => {
66
+ const addPlugin = (plugin) => {
33
67
  if (!includePlugin(plugins, plugin)) {
34
- plugins.push(_objectSpread({}, plugin));
68
+ plugins.push(__spreadValues({}, plugin));
35
69
  }
36
70
  };
37
71
  const usePlugin = (...input) => {
38
- input.forEach(plugin => {
39
- // already created by createPlugin
72
+ input.forEach((plugin) => {
40
73
  if (isPlugin(plugin)) {
41
74
  addPlugin(plugin);
42
- }
43
- // using function to return plugin options
44
- else if (typeof plugin === 'function') {
75
+ } else if (typeof plugin === "function") {
45
76
  const options = plugin();
46
77
  addPlugin(createPlugin(options.setup, options));
47
- }
48
- // plain plugin object
49
- else if (isObject(plugin)) {
78
+ } else if (isObject(plugin)) {
50
79
  addPlugin(createPlugin(plugin.setup, plugin));
51
- }
52
- // unknown plugin
53
- else {
80
+ } else {
54
81
  console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
55
82
  }
56
83
  });
57
84
  return manager;
58
85
  };
59
- const createPlugin = (
60
- // eslint-disable-next-line @typescript-eslint/no-empty-function
61
- setup = () => {}, options = {}) => {
62
- var _options$usePlugins;
63
- if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
64
- options.usePlugins.forEach(plugin => {
86
+ const createPlugin = (setup = () => {
87
+ }, options = {}) => {
88
+ var _a;
89
+ if ((_a = options.usePlugins) == null ? void 0 : _a.length) {
90
+ options.usePlugins.forEach((plugin) => {
65
91
  usePlugin(createPlugin(plugin.setup, plugin));
66
92
  });
67
93
  }
68
94
  if (options.registerHook) {
69
95
  registerHook(options.registerHook);
70
96
  }
71
- return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
97
+ return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, DEFAULT_OPTIONS), {
72
98
  name: `No.${index++} plugin`
73
- }, options), {}, {
99
+ }), options), {
74
100
  SYNC_PLUGIN_SYMBOL,
75
101
  setup
76
102
  });
@@ -80,13 +106,15 @@ export const createManager = (hooks, api) => {
80
106
  };
81
107
  const init = () => {
82
108
  const sortedPlugins = sortPlugins(plugins);
83
- const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
109
+ const mergedPluginAPI = __spreadValues(__spreadValues({}, pluginAPI), overrideAPI);
84
110
  checkPlugins(sortedPlugins);
85
- const hooksList = sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI));
111
+ const hooksList = sortedPlugins.map(
112
+ (plugin) => plugin.setup(mergedPluginAPI)
113
+ );
86
114
  runners = generateRunner(hooksList, currentHooks);
87
115
  return runners;
88
116
  };
89
- const run = cb => cb();
117
+ const run = (cb) => cb();
90
118
  const manager = {
91
119
  createPlugin,
92
120
  isPlugin,
@@ -102,7 +130,7 @@ export const createManager = (hooks, api) => {
102
130
  };
103
131
  return clone();
104
132
  };
105
- export const generateRunner = (hooksList, hooksMap) => {
133
+ const generateRunner = (hooksList, hooksMap) => {
106
134
  const runner = {};
107
135
  const cloneShape = cloneHooksMap(hooksMap);
108
136
  if (hooksMap) {
@@ -115,14 +143,12 @@ export const generateRunner = (hooksList, hooksMap) => {
115
143
  cloneShape[key].use(hooks[key]);
116
144
  }
117
145
  }
118
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
119
- // @ts-expect-error
120
- runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({}, options));
146
+ runner[key] = (input, options) => cloneShape[key].run(input, __spreadValues({}, options));
121
147
  }
122
148
  }
123
149
  return runner;
124
150
  };
125
- export const cloneHook = hook => {
151
+ const cloneHook = (hook) => {
126
152
  if (isWaterfall(hook)) {
127
153
  return createWaterfall();
128
154
  }
@@ -143,15 +169,20 @@ export const cloneHook = hook => {
143
169
  }
144
170
  throw new Error(`Unknown hook: ${hook}`);
145
171
  };
146
- export const cloneHooksMap = record => {
172
+ const cloneHooksMap = (record) => {
147
173
  if (!record) {
148
174
  return record;
149
175
  }
150
176
  const result = {};
151
177
  for (const key in record) {
152
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
153
- // @ts-expect-error
154
178
  result[key] = cloneHook(record[key]);
155
179
  }
156
180
  return result;
157
- };
181
+ };
182
+ export {
183
+ DEFAULT_OPTIONS,
184
+ cloneHook,
185
+ cloneHooksMap,
186
+ createManager,
187
+ generateRunner
188
+ };