@modern-js/app-tools 2.49.3-alpha.10 → 2.49.3-alpha.2

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