@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.
Files changed (57) hide show
  1. package/CHANGELOG.md +14 -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 +25 -15
  20. package/dist/js/node/farrow-pipeline/counter.js +23 -13
  21. package/dist/js/node/farrow-pipeline/index.js +17 -16
  22. package/dist/js/node/farrow-pipeline/pipeline.js +54 -30
  23. package/dist/js/node/index.js +20 -49
  24. package/dist/js/node/manager/async.js +92 -47
  25. package/dist/js/node/manager/index.js +19 -38
  26. package/dist/js/node/manager/shared.js +38 -21
  27. package/dist/js/node/manager/sync.js +92 -71
  28. package/dist/js/node/utils/pluginDagSort.js +45 -26
  29. package/dist/js/node/waterfall/async.js +79 -28
  30. package/dist/js/node/waterfall/index.js +18 -27
  31. package/dist/js/node/waterfall/sync.js +54 -27
  32. package/dist/js/node/workflow/async.js +75 -24
  33. package/dist/js/node/workflow/index.js +19 -38
  34. package/dist/js/node/workflow/parallel.js +72 -19
  35. package/dist/js/node/workflow/sync.js +49 -20
  36. package/dist/js/treeshaking/farrow-pipeline/context.js +30 -34
  37. package/dist/js/treeshaking/farrow-pipeline/counter.js +16 -20
  38. package/dist/js/treeshaking/farrow-pipeline/index.js +1 -5
  39. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +106 -59
  40. package/dist/js/treeshaking/index.js +1 -1
  41. package/dist/js/treeshaking/manager/async.js +297 -115
  42. package/dist/js/treeshaking/manager/index.js +1 -1
  43. package/dist/js/treeshaking/manager/shared.js +29 -29
  44. package/dist/js/treeshaking/manager/sync.js +213 -168
  45. package/dist/js/treeshaking/manager/types.js +1 -0
  46. package/dist/js/treeshaking/utils/pluginDagSort.js +67 -72
  47. package/dist/js/treeshaking/waterfall/async.js +266 -68
  48. package/dist/js/treeshaking/waterfall/index.js +1 -1
  49. package/dist/js/treeshaking/waterfall/sync.js +122 -46
  50. package/dist/js/treeshaking/workflow/async.js +285 -84
  51. package/dist/js/treeshaking/workflow/index.js +1 -1
  52. package/dist/js/treeshaking/workflow/parallel.js +244 -49
  53. package/dist/js/treeshaking/workflow/sync.js +110 -32
  54. package/dist/types/manager/async.d.ts +9 -0
  55. package/dist/types/manager/sync.d.ts +9 -0
  56. package/dist/types/manager/types.d.ts +9 -2
  57. package/package.json +3 -3
@@ -1,36 +1,114 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
- import { createPipeline } from "../farrow-pipeline";
5
- var WORKFLOW_SYMBOL = Symbol["for"]('MODERN_WORKFLOW');
6
- export var createWorkflow = function createWorkflow() {
7
- var pipeline = createPipeline();
8
- var use = function use() {
9
- for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
10
- input[_key] = arguments[_key];
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function _defineProperty(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
22
+ function _iterableToArray(iter) {
23
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
24
+ }
25
+ function _nonIterableSpread() {
26
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
27
+ }
28
+ function _objectSpread(target) {
29
+ for(var i = 1; i < arguments.length; i++){
30
+ var source = arguments[i] != null ? arguments[i] : {};
31
+ var ownKeys = Object.keys(source);
32
+ if (typeof Object.getOwnPropertySymbols === "function") {
33
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
34
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
35
+ }));
36
+ }
37
+ ownKeys.forEach(function(key) {
38
+ _defineProperty(target, key, source[key]);
39
+ });
40
+ }
41
+ return target;
42
+ }
43
+ function ownKeys(object, enumerableOnly) {
44
+ var keys = Object.keys(object);
45
+ if (Object.getOwnPropertySymbols) {
46
+ var symbols = Object.getOwnPropertySymbols(object);
47
+ if (enumerableOnly) {
48
+ symbols = symbols.filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
50
+ });
51
+ }
52
+ keys.push.apply(keys, symbols);
11
53
  }
12
- pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapWorkerToMiddleware)));
54
+ return keys;
55
+ }
56
+ function _objectSpreadProps(target, source) {
57
+ source = source != null ? source : {};
58
+ if (Object.getOwnPropertyDescriptors) {
59
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
60
+ } else {
61
+ ownKeys(Object(source)).forEach(function(key) {
62
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
63
+ });
64
+ }
65
+ return target;
66
+ }
67
+ function _toConsumableArray(arr) {
68
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
69
+ }
70
+ function _unsupportedIterableToArray(o, minLen) {
71
+ if (!o) return;
72
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
73
+ var n = Object.prototype.toString.call(o).slice(8, -1);
74
+ if (n === "Object" && o.constructor) n = o.constructor.name;
75
+ if (n === "Map" || n === "Set") return Array.from(n);
76
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
77
+ }
78
+ import { createPipeline } from "../farrow-pipeline";
79
+ var WORKFLOW_SYMBOL = Symbol.for("MODERN_WORKFLOW");
80
+ var createWorkflow = function() {
81
+ var pipeline = createPipeline();
82
+ var use = function() {
83
+ for(var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++){
84
+ input[_key] = arguments[_key];
85
+ }
86
+ var _pipeline;
87
+ (_pipeline = pipeline).use.apply(_pipeline, _toConsumableArray(input.map(mapWorkerToMiddleware)));
88
+ return workflow;
89
+ };
90
+ var run = function(input) {
91
+ var result = pipeline.run(input, {
92
+ onLast: function() {
93
+ return [];
94
+ }
95
+ });
96
+ return result.filter(Boolean);
97
+ };
98
+ var workflow = _objectSpreadProps(_objectSpread({}, pipeline), _defineProperty({
99
+ use: use,
100
+ run: run
101
+ }, WORKFLOW_SYMBOL, true));
13
102
  return workflow;
14
- };
15
- var run = function run(input) {
16
- var result = pipeline.run(input, {
17
- onLast: function onLast() {
18
- return [];
19
- }
20
- });
21
- return result.filter(Boolean);
22
- };
23
- var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
24
- use: use,
25
- run: run
26
- }, WORKFLOW_SYMBOL, true));
27
- return workflow;
28
103
  };
29
- export var isWorkflow = function isWorkflow(input) {
30
- return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
104
+ var isWorkflow = function(input) {
105
+ return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
106
+ };
107
+ var mapWorkerToMiddleware = function(worker) {
108
+ return function(input, next) {
109
+ return [
110
+ worker(input)
111
+ ].concat(_toConsumableArray(next(input)));
112
+ };
31
113
  };
32
- var mapWorkerToMiddleware = function mapWorkerToMiddleware(worker) {
33
- return function (input, next) {
34
- return [worker(input)].concat(_toConsumableArray(next(input)));
35
- };
36
- };
114
+ export { createWorkflow, isWorkflow };
@@ -1,5 +1,6 @@
1
1
  import type { ToRunners, ToThreads, CommonAPI, PluginOptions } from './types';
2
2
  /** Setup function of async plugin. */
3
+
3
4
  export declare type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
4
5
  declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
5
6
  export declare type AsyncPlugin<Hooks, API> = {
@@ -16,38 +17,46 @@ export declare type AsyncManager<Hooks, API> = {
16
17
  * Determine if a value is a async plugin.
17
18
  * @param input
18
19
  */
20
+
19
21
  isPlugin: (input: unknown) => input is AsyncPlugin<Hooks, API>;
20
22
  /**
21
23
  * Register new plugins to current manager.
22
24
  * @param plugins one or more plugin.
23
25
  */
26
+
24
27
  usePlugin: (...plugins: Array<AsyncPlugin<Hooks, API> | PluginOptions<Hooks, AsyncSetup<Hooks, API>> | (() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>)>) => AsyncManager<Hooks, API>;
25
28
  /**
26
29
  * Init manager, it will call the setup function of all registered plugins.
27
30
  */
31
+
28
32
  init: () => Promise<ToRunners<Hooks>>;
29
33
  /**
30
34
  * Run callback function.
31
35
  * @param callback
32
36
  */
37
+
33
38
  run: <O>(cb: () => O) => O;
34
39
  /**
35
40
  * Register new hooks.
36
41
  * @param newHooks
37
42
  */
43
+
38
44
  registerHook: (newHooks: Partial<Hooks>) => void;
39
45
  /**
40
46
  * Return a cloned manager.
41
47
  * @param overrideAPI override the default plugin API.
42
48
  */
49
+
43
50
  clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => AsyncManager<Hooks, API>;
44
51
  /**
45
52
  * Clear all registered plugins.
46
53
  */
54
+
47
55
  clear: () => void;
48
56
  /**
49
57
  * Get all runner functions of the hooks.
50
58
  */
59
+
51
60
  useRunner: () => ToRunners<Hooks>;
52
61
  };
53
62
  export declare const createAsyncManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => AsyncManager<Hooks, API>;
@@ -1,5 +1,6 @@
1
1
  import type { Hook, CommonAPI, ToRunners, ToThreads, PluginOptions } from './types';
2
2
  /** Setup function of sync plugin. */
3
+
3
4
  export declare type Setup<Hooks, API = Record<string, never>> = (api: API) => Partial<ToThreads<Hooks>> | void;
4
5
  declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
5
6
  export declare type Plugin<Hooks, API> = {
@@ -16,38 +17,46 @@ export declare type Manager<Hooks, API> = {
16
17
  * Determine if a value is a sync plugin.
17
18
  * @param input
18
19
  */
20
+
19
21
  isPlugin: (input: unknown) => input is Plugin<Hooks, API>;
20
22
  /**
21
23
  * Register new plugins to current manager.
22
24
  * @param plugins one or more plugin.
23
25
  */
26
+
24
27
  usePlugin: (...plugins: Array<Plugin<Hooks, API> | PluginOptions<Hooks, Setup<Hooks, API>> | (() => PluginOptions<Hooks, Setup<Hooks, API>>)>) => Manager<Hooks, API>;
25
28
  /**
26
29
  * Init manager, it will call the setup function of all registered plugins.
27
30
  */
31
+
28
32
  init: () => ToRunners<Hooks>;
29
33
  /**
30
34
  * Run callback function.
31
35
  * @param callback
32
36
  */
37
+
33
38
  run: <O>(cb: () => O) => O;
34
39
  /**
35
40
  * Register new hooks.
36
41
  * @param newHooks
37
42
  */
43
+
38
44
  registerHook: (hewHooks: Partial<Hooks>) => void;
39
45
  /**
40
46
  * Clear all registered plugins.
41
47
  */
48
+
42
49
  clear: () => void;
43
50
  /**
44
51
  * Return a cloned manager.
45
52
  * @param overrideAPI override the default plugin API.
46
53
  */
54
+
47
55
  clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => Manager<Hooks, API>;
48
56
  /**
49
57
  * Get all runner functions of the hooks.
50
58
  */
59
+
51
60
  useRunner: () => ToRunners<Hooks>;
52
61
  };
53
62
  export declare const DEFAULT_OPTIONS: {
@@ -2,28 +2,35 @@ import type { Pipeline, MaybeAsync, Middleware, AsyncPipeline } from '../farrow-
2
2
  import type { Brook, Waterfall, AsyncBrook, AsyncWaterfall } from '../waterfall';
3
3
  import type { Worker, Workflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow } from '../workflow';
4
4
  /** All hook types. */
5
+
5
6
  export declare type Hook = Waterfall<any> | AsyncWaterfall<any> | Workflow<any, any> | AsyncWorkflow<any, any> | ParallelWorkflow<any> | Pipeline<any, any> | AsyncPipeline<any, any>;
6
7
  export declare type HooksMap = Record<string, Hook>;
7
8
  /** Extract the type of callback function from a hook. */
9
+
8
10
  export declare type ToThread<P extends Hook> = P extends Workflow<infer I, infer O> ? Worker<I, O> : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends ParallelWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends Waterfall<infer I> ? Brook<I> : P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : P extends Pipeline<infer I, infer O> ? Middleware<I, O> : P extends AsyncPipeline<infer I, infer O> ? Middleware<I, MaybeAsync<O>> : never;
9
11
  /** Extract types of callback function from hooks. */
12
+
10
13
  export declare type ToThreads<PS> = { [K in keyof PS]: PS[K] extends Hook ? ToThread<PS[K]> : PS[K] extends void ? void : never };
11
14
  /** Extract run method from a hook. */
15
+
12
16
  export declare type RunnerFromHook<P extends Hook> = P extends Waterfall<infer I> ? Waterfall<I>['run'] : P extends AsyncWaterfall<infer I> ? AsyncWaterfall<I>['run'] : P extends Workflow<infer I, infer O> ? Workflow<I, O>['run'] : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorkflow<I, O>['run'] : P extends ParallelWorkflow<infer I, infer O> ? ParallelWorkflow<I, O>['run'] : P extends Pipeline<infer I, infer O> ? Pipeline<I, O>['run'] : P extends AsyncPipeline<infer I, infer O> ? AsyncPipeline<I, O>['run'] : never;
13
17
  /** Extract all run methods from hooks. */
18
+
14
19
  export declare type ToRunners<PS> = { [K in keyof PS]: PS[K] extends Hook ? RunnerFromHook<PS[K]> : PS[K] extends void ? void : never };
15
20
  /** All options to define a plugin. */
16
- export declare type PluginOptions<Hooks, Setup = undefined, ExtendHooks = Record<string, unknown>, PluginHooks = any, PluginSetup = any> = {
21
+
22
+ export declare type PluginOptions<Hooks, Setup = undefined, ExtendHooks = Record<string, unknown>> = {
17
23
  name?: string;
18
24
  pre?: string[];
19
25
  post?: string[];
20
26
  setup?: Setup;
21
27
  rivals?: string[];
22
28
  required?: string[];
23
- usePlugins?: PluginOptions<PluginHooks, PluginSetup>[];
29
+ usePlugins?: PluginOptions<any, any>[];
24
30
  registerHook?: Partial<Hooks & ExtendHooks>;
25
31
  };
26
32
  /** Common api of setup function. */
33
+
27
34
  export declare type CommonAPI<Hooks> = {
28
35
  useHookRunners: () => ToRunners<Hooks>;
29
36
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.3",
14
+ "version": "2.0.0-beta.4",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -36,8 +36,8 @@
36
36
  "@types/node": "^14",
37
37
  "typescript": "^4",
38
38
  "jest": "^27",
39
- "@scripts/build": "2.0.0-beta.3",
40
- "@scripts/jest-config": "2.0.0-beta.3"
39
+ "@scripts/build": "2.0.0-beta.4",
40
+ "@scripts/jest-config": "2.0.0-beta.4"
41
41
  },
42
42
  "sideEffects": false,
43
43
  "publishConfig": {