@modern-js/app-tools 1.5.0 → 1.6.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/CHANGELOG.md +39 -0
- package/dist/js/modern/commands/build.js +10 -3
- package/dist/js/modern/commands/dev.js +7 -7
- package/dist/js/modern/commands/start.js +4 -2
- package/dist/js/modern/index.js +2 -2
- package/dist/js/modern/locale/en.js +2 -1
- package/dist/js/modern/locale/zh.js +2 -1
- package/dist/js/modern/utils/config.js +2 -1
- package/dist/js/modern/utils/printInstructions.js +2 -2
- package/dist/js/node/commands/build.js +10 -3
- package/dist/js/node/commands/dev.js +7 -8
- package/dist/js/node/commands/start.js +3 -1
- package/dist/js/node/index.js +2 -2
- package/dist/js/node/locale/en.js +2 -1
- package/dist/js/node/locale/zh.js +2 -1
- package/dist/js/node/utils/config.js +2 -1
- package/dist/js/node/utils/printInstructions.js +2 -2
- package/dist/types/locale/en.d.ts +1 -0
- package/dist/types/locale/index.d.ts +2 -0
- package/dist/types/locale/zh.d.ts +1 -0
- package/dist/types/utils/types.d.ts +4 -0
- package/package.json +15 -15
- package/tests/.eslintrc.js +0 -8
- package/tests/__snapshots__/utils.test.ts.snap +0 -5
- package/tests/commands/build.test.ts +0 -42
- package/tests/commands/dev.test.ts +0 -7
- package/tests/index.test.ts +0 -7
- package/tests/routes.test.ts +0 -27
- package/tests/tsconfig.json +0 -13
- package/tests/utils.test.ts +0 -112
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3bf4f8b0: feat: support start api server only
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
12
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
13
|
+
- 5dbbeb57: fix: export extended Command type
|
|
14
|
+
- 305e0bb4: fix: commander.commandsMap typing not work
|
|
15
|
+
- Updated dependencies [a4330c73]
|
|
16
|
+
- Updated dependencies [b8599d09]
|
|
17
|
+
- Updated dependencies [6cffe99d]
|
|
18
|
+
- Updated dependencies [04ae5262]
|
|
19
|
+
- Updated dependencies [60f7d8bf]
|
|
20
|
+
- Updated dependencies [e4cec1ce]
|
|
21
|
+
- Updated dependencies [3b7aa8bb]
|
|
22
|
+
- Updated dependencies [5dbbeb57]
|
|
23
|
+
- Updated dependencies [ebfcbb35]
|
|
24
|
+
- Updated dependencies [3bf4f8b0]
|
|
25
|
+
- Updated dependencies [305e0bb4]
|
|
26
|
+
- Updated dependencies [ebfcbb35]
|
|
27
|
+
- Updated dependencies [28ac120a]
|
|
28
|
+
- @modern-js/core@1.8.0
|
|
29
|
+
- @modern-js/node-bundle-require@1.3.1
|
|
30
|
+
- @modern-js/utils@1.5.0
|
|
31
|
+
- @modern-js/i18n-cli-language-detector@1.2.2
|
|
32
|
+
- @modern-js/plugin-fast-refresh@1.2.4
|
|
33
|
+
- @modern-js/plugin-i18n@1.2.4
|
|
34
|
+
- @modern-js/webpack@1.5.5
|
|
35
|
+
- @modern-js/new-action@1.3.6
|
|
36
|
+
- @modern-js/prod-server@1.1.1
|
|
37
|
+
- @modern-js/server@1.4.10
|
|
38
|
+
- @modern-js/plugin@1.3.3
|
|
39
|
+
- @modern-js/types@1.5.0
|
|
40
|
+
- @modern-js/plugin-analyze@1.4.0
|
|
41
|
+
|
|
3
42
|
## 1.5.0
|
|
4
43
|
|
|
5
44
|
### Minor Changes
|
|
@@ -18,17 +18,24 @@ export const build = async (api, options) => {
|
|
|
18
18
|
const appContext = api.useAppContext();
|
|
19
19
|
const hookRunners = api.useHookRunners();
|
|
20
20
|
const {
|
|
21
|
-
|
|
21
|
+
apiOnly
|
|
22
22
|
} = appContext;
|
|
23
23
|
|
|
24
|
-
if (
|
|
24
|
+
if (apiOnly) {
|
|
25
25
|
const {
|
|
26
|
-
|
|
26
|
+
appDirectory,
|
|
27
|
+
distDirectory,
|
|
28
|
+
serverConfigFile
|
|
27
29
|
} = appContext;
|
|
28
30
|
await emptyDir(distDirectory);
|
|
29
31
|
await hookRunners.beforeBuild({
|
|
30
32
|
webpackConfigs: []
|
|
31
33
|
});
|
|
34
|
+
await buildServerConfig({
|
|
35
|
+
appDirectory,
|
|
36
|
+
distDirectory,
|
|
37
|
+
configFile: serverConfigFile
|
|
38
|
+
});
|
|
32
39
|
await generateRoutes(appContext);
|
|
33
40
|
await hookRunners.afterBuild();
|
|
34
41
|
return;
|
|
@@ -19,7 +19,7 @@ export const dev = async (api, options) => {
|
|
|
19
19
|
appDirectory,
|
|
20
20
|
distDirectory,
|
|
21
21
|
port,
|
|
22
|
-
|
|
22
|
+
apiOnly,
|
|
23
23
|
entrypoints,
|
|
24
24
|
serverConfigFile
|
|
25
25
|
} = appContext;
|
|
@@ -42,7 +42,7 @@ export const dev = async (api, options) => {
|
|
|
42
42
|
await hookRunners.beforeDev();
|
|
43
43
|
let compiler = null;
|
|
44
44
|
|
|
45
|
-
if (
|
|
45
|
+
if (!apiOnly) {
|
|
46
46
|
const {
|
|
47
47
|
getWebpackConfig,
|
|
48
48
|
WebpackConfigTarget
|
|
@@ -86,11 +86,11 @@ export const dev = async (api, options) => {
|
|
|
86
86
|
throw err;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
logger.log(chalk.cyan(`Starting the development server...`));
|
|
92
|
-
} else {
|
|
93
|
-
await printInstructions(hookRunners, appContext, userConfig);
|
|
89
|
+
if (apiOnly) {
|
|
90
|
+
return printInstructions(hookRunners, appContext, userConfig);
|
|
94
91
|
}
|
|
92
|
+
|
|
93
|
+
clearConsole();
|
|
94
|
+
return logger.log(chalk.cyan(`Starting the development server...`));
|
|
95
95
|
});
|
|
96
96
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger, chalk } from '@modern-js/utils';
|
|
1
|
+
import { logger, chalk, isApiOnly } from '@modern-js/utils';
|
|
2
2
|
import server from '@modern-js/prod-server';
|
|
3
3
|
import { printInstructions } from "../utils/printInstructions";
|
|
4
4
|
export const start = async api => {
|
|
@@ -11,11 +11,13 @@ export const start = async api => {
|
|
|
11
11
|
serverConfigFile
|
|
12
12
|
} = appContext;
|
|
13
13
|
logger.log(chalk.cyan(`Starting the modern server...`));
|
|
14
|
+
const apiOnly = await isApiOnly(appContext.appDirectory);
|
|
14
15
|
const app = await server({
|
|
15
16
|
pwd: appDirectory,
|
|
16
17
|
config: userConfig,
|
|
17
18
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
|
|
18
|
-
serverConfigFile
|
|
19
|
+
serverConfigFile,
|
|
20
|
+
apiOnly
|
|
19
21
|
});
|
|
20
22
|
app.listen(port, async err => {
|
|
21
23
|
if (err) {
|
package/dist/js/modern/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export default (() => ({
|
|
|
30
30
|
commands({
|
|
31
31
|
program
|
|
32
32
|
}) {
|
|
33
|
-
program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).action(async options => {
|
|
33
|
+
program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).action(async options => {
|
|
34
34
|
await dev(api, options);
|
|
35
35
|
});
|
|
36
36
|
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('--analyze', i18n.t(localeKeys.command.build.analyze)).action(async options => {
|
|
@@ -42,7 +42,7 @@ export default (() => ({
|
|
|
42
42
|
|
|
43
43
|
process.exit(0);
|
|
44
44
|
});
|
|
45
|
-
program.command('start').usage('[options]').description(i18n.t(localeKeys.command.start.describe)).action(async () => {
|
|
45
|
+
program.command('start').usage('[options]').description(i18n.t(localeKeys.command.start.describe)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).action(async () => {
|
|
46
46
|
await start(api);
|
|
47
47
|
});
|
|
48
48
|
program.command('deploy').usage('[options]').description(i18n.t(localeKeys.command.deploy.describe)).action(async options => {
|
|
@@ -19,10 +19,11 @@ export const buildServerConfig = async ({
|
|
|
19
19
|
const getOutputFile = filepath => path.resolve(distDirectory, `${filepath.replace(new RegExp(CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
|
|
20
20
|
|
|
21
21
|
if (configFilePath) {
|
|
22
|
-
const configHelperFilePath = path.join(distDirectory, './config-helper.js');
|
|
22
|
+
const configHelperFilePath = path.normalize(path.join(distDirectory, './config-helper.js'));
|
|
23
23
|
const helperCode = `
|
|
24
24
|
export const defineConfig = (config) => config;
|
|
25
25
|
`;
|
|
26
|
+
await fs.ensureDir(distDirectory);
|
|
26
27
|
await fs.writeFile(configHelperFilePath, helperCode);
|
|
27
28
|
await bundle(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
|
|
28
29
|
getOutputFile,
|
|
@@ -2,10 +2,10 @@ import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
|
|
|
2
2
|
export const printInstructions = async (hookRunners, appContext, config) => {
|
|
3
3
|
let message = prettyInstructions(appContext, config);
|
|
4
4
|
const {
|
|
5
|
-
|
|
5
|
+
apiOnly
|
|
6
6
|
} = appContext;
|
|
7
7
|
|
|
8
|
-
if (isDev() &&
|
|
8
|
+
if (isDev() && !apiOnly) {
|
|
9
9
|
message += `\n${chalk.cyanBright([`Note that the development build is not optimized.`, `To create a production build, execute build command.`].join('\n'))}`;
|
|
10
10
|
} // call beforePrintInstructions hook.
|
|
11
11
|
|
|
@@ -32,17 +32,24 @@ const build = async (api, options) => {
|
|
|
32
32
|
const appContext = api.useAppContext();
|
|
33
33
|
const hookRunners = api.useHookRunners();
|
|
34
34
|
const {
|
|
35
|
-
|
|
35
|
+
apiOnly
|
|
36
36
|
} = appContext;
|
|
37
37
|
|
|
38
|
-
if (
|
|
38
|
+
if (apiOnly) {
|
|
39
39
|
const {
|
|
40
|
-
|
|
40
|
+
appDirectory,
|
|
41
|
+
distDirectory,
|
|
42
|
+
serverConfigFile
|
|
41
43
|
} = appContext;
|
|
42
44
|
await (0, _utils.emptyDir)(distDirectory);
|
|
43
45
|
await hookRunners.beforeBuild({
|
|
44
46
|
webpackConfigs: []
|
|
45
47
|
});
|
|
48
|
+
await (0, _config.buildServerConfig)({
|
|
49
|
+
appDirectory,
|
|
50
|
+
distDirectory,
|
|
51
|
+
configFile: serverConfigFile
|
|
52
|
+
});
|
|
46
53
|
await (0, _routes.generateRoutes)(appContext);
|
|
47
54
|
await hookRunners.afterBuild();
|
|
48
55
|
return;
|
|
@@ -37,7 +37,7 @@ const dev = async (api, options) => {
|
|
|
37
37
|
appDirectory,
|
|
38
38
|
distDirectory,
|
|
39
39
|
port,
|
|
40
|
-
|
|
40
|
+
apiOnly,
|
|
41
41
|
entrypoints,
|
|
42
42
|
serverConfigFile
|
|
43
43
|
} = appContext;
|
|
@@ -62,7 +62,7 @@ const dev = async (api, options) => {
|
|
|
62
62
|
await hookRunners.beforeDev();
|
|
63
63
|
let compiler = null;
|
|
64
64
|
|
|
65
|
-
if (
|
|
65
|
+
if (!apiOnly) {
|
|
66
66
|
const {
|
|
67
67
|
getWebpackConfig,
|
|
68
68
|
WebpackConfigTarget
|
|
@@ -106,13 +106,12 @@ const dev = async (api, options) => {
|
|
|
106
106
|
throw err;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
if (
|
|
110
|
-
(0,
|
|
111
|
-
|
|
112
|
-
_utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
113
|
-
} else {
|
|
114
|
-
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
|
109
|
+
if (apiOnly) {
|
|
110
|
+
return (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
|
115
111
|
}
|
|
112
|
+
|
|
113
|
+
(0, _utils.clearConsole)();
|
|
114
|
+
return _utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
116
115
|
});
|
|
117
116
|
};
|
|
118
117
|
|
|
@@ -25,11 +25,13 @@ const start = async api => {
|
|
|
25
25
|
|
|
26
26
|
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
27
27
|
|
|
28
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory);
|
|
28
29
|
const app = await (0, _prodServer.default)({
|
|
29
30
|
pwd: appDirectory,
|
|
30
31
|
config: userConfig,
|
|
31
32
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
|
|
32
|
-
serverConfigFile
|
|
33
|
+
serverConfigFile,
|
|
34
|
+
apiOnly
|
|
33
35
|
});
|
|
34
36
|
app.listen(port, async err => {
|
|
35
37
|
if (err) {
|
package/dist/js/node/index.js
CHANGED
|
@@ -61,7 +61,7 @@ var _default = () => ({
|
|
|
61
61
|
commands({
|
|
62
62
|
program
|
|
63
63
|
}) {
|
|
64
|
-
program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.dev.config)).option('-e --entry [entry...]', _locale.i18n.t(_locale.localeKeys.command.dev.entry)).action(async options => {
|
|
64
|
+
program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.dev.config)).option('-e --entry [entry...]', _locale.i18n.t(_locale.localeKeys.command.dev.entry)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).action(async options => {
|
|
65
65
|
await (0, _dev.dev)(api, options);
|
|
66
66
|
});
|
|
67
67
|
program.command('build').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.build.describe)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.build.analyze)).action(async options => {
|
|
@@ -73,7 +73,7 @@ var _default = () => ({
|
|
|
73
73
|
|
|
74
74
|
process.exit(0);
|
|
75
75
|
});
|
|
76
|
-
program.command('start').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.start.describe)).action(async () => {
|
|
76
|
+
program.command('start').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.start.describe)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).action(async () => {
|
|
77
77
|
await (0, _start.start)(api);
|
|
78
78
|
});
|
|
79
79
|
program.command('deploy').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async options => {
|
|
@@ -36,10 +36,11 @@ const buildServerConfig = async ({
|
|
|
36
36
|
const getOutputFile = filepath => path.resolve(distDirectory, `${filepath.replace(new RegExp(_utils.CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
|
|
37
37
|
|
|
38
38
|
if (configFilePath) {
|
|
39
|
-
const configHelperFilePath = path.join(distDirectory, './config-helper.js');
|
|
39
|
+
const configHelperFilePath = path.normalize(path.join(distDirectory, './config-helper.js'));
|
|
40
40
|
const helperCode = `
|
|
41
41
|
export const defineConfig = (config) => config;
|
|
42
42
|
`;
|
|
43
|
+
await _utils.fs.ensureDir(distDirectory);
|
|
43
44
|
await _utils.fs.writeFile(configHelperFilePath, helperCode);
|
|
44
45
|
await (0, _nodeBundleRequire.bundle)(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
|
|
45
46
|
getOutputFile,
|
|
@@ -10,10 +10,10 @@ var _utils = require("@modern-js/utils");
|
|
|
10
10
|
const printInstructions = async (hookRunners, appContext, config) => {
|
|
11
11
|
let message = (0, _utils.prettyInstructions)(appContext, config);
|
|
12
12
|
const {
|
|
13
|
-
|
|
13
|
+
apiOnly
|
|
14
14
|
} = appContext;
|
|
15
15
|
|
|
16
|
-
if ((0, _utils.isDev)() &&
|
|
16
|
+
if ((0, _utils.isDev)() && !apiOnly) {
|
|
17
17
|
message += `\n${_utils.chalk.cyanBright([`Note that the development build is not optimized.`, `To create a production build, execute build command.`].join('\n'))}`;
|
|
18
18
|
} // call beforePrintInstructions hook.
|
|
19
19
|
|
|
@@ -6,6 +6,7 @@ declare const localeKeys: {
|
|
|
6
6
|
describe: string;
|
|
7
7
|
config: string;
|
|
8
8
|
entry: string;
|
|
9
|
+
apiOnly: string;
|
|
9
10
|
};
|
|
10
11
|
build: {
|
|
11
12
|
describe: string;
|
|
@@ -31,6 +32,7 @@ declare const localeKeys: {
|
|
|
31
32
|
describe: string;
|
|
32
33
|
config: string;
|
|
33
34
|
entry: string;
|
|
35
|
+
apiOnly: string;
|
|
34
36
|
};
|
|
35
37
|
build: {
|
|
36
38
|
describe: string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.6.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -57,24 +57,24 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@babel/runtime": "^7",
|
|
60
|
-
"@modern-js/core": "^1.
|
|
61
|
-
"@modern-js/i18n-cli-language-detector": "^1.2.
|
|
62
|
-
"@modern-js/new-action": "^1.3.
|
|
63
|
-
"@modern-js/node-bundle-require": "^1.3.
|
|
64
|
-
"@modern-js/plugin": "^1.3.
|
|
65
|
-
"@modern-js/plugin-analyze": "^1.
|
|
66
|
-
"@modern-js/plugin-fast-refresh": "^1.2.
|
|
67
|
-
"@modern-js/plugin-i18n": "^1.2.
|
|
68
|
-
"@modern-js/prod-server": "^1.1.
|
|
69
|
-
"@modern-js/server": "^1.4.
|
|
70
|
-
"@modern-js/types": "^1.
|
|
71
|
-
"@modern-js/utils": "^1.
|
|
72
|
-
"@modern-js/webpack": "^1.5.
|
|
60
|
+
"@modern-js/core": "^1.8.0",
|
|
61
|
+
"@modern-js/i18n-cli-language-detector": "^1.2.2",
|
|
62
|
+
"@modern-js/new-action": "^1.3.6",
|
|
63
|
+
"@modern-js/node-bundle-require": "^1.3.1",
|
|
64
|
+
"@modern-js/plugin": "^1.3.3",
|
|
65
|
+
"@modern-js/plugin-analyze": "^1.4.0",
|
|
66
|
+
"@modern-js/plugin-fast-refresh": "^1.2.4",
|
|
67
|
+
"@modern-js/plugin-i18n": "^1.2.4",
|
|
68
|
+
"@modern-js/prod-server": "^1.1.1",
|
|
69
|
+
"@modern-js/server": "^1.4.10",
|
|
70
|
+
"@modern-js/types": "^1.5.0",
|
|
71
|
+
"@modern-js/utils": "^1.5.0",
|
|
72
|
+
"@modern-js/webpack": "^1.5.6",
|
|
73
73
|
"inquirer": "^8.2.0",
|
|
74
74
|
"webpack": "^5.71.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@modern-js/server-core": "^1.3.
|
|
77
|
+
"@modern-js/server-core": "^1.3.1",
|
|
78
78
|
"@scripts/build": "0.0.0",
|
|
79
79
|
"@scripts/jest-config": "0.0.0",
|
|
80
80
|
"@types/inquirer": "^8.2.0",
|
package/tests/.eslintrc.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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,42 +0,0 @@
|
|
|
1
|
-
import { manager } from '@modern-js/core';
|
|
2
|
-
import { build } from '../../src/commands/build';
|
|
3
|
-
|
|
4
|
-
const mockGenerateRoutes = jest.fn();
|
|
5
|
-
|
|
6
|
-
jest.mock('../../src/utils/routes', () => ({
|
|
7
|
-
__esModule: true,
|
|
8
|
-
generateRoutes: () => mockGenerateRoutes(),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
describe('command build', () => {
|
|
12
|
-
afterAll(() => {
|
|
13
|
-
jest.resetAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('existSrc is false', async () => {
|
|
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();
|
|
41
|
-
});
|
|
42
|
-
});
|
package/tests/index.test.ts
DELETED
package/tests/routes.test.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { fs } from '@modern-js/utils';
|
|
2
|
-
import { generateRoutes } from '../src/utils/routes';
|
|
3
|
-
|
|
4
|
-
jest.mock('@modern-js/utils', () => {
|
|
5
|
-
const originalModule = jest.requireActual('@modern-js/utils');
|
|
6
|
-
return {
|
|
7
|
-
__esModule: true,
|
|
8
|
-
...originalModule,
|
|
9
|
-
fs: {
|
|
10
|
-
outputFile: jest.fn((filename: string, output: string) => ({
|
|
11
|
-
filename,
|
|
12
|
-
output,
|
|
13
|
-
})),
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('routes', () => {
|
|
19
|
-
test('generateRoutes', async () => {
|
|
20
|
-
const mockAppContext = {
|
|
21
|
-
serverRoutes: [],
|
|
22
|
-
distDirectory: './dist',
|
|
23
|
-
};
|
|
24
|
-
await generateRoutes(mockAppContext as any);
|
|
25
|
-
expect(fs.outputFile).toHaveBeenCalledTimes(1);
|
|
26
|
-
});
|
|
27
|
-
});
|
package/tests/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@modern-js/tsconfig/base",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"jsx": "preserve",
|
|
6
|
-
"baseUrl": "./",
|
|
7
|
-
"outDir": "./out",
|
|
8
|
-
"emitDeclarationOnly": true,
|
|
9
|
-
"isolatedModules": true,
|
|
10
|
-
"paths": {},
|
|
11
|
-
"types": ["node", "jest"]
|
|
12
|
-
}
|
|
13
|
-
}
|
package/tests/utils.test.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import inquirer from 'inquirer';
|
|
2
|
-
import { Server } from '@modern-js/server';
|
|
3
|
-
import {
|
|
4
|
-
closeServer,
|
|
5
|
-
createServer,
|
|
6
|
-
getServer,
|
|
7
|
-
} from '../src/utils/createServer';
|
|
8
|
-
import { getSpecifiedEntries } from '../src/utils/getSpecifiedEntries';
|
|
9
|
-
import { safeReplacer } from '../src/utils/config';
|
|
10
|
-
|
|
11
|
-
describe('test app-tools utils', () => {
|
|
12
|
-
it('should return all entryNames correctly', async () => {
|
|
13
|
-
const checked = await getSpecifiedEntries(false, [
|
|
14
|
-
{ entryName: 'a' },
|
|
15
|
-
{ entryName: 'b' },
|
|
16
|
-
] as any);
|
|
17
|
-
|
|
18
|
-
expect(checked).toEqual(['a', 'b']);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should return spec entry', async () => {
|
|
22
|
-
const checked = await getSpecifiedEntries(['a'], [
|
|
23
|
-
{ entryName: 'a' },
|
|
24
|
-
{ entryName: 'b' },
|
|
25
|
-
] as any);
|
|
26
|
-
|
|
27
|
-
expect(checked).toEqual(['a']);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should return select entry', async () => {
|
|
31
|
-
inquirer.prompt = jest.fn().mockResolvedValue({ selected: ['b'] }) as any;
|
|
32
|
-
const checked = await getSpecifiedEntries(true, [
|
|
33
|
-
{ entryName: 'a' },
|
|
34
|
-
{ entryName: 'b' },
|
|
35
|
-
] as any);
|
|
36
|
-
|
|
37
|
-
expect(checked).toEqual(['b']);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should get error if entry not allow', resolve => {
|
|
41
|
-
getSpecifiedEntries(['c'], [
|
|
42
|
-
{ entryName: 'a' },
|
|
43
|
-
{ entryName: 'b' },
|
|
44
|
-
] as any).catch(e => {
|
|
45
|
-
expect((e as Error).message).toMatch('can not found entry c');
|
|
46
|
-
resolve();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should create and close server correctly', async () => {
|
|
51
|
-
const app = await createServer({
|
|
52
|
-
dev: false,
|
|
53
|
-
pwd: '.',
|
|
54
|
-
config: {
|
|
55
|
-
output: {
|
|
56
|
-
path: 'dist',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
} as any);
|
|
60
|
-
|
|
61
|
-
expect(app instanceof Server).toBe(true);
|
|
62
|
-
expect(getServer()).toBe(app);
|
|
63
|
-
|
|
64
|
-
await closeServer();
|
|
65
|
-
expect(getServer()).toBeNull();
|
|
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
|
-
});
|
|
112
|
-
});
|