@modern-js/plugin 1.3.2 → 1.3.5
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 +22 -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 +1 -1
- package/dist/js/modern/manager/runner.js +1 -1
- package/dist/js/modern/manager/sync.js +2 -3
- package/dist/js/modern/waterfall/async.js +5 -9
- package/dist/js/modern/waterfall/sync.js +5 -9
- package/dist/js/modern/workflow/async.js +2 -5
- package/dist/js/modern/workflow/parallel.js +3 -4
- package/dist/js/modern/workflow/sync.js +2 -2
- 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 +1 -1
- package/dist/js/node/manager/runner.js +1 -1
- package/dist/js/node/manager/sync.js +2 -3
- package/dist/js/node/waterfall/async.js +5 -9
- package/dist/js/node/waterfall/sync.js +5 -9
- package/dist/js/node/workflow/async.js +2 -5
- package/dist/js/node/workflow/parallel.js +3 -4
- package/dist/js/node/workflow/sync.js +2 -2
- 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 +5 -26
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +6 -25
- package/dist/js/treeshaking/waterfall/async.js +13 -37
- package/dist/js/treeshaking/waterfall/sync.js +12 -32
- package/dist/js/treeshaking/workflow/async.js +7 -29
- package/dist/js/treeshaking/workflow/parallel.js +7 -27
- package/dist/js/treeshaking/workflow/sync.js +6 -25
- 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 -8
- 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 -738
- 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 -701
- 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
@@ -1,22 +0,0 @@
|
|
1
|
-
import { createPlugin } from '../core';
|
2
|
-
import { register } from './fooManager';
|
3
|
-
|
4
|
-
let count = 0;
|
5
|
-
export const getBar = () => count;
|
6
|
-
|
7
|
-
register(() => {
|
8
|
-
count = 1;
|
9
|
-
|
10
|
-
return {
|
11
|
-
fooWaterfall: () => {
|
12
|
-
count = 2;
|
13
|
-
},
|
14
|
-
fooWorflow: () => {
|
15
|
-
count = 3;
|
16
|
-
},
|
17
|
-
};
|
18
|
-
});
|
19
|
-
|
20
|
-
const bar = createPlugin(() => ({}), { post: ['foo'] });
|
21
|
-
|
22
|
-
export default bar;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { createPlugin } from '../core';
|
2
|
-
import { initFooPlugins } from './fooManager';
|
3
|
-
|
4
|
-
const foo = createPlugin(
|
5
|
-
async () => {
|
6
|
-
const fooManage = initFooPlugins();
|
7
|
-
|
8
|
-
return {
|
9
|
-
preDev: () => {
|
10
|
-
fooManage.fooWaterfall();
|
11
|
-
},
|
12
|
-
postDev: () => {
|
13
|
-
fooManage.fooWorflow();
|
14
|
-
},
|
15
|
-
};
|
16
|
-
},
|
17
|
-
{ name: 'foo' },
|
18
|
-
);
|
19
|
-
|
20
|
-
export default foo;
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createContext,
|
3
|
-
createWaterfall,
|
4
|
-
createWorkflow,
|
5
|
-
createManager,
|
6
|
-
} from '../../../../src';
|
7
|
-
|
8
|
-
// foo plugin
|
9
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
10
|
-
export type Config = {};
|
11
|
-
const defaultConfig = {};
|
12
|
-
const ConfigContext = createContext<Config>(defaultConfig);
|
13
|
-
export const useConfig = (): Config => {
|
14
|
-
const config = ConfigContext.use().value;
|
15
|
-
|
16
|
-
if (!config) {
|
17
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-base-to-string
|
18
|
-
throw new Error(`Expected modern config, but got: ${config}`);
|
19
|
-
}
|
20
|
-
|
21
|
-
return config;
|
22
|
-
};
|
23
|
-
|
24
|
-
// prepare
|
25
|
-
export const fooWaterfall = createWaterfall();
|
26
|
-
const fooWorflow = createWorkflow();
|
27
|
-
|
28
|
-
const fooMain = createManager({
|
29
|
-
fooWaterfall,
|
30
|
-
fooWorflow,
|
31
|
-
});
|
32
|
-
|
33
|
-
export const createFooPlugin = fooMain.createPlugin;
|
34
|
-
|
35
|
-
export const isFooPlugin = fooMain.isPlugin;
|
36
|
-
|
37
|
-
export const useFooPlugin = fooMain.usePlugin;
|
38
|
-
|
39
|
-
export const initFooPlugins = fooMain.init;
|
40
|
-
|
41
|
-
type Paramter<F extends (i: any) => any> = F extends (i: infer P) => any
|
42
|
-
? P
|
43
|
-
: never;
|
44
|
-
|
45
|
-
export const register = (initializer: Paramter<typeof fooMain.createPlugin>) =>
|
46
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
47
|
-
useFooPlugin(createFooPlugin(initializer));
|
@@ -1,174 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createAsyncManager,
|
3
|
-
createWaterfall,
|
4
|
-
createWorkflow,
|
5
|
-
createContext,
|
6
|
-
PluginOptions,
|
7
|
-
AsyncSetup,
|
8
|
-
} from '../../../../src';
|
9
|
-
|
10
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
11
|
-
export type CTX = {};
|
12
|
-
const defaultContext = {};
|
13
|
-
const CTXContext = createContext<CTX>(defaultContext);
|
14
|
-
export const useContext = (): CTX => {
|
15
|
-
const context = CTXContext.use().value;
|
16
|
-
|
17
|
-
if (!context) {
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
19
|
-
throw new Error(`Expected modern context, but got: ${context}`);
|
20
|
-
}
|
21
|
-
|
22
|
-
return context;
|
23
|
-
};
|
24
|
-
|
25
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
26
|
-
export type Config = {};
|
27
|
-
const defaultConfig = {};
|
28
|
-
const ConfigContext = createContext<Config>(defaultConfig);
|
29
|
-
export const useConfig = (): Config => {
|
30
|
-
const config = ConfigContext.use().value;
|
31
|
-
|
32
|
-
if (!config) {
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
34
|
-
throw new Error(`Expected modern config, but got: ${config}`);
|
35
|
-
}
|
36
|
-
|
37
|
-
return config;
|
38
|
-
};
|
39
|
-
|
40
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
41
|
-
export type WebpackConfig = {};
|
42
|
-
const defaultWebpackConfig = {};
|
43
|
-
const WebpackConfigContext = createContext<WebpackConfig>(defaultWebpackConfig);
|
44
|
-
export const useWebpackConfig = (): WebpackConfig => {
|
45
|
-
const webpackConfig = WebpackConfigContext.use().value;
|
46
|
-
|
47
|
-
if (!webpackConfig) {
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
49
|
-
throw new Error(`Expected webpack config, but got: ${webpackConfig}`);
|
50
|
-
}
|
51
|
-
|
52
|
-
return webpackConfig;
|
53
|
-
};
|
54
|
-
|
55
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
56
|
-
export type BabelConfig = {};
|
57
|
-
const defaultBabelConfig = {};
|
58
|
-
const BabelConfigContext = createContext<BabelConfig>(defaultBabelConfig);
|
59
|
-
export const useBabelConfig = (): BabelConfig => {
|
60
|
-
const babelConfig = BabelConfigContext.use().value;
|
61
|
-
|
62
|
-
if (!babelConfig) {
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
64
|
-
throw new Error(`Expected babel config, but got: ${babelConfig}`);
|
65
|
-
}
|
66
|
-
|
67
|
-
return babelConfig;
|
68
|
-
};
|
69
|
-
|
70
|
-
// prepare
|
71
|
-
const prepare = createWaterfall();
|
72
|
-
|
73
|
-
// develop
|
74
|
-
const preDev = createWorkflow();
|
75
|
-
|
76
|
-
const postDev = createWorkflow();
|
77
|
-
|
78
|
-
// build
|
79
|
-
const preBuild = createWorkflow();
|
80
|
-
|
81
|
-
const postBuild = createWorkflow();
|
82
|
-
|
83
|
-
// config
|
84
|
-
const config = createWaterfall<{
|
85
|
-
config: Config;
|
86
|
-
webpackConfig: WebpackConfig;
|
87
|
-
babelConfig: BabelConfig;
|
88
|
-
}>();
|
89
|
-
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
91
|
-
export interface ExternalProgress {}
|
92
|
-
|
93
|
-
// main process
|
94
|
-
const lifecircle = {
|
95
|
-
prepare,
|
96
|
-
config,
|
97
|
-
|
98
|
-
preDev,
|
99
|
-
postDev,
|
100
|
-
|
101
|
-
preBuild,
|
102
|
-
postBuild,
|
103
|
-
};
|
104
|
-
|
105
|
-
export type TestAsyncHooks = ExternalProgress & typeof lifecircle;
|
106
|
-
|
107
|
-
export const main = createAsyncManager<TestAsyncHooks>(lifecircle);
|
108
|
-
|
109
|
-
export type TestAsyncPlugin = PluginOptions<
|
110
|
-
TestAsyncHooks,
|
111
|
-
AsyncSetup<TestAsyncHooks>
|
112
|
-
>;
|
113
|
-
|
114
|
-
export const { createPlugin } = main;
|
115
|
-
|
116
|
-
export const { isPlugin } = main;
|
117
|
-
|
118
|
-
export const { usePlugin } = main;
|
119
|
-
|
120
|
-
export const initPlugins = main.init;
|
121
|
-
|
122
|
-
export const { registerHook } = main;
|
123
|
-
|
124
|
-
export const { useRunner } = main;
|
125
|
-
|
126
|
-
export const createNewManager = main.clone;
|
127
|
-
|
128
|
-
export const develop = async (context: CTX) => {
|
129
|
-
const runner = await main.init();
|
130
|
-
|
131
|
-
main.run(() => {
|
132
|
-
CTXContext.set(context);
|
133
|
-
});
|
134
|
-
runner.prepare();
|
135
|
-
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
137
|
-
const { config, webpackConfig, babelConfig } = runner.config({
|
138
|
-
config: defaultConfig,
|
139
|
-
webpackConfig: defaultWebpackConfig,
|
140
|
-
babelConfig: defaultBabelConfig,
|
141
|
-
});
|
142
|
-
|
143
|
-
main.run(() => {
|
144
|
-
ConfigContext.set(config);
|
145
|
-
WebpackConfigContext.set(webpackConfig);
|
146
|
-
BabelConfigContext.set(babelConfig);
|
147
|
-
});
|
148
|
-
runner.preDev();
|
149
|
-
runner.postDev();
|
150
|
-
};
|
151
|
-
|
152
|
-
export const build = async (context: CTX) => {
|
153
|
-
const runner = await main.init();
|
154
|
-
|
155
|
-
main.run(() => {
|
156
|
-
CTXContext.set(context);
|
157
|
-
});
|
158
|
-
runner.prepare();
|
159
|
-
|
160
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
161
|
-
const { config, webpackConfig, babelConfig } = runner.config({
|
162
|
-
config: defaultConfig,
|
163
|
-
webpackConfig: defaultWebpackConfig,
|
164
|
-
babelConfig: defaultBabelConfig,
|
165
|
-
});
|
166
|
-
|
167
|
-
main.run(() => {
|
168
|
-
ConfigContext.set(config);
|
169
|
-
WebpackConfigContext.set(webpackConfig);
|
170
|
-
BabelConfigContext.set(babelConfig);
|
171
|
-
});
|
172
|
-
runner.preDev();
|
173
|
-
runner.postDev();
|
174
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { createPlugin } from '../core';
|
2
|
-
|
3
|
-
let number = 0;
|
4
|
-
export const getNumber = () => number;
|
5
|
-
|
6
|
-
const bar = createPlugin(() => {
|
7
|
-
number = 1;
|
8
|
-
return {
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
10
|
-
preDev: () => {},
|
11
|
-
fooWaterfall: async input => {
|
12
|
-
number = 2;
|
13
|
-
return input;
|
14
|
-
},
|
15
|
-
};
|
16
|
-
});
|
17
|
-
|
18
|
-
export default bar;
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { createAsyncWaterfall } from '../../../../src';
|
2
|
-
import { createPlugin, registerHook, useRunner } from '../core';
|
3
|
-
|
4
|
-
// declare new lifecircle type
|
5
|
-
declare module '../core' {
|
6
|
-
interface ExternalProgress {
|
7
|
-
fooWaterfall: typeof fooWaterfall;
|
8
|
-
}
|
9
|
-
}
|
10
|
-
|
11
|
-
// create new manage model of new lifecircle 新生命周期运行管理模型创建
|
12
|
-
const fooWaterfall = createAsyncWaterfall();
|
13
|
-
|
14
|
-
const foo = createPlugin(() => {
|
15
|
-
// registe new lifecircle
|
16
|
-
registerHook({ fooWaterfall });
|
17
|
-
|
18
|
-
return {
|
19
|
-
preDev: () => {
|
20
|
-
// run new lifecircle
|
21
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
22
|
-
useRunner().fooWaterfall();
|
23
|
-
},
|
24
|
-
};
|
25
|
-
});
|
26
|
-
|
27
|
-
export default foo;
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import { createPlugin } from '../core';
|
2
|
-
import { register } from './fooManager';
|
3
|
-
|
4
|
-
let count = 0;
|
5
|
-
export const getBar = () => count;
|
6
|
-
register(() => {
|
7
|
-
count = 1;
|
8
|
-
|
9
|
-
return {
|
10
|
-
fooWaterfall: () => {
|
11
|
-
count = 2;
|
12
|
-
},
|
13
|
-
fooWorflow: () => {
|
14
|
-
count = 3;
|
15
|
-
},
|
16
|
-
};
|
17
|
-
});
|
18
|
-
|
19
|
-
const bar = createPlugin(() => ({}), { post: ['foo'] });
|
20
|
-
|
21
|
-
export default bar;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { createPlugin } from '../core';
|
2
|
-
import { initFooPlugins } from './fooManager';
|
3
|
-
|
4
|
-
const foo = createPlugin(
|
5
|
-
() => {
|
6
|
-
const fooManage = initFooPlugins();
|
7
|
-
|
8
|
-
return {
|
9
|
-
preDev: async () => {
|
10
|
-
fooManage.fooWaterfall();
|
11
|
-
},
|
12
|
-
postDev: async () => {
|
13
|
-
fooManage.fooWorflow();
|
14
|
-
},
|
15
|
-
};
|
16
|
-
},
|
17
|
-
{ name: 'foo' },
|
18
|
-
);
|
19
|
-
|
20
|
-
export default foo;
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createContext,
|
3
|
-
createWaterfall,
|
4
|
-
createWorkflow,
|
5
|
-
createManager,
|
6
|
-
} from '../../../../src';
|
7
|
-
|
8
|
-
// foo plugin
|
9
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
10
|
-
export type Config = {};
|
11
|
-
const defaultConfig = {};
|
12
|
-
const ConfigContext = createContext<Config>(defaultConfig);
|
13
|
-
export const useConfig = (): Config => {
|
14
|
-
const config = ConfigContext.use().value;
|
15
|
-
|
16
|
-
if (!config) {
|
17
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-base-to-string
|
18
|
-
throw new Error(`Expected modern config, but got: ${config}`);
|
19
|
-
}
|
20
|
-
|
21
|
-
return config;
|
22
|
-
};
|
23
|
-
|
24
|
-
// prepare
|
25
|
-
export const fooWaterfall = createWaterfall();
|
26
|
-
const fooWorflow = createWorkflow();
|
27
|
-
|
28
|
-
const fooMain = createManager({
|
29
|
-
fooWaterfall,
|
30
|
-
fooWorflow,
|
31
|
-
});
|
32
|
-
|
33
|
-
export const createFooPlugin = fooMain.createPlugin;
|
34
|
-
|
35
|
-
export const isFooPlugin = fooMain.isPlugin;
|
36
|
-
|
37
|
-
export const useFooPlugin = fooMain.usePlugin;
|
38
|
-
|
39
|
-
export const initFooPlugins = fooMain.init;
|
40
|
-
|
41
|
-
type Paramter<F extends (i: any) => any> = F extends (i: infer P) => any
|
42
|
-
? P
|
43
|
-
: never;
|
44
|
-
|
45
|
-
export const register = (initializer: Paramter<typeof fooMain.createPlugin>) =>
|
46
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
47
|
-
useFooPlugin(createFooPlugin(initializer));
|
@@ -1,171 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Setup,
|
3
|
-
createManager,
|
4
|
-
createWaterfall,
|
5
|
-
createWorkflow,
|
6
|
-
createContext,
|
7
|
-
PluginOptions,
|
8
|
-
} from '../../../../src';
|
9
|
-
|
10
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
11
|
-
export type CTX = {};
|
12
|
-
const defaultContext = {};
|
13
|
-
const CTXContext = createContext<CTX>(defaultContext);
|
14
|
-
export const useContext = (): CTX => {
|
15
|
-
const context = CTXContext.use().value;
|
16
|
-
|
17
|
-
if (!context) {
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
19
|
-
throw new Error(`Expected modern context, but got: ${context}`);
|
20
|
-
}
|
21
|
-
|
22
|
-
return context;
|
23
|
-
};
|
24
|
-
|
25
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
26
|
-
export type Config = {};
|
27
|
-
const defaultConfig = {};
|
28
|
-
const ConfigContext = createContext<Config>(defaultConfig);
|
29
|
-
export const useConfig = (): Config => {
|
30
|
-
const config = ConfigContext.use().value;
|
31
|
-
|
32
|
-
if (!config) {
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
34
|
-
throw new Error(`Expected modern config, but got: ${config}`);
|
35
|
-
}
|
36
|
-
|
37
|
-
return config;
|
38
|
-
};
|
39
|
-
|
40
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
41
|
-
export type WebpackConfig = {};
|
42
|
-
const defaultWebpackConfig = {};
|
43
|
-
const WebpackConfigContext = createContext<WebpackConfig>(defaultWebpackConfig);
|
44
|
-
export const useWebpackConfig = (): WebpackConfig => {
|
45
|
-
const webpackConfig = WebpackConfigContext.use().value;
|
46
|
-
|
47
|
-
if (!webpackConfig) {
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
49
|
-
throw new Error(`Expected webpack config, but got: ${webpackConfig}`);
|
50
|
-
}
|
51
|
-
|
52
|
-
return webpackConfig;
|
53
|
-
};
|
54
|
-
|
55
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
56
|
-
export type BabelConfig = {};
|
57
|
-
const defaultBabelConfig = {};
|
58
|
-
const BabelConfigContext = createContext<BabelConfig>(defaultBabelConfig);
|
59
|
-
export const useBabelConfig = (): BabelConfig => {
|
60
|
-
const babelConfig = BabelConfigContext.use().value;
|
61
|
-
|
62
|
-
if (!babelConfig) {
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
64
|
-
throw new Error(`Expected babel config, but got: ${babelConfig}`);
|
65
|
-
}
|
66
|
-
|
67
|
-
return babelConfig;
|
68
|
-
};
|
69
|
-
|
70
|
-
// prepare
|
71
|
-
const prepare = createWaterfall();
|
72
|
-
|
73
|
-
// develop
|
74
|
-
const preDev = createWorkflow();
|
75
|
-
|
76
|
-
const postDev = createWorkflow();
|
77
|
-
|
78
|
-
// build
|
79
|
-
const preBuild = createWorkflow();
|
80
|
-
|
81
|
-
const postBuild = createWorkflow();
|
82
|
-
|
83
|
-
// config
|
84
|
-
const config = createWaterfall<{
|
85
|
-
config: Config;
|
86
|
-
webpackConfig: WebpackConfig;
|
87
|
-
babelConfig: BabelConfig;
|
88
|
-
}>();
|
89
|
-
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
91
|
-
export interface ExternalProgress {}
|
92
|
-
|
93
|
-
// main process
|
94
|
-
const lifecircle = {
|
95
|
-
prepare,
|
96
|
-
config,
|
97
|
-
|
98
|
-
preDev,
|
99
|
-
postDev,
|
100
|
-
|
101
|
-
preBuild,
|
102
|
-
postBuild,
|
103
|
-
};
|
104
|
-
|
105
|
-
export type TestHooks = ExternalProgress & typeof lifecircle;
|
106
|
-
|
107
|
-
export const main = createManager<TestHooks>(lifecircle);
|
108
|
-
|
109
|
-
export type TestPlugin = PluginOptions<TestHooks, Setup<TestHooks>>;
|
110
|
-
|
111
|
-
export const { createPlugin } = main;
|
112
|
-
|
113
|
-
export const { isPlugin } = main;
|
114
|
-
|
115
|
-
export const { usePlugin } = main;
|
116
|
-
|
117
|
-
export const initPlugins = main.init;
|
118
|
-
|
119
|
-
export const { registerHook } = main;
|
120
|
-
|
121
|
-
export const { useRunner } = main;
|
122
|
-
|
123
|
-
export const develop = (context: CTX) => {
|
124
|
-
const runner = main.init();
|
125
|
-
|
126
|
-
main.run(() => {
|
127
|
-
CTXContext.set(context);
|
128
|
-
});
|
129
|
-
runner.prepare();
|
130
|
-
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
132
|
-
const { config, webpackConfig, babelConfig } = runner.config({
|
133
|
-
config: defaultConfig,
|
134
|
-
webpackConfig: defaultWebpackConfig,
|
135
|
-
babelConfig: defaultBabelConfig,
|
136
|
-
});
|
137
|
-
|
138
|
-
main.run(() => {
|
139
|
-
ConfigContext.set(config);
|
140
|
-
WebpackConfigContext.set(webpackConfig);
|
141
|
-
BabelConfigContext.set(babelConfig);
|
142
|
-
});
|
143
|
-
runner.preDev();
|
144
|
-
runner.postDev();
|
145
|
-
};
|
146
|
-
|
147
|
-
export const build = (context: CTX) => {
|
148
|
-
const runner = main.init();
|
149
|
-
|
150
|
-
main.run(() => {
|
151
|
-
CTXContext.set(context);
|
152
|
-
});
|
153
|
-
runner.prepare();
|
154
|
-
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
156
|
-
const { config, webpackConfig, babelConfig } = runner.config({
|
157
|
-
config: defaultConfig,
|
158
|
-
webpackConfig: defaultWebpackConfig,
|
159
|
-
babelConfig: defaultBabelConfig,
|
160
|
-
});
|
161
|
-
|
162
|
-
main.run(() => {
|
163
|
-
ConfigContext.set(config);
|
164
|
-
WebpackConfigContext.set(webpackConfig);
|
165
|
-
BabelConfigContext.set(babelConfig);
|
166
|
-
});
|
167
|
-
|
168
|
-
runner.preBuild();
|
169
|
-
|
170
|
-
runner.postBuild();
|
171
|
-
};
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { createPlugin } from '../core';
|
2
|
-
|
3
|
-
let number = 0;
|
4
|
-
export const getNumber = () => number;
|
5
|
-
|
6
|
-
export const setNumber = (newNumber: number) => {
|
7
|
-
number = newNumber;
|
8
|
-
};
|
9
|
-
|
10
|
-
const bar = createPlugin(() => {
|
11
|
-
number = 1;
|
12
|
-
return {
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
14
|
-
preDev: async () => {},
|
15
|
-
fooWaterfall: async input => {
|
16
|
-
number = 2;
|
17
|
-
return input;
|
18
|
-
},
|
19
|
-
};
|
20
|
-
});
|
21
|
-
|
22
|
-
export default bar;
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { createAsyncWaterfall } from '../../../../src';
|
2
|
-
import { createPlugin, registerHook, useRunner } from '../core';
|
3
|
-
|
4
|
-
// declare new lifecircle type
|
5
|
-
declare module '../core' {
|
6
|
-
interface ExternalProgress {
|
7
|
-
fooWaterfall: typeof fooWaterfall;
|
8
|
-
}
|
9
|
-
}
|
10
|
-
|
11
|
-
// create new manage model of new lifecircle 新生命周期运行管理模型创建
|
12
|
-
const fooWaterfall = createAsyncWaterfall();
|
13
|
-
|
14
|
-
const foo = createPlugin(() => {
|
15
|
-
// registe new lifecircle
|
16
|
-
registerHook({ fooWaterfall });
|
17
|
-
|
18
|
-
return {
|
19
|
-
preDev: () => {
|
20
|
-
// run new lifecircle
|
21
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
22
|
-
useRunner().fooWaterfall();
|
23
|
-
},
|
24
|
-
};
|
25
|
-
});
|
26
|
-
|
27
|
-
export default foo;
|
package/tests/helpers.ts
DELETED