@modern-js/app-tools 1.4.0 → 1.4.1
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/commands/dev.js +10 -3
- package/dist/js/modern/index.js +4 -2
- package/dist/js/modern/locale/en.js +2 -1
- package/dist/js/modern/locale/zh.js +2 -1
- package/dist/js/modern/utils/createServer.js +8 -1
- package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/commands/dev.js +12 -2
- package/dist/js/node/index.js +5 -2
- package/dist/js/node/locale/en.js +2 -1
- package/dist/js/node/locale/zh.js +2 -1
- package/dist/js/node/utils/createServer.js +15 -2
- package/dist/js/node/utils/getSpecifiedEntries.js +48 -0
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/commands/dev.d.ts +2 -1
- 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/createServer.d.ts +2 -0
- package/dist/types/utils/getSpecifiedEntries.d.ts +2 -0
- package/dist/types/utils/types.d.ts +3 -0
- package/lib/types.d.ts +0 -10
- package/package.json +11 -10
- package/tests/utils.test.ts +67 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 78279953: compiler entry bug fix and dev build console
|
|
8
|
+
- c78400c7: fix: remove stylus support
|
|
9
|
+
- 4d72edea: support dev compiler by entry
|
|
10
|
+
- Updated dependencies [75f4eeb8]
|
|
11
|
+
- Updated dependencies [b7a9eeba]
|
|
12
|
+
- Updated dependencies [2cfc4235]
|
|
13
|
+
- Updated dependencies [8d55e234]
|
|
14
|
+
- Updated dependencies [53aca274]
|
|
15
|
+
- Updated dependencies [78279953]
|
|
16
|
+
- Updated dependencies [e116ace5]
|
|
17
|
+
- Updated dependencies [4d72edea]
|
|
18
|
+
- @modern-js/webpack@1.3.1
|
|
19
|
+
- @modern-js/plugin-analyze@1.3.1
|
|
20
|
+
- @modern-js/server@1.4.1
|
|
21
|
+
- @modern-js/core@1.4.1
|
|
22
|
+
- @modern-js/types@1.3.1
|
|
23
|
+
- @modern-js/utils@1.3.1
|
|
24
|
+
|
|
3
25
|
## 1.4.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
|
@@ -6,12 +6,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
|
8
8
|
import { fs, logger, HMR_SOCK_PATH, clearConsole, chalk, isSSR } from '@modern-js/utils';
|
|
9
|
-
import { useAppContext, useResolvedConfigContext, mountHook } from '@modern-js/core';
|
|
9
|
+
import { useAppContext, useResolvedConfigContext, mountHook, AppContext } from '@modern-js/core';
|
|
10
10
|
import { createCompiler } from "../utils/createCompiler";
|
|
11
11
|
import { createServer } from "../utils/createServer";
|
|
12
12
|
import { generateRoutes } from "../utils/routes";
|
|
13
13
|
import { printInstructions } from "../utils/printInstructions";
|
|
14
|
-
|
|
14
|
+
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
15
|
+
export const dev = async options => {
|
|
15
16
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
16
17
|
const appContext = useAppContext();
|
|
17
18
|
const userConfig = useResolvedConfigContext();
|
|
@@ -21,8 +22,14 @@ export const dev = async () => {
|
|
|
21
22
|
appDirectory,
|
|
22
23
|
distDirectory,
|
|
23
24
|
port,
|
|
24
|
-
existSrc
|
|
25
|
+
existSrc,
|
|
26
|
+
entrypoints
|
|
25
27
|
} = appContext;
|
|
28
|
+
const checkedEntries = await getSpecifiedEntries(options.entry || false, entrypoints);
|
|
29
|
+
AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
30
|
+
checkedEntries
|
|
31
|
+
}));
|
|
32
|
+
appContext.checkedEntries = checkedEntries;
|
|
26
33
|
fs.emptyDirSync(distDirectory);
|
|
27
34
|
await mountHook().beforeDev();
|
|
28
35
|
let compiler = null;
|
package/dist/js/modern/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { i18n, localeKeys } from "./locale";
|
|
|
12
12
|
import { getLocaleLanguage } from "./utils/language";
|
|
13
13
|
import { start } from "./commands/start";
|
|
14
14
|
import { dev } from "./commands/dev";
|
|
15
|
+
import { closeServer } from "./utils/createServer";
|
|
15
16
|
export { defineConfig }; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
16
17
|
|
|
17
18
|
usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
@@ -25,8 +26,8 @@ export default createPlugin(() => {
|
|
|
25
26
|
commands({
|
|
26
27
|
program
|
|
27
28
|
}) {
|
|
28
|
-
program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).
|
|
29
|
-
await dev();
|
|
29
|
+
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 => {
|
|
30
|
+
await dev(options);
|
|
30
31
|
});
|
|
31
32
|
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('--analyze', i18n.t(localeKeys.command.build.analyze)).action(async options => {
|
|
32
33
|
const {
|
|
@@ -77,6 +78,7 @@ export default createPlugin(() => {
|
|
|
77
78
|
const absolutePath = path.resolve(appDirectory, filename);
|
|
78
79
|
|
|
79
80
|
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
81
|
+
await closeServer();
|
|
80
82
|
await cli.restart();
|
|
81
83
|
}
|
|
82
84
|
},
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Server } from '@modern-js/server';
|
|
2
|
-
let server;
|
|
2
|
+
let server = null;
|
|
3
|
+
export const getServer = () => server;
|
|
4
|
+
export const closeServer = async () => {
|
|
5
|
+
if (server) {
|
|
6
|
+
await server.close();
|
|
7
|
+
server = null;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
3
10
|
export const createServer = async options => {
|
|
4
11
|
if (server) {
|
|
5
12
|
await server.close();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
export const getSpecifiedEntries = async (entry, entrypoints) => {
|
|
3
|
+
const entryNames = entrypoints.map(e => e.entryName);
|
|
4
|
+
|
|
5
|
+
if (!entry) {
|
|
6
|
+
return entryNames;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (typeof entry === 'boolean') {
|
|
10
|
+
const {
|
|
11
|
+
selected
|
|
12
|
+
} = await inquirer.prompt([{
|
|
13
|
+
type: 'checkbox',
|
|
14
|
+
name: 'selected',
|
|
15
|
+
choices: entryNames,
|
|
16
|
+
message: '请选择需要构建的入口',
|
|
17
|
+
|
|
18
|
+
validate(answer) {
|
|
19
|
+
if (answer.length < 1) {
|
|
20
|
+
return 'You must choose at least one topping.';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}]);
|
|
27
|
+
return selected;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
entry.forEach(name => {
|
|
31
|
+
if (!entryNames.includes(name)) {
|
|
32
|
+
throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return entry;
|
|
36
|
+
};
|
|
File without changes
|
|
@@ -19,13 +19,15 @@ var _routes = require("../utils/routes");
|
|
|
19
19
|
|
|
20
20
|
var _printInstructions = require("../utils/printInstructions");
|
|
21
21
|
|
|
22
|
+
var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
|
|
23
|
+
|
|
22
24
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
25
|
|
|
24
26
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
27
|
|
|
26
28
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
29
|
|
|
28
|
-
const dev = async
|
|
30
|
+
const dev = async options => {
|
|
29
31
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
30
32
|
const appContext = (0, _core.useAppContext)();
|
|
31
33
|
const userConfig = (0, _core.useResolvedConfigContext)();
|
|
@@ -35,8 +37,16 @@ const dev = async () => {
|
|
|
35
37
|
appDirectory,
|
|
36
38
|
distDirectory,
|
|
37
39
|
port,
|
|
38
|
-
existSrc
|
|
40
|
+
existSrc,
|
|
41
|
+
entrypoints
|
|
39
42
|
} = appContext;
|
|
43
|
+
const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
|
|
44
|
+
|
|
45
|
+
_core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
46
|
+
checkedEntries
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
appContext.checkedEntries = checkedEntries;
|
|
40
50
|
|
|
41
51
|
_utils.fs.emptyDirSync(distDirectory);
|
|
42
52
|
|
package/dist/js/node/index.js
CHANGED
|
@@ -27,6 +27,8 @@ var _start = require("./commands/start");
|
|
|
27
27
|
|
|
28
28
|
var _dev = require("./commands/dev");
|
|
29
29
|
|
|
30
|
+
var _createServer = require("./utils/createServer");
|
|
31
|
+
|
|
30
32
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
33
|
|
|
32
34
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -52,8 +54,8 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
52
54
|
commands({
|
|
53
55
|
program
|
|
54
56
|
}) {
|
|
55
|
-
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)).
|
|
56
|
-
await (0, _dev.dev)();
|
|
57
|
+
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 => {
|
|
58
|
+
await (0, _dev.dev)(options);
|
|
57
59
|
});
|
|
58
60
|
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 => {
|
|
59
61
|
const {
|
|
@@ -104,6 +106,7 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
104
106
|
const absolutePath = path.resolve(appDirectory, filename);
|
|
105
107
|
|
|
106
108
|
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
109
|
+
await (0, _createServer.closeServer)();
|
|
107
110
|
await _core.cli.restart();
|
|
108
111
|
}
|
|
109
112
|
},
|
|
@@ -3,11 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createServer = void 0;
|
|
6
|
+
exports.getServer = exports.createServer = exports.closeServer = void 0;
|
|
7
7
|
|
|
8
8
|
var _server = require("@modern-js/server");
|
|
9
9
|
|
|
10
|
-
let server;
|
|
10
|
+
let server = null;
|
|
11
|
+
|
|
12
|
+
const getServer = () => server;
|
|
13
|
+
|
|
14
|
+
exports.getServer = getServer;
|
|
15
|
+
|
|
16
|
+
const closeServer = async () => {
|
|
17
|
+
if (server) {
|
|
18
|
+
await server.close();
|
|
19
|
+
server = null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.closeServer = closeServer;
|
|
11
24
|
|
|
12
25
|
const createServer = async options => {
|
|
13
26
|
if (server) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSpecifiedEntries = void 0;
|
|
7
|
+
|
|
8
|
+
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const getSpecifiedEntries = async (entry, entrypoints) => {
|
|
13
|
+
const entryNames = entrypoints.map(e => e.entryName);
|
|
14
|
+
|
|
15
|
+
if (!entry) {
|
|
16
|
+
return entryNames;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof entry === 'boolean') {
|
|
20
|
+
const {
|
|
21
|
+
selected
|
|
22
|
+
} = await _inquirer.default.prompt([{
|
|
23
|
+
type: 'checkbox',
|
|
24
|
+
name: 'selected',
|
|
25
|
+
choices: entryNames,
|
|
26
|
+
message: '请选择需要构建的入口',
|
|
27
|
+
|
|
28
|
+
validate(answer) {
|
|
29
|
+
if (answer.length < 1) {
|
|
30
|
+
return 'You must choose at least one topping.';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}]);
|
|
37
|
+
return selected;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
entry.forEach(name => {
|
|
41
|
+
if (!entryNames.includes(name)) {
|
|
42
|
+
throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return entry;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.getSpecifiedEntries = getSpecifiedEntries;
|
|
File without changes
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { DevOptions } from '../utils/types';
|
|
2
|
+
export declare const dev: (options: DevOptions) => Promise<void>;
|
|
@@ -5,6 +5,7 @@ declare const localeKeys: {
|
|
|
5
5
|
dev: {
|
|
6
6
|
describe: string;
|
|
7
7
|
config: string;
|
|
8
|
+
entry: string;
|
|
8
9
|
};
|
|
9
10
|
build: {
|
|
10
11
|
describe: string;
|
|
@@ -29,6 +30,7 @@ declare const localeKeys: {
|
|
|
29
30
|
dev: {
|
|
30
31
|
describe: string;
|
|
31
32
|
config: string;
|
|
33
|
+
entry: string;
|
|
32
34
|
};
|
|
33
35
|
build: {
|
|
34
36
|
describe: string;
|
package/lib/types.d.ts
CHANGED
|
@@ -71,11 +71,6 @@ declare module '*.less' {
|
|
|
71
71
|
export default classes;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
declare module '*.styl' {
|
|
75
|
-
const classes: { readonly [key: string]: string };
|
|
76
|
-
export default classes;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
74
|
declare module '*.sass' {
|
|
80
75
|
const classes: { readonly [key: string]: string };
|
|
81
76
|
export default classes;
|
|
@@ -96,11 +91,6 @@ declare module '*.module.less' {
|
|
|
96
91
|
export default classes;
|
|
97
92
|
}
|
|
98
93
|
|
|
99
|
-
declare module '*.module.styl' {
|
|
100
|
-
const classes: { readonly [key: string]: string };
|
|
101
|
-
export default classes;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
94
|
declare module '*.module.sass' {
|
|
105
95
|
const classes: { readonly [key: string]: string };
|
|
106
96
|
export default classes;
|
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.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -50,17 +50,18 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@babel/runtime": "^7",
|
|
53
|
-
"@modern-js/core": "^1.4.
|
|
54
|
-
"@modern-js/types": "^1.3.
|
|
53
|
+
"@modern-js/core": "^1.4.1",
|
|
54
|
+
"@modern-js/types": "^1.3.1",
|
|
55
55
|
"@modern-js/i18n-cli-language-detector": "^1.2.1",
|
|
56
56
|
"@modern-js/new-action": "^1.3.1",
|
|
57
57
|
"@modern-js/plugin": "^1.2.1",
|
|
58
|
-
"@modern-js/plugin-analyze": "^1.3.
|
|
58
|
+
"@modern-js/plugin-analyze": "^1.3.1",
|
|
59
59
|
"@modern-js/plugin-fast-refresh": "^1.2.1",
|
|
60
60
|
"@modern-js/plugin-i18n": "^1.2.1",
|
|
61
|
-
"@modern-js/server": "^1.4.
|
|
62
|
-
"@modern-js/utils": "^1.3.
|
|
63
|
-
"@modern-js/webpack": "^1.3.
|
|
61
|
+
"@modern-js/server": "^1.4.1",
|
|
62
|
+
"@modern-js/utils": "^1.3.1",
|
|
63
|
+
"@modern-js/webpack": "^1.3.1",
|
|
64
|
+
"inquirer": "^8.2.0",
|
|
64
65
|
"webpack": "^5.54.0"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
@@ -71,7 +72,8 @@
|
|
|
71
72
|
"typescript": "^4",
|
|
72
73
|
"@scripts/build": "0.0.0",
|
|
73
74
|
"jest": "^27",
|
|
74
|
-
"@scripts/jest-config": "0.0.0"
|
|
75
|
+
"@scripts/jest-config": "0.0.0",
|
|
76
|
+
"@types/inquirer": "^8.2.0"
|
|
75
77
|
},
|
|
76
78
|
"sideEffects": false,
|
|
77
79
|
"modernConfig": {
|
|
@@ -81,8 +83,7 @@
|
|
|
81
83
|
},
|
|
82
84
|
"publishConfig": {
|
|
83
85
|
"registry": "https://registry.npmjs.org/",
|
|
84
|
-
"access": "public"
|
|
85
|
-
"types": "./dist/types/index.d.ts"
|
|
86
|
+
"access": "public"
|
|
86
87
|
},
|
|
87
88
|
"scripts": {
|
|
88
89
|
"new": "modern new",
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
|
|
10
|
+
describe('test app-tools utils', () => {
|
|
11
|
+
it('should return all entryNames correctly', async () => {
|
|
12
|
+
const checked = await getSpecifiedEntries(false, [
|
|
13
|
+
{ entryName: 'a' },
|
|
14
|
+
{ entryName: 'b' },
|
|
15
|
+
] as any);
|
|
16
|
+
|
|
17
|
+
expect(checked).toEqual(['a', 'b']);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return spec entry', async () => {
|
|
21
|
+
const checked = await getSpecifiedEntries(['a'], [
|
|
22
|
+
{ entryName: 'a' },
|
|
23
|
+
{ entryName: 'b' },
|
|
24
|
+
] as any);
|
|
25
|
+
|
|
26
|
+
expect(checked).toEqual(['a']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return select entry', async () => {
|
|
30
|
+
inquirer.prompt = jest.fn().mockResolvedValue({ selected: ['b'] }) as any;
|
|
31
|
+
const checked = await getSpecifiedEntries(true, [
|
|
32
|
+
{ entryName: 'a' },
|
|
33
|
+
{ entryName: 'b' },
|
|
34
|
+
] as any);
|
|
35
|
+
|
|
36
|
+
expect(checked).toEqual(['b']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should get error if entry not allow', resolve => {
|
|
40
|
+
getSpecifiedEntries(['c'], [
|
|
41
|
+
{ entryName: 'a' },
|
|
42
|
+
{ entryName: 'b' },
|
|
43
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
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
|
+
});
|