@modern-js/app-tools 2.49.3-alpha.0 → 2.49.3-alpha.10
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/dist/cjs/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/locale/en.js +1 -2
- package/dist/cjs/locale/zh.js +1 -2
- package/dist/cjs/plugins/deploy/index.js +55 -26
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +36 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +57 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +55 -0
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/index.js +1 -1
- package/dist/esm/locale/en.js +1 -2
- package/dist/esm/locale/zh.js +1 -2
- package/dist/esm/plugins/deploy/index.js +120 -61
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +99 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +47 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +197 -0
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/index.js +1 -1
- package/dist/esm-node/locale/en.js +1 -2
- package/dist/esm-node/locale/zh.js +1 -2
- package/dist/esm-node/plugins/deploy/index.js +55 -26
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +35 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +23 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +63 -0
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/locale/en.d.ts +0 -1
- package/dist/types/locale/index.d.ts +0 -2
- package/dist/types/locale/zh.d.ts +0 -1
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +1 -0
- package/dist/types/plugins/deploy/{entrys → platforms}/vercel.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/utils/routes.d.ts +3 -3
- package/dist/types/utils/types.d.ts +0 -1
- package/package.json +10 -10
- package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -94
- package/dist/esm/plugins/deploy/entrys/vercel.js +0 -40
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -70
- /package/dist/cjs/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/cjs/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/esm/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/esm/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/esm-node/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/esm-node/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/types/plugins/deploy/{entrys → platforms}/netlify.d.ts +0 -0
- /package/dist/types/plugins/deploy/{entrys → platforms}/node.d.ts +0 -0
@@ -3,6 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
4
4
|
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
5
5
|
import { provider } from "std-env";
|
6
|
+
import { isMainEntry } from "../../utils/routes";
|
6
7
|
import { getProjectUsage } from "./utils";
|
7
8
|
import { handleDependencies } from "./dependencies";
|
8
9
|
function deploy_default() {
|
@@ -15,22 +16,19 @@ function deploy_default() {
|
|
15
16
|
setup: function(api) {
|
16
17
|
var deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
17
18
|
return {
|
18
|
-
beforeDeploy: function beforeDeploy(
|
19
|
+
beforeDeploy: function beforeDeploy() {
|
19
20
|
return _async_to_generator(function() {
|
20
|
-
var
|
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;
|
21
22
|
return _ts_generator(this, function(_state) {
|
22
23
|
switch (_state.label) {
|
23
24
|
case 0:
|
24
|
-
outputPath = options.output;
|
25
25
|
appContext = api.useAppContext();
|
26
|
+
modernConfig = api.useResolvedConfigContext();
|
27
|
+
mainEntryName = modernConfig.source.mainEntryName;
|
26
28
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
|
27
29
|
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
28
30
|
needModernServer = useSSR || useAPI || useWebServer;
|
29
|
-
|
30
|
-
outputDirectory = path.resolve(appDirectory, ".output");
|
31
|
-
if (outputPath) {
|
32
|
-
outputDirectory = path.isAbsolute(outputPath) ? outputPath : path.resolve(outputPath);
|
33
|
-
}
|
31
|
+
outputDirectory = path.join(appDirectory, ".output");
|
34
32
|
funcsDirectory = outputDirectory;
|
35
33
|
staticDirectory = path.join(outputDirectory, "static");
|
36
34
|
if (!(deployTarget === "node"))
|
@@ -52,17 +50,79 @@ function deploy_default() {
|
|
52
50
|
_state.sent();
|
53
51
|
_state.label = 3;
|
54
52
|
case 3:
|
53
|
+
if (!(deployTarget === "netlify"))
|
54
|
+
return [
|
55
|
+
3,
|
56
|
+
8
|
57
|
+
];
|
58
|
+
netlifyOutput = path.join(appDirectory, ".netlify");
|
59
|
+
funcsDirectory = path.join(netlifyOutput, "functions");
|
60
|
+
routes = [];
|
61
|
+
if (!needModernServer) {
|
62
|
+
entrypoints.forEach(function(entry) {
|
63
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
64
|
+
routes.push({
|
65
|
+
src: "/".concat(isMain ? "" : "".concat(entry.entryName, "/"), "*"),
|
66
|
+
dest: "/html/".concat(entry.entryName, "/index.html"),
|
67
|
+
status: 200
|
68
|
+
});
|
69
|
+
});
|
70
|
+
} else {
|
71
|
+
routes.push({
|
72
|
+
src: "/*",
|
73
|
+
dest: "/.netlify/functions/index",
|
74
|
+
status: 200
|
75
|
+
});
|
76
|
+
throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
|
77
|
+
}
|
78
|
+
console.log("routes", routes, needModernServer);
|
79
|
+
redirectContent = routes.map(function(route) {
|
80
|
+
return "".concat(route.src, " ").concat(route.dest, " ").concat(route.status);
|
81
|
+
}).join("\n");
|
82
|
+
console.log("redirectContent", redirectContent);
|
83
|
+
return [
|
84
|
+
4,
|
85
|
+
fse.remove(outputDirectory)
|
86
|
+
];
|
87
|
+
case 4:
|
88
|
+
_state.sent();
|
89
|
+
return [
|
90
|
+
4,
|
91
|
+
fse.ensureDir(funcsDirectory)
|
92
|
+
];
|
93
|
+
case 5:
|
94
|
+
_state.sent();
|
95
|
+
return [
|
96
|
+
4,
|
97
|
+
fse.copy(distDirectory, funcsDirectory, {
|
98
|
+
filter: function(src) {
|
99
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
100
|
+
return !src.includes(distStaticDirectory);
|
101
|
+
}
|
102
|
+
})
|
103
|
+
];
|
104
|
+
case 6:
|
105
|
+
_state.sent();
|
106
|
+
redirectFilePath = path.join(distDirectory, "_redirects");
|
107
|
+
return [
|
108
|
+
4,
|
109
|
+
fse.writeFile(redirectFilePath, redirectContent)
|
110
|
+
];
|
111
|
+
case 7:
|
112
|
+
_state.sent();
|
113
|
+
_state.label = 8;
|
114
|
+
case 8:
|
55
115
|
if (!(deployTarget === "vercel"))
|
56
116
|
return [
|
57
117
|
3,
|
58
|
-
|
118
|
+
18
|
59
119
|
];
|
60
120
|
vercelOutput = path.join(appDirectory, ".vercel");
|
61
121
|
return [
|
62
122
|
4,
|
63
123
|
fse.remove(vercelOutput)
|
64
124
|
];
|
65
|
-
case
|
125
|
+
case 9:
|
66
126
|
_state.sent();
|
67
127
|
outputDirectory = path.join(vercelOutput, "output");
|
68
128
|
config = {
|
@@ -82,8 +142,9 @@ function deploy_default() {
|
|
82
142
|
};
|
83
143
|
if (!needModernServer) {
|
84
144
|
entrypoints.forEach(function(entry) {
|
145
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
85
146
|
config.routes.push({
|
86
|
-
src: "/".concat(entry.entryName, "(?:/.*)?"),
|
147
|
+
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
87
148
|
headers: {
|
88
149
|
"cache-control": "s-maxage=0"
|
89
150
|
},
|
@@ -100,7 +161,7 @@ function deploy_default() {
|
|
100
161
|
4,
|
101
162
|
fse.ensureDir(outputDirectory)
|
102
163
|
];
|
103
|
-
case
|
164
|
+
case 10:
|
104
165
|
_state.sent();
|
105
166
|
return [
|
106
167
|
4,
|
@@ -108,19 +169,19 @@ function deploy_default() {
|
|
108
169
|
spaces: 2
|
109
170
|
})
|
110
171
|
];
|
111
|
-
case
|
172
|
+
case 11:
|
112
173
|
_state.sent();
|
113
174
|
staticDirectory = path.join(outputDirectory, "static/static");
|
114
175
|
return [
|
115
176
|
4,
|
116
177
|
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
117
178
|
];
|
118
|
-
case
|
179
|
+
case 12:
|
119
180
|
_state.sent();
|
120
181
|
if (!!needModernServer)
|
121
182
|
return [
|
122
183
|
3,
|
123
|
-
|
184
|
+
14
|
124
185
|
];
|
125
186
|
destHtmlDirectory = path.join(distDirectory, "html");
|
126
187
|
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
@@ -128,19 +189,19 @@ function deploy_default() {
|
|
128
189
|
4,
|
129
190
|
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
130
191
|
];
|
131
|
-
case
|
192
|
+
case 13:
|
132
193
|
_state.sent();
|
133
194
|
return [
|
134
195
|
3,
|
135
|
-
|
196
|
+
18
|
136
197
|
];
|
137
|
-
case
|
198
|
+
case 14:
|
138
199
|
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
139
200
|
return [
|
140
201
|
4,
|
141
202
|
fse.ensureDir(funcsDirectory)
|
142
203
|
];
|
143
|
-
case
|
204
|
+
case 15:
|
144
205
|
_state.sent();
|
145
206
|
return [
|
146
207
|
4,
|
@@ -151,7 +212,7 @@ function deploy_default() {
|
|
151
212
|
}
|
152
213
|
})
|
153
214
|
];
|
154
|
-
case
|
215
|
+
case 16:
|
155
216
|
_state.sent();
|
156
217
|
return [
|
157
218
|
4,
|
@@ -163,17 +224,10 @@ function deploy_default() {
|
|
163
224
|
supportsResponseStreaming: true
|
164
225
|
})
|
165
226
|
];
|
166
|
-
case
|
227
|
+
case 17:
|
167
228
|
_state.sent();
|
168
|
-
_state.label =
|
169
|
-
case
|
170
|
-
bff = configContext.bff;
|
171
|
-
config1 = {
|
172
|
-
output: {
|
173
|
-
path: "."
|
174
|
-
},
|
175
|
-
bff
|
176
|
-
};
|
229
|
+
_state.label = 18;
|
230
|
+
case 18:
|
177
231
|
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
178
232
|
serverAppContext = {
|
179
233
|
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
@@ -187,88 +241,93 @@ function deploy_default() {
|
|
187
241
|
case "node":
|
188
242
|
return [
|
189
243
|
3,
|
190
|
-
|
244
|
+
19
|
191
245
|
];
|
192
246
|
case "vercel":
|
193
247
|
return [
|
194
248
|
3,
|
195
|
-
|
249
|
+
21
|
196
250
|
];
|
197
251
|
case "netlify":
|
198
252
|
return [
|
199
253
|
3,
|
200
|
-
|
254
|
+
24
|
201
255
|
];
|
202
256
|
}
|
203
257
|
return [
|
204
258
|
3,
|
205
|
-
|
259
|
+
26
|
206
260
|
];
|
207
|
-
case
|
261
|
+
case 19:
|
208
262
|
return [
|
209
263
|
4,
|
210
|
-
import("./
|
264
|
+
import("./platforms/node")
|
211
265
|
];
|
212
|
-
case
|
266
|
+
case 20:
|
213
267
|
genNodeEntry = _state.sent().genNodeEntry;
|
214
268
|
code = genNodeEntry({
|
215
269
|
plugins,
|
216
|
-
config:
|
270
|
+
config: modernConfig,
|
217
271
|
appContext: serverAppContext
|
218
272
|
});
|
219
273
|
return [
|
220
274
|
3,
|
221
|
-
|
275
|
+
27
|
222
276
|
];
|
223
|
-
case
|
277
|
+
case 21:
|
224
278
|
return [
|
225
279
|
4,
|
226
|
-
import("./
|
280
|
+
import("./platforms/vercel")
|
227
281
|
];
|
228
|
-
case
|
282
|
+
case 22:
|
229
283
|
genVercelEntry = _state.sent().genVercelEntry;
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
284
|
+
return [
|
285
|
+
4,
|
286
|
+
genVercelEntry({
|
287
|
+
plugins,
|
288
|
+
config: modernConfig,
|
289
|
+
appContext: serverAppContext
|
290
|
+
})
|
291
|
+
];
|
292
|
+
case 23:
|
293
|
+
code = _state.sent();
|
235
294
|
return [
|
236
295
|
3,
|
237
|
-
|
296
|
+
27
|
238
297
|
];
|
239
|
-
case
|
298
|
+
case 24:
|
240
299
|
return [
|
241
300
|
4,
|
242
|
-
import("./
|
301
|
+
import("./platforms/netlify")
|
243
302
|
];
|
244
|
-
case
|
303
|
+
case 25:
|
245
304
|
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
246
305
|
code = genNetlifyEntry({
|
247
306
|
plugins,
|
248
|
-
config:
|
307
|
+
config: modernConfig,
|
249
308
|
appContext: serverAppContext
|
250
309
|
});
|
251
310
|
return [
|
252
311
|
3,
|
253
|
-
|
312
|
+
27
|
254
313
|
];
|
255
|
-
case
|
314
|
+
case 26:
|
256
315
|
{
|
257
316
|
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
258
317
|
}
|
259
|
-
_state.label =
|
260
|
-
case
|
318
|
+
_state.label = 27;
|
319
|
+
case 27:
|
261
320
|
entryFilePath = path.join(funcsDirectory, "index.js");
|
262
321
|
if (!needModernServer)
|
263
322
|
return [
|
264
323
|
3,
|
265
|
-
|
324
|
+
30
|
266
325
|
];
|
267
326
|
return [
|
268
327
|
4,
|
269
328
|
fse.writeFile(entryFilePath, code)
|
270
329
|
];
|
271
|
-
case
|
330
|
+
case 28:
|
272
331
|
_state.sent();
|
273
332
|
return [
|
274
333
|
4,
|
@@ -276,10 +335,10 @@ function deploy_default() {
|
|
276
335
|
"@modern-js/prod-server"
|
277
336
|
])
|
278
337
|
];
|
279
|
-
case
|
338
|
+
case 29:
|
280
339
|
_state.sent();
|
281
|
-
_state.label =
|
282
|
-
case
|
340
|
+
_state.label = 30;
|
341
|
+
case 30:
|
283
342
|
return [
|
284
343
|
2
|
285
344
|
];
|
@@ -0,0 +1,99 @@
|
|
1
|
+
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
|
2
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
3
|
+
var _ts_generator = require("@swc/helpers/_/_ts_generator");
|
4
|
+
var fs = require("node:fs/promises");
|
5
|
+
var path = require("node:path");
|
6
|
+
var createProdServer = require("@modern-js/prod-server").createProdServer;
|
7
|
+
p_genPluginImportsCode;
|
8
|
+
if (!process.env.NODE_ENV) {
|
9
|
+
process.env.NODE_ENV = "production";
|
10
|
+
}
|
11
|
+
function loadRoutes(routeFilepath) {
|
12
|
+
return _loadRoutes.apply(this, arguments);
|
13
|
+
}
|
14
|
+
function _loadRoutes() {
|
15
|
+
_loadRoutes = _async_to_generator._(function(routeFilepath) {
|
16
|
+
var content, routeSpec, error;
|
17
|
+
return _ts_generator._(this, function(_state) {
|
18
|
+
switch (_state.label) {
|
19
|
+
case 0:
|
20
|
+
_state.trys.push([
|
21
|
+
0,
|
22
|
+
3,
|
23
|
+
,
|
24
|
+
4
|
25
|
+
]);
|
26
|
+
return [
|
27
|
+
4,
|
28
|
+
fs.access(routeFilepath)
|
29
|
+
];
|
30
|
+
case 1:
|
31
|
+
_state.sent();
|
32
|
+
return [
|
33
|
+
4,
|
34
|
+
fs.readFile(routeFilepath, "utf-8")
|
35
|
+
];
|
36
|
+
case 2:
|
37
|
+
content = _state.sent();
|
38
|
+
routeSpec = JSON.parse(content);
|
39
|
+
return [
|
40
|
+
2,
|
41
|
+
routeSpec.routes || []
|
42
|
+
];
|
43
|
+
case 3:
|
44
|
+
error = _state.sent();
|
45
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
46
|
+
return [
|
47
|
+
2,
|
48
|
+
[]
|
49
|
+
];
|
50
|
+
case 4:
|
51
|
+
return [
|
52
|
+
2
|
53
|
+
];
|
54
|
+
}
|
55
|
+
});
|
56
|
+
});
|
57
|
+
return _loadRoutes.apply(this, arguments);
|
58
|
+
}
|
59
|
+
function main() {
|
60
|
+
return _main.apply(this, arguments);
|
61
|
+
}
|
62
|
+
function _main() {
|
63
|
+
_main = _async_to_generator._(function() {
|
64
|
+
var routeFilepath, routes, dynamicProdOptions, prodServerOptions, app, port;
|
65
|
+
return _ts_generator._(this, function(_state) {
|
66
|
+
switch (_state.label) {
|
67
|
+
case 0:
|
68
|
+
routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
69
|
+
return [
|
70
|
+
4,
|
71
|
+
loadRoutes(routeFilepath)
|
72
|
+
];
|
73
|
+
case 1:
|
74
|
+
routes = _state.sent();
|
75
|
+
dynamicProdOptions = p_dynamicProdOptions;
|
76
|
+
prodServerOptions = _object_spread._({
|
77
|
+
pwd: __dirname,
|
78
|
+
routes,
|
79
|
+
disableCustomHook: true
|
80
|
+
}, dynamicProdOptions);
|
81
|
+
return [
|
82
|
+
4,
|
83
|
+
createProdServer(prodServerOptions)
|
84
|
+
];
|
85
|
+
case 2:
|
86
|
+
app = _state.sent();
|
87
|
+
port = process.env.PORT || 8080;
|
88
|
+
app.listen(port, function() {
|
89
|
+
console.log("\\x1b[32mServer is listening on port", port, "\\x1b[0m");
|
90
|
+
});
|
91
|
+
return [
|
92
|
+
2
|
93
|
+
];
|
94
|
+
}
|
95
|
+
});
|
96
|
+
});
|
97
|
+
return _main.apply(this, arguments);
|
98
|
+
}
|
99
|
+
main();
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
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, getPluginsCode, severAppContextTemplate } from "../utils";
|
6
|
+
function genVercelEntry() {
|
7
|
+
return _genVercelEntry.apply(this, arguments);
|
8
|
+
}
|
9
|
+
function _genVercelEntry() {
|
10
|
+
_genVercelEntry = _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
|
+
output: {
|
19
|
+
path: "."
|
20
|
+
}
|
21
|
+
};
|
22
|
+
pluginImportCode = genPluginImportsCode(plugins || []);
|
23
|
+
dynamicProdOptions = {
|
24
|
+
config: "".concat(JSON.stringify(config || defaultConfig)),
|
25
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
26
|
+
plugins: "".concat(getPluginsCode(plugins || [])),
|
27
|
+
appContext: "".concat(appContext ? severAppContextTemplate(appContext) : "undefined")
|
28
|
+
};
|
29
|
+
return [
|
30
|
+
4,
|
31
|
+
fse.readFile(path.join(__dirname, "./vercelEntry.js"))
|
32
|
+
];
|
33
|
+
case 1:
|
34
|
+
entryCode = _state.sent().toString();
|
35
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions));
|
36
|
+
return [
|
37
|
+
2,
|
38
|
+
entryCode
|
39
|
+
];
|
40
|
+
}
|
41
|
+
});
|
42
|
+
});
|
43
|
+
return _genVercelEntry.apply(this, arguments);
|
44
|
+
}
|
45
|
+
export {
|
46
|
+
genVercelEntry
|
47
|
+
};
|
@@ -0,0 +1,197 @@
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
4
|
+
};
|
5
|
+
var require_vercelEntry = __commonJS({
|
6
|
+
"src/plugins/deploy/platforms/vercelEntry.js"(exports, module) {
|
7
|
+
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
|
8
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
9
|
+
var _ts_generator = require("@swc/helpers/_/_ts_generator");
|
10
|
+
var fs = require("node:fs/promises");
|
11
|
+
var path = require("node:path");
|
12
|
+
var createProdServer = require("@modern-js/prod-server").createProdServer;
|
13
|
+
p_genPluginImportsCode;
|
14
|
+
if (!process.env.NODE_ENV) {
|
15
|
+
process.env.NODE_ENV = "production";
|
16
|
+
}
|
17
|
+
var requestHandler = null;
|
18
|
+
var handlerCreationPromise = null;
|
19
|
+
function loadRoutes(routeFilepath) {
|
20
|
+
return _loadRoutes.apply(this, arguments);
|
21
|
+
}
|
22
|
+
function _loadRoutes() {
|
23
|
+
_loadRoutes = _async_to_generator._(function(routeFilepath) {
|
24
|
+
var content, routeSpec, error;
|
25
|
+
return _ts_generator._(this, function(_state) {
|
26
|
+
switch (_state.label) {
|
27
|
+
case 0:
|
28
|
+
_state.trys.push([
|
29
|
+
0,
|
30
|
+
3,
|
31
|
+
,
|
32
|
+
4
|
33
|
+
]);
|
34
|
+
return [
|
35
|
+
4,
|
36
|
+
fs.access(routeFilepath)
|
37
|
+
];
|
38
|
+
case 1:
|
39
|
+
_state.sent();
|
40
|
+
return [
|
41
|
+
4,
|
42
|
+
fs.readFile(routeFilepath, "utf-8")
|
43
|
+
];
|
44
|
+
case 2:
|
45
|
+
content = _state.sent();
|
46
|
+
routeSpec = JSON.parse(content);
|
47
|
+
return [
|
48
|
+
2,
|
49
|
+
routeSpec.routes || []
|
50
|
+
];
|
51
|
+
case 3:
|
52
|
+
error = _state.sent();
|
53
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
54
|
+
return [
|
55
|
+
2,
|
56
|
+
[]
|
57
|
+
];
|
58
|
+
case 4:
|
59
|
+
return [
|
60
|
+
2
|
61
|
+
];
|
62
|
+
}
|
63
|
+
});
|
64
|
+
});
|
65
|
+
return _loadRoutes.apply(this, arguments);
|
66
|
+
}
|
67
|
+
function initServer() {
|
68
|
+
return _initServer.apply(this, arguments);
|
69
|
+
}
|
70
|
+
function _initServer() {
|
71
|
+
_initServer = _async_to_generator._(function() {
|
72
|
+
var routeFilepath, routes, dynamicProdOptions, prodServerOptions, app;
|
73
|
+
return _ts_generator._(this, function(_state) {
|
74
|
+
switch (_state.label) {
|
75
|
+
case 0:
|
76
|
+
routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
77
|
+
return [
|
78
|
+
4,
|
79
|
+
loadRoutes(routeFilepath)
|
80
|
+
];
|
81
|
+
case 1:
|
82
|
+
routes = _state.sent();
|
83
|
+
dynamicProdOptions = p_dynamicProdOptions;
|
84
|
+
prodServerOptions = _object_spread._({
|
85
|
+
pwd: __dirname,
|
86
|
+
routes,
|
87
|
+
disableCustomHook: true
|
88
|
+
}, dynamicProdOptions);
|
89
|
+
return [
|
90
|
+
4,
|
91
|
+
createProdServer(prodServerOptions)
|
92
|
+
];
|
93
|
+
case 2:
|
94
|
+
app = _state.sent();
|
95
|
+
return [
|
96
|
+
2,
|
97
|
+
app.getRequestListener()
|
98
|
+
];
|
99
|
+
}
|
100
|
+
});
|
101
|
+
});
|
102
|
+
return _initServer.apply(this, arguments);
|
103
|
+
}
|
104
|
+
function createHandler() {
|
105
|
+
return _createHandler.apply(this, arguments);
|
106
|
+
}
|
107
|
+
function _createHandler() {
|
108
|
+
_createHandler = _async_to_generator._(function() {
|
109
|
+
return _ts_generator._(this, function(_state) {
|
110
|
+
switch (_state.label) {
|
111
|
+
case 0:
|
112
|
+
if (!handlerCreationPromise) {
|
113
|
+
handlerCreationPromise = _async_to_generator._(function() {
|
114
|
+
var error;
|
115
|
+
return _ts_generator._(this, function(_state2) {
|
116
|
+
switch (_state2.label) {
|
117
|
+
case 0:
|
118
|
+
_state2.trys.push([
|
119
|
+
0,
|
120
|
+
2,
|
121
|
+
,
|
122
|
+
3
|
123
|
+
]);
|
124
|
+
return [
|
125
|
+
4,
|
126
|
+
initServer()
|
127
|
+
];
|
128
|
+
case 1:
|
129
|
+
requestHandler = _state2.sent();
|
130
|
+
return [
|
131
|
+
3,
|
132
|
+
3
|
133
|
+
];
|
134
|
+
case 2:
|
135
|
+
error = _state2.sent();
|
136
|
+
console.error("Error creating server:", error);
|
137
|
+
process.exit(1);
|
138
|
+
return [
|
139
|
+
3,
|
140
|
+
3
|
141
|
+
];
|
142
|
+
case 3:
|
143
|
+
return [
|
144
|
+
2
|
145
|
+
];
|
146
|
+
}
|
147
|
+
});
|
148
|
+
})();
|
149
|
+
}
|
150
|
+
return [
|
151
|
+
4,
|
152
|
+
handlerCreationPromise
|
153
|
+
];
|
154
|
+
case 1:
|
155
|
+
_state.sent();
|
156
|
+
return [
|
157
|
+
2,
|
158
|
+
requestHandler
|
159
|
+
];
|
160
|
+
}
|
161
|
+
});
|
162
|
+
});
|
163
|
+
return _createHandler.apply(this, arguments);
|
164
|
+
}
|
165
|
+
createHandler();
|
166
|
+
module.exports = function() {
|
167
|
+
var _ref = _async_to_generator._(function(req, res) {
|
168
|
+
return _ts_generator._(this, function(_state) {
|
169
|
+
switch (_state.label) {
|
170
|
+
case 0:
|
171
|
+
if (!!requestHandler)
|
172
|
+
return [
|
173
|
+
3,
|
174
|
+
2
|
175
|
+
];
|
176
|
+
return [
|
177
|
+
4,
|
178
|
+
createHandler()
|
179
|
+
];
|
180
|
+
case 1:
|
181
|
+
_state.sent();
|
182
|
+
_state.label = 2;
|
183
|
+
case 2:
|
184
|
+
return [
|
185
|
+
2,
|
186
|
+
requestHandler(req, res)
|
187
|
+
];
|
188
|
+
}
|
189
|
+
});
|
190
|
+
});
|
191
|
+
return function(req, res) {
|
192
|
+
return _ref.apply(this, arguments);
|
193
|
+
};
|
194
|
+
}();
|
195
|
+
}
|
196
|
+
});
|
197
|
+
export default require_vercelEntry();
|