@modern-js/app-tools 1.4.4 → 1.4.7-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +8 -0
- package/CHANGELOG.md +47 -0
- package/dist/js/modern/commands/build.js +15 -11
- package/dist/js/modern/commands/deploy.js +4 -4
- package/dist/js/modern/commands/dev.js +17 -11
- package/dist/js/modern/commands/start.js +9 -10
- package/dist/js/modern/exports/server.js +1 -0
- package/dist/js/modern/{lifecycle.js → hooks.js} +10 -13
- package/dist/js/modern/index.js +74 -73
- package/dist/js/modern/utils/config.js +53 -0
- package/dist/js/modern/utils/createCompiler.js +7 -7
- package/dist/js/modern/utils/createServer.js +1 -2
- package/dist/js/modern/utils/printInstructions.js +2 -3
- package/dist/js/node/commands/build.js +15 -10
- package/dist/js/node/commands/deploy.js +4 -5
- package/dist/js/node/commands/dev.js +18 -14
- package/dist/js/node/commands/start.js +9 -11
- package/dist/js/node/exports/server.js +13 -0
- package/dist/js/node/{lifecycle.js → hooks.js} +12 -18
- package/dist/js/node/index.js +81 -77
- package/dist/js/node/utils/config.js +78 -0
- package/dist/js/node/utils/createCompiler.js +7 -8
- package/dist/js/node/utils/createServer.js +1 -2
- package/dist/js/node/utils/printInstructions.js +2 -4
- package/dist/types/commands/build.d.ts +2 -1
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/commands/start.d.ts +2 -1
- package/dist/types/exports/server.d.ts +1 -0
- package/dist/types/{lifecycle.d.ts → hooks.d.ts} +19 -1
- package/dist/types/index.d.ts +2 -7
- package/dist/types/utils/config.d.ts +12 -0
- package/dist/types/utils/createCompiler.d.ts +3 -1
- package/dist/types/utils/printInstructions.d.ts +2 -2
- package/dist/types/utils/routes.d.ts +1 -1
- package/jest.config.js +0 -1
- package/modern.config.js +1 -0
- package/package.json +28 -22
- package/tests/.eslintrc.js +8 -0
- package/tests/__snapshots__/utils.test.ts.snap +5 -0
- package/tests/commands/build.test.ts +25 -24
- package/tests/utils.test.ts +46 -1
|
@@ -15,6 +15,8 @@ var _utils = require("@modern-js/utils");
|
|
|
15
15
|
|
|
16
16
|
var _routes = require("../utils/routes");
|
|
17
17
|
|
|
18
|
+
var _config = require("../utils/config");
|
|
19
|
+
|
|
18
20
|
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
21
|
|
|
20
22
|
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,25 +27,24 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
25
27
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
26
28
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; // eslint-disable-next-line max-statements
|
|
27
29
|
|
|
28
|
-
const build = async options => {
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
30
|
+
const build = async (api, options) => {
|
|
31
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
32
|
+
const appContext = api.useAppContext();
|
|
33
|
+
const hookRunners = api.useHookRunners();
|
|
32
34
|
const {
|
|
33
35
|
existSrc
|
|
34
36
|
} = appContext;
|
|
35
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
36
37
|
|
|
37
38
|
if (!existSrc) {
|
|
38
39
|
const {
|
|
39
40
|
distDirectory
|
|
40
41
|
} = appContext;
|
|
41
42
|
await (0, _utils.emptyDir)(distDirectory);
|
|
42
|
-
await
|
|
43
|
+
await hookRunners.beforeBuild({
|
|
43
44
|
webpackConfigs: []
|
|
44
45
|
});
|
|
45
46
|
await (0, _routes.generateRoutes)(appContext);
|
|
46
|
-
await
|
|
47
|
+
await hookRunners.afterBuild();
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -108,10 +109,13 @@ const build = async options => {
|
|
|
108
109
|
});
|
|
109
110
|
|
|
110
111
|
const {
|
|
111
|
-
distDirectory
|
|
112
|
+
distDirectory,
|
|
113
|
+
appDirectory,
|
|
114
|
+
serverConfigFile
|
|
112
115
|
} = appContext;
|
|
113
116
|
const previousFileSizes = await (0, _utils.measureFileSizesBeforeBuild)(distDirectory);
|
|
114
117
|
await (0, _utils.emptyDir)(distDirectory);
|
|
118
|
+
await (0, _config.buildServerConfig)(appDirectory, serverConfigFile);
|
|
115
119
|
const buildConfigs = [];
|
|
116
120
|
buildConfigs.push({
|
|
117
121
|
type: 'legacy',
|
|
@@ -132,7 +136,7 @@ const build = async options => {
|
|
|
132
136
|
});
|
|
133
137
|
}
|
|
134
138
|
|
|
135
|
-
await
|
|
139
|
+
await hookRunners.beforeBuild({
|
|
136
140
|
webpackConfigs: buildConfigs.map(({
|
|
137
141
|
config
|
|
138
142
|
}) => config)
|
|
@@ -154,7 +158,8 @@ const build = async options => {
|
|
|
154
158
|
}
|
|
155
159
|
|
|
156
160
|
await (0, _routes.generateRoutes)(appContext);
|
|
157
|
-
await
|
|
161
|
+
await hookRunners.afterBuild();
|
|
162
|
+
await (0, _config.emitResolvedConfig)(appDirectory, resolvedConfig);
|
|
158
163
|
};
|
|
159
164
|
|
|
160
165
|
exports.build = build;
|
|
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.deploy = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
await
|
|
12
|
-
await (0, _core.mountHook)().afterDeploy(options);
|
|
8
|
+
const deploy = async (api, options) => {
|
|
9
|
+
const hookRunners = api.useHookRunners();
|
|
10
|
+
await hookRunners.beforeDeploy(options);
|
|
11
|
+
await hookRunners.afterDeploy(options);
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
exports.deploy = deploy;
|
|
@@ -7,8 +7,6 @@ exports.dev = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
10
|
var _createCompiler = require("../utils/createCompiler");
|
|
13
11
|
|
|
14
12
|
var _createServer = require("../utils/createServer");
|
|
@@ -19,6 +17,8 @@ var _printInstructions = require("../utils/printInstructions");
|
|
|
19
17
|
|
|
20
18
|
var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
|
|
21
19
|
|
|
20
|
+
var _config = require("../utils/config");
|
|
21
|
+
|
|
22
22
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
23
|
|
|
24
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -29,30 +29,32 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
29
29
|
|
|
30
30
|
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; }
|
|
31
31
|
|
|
32
|
-
const dev = async options => {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
37
|
-
|
|
32
|
+
const dev = async (api, options) => {
|
|
33
|
+
const appContext = api.useAppContext();
|
|
34
|
+
const userConfig = api.useResolvedConfigContext();
|
|
35
|
+
const hookRunners = api.useHookRunners();
|
|
38
36
|
const {
|
|
39
37
|
appDirectory,
|
|
40
38
|
distDirectory,
|
|
41
39
|
port,
|
|
42
40
|
existSrc,
|
|
43
|
-
entrypoints
|
|
41
|
+
entrypoints,
|
|
42
|
+
serverConfigFile
|
|
44
43
|
} = appContext;
|
|
45
44
|
const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
|
|
46
|
-
|
|
47
|
-
_core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
45
|
+
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
48
46
|
checkedEntries
|
|
49
47
|
}));
|
|
50
|
-
|
|
51
48
|
appContext.checkedEntries = checkedEntries;
|
|
52
49
|
|
|
53
50
|
_utils.fs.emptyDirSync(distDirectory);
|
|
54
51
|
|
|
55
|
-
await (0,
|
|
52
|
+
await (0, _config.buildServerConfig)(appDirectory, serverConfigFile, {
|
|
53
|
+
esbuildOptions: {
|
|
54
|
+
watch: true
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
await hookRunners.beforeDev();
|
|
56
58
|
let compiler = null;
|
|
57
59
|
|
|
58
60
|
if (existSrc) {
|
|
@@ -62,6 +64,7 @@ const dev = async options => {
|
|
|
62
64
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/webpack')));
|
|
63
65
|
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
64
66
|
compiler = await (0, _createCompiler.createCompiler)({
|
|
67
|
+
api,
|
|
65
68
|
webpackConfigs,
|
|
66
69
|
userConfig,
|
|
67
70
|
appContext
|
|
@@ -90,6 +93,7 @@ const dev = async options => {
|
|
|
90
93
|
compiler,
|
|
91
94
|
pwd: appDirectory,
|
|
92
95
|
config: userConfig,
|
|
96
|
+
serverConfigFile,
|
|
93
97
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
94
98
|
});
|
|
95
99
|
app.listen(port, async err => {
|
|
@@ -102,7 +106,7 @@ const dev = async options => {
|
|
|
102
106
|
|
|
103
107
|
_utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
104
108
|
} else {
|
|
105
|
-
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
109
|
+
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
|
106
110
|
}
|
|
107
111
|
});
|
|
108
112
|
};
|
|
@@ -7,23 +7,20 @@ exports.start = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
10
|
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
|
13
11
|
|
|
14
12
|
var _printInstructions = require("../utils/printInstructions");
|
|
15
13
|
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
15
|
|
|
18
|
-
const start = async
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
23
|
-
|
|
16
|
+
const start = async api => {
|
|
17
|
+
const appContext = api.useAppContext();
|
|
18
|
+
const userConfig = api.useResolvedConfigContext();
|
|
19
|
+
const hookRunners = api.useHookRunners();
|
|
24
20
|
const {
|
|
25
21
|
appDirectory,
|
|
26
|
-
port
|
|
22
|
+
port,
|
|
23
|
+
serverConfigFile
|
|
27
24
|
} = appContext;
|
|
28
25
|
|
|
29
26
|
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
@@ -31,14 +28,15 @@ const start = async () => {
|
|
|
31
28
|
const app = await (0, _prodServer.default)({
|
|
32
29
|
pwd: appDirectory,
|
|
33
30
|
config: userConfig,
|
|
34
|
-
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
31
|
+
plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
|
|
32
|
+
serverConfigFile
|
|
35
33
|
});
|
|
36
34
|
app.listen(port, async err => {
|
|
37
35
|
if (err) {
|
|
38
36
|
throw err;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
39
|
+
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
|
42
40
|
});
|
|
43
41
|
};
|
|
44
42
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "defineConfig", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _config.defineServerConfig;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _config = require("../utils/config");
|
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.hooks = exports.beforePrintInstructions = exports.beforeDev = exports.beforeDeploy = exports.beforeCreateCompiler = exports.beforeBuild = exports.afterDev = exports.afterDeploy = exports.afterCreateCompiler = exports.afterBuild = void 0;
|
|
7
7
|
|
|
8
8
|
var _plugin = require("@modern-js/plugin");
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
10
|
const beforeDev = (0, _plugin.createAsyncWorkflow)();
|
|
13
11
|
exports.beforeDev = beforeDev;
|
|
14
12
|
const afterDev = (0, _plugin.createAsyncWorkflow)();
|
|
@@ -27,19 +25,15 @@ const beforeDeploy = (0, _plugin.createAsyncWorkflow)();
|
|
|
27
25
|
exports.beforeDeploy = beforeDeploy;
|
|
28
26
|
const afterDeploy = (0, _plugin.createAsyncWorkflow)();
|
|
29
27
|
exports.afterDeploy = afterDeploy;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
beforeDeploy,
|
|
41
|
-
afterDeploy
|
|
42
|
-
});
|
|
28
|
+
const hooks = {
|
|
29
|
+
beforeDev,
|
|
30
|
+
afterDev,
|
|
31
|
+
beforeCreateCompiler,
|
|
32
|
+
afterCreateCompiler,
|
|
33
|
+
beforePrintInstructions,
|
|
34
|
+
beforeBuild,
|
|
35
|
+
afterBuild,
|
|
36
|
+
beforeDeploy,
|
|
37
|
+
afterDeploy
|
|
43
38
|
};
|
|
44
|
-
|
|
45
|
-
exports.lifecycle = lifecycle;
|
|
39
|
+
exports.hooks = hooks;
|
package/dist/js/node/index.js
CHANGED
|
@@ -15,9 +15,13 @@ var path = _interopRequireWildcard(require("path"));
|
|
|
15
15
|
|
|
16
16
|
var _core = require("@modern-js/core");
|
|
17
17
|
|
|
18
|
+
var _pluginAnalyze = _interopRequireDefault(require("@modern-js/plugin-analyze"));
|
|
19
|
+
|
|
20
|
+
var _cli = _interopRequireDefault(require("@modern-js/plugin-fast-refresh/cli"));
|
|
21
|
+
|
|
18
22
|
var _utils = require("@modern-js/utils");
|
|
19
23
|
|
|
20
|
-
var
|
|
24
|
+
var _hooks = require("./hooks");
|
|
21
25
|
|
|
22
26
|
var _locale = require("./locale");
|
|
23
27
|
|
|
@@ -29,6 +33,8 @@ var _dev = require("./commands/dev");
|
|
|
29
33
|
|
|
30
34
|
var _createServer = require("./utils/createServer");
|
|
31
35
|
|
|
36
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
+
|
|
32
38
|
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; }
|
|
33
39
|
|
|
34
40
|
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; }
|
|
@@ -39,86 +45,84 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
39
45
|
|
|
40
46
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
48
|
+
var _default = () => ({
|
|
49
|
+
name: '@modern-js/app-tools',
|
|
50
|
+
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'],
|
|
51
|
+
registerHook: _hooks.hooks,
|
|
52
|
+
usePlugins: [(0, _pluginAnalyze.default)(), (0, _cli.default)()],
|
|
53
|
+
setup: api => {
|
|
54
|
+
const locale = (0, _language.getLocaleLanguage)();
|
|
55
|
+
|
|
56
|
+
_locale.i18n.changeLanguage({
|
|
57
|
+
locale
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
commands({
|
|
62
|
+
program
|
|
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 => {
|
|
65
|
+
await (0, _dev.dev)(api, options);
|
|
66
|
+
});
|
|
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 => {
|
|
68
|
+
const {
|
|
69
|
+
build
|
|
70
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
|
71
|
+
await build(api, options); // force exit after build.
|
|
72
|
+
// eslint-disable-next-line no-process-exit
|
|
73
|
+
|
|
74
|
+
process.exit(0);
|
|
75
|
+
});
|
|
76
|
+
program.command('start').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.start.describe)).action(async () => {
|
|
77
|
+
await (0, _start.start)(api);
|
|
78
|
+
});
|
|
79
|
+
program.command('deploy').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async options => {
|
|
80
|
+
const {
|
|
81
|
+
build
|
|
82
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
|
|
83
|
+
await build(api);
|
|
84
|
+
const {
|
|
85
|
+
deploy
|
|
86
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/deploy")));
|
|
87
|
+
await deploy(api, options); // eslint-disable-next-line no-process-exit
|
|
88
|
+
|
|
89
|
+
process.exit(0);
|
|
90
|
+
});
|
|
91
|
+
program.command('new').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option('-d, --debug', _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option('-c, --config <config>', _locale.i18n.t(_locale.localeKeys.command.new.config)).option('--dist-tag <tag>', _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option('--registry', _locale.i18n.t(_locale.localeKeys.command.new.registry)).action(async options => {
|
|
92
|
+
const {
|
|
93
|
+
MWANewAction
|
|
94
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/new-action')));
|
|
95
|
+
await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
|
|
96
|
+
locale
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
102
|
+
async fileChange(e) {
|
|
77
103
|
const {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
process.exit(0);
|
|
83
|
-
});
|
|
84
|
-
program.command('new').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option('-d, --debug', _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option('-c, --config <config>', _locale.i18n.t(_locale.localeKeys.command.new.config)).option('--dist-tag <tag>', _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option('--registry', _locale.i18n.t(_locale.localeKeys.command.new.registry)).action(async options => {
|
|
104
|
+
filename,
|
|
105
|
+
eventType
|
|
106
|
+
} = e;
|
|
107
|
+
const appContext = api.useAppContext();
|
|
85
108
|
const {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
100
|
-
|
|
101
|
-
const appContext = (0, _core.useAppContext)();
|
|
102
|
-
const {
|
|
103
|
-
appDirectory,
|
|
104
|
-
srcDirectory
|
|
105
|
-
} = appContext;
|
|
106
|
-
const absolutePath = path.resolve(appDirectory, filename);
|
|
107
|
-
|
|
108
|
-
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
109
|
-
await (0, _createServer.closeServer)();
|
|
110
|
-
await _core.cli.restart();
|
|
109
|
+
appDirectory,
|
|
110
|
+
srcDirectory
|
|
111
|
+
} = appContext;
|
|
112
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
113
|
+
|
|
114
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
115
|
+
await (0, _createServer.closeServer)();
|
|
116
|
+
await _core.cli.restart();
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
async beforeRestart() {
|
|
121
|
+
(0, _utils.cleanRequireCache)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
111
122
|
}
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
async beforeRestart() {
|
|
115
|
-
(0, _utils.cleanRequireCache)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
116
|
-
}
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
name: '@modern-js/app-tools',
|
|
121
|
-
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']
|
|
124
|
+
};
|
|
125
|
+
}
|
|
122
126
|
});
|
|
123
127
|
|
|
124
128
|
exports.default = _default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.safeReplacer = exports.emitResolvedConfig = exports.defineServerConfig = exports.buildServerConfig = void 0;
|
|
7
|
+
|
|
8
|
+
var path = _interopRequireWildcard(require("path"));
|
|
9
|
+
|
|
10
|
+
var _nodeBundleRequire = require("@modern-js/node-bundle-require");
|
|
11
|
+
|
|
12
|
+
var _utils = require("@modern-js/utils");
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
|
|
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; }
|
|
19
|
+
|
|
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
const defineServerConfig = config => config;
|
|
25
|
+
|
|
26
|
+
exports.defineServerConfig = defineServerConfig;
|
|
27
|
+
|
|
28
|
+
const buildServerConfig = async (appDirectory, configFile, options) => {
|
|
29
|
+
const configFilePath = await (0, _utils.getServerConfig)(appDirectory, configFile);
|
|
30
|
+
|
|
31
|
+
const getOutputFile = filepath => path.resolve(_utils.CONFIG_CACHE_DIR, `${filepath.replace(new RegExp(_utils.CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
|
|
32
|
+
|
|
33
|
+
if (configFilePath) {
|
|
34
|
+
await (0, _nodeBundleRequire.bundle)(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
|
|
35
|
+
getOutputFile
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* 处理循环引用的 replacer
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
exports.buildServerConfig = buildServerConfig;
|
|
46
|
+
|
|
47
|
+
const safeReplacer = () => {
|
|
48
|
+
const cache = [];
|
|
49
|
+
const keyCache = [];
|
|
50
|
+
return function (key, value) {
|
|
51
|
+
if (typeof value === 'object' && value !== null) {
|
|
52
|
+
const index = cache.indexOf(value);
|
|
53
|
+
|
|
54
|
+
if (index !== -1) {
|
|
55
|
+
return `[Circular ${keyCache[index]}]`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
cache.push(value);
|
|
59
|
+
keyCache.push(key || 'root');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return value;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.safeReplacer = safeReplacer;
|
|
67
|
+
|
|
68
|
+
const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
|
69
|
+
var _resolvedConfig$outpu;
|
|
70
|
+
|
|
71
|
+
const outputPath = path.join(appDirectory, (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$outpu = resolvedConfig.output) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.path) || './dist', _utils.OUTPUT_CONFIG_FILE);
|
|
72
|
+
await _utils.fs.writeJSON(outputPath, resolvedConfig, {
|
|
73
|
+
spaces: 2,
|
|
74
|
+
replacer: safeReplacer()
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.emitResolvedConfig = emitResolvedConfig;
|
|
@@ -7,8 +7,6 @@ exports.createCompiler = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _webpack = _interopRequireDefault(require("webpack"));
|
|
9
9
|
|
|
10
|
-
var _core = require("@modern-js/core");
|
|
11
|
-
|
|
12
10
|
var _utils = require("@modern-js/utils");
|
|
13
11
|
|
|
14
12
|
var _printInstructions = require("./printInstructions");
|
|
@@ -22,17 +20,19 @@ const prettyTime = stats => {
|
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
const createCompiler = async ({
|
|
23
|
+
api,
|
|
25
24
|
webpackConfigs,
|
|
26
25
|
// TODO: params
|
|
27
26
|
userConfig,
|
|
28
27
|
appContext
|
|
29
28
|
}) => {
|
|
30
29
|
try {
|
|
31
|
-
|
|
30
|
+
const hookRunners = api.useHookRunners();
|
|
31
|
+
await hookRunners.beforeCreateCompiler({
|
|
32
32
|
webpackConfigs
|
|
33
33
|
});
|
|
34
34
|
const compiler = (0, _webpack.default)(webpackConfigs);
|
|
35
|
-
await
|
|
35
|
+
await hookRunners.afterCreateCompiler({
|
|
36
36
|
compiler
|
|
37
37
|
});
|
|
38
38
|
let isFirstCompile = true;
|
|
@@ -61,7 +61,7 @@ const createCompiler = async ({
|
|
|
61
61
|
|
|
62
62
|
_utils.logger.log();
|
|
63
63
|
} else if (process.stdout.isTTY || isFirstCompile) {
|
|
64
|
-
await
|
|
64
|
+
await hookRunners.afterDev();
|
|
65
65
|
|
|
66
66
|
if (warnings.length) {
|
|
67
67
|
_utils.logger.log(_utils.chalk.yellow(`Compiled with warnings.\n`));
|
|
@@ -73,9 +73,8 @@ const createCompiler = async ({
|
|
|
73
73
|
_utils.logger.log(_utils.chalk.green(`Compiled successfully in ${prettyTime(statsData)} ms.\n`));
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
77
|
-
}
|
|
78
|
-
|
|
76
|
+
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
|
77
|
+
}
|
|
79
78
|
|
|
80
79
|
isFirstCompile = false;
|
|
81
80
|
});
|
|
@@ -25,8 +25,7 @@ exports.closeServer = closeServer;
|
|
|
25
25
|
const createServer = async options => {
|
|
26
26
|
if (server) {
|
|
27
27
|
await server.close();
|
|
28
|
-
}
|
|
29
|
-
|
|
28
|
+
}
|
|
30
29
|
|
|
31
30
|
server = new _server.Server(options);
|
|
32
31
|
const app = await server.init();
|
|
@@ -7,9 +7,7 @@ exports.printInstructions = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const printInstructions = async (appContext, config) => {
|
|
10
|
+
const printInstructions = async (hookRunners, appContext, config) => {
|
|
13
11
|
let message = (0, _utils.prettyInstructions)(appContext, config);
|
|
14
12
|
const {
|
|
15
13
|
existSrc
|
|
@@ -22,7 +20,7 @@ const printInstructions = async (appContext, config) => {
|
|
|
22
20
|
|
|
23
21
|
const {
|
|
24
22
|
instructions
|
|
25
|
-
} = await
|
|
23
|
+
} = await hookRunners.beforePrintInstructions({
|
|
26
24
|
instructions: message
|
|
27
25
|
});
|
|
28
26
|
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { PluginAPI } from '@modern-js/core';
|
|
1
2
|
import type { BuildOptions } from '../utils/types';
|
|
2
|
-
export declare const build: (options?: BuildOptions | undefined) => Promise<void>;
|
|
3
|
+
export declare const build: (api: PluginAPI, options?: BuildOptions | undefined) => Promise<void>;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PluginAPI } from '@modern-js/core';
|
|
2
|
+
export declare const deploy: (api: PluginAPI, options: any) => Promise<void>;
|