@modern-js/plugin 0.0.0-nightly-20230920160608 → 0.0.0-nightly-20230922160540
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/dist/cjs/farrow-pipeline/context.js +24 -7
- package/dist/cjs/farrow-pipeline/counter.js +24 -7
- package/dist/cjs/farrow-pipeline/index.js +38 -26
- package/dist/cjs/index.js +26 -7
- package/dist/cjs/manager/async.js +33 -16
- package/dist/cjs/manager/index.js +24 -6
- package/dist/cjs/manager/shared.js +33 -26
- package/dist/cjs/manager/sync.js +54 -46
- package/dist/cjs/manager/types.js +15 -3
- package/dist/cjs/waterfall/async.js +33 -21
- package/dist/cjs/waterfall/index.js +22 -5
- package/dist/cjs/waterfall/sync.js +33 -21
- package/dist/cjs/workflow/async.js +31 -18
- package/dist/cjs/workflow/index.js +24 -6
- package/dist/cjs/workflow/parallel.js +31 -18
- package/dist/cjs/workflow/sync.js +31 -18
- package/dist/esm/index.js +51 -43
- package/dist/esm-node/farrow-pipeline/context.js +4 -1
- package/dist/esm-node/farrow-pipeline/counter.js +4 -1
- package/dist/esm-node/farrow-pipeline/index.js +14 -5
- package/dist/esm-node/manager/async.js +4 -1
- package/dist/esm-node/manager/shared.js +12 -5
- package/dist/esm-node/manager/sync.js +14 -6
- package/dist/esm-node/manager/types.js +0 -1
- package/dist/esm-node/waterfall/async.js +11 -3
- package/dist/esm-node/waterfall/sync.js +11 -3
- package/dist/esm-node/workflow/async.js +9 -2
- package/dist/esm-node/workflow/parallel.js +9 -2
- package/dist/esm-node/workflow/sync.js +9 -2
- package/package.json +4 -4
@@ -1,7 +1,9 @@
|
|
1
1
|
import { createContext } from "./context";
|
2
2
|
import { createCounter } from "./counter";
|
3
|
-
|
4
|
-
|
3
|
+
const isPipeline = (input) => {
|
4
|
+
var _input;
|
5
|
+
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PipelineSymbol]);
|
6
|
+
};
|
5
7
|
const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
6
8
|
const getMiddleware = (input) => {
|
7
9
|
if (typeof input === "function") {
|
@@ -11,7 +13,7 @@ const getMiddleware = (input) => {
|
|
11
13
|
}
|
12
14
|
throw new Error(`${input} is not a Middleware`);
|
13
15
|
};
|
14
|
-
|
16
|
+
const createPipeline = () => {
|
15
17
|
const middlewares = [];
|
16
18
|
const use = (...inputs) => {
|
17
19
|
middlewares.push(...inputs.map(getMiddleware));
|
@@ -30,10 +32,11 @@ export const createPipeline = () => {
|
|
30
32
|
};
|
31
33
|
const currentCounter = createCurrentCounter();
|
32
34
|
const getCounter = (options) => {
|
35
|
+
var _options;
|
33
36
|
if (!options) {
|
34
37
|
return currentCounter;
|
35
38
|
}
|
36
|
-
return createCurrentCounter(options === null ||
|
39
|
+
return createCurrentCounter((_options = options) === null || _options === void 0 ? void 0 : _options.onLast);
|
37
40
|
};
|
38
41
|
const run = (input, options) => getCounter(options).start(input);
|
39
42
|
const middleware = (input, next) => run(input, {
|
@@ -47,9 +50,15 @@ export const createPipeline = () => {
|
|
47
50
|
};
|
48
51
|
return pipeline;
|
49
52
|
};
|
50
|
-
|
53
|
+
const createAsyncPipeline = () => {
|
51
54
|
const pipeline = createPipeline();
|
52
55
|
return {
|
53
56
|
...pipeline
|
54
57
|
};
|
55
58
|
};
|
59
|
+
export {
|
60
|
+
createAsyncPipeline,
|
61
|
+
createContext,
|
62
|
+
createPipeline,
|
63
|
+
isPipeline
|
64
|
+
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { generateRunner, DEFAULT_OPTIONS } from "./sync";
|
2
2
|
import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
|
3
3
|
const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
4
|
-
|
4
|
+
const createAsyncManager = (hooks, api) => {
|
5
5
|
let index = 0;
|
6
6
|
let runners;
|
7
7
|
let currentHooks = {
|
@@ -95,3 +95,6 @@ export const createAsyncManager = (hooks, api) => {
|
|
95
95
|
};
|
96
96
|
return clone();
|
97
97
|
};
|
98
|
+
export {
|
99
|
+
createAsyncManager
|
100
|
+
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { pluginDagSort } from "@modern-js/utils/universal/plugin-dag-sort";
|
2
|
-
|
2
|
+
const checkPlugins = (plugins) => {
|
3
3
|
if (process.env.NODE_ENV !== "production") {
|
4
4
|
plugins.forEach((origin) => {
|
5
5
|
origin.rivals.forEach((rival) => {
|
@@ -17,9 +17,16 @@ export const checkPlugins = (plugins) => {
|
|
17
17
|
});
|
18
18
|
}
|
19
19
|
};
|
20
|
-
|
20
|
+
function sortPlugins(input) {
|
21
21
|
return pluginDagSort(input.slice());
|
22
22
|
}
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
|
24
|
+
const isObject = (obj) => obj !== null && typeof obj === "object";
|
25
|
+
const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
26
|
+
export {
|
27
|
+
checkPlugins,
|
28
|
+
hasOwnProperty,
|
29
|
+
includePlugin,
|
30
|
+
isObject,
|
31
|
+
sortPlugins
|
32
|
+
};
|
@@ -3,7 +3,7 @@ import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall }
|
|
3
3
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
4
4
|
import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
|
5
5
|
const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
6
|
-
|
6
|
+
const DEFAULT_OPTIONS = {
|
7
7
|
name: "untitled",
|
8
8
|
pre: [],
|
9
9
|
post: [],
|
@@ -12,7 +12,7 @@ export const DEFAULT_OPTIONS = {
|
|
12
12
|
usePlugins: [],
|
13
13
|
registerHook: {}
|
14
14
|
};
|
15
|
-
|
15
|
+
const createManager = (hooks, api) => {
|
16
16
|
let index = 0;
|
17
17
|
let runners;
|
18
18
|
let currentHooks = {
|
@@ -103,13 +103,14 @@ export const createManager = (hooks, api) => {
|
|
103
103
|
};
|
104
104
|
return clone();
|
105
105
|
};
|
106
|
-
|
106
|
+
const generateRunner = (hooksList, hooksMap) => {
|
107
107
|
const runner = {};
|
108
108
|
const cloneShape = cloneHooksMap(hooksMap);
|
109
109
|
if (hooksMap) {
|
110
110
|
for (const key in cloneShape) {
|
111
111
|
hooksList.forEach((hooks) => {
|
112
|
-
|
112
|
+
var _hooks;
|
113
|
+
if ((_hooks = hooks) === null || _hooks === void 0 ? void 0 : _hooks[key]) {
|
113
114
|
cloneShape[key].use(hooks[key]);
|
114
115
|
}
|
115
116
|
});
|
@@ -120,7 +121,7 @@ export const generateRunner = (hooksList, hooksMap) => {
|
|
120
121
|
}
|
121
122
|
return runner;
|
122
123
|
};
|
123
|
-
|
124
|
+
const cloneHook = (hook) => {
|
124
125
|
if (isWaterfall(hook)) {
|
125
126
|
return createWaterfall();
|
126
127
|
}
|
@@ -141,7 +142,7 @@ export const cloneHook = (hook) => {
|
|
141
142
|
}
|
142
143
|
throw new Error(`Unknown hook: ${hook}`);
|
143
144
|
};
|
144
|
-
|
145
|
+
const cloneHooksMap = (record) => {
|
145
146
|
if (!record) {
|
146
147
|
return record;
|
147
148
|
}
|
@@ -151,3 +152,10 @@ export const cloneHooksMap = (record) => {
|
|
151
152
|
}
|
152
153
|
return result;
|
153
154
|
};
|
155
|
+
export {
|
156
|
+
DEFAULT_OPTIONS,
|
157
|
+
cloneHook,
|
158
|
+
cloneHooksMap,
|
159
|
+
createManager,
|
160
|
+
generateRunner
|
161
|
+
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createAsyncPipeline } from "../farrow-pipeline";
|
2
2
|
const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
|
3
|
-
|
3
|
+
const getAsyncBrook = (input) => {
|
4
4
|
if (typeof input === "function") {
|
5
5
|
return input;
|
6
6
|
}
|
@@ -9,7 +9,7 @@ export const getAsyncBrook = (input) => {
|
|
9
9
|
}
|
10
10
|
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
11
11
|
};
|
12
|
-
|
12
|
+
const createAsyncWaterfall = () => {
|
13
13
|
const pipeline = createAsyncPipeline();
|
14
14
|
const use = (...input) => {
|
15
15
|
pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
|
@@ -33,5 +33,13 @@ export const createAsyncWaterfall = () => {
|
|
33
33
|
};
|
34
34
|
return waterfall;
|
35
35
|
};
|
36
|
-
|
36
|
+
const isAsyncWaterfall = (input) => {
|
37
|
+
var _input;
|
38
|
+
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WATERFALL_SYMBOL]);
|
39
|
+
};
|
37
40
|
const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
|
41
|
+
export {
|
42
|
+
createAsyncWaterfall,
|
43
|
+
getAsyncBrook,
|
44
|
+
isAsyncWaterfall
|
45
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createPipeline } from "../farrow-pipeline";
|
2
2
|
const WATERFALL_SYMBOL = Symbol.for("MODERN_WATERFALL");
|
3
|
-
|
3
|
+
const getBrook = (input) => {
|
4
4
|
if (typeof input === "function") {
|
5
5
|
return input;
|
6
6
|
} else if (input && typeof input.middleware === "function") {
|
@@ -8,7 +8,7 @@ export const getBrook = (input) => {
|
|
8
8
|
}
|
9
9
|
throw new Error(`${input} is not a Brook or { brook: Brook }`);
|
10
10
|
};
|
11
|
-
|
11
|
+
const createWaterfall = () => {
|
12
12
|
const pipeline = createPipeline();
|
13
13
|
const use = (...brooks) => {
|
14
14
|
pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
|
@@ -32,5 +32,13 @@ export const createWaterfall = () => {
|
|
32
32
|
};
|
33
33
|
return waterfall;
|
34
34
|
};
|
35
|
-
|
35
|
+
const isWaterfall = (input) => {
|
36
|
+
var _input;
|
37
|
+
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WATERFALL_SYMBOL]);
|
38
|
+
};
|
36
39
|
const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
|
40
|
+
export {
|
41
|
+
createWaterfall,
|
42
|
+
getBrook,
|
43
|
+
isWaterfall
|
44
|
+
};
|
@@ -1,8 +1,11 @@
|
|
1
1
|
import { createAsyncPipeline } from "../farrow-pipeline";
|
2
2
|
const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
|
3
3
|
const isPromise = (obj) => obj && typeof obj.then === "function";
|
4
|
-
|
5
|
-
|
4
|
+
const isAsyncWorkflow = (input) => {
|
5
|
+
var _input;
|
6
|
+
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WORKFLOW_SYMBOL]);
|
7
|
+
};
|
8
|
+
const createAsyncWorkflow = () => {
|
6
9
|
const pipeline = createAsyncPipeline();
|
7
10
|
const use = (...input) => {
|
8
11
|
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
@@ -29,3 +32,7 @@ const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.res
|
|
29
32
|
result,
|
30
33
|
...nextResult
|
31
34
|
]));
|
35
|
+
export {
|
36
|
+
createAsyncWorkflow,
|
37
|
+
isAsyncWorkflow
|
38
|
+
};
|
@@ -1,7 +1,10 @@
|
|
1
1
|
import { createPipeline } from "../farrow-pipeline";
|
2
2
|
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
|
3
|
-
|
4
|
-
|
3
|
+
const isParallelWorkflow = (input) => {
|
4
|
+
var _input;
|
5
|
+
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PARALLEL_WORKFLOW_SYMBOL]);
|
6
|
+
};
|
7
|
+
const createParallelWorkflow = () => {
|
5
8
|
const pipeline = createPipeline();
|
6
9
|
const use = (...input) => {
|
7
10
|
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
@@ -22,3 +25,7 @@ const mapParallelWorkerToAsyncMiddleware = (worker) => (input, next) => [
|
|
22
25
|
worker(input),
|
23
26
|
...next(input)
|
24
27
|
];
|
28
|
+
export {
|
29
|
+
createParallelWorkflow,
|
30
|
+
isParallelWorkflow
|
31
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createPipeline } from "../farrow-pipeline";
|
2
2
|
const WORKFLOW_SYMBOL = Symbol.for("MODERN_WORKFLOW");
|
3
|
-
|
3
|
+
const createWorkflow = () => {
|
4
4
|
const pipeline = createPipeline();
|
5
5
|
const use = (...input) => {
|
6
6
|
pipeline.use(...input.map(mapWorkerToMiddleware));
|
@@ -20,8 +20,15 @@ export const createWorkflow = () => {
|
|
20
20
|
};
|
21
21
|
return workflow;
|
22
22
|
};
|
23
|
-
|
23
|
+
const isWorkflow = (input) => {
|
24
|
+
var _input;
|
25
|
+
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WORKFLOW_SYMBOL]);
|
26
|
+
};
|
24
27
|
const mapWorkerToMiddleware = (worker) => (input, next) => [
|
25
28
|
worker(input),
|
26
29
|
...next(input)
|
27
30
|
];
|
31
|
+
export {
|
32
|
+
createWorkflow,
|
33
|
+
isWorkflow
|
34
|
+
};
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "0.0.0-nightly-
|
18
|
+
"version": "0.0.0-nightly-20230922160540",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -33,15 +33,15 @@
|
|
33
33
|
},
|
34
34
|
"dependencies": {
|
35
35
|
"@swc/helpers": "0.5.1",
|
36
|
-
"@modern-js/utils": "0.0.0-nightly-
|
36
|
+
"@modern-js/utils": "0.0.0-nightly-20230922160540"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
39
|
"@types/jest": "^29",
|
40
40
|
"@types/node": "^14",
|
41
41
|
"typescript": "^5",
|
42
42
|
"jest": "^29",
|
43
|
-
"@scripts/build": "0.0.0-nightly-
|
44
|
-
"@scripts/jest-config": "0.0.0-nightly-
|
43
|
+
"@scripts/build": "0.0.0-nightly-20230922160540",
|
44
|
+
"@scripts/jest-config": "0.0.0-nightly-20230922160540"
|
45
45
|
},
|
46
46
|
"sideEffects": false,
|
47
47
|
"publishConfig": {
|