@modern-js/app-tools 1.4.4 → 1.4.7-canary.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/.eslintrc.js +8 -0
- package/CHANGELOG.md +47 -0
- package/dist/js/modern/commands/build.js +15 -11
- package/dist/js/modern/commands/deploy.js +4 -4
- package/dist/js/modern/commands/dev.js +17 -11
- package/dist/js/modern/commands/start.js +9 -10
- package/dist/js/modern/exports/server.js +1 -0
- package/dist/js/modern/{lifecycle.js → hooks.js} +10 -13
- package/dist/js/modern/index.js +74 -73
- package/dist/js/modern/utils/config.js +53 -0
- package/dist/js/modern/utils/createCompiler.js +7 -7
- package/dist/js/modern/utils/createServer.js +1 -2
- package/dist/js/modern/utils/printInstructions.js +2 -3
- package/dist/js/node/commands/build.js +15 -10
- package/dist/js/node/commands/deploy.js +4 -5
- package/dist/js/node/commands/dev.js +18 -14
- package/dist/js/node/commands/start.js +9 -11
- package/dist/js/node/exports/server.js +13 -0
- package/dist/js/node/{lifecycle.js → hooks.js} +12 -18
- package/dist/js/node/index.js +81 -77
- package/dist/js/node/utils/config.js +78 -0
- package/dist/js/node/utils/createCompiler.js +7 -8
- package/dist/js/node/utils/createServer.js +1 -2
- package/dist/js/node/utils/printInstructions.js +2 -4
- package/dist/types/commands/build.d.ts +2 -1
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/commands/start.d.ts +2 -1
- package/dist/types/exports/server.d.ts +1 -0
- package/dist/types/{lifecycle.d.ts → hooks.d.ts} +19 -1
- package/dist/types/index.d.ts +2 -7
- package/dist/types/utils/config.d.ts +12 -0
- package/dist/types/utils/createCompiler.d.ts +3 -1
- package/dist/types/utils/printInstructions.d.ts +2 -2
- package/dist/types/utils/routes.d.ts +1 -1
- package/jest.config.js +0 -1
- package/modern.config.js +1 -0
- package/package.json +28 -22
- package/tests/.eslintrc.js +8 -0
- package/tests/__snapshots__/utils.test.ts.snap +5 -0
- package/tests/commands/build.test.ts +25 -24
- package/tests/utils.test.ts +46 -1
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
2
|
+
export declare const start: (api: PluginAPI) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineServerConfig as defineConfig } from '../utils/config';
|
|
@@ -16,4 +16,22 @@ export declare const beforeBuild: import("@modern-js/plugin").AsyncWorkflow<{
|
|
|
16
16
|
export declare const afterBuild: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
17
17
|
export declare const beforeDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
18
18
|
export declare const afterDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
19
|
-
export declare const
|
|
19
|
+
export declare const hooks: {
|
|
20
|
+
beforeDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
21
|
+
afterDev: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
22
|
+
beforeCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
|
|
23
|
+
webpackConfigs: Configuration[];
|
|
24
|
+
}, unknown>;
|
|
25
|
+
afterCreateCompiler: import("@modern-js/plugin").AsyncWorkflow<{
|
|
26
|
+
compiler: Compiler | MultiCompiler | undefined;
|
|
27
|
+
}, unknown>;
|
|
28
|
+
beforePrintInstructions: import("@modern-js/plugin").AsyncWaterfall<{
|
|
29
|
+
instructions: string;
|
|
30
|
+
}>;
|
|
31
|
+
beforeBuild: import("@modern-js/plugin").AsyncWorkflow<{
|
|
32
|
+
webpackConfigs: Configuration[];
|
|
33
|
+
}, unknown>;
|
|
34
|
+
afterBuild: import("@modern-js/plugin").AsyncWorkflow<void, unknown>;
|
|
35
|
+
beforeDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
36
|
+
afterDeploy: import("@modern-js/plugin").AsyncWorkflow<Record<string, any>, unknown>;
|
|
37
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { defineConfig } from '@modern-js/core';
|
|
1
|
+
import { defineConfig, CliPlugin } from '@modern-js/core';
|
|
2
2
|
export { defineConfig };
|
|
3
3
|
|
|
4
|
-
declare const _default:
|
|
5
|
-
setAppContext: (value: import("@modern-js/core").IAppContext) => void;
|
|
6
|
-
useAppContext: () => import("@modern-js/core").IAppContext;
|
|
7
|
-
useConfigContext: () => import("@modern-js/core/src/config").UserConfig;
|
|
8
|
-
useResolvedConfigContext: () => import("@modern-js/core").NormalizedConfig;
|
|
9
|
-
}>;
|
|
4
|
+
declare const _default: () => CliPlugin;
|
|
10
5
|
|
|
11
6
|
export default _default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { bundle } from '@modern-js/node-bundle-require';
|
|
2
|
+
import type { NormalizedConfig } from '@modern-js/core';
|
|
3
|
+
import type { ServerConfig } from '@modern-js/server-core';
|
|
4
|
+
export declare const defineServerConfig: (config: ServerConfig) => ServerConfig;
|
|
5
|
+
export declare const buildServerConfig: (appDirectory: string, configFile: string, options?: Parameters<typeof bundle>[1]) => Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* 处理循环引用的 replacer
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export declare const safeReplacer: () => (key: string, value: unknown) => unknown;
|
|
12
|
+
export declare const emitResolvedConfig: (appDirectory: string, resolvedConfig: NormalizedConfig) => Promise<void>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import webpack, { Configuration } from 'webpack';
|
|
2
|
-
import { IAppContext, NormalizedConfig } from '@modern-js/core';
|
|
2
|
+
import type { IAppContext, NormalizedConfig, PluginAPI } from '@modern-js/core';
|
|
3
3
|
export declare const createCompiler: ({
|
|
4
|
+
api,
|
|
4
5
|
webpackConfigs,
|
|
5
6
|
userConfig,
|
|
6
7
|
appContext
|
|
7
8
|
}: {
|
|
9
|
+
api: PluginAPI;
|
|
8
10
|
webpackConfigs: Configuration[];
|
|
9
11
|
userConfig: NormalizedConfig;
|
|
10
12
|
appContext: IAppContext;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IAppContext, NormalizedConfig } from '@modern-js/core';
|
|
2
|
-
export declare const printInstructions: (appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
|
|
1
|
+
import type { IAppContext, NormalizedConfig, ToRunners, CliHooks } from '@modern-js/core';
|
|
2
|
+
export declare const printInstructions: (hookRunners: ToRunners<CliHooks>, appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
|
package/jest.config.js
CHANGED
package/modern.config.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.7-canary.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -30,9 +30,13 @@
|
|
|
30
30
|
"jsnext:source": "./src/index.ts",
|
|
31
31
|
"default": "./dist/js/node/index.js"
|
|
32
32
|
},
|
|
33
|
-
"./
|
|
33
|
+
"./types": {
|
|
34
34
|
"jsnext:source": "./lib/types.d.ts",
|
|
35
35
|
"default": "./lib/types.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./server": {
|
|
38
|
+
"jsnext:source": "./src/exports/server.ts",
|
|
39
|
+
"default": "./dist/js/node/exports/server.js"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"typesVersions": {
|
|
@@ -42,6 +46,9 @@
|
|
|
42
46
|
],
|
|
43
47
|
"types": [
|
|
44
48
|
"./lib/types.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"server": [
|
|
51
|
+
"./dist/types/exports/server.d.ts"
|
|
45
52
|
]
|
|
46
53
|
}
|
|
47
54
|
},
|
|
@@ -49,45 +56,44 @@
|
|
|
49
56
|
"modern": "./bin/modern.js"
|
|
50
57
|
},
|
|
51
58
|
"dependencies": {
|
|
52
|
-
"@modern-js/core": "^1.5.0",
|
|
53
59
|
"@babel/runtime": "^7",
|
|
54
|
-
"@modern-js/
|
|
60
|
+
"@modern-js/core": "^1.6.1",
|
|
55
61
|
"@modern-js/i18n-cli-language-detector": "^1.2.1",
|
|
56
62
|
"@modern-js/new-action": "^1.3.3",
|
|
57
|
-
"@modern-js/
|
|
58
|
-
"@modern-js/plugin
|
|
59
|
-
"@modern-js/plugin-
|
|
63
|
+
"@modern-js/node-bundle-require": "^1.2.3",
|
|
64
|
+
"@modern-js/plugin": "^1.3.2",
|
|
65
|
+
"@modern-js/plugin-analyze": "^1.3.5",
|
|
66
|
+
"@modern-js/plugin-fast-refresh": "^1.2.3",
|
|
60
67
|
"@modern-js/plugin-i18n": "^1.2.1",
|
|
61
|
-
"@modern-js/server": "^1.
|
|
62
|
-
"@modern-js/
|
|
63
|
-
"@modern-js/
|
|
64
|
-
"@modern-js/
|
|
68
|
+
"@modern-js/prod-server": "^1.0.6",
|
|
69
|
+
"@modern-js/server": "^1.4.9",
|
|
70
|
+
"@modern-js/types": "^1.3.6",
|
|
71
|
+
"@modern-js/utils": "^1.3.7",
|
|
72
|
+
"@modern-js/webpack": "^1.5.3",
|
|
65
73
|
"inquirer": "^8.2.0",
|
|
66
|
-
"webpack": "^5.
|
|
74
|
+
"webpack": "^5.71.0"
|
|
67
75
|
},
|
|
68
76
|
"devDependencies": {
|
|
77
|
+
"@modern-js/server-core": "^1.2.4",
|
|
78
|
+
"@scripts/build": "0.0.0",
|
|
79
|
+
"@scripts/jest-config": "0.0.0",
|
|
80
|
+
"@types/inquirer": "^8.2.0",
|
|
69
81
|
"@types/jest": "^26",
|
|
70
82
|
"@types/node": "^14",
|
|
71
83
|
"@types/react": "^17",
|
|
72
84
|
"@types/react-dom": "^17",
|
|
73
|
-
"typescript": "^4",
|
|
74
|
-
"@scripts/build": "0.0.0",
|
|
75
85
|
"jest": "^27",
|
|
76
|
-
"
|
|
77
|
-
"@types/inquirer": "^8.2.0"
|
|
86
|
+
"typescript": "^4"
|
|
78
87
|
},
|
|
79
88
|
"sideEffects": false,
|
|
80
|
-
"modernConfig": {
|
|
81
|
-
"output": {
|
|
82
|
-
"packageMode": "node-js"
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
89
|
"publishConfig": {
|
|
86
90
|
"registry": "https://registry.npmjs.org/",
|
|
87
|
-
"access": "public"
|
|
91
|
+
"access": "public",
|
|
92
|
+
"types": "./dist/types/index.d.ts"
|
|
88
93
|
},
|
|
89
94
|
"scripts": {
|
|
90
95
|
"new": "modern new",
|
|
96
|
+
"dev": "modern build --watch",
|
|
91
97
|
"build": "modern build",
|
|
92
98
|
"test": "jest --passWithNoTests"
|
|
93
99
|
},
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`test app-tools utils safeReplacer should handle circular object 1`] = `"{\\"name\\":\\"a\\",\\"b\\":{\\"name\\":\\"b\\",\\"a\\":\\"[Circular root]\\"}}"`;
|
|
4
|
+
|
|
5
|
+
exports[`test app-tools utils safeReplacer should handle circular object 2`] = `"{\\"name\\":\\"c\\",\\"d\\":{\\"name\\":\\"d\\",\\"e\\":{\\"name\\":\\"e\\",\\"c\\":\\"[Circular root]\\"}}}"`;
|
|
@@ -1,27 +1,8 @@
|
|
|
1
|
+
import { manager } from '@modern-js/core';
|
|
1
2
|
import { build } from '../../src/commands/build';
|
|
2
3
|
|
|
3
|
-
const mockBeforeBuild = jest.fn();
|
|
4
|
-
const mockAfterBuild = jest.fn();
|
|
5
4
|
const mockGenerateRoutes = jest.fn();
|
|
6
5
|
|
|
7
|
-
// eslint-disable-next-line arrow-body-style
|
|
8
|
-
jest.mock('@modern-js/core', () => {
|
|
9
|
-
return {
|
|
10
|
-
__esModule: true,
|
|
11
|
-
mountHook() {
|
|
12
|
-
return {
|
|
13
|
-
beforeBuild: mockBeforeBuild,
|
|
14
|
-
afterBuild: mockAfterBuild,
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
useAppContext: jest.fn(() => ({
|
|
18
|
-
existSrc: false,
|
|
19
|
-
distDirectory: '',
|
|
20
|
-
})),
|
|
21
|
-
useResolvedConfigContext: jest.fn(),
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
6
|
jest.mock('../../src/utils/routes', () => ({
|
|
26
7
|
__esModule: true,
|
|
27
8
|
generateRoutes: () => mockGenerateRoutes(),
|
|
@@ -33,9 +14,29 @@ describe('command build', () => {
|
|
|
33
14
|
});
|
|
34
15
|
|
|
35
16
|
test('existSrc is false', async () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
const mockBeforeBuild = jest.fn();
|
|
18
|
+
const mockAfterBuild = jest.fn();
|
|
19
|
+
const mockAPI = {
|
|
20
|
+
useAppContext: jest.fn((): any => ({
|
|
21
|
+
existSrc: false,
|
|
22
|
+
distDirectory: '',
|
|
23
|
+
})),
|
|
24
|
+
useResolvedConfigContext: jest.fn(),
|
|
25
|
+
useHookRunners: (): any => ({
|
|
26
|
+
afterBuild: mockAfterBuild,
|
|
27
|
+
beforeBuild: mockBeforeBuild,
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const cloned = manager.clone(mockAPI);
|
|
32
|
+
cloned.usePlugin({
|
|
33
|
+
async setup(api) {
|
|
34
|
+
await build(api);
|
|
35
|
+
expect(mockBeforeBuild).toBeCalled();
|
|
36
|
+
expect(mockGenerateRoutes).toBeCalled();
|
|
37
|
+
expect(mockAfterBuild).toBeCalled();
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
await cloned.init();
|
|
40
41
|
});
|
|
41
42
|
});
|
package/tests/utils.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getServer,
|
|
7
7
|
} from '../src/utils/createServer';
|
|
8
8
|
import { getSpecifiedEntries } from '../src/utils/getSpecifiedEntries';
|
|
9
|
+
import { safeReplacer } from '../src/utils/config';
|
|
9
10
|
|
|
10
11
|
describe('test app-tools utils', () => {
|
|
11
12
|
it('should return all entryNames correctly', async () => {
|
|
@@ -40,7 +41,6 @@ describe('test app-tools utils', () => {
|
|
|
40
41
|
getSpecifiedEntries(['c'], [
|
|
41
42
|
{ entryName: 'a' },
|
|
42
43
|
{ entryName: 'b' },
|
|
43
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
44
44
|
] as any).catch(e => {
|
|
45
45
|
expect((e as Error).message).toMatch('can not found entry c');
|
|
46
46
|
resolve();
|
|
@@ -64,4 +64,49 @@ describe('test app-tools utils', () => {
|
|
|
64
64
|
await closeServer();
|
|
65
65
|
expect(getServer()).toBeNull();
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
it('safeReplacer should handle circular object', () => {
|
|
69
|
+
const a: {
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
} = {
|
|
72
|
+
name: 'a',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const b: {
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
} = {
|
|
78
|
+
name: 'b',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
a.b = b;
|
|
82
|
+
b.a = a;
|
|
83
|
+
|
|
84
|
+
const res1 = JSON.stringify(a, safeReplacer());
|
|
85
|
+
expect(res1).toMatchSnapshot();
|
|
86
|
+
|
|
87
|
+
const c: {
|
|
88
|
+
[key: string]: unknown;
|
|
89
|
+
} = {
|
|
90
|
+
name: 'c',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const d: {
|
|
94
|
+
[key: string]: unknown;
|
|
95
|
+
} = {
|
|
96
|
+
name: 'd',
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const e: {
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
} = {
|
|
102
|
+
name: 'e',
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
c.d = d;
|
|
106
|
+
d.e = e;
|
|
107
|
+
e.c = c;
|
|
108
|
+
|
|
109
|
+
const res2 = JSON.stringify(c, safeReplacer());
|
|
110
|
+
expect(res2).toMatchSnapshot();
|
|
111
|
+
});
|
|
67
112
|
});
|