@modern-js/app-tools 2.49.3-alpha.5 → 2.49.3-alpha.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(getServerRoutes_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_fs = __toESM(require("fs"));
36
36
  var import_utils = require("@modern-js/utils");
37
+ var import_routes = require("../utils/routes");
37
38
  var import_utils2 = require("./utils");
38
39
  const applyBaseUrl = (baseUrl, routes) => {
39
40
  if (baseUrl) {
@@ -106,14 +107,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
106
107
  const { packageName } = appContext;
107
108
  const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
108
109
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
109
- const isMainEntry = entryName === (mainEntryName || import_utils.MAIN_ENTRY_NAME);
110
- const entryOptions = (0, import_utils.getEntryOptions)(entryName, isMainEntry, ssr, ssrByEntries, packageName);
110
+ const isMain = (0, import_routes.isMainEntry)(entryName, mainEntryName);
111
+ const entryOptions = (0, import_utils.getEntryOptions)(entryName, isMain, ssr, ssrByEntries, packageName);
111
112
  const isSSR = Boolean(entryOptions);
112
113
  const isWorker = Boolean(workerSSR);
113
114
  const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
114
115
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
115
116
  let route = {
116
- urlPath: `/${isMainEntry ? "" : entryName}`,
117
+ urlPath: `/${isMain ? "" : entryName}`,
117
118
  entryName,
118
119
  entryPath: (0, import_utils.removeLeadingSlash)(import_path.default.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
119
120
  isSPA: true,
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(deploy_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
36
  var import_std_env = require("std-env");
37
+ var import_routes = require("../../utils/routes");
37
38
  var import_utils2 = require("./utils");
38
39
  var import_dependencies = require("./dependencies");
39
40
  var deploy_default = () => ({
@@ -47,6 +48,8 @@ var deploy_default = () => ({
47
48
  return {
48
49
  async beforeDeploy() {
49
50
  const appContext = api.useAppContext();
51
+ const modernConfig = api.useResolvedConfigContext();
52
+ const { source: { mainEntryName } } = modernConfig;
50
53
  const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
51
54
  const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
52
55
  const needModernServer = useSSR || useAPI || useWebServer;
@@ -64,13 +67,27 @@ var deploy_default = () => ({
64
67
  const routes = [];
65
68
  if (!needModernServer) {
66
69
  entrypoints.forEach((entry) => {
70
+ const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
67
71
  routes.push({
68
- src: `/${entry.entryName}(?:/.*)?`,
69
- dest: `/html/${entry.entryName}/index.html`
72
+ src: `/${isMain ? "" : entry.entryName}/*`,
73
+ dest: `/html/${entry.entryName}/index.html`,
74
+ status: 200
70
75
  });
71
76
  });
72
77
  } else {
78
+ routes.push({
79
+ src: `/*`,
80
+ dest: `/.netlify/functions/index`,
81
+ status: 200
82
+ });
73
83
  }
84
+ console.log("routes", routes, needModernServer);
85
+ const redirectContent = routes.map((route) => {
86
+ return `${route.src} ${route.dest} ${route.status}`;
87
+ }).join("\n");
88
+ console.log("redirectContent", redirectContent);
89
+ const redirectFilePath = import_path.default.join(distDirectory, "_redirects");
90
+ await import_utils.fs.writeFile(redirectFilePath, redirectContent);
74
91
  await import_utils.fs.remove(outputDirectory);
75
92
  await import_utils.fs.ensureDir(funcsDirectory);
76
93
  await import_utils.fs.copy(distDirectory, funcsDirectory, {
@@ -101,8 +118,9 @@ var deploy_default = () => ({
101
118
  };
102
119
  if (!needModernServer) {
103
120
  entrypoints.forEach((entry) => {
121
+ const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
104
122
  config2.routes.push({
105
- src: `/${entry.entryName}(?:/.*)?`,
123
+ src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
106
124
  headers: {
107
125
  "cache-control": "s-maxage=0"
108
126
  },
@@ -164,7 +182,7 @@ var deploy_default = () => ({
164
182
  const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/node")));
165
183
  code = genNodeEntry({
166
184
  plugins,
167
- config,
185
+ config: modernConfig,
168
186
  appContext: serverAppContext
169
187
  });
170
188
  break;
@@ -173,7 +191,7 @@ var deploy_default = () => ({
173
191
  const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/vercel")));
174
192
  code = genVercelEntry({
175
193
  plugins,
176
- config,
194
+ config: modernConfig,
177
195
  appContext: serverAppContext
178
196
  });
179
197
  break;
@@ -182,7 +200,7 @@ var deploy_default = () => ({
182
200
  const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/netlify")));
183
201
  code = genNetlifyEntry({
184
202
  plugins,
185
- config,
203
+ config: modernConfig,
186
204
  appContext: serverAppContext
187
205
  });
188
206
  break;
@@ -29,7 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var routes_exports = {};
30
30
  __export(routes_exports, {
31
31
  generateRoutes: () => generateRoutes,
32
- getPathWithoutExt: () => getPathWithoutExt
32
+ getPathWithoutExt: () => getPathWithoutExt,
33
+ isMainEntry: () => isMainEntry
33
34
  });
34
35
  module.exports = __toCommonJS(routes_exports);
35
36
  var import_path = __toESM(require("path"));
@@ -45,8 +46,12 @@ const getPathWithoutExt = (filename) => {
45
46
  const extname = import_path.default.extname(filename);
46
47
  return filename.slice(0, -extname.length);
47
48
  };
49
+ const isMainEntry = (entryName, mainEntryName) => {
50
+ return entryName === (mainEntryName || import_utils.MAIN_ENTRY_NAME);
51
+ };
48
52
  // Annotate the CommonJS export names for ESM import in node:
49
53
  0 && (module.exports = {
50
54
  generateRoutes,
51
- getPathWithoutExt
55
+ getPathWithoutExt,
56
+ isMainEntry
52
57
  });
@@ -4,7 +4,8 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_
4
4
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
5
  import path from "path";
6
6
  import fs from "fs";
7
- import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
7
+ import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
8
+ import { isMainEntry } from "../utils/routes";
8
9
  import { walkDirectory } from "./utils";
9
10
  var applyBaseUrl = function(baseUrl, routes) {
10
11
  if (baseUrl) {
@@ -75,14 +76,14 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
75
76
  var workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
76
77
  var htmlRoutes = entrypoints.reduce(function(previous, param) {
77
78
  var entryName = param.entryName;
78
- var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
79
- var entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
79
+ var isMain = isMainEntry(entryName, mainEntryName);
80
+ var entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
80
81
  var isSSR = Boolean(entryOptions);
81
82
  var isWorker = Boolean(workerSSR);
82
83
  var isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
83
84
  var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
84
85
  var route = {
85
- urlPath: "/".concat(isMainEntry ? "" : entryName),
86
+ urlPath: "/".concat(isMain ? "" : entryName),
86
87
  entryName,
87
88
  entryPath: removeLeadingSlash(path.posix.normalize("".concat(htmlPath, "/").concat(entryName).concat(disableHtmlFolder ? ".html" : "/index.html"))),
88
89
  isSPA: true,
@@ -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() {
@@ -17,11 +18,13 @@ function deploy_default() {
17
18
  return {
18
19
  beforeDeploy: function beforeDeploy() {
19
20
  return _async_to_generator(function() {
20
- var appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, configContext, outputDirectory, funcsDirectory, staticDirectory, netlifyOutput, routes, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, bff, config1, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
21
+ var appContext, modernConfig, mainEntryName, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, configContext, outputDirectory, funcsDirectory, staticDirectory, netlifyOutput, routes, redirectContent, redirectFilePath, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, bff, config1, 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
25
  appContext = api.useAppContext();
26
+ modernConfig = api.useResolvedConfigContext();
27
+ mainEntryName = modernConfig.source.mainEntryName;
25
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;
26
29
  _getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
27
30
  needModernServer = useSSR || useAPI || useWebServer;
@@ -51,31 +54,50 @@ function deploy_default() {
51
54
  if (!(deployTarget === "netlify"))
52
55
  return [
53
56
  3,
54
- 7
57
+ 8
55
58
  ];
56
59
  netlifyOutput = path.join(appDirectory, ".netlify");
57
60
  funcsDirectory = path.join(netlifyOutput, "functions");
58
61
  routes = [];
59
62
  if (!needModernServer) {
60
63
  entrypoints.forEach(function(entry) {
64
+ var isMain = isMainEntry(entry.entryName, mainEntryName);
61
65
  routes.push({
62
- src: "/".concat(entry.entryName, "(?:/.*)?"),
63
- dest: "/html/".concat(entry.entryName, "/index.html")
66
+ src: "/".concat(isMain ? "" : entry.entryName, "/*"),
67
+ dest: "/html/".concat(entry.entryName, "/index.html"),
68
+ status: 200
64
69
  });
65
70
  });
66
71
  } else {
72
+ routes.push({
73
+ src: "/*",
74
+ dest: "/.netlify/functions/index",
75
+ status: 200
76
+ });
67
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
+ redirectFilePath = path.join(distDirectory, "_redirects");
68
84
  return [
69
85
  4,
70
- fse.remove(outputDirectory)
86
+ fse.writeFile(redirectFilePath, redirectContent)
71
87
  ];
72
88
  case 4:
73
89
  _state.sent();
74
90
  return [
75
91
  4,
76
- fse.ensureDir(funcsDirectory)
92
+ fse.remove(outputDirectory)
77
93
  ];
78
94
  case 5:
95
+ _state.sent();
96
+ return [
97
+ 4,
98
+ fse.ensureDir(funcsDirectory)
99
+ ];
100
+ case 6:
79
101
  _state.sent();
80
102
  return [
81
103
  4,
@@ -86,21 +108,21 @@ function deploy_default() {
86
108
  }
87
109
  })
88
110
  ];
89
- case 6:
90
- _state.sent();
91
- _state.label = 7;
92
111
  case 7:
112
+ _state.sent();
113
+ _state.label = 8;
114
+ case 8:
93
115
  if (!(deployTarget === "vercel"))
94
116
  return [
95
117
  3,
96
- 17
118
+ 18
97
119
  ];
98
120
  vercelOutput = path.join(appDirectory, ".vercel");
99
121
  return [
100
122
  4,
101
123
  fse.remove(vercelOutput)
102
124
  ];
103
- case 8:
125
+ case 9:
104
126
  _state.sent();
105
127
  outputDirectory = path.join(vercelOutput, "output");
106
128
  config = {
@@ -120,8 +142,9 @@ function deploy_default() {
120
142
  };
121
143
  if (!needModernServer) {
122
144
  entrypoints.forEach(function(entry) {
145
+ var isMain = isMainEntry(entry.entryName, mainEntryName);
123
146
  config.routes.push({
124
- src: "/".concat(entry.entryName, "(?:/.*)?"),
147
+ src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
125
148
  headers: {
126
149
  "cache-control": "s-maxage=0"
127
150
  },
@@ -138,7 +161,7 @@ function deploy_default() {
138
161
  4,
139
162
  fse.ensureDir(outputDirectory)
140
163
  ];
141
- case 9:
164
+ case 10:
142
165
  _state.sent();
143
166
  return [
144
167
  4,
@@ -146,19 +169,19 @@ function deploy_default() {
146
169
  spaces: 2
147
170
  })
148
171
  ];
149
- case 10:
172
+ case 11:
150
173
  _state.sent();
151
174
  staticDirectory = path.join(outputDirectory, "static/static");
152
175
  return [
153
176
  4,
154
177
  fse.copy(path.join(distDirectory, "static"), staticDirectory)
155
178
  ];
156
- case 11:
179
+ case 12:
157
180
  _state.sent();
158
181
  if (!!needModernServer)
159
182
  return [
160
183
  3,
161
- 13
184
+ 14
162
185
  ];
163
186
  destHtmlDirectory = path.join(distDirectory, "html");
164
187
  outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
@@ -166,19 +189,19 @@ function deploy_default() {
166
189
  4,
167
190
  fse.copy(destHtmlDirectory, outputHtmlDirectory)
168
191
  ];
169
- case 12:
192
+ case 13:
170
193
  _state.sent();
171
194
  return [
172
195
  3,
173
- 17
196
+ 18
174
197
  ];
175
- case 13:
198
+ case 14:
176
199
  funcsDirectory = path.join(outputDirectory, "functions", "index.func");
177
200
  return [
178
201
  4,
179
202
  fse.ensureDir(funcsDirectory)
180
203
  ];
181
- case 14:
204
+ case 15:
182
205
  _state.sent();
183
206
  return [
184
207
  4,
@@ -189,7 +212,7 @@ function deploy_default() {
189
212
  }
190
213
  })
191
214
  ];
192
- case 15:
215
+ case 16:
193
216
  _state.sent();
194
217
  return [
195
218
  4,
@@ -201,10 +224,10 @@ function deploy_default() {
201
224
  supportsResponseStreaming: true
202
225
  })
203
226
  ];
204
- case 16:
205
- _state.sent();
206
- _state.label = 17;
207
227
  case 17:
228
+ _state.sent();
229
+ _state.label = 18;
230
+ case 18:
208
231
  bff = configContext.bff;
209
232
  config1 = {
210
233
  output: {
@@ -225,88 +248,88 @@ function deploy_default() {
225
248
  case "node":
226
249
  return [
227
250
  3,
228
- 18
251
+ 19
229
252
  ];
230
253
  case "vercel":
231
254
  return [
232
255
  3,
233
- 20
256
+ 21
234
257
  ];
235
258
  case "netlify":
236
259
  return [
237
260
  3,
238
- 22
261
+ 23
239
262
  ];
240
263
  }
241
264
  return [
242
265
  3,
243
- 24
266
+ 25
244
267
  ];
245
- case 18:
268
+ case 19:
246
269
  return [
247
270
  4,
248
271
  import("./entrys/node")
249
272
  ];
250
- case 19:
273
+ case 20:
251
274
  genNodeEntry = _state.sent().genNodeEntry;
252
275
  code = genNodeEntry({
253
276
  plugins,
254
- config: config1,
277
+ config: modernConfig,
255
278
  appContext: serverAppContext
256
279
  });
257
280
  return [
258
281
  3,
259
- 25
282
+ 26
260
283
  ];
261
- case 20:
284
+ case 21:
262
285
  return [
263
286
  4,
264
287
  import("./entrys/vercel")
265
288
  ];
266
- case 21:
289
+ case 22:
267
290
  genVercelEntry = _state.sent().genVercelEntry;
268
291
  code = genVercelEntry({
269
292
  plugins,
270
- config: config1,
293
+ config: modernConfig,
271
294
  appContext: serverAppContext
272
295
  });
273
296
  return [
274
297
  3,
275
- 25
298
+ 26
276
299
  ];
277
- case 22:
300
+ case 23:
278
301
  return [
279
302
  4,
280
303
  import("./entrys/netlify")
281
304
  ];
282
- case 23:
305
+ case 24:
283
306
  genNetlifyEntry = _state.sent().genNetlifyEntry;
284
307
  code = genNetlifyEntry({
285
308
  plugins,
286
- config: config1,
309
+ config: modernConfig,
287
310
  appContext: serverAppContext
288
311
  });
289
312
  return [
290
313
  3,
291
- 25
314
+ 26
292
315
  ];
293
- case 24:
316
+ case 25:
294
317
  {
295
318
  code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
296
319
  }
297
- _state.label = 25;
298
- case 25:
320
+ _state.label = 26;
321
+ case 26:
299
322
  entryFilePath = path.join(funcsDirectory, "index.js");
300
323
  if (!needModernServer)
301
324
  return [
302
325
  3,
303
- 28
326
+ 29
304
327
  ];
305
328
  return [
306
329
  4,
307
330
  fse.writeFile(entryFilePath, code)
308
331
  ];
309
- case 26:
332
+ case 27:
310
333
  _state.sent();
311
334
  return [
312
335
  4,
@@ -314,10 +337,10 @@ function deploy_default() {
314
337
  "@modern-js/prod-server"
315
338
  ])
316
339
  ];
317
- case 27:
318
- _state.sent();
319
- _state.label = 28;
320
340
  case 28:
341
+ _state.sent();
342
+ _state.label = 29;
343
+ case 29:
321
344
  return [
322
345
  2
323
346
  ];
@@ -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, ROUTE_SPEC_FILE } from "@modern-js/utils";
4
+ import { fs, MAIN_ENTRY_NAME, 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,7 +32,11 @@ 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
+ };
35
38
  export {
36
39
  generateRoutes,
37
- getPathWithoutExt
40
+ getPathWithoutExt,
41
+ isMainEntry
38
42
  };
@@ -1,6 +1,7 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
- import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
3
+ import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
4
+ import { isMainEntry } from "../utils/routes";
4
5
  import { walkDirectory } from "./utils";
5
6
  const applyBaseUrl = (baseUrl, routes) => {
6
7
  if (baseUrl) {
@@ -73,14 +74,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
73
74
  const { packageName } = appContext;
74
75
  const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
75
76
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
76
- const isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
77
- const entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
77
+ const isMain = isMainEntry(entryName, mainEntryName);
78
+ const entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
78
79
  const isSSR = Boolean(entryOptions);
79
80
  const isWorker = Boolean(workerSSR);
80
81
  const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
81
82
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
82
83
  let route = {
83
- urlPath: `/${isMainEntry ? "" : entryName}`,
84
+ urlPath: `/${isMain ? "" : entryName}`,
84
85
  entryName,
85
86
  entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
86
87
  isSPA: true,
@@ -1,6 +1,7 @@
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";
4
5
  import { getProjectUsage } from "./utils";
5
6
  import { handleDependencies } from "./dependencies";
6
7
  var deploy_default = () => ({
@@ -14,6 +15,8 @@ var deploy_default = () => ({
14
15
  return {
15
16
  async beforeDeploy() {
16
17
  const appContext = api.useAppContext();
18
+ const modernConfig = api.useResolvedConfigContext();
19
+ const { source: { mainEntryName } } = modernConfig;
17
20
  const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
18
21
  const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
19
22
  const needModernServer = useSSR || useAPI || useWebServer;
@@ -31,13 +34,27 @@ var deploy_default = () => ({
31
34
  const routes = [];
32
35
  if (!needModernServer) {
33
36
  entrypoints.forEach((entry) => {
37
+ const isMain = isMainEntry(entry.entryName, mainEntryName);
34
38
  routes.push({
35
- src: `/${entry.entryName}(?:/.*)?`,
36
- dest: `/html/${entry.entryName}/index.html`
39
+ src: `/${isMain ? "" : entry.entryName}/*`,
40
+ dest: `/html/${entry.entryName}/index.html`,
41
+ status: 200
37
42
  });
38
43
  });
39
44
  } else {
45
+ routes.push({
46
+ src: `/*`,
47
+ dest: `/.netlify/functions/index`,
48
+ status: 200
49
+ });
40
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
+ const redirectFilePath = path.join(distDirectory, "_redirects");
57
+ await fse.writeFile(redirectFilePath, redirectContent);
41
58
  await fse.remove(outputDirectory);
42
59
  await fse.ensureDir(funcsDirectory);
43
60
  await fse.copy(distDirectory, funcsDirectory, {
@@ -68,8 +85,9 @@ var deploy_default = () => ({
68
85
  };
69
86
  if (!needModernServer) {
70
87
  entrypoints.forEach((entry) => {
88
+ const isMain = isMainEntry(entry.entryName, mainEntryName);
71
89
  config2.routes.push({
72
- src: `/${entry.entryName}(?:/.*)?`,
90
+ src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
73
91
  headers: {
74
92
  "cache-control": "s-maxage=0"
75
93
  },
@@ -131,7 +149,7 @@ var deploy_default = () => ({
131
149
  const { genNodeEntry } = await import("./entrys/node");
132
150
  code = genNodeEntry({
133
151
  plugins,
134
- config,
152
+ config: modernConfig,
135
153
  appContext: serverAppContext
136
154
  });
137
155
  break;
@@ -140,7 +158,7 @@ var deploy_default = () => ({
140
158
  const { genVercelEntry } = await import("./entrys/vercel");
141
159
  code = genVercelEntry({
142
160
  plugins,
143
- config,
161
+ config: modernConfig,
144
162
  appContext: serverAppContext
145
163
  });
146
164
  break;
@@ -149,7 +167,7 @@ var deploy_default = () => ({
149
167
  const { genNetlifyEntry } = await import("./entrys/netlify");
150
168
  code = genNetlifyEntry({
151
169
  plugins,
152
- config,
170
+ config: modernConfig,
153
171
  appContext: serverAppContext
154
172
  });
155
173
  break;
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fs, ROUTE_SPEC_FILE } from "@modern-js/utils";
2
+ import { fs, MAIN_ENTRY_NAME, 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,7 +11,11 @@ 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
+ };
14
17
  export {
15
18
  generateRoutes,
16
- getPathWithoutExt
19
+ getPathWithoutExt,
20
+ isMainEntry
17
21
  };
@@ -1,4 +1,4 @@
1
1
  import type { IAppContext } from '@modern-js/core';
2
- declare const generateRoutes: (appContext: IAppContext) => Promise<void>;
3
- declare const getPathWithoutExt: (filename: string) => string;
4
- export { generateRoutes, getPathWithoutExt };
2
+ export declare const generateRoutes: (appContext: IAppContext) => Promise<void>;
3
+ export declare const getPathWithoutExt: (filename: string) => string;
4
+ export declare const isMainEntry: (entryName: string, mainEntryName?: string) => boolean;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.3-alpha.5",
18
+ "version": "2.49.3-alpha.7",
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/node-bundle-require": "2.49.2",
84
83
  "@modern-js/core": "2.49.2",
84
+ "@modern-js/prod-server": "2.49.2",
85
85
  "@modern-js/plugin": "2.49.2",
86
- "@modern-js/plugin-data-loader": "2.49.2",
86
+ "@modern-js/node-bundle-require": "2.49.2",
87
87
  "@modern-js/plugin-i18n": "2.49.2",
88
- "@modern-js/prod-server": "2.49.2",
89
- "@modern-js/plugin-lint": "2.49.2",
90
88
  "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
91
- "@modern-js/server-utils": "2.49.2",
92
89
  "@modern-js/server": "2.49.2",
93
90
  "@modern-js/server-core": "2.49.2",
91
+ "@modern-js/server-utils": "2.49.2",
94
92
  "@modern-js/types": "2.49.2",
95
93
  "@modern-js/uni-builder": "2.49.2",
96
- "@modern-js/utils": "2.49.2"
94
+ "@modern-js/utils": "2.49.2",
95
+ "@modern-js/plugin-lint": "2.49.2",
96
+ "@modern-js/plugin-data-loader": "2.49.2"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@rsbuild/plugin-swc": "0.6.10",