@modern-js/plugin 1.3.0 → 1.3.3

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 (44) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +16 -0
  3. package/dist/js/modern/manager/async.js +9 -5
  4. package/dist/js/modern/manager/sync.js +10 -7
  5. package/dist/js/modern/waterfall/async.js +3 -5
  6. package/dist/js/modern/waterfall/sync.js +3 -5
  7. package/dist/js/modern/workflow/async.js +0 -3
  8. package/dist/js/modern/workflow/parallel.js +1 -2
  9. package/dist/js/node/manager/async.js +9 -5
  10. package/dist/js/node/manager/sync.js +10 -7
  11. package/dist/js/node/waterfall/async.js +3 -5
  12. package/dist/js/node/waterfall/sync.js +3 -5
  13. package/dist/js/node/workflow/async.js +0 -3
  14. package/dist/js/node/workflow/parallel.js +1 -2
  15. package/dist/js/treeshaking/manager/async.js +9 -5
  16. package/dist/js/treeshaking/manager/sync.js +10 -7
  17. package/dist/js/treeshaking/waterfall/async.js +7 -10
  18. package/dist/js/treeshaking/waterfall/sync.js +7 -10
  19. package/dist/js/treeshaking/workflow/async.js +0 -2
  20. package/dist/js/treeshaking/workflow/parallel.js +1 -2
  21. package/dist/types/manager/async.d.ts +1 -1
  22. package/dist/types/manager/sync.d.ts +1 -1
  23. package/jest.config.js +0 -1
  24. package/package.json +1 -1
  25. package/tests/.eslintrc.js +0 -6
  26. package/tests/async.test.ts +0 -712
  27. package/tests/fixtures/async/base/bar.ts +0 -22
  28. package/tests/fixtures/async/base/foo.ts +0 -20
  29. package/tests/fixtures/async/base/fooManager.ts +0 -47
  30. package/tests/fixtures/async/core/index.ts +0 -174
  31. package/tests/fixtures/async/dynamic/bar.ts +0 -18
  32. package/tests/fixtures/async/dynamic/foo.ts +0 -27
  33. package/tests/fixtures/sync/base/bar.ts +0 -21
  34. package/tests/fixtures/sync/base/foo.ts +0 -20
  35. package/tests/fixtures/sync/base/fooManager.ts +0 -47
  36. package/tests/fixtures/sync/core/index.ts +0 -171
  37. package/tests/fixtures/sync/dynamic/bar.ts +0 -22
  38. package/tests/fixtures/sync/dynamic/foo.ts +0 -27
  39. package/tests/helpers.ts +0 -4
  40. package/tests/pipeline.test.ts +0 -607
  41. package/tests/sync.test.ts +0 -677
  42. package/tests/tsconfig.json +0 -13
  43. package/tests/waterfall.test.ts +0 -172
  44. package/tests/workflow.test.ts +0 -111
@@ -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
@@ -1,4 +0,0 @@
1
- export const sleep = (ms: number) =>
2
- new Promise(resolve => {
3
- setTimeout(resolve, ms);
4
- });