@modern-js/plugin 1.3.1 → 1.3.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.
- package/CHANGELOG.md +23 -0
- package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +74 -0
- package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +12 -0
- package/dist/js/modern/farrow-pipeline/context.js +99 -0
- package/dist/js/modern/farrow-pipeline/counter.js +18 -0
- package/dist/js/modern/farrow-pipeline/hook.js +42 -0
- package/dist/js/modern/farrow-pipeline/index.js +19 -0
- package/dist/js/modern/farrow-pipeline/pipeline.js +93 -0
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/manager/async.js +4 -4
- package/dist/js/modern/manager/runner.js +1 -1
- package/dist/js/modern/manager/sync.js +5 -6
- package/dist/js/modern/waterfall/async.js +4 -8
- package/dist/js/modern/waterfall/sync.js +4 -8
- package/dist/js/modern/workflow/async.js +1 -4
- package/dist/js/modern/workflow/parallel.js +2 -3
- package/dist/js/modern/workflow/sync.js +1 -1
- package/dist/js/node/farrow-pipeline/asyncHooks.node.js +93 -0
- package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +26 -0
- package/dist/js/node/farrow-pipeline/context.js +120 -0
- package/dist/js/node/farrow-pipeline/counter.js +27 -0
- package/dist/js/node/farrow-pipeline/hook.js +52 -0
- package/dist/js/node/farrow-pipeline/index.js +18 -0
- package/dist/js/node/farrow-pipeline/pipeline.js +129 -0
- package/dist/js/node/index.js +1 -1
- package/dist/js/node/manager/async.js +4 -4
- package/dist/js/node/manager/runner.js +1 -1
- package/dist/js/node/manager/sync.js +5 -6
- package/dist/js/node/waterfall/async.js +4 -8
- package/dist/js/node/waterfall/sync.js +4 -8
- package/dist/js/node/workflow/async.js +1 -4
- package/dist/js/node/workflow/parallel.js +2 -3
- package/dist/js/node/workflow/sync.js +1 -1
- package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +74 -0
- package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +12 -0
- package/dist/js/treeshaking/farrow-pipeline/context.js +103 -0
- package/dist/js/treeshaking/farrow-pipeline/counter.js +23 -0
- package/dist/js/treeshaking/farrow-pipeline/hook.js +46 -0
- package/dist/js/treeshaking/farrow-pipeline/index.js +19 -0
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +100 -0
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/manager/async.js +8 -29
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +9 -28
- package/dist/js/treeshaking/waterfall/async.js +12 -36
- package/dist/js/treeshaking/waterfall/sync.js +11 -31
- package/dist/js/treeshaking/workflow/async.js +6 -28
- package/dist/js/treeshaking/workflow/parallel.js +6 -26
- package/dist/js/treeshaking/workflow/sync.js +5 -24
- package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +2 -0
- package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +19 -0
- package/dist/types/farrow-pipeline/context.d.ts +28 -0
- package/dist/types/farrow-pipeline/counter.d.ts +11 -0
- package/dist/types/farrow-pipeline/hook.d.ts +9 -0
- package/dist/types/farrow-pipeline/index.d.ts +19 -0
- package/dist/types/farrow-pipeline/pipeline.d.ts +38 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/manager/runner.d.ts +1 -1
- package/dist/types/manager/sync.d.ts +1 -1
- package/dist/types/manager/types.d.ts +1 -1
- package/dist/types/waterfall/async.d.ts +1 -1
- package/dist/types/waterfall/sync.d.ts +1 -1
- package/dist/types/workflow/async.d.ts +1 -1
- package/dist/types/workflow/sync.d.ts +1 -1
- package/package.json +37 -10
- package/jest.config.js +0 -8
- package/modern.config.js +0 -2
- package/node.d.ts +0 -1
- package/node.js +0 -1
- package/tests/.eslintrc.js +0 -6
- package/tests/async.test.ts +0 -715
- package/tests/fixtures/async/base/bar.ts +0 -22
- package/tests/fixtures/async/base/foo.ts +0 -20
- package/tests/fixtures/async/base/fooManager.ts +0 -47
- package/tests/fixtures/async/core/index.ts +0 -174
- package/tests/fixtures/async/dynamic/bar.ts +0 -18
- package/tests/fixtures/async/dynamic/foo.ts +0 -27
- package/tests/fixtures/sync/base/bar.ts +0 -21
- package/tests/fixtures/sync/base/foo.ts +0 -20
- package/tests/fixtures/sync/base/fooManager.ts +0 -47
- package/tests/fixtures/sync/core/index.ts +0 -171
- package/tests/fixtures/sync/dynamic/bar.ts +0 -22
- package/tests/fixtures/sync/dynamic/foo.ts +0 -27
- package/tests/helpers.ts +0 -4
- package/tests/pipeline.test.ts +0 -607
- package/tests/sync.test.ts +0 -679
- package/tests/tsconfig.json +0 -13
- package/tests/waterfall.test.ts +0 -172
- package/tests/workflow.test.ts +0 -111
- package/tsconfig.json +0 -14
package/tests/waterfall.test.ts
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
import { enable, disable } from 'farrow-pipeline/asyncHooks.node';
|
2
|
-
import {
|
3
|
-
createWaterfall,
|
4
|
-
createAsyncWaterfall,
|
5
|
-
createContext,
|
6
|
-
createContainer,
|
7
|
-
isWaterfall,
|
8
|
-
isAsyncWaterfall,
|
9
|
-
} from '../src';
|
10
|
-
import { sleep } from './helpers';
|
11
|
-
|
12
|
-
describe('waterfall', () => {
|
13
|
-
it('base usage', () => {
|
14
|
-
const waterfall = createWaterfall<{ count: number }>();
|
15
|
-
|
16
|
-
waterfall.use(({ count }) => ({ count: count + 1 }));
|
17
|
-
|
18
|
-
waterfall.use(a => a);
|
19
|
-
|
20
|
-
waterfall.use(a => a);
|
21
|
-
|
22
|
-
expect(waterfall.run({ count: 0 })).toStrictEqual({ count: 1 });
|
23
|
-
});
|
24
|
-
|
25
|
-
it('should support async waterfall', async () => {
|
26
|
-
const waterfall = createAsyncWaterfall<{ count: number }>();
|
27
|
-
|
28
|
-
waterfall.use(async ({ count }) => ({ count: count + 1 }));
|
29
|
-
|
30
|
-
waterfall.use(a => a);
|
31
|
-
|
32
|
-
waterfall.use(a => a);
|
33
|
-
|
34
|
-
expect(await waterfall.run({ count: 0 })).toStrictEqual({ count: 1 });
|
35
|
-
});
|
36
|
-
|
37
|
-
it('should support hook in async waterfall', async () => {
|
38
|
-
const waterfall = createAsyncWaterfall<number>();
|
39
|
-
|
40
|
-
const Count = createContext({ count: 10 });
|
41
|
-
|
42
|
-
const incre = async () => {
|
43
|
-
await sleep(0);
|
44
|
-
Count.set({ count: Count.assert().count + 1 });
|
45
|
-
};
|
46
|
-
const list: { count: number }[] = [];
|
47
|
-
|
48
|
-
waterfall.use(async count => {
|
49
|
-
const before = Count.get();
|
50
|
-
|
51
|
-
await incre();
|
52
|
-
|
53
|
-
const after = Count.get();
|
54
|
-
|
55
|
-
list.push(before, after);
|
56
|
-
|
57
|
-
return count + Count.get().count;
|
58
|
-
});
|
59
|
-
|
60
|
-
waterfall.use(async count => {
|
61
|
-
await sleep(0);
|
62
|
-
await incre();
|
63
|
-
|
64
|
-
return count + Count.get().count;
|
65
|
-
});
|
66
|
-
|
67
|
-
const container = createContainer({ count: Count });
|
68
|
-
|
69
|
-
enable();
|
70
|
-
const result = await waterfall.run(10, { container });
|
71
|
-
disable();
|
72
|
-
|
73
|
-
expect(result).toBe(33);
|
74
|
-
expect(list).toStrictEqual([{ count: 10 }, { count: 11 }]);
|
75
|
-
});
|
76
|
-
|
77
|
-
describe('sync', () => {
|
78
|
-
it('should support waterfall.use(anotherWaterfall) if their type is matched', () => {
|
79
|
-
const StepContext = createContext(1);
|
80
|
-
|
81
|
-
const waterfall0 = createWaterfall<number>();
|
82
|
-
|
83
|
-
const waterfall1 = createWaterfall<number>();
|
84
|
-
|
85
|
-
const steps = [] as number[];
|
86
|
-
|
87
|
-
waterfall0.use(input => {
|
88
|
-
const step = StepContext.use();
|
89
|
-
return input + step.value++;
|
90
|
-
});
|
91
|
-
|
92
|
-
waterfall0.use(waterfall1);
|
93
|
-
|
94
|
-
waterfall1.use(input => {
|
95
|
-
const step = StepContext.use();
|
96
|
-
steps.push(step.value);
|
97
|
-
return input + step.value;
|
98
|
-
});
|
99
|
-
|
100
|
-
const result0 = waterfall1.run(0);
|
101
|
-
const result1 = waterfall0.run(0);
|
102
|
-
|
103
|
-
expect(result0).toEqual(1);
|
104
|
-
expect(result1).toEqual(3);
|
105
|
-
expect(steps).toEqual([1, 2]);
|
106
|
-
});
|
107
|
-
|
108
|
-
it('should throw error when add illegal brook', () => {
|
109
|
-
const waterfall = createWaterfall<number>();
|
110
|
-
expect(() => waterfall.use({} as any)).toThrowError();
|
111
|
-
});
|
112
|
-
|
113
|
-
it('isWaterfall', () => {
|
114
|
-
const waterfall = createWaterfall();
|
115
|
-
|
116
|
-
expect(isWaterfall(waterfall)).toBeTruthy();
|
117
|
-
expect(isWaterfall({})).toBeFalsy();
|
118
|
-
expect(isWaterfall('test')).toBeFalsy();
|
119
|
-
expect(isWaterfall(null)).toBeFalsy();
|
120
|
-
});
|
121
|
-
});
|
122
|
-
|
123
|
-
describe('async', () => {
|
124
|
-
it('should support waterfall.use(anotherWaterfall) if their type is matched', async () => {
|
125
|
-
const StepContext = createContext(1);
|
126
|
-
|
127
|
-
const waterfall0 = createAsyncWaterfall<number>();
|
128
|
-
|
129
|
-
const waterfall1 = createAsyncWaterfall<number>();
|
130
|
-
|
131
|
-
const steps = [] as number[];
|
132
|
-
|
133
|
-
waterfall0.use(async input => {
|
134
|
-
await sleep(0);
|
135
|
-
const step = StepContext.use();
|
136
|
-
return input + step.value++;
|
137
|
-
});
|
138
|
-
|
139
|
-
waterfall0.use(waterfall1);
|
140
|
-
|
141
|
-
waterfall1.use(async input => {
|
142
|
-
const step = StepContext.use();
|
143
|
-
steps.push(step.value);
|
144
|
-
await sleep(0);
|
145
|
-
return input + step.value;
|
146
|
-
});
|
147
|
-
|
148
|
-
enable();
|
149
|
-
const result0 = await waterfall1.run(0);
|
150
|
-
const result1 = await waterfall0.run(0);
|
151
|
-
disable();
|
152
|
-
|
153
|
-
expect(result0).toEqual(1);
|
154
|
-
expect(result1).toEqual(3);
|
155
|
-
expect(steps).toEqual([1, 2]);
|
156
|
-
});
|
157
|
-
|
158
|
-
it('should throw error when add illegal brook', () => {
|
159
|
-
const waterfall = createAsyncWaterfall<number>();
|
160
|
-
expect(() => waterfall.use({} as any)).toThrowError();
|
161
|
-
});
|
162
|
-
|
163
|
-
it('isAsyncWaterfall', () => {
|
164
|
-
const waterfall = createAsyncWaterfall();
|
165
|
-
|
166
|
-
expect(isAsyncWaterfall(waterfall)).toBeTruthy();
|
167
|
-
expect(isAsyncWaterfall({})).toBeFalsy();
|
168
|
-
expect(isAsyncWaterfall('test')).toBeFalsy();
|
169
|
-
expect(isAsyncWaterfall(null)).toBeFalsy();
|
170
|
-
});
|
171
|
-
});
|
172
|
-
});
|
package/tests/workflow.test.ts
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createWorkflow,
|
3
|
-
createAsyncWorkflow,
|
4
|
-
createParallelWorkflow,
|
5
|
-
isWorkflow,
|
6
|
-
isAsyncWorkflow,
|
7
|
-
isParallelWorkflow,
|
8
|
-
} from '../src/workflow';
|
9
|
-
import { sleep } from './helpers';
|
10
|
-
|
11
|
-
describe('workflow', () => {
|
12
|
-
describe('sync', () => {
|
13
|
-
it('should run with attaching order', () => {
|
14
|
-
const workflow = createWorkflow();
|
15
|
-
|
16
|
-
let count = 0;
|
17
|
-
workflow.use(() => {
|
18
|
-
count++;
|
19
|
-
});
|
20
|
-
|
21
|
-
workflow.use(() => {
|
22
|
-
count++;
|
23
|
-
});
|
24
|
-
|
25
|
-
workflow.use(() => {
|
26
|
-
count++;
|
27
|
-
});
|
28
|
-
|
29
|
-
workflow.run();
|
30
|
-
|
31
|
-
expect(count).toBe(3);
|
32
|
-
});
|
33
|
-
|
34
|
-
it('isWorkflow', () => {
|
35
|
-
const workflow = createWorkflow();
|
36
|
-
|
37
|
-
expect(isWorkflow(workflow)).toBeTruthy();
|
38
|
-
expect(isWorkflow({})).toBeFalsy();
|
39
|
-
expect(isWorkflow('test')).toBeFalsy();
|
40
|
-
expect(isWorkflow(null)).toBeFalsy();
|
41
|
-
});
|
42
|
-
});
|
43
|
-
|
44
|
-
describe('async', () => {
|
45
|
-
it('should run with attaching order', async () => {
|
46
|
-
const workflow = createAsyncWorkflow();
|
47
|
-
|
48
|
-
let count = 0;
|
49
|
-
|
50
|
-
workflow.use(() => {
|
51
|
-
count = 1;
|
52
|
-
});
|
53
|
-
|
54
|
-
workflow.use(async () => {
|
55
|
-
await sleep(100);
|
56
|
-
count = 2;
|
57
|
-
});
|
58
|
-
|
59
|
-
workflow.use(() => {
|
60
|
-
count = 3;
|
61
|
-
});
|
62
|
-
|
63
|
-
await workflow.run();
|
64
|
-
|
65
|
-
expect(count).toBe(3);
|
66
|
-
});
|
67
|
-
|
68
|
-
it('isAsyncWorkflow', () => {
|
69
|
-
const workflow = createAsyncWorkflow();
|
70
|
-
|
71
|
-
expect(isAsyncWorkflow(workflow)).toBeTruthy();
|
72
|
-
expect(isAsyncWorkflow({})).toBeFalsy();
|
73
|
-
expect(isAsyncWorkflow('test')).toBeFalsy();
|
74
|
-
expect(isAsyncWorkflow(null)).toBeFalsy();
|
75
|
-
});
|
76
|
-
});
|
77
|
-
|
78
|
-
describe('parallel', () => {
|
79
|
-
it('should run without stable order', async () => {
|
80
|
-
const workflow = createParallelWorkflow();
|
81
|
-
|
82
|
-
let count = 0;
|
83
|
-
|
84
|
-
workflow.use(() => {
|
85
|
-
count = 1;
|
86
|
-
});
|
87
|
-
|
88
|
-
workflow.use(async () => {
|
89
|
-
await sleep(100);
|
90
|
-
count = 2;
|
91
|
-
});
|
92
|
-
|
93
|
-
workflow.use(() => {
|
94
|
-
count = 3;
|
95
|
-
});
|
96
|
-
|
97
|
-
await workflow.run();
|
98
|
-
|
99
|
-
expect(count).toBe(2);
|
100
|
-
});
|
101
|
-
|
102
|
-
it('isParallelWorkflow', () => {
|
103
|
-
const workflow = createParallelWorkflow();
|
104
|
-
|
105
|
-
expect(isParallelWorkflow(workflow)).toBeTruthy();
|
106
|
-
expect(isParallelWorkflow({})).toBeFalsy();
|
107
|
-
expect(isParallelWorkflow('test')).toBeFalsy();
|
108
|
-
expect(isParallelWorkflow(null)).toBeFalsy();
|
109
|
-
});
|
110
|
-
});
|
111
|
-
});
|
package/tsconfig.json
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": "@modern-js/tsconfig/base",
|
3
|
-
"compilerOptions": {
|
4
|
-
"declaration": false,
|
5
|
-
"jsx": "preserve",
|
6
|
-
"baseUrl": "./",
|
7
|
-
"isolatedModules": true,
|
8
|
-
"target": "ES5",
|
9
|
-
"esModuleInterop": true,
|
10
|
-
"paths": {},
|
11
|
-
"types": ["node", "jest"]
|
12
|
-
},
|
13
|
-
"include": ["src"]
|
14
|
-
}
|