@modern-js/app-tools 1.3.2 → 1.4.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 +29 -0
- package/dist/js/modern/commands/build.js +24 -8
- package/dist/js/modern/commands/dev.js +23 -10
- package/dist/js/modern/index.js +25 -3
- package/dist/js/modern/utils/printInstructions.js +4 -1
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/node/commands/build.js +24 -7
- package/dist/js/node/commands/dev.js +25 -10
- package/dist/js/node/index.js +26 -2
- package/dist/js/node/utils/printInstructions.js +4 -1
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/routes.d.ts +3 -0
- package/package.json +7 -7
- package/tests/commands/build.test.ts +37 -0
- package/tests/commands/dev.test.ts +7 -0
- package/tests/routes.test.ts +27 -0
- package/tests/tsconfig.json +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ec4dbffb: feat: support as a pure api service
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- bd819a8d: fix: file route changed not trigger hot reload
|
|
12
|
+
- 62cd58c6: fix: create route.json failure
|
|
13
|
+
- d099e5c5: fix error when modify modern.config.js
|
|
14
|
+
- Updated dependencies [816fd721]
|
|
15
|
+
- Updated dependencies [d9cc5ea9]
|
|
16
|
+
- Updated dependencies [ddf0c3a6]
|
|
17
|
+
- Updated dependencies [bfbea9a7]
|
|
18
|
+
- Updated dependencies [bd819a8d]
|
|
19
|
+
- Updated dependencies [ec4dbffb]
|
|
20
|
+
- Updated dependencies [d099e5c5]
|
|
21
|
+
- Updated dependencies [bada2879]
|
|
22
|
+
- Updated dependencies [24f616ca]
|
|
23
|
+
- Updated dependencies [bd819a8d]
|
|
24
|
+
- Updated dependencies [272cab15]
|
|
25
|
+
- @modern-js/server@1.4.0
|
|
26
|
+
- @modern-js/types@1.3.0
|
|
27
|
+
- @modern-js/core@1.4.0
|
|
28
|
+
- @modern-js/plugin-analyze@1.3.0
|
|
29
|
+
- @modern-js/webpack@1.3.0
|
|
30
|
+
- @modern-js/utils@1.3.0
|
|
31
|
+
|
|
3
32
|
## 1.3.2
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -7,11 +7,30 @@ 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 { fs, formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle } from '@modern-js/utils';
|
|
10
|
+
import { fs, formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle } from '@modern-js/utils';
|
|
11
|
+
import { generateRoutes } from "../utils/routes"; // These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
11
12
|
|
|
12
13
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
13
14
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
15
|
+
// eslint-disable-next-line max-statements
|
|
14
16
|
export const build = async options => {
|
|
17
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
18
|
+
const resolvedConfig = useResolvedConfigContext();
|
|
19
|
+
const appContext = useAppContext();
|
|
20
|
+
const {
|
|
21
|
+
existSrc
|
|
22
|
+
} = appContext;
|
|
23
|
+
/* eslint-enable react-hooks/rules-of-hooks */
|
|
24
|
+
|
|
25
|
+
if (!existSrc) {
|
|
26
|
+
await mountHook().beforeBuild({
|
|
27
|
+
webpackConfigs: []
|
|
28
|
+
});
|
|
29
|
+
await generateRoutes(appContext);
|
|
30
|
+
await mountHook().afterBuild();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
15
34
|
const webpackBuild = async (webpackConfig, type) => {
|
|
16
35
|
const compiler = webpack(webpackConfig);
|
|
17
36
|
return new Promise((resolve, reject) => {
|
|
@@ -62,12 +81,6 @@ export const build = async options => {
|
|
|
62
81
|
});
|
|
63
82
|
});
|
|
64
83
|
};
|
|
65
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const resolvedConfig = useResolvedConfigContext();
|
|
69
|
-
const appContext = useAppContext();
|
|
70
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
71
84
|
|
|
72
85
|
manager.run(() => {
|
|
73
86
|
ResolvedConfigContext.set(_objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
|
@@ -112,9 +125,12 @@ export const build = async options => {
|
|
|
112
125
|
try {
|
|
113
126
|
await webpackBuild(config, buildType);
|
|
114
127
|
} catch (error) {
|
|
115
|
-
printBuildError(error);
|
|
128
|
+
printBuildError(error); // eslint-disable-next-line no-process-exit
|
|
129
|
+
|
|
130
|
+
process.exit(1);
|
|
116
131
|
}
|
|
117
132
|
}
|
|
118
133
|
|
|
134
|
+
await generateRoutes(appContext);
|
|
119
135
|
await mountHook().afterBuild();
|
|
120
136
|
};
|
|
@@ -9,6 +9,8 @@ import { fs, logger, HMR_SOCK_PATH, clearConsole, chalk, isSSR } from '@modern-j
|
|
|
9
9
|
import { useAppContext, useResolvedConfigContext, mountHook } from '@modern-js/core';
|
|
10
10
|
import { createCompiler } from "../utils/createCompiler";
|
|
11
11
|
import { createServer } from "../utils/createServer";
|
|
12
|
+
import { generateRoutes } from "../utils/routes";
|
|
13
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
12
14
|
export const dev = async () => {
|
|
13
15
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
14
16
|
const appContext = useAppContext();
|
|
@@ -18,16 +20,23 @@ export const dev = async () => {
|
|
|
18
20
|
const {
|
|
19
21
|
appDirectory,
|
|
20
22
|
distDirectory,
|
|
21
|
-
port
|
|
23
|
+
port,
|
|
24
|
+
existSrc
|
|
22
25
|
} = appContext;
|
|
23
26
|
fs.emptyDirSync(distDirectory);
|
|
24
27
|
await mountHook().beforeDev();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
userConfig,
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
let compiler = null;
|
|
29
|
+
|
|
30
|
+
if (existSrc) {
|
|
31
|
+
const webpackConfigs = [isSSR(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
32
|
+
compiler = await createCompiler({
|
|
33
|
+
webpackConfigs,
|
|
34
|
+
userConfig,
|
|
35
|
+
appContext
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await generateRoutes(appContext);
|
|
31
40
|
const app = await createServer({
|
|
32
41
|
dev: _objectSpread(_objectSpread({}, {
|
|
33
42
|
client: {
|
|
@@ -50,12 +59,16 @@ export const dev = async () => {
|
|
|
50
59
|
config: userConfig,
|
|
51
60
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
52
61
|
});
|
|
53
|
-
app.listen(port, err => {
|
|
62
|
+
app.listen(port, async err => {
|
|
54
63
|
if (err) {
|
|
55
64
|
throw err;
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
if (existSrc) {
|
|
68
|
+
clearConsole();
|
|
69
|
+
logger.log(chalk.cyan(`Starting the development server...`));
|
|
70
|
+
} else {
|
|
71
|
+
await printInstructions(appContext, userConfig);
|
|
72
|
+
}
|
|
60
73
|
});
|
|
61
74
|
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -4,7 +4,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { createPlugin, defineConfig, usePlugins, cli, useAppContext } from '@modern-js/core';
|
|
9
|
+
import { cleanRequireCache } from '@modern-js/utils';
|
|
8
10
|
import { lifecycle } from "./lifecycle";
|
|
9
11
|
import { i18n, localeKeys } from "./locale";
|
|
10
12
|
import { getLocaleLanguage } from "./utils/language";
|
|
@@ -60,11 +62,31 @@ export default createPlugin(() => {
|
|
|
60
62
|
});
|
|
61
63
|
},
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
66
|
+
async fileChange(e) {
|
|
67
|
+
const {
|
|
68
|
+
filename,
|
|
69
|
+
eventType
|
|
70
|
+
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
71
|
+
|
|
72
|
+
const appContext = useAppContext();
|
|
73
|
+
const {
|
|
74
|
+
appDirectory,
|
|
75
|
+
srcDirectory
|
|
76
|
+
} = appContext;
|
|
77
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
78
|
+
|
|
79
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
80
|
+
await cli.restart();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
async beforeRestart() {
|
|
85
|
+
cleanRequireCache([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
65
86
|
}
|
|
66
87
|
|
|
67
88
|
};
|
|
68
89
|
}, {
|
|
90
|
+
name: '@modern-js/app-tools',
|
|
69
91
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill']
|
|
70
92
|
});
|
|
@@ -2,8 +2,11 @@ import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
|
|
|
2
2
|
import { mountHook } from '@modern-js/core';
|
|
3
3
|
export const printInstructions = async (appContext, config) => {
|
|
4
4
|
let message = prettyInstructions(appContext, config);
|
|
5
|
+
const {
|
|
6
|
+
existSrc
|
|
7
|
+
} = appContext;
|
|
5
8
|
|
|
6
|
-
if (isDev()) {
|
|
9
|
+
if (isDev() && existSrc) {
|
|
7
10
|
message += `\n${chalk.cyanBright([`Note that the development build is not optimized.`, `To create a production build, execute build command.`].join('\n'))}`;
|
|
8
11
|
} // call beforePrintInstructions hook.
|
|
9
12
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fs, ROUTE_SPEC_FILE } from '@modern-js/utils';
|
|
3
|
+
|
|
4
|
+
const generateRoutes = async appContext => {
|
|
5
|
+
const {
|
|
6
|
+
serverRoutes,
|
|
7
|
+
distDirectory
|
|
8
|
+
} = appContext;
|
|
9
|
+
const output = JSON.stringify({
|
|
10
|
+
routes: serverRoutes
|
|
11
|
+
}, null, 2);
|
|
12
|
+
await fs.outputFile(path.join(distDirectory, ROUTE_SPEC_FILE), output);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { generateRoutes };
|
|
@@ -13,6 +13,8 @@ var _core = require("@modern-js/core");
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@modern-js/utils");
|
|
15
15
|
|
|
16
|
+
var _routes = require("../utils/routes");
|
|
17
|
+
|
|
16
18
|
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; }
|
|
17
19
|
|
|
18
20
|
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; }
|
|
@@ -23,7 +25,25 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
23
25
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
24
26
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
25
27
|
|
|
28
|
+
// eslint-disable-next-line max-statements
|
|
26
29
|
const build = async options => {
|
|
30
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
31
|
+
const resolvedConfig = (0, _core.useResolvedConfigContext)();
|
|
32
|
+
const appContext = (0, _core.useAppContext)();
|
|
33
|
+
const {
|
|
34
|
+
existSrc
|
|
35
|
+
} = appContext;
|
|
36
|
+
/* eslint-enable react-hooks/rules-of-hooks */
|
|
37
|
+
|
|
38
|
+
if (!existSrc) {
|
|
39
|
+
await (0, _core.mountHook)().beforeBuild({
|
|
40
|
+
webpackConfigs: []
|
|
41
|
+
});
|
|
42
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
43
|
+
await (0, _core.mountHook)().afterBuild();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
const webpackBuild = async (webpackConfig, type) => {
|
|
28
48
|
const compiler = (0, _webpack.webpack)(webpackConfig);
|
|
29
49
|
return new Promise((resolve, reject) => {
|
|
@@ -77,12 +97,6 @@ const build = async options => {
|
|
|
77
97
|
});
|
|
78
98
|
});
|
|
79
99
|
};
|
|
80
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const resolvedConfig = (0, _core.useResolvedConfigContext)();
|
|
84
|
-
const appContext = (0, _core.useAppContext)();
|
|
85
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
86
100
|
|
|
87
101
|
_core.manager.run(() => {
|
|
88
102
|
_core.ResolvedConfigContext.set(_objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
|
@@ -130,10 +144,13 @@ const build = async options => {
|
|
|
130
144
|
try {
|
|
131
145
|
await webpackBuild(config, buildType);
|
|
132
146
|
} catch (error) {
|
|
133
|
-
(0, _utils.printBuildError)(error);
|
|
147
|
+
(0, _utils.printBuildError)(error); // eslint-disable-next-line no-process-exit
|
|
148
|
+
|
|
149
|
+
process.exit(1);
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
152
|
|
|
153
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
137
154
|
await (0, _core.mountHook)().afterBuild();
|
|
138
155
|
};
|
|
139
156
|
|
|
@@ -15,6 +15,10 @@ var _createCompiler = require("../utils/createCompiler");
|
|
|
15
15
|
|
|
16
16
|
var _createServer = require("../utils/createServer");
|
|
17
17
|
|
|
18
|
+
var _routes = require("../utils/routes");
|
|
19
|
+
|
|
20
|
+
var _printInstructions = require("../utils/printInstructions");
|
|
21
|
+
|
|
18
22
|
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; }
|
|
19
23
|
|
|
20
24
|
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; }
|
|
@@ -30,18 +34,25 @@ const dev = async () => {
|
|
|
30
34
|
const {
|
|
31
35
|
appDirectory,
|
|
32
36
|
distDirectory,
|
|
33
|
-
port
|
|
37
|
+
port,
|
|
38
|
+
existSrc
|
|
34
39
|
} = appContext;
|
|
35
40
|
|
|
36
41
|
_utils.fs.emptyDirSync(distDirectory);
|
|
37
42
|
|
|
38
43
|
await (0, _core.mountHook)().beforeDev();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
userConfig,
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
let compiler = null;
|
|
45
|
+
|
|
46
|
+
if (existSrc) {
|
|
47
|
+
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.NODE), (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
48
|
+
compiler = await (0, _createCompiler.createCompiler)({
|
|
49
|
+
webpackConfigs,
|
|
50
|
+
userConfig,
|
|
51
|
+
appContext
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
45
56
|
const app = await (0, _createServer.createServer)({
|
|
46
57
|
dev: _objectSpread(_objectSpread({}, {
|
|
47
58
|
client: {
|
|
@@ -64,14 +75,18 @@ const dev = async () => {
|
|
|
64
75
|
config: userConfig,
|
|
65
76
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
66
77
|
});
|
|
67
|
-
app.listen(port, err => {
|
|
78
|
+
app.listen(port, async err => {
|
|
68
79
|
if (err) {
|
|
69
80
|
throw err;
|
|
70
81
|
}
|
|
71
82
|
|
|
72
|
-
|
|
83
|
+
if (existSrc) {
|
|
84
|
+
(0, _utils.clearConsole)();
|
|
73
85
|
|
|
74
|
-
|
|
86
|
+
_utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
87
|
+
} else {
|
|
88
|
+
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
89
|
+
}
|
|
75
90
|
});
|
|
76
91
|
};
|
|
77
92
|
|
package/dist/js/node/index.js
CHANGED
|
@@ -11,8 +11,12 @@ Object.defineProperty(exports, "defineConfig", {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
var path = _interopRequireWildcard(require("path"));
|
|
15
|
+
|
|
14
16
|
var _core = require("@modern-js/core");
|
|
15
17
|
|
|
18
|
+
var _utils = require("@modern-js/utils");
|
|
19
|
+
|
|
16
20
|
var _lifecycle = require("./lifecycle");
|
|
17
21
|
|
|
18
22
|
var _locale = require("./locale");
|
|
@@ -85,12 +89,32 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
85
89
|
});
|
|
86
90
|
},
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
93
|
+
async fileChange(e) {
|
|
94
|
+
const {
|
|
95
|
+
filename,
|
|
96
|
+
eventType
|
|
97
|
+
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
98
|
+
|
|
99
|
+
const appContext = (0, _core.useAppContext)();
|
|
100
|
+
const {
|
|
101
|
+
appDirectory,
|
|
102
|
+
srcDirectory
|
|
103
|
+
} = appContext;
|
|
104
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
105
|
+
|
|
106
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
107
|
+
await _core.cli.restart();
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
async beforeRestart() {
|
|
112
|
+
(0, _utils.cleanRequireCache)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
90
113
|
}
|
|
91
114
|
|
|
92
115
|
};
|
|
93
116
|
}, {
|
|
117
|
+
name: '@modern-js/app-tools',
|
|
94
118
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill']
|
|
95
119
|
});
|
|
96
120
|
|
|
@@ -11,8 +11,11 @@ var _core = require("@modern-js/core");
|
|
|
11
11
|
|
|
12
12
|
const printInstructions = async (appContext, config) => {
|
|
13
13
|
let message = (0, _utils.prettyInstructions)(appContext, config);
|
|
14
|
+
const {
|
|
15
|
+
existSrc
|
|
16
|
+
} = appContext;
|
|
14
17
|
|
|
15
|
-
if ((0, _utils.isDev)()) {
|
|
18
|
+
if ((0, _utils.isDev)() && existSrc) {
|
|
16
19
|
message += `\n${_utils.chalk.cyanBright([`Note that the development build is not optimized.`, `To create a production build, execute build command.`].join('\n'))}`;
|
|
17
20
|
} // call beforePrintInstructions hook.
|
|
18
21
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateRoutes = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const generateRoutes = async appContext => {
|
|
15
|
+
const {
|
|
16
|
+
serverRoutes,
|
|
17
|
+
distDirectory
|
|
18
|
+
} = appContext;
|
|
19
|
+
const output = JSON.stringify({
|
|
20
|
+
routes: serverRoutes
|
|
21
|
+
}, null, 2);
|
|
22
|
+
await _utils.fs.outputFile(_path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE), output);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.generateRoutes = generateRoutes;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -14,8 +14,10 @@ declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@m
|
|
|
14
14
|
watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
15
15
|
fileChange: import("@modern-js/core").AsyncWorkflow<{
|
|
16
16
|
filename: string;
|
|
17
|
+
eventType: "add" | "unlink" | "change";
|
|
17
18
|
}, void>;
|
|
18
19
|
beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
20
|
+
beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
19
21
|
} & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
|
|
20
22
|
|
|
21
23
|
export default _default;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.4.0",
|
|
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,17 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@babel/runtime": "^7",
|
|
53
|
-
"@modern-js/core": "^1.
|
|
54
|
-
"@modern-js/types": "^1.
|
|
53
|
+
"@modern-js/core": "^1.4.0",
|
|
54
|
+
"@modern-js/types": "^1.3.0",
|
|
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.
|
|
58
|
+
"@modern-js/plugin-analyze": "^1.3.0",
|
|
59
59
|
"@modern-js/plugin-fast-refresh": "^1.2.1",
|
|
60
60
|
"@modern-js/plugin-i18n": "^1.2.1",
|
|
61
|
-
"@modern-js/server": "^1.
|
|
62
|
-
"@modern-js/utils": "^1.
|
|
63
|
-
"@modern-js/webpack": "^1.
|
|
61
|
+
"@modern-js/server": "^1.4.0",
|
|
62
|
+
"@modern-js/utils": "^1.3.0",
|
|
63
|
+
"@modern-js/webpack": "^1.3.0",
|
|
64
64
|
"webpack": "^5.54.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { build } from '../../src/commands/build';
|
|
2
|
+
|
|
3
|
+
const mockBeforeBuild = jest.fn();
|
|
4
|
+
const mockAfterBuild = jest.fn();
|
|
5
|
+
const mockGenerateRoutes = jest.fn();
|
|
6
|
+
|
|
7
|
+
jest.mock('@modern-js/core', () => ({
|
|
8
|
+
__esModule: true,
|
|
9
|
+
mountHook() {
|
|
10
|
+
return {
|
|
11
|
+
beforeBuild: mockBeforeBuild,
|
|
12
|
+
afterBuild: mockAfterBuild,
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
useAppContext: jest.fn(() => ({
|
|
16
|
+
existSrc: false,
|
|
17
|
+
})),
|
|
18
|
+
useResolvedConfigContext: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock('../../src/utils/routes', () => ({
|
|
22
|
+
__esModule: true,
|
|
23
|
+
generateRoutes: () => mockGenerateRoutes(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
describe('command build', () => {
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
jest.resetAllMocks();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('existSrc is false', async () => {
|
|
32
|
+
await build();
|
|
33
|
+
expect(mockBeforeBuild).toBeCalled();
|
|
34
|
+
expect(mockGenerateRoutes).toBeCalled();
|
|
35
|
+
expect(mockAfterBuild).toBeCalled();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|