@modern-js/plugin 1.0.1 → 1.2.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.
- package/CHANGELOG.md +20 -2
- package/dist/js/modern/index.js +2 -3
- package/dist/js/modern/manager/async.js +3 -3
- package/dist/js/modern/manager/runner.js +1 -1
- package/dist/js/modern/manager/sync.js +3 -8
- package/dist/js/modern/waterfall/async.js +28 -34
- package/dist/js/modern/waterfall/sync.js +29 -36
- package/dist/js/modern/workflow/async.js +31 -30
- package/dist/js/modern/workflow/parallel.js +20 -29
- package/dist/js/modern/workflow/sync.js +20 -27
- package/dist/js/node/index.js +12 -25
- package/dist/js/node/manager/async.js +6 -6
- package/dist/js/node/manager/runner.js +2 -2
- package/dist/js/node/manager/sync.js +8 -14
- package/dist/js/node/waterfall/async.js +27 -34
- package/dist/js/node/waterfall/sync.js +29 -36
- package/dist/js/node/workflow/async.js +30 -30
- package/dist/js/node/workflow/parallel.js +19 -29
- package/dist/js/node/workflow/sync.js +19 -27
- package/dist/js/treeshaking/index.js +2 -3
- package/dist/js/treeshaking/manager/async.js +3 -3
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +3 -8
- package/dist/js/treeshaking/waterfall/async.js +63 -108
- package/dist/js/treeshaking/waterfall/sync.js +36 -39
- package/dist/js/treeshaking/workflow/async.js +89 -88
- package/dist/js/treeshaking/workflow/parallel.js +42 -66
- package/dist/js/treeshaking/workflow/sync.js +50 -30
- package/dist/types/index.d.ts +2 -3
- package/dist/types/manager/runner.d.ts +1 -1
- package/dist/types/manager/sync.d.ts +2 -3
- package/dist/types/waterfall/async.d.ts +9 -5
- package/dist/types/waterfall/sync.d.ts +4 -4
- package/dist/types/workflow/async.d.ts +3 -2
- package/dist/types/workflow/parallel.d.ts +1 -1
- package/dist/types/workflow/sync.d.ts +1 -1
- package/jest.config.js +8 -0
- package/modern.config.js +1 -9
- package/node.d.ts +1 -1
- package/node.js +1 -1
- package/package.json +13 -7
- package/src/index.ts +2 -2
- package/src/manager/async.ts +1 -1
- package/src/manager/runner.ts +1 -1
- package/src/manager/sync.ts +12 -16
- package/src/waterfall/async.ts +34 -49
- package/src/waterfall/sync.ts +26 -45
- package/src/workflow/async.ts +29 -33
- package/src/workflow/parallel.ts +17 -35
- package/src/workflow/sync.ts +13 -35
- package/tests/async.test.ts +14 -10
- package/tests/fixtures/async/base/fooManager.ts +1 -1
- package/tests/fixtures/async/core/index.ts +1 -1
- package/tests/fixtures/async/dynamic/foo.ts +1 -1
- package/tests/fixtures/sync/base/fooManager.ts +1 -1
- package/tests/fixtures/sync/core/index.ts +1 -1
- package/tests/fixtures/sync/dynamic/foo.ts +1 -1
- package/tests/pipeline.test.ts +6 -16
- package/tests/sync.test.ts +13 -9
- package/tests/tsconfig.json +1 -3
- package/tests/waterfall.test.ts +3 -3
- package/tests/workflow.test.ts +2 -2
- package/tsconfig.json +1 -3
- package/dist/js/modern/asyncHooksImpl.js +0 -63
- package/dist/js/modern/asyncHooksInterface.js +0 -16
- package/dist/js/modern/context.js +0 -130
- package/dist/js/modern/counter.js +0 -40
- package/dist/js/modern/hook.js +0 -47
- package/dist/js/modern/pipeline/async.js +0 -97
- package/dist/js/modern/pipeline/index.js +0 -2
- package/dist/js/modern/pipeline/sync.js +0 -97
- package/dist/js/node/asyncHooksImpl.js +0 -82
- package/dist/js/node/asyncHooksInterface.js +0 -30
- package/dist/js/node/context.js +0 -164
- package/dist/js/node/counter.js +0 -52
- package/dist/js/node/hook.js +0 -57
- package/dist/js/node/pipeline/async.js +0 -110
- package/dist/js/node/pipeline/index.js +0 -31
- package/dist/js/node/pipeline/sync.js +0 -110
- package/dist/js/treeshaking/asyncHooksImpl.js +0 -65
- package/dist/js/treeshaking/asyncHooksInterface.js +0 -16
- package/dist/js/treeshaking/context.js +0 -137
- package/dist/js/treeshaking/counter.js +0 -74
- package/dist/js/treeshaking/hook.js +0 -51
- package/dist/js/treeshaking/pipeline/async.js +0 -165
- package/dist/js/treeshaking/pipeline/index.js +0 -2
- package/dist/js/treeshaking/pipeline/sync.js +0 -118
- package/dist/types/asyncHooksImpl.d.ts +0 -10
- package/dist/types/asyncHooksInterface.d.ts +0 -21
- package/dist/types/context.d.ts +0 -47
- package/dist/types/counter.d.ts +0 -22
- package/dist/types/hook.d.ts +0 -13
- package/dist/types/pipeline/async.d.ts +0 -35
- package/dist/types/pipeline/index.d.ts +0 -2
- package/dist/types/pipeline/sync.d.ts +0 -37
- package/src/asyncHooksImpl.ts +0 -64
- package/src/asyncHooksInterface.ts +0 -34
- package/src/context.ts +0 -184
- package/src/counter.ts +0 -78
- package/src/hook.ts +0 -46
- package/src/pipeline/async.ts +0 -155
- package/src/pipeline/index.ts +0 -2
- package/src/pipeline/sync.ts +0 -152
- package/tests/context.test.ts +0 -114
- package/tests/counter.test.ts +0 -31
- package/tests/hook.test.ts +0 -113
@@ -1,6 +1,14 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
2
|
+
|
3
|
+
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; }
|
4
|
+
|
5
|
+
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; }
|
6
|
+
|
1
7
|
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; }
|
2
8
|
|
3
|
-
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
10
|
+
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
4
12
|
|
5
13
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
6
14
|
|
@@ -14,93 +22,61 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
14
22
|
|
15
23
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
16
24
|
|
17
|
-
|
18
|
-
|
19
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
20
|
-
|
21
|
-
import { createAsyncCounter } from "../counter";
|
22
|
-
import { runHooks, fromContainer, createContainer } from "../context";
|
25
|
+
import { createPipeline } from 'farrow-pipeline';
|
23
26
|
var PARALLEL_WORKFLOW_SYMBOL = Symbol('PARALLEL_WORKFLOW_SYMBOL');
|
24
27
|
export var isParallelWorkflow = function isParallelWorkflow(input) {
|
25
28
|
return Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
26
29
|
};
|
27
30
|
export var createParallelWorkflow = function createParallelWorkflow() {
|
28
|
-
var
|
29
|
-
|
30
|
-
var createCurrentRunner = function createCurrentRunner(hooks) {
|
31
|
-
return createAsyncCounter(function (index, input, next) {
|
32
|
-
if (index >= middlewares.length) {
|
33
|
-
return Promise.resolve([]);
|
34
|
-
}
|
35
|
-
|
36
|
-
var middleware = middlewares[index];
|
37
|
-
return runHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
38
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
39
|
-
while (1) {
|
40
|
-
switch (_context.prev = _context.next) {
|
41
|
-
case 0:
|
42
|
-
_context.t0 = Promise;
|
43
|
-
_context.t1 = [middleware(input)];
|
44
|
-
_context.t2 = _toConsumableArray;
|
45
|
-
_context.next = 5;
|
46
|
-
return next(input);
|
47
|
-
|
48
|
-
case 5:
|
49
|
-
_context.t3 = _context.sent;
|
50
|
-
_context.t4 = (0, _context.t2)(_context.t3);
|
51
|
-
_context.t5 = _context.t1.concat.call(_context.t1, _context.t4);
|
52
|
-
return _context.abrupt("return", _context.t0.all.call(_context.t0, _context.t5));
|
53
|
-
|
54
|
-
case 9:
|
55
|
-
case "end":
|
56
|
-
return _context.stop();
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}, _callee);
|
60
|
-
})), hooks);
|
61
|
-
});
|
62
|
-
};
|
63
|
-
|
64
|
-
var currentContainer = createContainer();
|
65
|
-
var currentHooks = fromContainer(currentContainer);
|
66
|
-
var currentRunner = createCurrentRunner(currentHooks);
|
31
|
+
var pipeline = createPipeline();
|
67
32
|
|
68
33
|
var use = function use() {
|
69
|
-
|
34
|
+
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
35
|
+
input[_key] = arguments[_key];
|
36
|
+
}
|
37
|
+
|
38
|
+
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapParallelWorkerToAsyncMiddleware)));
|
70
39
|
return workflow;
|
71
40
|
};
|
72
41
|
|
73
42
|
var run = /*#__PURE__*/function () {
|
74
|
-
var
|
75
|
-
|
76
|
-
|
77
|
-
var container, hooks, runner;
|
78
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
43
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, options) {
|
44
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
79
45
|
while (1) {
|
80
|
-
switch (
|
46
|
+
switch (_context.prev = _context.next) {
|
81
47
|
case 0:
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
48
|
+
return _context.abrupt("return", // eslint-disable-next-line promise/prefer-await-to-then
|
49
|
+
Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
50
|
+
onLast: function onLast() {
|
51
|
+
return [];
|
52
|
+
}
|
53
|
+
}))).then(function (result) {
|
54
|
+
return result.filter(Boolean);
|
55
|
+
}));
|
56
|
+
|
57
|
+
case 1:
|
88
58
|
case "end":
|
89
|
-
return
|
59
|
+
return _context.stop();
|
90
60
|
}
|
91
61
|
}
|
92
|
-
},
|
62
|
+
}, _callee);
|
93
63
|
}));
|
94
64
|
|
95
65
|
return function run(_x, _x2) {
|
96
|
-
return
|
66
|
+
return _ref.apply(this, arguments);
|
97
67
|
};
|
98
68
|
}();
|
99
69
|
|
100
|
-
var workflow = _defineProperty({
|
101
|
-
|
102
|
-
|
103
|
-
}, PARALLEL_WORKFLOW_SYMBOL, true);
|
70
|
+
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
71
|
+
run: run,
|
72
|
+
use: use
|
73
|
+
}, PARALLEL_WORKFLOW_SYMBOL, true));
|
104
74
|
|
105
75
|
return workflow;
|
76
|
+
};
|
77
|
+
|
78
|
+
var mapParallelWorkerToAsyncMiddleware = function mapParallelWorkerToAsyncMiddleware(worker) {
|
79
|
+
return function (input, next) {
|
80
|
+
return [worker(input)].concat(_toConsumableArray(next(input)));
|
81
|
+
};
|
106
82
|
};
|
@@ -1,5 +1,15 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
2
|
+
|
3
|
+
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; }
|
4
|
+
|
5
|
+
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; }
|
6
|
+
|
1
7
|
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; }
|
2
8
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
10
|
+
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
12
|
+
|
3
13
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
4
14
|
|
5
15
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
@@ -12,51 +22,61 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
12
22
|
|
13
23
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
14
24
|
|
15
|
-
import {
|
16
|
-
import { runHooks, fromContainer, createContainer } from "../context";
|
25
|
+
import { createPipeline } from 'farrow-pipeline';
|
17
26
|
var WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
|
18
27
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
19
28
|
export var createWorkflow = function createWorkflow() {
|
20
|
-
var
|
21
|
-
|
22
|
-
var createCurrentRunner = function createCurrentRunner(hooks) {
|
23
|
-
return createCounter(function (index, input, next) {
|
24
|
-
if (index >= middlewares.length) {
|
25
|
-
return [];
|
26
|
-
}
|
27
|
-
|
28
|
-
var middleware = middlewares[index];
|
29
|
-
return runHooks(function () {
|
30
|
-
return [middleware(input)].concat(_toConsumableArray(next(input)));
|
31
|
-
}, hooks);
|
32
|
-
});
|
33
|
-
};
|
34
|
-
|
35
|
-
var currentContainer = createContainer();
|
36
|
-
var currentHooks = fromContainer(currentContainer);
|
37
|
-
var currentRunner = createCurrentRunner(currentHooks);
|
29
|
+
var pipeline = createPipeline();
|
38
30
|
|
39
31
|
var use = function use() {
|
40
|
-
|
32
|
+
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
33
|
+
input[_key] = arguments[_key];
|
34
|
+
}
|
35
|
+
|
36
|
+
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapWorkerToMiddleware)));
|
41
37
|
return workflow;
|
42
38
|
};
|
43
39
|
|
44
|
-
var run = function
|
45
|
-
var
|
40
|
+
var run = /*#__PURE__*/function () {
|
41
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, options) {
|
42
|
+
var result;
|
43
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
44
|
+
while (1) {
|
45
|
+
switch (_context.prev = _context.next) {
|
46
|
+
case 0:
|
47
|
+
result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
48
|
+
onLast: function onLast() {
|
49
|
+
return [];
|
50
|
+
}
|
51
|
+
}));
|
52
|
+
return _context.abrupt("return", result.filter(Boolean));
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
case 2:
|
55
|
+
case "end":
|
56
|
+
return _context.stop();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}, _callee);
|
60
|
+
}));
|
61
|
+
|
62
|
+
return function run(_x, _x2) {
|
63
|
+
return _ref.apply(this, arguments);
|
64
|
+
};
|
65
|
+
}();
|
52
66
|
|
53
|
-
var workflow = _defineProperty({
|
67
|
+
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
54
68
|
use: use,
|
55
69
|
run: run
|
56
|
-
}, WORKFLOW_SYMBOL, true);
|
70
|
+
}, WORKFLOW_SYMBOL, true));
|
57
71
|
|
58
72
|
return workflow;
|
59
73
|
};
|
60
74
|
export var isWorkflow = function isWorkflow(input) {
|
61
75
|
return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
76
|
+
};
|
77
|
+
|
78
|
+
var mapWorkerToMiddleware = function mapWorkerToMiddleware(worker) {
|
79
|
+
return function (input, next) {
|
80
|
+
return [worker(input)].concat(_toConsumableArray(next(input)));
|
81
|
+
};
|
62
82
|
};
|
package/dist/types/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const RunnerContext: import("
|
1
|
+
export declare const RunnerContext: import("farrow-pipeline").Context<any>;
|
2
2
|
export declare const useRunner: () => any;
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { Container } from '
|
1
|
+
import { Middleware, Pipeline, AsyncPipeline, MaybeAsync, Container } from 'farrow-pipeline';
|
2
2
|
import { Waterfall, Brook, AsyncWaterfall, AsyncBrook } from '../waterfall';
|
3
3
|
import { Worker, Workflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow } from '../workflow';
|
4
|
-
import { Middleware, Pipeline, AsyncMiddleware, AsyncPipeline } from '../pipeline';
|
5
4
|
export declare type Initializer<O> = () => O | void;
|
6
5
|
declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
7
6
|
export declare type Plugin<O> = {
|
@@ -21,7 +20,7 @@ export declare type PluginOptions = {
|
|
21
20
|
required?: string[];
|
22
21
|
};
|
23
22
|
export declare type Progress = Waterfall<any> | AsyncWaterfall<any> | Workflow<any, any> | AsyncWorkflow<any, any> | ParallelWorkflow<any> | Pipeline<any, any> | AsyncPipeline<any, any>;
|
24
|
-
export declare type Progress2Thread<P extends Progress> = 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> ?
|
23
|
+
export declare type Progress2Thread<P extends Progress> = 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;
|
25
24
|
export declare type ProgressRecord = Record<string, Progress>;
|
26
25
|
export declare type Progresses2Threads<PS extends ProgressRecord | void> = { [K in keyof PS]: PS[K] extends Progress ? Progress2Thread<PS[K]> : PS[K] extends void ? void : never };
|
27
26
|
export declare type RunnerFromProgress<P extends Progress> = 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;
|
@@ -1,16 +1,20 @@
|
|
1
|
-
import
|
1
|
+
import { MaybeAsync, Container } from 'farrow-pipeline';
|
2
2
|
declare const ASYNC_WATERFALL_SYMBOL: unique symbol;
|
3
|
-
export declare type AsyncBrook<I = unknown> = (I: I) =>
|
3
|
+
export declare type AsyncBrook<I = unknown> = (I: I) => MaybeAsync<I>;
|
4
4
|
export declare type AsyncBrookInput<I = unknown> = AsyncBrook<I> | {
|
5
|
-
|
5
|
+
middlware: AsyncBrook<I>;
|
6
6
|
};
|
7
7
|
export declare type AsyncBrooks<I = unknown> = AsyncBrook<I>[];
|
8
8
|
export declare type AsyncBrookInputs<I = unknown> = AsyncBrookInput<I>[];
|
9
9
|
export declare const getAsyncBrook: <I>(input: AsyncBrookInput<I>) => AsyncBrook<I>;
|
10
|
+
export declare type RunAsyncWaterfallOptions<I = unknown> = {
|
11
|
+
container?: Container;
|
12
|
+
onLast?: AsyncBrook<I>;
|
13
|
+
};
|
10
14
|
export declare type AsyncWaterfall<I> = {
|
11
|
-
run: (input: I, options?:
|
15
|
+
run: (input: I, options?: RunAsyncWaterfallOptions<I>) => MaybeAsync<I>;
|
12
16
|
use: (...I: AsyncBrookInputs<I>) => AsyncWaterfall<I>;
|
13
|
-
|
17
|
+
middlware: AsyncBrook<I>;
|
14
18
|
[ASYNC_WATERFALL_SYMBOL]: true;
|
15
19
|
};
|
16
20
|
export declare type AsyncWaterfall2AsyncBrook<P extends AsyncWaterfall<any>> = P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : never;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Container } from '
|
1
|
+
import { Container } from 'farrow-pipeline';
|
2
2
|
declare const WATERFALL_SYMBOL: unique symbol;
|
3
|
-
export declare type Brook<I = unknown> = (I: I) => I
|
3
|
+
export declare type Brook<I = unknown> = (I: I) => I;
|
4
4
|
export declare type BrookInput<I = unknown> = Brook<I> | {
|
5
|
-
|
5
|
+
middleware: Brook<I>;
|
6
6
|
};
|
7
7
|
export declare type Brooks<I = unknown> = Brook<I>[];
|
8
8
|
export declare type BrookInputs<I = unknown> = BrookInput<I>[];
|
@@ -14,7 +14,7 @@ export declare type RunWaterfallOptions<I = unknown> = {
|
|
14
14
|
export declare type Waterfall<I = void> = {
|
15
15
|
run: (input: I, options?: RunWaterfallOptions<I>) => I;
|
16
16
|
use: (...I: BrookInputs<I>) => Waterfall<I>;
|
17
|
-
|
17
|
+
middleware: Brook<I>;
|
18
18
|
[WATERFALL_SYMBOL]: true;
|
19
19
|
};
|
20
20
|
export declare type Waterfall2Brook<P extends Waterfall<any>> = P extends Waterfall<infer I> ? Brook<I> : never;
|
@@ -1,9 +1,10 @@
|
|
1
|
+
import { MaybeAsync } from 'farrow-pipeline';
|
1
2
|
import type { RunWorkflowOptions } from './sync';
|
2
3
|
declare const ASYNC_WORKFLOW_SYMBOL: unique symbol;
|
3
|
-
export declare type AsyncWorker<I, O> = (I: I) =>
|
4
|
+
export declare type AsyncWorker<I, O> = (I: I) => MaybeAsync<O>;
|
4
5
|
export declare type AsyncWorkers<I, O> = AsyncWorker<I, O>[];
|
5
6
|
export declare type AsyncWorkflow<I, O> = {
|
6
|
-
run: (input: I, options?: RunWorkflowOptions) =>
|
7
|
+
run: (input: I, options?: RunWorkflowOptions) => MaybeAsync<O[]>;
|
7
8
|
use: (...I: AsyncWorkers<I, O>) => AsyncWorkflow<I, O>;
|
8
9
|
[ASYNC_WORKFLOW_SYMBOL]: true;
|
9
10
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AsyncWorker, AsyncWorkers } from './async';
|
1
|
+
import type { AsyncWorker, AsyncWorkers } from './async';
|
2
2
|
import type { RunWorkflowOptions } from './sync';
|
3
3
|
declare const PARALLEL_WORKFLOW_SYMBOL: unique symbol;
|
4
4
|
export declare type ParallelWorkflow<I, O = any> = {
|
package/jest.config.js
ADDED
package/modern.config.js
CHANGED
@@ -1,10 +1,2 @@
|
|
1
1
|
/** @type {import('@modern-js/module-tools').UserConfig} */
|
2
|
-
module.exports = {
|
3
|
-
testing: {
|
4
|
-
jest: {
|
5
|
-
collectCoverage: true,
|
6
|
-
collectCoverageFrom: ['./src/**/*.ts'],
|
7
|
-
coveragePathIgnorePatterns: ['/node_modules/'],
|
8
|
-
},
|
9
|
-
},
|
10
|
-
};
|
2
|
+
module.exports = {};
|
package/node.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from '
|
1
|
+
export * from 'farrow-pipeline/asyncHooks.node';
|
package/node.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
module.exports = require('
|
1
|
+
module.exports = require('farrow-pipeline/asyncHooks.node');
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.0
|
14
|
+
"version": "1.2.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -20,33 +20,39 @@
|
|
20
20
|
"exports": {
|
21
21
|
".": {
|
22
22
|
"node": {
|
23
|
+
"jsnext:source": "./src/index.ts",
|
23
24
|
"import": "./dist/js/modern/index.js",
|
24
25
|
"require": "./dist/js/node/index.js"
|
25
26
|
},
|
26
27
|
"default": "./dist/js/treeshaking/index.js"
|
27
28
|
},
|
28
29
|
"./node": {
|
30
|
+
"jsnext:source": "./node.js",
|
29
31
|
"default": "./node.js"
|
30
32
|
}
|
31
33
|
},
|
32
34
|
"dependencies": {
|
33
|
-
"@babel/runtime": "^7"
|
35
|
+
"@babel/runtime": "^7",
|
36
|
+
"farrow-pipeline": "^1.10.6"
|
34
37
|
},
|
35
38
|
"devDependencies": {
|
36
39
|
"@types/jest": "^26",
|
37
40
|
"@types/node": "^14",
|
38
41
|
"typescript": "^4",
|
39
|
-
"@
|
40
|
-
"
|
42
|
+
"@scripts/build": "0.0.0",
|
43
|
+
"jest": "^27",
|
44
|
+
"@scripts/jest-config": "0.0.0"
|
41
45
|
},
|
42
46
|
"sideEffects": false,
|
43
47
|
"publishConfig": {
|
44
48
|
"registry": "https://registry.npmjs.org/",
|
45
|
-
"access": "public"
|
49
|
+
"access": "public",
|
50
|
+
"types": "./dist/types/index.d.ts"
|
46
51
|
},
|
47
52
|
"scripts": {
|
48
53
|
"new": "modern new",
|
49
54
|
"build": "modern build",
|
50
|
-
"test": "
|
51
|
-
}
|
55
|
+
"test": "jest --passWithNoTests"
|
56
|
+
},
|
57
|
+
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
52
58
|
}
|
package/src/index.ts
CHANGED
package/src/manager/async.ts
CHANGED
package/src/manager/runner.ts
CHANGED
package/src/manager/sync.ts
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
2
2
|
/* eslint-disable max-lines */
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
Middleware,
|
5
|
+
Pipeline,
|
6
|
+
isPipeline,
|
7
|
+
createPipeline,
|
8
|
+
AsyncPipeline,
|
9
|
+
MaybeAsync,
|
10
|
+
runWithContainer,
|
11
|
+
createContainer,
|
12
|
+
Container,
|
13
|
+
} from 'farrow-pipeline';
|
4
14
|
import {
|
5
15
|
Waterfall,
|
6
16
|
Brook,
|
@@ -24,16 +34,6 @@ import {
|
|
24
34
|
isParallelWorkflow,
|
25
35
|
createParallelWorkflow,
|
26
36
|
} from '../workflow';
|
27
|
-
import {
|
28
|
-
Middleware,
|
29
|
-
Pipeline,
|
30
|
-
isPipeline,
|
31
|
-
createPipeline,
|
32
|
-
AsyncMiddleware,
|
33
|
-
AsyncPipeline,
|
34
|
-
isAsyncPipeline,
|
35
|
-
createAsyncPipeline,
|
36
|
-
} from '../pipeline';
|
37
37
|
import { RunnerContext, useRunner } from './runner';
|
38
38
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
@@ -86,7 +86,7 @@ export type Progress2Thread<P extends Progress> = P extends Workflow<
|
|
86
86
|
: P extends Pipeline<infer I, infer O>
|
87
87
|
? Middleware<I, O>
|
88
88
|
: P extends AsyncPipeline<infer I, infer O>
|
89
|
-
?
|
89
|
+
? Middleware<I, MaybeAsync<O>>
|
90
90
|
: never;
|
91
91
|
|
92
92
|
export type ProgressRecord = Record<string, Progress>;
|
@@ -360,10 +360,6 @@ export const cloneProgress = (progress: Progress): Progress => {
|
|
360
360
|
return createPipeline();
|
361
361
|
}
|
362
362
|
|
363
|
-
if (isAsyncPipeline(progress)) {
|
364
|
-
return createAsyncPipeline();
|
365
|
-
}
|
366
|
-
|
367
363
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
368
364
|
throw new Error(`Unknown progress: ${progress}`);
|
369
365
|
};
|