@modern-js/app-tools 2.49.3-alpha.11 → 2.49.3-alpha.12
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/index.js +6 -12
- package/dist/cjs/plugins/deploy/platforms/node.js +30 -50
- package/dist/cjs/plugins/deploy/platforms/vercel.js +0 -1
- package/dist/esm/plugins/deploy/index.js +44 -40
- package/dist/esm/plugins/deploy/platforms/node.js +52 -33
- package/dist/esm/plugins/deploy/platforms/vercel.js +0 -1
- package/dist/esm-node/plugins/deploy/index.js +6 -12
- package/dist/esm-node/plugins/deploy/platforms/node.js +22 -52
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -1
- package/dist/types/plugins/deploy/platforms/node.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/platform.d.ts +5 -1
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +5 -2
- package/package.json +8 -8
@@ -163,9 +163,9 @@ var deploy_default = () => ({
|
|
163
163
|
}
|
164
164
|
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
165
165
|
const serverAppContext = {
|
166
|
-
sharedDirectory:
|
167
|
-
apiDirectory:
|
168
|
-
lambdaDirectory:
|
166
|
+
sharedDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, sharedDirectory)),
|
167
|
+
apiDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, apiDirectory)),
|
168
|
+
lambdaDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, lambdaDirectory)),
|
169
169
|
metaName
|
170
170
|
};
|
171
171
|
let code = ``;
|
@@ -173,7 +173,7 @@ var deploy_default = () => ({
|
|
173
173
|
switch (deployTarget) {
|
174
174
|
case "node": {
|
175
175
|
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
|
176
|
-
code = genNodeEntry({
|
176
|
+
code = await genNodeEntry({
|
177
177
|
plugins,
|
178
178
|
config: modernConfig,
|
179
179
|
appContext: serverAppContext
|
@@ -182,22 +182,16 @@ var deploy_default = () => ({
|
|
182
182
|
}
|
183
183
|
case "vercel": {
|
184
184
|
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
|
185
|
-
const serverAppContext2 = {
|
186
|
-
sharedDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, sharedDirectory)),
|
187
|
-
apiDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, apiDirectory)),
|
188
|
-
lambdaDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, lambdaDirectory)),
|
189
|
-
metaName
|
190
|
-
};
|
191
185
|
code = await genVercelEntry({
|
192
186
|
plugins,
|
193
187
|
config: modernConfig,
|
194
|
-
appContext:
|
188
|
+
appContext: serverAppContext
|
195
189
|
});
|
196
190
|
break;
|
197
191
|
}
|
198
192
|
case "netlify": {
|
199
193
|
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
|
200
|
-
code = genNetlifyEntry({
|
194
|
+
code = await genNetlifyEntry({
|
201
195
|
plugins,
|
202
196
|
config: modernConfig,
|
203
197
|
appContext: serverAppContext
|
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
8
|
var __export = (target, all) => {
|
7
9
|
for (var name in all)
|
@@ -15,15 +17,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
}
|
16
18
|
return to;
|
17
19
|
};
|
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
|
+
));
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
29
|
var node_exports = {};
|
20
30
|
__export(node_exports, {
|
21
31
|
genNodeEntry: () => genNodeEntry
|
22
32
|
});
|
23
33
|
module.exports = __toCommonJS(node_exports);
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
24
35
|
var import_utils = require("@modern-js/utils");
|
25
36
|
var import_utils2 = require("../utils");
|
26
|
-
function genNodeEntry({ config, plugins, appContext } = {}) {
|
37
|
+
async function genNodeEntry({ config, plugins, appContext } = {}) {
|
27
38
|
const defaultConfig = {
|
28
39
|
server: {
|
29
40
|
port: 8080
|
@@ -32,55 +43,24 @@ function genNodeEntry({ config, plugins, appContext } = {}) {
|
|
32
43
|
path: "."
|
33
44
|
}
|
34
45
|
};
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
const routeSpec = JSON.parse(content);
|
54
|
-
routes = routeSpec.routes;
|
55
|
-
} catch (error) {
|
56
|
-
console.warn('route.json not found, continuing with empty routes.');
|
57
|
-
}
|
58
|
-
|
59
|
-
const prodServerOptions = {
|
60
|
-
pwd: __dirname,
|
61
|
-
routes,
|
62
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
63
|
-
serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
|
64
|
-
plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
|
65
|
-
appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
|
66
|
-
disableCustomHook: true
|
67
|
-
}
|
68
|
-
|
69
|
-
const app = await createProdServer(prodServerOptions)
|
70
|
-
|
71
|
-
const port = process.env.PORT || 3000;
|
72
|
-
|
73
|
-
app.listen(port, () => {
|
74
|
-
console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');
|
75
|
-
});
|
76
|
-
} catch(error) {
|
77
|
-
console.error(error);
|
78
|
-
process.exit(1);
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
main();
|
83
|
-
`;
|
46
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
47
|
+
const dynamicProdOptions = {
|
48
|
+
config: config || defaultConfig,
|
49
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
50
|
+
plugins,
|
51
|
+
appContext: appContext ? {
|
52
|
+
sharedDirectory: appContext.sharedDirectory,
|
53
|
+
apiDirectory: appContext.apiDirectory,
|
54
|
+
lambdaDirectory: appContext.lambdaDirectory
|
55
|
+
} : "undefined"
|
56
|
+
};
|
57
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
58
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace(
|
59
|
+
"p_dynamicProdOptions",
|
60
|
+
// JSON.stringify(dynamicProdOptions),
|
61
|
+
JSON.stringify(dynamicProdOptions)
|
62
|
+
);
|
63
|
+
return entryCode;
|
84
64
|
}
|
85
65
|
// Annotate the CommonJS export names for ESM import in node:
|
86
66
|
0 && (module.exports = {
|
@@ -40,7 +40,6 @@ async function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
40
40
|
path: "."
|
41
41
|
}
|
42
42
|
};
|
43
|
-
console.log("appContext.sharedDirectory", appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory);
|
44
43
|
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
45
44
|
const dynamicProdOptions = {
|
46
45
|
config: config || defaultConfig,
|
@@ -18,7 +18,7 @@ function deploy_default() {
|
|
18
18
|
return {
|
19
19
|
beforeDeploy: function beforeDeploy() {
|
20
20
|
return _async_to_generator(function() {
|
21
|
-
var appContext, modernConfig, mainEntryName, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, outputDirectory, funcsDirectory, staticDirectory, netlifyOutput, routes, redirectContent, redirectFilePath, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, plugins, serverAppContext, code, genNodeEntry, genVercelEntry,
|
21
|
+
var appContext, modernConfig, mainEntryName, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, outputDirectory, funcsDirectory, staticDirectory, netlifyOutput, routes, redirectContent, redirectFilePath, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
|
22
22
|
return _ts_generator(this, function(_state) {
|
23
23
|
switch (_state.label) {
|
24
24
|
case 0:
|
@@ -230,9 +230,9 @@ function deploy_default() {
|
|
230
230
|
case 18:
|
231
231
|
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
232
232
|
serverAppContext = {
|
233
|
-
sharedDirectory:
|
234
|
-
apiDirectory:
|
235
|
-
lambdaDirectory:
|
233
|
+
sharedDirectory: path.join(__dirname, path.relative(appDirectory, sharedDirectory)),
|
234
|
+
apiDirectory: path.join(__dirname, path.relative(appDirectory, apiDirectory)),
|
235
|
+
lambdaDirectory: path.join(__dirname, path.relative(appDirectory, lambdaDirectory)),
|
236
236
|
metaName
|
237
237
|
};
|
238
238
|
code = "";
|
@@ -246,17 +246,17 @@ function deploy_default() {
|
|
246
246
|
case "vercel":
|
247
247
|
return [
|
248
248
|
3,
|
249
|
-
|
249
|
+
22
|
250
250
|
];
|
251
251
|
case "netlify":
|
252
252
|
return [
|
253
253
|
3,
|
254
|
-
|
254
|
+
25
|
255
255
|
];
|
256
256
|
}
|
257
257
|
return [
|
258
258
|
3,
|
259
|
-
|
259
|
+
28
|
260
260
|
];
|
261
261
|
case 19:
|
262
262
|
return [
|
@@ -265,75 +265,79 @@ function deploy_default() {
|
|
265
265
|
];
|
266
266
|
case 20:
|
267
267
|
genNodeEntry = _state.sent().genNodeEntry;
|
268
|
-
code = genNodeEntry({
|
269
|
-
plugins,
|
270
|
-
config: modernConfig,
|
271
|
-
appContext: serverAppContext
|
272
|
-
});
|
273
268
|
return [
|
274
|
-
|
275
|
-
|
269
|
+
4,
|
270
|
+
genNodeEntry({
|
271
|
+
plugins,
|
272
|
+
config: modernConfig,
|
273
|
+
appContext: serverAppContext
|
274
|
+
})
|
276
275
|
];
|
277
276
|
case 21:
|
277
|
+
code = _state.sent();
|
278
|
+
return [
|
279
|
+
3,
|
280
|
+
29
|
281
|
+
];
|
282
|
+
case 22:
|
278
283
|
return [
|
279
284
|
4,
|
280
285
|
import("./platforms/vercel")
|
281
286
|
];
|
282
|
-
case
|
287
|
+
case 23:
|
283
288
|
genVercelEntry = _state.sent().genVercelEntry;
|
284
|
-
serverAppContext1 = {
|
285
|
-
sharedDirectory: path.join(__dirname, path.relative(appDirectory, sharedDirectory)),
|
286
|
-
apiDirectory: path.join(__dirname, path.relative(appDirectory, apiDirectory)),
|
287
|
-
lambdaDirectory: path.join(__dirname, path.relative(appDirectory, lambdaDirectory)),
|
288
|
-
metaName
|
289
|
-
};
|
290
289
|
return [
|
291
290
|
4,
|
292
291
|
genVercelEntry({
|
293
292
|
plugins,
|
294
293
|
config: modernConfig,
|
295
|
-
appContext:
|
294
|
+
appContext: serverAppContext
|
296
295
|
})
|
297
296
|
];
|
298
|
-
case
|
297
|
+
case 24:
|
299
298
|
code = _state.sent();
|
300
299
|
return [
|
301
300
|
3,
|
302
|
-
|
301
|
+
29
|
303
302
|
];
|
304
|
-
case
|
303
|
+
case 25:
|
305
304
|
return [
|
306
305
|
4,
|
307
306
|
import("./platforms/netlify")
|
308
307
|
];
|
309
|
-
case
|
308
|
+
case 26:
|
310
309
|
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
310
|
+
return [
|
311
|
+
4,
|
312
|
+
genNetlifyEntry({
|
313
|
+
plugins,
|
314
|
+
config: modernConfig,
|
315
|
+
appContext: serverAppContext
|
316
|
+
})
|
317
|
+
];
|
318
|
+
case 27:
|
319
|
+
code = _state.sent();
|
316
320
|
return [
|
317
321
|
3,
|
318
|
-
|
322
|
+
29
|
319
323
|
];
|
320
|
-
case
|
324
|
+
case 28:
|
321
325
|
{
|
322
326
|
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
323
327
|
}
|
324
|
-
_state.label =
|
325
|
-
case
|
328
|
+
_state.label = 29;
|
329
|
+
case 29:
|
326
330
|
entryFilePath = path.join(funcsDirectory, "index.js");
|
327
331
|
if (!needModernServer)
|
328
332
|
return [
|
329
333
|
3,
|
330
|
-
|
334
|
+
32
|
331
335
|
];
|
332
336
|
return [
|
333
337
|
4,
|
334
338
|
fse.writeFile(entryFilePath, code)
|
335
339
|
];
|
336
|
-
case
|
340
|
+
case 30:
|
337
341
|
_state.sent();
|
338
342
|
return [
|
339
343
|
4,
|
@@ -341,10 +345,10 @@ function deploy_default() {
|
|
341
345
|
"@modern-js/prod-server"
|
342
346
|
])
|
343
347
|
];
|
344
|
-
case
|
348
|
+
case 31:
|
345
349
|
_state.sent();
|
346
|
-
_state.label =
|
347
|
-
case
|
350
|
+
_state.label = 32;
|
351
|
+
case 32:
|
348
352
|
return [
|
349
353
|
2
|
350
354
|
];
|
@@ -1,38 +1,57 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import path from "node:path";
|
4
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
5
|
+
import { genPluginImportsCode } from "../utils";
|
3
6
|
function genNodeEntry() {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
7
|
+
return _genNodeEntry.apply(this, arguments);
|
8
|
+
}
|
9
|
+
function _genNodeEntry() {
|
10
|
+
_genNodeEntry = _async_to_generator(function() {
|
11
|
+
var _ref, config, plugins, appContext, defaultConfig, pluginImportCode, dynamicProdOptions, entryCode;
|
12
|
+
var _arguments = arguments;
|
13
|
+
return _ts_generator(this, function(_state) {
|
14
|
+
switch (_state.label) {
|
15
|
+
case 0:
|
16
|
+
_ref = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
|
17
|
+
defaultConfig = {
|
18
|
+
server: {
|
19
|
+
port: 8080
|
20
|
+
},
|
21
|
+
output: {
|
22
|
+
path: "."
|
23
|
+
}
|
24
|
+
};
|
25
|
+
pluginImportCode = genPluginImportsCode(plugins || []);
|
26
|
+
dynamicProdOptions = {
|
27
|
+
config: config || defaultConfig,
|
28
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
29
|
+
plugins,
|
30
|
+
appContext: appContext ? {
|
31
|
+
sharedDirectory: appContext.sharedDirectory,
|
32
|
+
apiDirectory: appContext.apiDirectory,
|
33
|
+
lambdaDirectory: appContext.lambdaDirectory
|
34
|
+
} : "undefined"
|
35
|
+
};
|
36
|
+
return [
|
37
|
+
4,
|
38
|
+
fse.readFile(path.join(__dirname, "./nodeEntry.js"))
|
39
|
+
];
|
40
|
+
case 1:
|
41
|
+
entryCode = _state.sent().toString();
|
42
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace(
|
43
|
+
"p_dynamicProdOptions",
|
44
|
+
// JSON.stringify(dynamicProdOptions),
|
45
|
+
JSON.stringify(dynamicProdOptions)
|
46
|
+
);
|
47
|
+
return [
|
48
|
+
2,
|
49
|
+
entryCode
|
50
|
+
];
|
30
51
|
}
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
routes,
|
35
|
-
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n const app = await createProdServer(prodServerOptions)\n\n const port = process.env.PORT || 3000;\n\n app.listen(port, () => {\n console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');\n });\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n main();\n ");
|
52
|
+
});
|
53
|
+
});
|
54
|
+
return _genNodeEntry.apply(this, arguments);
|
36
55
|
}
|
37
56
|
export {
|
38
57
|
genNodeEntry
|
@@ -19,7 +19,6 @@ function _genVercelEntry() {
|
|
19
19
|
path: "."
|
20
20
|
}
|
21
21
|
};
|
22
|
-
console.log("appContext.sharedDirectory", appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory);
|
23
22
|
pluginImportCode = genPluginImportsCode(plugins || []);
|
24
23
|
dynamicProdOptions = {
|
25
24
|
config: config || defaultConfig,
|
@@ -130,9 +130,9 @@ var deploy_default = () => ({
|
|
130
130
|
}
|
131
131
|
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
132
132
|
const serverAppContext = {
|
133
|
-
sharedDirectory:
|
134
|
-
apiDirectory:
|
135
|
-
lambdaDirectory:
|
133
|
+
sharedDirectory: path.join(__dirname, path.relative(appDirectory, sharedDirectory)),
|
134
|
+
apiDirectory: path.join(__dirname, path.relative(appDirectory, apiDirectory)),
|
135
|
+
lambdaDirectory: path.join(__dirname, path.relative(appDirectory, lambdaDirectory)),
|
136
136
|
metaName
|
137
137
|
};
|
138
138
|
let code = ``;
|
@@ -140,7 +140,7 @@ var deploy_default = () => ({
|
|
140
140
|
switch (deployTarget) {
|
141
141
|
case "node": {
|
142
142
|
const { genNodeEntry } = await import("./platforms/node");
|
143
|
-
code = genNodeEntry({
|
143
|
+
code = await genNodeEntry({
|
144
144
|
plugins,
|
145
145
|
config: modernConfig,
|
146
146
|
appContext: serverAppContext
|
@@ -149,22 +149,16 @@ var deploy_default = () => ({
|
|
149
149
|
}
|
150
150
|
case "vercel": {
|
151
151
|
const { genVercelEntry } = await import("./platforms/vercel");
|
152
|
-
const serverAppContext2 = {
|
153
|
-
sharedDirectory: path.join(__dirname, path.relative(appDirectory, sharedDirectory)),
|
154
|
-
apiDirectory: path.join(__dirname, path.relative(appDirectory, apiDirectory)),
|
155
|
-
lambdaDirectory: path.join(__dirname, path.relative(appDirectory, lambdaDirectory)),
|
156
|
-
metaName
|
157
|
-
};
|
158
152
|
code = await genVercelEntry({
|
159
153
|
plugins,
|
160
154
|
config: modernConfig,
|
161
|
-
appContext:
|
155
|
+
appContext: serverAppContext
|
162
156
|
});
|
163
157
|
break;
|
164
158
|
}
|
165
159
|
case "netlify": {
|
166
160
|
const { genNetlifyEntry } = await import("./platforms/netlify");
|
167
|
-
code = genNetlifyEntry({
|
161
|
+
code = await genNetlifyEntry({
|
168
162
|
plugins,
|
169
163
|
config: modernConfig,
|
170
164
|
appContext: serverAppContext
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import
|
2
|
-
import {
|
3
|
-
|
1
|
+
import path from "node:path";
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
3
|
+
import { genPluginImportsCode } from "../utils";
|
4
|
+
async function genNodeEntry({ config, plugins, appContext } = {}) {
|
4
5
|
const defaultConfig = {
|
5
6
|
server: {
|
6
7
|
port: 8080
|
@@ -9,55 +10,24 @@ function genNodeEntry({ config, plugins, appContext } = {}) {
|
|
9
10
|
path: "."
|
10
11
|
}
|
11
12
|
};
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
const routeSpec = JSON.parse(content);
|
31
|
-
routes = routeSpec.routes;
|
32
|
-
} catch (error) {
|
33
|
-
console.warn('route.json not found, continuing with empty routes.');
|
34
|
-
}
|
35
|
-
|
36
|
-
const prodServerOptions = {
|
37
|
-
pwd: __dirname,
|
38
|
-
routes,
|
39
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
40
|
-
serverConfigFile: '${DEFAULT_SERVER_CONFIG}',
|
41
|
-
plugins: ${getPluginsCode(plugins || [])},
|
42
|
-
appContext: ${appContext ? severAppContextTemplate(appContext) : "undefined"},
|
43
|
-
disableCustomHook: true
|
44
|
-
}
|
45
|
-
|
46
|
-
const app = await createProdServer(prodServerOptions)
|
47
|
-
|
48
|
-
const port = process.env.PORT || 3000;
|
49
|
-
|
50
|
-
app.listen(port, () => {
|
51
|
-
console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');
|
52
|
-
});
|
53
|
-
} catch(error) {
|
54
|
-
console.error(error);
|
55
|
-
process.exit(1);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
main();
|
60
|
-
`;
|
13
|
+
const pluginImportCode = genPluginImportsCode(plugins || []);
|
14
|
+
const dynamicProdOptions = {
|
15
|
+
config: config || defaultConfig,
|
16
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
17
|
+
plugins,
|
18
|
+
appContext: appContext ? {
|
19
|
+
sharedDirectory: appContext.sharedDirectory,
|
20
|
+
apiDirectory: appContext.apiDirectory,
|
21
|
+
lambdaDirectory: appContext.lambdaDirectory
|
22
|
+
} : "undefined"
|
23
|
+
};
|
24
|
+
let entryCode = (await fse.readFile(path.join(__dirname, "./nodeEntry.js"))).toString();
|
25
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace(
|
26
|
+
"p_dynamicProdOptions",
|
27
|
+
// JSON.stringify(dynamicProdOptions),
|
28
|
+
JSON.stringify(dynamicProdOptions)
|
29
|
+
);
|
30
|
+
return entryCode;
|
61
31
|
}
|
62
32
|
export {
|
63
33
|
genNodeEntry
|
@@ -7,7 +7,6 @@ async function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
7
7
|
path: "."
|
8
8
|
}
|
9
9
|
};
|
10
|
-
console.log("appContext.sharedDirectory", appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory);
|
11
10
|
const pluginImportCode = genPluginImportsCode(plugins || []);
|
12
11
|
const dynamicProdOptions = {
|
13
12
|
config: config || defaultConfig,
|
@@ -1,5 +1,8 @@
|
|
1
|
+
import { NormalizedConfig } from '@modern-js/core';
|
2
|
+
import { AppTools } from '../../../types';
|
3
|
+
import { AppContext } from './platform';
|
1
4
|
export declare function genVercelEntry({ config, plugins, appContext, }?: {
|
2
|
-
config?:
|
5
|
+
config?: NormalizedConfig<AppTools>;
|
3
6
|
plugins?: string[];
|
4
|
-
appContext?:
|
7
|
+
appContext?: AppContext;
|
5
8
|
}): Promise<string>;
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.49.3-alpha.
|
18
|
+
"version": "2.49.3-alpha.12",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -80,20 +80,20 @@
|
|
80
80
|
"mlly": "^1.6.1",
|
81
81
|
"pkg-types": "^1.1.0",
|
82
82
|
"std-env": "^3.7.0",
|
83
|
-
"@modern-js/
|
83
|
+
"@modern-js/node-bundle-require": "2.49.2",
|
84
84
|
"@modern-js/plugin": "2.49.2",
|
85
85
|
"@modern-js/plugin-data-loader": "2.49.2",
|
86
|
+
"@modern-js/plugin-lint": "2.49.2",
|
86
87
|
"@modern-js/plugin-i18n": "2.49.2",
|
88
|
+
"@modern-js/server": "2.49.2",
|
87
89
|
"@modern-js/rsbuild-plugin-esbuild": "2.49.2",
|
88
|
-
"@modern-js/
|
89
|
-
"@modern-js/plugin-lint": "2.49.2",
|
90
|
-
"@modern-js/server-core": "2.49.2",
|
91
|
-
"@modern-js/node-bundle-require": "2.49.2",
|
90
|
+
"@modern-js/core": "2.49.2",
|
92
91
|
"@modern-js/server-utils": "2.49.2",
|
92
|
+
"@modern-js/utils": "2.49.2",
|
93
93
|
"@modern-js/types": "2.49.2",
|
94
|
+
"@modern-js/server-core": "2.49.2",
|
94
95
|
"@modern-js/uni-builder": "2.49.2",
|
95
|
-
"@modern-js/
|
96
|
-
"@modern-js/server": "2.49.2"
|
96
|
+
"@modern-js/prod-server": "2.49.2"
|
97
97
|
},
|
98
98
|
"devDependencies": {
|
99
99
|
"@rsbuild/plugin-swc": "0.6.10",
|