@modern-js/app-tools 1.4.0 → 1.4.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.
- package/CHANGELOG.md +71 -0
- package/dist/js/modern/commands/build.js +11 -5
- package/dist/js/modern/commands/dev.js +10 -3
- package/dist/js/modern/commands/start.js +1 -1
- 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/build.js +10 -6
- package/dist/js/node/commands/dev.js +12 -2
- package/dist/js/node/commands/start.js +2 -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 +4 -2
- package/dist/types/utils/getSpecifiedEntries.d.ts +2 -0
- package/dist/types/utils/types.d.ts +3 -0
- package/lib/types.d.ts +92 -10
- package/package.json +13 -11
- package/tests/commands/build.test.ts +17 -13
- package/tests/utils.test.ts +67 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4b5d4bf4: feat: add img resource's inline and url type declaration
|
|
8
|
+
- bdcf0865: fix: empty distDirectory for api service
|
|
9
|
+
- 02fb4146: support product server
|
|
10
|
+
- edc3bd3d: fix: @modern-js/core package not found
|
|
11
|
+
- Updated dependencies [969f172f]
|
|
12
|
+
- Updated dependencies [0ad75faa]
|
|
13
|
+
- Updated dependencies [4c792f68]
|
|
14
|
+
- Updated dependencies [83059b93]
|
|
15
|
+
- Updated dependencies [4b5d4bf4]
|
|
16
|
+
- Updated dependencies [0ad75faa]
|
|
17
|
+
- Updated dependencies [62f5b8c8]
|
|
18
|
+
- Updated dependencies [55e18278]
|
|
19
|
+
- Updated dependencies [4499a674]
|
|
20
|
+
- Updated dependencies [0ad75faa]
|
|
21
|
+
- Updated dependencies [02fb4146]
|
|
22
|
+
- Updated dependencies [403f5169]
|
|
23
|
+
- Updated dependencies [e37ea5b2]
|
|
24
|
+
- Updated dependencies [a7f42f48]
|
|
25
|
+
- Updated dependencies [83059b93]
|
|
26
|
+
- @modern-js/core@1.4.4
|
|
27
|
+
- @modern-js/webpack@1.4.1
|
|
28
|
+
- @modern-js/utils@1.3.3
|
|
29
|
+
- @modern-js/new-action@1.3.3
|
|
30
|
+
- @modern-js/server@1.4.4
|
|
31
|
+
- @modern-js/types@1.3.4
|
|
32
|
+
- @modern-js/prod-server@1.0.1
|
|
33
|
+
|
|
34
|
+
## 1.4.2
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- fab92861: fix: @modern-js/core phantom dep
|
|
39
|
+
- Updated dependencies [deeaa602]
|
|
40
|
+
- Updated dependencies [54786e58]
|
|
41
|
+
- Updated dependencies [6668a1bf]
|
|
42
|
+
- Updated dependencies [fab92861]
|
|
43
|
+
- Updated dependencies [3da3bf48]
|
|
44
|
+
- @modern-js/plugin-analyze@1.3.3
|
|
45
|
+
- @modern-js/server@1.4.3
|
|
46
|
+
- @modern-js/types@1.3.3
|
|
47
|
+
- @modern-js/utils@1.3.2
|
|
48
|
+
- @modern-js/webpack@1.4.0
|
|
49
|
+
- @modern-js/core@1.4.3
|
|
50
|
+
- @modern-js/new-action@1.3.2
|
|
51
|
+
|
|
52
|
+
## 1.4.1
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- 78279953: compiler entry bug fix and dev build console
|
|
57
|
+
- c78400c7: fix: remove stylus support
|
|
58
|
+
- 4d72edea: support dev compiler by entry
|
|
59
|
+
- Updated dependencies [75f4eeb8]
|
|
60
|
+
- Updated dependencies [b7a9eeba]
|
|
61
|
+
- Updated dependencies [2cfc4235]
|
|
62
|
+
- Updated dependencies [8d55e234]
|
|
63
|
+
- Updated dependencies [53aca274]
|
|
64
|
+
- Updated dependencies [78279953]
|
|
65
|
+
- Updated dependencies [e116ace5]
|
|
66
|
+
- Updated dependencies [4d72edea]
|
|
67
|
+
- @modern-js/webpack@1.3.1
|
|
68
|
+
- @modern-js/plugin-analyze@1.3.1
|
|
69
|
+
- @modern-js/server@1.4.1
|
|
70
|
+
- @modern-js/core@1.4.1
|
|
71
|
+
- @modern-js/types@1.3.1
|
|
72
|
+
- @modern-js/utils@1.3.1
|
|
73
|
+
|
|
3
74
|
## 1.4.0
|
|
4
75
|
|
|
5
76
|
### Minor Changes
|
|
@@ -7,7 +7,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
7
7
|
import { webpack } from 'webpack';
|
|
8
8
|
import { WebpackConfigTarget, getWebpackConfig } from '@modern-js/webpack';
|
|
9
9
|
import { useAppContext, useResolvedConfigContext, mountHook, ResolvedConfigContext, manager } from '@modern-js/core';
|
|
10
|
-
import {
|
|
10
|
+
import { formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle, emptyDir } from '@modern-js/utils';
|
|
11
11
|
import { generateRoutes } from "../utils/routes"; // These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
12
12
|
|
|
13
13
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
@@ -23,6 +23,10 @@ export const build = async options => {
|
|
|
23
23
|
/* eslint-enable react-hooks/rules-of-hooks */
|
|
24
24
|
|
|
25
25
|
if (!existSrc) {
|
|
26
|
+
const {
|
|
27
|
+
distDirectory
|
|
28
|
+
} = appContext;
|
|
29
|
+
await emptyDir(distDirectory);
|
|
26
30
|
await mountHook().beforeBuild({
|
|
27
31
|
webpackConfigs: []
|
|
28
32
|
});
|
|
@@ -53,7 +57,7 @@ export const build = async options => {
|
|
|
53
57
|
|
|
54
58
|
if (messages.errors.length === 0) {
|
|
55
59
|
logger.info(`File sizes after ${label} build:\n`);
|
|
56
|
-
printFileSizesAfterBuild(stats, previousFileSizes,
|
|
60
|
+
printFileSizesAfterBuild(stats, previousFileSizes, distDirectory, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
|
|
57
61
|
logger.log();
|
|
58
62
|
}
|
|
59
63
|
} // When using run or watch, call close and wait for it to finish before calling run or watch again.
|
|
@@ -87,9 +91,11 @@ export const build = async options => {
|
|
|
87
91
|
cliOptions: options
|
|
88
92
|
}));
|
|
89
93
|
});
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
const {
|
|
95
|
+
distDirectory
|
|
96
|
+
} = appContext;
|
|
97
|
+
const previousFileSizes = await measureFileSizesBeforeBuild(distDirectory);
|
|
98
|
+
await emptyDir(distDirectory);
|
|
93
99
|
const buildConfigs = [];
|
|
94
100
|
buildConfigs.push({
|
|
95
101
|
type: 'legacy',
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { logger, chalk } from '@modern-js/utils';
|
|
2
2
|
import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
3
|
-
import server from '@modern-js/server';
|
|
3
|
+
import server from '@modern-js/prod-server';
|
|
4
4
|
import { printInstructions } from "../utils/printInstructions";
|
|
5
5
|
export const start = async () => {
|
|
6
6
|
/* eslint-disable react-hooks/rules-of-hooks */
|
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
|
|
@@ -36,6 +36,10 @@ const build = async options => {
|
|
|
36
36
|
/* eslint-enable react-hooks/rules-of-hooks */
|
|
37
37
|
|
|
38
38
|
if (!existSrc) {
|
|
39
|
+
const {
|
|
40
|
+
distDirectory
|
|
41
|
+
} = appContext;
|
|
42
|
+
await (0, _utils.emptyDir)(distDirectory);
|
|
39
43
|
await (0, _core.mountHook)().beforeBuild({
|
|
40
44
|
webpackConfigs: []
|
|
41
45
|
});
|
|
@@ -68,7 +72,7 @@ const build = async options => {
|
|
|
68
72
|
if (messages.errors.length === 0) {
|
|
69
73
|
_utils.logger.info(`File sizes after ${label} build:\n`);
|
|
70
74
|
|
|
71
|
-
(0, _utils.printFileSizesAfterBuild)(stats, previousFileSizes,
|
|
75
|
+
(0, _utils.printFileSizesAfterBuild)(stats, previousFileSizes, distDirectory, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
|
|
72
76
|
|
|
73
77
|
_utils.logger.log();
|
|
74
78
|
}
|
|
@@ -104,11 +108,11 @@ const build = async options => {
|
|
|
104
108
|
}));
|
|
105
109
|
});
|
|
106
110
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
_utils.
|
|
111
|
-
|
|
111
|
+
const {
|
|
112
|
+
distDirectory
|
|
113
|
+
} = appContext;
|
|
114
|
+
const previousFileSizes = await (0, _utils.measureFileSizesBeforeBuild)(distDirectory);
|
|
115
|
+
await (0, _utils.emptyDir)(distDirectory);
|
|
112
116
|
const buildConfigs = [];
|
|
113
117
|
buildConfigs.push({
|
|
114
118
|
type: 'legacy',
|
|
@@ -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
|
|
|
@@ -9,7 +9,7 @@ var _utils = require("@modern-js/utils");
|
|
|
9
9
|
|
|
10
10
|
var _core = require("@modern-js/core");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
|
13
13
|
|
|
14
14
|
var _printInstructions = require("../utils/printInstructions");
|
|
15
15
|
|
|
@@ -28,7 +28,7 @@ const start = async () => {
|
|
|
28
28
|
|
|
29
29
|
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
30
30
|
|
|
31
|
-
const app = await (0,
|
|
31
|
+
const app = await (0, _prodServer.default)({
|
|
32
32
|
pwd: appDirectory,
|
|
33
33
|
config: userConfig,
|
|
34
34
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
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;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { Server,
|
|
2
|
-
export declare const
|
|
1
|
+
import { Server, ModernDevServerOptions } from '@modern-js/server';
|
|
2
|
+
export declare const getServer: () => Server | null;
|
|
3
|
+
export declare const closeServer: () => Promise<void>;
|
|
4
|
+
export declare const createServer: (options: ModernDevServerOptions) => Promise<Server>;
|
package/lib/types.d.ts
CHANGED
|
@@ -56,6 +56,98 @@ declare module '*.svg' {
|
|
|
56
56
|
export default src;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
declare module '*.bmp?inline' {
|
|
60
|
+
const src: string;
|
|
61
|
+
export default src;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare module '*.gif?inline' {
|
|
65
|
+
const src: string;
|
|
66
|
+
export default src;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare module '*.jpg?inline' {
|
|
70
|
+
const src: string;
|
|
71
|
+
export default src;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare module '*.jpeg?inline' {
|
|
75
|
+
const src: string;
|
|
76
|
+
export default src;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare module '*.png?inline' {
|
|
80
|
+
const src: string;
|
|
81
|
+
export default src;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare module '*.ico?inline' {
|
|
85
|
+
const src: string;
|
|
86
|
+
export default src;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare module '*.webp?inline' {
|
|
90
|
+
const src: string;
|
|
91
|
+
export default src;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
declare module '*.svg?inline' {
|
|
95
|
+
import * as React from 'react';
|
|
96
|
+
|
|
97
|
+
export const ReactComponent: React.FunctionComponent<
|
|
98
|
+
React.SVGProps<SVGSVGElement>
|
|
99
|
+
>;
|
|
100
|
+
|
|
101
|
+
const src: string;
|
|
102
|
+
export default src;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare module '*.bmp?url' {
|
|
106
|
+
const src: string;
|
|
107
|
+
export default src;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare module '*.gif?url' {
|
|
111
|
+
const src: string;
|
|
112
|
+
export default src;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare module '*.jpg?url' {
|
|
116
|
+
const src: string;
|
|
117
|
+
export default src;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
declare module '*.jpeg?url' {
|
|
121
|
+
const src: string;
|
|
122
|
+
export default src;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare module '*.png?url' {
|
|
126
|
+
const src: string;
|
|
127
|
+
export default src;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare module '*.ico?url' {
|
|
131
|
+
const src: string;
|
|
132
|
+
export default src;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare module '*.webp?url' {
|
|
136
|
+
const src: string;
|
|
137
|
+
export default src;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
declare module '*.svg?url' {
|
|
141
|
+
import * as React from 'react';
|
|
142
|
+
|
|
143
|
+
export const ReactComponent: React.FunctionComponent<
|
|
144
|
+
React.SVGProps<SVGSVGElement>
|
|
145
|
+
>;
|
|
146
|
+
|
|
147
|
+
const src: string;
|
|
148
|
+
export default src;
|
|
149
|
+
}
|
|
150
|
+
|
|
59
151
|
declare module '*.css' {
|
|
60
152
|
const classes: { readonly [key: string]: string };
|
|
61
153
|
export default classes;
|
|
@@ -71,11 +163,6 @@ declare module '*.less' {
|
|
|
71
163
|
export default classes;
|
|
72
164
|
}
|
|
73
165
|
|
|
74
|
-
declare module '*.styl' {
|
|
75
|
-
const classes: { readonly [key: string]: string };
|
|
76
|
-
export default classes;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
166
|
declare module '*.sass' {
|
|
80
167
|
const classes: { readonly [key: string]: string };
|
|
81
168
|
export default classes;
|
|
@@ -96,11 +183,6 @@ declare module '*.module.less' {
|
|
|
96
183
|
export default classes;
|
|
97
184
|
}
|
|
98
185
|
|
|
99
|
-
declare module '*.module.styl' {
|
|
100
|
-
const classes: { readonly [key: string]: string };
|
|
101
|
-
export default classes;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
186
|
declare module '*.module.sass' {
|
|
105
187
|
const classes: { readonly [key: string]: string };
|
|
106
188
|
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.3",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -49,18 +49,20 @@
|
|
|
49
49
|
"modern": "./bin/modern.js"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@modern-js/core": "^1.4.4",
|
|
52
53
|
"@babel/runtime": "^7",
|
|
53
|
-
"@modern-js/
|
|
54
|
-
"@modern-js/types": "^1.3.0",
|
|
54
|
+
"@modern-js/types": "^1.3.4",
|
|
55
55
|
"@modern-js/i18n-cli-language-detector": "^1.2.1",
|
|
56
|
-
"@modern-js/new-action": "^1.3.
|
|
56
|
+
"@modern-js/new-action": "^1.3.3",
|
|
57
57
|
"@modern-js/plugin": "^1.2.1",
|
|
58
|
-
"@modern-js/plugin-analyze": "^1.3.
|
|
58
|
+
"@modern-js/plugin-analyze": "^1.3.3",
|
|
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/
|
|
63
|
-
"@modern-js/
|
|
61
|
+
"@modern-js/server": "^1.4.4",
|
|
62
|
+
"@modern-js/prod-server": "^1.0.1",
|
|
63
|
+
"@modern-js/utils": "^1.3.3",
|
|
64
|
+
"@modern-js/webpack": "^1.4.1",
|
|
65
|
+
"inquirer": "^8.2.0",
|
|
64
66
|
"webpack": "^5.54.0"
|
|
65
67
|
},
|
|
66
68
|
"devDependencies": {
|
|
@@ -71,7 +73,8 @@
|
|
|
71
73
|
"typescript": "^4",
|
|
72
74
|
"@scripts/build": "0.0.0",
|
|
73
75
|
"jest": "^27",
|
|
74
|
-
"@scripts/jest-config": "0.0.0"
|
|
76
|
+
"@scripts/jest-config": "0.0.0",
|
|
77
|
+
"@types/inquirer": "^8.2.0"
|
|
75
78
|
},
|
|
76
79
|
"sideEffects": false,
|
|
77
80
|
"modernConfig": {
|
|
@@ -81,8 +84,7 @@
|
|
|
81
84
|
},
|
|
82
85
|
"publishConfig": {
|
|
83
86
|
"registry": "https://registry.npmjs.org/",
|
|
84
|
-
"access": "public"
|
|
85
|
-
"types": "./dist/types/index.d.ts"
|
|
87
|
+
"access": "public"
|
|
86
88
|
},
|
|
87
89
|
"scripts": {
|
|
88
90
|
"new": "modern new",
|
|
@@ -4,19 +4,23 @@ const mockBeforeBuild = jest.fn();
|
|
|
4
4
|
const mockAfterBuild = jest.fn();
|
|
5
5
|
const mockGenerateRoutes = jest.fn();
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
});
|
|
20
24
|
|
|
21
25
|
jest.mock('../../src/utils/routes', () => ({
|
|
22
26
|
__esModule: true,
|
|
@@ -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
|
+
});
|