@modern-js/app-tools 2.48.4 → 2.48.5-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/commands/dev.js +13 -15
- package/dist/cjs/commands/serve.js +14 -22
- package/dist/cjs/utils/createServer.js +5 -27
- package/dist/cjs/utils/env.js +2 -2
- package/dist/esm/commands/dev.js +16 -27
- package/dist/esm/commands/serve.js +28 -32
- package/dist/esm/utils/createServer.js +14 -50
- package/dist/esm/utils/env.js +1 -1
- package/dist/esm-node/commands/dev.js +14 -16
- package/dist/esm-node/commands/serve.js +14 -12
- package/dist/esm-node/utils/createServer.js +6 -17
- package/dist/esm-node/utils/env.js +1 -1
- package/dist/types/utils/createServer.d.ts +7 -9
- package/package.json +7 -7
package/dist/cjs/commands/dev.js
CHANGED
@@ -23,6 +23,8 @@ __export(dev_exports, {
|
|
23
23
|
module.exports = __toCommonJS(dev_exports);
|
24
24
|
var import_core = require("@modern-js/core");
|
25
25
|
var import_utils = require("@modern-js/utils");
|
26
|
+
var import_server = require("@modern-js/server");
|
27
|
+
var import_prod_server = require("@modern-js/prod-server");
|
26
28
|
var import_printInstructions = require("../utils/printInstructions");
|
27
29
|
var import_createServer = require("../utils/createServer");
|
28
30
|
var import_routes = require("../utils/routes");
|
@@ -41,7 +43,7 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
41
43
|
cliOptions: options
|
42
44
|
};
|
43
45
|
import_core.ResolvedConfigContext.set(normalizedConfig);
|
44
|
-
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName } = appContext;
|
46
|
+
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
|
45
47
|
await (0, import_config.buildServerConfig)({
|
46
48
|
appDirectory,
|
47
49
|
distDirectory,
|
@@ -55,6 +57,7 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
55
57
|
await (0, import_routes.generateRoutes)(appContext);
|
56
58
|
const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
|
57
59
|
const serverOptions = {
|
60
|
+
metaName,
|
58
61
|
dev: {
|
59
62
|
port,
|
60
63
|
https: normalizedConfig.dev.https,
|
@@ -62,37 +65,32 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
62
65
|
...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
|
63
66
|
},
|
64
67
|
appContext: {
|
65
|
-
|
66
|
-
appDirectory: appContext.appDirectory,
|
67
|
-
sharedDirectory: appContext.sharedDirectory,
|
68
|
+
appDirectory,
|
68
69
|
apiDirectory: appContext.apiDirectory,
|
69
|
-
lambdaDirectory: appContext.lambdaDirectory
|
70
|
+
lambdaDirectory: appContext.lambdaDirectory,
|
71
|
+
sharedDirectory: appContext.sharedDirectory
|
70
72
|
},
|
73
|
+
routes: serverRoutes,
|
71
74
|
pwd: appDirectory,
|
72
75
|
config: normalizedConfig,
|
73
76
|
serverConfigFile,
|
74
|
-
internalPlugins:
|
77
|
+
internalPlugins: serverInternalPlugins,
|
75
78
|
...devServerOptions
|
76
79
|
};
|
77
80
|
if (apiOnly) {
|
78
81
|
var _normalizedConfig_dev;
|
79
|
-
const app = await (0,
|
80
|
-
...serverOptions,
|
81
|
-
compiler: null
|
82
|
-
});
|
82
|
+
const app = await (0, import_server.createDevServer)(serverOptions, import_prod_server.initProdMiddlewares);
|
83
83
|
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || import_utils.DEFAULT_DEV_HOST;
|
84
84
|
app.listen({
|
85
85
|
port,
|
86
86
|
host
|
87
|
-
},
|
88
|
-
if (err) {
|
89
|
-
throw err;
|
90
|
-
}
|
87
|
+
}, () => {
|
91
88
|
(0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
|
92
89
|
});
|
93
90
|
} else {
|
94
91
|
const { server } = await appContext.builder.startDevServer({
|
95
|
-
serverOptions
|
92
|
+
serverOptions,
|
93
|
+
initProdMiddlewares: import_prod_server.initProdMiddlewares
|
96
94
|
});
|
97
95
|
(0, import_createServer.setServer)(server);
|
98
96
|
}
|
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
7
|
for (var name in all)
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
19
|
var serve_exports = {};
|
30
20
|
__export(serve_exports, {
|
@@ -32,21 +22,25 @@ __export(serve_exports, {
|
|
32
22
|
});
|
33
23
|
module.exports = __toCommonJS(serve_exports);
|
34
24
|
var import_utils = require("@modern-js/utils");
|
35
|
-
var import_prod_server =
|
25
|
+
var import_prod_server = require("@modern-js/prod-server");
|
36
26
|
var import_printInstructions = require("../utils/printInstructions");
|
37
|
-
var import_createServer = require("../utils/createServer");
|
38
27
|
var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
39
28
|
const start = async (api) => {
|
40
29
|
var _userConfig_source, _userConfig_output_distPath;
|
41
30
|
const appContext = api.useAppContext();
|
42
31
|
const userConfig = api.useResolvedConfigContext();
|
43
32
|
const hookRunners = api.useHookRunners();
|
44
|
-
const { appDirectory, port, serverConfigFile, metaName } = appContext;
|
33
|
+
const { distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes } = appContext;
|
45
34
|
import_utils.logger.info(`Starting production server...`);
|
46
35
|
const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
|
36
|
+
let runMode;
|
37
|
+
if (apiOnly) {
|
38
|
+
runMode = "apiOnly";
|
39
|
+
}
|
47
40
|
const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
|
48
|
-
const app = await (0, import_prod_server.
|
49
|
-
|
41
|
+
const app = await (0, import_prod_server.createProdServer)({
|
42
|
+
metaName,
|
43
|
+
pwd: distDirectory,
|
50
44
|
config: {
|
51
45
|
...userConfig,
|
52
46
|
dev: userConfig.dev,
|
@@ -55,20 +49,18 @@ const start = async (api) => {
|
|
55
49
|
...userConfig.output || {}
|
56
50
|
}
|
57
51
|
},
|
52
|
+
routes: serverRoutes,
|
58
53
|
appContext: {
|
59
|
-
|
54
|
+
appDirectory,
|
60
55
|
sharedDirectory: (0, import_utils.getTargetDir)(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
61
56
|
apiDirectory: (0, import_utils.getTargetDir)(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
62
57
|
lambdaDirectory: (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
63
58
|
},
|
64
59
|
serverConfigFile,
|
65
|
-
internalPlugins:
|
66
|
-
|
60
|
+
internalPlugins: serverInternalPlugins,
|
61
|
+
runMode
|
67
62
|
});
|
68
|
-
app.listen(port, async (
|
69
|
-
if (err) {
|
70
|
-
throw err;
|
71
|
-
}
|
63
|
+
app.listen(port, async () => {
|
72
64
|
await (0, import_printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
73
65
|
});
|
74
66
|
};
|
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
7
|
for (var name in all)
|
@@ -17,25 +15,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
19
|
var createServer_exports = {};
|
30
20
|
__export(createServer_exports, {
|
31
21
|
closeServer: () => closeServer,
|
32
22
|
createServer: () => createServer,
|
33
23
|
getServer: () => getServer,
|
34
|
-
injectDataLoaderPlugin: () => injectDataLoaderPlugin,
|
35
24
|
setServer: () => setServer
|
36
25
|
});
|
37
26
|
module.exports = __toCommonJS(createServer_exports);
|
38
27
|
var import_server = require("@modern-js/server");
|
28
|
+
var import_prod_server = require("@modern-js/prod-server");
|
39
29
|
let server = null;
|
40
30
|
const getServer = () => server;
|
41
31
|
const setServer = (newServer) => {
|
@@ -43,33 +33,21 @@ const setServer = (newServer) => {
|
|
43
33
|
};
|
44
34
|
const closeServer = async () => {
|
45
35
|
if (server) {
|
46
|
-
|
36
|
+
server.close();
|
47
37
|
server = null;
|
48
38
|
}
|
49
39
|
};
|
50
40
|
const createServer = async (options) => {
|
51
41
|
if (server) {
|
52
|
-
|
42
|
+
server.close();
|
53
43
|
}
|
54
|
-
server =
|
55
|
-
|
56
|
-
return app;
|
57
|
-
};
|
58
|
-
const injectDataLoaderPlugin = (internalPlugins) => {
|
59
|
-
const DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
|
60
|
-
return {
|
61
|
-
...internalPlugins,
|
62
|
-
"@modern-js/plugin-data-loader": {
|
63
|
-
path: DataLoaderPlugin,
|
64
|
-
forced: true
|
65
|
-
}
|
66
|
-
};
|
44
|
+
server = await (0, import_server.createDevServer)(options, import_prod_server.initProdMiddlewares);
|
45
|
+
return server;
|
67
46
|
};
|
68
47
|
// Annotate the CommonJS export names for ESM import in node:
|
69
48
|
0 && (module.exports = {
|
70
49
|
closeServer,
|
71
50
|
createServer,
|
72
51
|
getServer,
|
73
|
-
injectDataLoaderPlugin,
|
74
52
|
setServer
|
75
53
|
});
|
package/dist/cjs/utils/env.js
CHANGED
@@ -21,10 +21,10 @@ __export(env_exports, {
|
|
21
21
|
getAutoInjectEnv: () => getAutoInjectEnv
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(env_exports);
|
24
|
-
var
|
24
|
+
var import_universal = require("@modern-js/utils/universal");
|
25
25
|
function getAutoInjectEnv(appContext) {
|
26
26
|
const { metaName } = appContext;
|
27
|
-
const prefix = `${(0,
|
27
|
+
const prefix = `${(0, import_universal.cutNameByHyphen)(metaName)}_`.toUpperCase();
|
28
28
|
const envReg = new RegExp(`^${prefix}`);
|
29
29
|
return Object.keys(process.env).reduce((prev, key) => {
|
30
30
|
const value = process.env[key];
|
package/dist/esm/commands/dev.js
CHANGED
@@ -4,14 +4,16 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import { ResolvedConfigContext } from "@modern-js/core";
|
6
6
|
import { DEFAULT_DEV_HOST } from "@modern-js/utils";
|
7
|
+
import { createDevServer } from "@modern-js/server";
|
8
|
+
import { initProdMiddlewares } from "@modern-js/prod-server";
|
7
9
|
import { printInstructions } from "../utils/printInstructions";
|
8
|
-
import { setServer
|
10
|
+
import { setServer } from "../utils/createServer";
|
9
11
|
import { generateRoutes } from "../utils/routes";
|
10
12
|
import { buildServerConfig } from "../utils/config";
|
11
13
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
12
14
|
var dev = function() {
|
13
15
|
var _ref = _async_to_generator(function(api, options) {
|
14
|
-
var devServerOptions, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
|
16
|
+
var devServerOptions, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
|
15
17
|
var _arguments = arguments;
|
16
18
|
return _ts_generator(this, function(_state) {
|
17
19
|
switch (_state.label) {
|
@@ -27,7 +29,7 @@ var dev = function() {
|
|
27
29
|
cliOptions: options
|
28
30
|
});
|
29
31
|
ResolvedConfigContext.set(normalizedConfig);
|
30
|
-
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName;
|
32
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
|
31
33
|
return [
|
32
34
|
4,
|
33
35
|
buildServerConfig({
|
@@ -61,22 +63,23 @@ var dev = function() {
|
|
61
63
|
case 4:
|
62
64
|
serverInternalPlugins = _state.sent();
|
63
65
|
serverOptions = _object_spread({
|
66
|
+
metaName,
|
64
67
|
dev: _object_spread({
|
65
68
|
port,
|
66
69
|
https: normalizedConfig.dev.https,
|
67
70
|
host: normalizedConfig.dev.host
|
68
71
|
}, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
|
69
72
|
appContext: {
|
70
|
-
|
71
|
-
appDirectory: appContext.appDirectory,
|
72
|
-
sharedDirectory: appContext.sharedDirectory,
|
73
|
+
appDirectory,
|
73
74
|
apiDirectory: appContext.apiDirectory,
|
74
|
-
lambdaDirectory: appContext.lambdaDirectory
|
75
|
+
lambdaDirectory: appContext.lambdaDirectory,
|
76
|
+
sharedDirectory: appContext.sharedDirectory
|
75
77
|
},
|
78
|
+
routes: serverRoutes,
|
76
79
|
pwd: appDirectory,
|
77
80
|
config: normalizedConfig,
|
78
81
|
serverConfigFile,
|
79
|
-
internalPlugins:
|
82
|
+
internalPlugins: serverInternalPlugins
|
80
83
|
}, devServerOptions);
|
81
84
|
if (!apiOnly)
|
82
85
|
return [
|
@@ -85,9 +88,7 @@ var dev = function() {
|
|
85
88
|
];
|
86
89
|
return [
|
87
90
|
4,
|
88
|
-
|
89
|
-
compiler: null
|
90
|
-
}))
|
91
|
+
createDevServer(serverOptions, initProdMiddlewares)
|
91
92
|
];
|
92
93
|
case 5:
|
93
94
|
app = _state.sent();
|
@@ -96,21 +97,8 @@ var dev = function() {
|
|
96
97
|
port,
|
97
98
|
host
|
98
99
|
}, function() {
|
99
|
-
|
100
|
-
|
101
|
-
if (err) {
|
102
|
-
throw err;
|
103
|
-
}
|
104
|
-
printInstructions(hookRunners, appContext, normalizedConfig);
|
105
|
-
return [
|
106
|
-
2
|
107
|
-
];
|
108
|
-
});
|
109
|
-
});
|
110
|
-
return function(err) {
|
111
|
-
return _ref2.apply(this, arguments);
|
112
|
-
};
|
113
|
-
}());
|
100
|
+
printInstructions(hookRunners, appContext, normalizedConfig);
|
101
|
+
});
|
114
102
|
return [
|
115
103
|
3,
|
116
104
|
8
|
@@ -119,7 +107,8 @@ var dev = function() {
|
|
119
107
|
return [
|
120
108
|
4,
|
121
109
|
appContext.builder.startDevServer({
|
122
|
-
serverOptions
|
110
|
+
serverOptions,
|
111
|
+
initProdMiddlewares
|
123
112
|
})
|
124
113
|
];
|
125
114
|
case 7:
|
@@ -3,20 +3,19 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
|
6
|
-
import
|
6
|
+
import { createProdServer } from "@modern-js/prod-server";
|
7
7
|
import { printInstructions } from "../utils/printInstructions";
|
8
|
-
import { injectDataLoaderPlugin } from "../utils/createServer";
|
9
8
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
10
9
|
var start = function() {
|
11
10
|
var _ref = _async_to_generator(function(api) {
|
12
|
-
var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, metaName, apiOnly, serverInternalPlugins, app;
|
11
|
+
var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes, apiOnly, runMode, serverInternalPlugins, app;
|
13
12
|
return _ts_generator(this, function(_state) {
|
14
13
|
switch (_state.label) {
|
15
14
|
case 0:
|
16
15
|
appContext = api.useAppContext();
|
17
16
|
userConfig = api.useResolvedConfigContext();
|
18
17
|
hookRunners = api.useHookRunners();
|
19
|
-
appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName;
|
18
|
+
distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
|
20
19
|
logger.info("Starting production server...");
|
21
20
|
return [
|
22
21
|
4,
|
@@ -24,6 +23,9 @@ var start = function() {
|
|
24
23
|
];
|
25
24
|
case 1:
|
26
25
|
apiOnly = _state.sent();
|
26
|
+
if (apiOnly) {
|
27
|
+
runMode = "apiOnly";
|
28
|
+
}
|
27
29
|
return [
|
28
30
|
4,
|
29
31
|
getServerInternalPlugins(api)
|
@@ -32,51 +34,45 @@ var start = function() {
|
|
32
34
|
serverInternalPlugins = _state.sent();
|
33
35
|
return [
|
34
36
|
4,
|
35
|
-
|
36
|
-
|
37
|
+
createProdServer({
|
38
|
+
metaName,
|
39
|
+
pwd: distDirectory,
|
37
40
|
config: _object_spread_props(_object_spread({}, userConfig), {
|
38
41
|
dev: userConfig.dev,
|
39
42
|
output: _object_spread({
|
40
43
|
path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
|
41
44
|
}, userConfig.output || {})
|
42
45
|
}),
|
46
|
+
routes: serverRoutes,
|
43
47
|
appContext: {
|
44
|
-
|
48
|
+
appDirectory,
|
45
49
|
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
46
50
|
apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
47
51
|
lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
48
52
|
},
|
49
53
|
serverConfigFile,
|
50
|
-
internalPlugins:
|
51
|
-
|
54
|
+
internalPlugins: serverInternalPlugins,
|
55
|
+
runMode
|
52
56
|
})
|
53
57
|
];
|
54
58
|
case 3:
|
55
59
|
app = _state.sent();
|
56
|
-
app.listen(port, function() {
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
return [
|
71
|
-
2
|
72
|
-
];
|
73
|
-
}
|
74
|
-
});
|
60
|
+
app.listen(port, /* @__PURE__ */ _async_to_generator(function() {
|
61
|
+
return _ts_generator(this, function(_state2) {
|
62
|
+
switch (_state2.label) {
|
63
|
+
case 0:
|
64
|
+
return [
|
65
|
+
4,
|
66
|
+
printInstructions(hookRunners, appContext, userConfig)
|
67
|
+
];
|
68
|
+
case 1:
|
69
|
+
_state2.sent();
|
70
|
+
return [
|
71
|
+
2
|
72
|
+
];
|
73
|
+
}
|
75
74
|
});
|
76
|
-
|
77
|
-
return _ref2.apply(this, arguments);
|
78
|
-
};
|
79
|
-
}());
|
75
|
+
}));
|
80
76
|
return [
|
81
77
|
2
|
82
78
|
];
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
-
import {
|
3
|
+
import { createDevServer } from "@modern-js/server";
|
4
|
+
import { initProdMiddlewares } from "@modern-js/prod-server";
|
6
5
|
var server = null;
|
7
6
|
var getServer = function() {
|
8
7
|
return server;
|
@@ -13,26 +12,13 @@ var setServer = function(newServer) {
|
|
13
12
|
var closeServer = function() {
|
14
13
|
var _ref = _async_to_generator(function() {
|
15
14
|
return _ts_generator(this, function(_state) {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
return [
|
20
|
-
3,
|
21
|
-
2
|
22
|
-
];
|
23
|
-
return [
|
24
|
-
4,
|
25
|
-
server.close()
|
26
|
-
];
|
27
|
-
case 1:
|
28
|
-
_state.sent();
|
29
|
-
server = null;
|
30
|
-
_state.label = 2;
|
31
|
-
case 2:
|
32
|
-
return [
|
33
|
-
2
|
34
|
-
];
|
15
|
+
if (server) {
|
16
|
+
server.close();
|
17
|
+
server = null;
|
35
18
|
}
|
19
|
+
return [
|
20
|
+
2
|
21
|
+
];
|
36
22
|
});
|
37
23
|
});
|
38
24
|
return function closeServer2() {
|
@@ -41,33 +27,21 @@ var closeServer = function() {
|
|
41
27
|
}();
|
42
28
|
var createServer = function() {
|
43
29
|
var _ref = _async_to_generator(function(options) {
|
44
|
-
var app;
|
45
30
|
return _ts_generator(this, function(_state) {
|
46
31
|
switch (_state.label) {
|
47
32
|
case 0:
|
48
|
-
if (
|
49
|
-
|
50
|
-
|
51
|
-
2
|
52
|
-
];
|
33
|
+
if (server) {
|
34
|
+
server.close();
|
35
|
+
}
|
53
36
|
return [
|
54
37
|
4,
|
55
|
-
|
38
|
+
createDevServer(options, initProdMiddlewares)
|
56
39
|
];
|
57
40
|
case 1:
|
58
|
-
_state.sent();
|
59
|
-
_state.label = 2;
|
60
|
-
case 2:
|
61
|
-
server = new Server(options);
|
62
|
-
return [
|
63
|
-
4,
|
64
|
-
server.init()
|
65
|
-
];
|
66
|
-
case 3:
|
67
|
-
app = _state.sent();
|
41
|
+
server = _state.sent();
|
68
42
|
return [
|
69
43
|
2,
|
70
|
-
|
44
|
+
server
|
71
45
|
];
|
72
46
|
}
|
73
47
|
});
|
@@ -76,19 +50,9 @@ var createServer = function() {
|
|
76
50
|
return _ref.apply(this, arguments);
|
77
51
|
};
|
78
52
|
}();
|
79
|
-
var injectDataLoaderPlugin = function(internalPlugins) {
|
80
|
-
var DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
|
81
|
-
return _object_spread_props(_object_spread({}, internalPlugins), {
|
82
|
-
"@modern-js/plugin-data-loader": {
|
83
|
-
path: DataLoaderPlugin,
|
84
|
-
forced: true
|
85
|
-
}
|
86
|
-
});
|
87
|
-
};
|
88
53
|
export {
|
89
54
|
closeServer,
|
90
55
|
createServer,
|
91
56
|
getServer,
|
92
|
-
injectDataLoaderPlugin,
|
93
57
|
setServer
|
94
58
|
};
|
package/dist/esm/utils/env.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
import { ResolvedConfigContext } from "@modern-js/core";
|
2
2
|
import { DEFAULT_DEV_HOST } from "@modern-js/utils";
|
3
|
+
import { createDevServer } from "@modern-js/server";
|
4
|
+
import { initProdMiddlewares } from "@modern-js/prod-server";
|
3
5
|
import { printInstructions } from "../utils/printInstructions";
|
4
|
-
import { setServer
|
6
|
+
import { setServer } from "../utils/createServer";
|
5
7
|
import { generateRoutes } from "../utils/routes";
|
6
8
|
import { buildServerConfig } from "../utils/config";
|
7
9
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
@@ -18,7 +20,7 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
18
20
|
cliOptions: options
|
19
21
|
};
|
20
22
|
ResolvedConfigContext.set(normalizedConfig);
|
21
|
-
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName } = appContext;
|
23
|
+
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
|
22
24
|
await buildServerConfig({
|
23
25
|
appDirectory,
|
24
26
|
distDirectory,
|
@@ -32,6 +34,7 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
32
34
|
await generateRoutes(appContext);
|
33
35
|
const serverInternalPlugins = await getServerInternalPlugins(api);
|
34
36
|
const serverOptions = {
|
37
|
+
metaName,
|
35
38
|
dev: {
|
36
39
|
port,
|
37
40
|
https: normalizedConfig.dev.https,
|
@@ -39,37 +42,32 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
39
42
|
...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
|
40
43
|
},
|
41
44
|
appContext: {
|
42
|
-
|
43
|
-
appDirectory: appContext.appDirectory,
|
44
|
-
sharedDirectory: appContext.sharedDirectory,
|
45
|
+
appDirectory,
|
45
46
|
apiDirectory: appContext.apiDirectory,
|
46
|
-
lambdaDirectory: appContext.lambdaDirectory
|
47
|
+
lambdaDirectory: appContext.lambdaDirectory,
|
48
|
+
sharedDirectory: appContext.sharedDirectory
|
47
49
|
},
|
50
|
+
routes: serverRoutes,
|
48
51
|
pwd: appDirectory,
|
49
52
|
config: normalizedConfig,
|
50
53
|
serverConfigFile,
|
51
|
-
internalPlugins:
|
54
|
+
internalPlugins: serverInternalPlugins,
|
52
55
|
...devServerOptions
|
53
56
|
};
|
54
57
|
if (apiOnly) {
|
55
58
|
var _normalizedConfig_dev;
|
56
|
-
const app = await
|
57
|
-
...serverOptions,
|
58
|
-
compiler: null
|
59
|
-
});
|
59
|
+
const app = await createDevServer(serverOptions, initProdMiddlewares);
|
60
60
|
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
61
61
|
app.listen({
|
62
62
|
port,
|
63
63
|
host
|
64
|
-
},
|
65
|
-
if (err) {
|
66
|
-
throw err;
|
67
|
-
}
|
64
|
+
}, () => {
|
68
65
|
printInstructions(hookRunners, appContext, normalizedConfig);
|
69
66
|
});
|
70
67
|
} else {
|
71
68
|
const { server } = await appContext.builder.startDevServer({
|
72
|
-
serverOptions
|
69
|
+
serverOptions,
|
70
|
+
initProdMiddlewares
|
73
71
|
});
|
74
72
|
setServer(server);
|
75
73
|
}
|
@@ -1,19 +1,23 @@
|
|
1
1
|
import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
|
2
|
-
import
|
2
|
+
import { createProdServer } from "@modern-js/prod-server";
|
3
3
|
import { printInstructions } from "../utils/printInstructions";
|
4
|
-
import { injectDataLoaderPlugin } from "../utils/createServer";
|
5
4
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
6
5
|
const start = async (api) => {
|
7
6
|
var _userConfig_source, _userConfig_output_distPath;
|
8
7
|
const appContext = api.useAppContext();
|
9
8
|
const userConfig = api.useResolvedConfigContext();
|
10
9
|
const hookRunners = api.useHookRunners();
|
11
|
-
const { appDirectory, port, serverConfigFile, metaName } = appContext;
|
10
|
+
const { distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes } = appContext;
|
12
11
|
logger.info(`Starting production server...`);
|
13
12
|
const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
|
13
|
+
let runMode;
|
14
|
+
if (apiOnly) {
|
15
|
+
runMode = "apiOnly";
|
16
|
+
}
|
14
17
|
const serverInternalPlugins = await getServerInternalPlugins(api);
|
15
|
-
const app = await
|
16
|
-
|
18
|
+
const app = await createProdServer({
|
19
|
+
metaName,
|
20
|
+
pwd: distDirectory,
|
17
21
|
config: {
|
18
22
|
...userConfig,
|
19
23
|
dev: userConfig.dev,
|
@@ -22,20 +26,18 @@ const start = async (api) => {
|
|
22
26
|
...userConfig.output || {}
|
23
27
|
}
|
24
28
|
},
|
29
|
+
routes: serverRoutes,
|
25
30
|
appContext: {
|
26
|
-
|
31
|
+
appDirectory,
|
27
32
|
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
28
33
|
apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
29
34
|
lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
30
35
|
},
|
31
36
|
serverConfigFile,
|
32
|
-
internalPlugins:
|
33
|
-
|
37
|
+
internalPlugins: serverInternalPlugins,
|
38
|
+
runMode
|
34
39
|
});
|
35
|
-
app.listen(port, async (
|
36
|
-
if (err) {
|
37
|
-
throw err;
|
38
|
-
}
|
40
|
+
app.listen(port, async () => {
|
39
41
|
await printInstructions(hookRunners, appContext, userConfig);
|
40
42
|
});
|
41
43
|
};
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { createDevServer } from "@modern-js/server";
|
2
|
+
import { initProdMiddlewares } from "@modern-js/prod-server";
|
2
3
|
let server = null;
|
3
4
|
const getServer = () => server;
|
4
5
|
const setServer = (newServer) => {
|
@@ -6,32 +7,20 @@ const setServer = (newServer) => {
|
|
6
7
|
};
|
7
8
|
const closeServer = async () => {
|
8
9
|
if (server) {
|
9
|
-
|
10
|
+
server.close();
|
10
11
|
server = null;
|
11
12
|
}
|
12
13
|
};
|
13
14
|
const createServer = async (options) => {
|
14
15
|
if (server) {
|
15
|
-
|
16
|
+
server.close();
|
16
17
|
}
|
17
|
-
server =
|
18
|
-
|
19
|
-
return app;
|
20
|
-
};
|
21
|
-
const injectDataLoaderPlugin = (internalPlugins) => {
|
22
|
-
const DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
|
23
|
-
return {
|
24
|
-
...internalPlugins,
|
25
|
-
"@modern-js/plugin-data-loader": {
|
26
|
-
path: DataLoaderPlugin,
|
27
|
-
forced: true
|
28
|
-
}
|
29
|
-
};
|
18
|
+
server = await createDevServer(options, initProdMiddlewares);
|
19
|
+
return server;
|
30
20
|
};
|
31
21
|
export {
|
32
22
|
closeServer,
|
33
23
|
createServer,
|
34
24
|
getServer,
|
35
|
-
injectDataLoaderPlugin,
|
36
25
|
setServer
|
37
26
|
};
|
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node/http" />
|
3
|
+
/// <reference types="@modern-js/server-core/dist/types/core/server" />
|
4
|
+
/// <reference types="@modern-js/server-core/src/core/server" />
|
5
|
+
import type { Server } from 'node:http';
|
6
|
+
import { ModernDevServerOptions } from '@modern-js/server';
|
7
|
+
export declare const getServer: () => Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | null;
|
4
8
|
export declare const setServer: (newServer: Server) => void;
|
5
9
|
export declare const closeServer: () => Promise<void>;
|
6
10
|
export declare const createServer: (options: ModernDevServerOptions) => Promise<Server>;
|
7
|
-
export declare const injectDataLoaderPlugin: (internalPlugins: InternalPlugins) => {
|
8
|
-
'@modern-js/plugin-data-loader': {
|
9
|
-
path: string;
|
10
|
-
forced: boolean;
|
11
|
-
};
|
12
|
-
};
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.48.
|
18
|
+
"version": "2.48.5-alpha.0",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -77,18 +77,18 @@
|
|
77
77
|
"esbuild": "0.17.19",
|
78
78
|
"@swc/helpers": "0.5.3",
|
79
79
|
"@modern-js/uni-builder": "2.48.4",
|
80
|
-
"@modern-js/core": "2.48.4",
|
81
|
-
"@modern-js/node-bundle-require": "2.48.4",
|
82
80
|
"@modern-js/plugin": "2.48.4",
|
83
|
-
"@modern-js/
|
81
|
+
"@modern-js/core": "2.48.4",
|
84
82
|
"@modern-js/plugin-i18n": "2.48.4",
|
83
|
+
"@modern-js/node-bundle-require": "2.48.4",
|
85
84
|
"@modern-js/plugin-lint": "2.48.4",
|
85
|
+
"@modern-js/prod-server": "2.48.4",
|
86
86
|
"@modern-js/server": "2.48.4",
|
87
87
|
"@modern-js/types": "2.48.4",
|
88
|
-
"@modern-js/server-utils": "2.48.4",
|
89
|
-
"@modern-js/prod-server": "2.48.4",
|
90
88
|
"@modern-js/utils": "2.48.4",
|
91
|
-
"@modern-js/
|
89
|
+
"@modern-js/plugin-data-loader": "2.48.4",
|
90
|
+
"@modern-js/server-utils": "2.48.5-alpha.0",
|
91
|
+
"@modern-js/server-core": "2.48.5-alpha.1"
|
92
92
|
},
|
93
93
|
"devDependencies": {
|
94
94
|
"@rsbuild/plugin-swc": "0.5.4",
|