@modern-js/app-tools 2.49.3-alpha.4 → 2.49.3-alpha.6
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/plugins/deploy/index.js +45 -5
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/plugins/deploy/index.js +106 -41
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/plugins/deploy/index.js +45 -5
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +8 -8
@@ -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
|
110
|
-
const entryOptions = (0, import_utils.getEntryOptions)(entryName,
|
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: `/${
|
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;
|
@@ -54,10 +57,46 @@ var deploy_default = () => ({
|
|
54
57
|
let outputDirectory = import_path.default.join(appDirectory, ".output");
|
55
58
|
let funcsDirectory = outputDirectory;
|
56
59
|
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
57
|
-
if (deployTarget === "node"
|
60
|
+
if (deployTarget === "node") {
|
58
61
|
await import_utils.fs.remove(outputDirectory);
|
59
62
|
await import_utils.fs.copy(distDirectory, outputDirectory);
|
60
63
|
}
|
64
|
+
if (deployTarget === "netlify") {
|
65
|
+
const netlifyOutput = import_path.default.join(appDirectory, ".netlify");
|
66
|
+
funcsDirectory = import_path.default.join(netlifyOutput, "functions");
|
67
|
+
const routes = [];
|
68
|
+
if (!needModernServer) {
|
69
|
+
entrypoints.forEach((entry) => {
|
70
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
71
|
+
routes.push({
|
72
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
73
|
+
dest: `/html/${entry.entryName}/index.html`,
|
74
|
+
status: 200
|
75
|
+
});
|
76
|
+
});
|
77
|
+
} else {
|
78
|
+
routes.push({
|
79
|
+
src: `/*`,
|
80
|
+
dest: `/.netlify/functions/index`,
|
81
|
+
status: 200
|
82
|
+
});
|
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);
|
91
|
+
await import_utils.fs.remove(outputDirectory);
|
92
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
93
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
94
|
+
filter: (src) => {
|
95
|
+
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
96
|
+
return !src.includes(distStaticDirectory);
|
97
|
+
}
|
98
|
+
});
|
99
|
+
}
|
61
100
|
if (deployTarget === "vercel") {
|
62
101
|
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
63
102
|
await import_utils.fs.remove(vercelOutput);
|
@@ -79,8 +118,9 @@ var deploy_default = () => ({
|
|
79
118
|
};
|
80
119
|
if (!needModernServer) {
|
81
120
|
entrypoints.forEach((entry) => {
|
121
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
82
122
|
config2.routes.push({
|
83
|
-
src: `/${entry.entryName}(?:/.*)?`,
|
123
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
84
124
|
headers: {
|
85
125
|
"cache-control": "s-maxage=0"
|
86
126
|
},
|
@@ -142,7 +182,7 @@ var deploy_default = () => ({
|
|
142
182
|
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/node")));
|
143
183
|
code = genNodeEntry({
|
144
184
|
plugins,
|
145
|
-
config,
|
185
|
+
config: modernConfig,
|
146
186
|
appContext: serverAppContext
|
147
187
|
});
|
148
188
|
break;
|
@@ -151,7 +191,7 @@ var deploy_default = () => ({
|
|
151
191
|
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/vercel")));
|
152
192
|
code = genVercelEntry({
|
153
193
|
plugins,
|
154
|
-
config,
|
194
|
+
config: modernConfig,
|
155
195
|
appContext: serverAppContext
|
156
196
|
});
|
157
197
|
break;
|
@@ -160,7 +200,7 @@ var deploy_default = () => ({
|
|
160
200
|
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/netlify")));
|
161
201
|
code = genNetlifyEntry({
|
162
202
|
plugins,
|
163
|
-
config,
|
203
|
+
config: modernConfig,
|
164
204
|
appContext: serverAppContext
|
165
205
|
});
|
166
206
|
break;
|
package/dist/cjs/utils/routes.js
CHANGED
@@ -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,
|
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
|
79
|
-
var entryOptions = getEntryOptions(entryName,
|
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(
|
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, 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;
|
@@ -29,7 +32,7 @@ function deploy_default() {
|
|
29
32
|
outputDirectory = path.join(appDirectory, ".output");
|
30
33
|
funcsDirectory = outputDirectory;
|
31
34
|
staticDirectory = path.join(outputDirectory, "static");
|
32
|
-
if (!(deployTarget === "node"
|
35
|
+
if (!(deployTarget === "node"))
|
33
36
|
return [
|
34
37
|
3,
|
35
38
|
3
|
@@ -48,17 +51,78 @@ function deploy_default() {
|
|
48
51
|
_state.sent();
|
49
52
|
_state.label = 3;
|
50
53
|
case 3:
|
54
|
+
if (!(deployTarget === "netlify"))
|
55
|
+
return [
|
56
|
+
3,
|
57
|
+
8
|
58
|
+
];
|
59
|
+
netlifyOutput = path.join(appDirectory, ".netlify");
|
60
|
+
funcsDirectory = path.join(netlifyOutput, "functions");
|
61
|
+
routes = [];
|
62
|
+
if (!needModernServer) {
|
63
|
+
entrypoints.forEach(function(entry) {
|
64
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
65
|
+
routes.push({
|
66
|
+
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
67
|
+
dest: "/html/".concat(entry.entryName, "/index.html"),
|
68
|
+
status: 200
|
69
|
+
});
|
70
|
+
});
|
71
|
+
} else {
|
72
|
+
routes.push({
|
73
|
+
src: "/*",
|
74
|
+
dest: "/.netlify/functions/index",
|
75
|
+
status: 200
|
76
|
+
});
|
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");
|
84
|
+
return [
|
85
|
+
4,
|
86
|
+
fse.writeFile(redirectFilePath, redirectContent)
|
87
|
+
];
|
88
|
+
case 4:
|
89
|
+
_state.sent();
|
90
|
+
return [
|
91
|
+
4,
|
92
|
+
fse.remove(outputDirectory)
|
93
|
+
];
|
94
|
+
case 5:
|
95
|
+
_state.sent();
|
96
|
+
return [
|
97
|
+
4,
|
98
|
+
fse.ensureDir(funcsDirectory)
|
99
|
+
];
|
100
|
+
case 6:
|
101
|
+
_state.sent();
|
102
|
+
return [
|
103
|
+
4,
|
104
|
+
fse.copy(distDirectory, funcsDirectory, {
|
105
|
+
filter: function(src) {
|
106
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
107
|
+
return !src.includes(distStaticDirectory);
|
108
|
+
}
|
109
|
+
})
|
110
|
+
];
|
111
|
+
case 7:
|
112
|
+
_state.sent();
|
113
|
+
_state.label = 8;
|
114
|
+
case 8:
|
51
115
|
if (!(deployTarget === "vercel"))
|
52
116
|
return [
|
53
117
|
3,
|
54
|
-
|
118
|
+
18
|
55
119
|
];
|
56
120
|
vercelOutput = path.join(appDirectory, ".vercel");
|
57
121
|
return [
|
58
122
|
4,
|
59
123
|
fse.remove(vercelOutput)
|
60
124
|
];
|
61
|
-
case
|
125
|
+
case 9:
|
62
126
|
_state.sent();
|
63
127
|
outputDirectory = path.join(vercelOutput, "output");
|
64
128
|
config = {
|
@@ -78,8 +142,9 @@ function deploy_default() {
|
|
78
142
|
};
|
79
143
|
if (!needModernServer) {
|
80
144
|
entrypoints.forEach(function(entry) {
|
145
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
81
146
|
config.routes.push({
|
82
|
-
src: "/".concat(entry.entryName, "(?:/.*)?"),
|
147
|
+
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
83
148
|
headers: {
|
84
149
|
"cache-control": "s-maxage=0"
|
85
150
|
},
|
@@ -96,7 +161,7 @@ function deploy_default() {
|
|
96
161
|
4,
|
97
162
|
fse.ensureDir(outputDirectory)
|
98
163
|
];
|
99
|
-
case
|
164
|
+
case 10:
|
100
165
|
_state.sent();
|
101
166
|
return [
|
102
167
|
4,
|
@@ -104,19 +169,19 @@ function deploy_default() {
|
|
104
169
|
spaces: 2
|
105
170
|
})
|
106
171
|
];
|
107
|
-
case
|
172
|
+
case 11:
|
108
173
|
_state.sent();
|
109
174
|
staticDirectory = path.join(outputDirectory, "static/static");
|
110
175
|
return [
|
111
176
|
4,
|
112
177
|
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
113
178
|
];
|
114
|
-
case
|
179
|
+
case 12:
|
115
180
|
_state.sent();
|
116
181
|
if (!!needModernServer)
|
117
182
|
return [
|
118
183
|
3,
|
119
|
-
|
184
|
+
14
|
120
185
|
];
|
121
186
|
destHtmlDirectory = path.join(distDirectory, "html");
|
122
187
|
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
@@ -124,19 +189,19 @@ function deploy_default() {
|
|
124
189
|
4,
|
125
190
|
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
126
191
|
];
|
127
|
-
case
|
192
|
+
case 13:
|
128
193
|
_state.sent();
|
129
194
|
return [
|
130
195
|
3,
|
131
|
-
|
196
|
+
18
|
132
197
|
];
|
133
|
-
case
|
198
|
+
case 14:
|
134
199
|
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
135
200
|
return [
|
136
201
|
4,
|
137
202
|
fse.ensureDir(funcsDirectory)
|
138
203
|
];
|
139
|
-
case
|
204
|
+
case 15:
|
140
205
|
_state.sent();
|
141
206
|
return [
|
142
207
|
4,
|
@@ -147,7 +212,7 @@ function deploy_default() {
|
|
147
212
|
}
|
148
213
|
})
|
149
214
|
];
|
150
|
-
case
|
215
|
+
case 16:
|
151
216
|
_state.sent();
|
152
217
|
return [
|
153
218
|
4,
|
@@ -159,10 +224,10 @@ function deploy_default() {
|
|
159
224
|
supportsResponseStreaming: true
|
160
225
|
})
|
161
226
|
];
|
162
|
-
case
|
227
|
+
case 17:
|
163
228
|
_state.sent();
|
164
|
-
_state.label =
|
165
|
-
case
|
229
|
+
_state.label = 18;
|
230
|
+
case 18:
|
166
231
|
bff = configContext.bff;
|
167
232
|
config1 = {
|
168
233
|
output: {
|
@@ -183,88 +248,88 @@ function deploy_default() {
|
|
183
248
|
case "node":
|
184
249
|
return [
|
185
250
|
3,
|
186
|
-
|
251
|
+
19
|
187
252
|
];
|
188
253
|
case "vercel":
|
189
254
|
return [
|
190
255
|
3,
|
191
|
-
|
256
|
+
21
|
192
257
|
];
|
193
258
|
case "netlify":
|
194
259
|
return [
|
195
260
|
3,
|
196
|
-
|
261
|
+
23
|
197
262
|
];
|
198
263
|
}
|
199
264
|
return [
|
200
265
|
3,
|
201
|
-
|
266
|
+
25
|
202
267
|
];
|
203
|
-
case
|
268
|
+
case 19:
|
204
269
|
return [
|
205
270
|
4,
|
206
271
|
import("./entrys/node")
|
207
272
|
];
|
208
|
-
case
|
273
|
+
case 20:
|
209
274
|
genNodeEntry = _state.sent().genNodeEntry;
|
210
275
|
code = genNodeEntry({
|
211
276
|
plugins,
|
212
|
-
config:
|
277
|
+
config: modernConfig,
|
213
278
|
appContext: serverAppContext
|
214
279
|
});
|
215
280
|
return [
|
216
281
|
3,
|
217
|
-
|
282
|
+
26
|
218
283
|
];
|
219
|
-
case
|
284
|
+
case 21:
|
220
285
|
return [
|
221
286
|
4,
|
222
287
|
import("./entrys/vercel")
|
223
288
|
];
|
224
|
-
case
|
289
|
+
case 22:
|
225
290
|
genVercelEntry = _state.sent().genVercelEntry;
|
226
291
|
code = genVercelEntry({
|
227
292
|
plugins,
|
228
|
-
config:
|
293
|
+
config: modernConfig,
|
229
294
|
appContext: serverAppContext
|
230
295
|
});
|
231
296
|
return [
|
232
297
|
3,
|
233
|
-
|
298
|
+
26
|
234
299
|
];
|
235
|
-
case
|
300
|
+
case 23:
|
236
301
|
return [
|
237
302
|
4,
|
238
303
|
import("./entrys/netlify")
|
239
304
|
];
|
240
|
-
case
|
305
|
+
case 24:
|
241
306
|
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
242
307
|
code = genNetlifyEntry({
|
243
308
|
plugins,
|
244
|
-
config:
|
309
|
+
config: modernConfig,
|
245
310
|
appContext: serverAppContext
|
246
311
|
});
|
247
312
|
return [
|
248
313
|
3,
|
249
|
-
|
314
|
+
26
|
250
315
|
];
|
251
|
-
case
|
316
|
+
case 25:
|
252
317
|
{
|
253
318
|
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
254
319
|
}
|
255
|
-
_state.label =
|
256
|
-
case
|
320
|
+
_state.label = 26;
|
321
|
+
case 26:
|
257
322
|
entryFilePath = path.join(funcsDirectory, "index.js");
|
258
323
|
if (!needModernServer)
|
259
324
|
return [
|
260
325
|
3,
|
261
|
-
|
326
|
+
29
|
262
327
|
];
|
263
328
|
return [
|
264
329
|
4,
|
265
330
|
fse.writeFile(entryFilePath, code)
|
266
331
|
];
|
267
|
-
case
|
332
|
+
case 27:
|
268
333
|
_state.sent();
|
269
334
|
return [
|
270
335
|
4,
|
@@ -272,10 +337,10 @@ function deploy_default() {
|
|
272
337
|
"@modern-js/prod-server"
|
273
338
|
])
|
274
339
|
];
|
275
|
-
case
|
340
|
+
case 28:
|
276
341
|
_state.sent();
|
277
|
-
_state.label =
|
278
|
-
case
|
342
|
+
_state.label = 29;
|
343
|
+
case 29:
|
279
344
|
return [
|
280
345
|
2
|
281
346
|
];
|
package/dist/esm/utils/routes.js
CHANGED
@@ -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,
|
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
|
77
|
-
const entryOptions = getEntryOptions(entryName,
|
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: `/${
|
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;
|
@@ -21,10 +24,46 @@ var deploy_default = () => ({
|
|
21
24
|
let outputDirectory = path.join(appDirectory, ".output");
|
22
25
|
let funcsDirectory = outputDirectory;
|
23
26
|
let staticDirectory = path.join(outputDirectory, "static");
|
24
|
-
if (deployTarget === "node"
|
27
|
+
if (deployTarget === "node") {
|
25
28
|
await fse.remove(outputDirectory);
|
26
29
|
await fse.copy(distDirectory, outputDirectory);
|
27
30
|
}
|
31
|
+
if (deployTarget === "netlify") {
|
32
|
+
const netlifyOutput = path.join(appDirectory, ".netlify");
|
33
|
+
funcsDirectory = path.join(netlifyOutput, "functions");
|
34
|
+
const routes = [];
|
35
|
+
if (!needModernServer) {
|
36
|
+
entrypoints.forEach((entry) => {
|
37
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
38
|
+
routes.push({
|
39
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
40
|
+
dest: `/html/${entry.entryName}/index.html`,
|
41
|
+
status: 200
|
42
|
+
});
|
43
|
+
});
|
44
|
+
} else {
|
45
|
+
routes.push({
|
46
|
+
src: `/*`,
|
47
|
+
dest: `/.netlify/functions/index`,
|
48
|
+
status: 200
|
49
|
+
});
|
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);
|
58
|
+
await fse.remove(outputDirectory);
|
59
|
+
await fse.ensureDir(funcsDirectory);
|
60
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
61
|
+
filter: (src) => {
|
62
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
63
|
+
return !src.includes(distStaticDirectory);
|
64
|
+
}
|
65
|
+
});
|
66
|
+
}
|
28
67
|
if (deployTarget === "vercel") {
|
29
68
|
const vercelOutput = path.join(appDirectory, ".vercel");
|
30
69
|
await fse.remove(vercelOutput);
|
@@ -46,8 +85,9 @@ var deploy_default = () => ({
|
|
46
85
|
};
|
47
86
|
if (!needModernServer) {
|
48
87
|
entrypoints.forEach((entry) => {
|
88
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
49
89
|
config2.routes.push({
|
50
|
-
src: `/${entry.entryName}(?:/.*)?`,
|
90
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
51
91
|
headers: {
|
52
92
|
"cache-control": "s-maxage=0"
|
53
93
|
},
|
@@ -109,7 +149,7 @@ var deploy_default = () => ({
|
|
109
149
|
const { genNodeEntry } = await import("./entrys/node");
|
110
150
|
code = genNodeEntry({
|
111
151
|
plugins,
|
112
|
-
config,
|
152
|
+
config: modernConfig,
|
113
153
|
appContext: serverAppContext
|
114
154
|
});
|
115
155
|
break;
|
@@ -118,7 +158,7 @@ var deploy_default = () => ({
|
|
118
158
|
const { genVercelEntry } = await import("./entrys/vercel");
|
119
159
|
code = genVercelEntry({
|
120
160
|
plugins,
|
121
|
-
config,
|
161
|
+
config: modernConfig,
|
122
162
|
appContext: serverAppContext
|
123
163
|
});
|
124
164
|
break;
|
@@ -127,7 +167,7 @@ var deploy_default = () => ({
|
|
127
167
|
const { genNetlifyEntry } = await import("./entrys/netlify");
|
128
168
|
code = genNetlifyEntry({
|
129
169
|
plugins,
|
130
|
-
config,
|
170
|
+
config: modernConfig,
|
131
171
|
appContext: serverAppContext
|
132
172
|
});
|
133
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
|
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.
|
18
|
+
"version": "2.49.3-alpha.6",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -81,19 +81,19 @@
|
|
81
81
|
"pkg-types": "^1.1.0",
|
82
82
|
"std-env": "^3.7.0",
|
83
83
|
"@modern-js/core": "2.49.2",
|
84
|
-
"@modern-js/
|
84
|
+
"@modern-js/node-bundle-require": "2.49.2",
|
85
85
|
"@modern-js/plugin-data-loader": "2.49.2",
|
86
|
+
"@modern-js/plugin-i18n": "2.49.2",
|
86
87
|
"@modern-js/prod-server": "2.49.2",
|
87
|
-
"@modern-js/
|
88
|
+
"@modern-js/plugin-lint": "2.49.2",
|
89
|
+
"@modern-js/plugin": "2.49.2",
|
88
90
|
"@modern-js/rsbuild-plugin-esbuild": "2.49.2",
|
89
|
-
"@modern-js/
|
91
|
+
"@modern-js/server": "2.49.2",
|
92
|
+
"@modern-js/server-utils": "2.49.2",
|
90
93
|
"@modern-js/types": "2.49.2",
|
91
|
-
"@modern-js/plugin-i18n": "2.49.2",
|
92
94
|
"@modern-js/utils": "2.49.2",
|
93
95
|
"@modern-js/uni-builder": "2.49.2",
|
94
|
-
"@modern-js/
|
95
|
-
"@modern-js/server-utils": "2.49.2",
|
96
|
-
"@modern-js/server": "2.49.2"
|
96
|
+
"@modern-js/server-core": "2.49.2"
|
97
97
|
},
|
98
98
|
"devDependencies": {
|
99
99
|
"@rsbuild/plugin-swc": "0.6.10",
|