@modern-js/app-tools 2.49.3-alpha.7 → 2.49.3-alpha.9
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/plugins/deploy/index.js +12 -19
- 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/esm/plugins/deploy/index.js +40 -42
- 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-node/plugins/deploy/index.js +12 -19
- 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/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/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
|
@@ -53,7 +53,6 @@ var deploy_default = () => ({
|
|
|
53
53
|
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
|
54
54
|
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
|
55
55
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
56
|
-
const configContext = api.useResolvedConfigContext();
|
|
57
56
|
let outputDirectory = import_path.default.join(appDirectory, ".output");
|
|
58
57
|
let funcsDirectory = outputDirectory;
|
|
59
58
|
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
|
@@ -69,7 +68,7 @@ var deploy_default = () => ({
|
|
|
69
68
|
entrypoints.forEach((entry) => {
|
|
70
69
|
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
|
71
70
|
routes.push({
|
|
72
|
-
src: `/${isMain ? "" : entry.entryName}
|
|
71
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
|
73
72
|
dest: `/html/${entry.entryName}/index.html`,
|
|
74
73
|
status: 200
|
|
75
74
|
});
|
|
@@ -80,14 +79,13 @@ var deploy_default = () => ({
|
|
|
80
79
|
dest: `/.netlify/functions/index`,
|
|
81
80
|
status: 200
|
|
82
81
|
});
|
|
82
|
+
throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
|
|
83
83
|
}
|
|
84
84
|
console.log("routes", routes, needModernServer);
|
|
85
85
|
const redirectContent = routes.map((route) => {
|
|
86
86
|
return `${route.src} ${route.dest} ${route.status}`;
|
|
87
87
|
}).join("\n");
|
|
88
88
|
console.log("redirectContent", redirectContent);
|
|
89
|
-
const redirectFilePath = import_path.default.join(distDirectory, "_redirects");
|
|
90
|
-
await import_utils.fs.writeFile(redirectFilePath, redirectContent);
|
|
91
89
|
await import_utils.fs.remove(outputDirectory);
|
|
92
90
|
await import_utils.fs.ensureDir(funcsDirectory);
|
|
93
91
|
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
|
@@ -96,12 +94,14 @@ var deploy_default = () => ({
|
|
|
96
94
|
return !src.includes(distStaticDirectory);
|
|
97
95
|
}
|
|
98
96
|
});
|
|
97
|
+
const redirectFilePath = import_path.default.join(distDirectory, "_redirects");
|
|
98
|
+
await import_utils.fs.writeFile(redirectFilePath, redirectContent);
|
|
99
99
|
}
|
|
100
100
|
if (deployTarget === "vercel") {
|
|
101
101
|
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
|
102
102
|
await import_utils.fs.remove(vercelOutput);
|
|
103
103
|
outputDirectory = import_path.default.join(vercelOutput, "output");
|
|
104
|
-
const
|
|
104
|
+
const config = {
|
|
105
105
|
version: 3,
|
|
106
106
|
routes: [
|
|
107
107
|
{
|
|
@@ -119,7 +119,7 @@ var deploy_default = () => ({
|
|
|
119
119
|
if (!needModernServer) {
|
|
120
120
|
entrypoints.forEach((entry) => {
|
|
121
121
|
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
|
122
|
-
|
|
122
|
+
config.routes.push({
|
|
123
123
|
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
|
124
124
|
headers: {
|
|
125
125
|
"cache-control": "s-maxage=0"
|
|
@@ -128,13 +128,13 @@ var deploy_default = () => ({
|
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
} else {
|
|
131
|
-
|
|
131
|
+
config.routes.push({
|
|
132
132
|
src: "/(.*)",
|
|
133
133
|
dest: `/index`
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
await import_utils.fs.ensureDir(outputDirectory);
|
|
137
|
-
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"),
|
|
137
|
+
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config, {
|
|
138
138
|
spaces: 2
|
|
139
139
|
});
|
|
140
140
|
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
|
@@ -161,13 +161,6 @@ var deploy_default = () => ({
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
const { bff } = configContext;
|
|
165
|
-
const config = {
|
|
166
|
-
output: {
|
|
167
|
-
path: "."
|
|
168
|
-
},
|
|
169
|
-
bff
|
|
170
|
-
};
|
|
171
164
|
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
|
172
165
|
const serverAppContext = {
|
|
173
166
|
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
|
@@ -179,7 +172,7 @@ var deploy_default = () => ({
|
|
|
179
172
|
console.log("deployTarget111111111", deployTarget);
|
|
180
173
|
switch (deployTarget) {
|
|
181
174
|
case "node": {
|
|
182
|
-
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./
|
|
175
|
+
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
|
|
183
176
|
code = genNodeEntry({
|
|
184
177
|
plugins,
|
|
185
178
|
config: modernConfig,
|
|
@@ -188,8 +181,8 @@ var deploy_default = () => ({
|
|
|
188
181
|
break;
|
|
189
182
|
}
|
|
190
183
|
case "vercel": {
|
|
191
|
-
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./
|
|
192
|
-
code = genVercelEntry({
|
|
184
|
+
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
|
|
185
|
+
code = await genVercelEntry({
|
|
193
186
|
plugins,
|
|
194
187
|
config: modernConfig,
|
|
195
188
|
appContext: serverAppContext
|
|
@@ -197,7 +190,7 @@ var deploy_default = () => ({
|
|
|
197
190
|
break;
|
|
198
191
|
}
|
|
199
192
|
case "netlify": {
|
|
200
|
-
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./
|
|
193
|
+
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
|
|
201
194
|
code = genNetlifyEntry({
|
|
202
195
|
plugins,
|
|
203
196
|
config: modernConfig,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var platform_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(platform_exports);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var vercel_exports = {};
|
|
30
|
+
__export(vercel_exports, {
|
|
31
|
+
genVercelEntry: () => genVercelEntry
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vercel_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_utils2 = require("../utils");
|
|
37
|
+
async function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
38
|
+
const defaultConfig = {
|
|
39
|
+
output: {
|
|
40
|
+
path: "."
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
44
|
+
const dynamicProdOptions = {
|
|
45
|
+
config: `${JSON.stringify(config || defaultConfig)}`,
|
|
46
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
|
47
|
+
plugins: `${(0, import_utils2.getPluginsCode)(plugins || [])}`,
|
|
48
|
+
appContext: `${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"}`
|
|
49
|
+
};
|
|
50
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
|
51
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", import_utils.ROUTE_SPEC_FILE).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions));
|
|
52
|
+
return entryCode;
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
genVercelEntry
|
|
57
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("node:fs/promises");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const { createProdServer } = require("@modern-js/prod-server");
|
|
5
|
+
p_genPluginImportsCode;
|
|
6
|
+
if (!process.env.NODE_ENV) {
|
|
7
|
+
process.env.NODE_ENV = "production";
|
|
8
|
+
}
|
|
9
|
+
let requestHandler = null;
|
|
10
|
+
let handlerCreationPromise = null;
|
|
11
|
+
async function loadRoutes(routeFilepath) {
|
|
12
|
+
try {
|
|
13
|
+
await fs.access(routeFilepath);
|
|
14
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
|
15
|
+
const routeSpec = JSON.parse(content);
|
|
16
|
+
return routeSpec.routes || [];
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function initServer() {
|
|
23
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
24
|
+
const routes = await loadRoutes(routeFilepath);
|
|
25
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
26
|
+
const prodServerOptions = {
|
|
27
|
+
pwd: __dirname,
|
|
28
|
+
routes,
|
|
29
|
+
disableCustomHook: true,
|
|
30
|
+
...dynamicProdOptions
|
|
31
|
+
};
|
|
32
|
+
const app = await createProdServer(prodServerOptions);
|
|
33
|
+
return app.getRequestListener();
|
|
34
|
+
}
|
|
35
|
+
async function createHandler() {
|
|
36
|
+
if (!handlerCreationPromise) {
|
|
37
|
+
handlerCreationPromise = (async () => {
|
|
38
|
+
try {
|
|
39
|
+
requestHandler = await initServer();
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("Error creating server:", error);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
}
|
|
46
|
+
await handlerCreationPromise;
|
|
47
|
+
return requestHandler;
|
|
48
|
+
}
|
|
49
|
+
createHandler();
|
|
50
|
+
module.exports = async (req, res) => {
|
|
51
|
+
if (!requestHandler) {
|
|
52
|
+
await createHandler();
|
|
53
|
+
}
|
|
54
|
+
return requestHandler(req, res);
|
|
55
|
+
};
|
|
@@ -18,7 +18,7 @@ function deploy_default() {
|
|
|
18
18
|
return {
|
|
19
19
|
beforeDeploy: function beforeDeploy() {
|
|
20
20
|
return _async_to_generator(function() {
|
|
21
|
-
var appContext, modernConfig, mainEntryName, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer,
|
|
21
|
+
var appContext, modernConfig, mainEntryName, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, outputDirectory, funcsDirectory, staticDirectory, netlifyOutput, routes, redirectContent, redirectFilePath, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
|
|
22
22
|
return _ts_generator(this, function(_state) {
|
|
23
23
|
switch (_state.label) {
|
|
24
24
|
case 0:
|
|
@@ -28,7 +28,6 @@ function deploy_default() {
|
|
|
28
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;
|
|
29
29
|
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
|
30
30
|
needModernServer = useSSR || useAPI || useWebServer;
|
|
31
|
-
configContext = api.useResolvedConfigContext();
|
|
32
31
|
outputDirectory = path.join(appDirectory, ".output");
|
|
33
32
|
funcsDirectory = outputDirectory;
|
|
34
33
|
staticDirectory = path.join(outputDirectory, "static");
|
|
@@ -63,7 +62,7 @@ function deploy_default() {
|
|
|
63
62
|
entrypoints.forEach(function(entry) {
|
|
64
63
|
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
|
65
64
|
routes.push({
|
|
66
|
-
src: "/".concat(isMain ? "" : entry.entryName, "
|
|
65
|
+
src: "/".concat(isMain ? "" : "".concat(entry.entryName, "/"), "*"),
|
|
67
66
|
dest: "/html/".concat(entry.entryName, "/index.html"),
|
|
68
67
|
status: 200
|
|
69
68
|
});
|
|
@@ -74,30 +73,24 @@ function deploy_default() {
|
|
|
74
73
|
dest: "/.netlify/functions/index",
|
|
75
74
|
status: 200
|
|
76
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
77
|
}
|
|
78
78
|
console.log("routes", routes, needModernServer);
|
|
79
79
|
redirectContent = routes.map(function(route) {
|
|
80
80
|
return "".concat(route.src, " ").concat(route.dest, " ").concat(route.status);
|
|
81
81
|
}).join("\n");
|
|
82
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
83
|
return [
|
|
91
84
|
4,
|
|
92
85
|
fse.remove(outputDirectory)
|
|
93
86
|
];
|
|
94
|
-
case
|
|
87
|
+
case 4:
|
|
95
88
|
_state.sent();
|
|
96
89
|
return [
|
|
97
90
|
4,
|
|
98
91
|
fse.ensureDir(funcsDirectory)
|
|
99
92
|
];
|
|
100
|
-
case
|
|
93
|
+
case 5:
|
|
101
94
|
_state.sent();
|
|
102
95
|
return [
|
|
103
96
|
4,
|
|
@@ -108,6 +101,13 @@ function deploy_default() {
|
|
|
108
101
|
}
|
|
109
102
|
})
|
|
110
103
|
];
|
|
104
|
+
case 6:
|
|
105
|
+
_state.sent();
|
|
106
|
+
redirectFilePath = path.join(distDirectory, "_redirects");
|
|
107
|
+
return [
|
|
108
|
+
4,
|
|
109
|
+
fse.writeFile(redirectFilePath, redirectContent)
|
|
110
|
+
];
|
|
111
111
|
case 7:
|
|
112
112
|
_state.sent();
|
|
113
113
|
_state.label = 8;
|
|
@@ -228,13 +228,6 @@ function deploy_default() {
|
|
|
228
228
|
_state.sent();
|
|
229
229
|
_state.label = 18;
|
|
230
230
|
case 18:
|
|
231
|
-
bff = configContext.bff;
|
|
232
|
-
config1 = {
|
|
233
|
-
output: {
|
|
234
|
-
path: "."
|
|
235
|
-
},
|
|
236
|
-
bff
|
|
237
|
-
};
|
|
238
231
|
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
|
239
232
|
serverAppContext = {
|
|
240
233
|
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
|
@@ -258,17 +251,17 @@ function deploy_default() {
|
|
|
258
251
|
case "netlify":
|
|
259
252
|
return [
|
|
260
253
|
3,
|
|
261
|
-
|
|
254
|
+
24
|
|
262
255
|
];
|
|
263
256
|
}
|
|
264
257
|
return [
|
|
265
258
|
3,
|
|
266
|
-
|
|
259
|
+
26
|
|
267
260
|
];
|
|
268
261
|
case 19:
|
|
269
262
|
return [
|
|
270
263
|
4,
|
|
271
|
-
import("./
|
|
264
|
+
import("./platforms/node")
|
|
272
265
|
];
|
|
273
266
|
case 20:
|
|
274
267
|
genNodeEntry = _state.sent().genNodeEntry;
|
|
@@ -279,30 +272,35 @@ function deploy_default() {
|
|
|
279
272
|
});
|
|
280
273
|
return [
|
|
281
274
|
3,
|
|
282
|
-
|
|
275
|
+
27
|
|
283
276
|
];
|
|
284
277
|
case 21:
|
|
285
278
|
return [
|
|
286
279
|
4,
|
|
287
|
-
import("./
|
|
280
|
+
import("./platforms/vercel")
|
|
288
281
|
];
|
|
289
282
|
case 22:
|
|
290
283
|
genVercelEntry = _state.sent().genVercelEntry;
|
|
291
|
-
code = genVercelEntry({
|
|
292
|
-
plugins,
|
|
293
|
-
config: modernConfig,
|
|
294
|
-
appContext: serverAppContext
|
|
295
|
-
});
|
|
296
284
|
return [
|
|
297
|
-
|
|
298
|
-
|
|
285
|
+
4,
|
|
286
|
+
genVercelEntry({
|
|
287
|
+
plugins,
|
|
288
|
+
config: modernConfig,
|
|
289
|
+
appContext: serverAppContext
|
|
290
|
+
})
|
|
299
291
|
];
|
|
300
292
|
case 23:
|
|
293
|
+
code = _state.sent();
|
|
301
294
|
return [
|
|
302
|
-
|
|
303
|
-
|
|
295
|
+
3,
|
|
296
|
+
27
|
|
304
297
|
];
|
|
305
298
|
case 24:
|
|
299
|
+
return [
|
|
300
|
+
4,
|
|
301
|
+
import("./platforms/netlify")
|
|
302
|
+
];
|
|
303
|
+
case 25:
|
|
306
304
|
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
|
307
305
|
code = genNetlifyEntry({
|
|
308
306
|
plugins,
|
|
@@ -311,25 +309,25 @@ function deploy_default() {
|
|
|
311
309
|
});
|
|
312
310
|
return [
|
|
313
311
|
3,
|
|
314
|
-
|
|
312
|
+
27
|
|
315
313
|
];
|
|
316
|
-
case
|
|
314
|
+
case 26:
|
|
317
315
|
{
|
|
318
316
|
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
|
319
317
|
}
|
|
320
|
-
_state.label =
|
|
321
|
-
case
|
|
318
|
+
_state.label = 27;
|
|
319
|
+
case 27:
|
|
322
320
|
entryFilePath = path.join(funcsDirectory, "index.js");
|
|
323
321
|
if (!needModernServer)
|
|
324
322
|
return [
|
|
325
323
|
3,
|
|
326
|
-
|
|
324
|
+
30
|
|
327
325
|
];
|
|
328
326
|
return [
|
|
329
327
|
4,
|
|
330
328
|
fse.writeFile(entryFilePath, code)
|
|
331
329
|
];
|
|
332
|
-
case
|
|
330
|
+
case 28:
|
|
333
331
|
_state.sent();
|
|
334
332
|
return [
|
|
335
333
|
4,
|
|
@@ -337,10 +335,10 @@ function deploy_default() {
|
|
|
337
335
|
"@modern-js/prod-server"
|
|
338
336
|
])
|
|
339
337
|
];
|
|
340
|
-
case 28:
|
|
341
|
-
_state.sent();
|
|
342
|
-
_state.label = 29;
|
|
343
338
|
case 29:
|
|
339
|
+
_state.sent();
|
|
340
|
+
_state.label = 30;
|
|
341
|
+
case 30:
|
|
344
342
|
return [
|
|
345
343
|
2
|
|
346
344
|
];
|
|
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", 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();
|
|
@@ -20,7 +20,6 @@ var deploy_default = () => ({
|
|
|
20
20
|
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
|
21
21
|
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
|
22
22
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
23
|
-
const configContext = api.useResolvedConfigContext();
|
|
24
23
|
let outputDirectory = path.join(appDirectory, ".output");
|
|
25
24
|
let funcsDirectory = outputDirectory;
|
|
26
25
|
let staticDirectory = path.join(outputDirectory, "static");
|
|
@@ -36,7 +35,7 @@ var deploy_default = () => ({
|
|
|
36
35
|
entrypoints.forEach((entry) => {
|
|
37
36
|
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
|
38
37
|
routes.push({
|
|
39
|
-
src: `/${isMain ? "" : entry.entryName}
|
|
38
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
|
40
39
|
dest: `/html/${entry.entryName}/index.html`,
|
|
41
40
|
status: 200
|
|
42
41
|
});
|
|
@@ -47,14 +46,13 @@ var deploy_default = () => ({
|
|
|
47
46
|
dest: `/.netlify/functions/index`,
|
|
48
47
|
status: 200
|
|
49
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
50
|
}
|
|
51
51
|
console.log("routes", routes, needModernServer);
|
|
52
52
|
const redirectContent = routes.map((route) => {
|
|
53
53
|
return `${route.src} ${route.dest} ${route.status}`;
|
|
54
54
|
}).join("\n");
|
|
55
55
|
console.log("redirectContent", redirectContent);
|
|
56
|
-
const redirectFilePath = path.join(distDirectory, "_redirects");
|
|
57
|
-
await fse.writeFile(redirectFilePath, redirectContent);
|
|
58
56
|
await fse.remove(outputDirectory);
|
|
59
57
|
await fse.ensureDir(funcsDirectory);
|
|
60
58
|
await fse.copy(distDirectory, funcsDirectory, {
|
|
@@ -63,12 +61,14 @@ var deploy_default = () => ({
|
|
|
63
61
|
return !src.includes(distStaticDirectory);
|
|
64
62
|
}
|
|
65
63
|
});
|
|
64
|
+
const redirectFilePath = path.join(distDirectory, "_redirects");
|
|
65
|
+
await fse.writeFile(redirectFilePath, redirectContent);
|
|
66
66
|
}
|
|
67
67
|
if (deployTarget === "vercel") {
|
|
68
68
|
const vercelOutput = path.join(appDirectory, ".vercel");
|
|
69
69
|
await fse.remove(vercelOutput);
|
|
70
70
|
outputDirectory = path.join(vercelOutput, "output");
|
|
71
|
-
const
|
|
71
|
+
const config = {
|
|
72
72
|
version: 3,
|
|
73
73
|
routes: [
|
|
74
74
|
{
|
|
@@ -86,7 +86,7 @@ var deploy_default = () => ({
|
|
|
86
86
|
if (!needModernServer) {
|
|
87
87
|
entrypoints.forEach((entry) => {
|
|
88
88
|
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
|
89
|
-
|
|
89
|
+
config.routes.push({
|
|
90
90
|
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
|
91
91
|
headers: {
|
|
92
92
|
"cache-control": "s-maxage=0"
|
|
@@ -95,13 +95,13 @@ var deploy_default = () => ({
|
|
|
95
95
|
});
|
|
96
96
|
});
|
|
97
97
|
} else {
|
|
98
|
-
|
|
98
|
+
config.routes.push({
|
|
99
99
|
src: "/(.*)",
|
|
100
100
|
dest: `/index`
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
await fse.ensureDir(outputDirectory);
|
|
104
|
-
await fse.writeJSON(path.join(outputDirectory, "config.json"),
|
|
104
|
+
await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
|
105
105
|
spaces: 2
|
|
106
106
|
});
|
|
107
107
|
staticDirectory = path.join(outputDirectory, "static/static");
|
|
@@ -128,13 +128,6 @@ var deploy_default = () => ({
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
const { bff } = configContext;
|
|
132
|
-
const config = {
|
|
133
|
-
output: {
|
|
134
|
-
path: "."
|
|
135
|
-
},
|
|
136
|
-
bff
|
|
137
|
-
};
|
|
138
131
|
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
|
139
132
|
const serverAppContext = {
|
|
140
133
|
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
|
@@ -146,7 +139,7 @@ var deploy_default = () => ({
|
|
|
146
139
|
console.log("deployTarget111111111", deployTarget);
|
|
147
140
|
switch (deployTarget) {
|
|
148
141
|
case "node": {
|
|
149
|
-
const { genNodeEntry } = await import("./
|
|
142
|
+
const { genNodeEntry } = await import("./platforms/node");
|
|
150
143
|
code = genNodeEntry({
|
|
151
144
|
plugins,
|
|
152
145
|
config: modernConfig,
|
|
@@ -155,8 +148,8 @@ var deploy_default = () => ({
|
|
|
155
148
|
break;
|
|
156
149
|
}
|
|
157
150
|
case "vercel": {
|
|
158
|
-
const { genVercelEntry } = await import("./
|
|
159
|
-
code = genVercelEntry({
|
|
151
|
+
const { genVercelEntry } = await import("./platforms/vercel");
|
|
152
|
+
code = await genVercelEntry({
|
|
160
153
|
plugins,
|
|
161
154
|
config: modernConfig,
|
|
162
155
|
appContext: serverAppContext
|
|
@@ -164,7 +157,7 @@ var deploy_default = () => ({
|
|
|
164
157
|
break;
|
|
165
158
|
}
|
|
166
159
|
case "netlify": {
|
|
167
|
-
const { genNetlifyEntry } = await import("./
|
|
160
|
+
const { genNetlifyEntry } = await import("./platforms/netlify");
|
|
168
161
|
code = genNetlifyEntry({
|
|
169
162
|
plugins,
|
|
170
163
|
config: modernConfig,
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
|
3
|
+
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
|
4
|
+
async function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
output: {
|
|
7
|
+
path: "."
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
11
|
+
const dynamicProdOptions = {
|
|
12
|
+
config: `${JSON.stringify(config || defaultConfig)}`,
|
|
13
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
|
14
|
+
plugins: `${getPluginsCode(plugins || [])}`,
|
|
15
|
+
appContext: `${appContext ? severAppContextTemplate(appContext) : "undefined"}`
|
|
16
|
+
};
|
|
17
|
+
let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
|
|
18
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", ROUTE_SPEC_FILE).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions));
|
|
19
|
+
return entryCode;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
genVercelEntry
|
|
23
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
const fs = require("node:fs/promises");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
const { createProdServer } = require("@modern-js/prod-server");
|
|
10
|
+
p_genPluginImportsCode;
|
|
11
|
+
if (!process.env.NODE_ENV) {
|
|
12
|
+
process.env.NODE_ENV = "production";
|
|
13
|
+
}
|
|
14
|
+
let requestHandler = null;
|
|
15
|
+
let handlerCreationPromise = null;
|
|
16
|
+
async function loadRoutes(routeFilepath) {
|
|
17
|
+
try {
|
|
18
|
+
await fs.access(routeFilepath);
|
|
19
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
|
20
|
+
const routeSpec = JSON.parse(content);
|
|
21
|
+
return routeSpec.routes || [];
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function initServer() {
|
|
28
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
29
|
+
const routes = await loadRoutes(routeFilepath);
|
|
30
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
31
|
+
const prodServerOptions = {
|
|
32
|
+
pwd: __dirname,
|
|
33
|
+
routes,
|
|
34
|
+
disableCustomHook: true,
|
|
35
|
+
...dynamicProdOptions
|
|
36
|
+
};
|
|
37
|
+
const app = await createProdServer(prodServerOptions);
|
|
38
|
+
return app.getRequestListener();
|
|
39
|
+
}
|
|
40
|
+
async function createHandler() {
|
|
41
|
+
if (!handlerCreationPromise) {
|
|
42
|
+
handlerCreationPromise = (async () => {
|
|
43
|
+
try {
|
|
44
|
+
requestHandler = await initServer();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error("Error creating server:", error);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
}
|
|
51
|
+
await handlerCreationPromise;
|
|
52
|
+
return requestHandler;
|
|
53
|
+
}
|
|
54
|
+
createHandler();
|
|
55
|
+
module.exports = async (req, res) => {
|
|
56
|
+
if (!requestHandler) {
|
|
57
|
+
await createHandler();
|
|
58
|
+
}
|
|
59
|
+
return requestHandler(req, res);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
export default require_vercelEntry();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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.9",
|
|
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/core": "2.49.2",
|
|
84
|
-
"@modern-js/prod-server": "2.49.2",
|
|
85
|
-
"@modern-js/plugin": "2.49.2",
|
|
86
83
|
"@modern-js/node-bundle-require": "2.49.2",
|
|
87
|
-
"@modern-js/plugin-
|
|
88
|
-
"@modern-js/
|
|
84
|
+
"@modern-js/plugin-data-loader": "2.49.2",
|
|
85
|
+
"@modern-js/plugin-lint": "2.49.2",
|
|
86
|
+
"@modern-js/plugin": "2.49.2",
|
|
87
|
+
"@modern-js/core": "2.49.2",
|
|
89
88
|
"@modern-js/server": "2.49.2",
|
|
90
|
-
"@modern-js/
|
|
89
|
+
"@modern-js/plugin-i18n": "2.49.2",
|
|
91
90
|
"@modern-js/server-utils": "2.49.2",
|
|
91
|
+
"@modern-js/prod-server": "2.49.2",
|
|
92
|
+
"@modern-js/server-core": "2.49.2",
|
|
93
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.49.2",
|
|
92
94
|
"@modern-js/types": "2.49.2",
|
|
93
|
-
"@modern-js/uni-builder": "2.49.2",
|
|
94
95
|
"@modern-js/utils": "2.49.2",
|
|
95
|
-
"@modern-js/
|
|
96
|
-
"@modern-js/plugin-data-loader": "2.49.2"
|
|
96
|
+
"@modern-js/uni-builder": "2.49.2"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@rsbuild/plugin-swc": "0.6.10",
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var vercel_exports = {};
|
|
20
|
-
__export(vercel_exports, {
|
|
21
|
-
genVercelEntry: () => genVercelEntry
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(vercel_exports);
|
|
24
|
-
var import_utils = require("@modern-js/utils");
|
|
25
|
-
var import_utils2 = require("../utils");
|
|
26
|
-
function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
27
|
-
const defaultConfig = {
|
|
28
|
-
server: {
|
|
29
|
-
port: 8080
|
|
30
|
-
},
|
|
31
|
-
output: {
|
|
32
|
-
path: "."
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return `
|
|
36
|
-
|
|
37
|
-
const fs = require('node:fs/promises');
|
|
38
|
-
const path = require('node:path');
|
|
39
|
-
const { createProdServer } = require('@modern-js/prod-server');
|
|
40
|
-
${(0, import_utils2.genPluginImportsCode)(plugins || [])}
|
|
41
|
-
|
|
42
|
-
if(!process.env.NODE_ENV){
|
|
43
|
-
process.env.NODE_ENV = 'production';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let requestHandler = null;
|
|
47
|
-
async function createHandler() {
|
|
48
|
-
try {
|
|
49
|
-
let routes = [];
|
|
50
|
-
const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
|
|
51
|
-
try {
|
|
52
|
-
await fs.access(routeFilepath);
|
|
53
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
|
54
|
-
const routeSpec = JSON.parse(content);
|
|
55
|
-
routes = routeSpec.routes;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.warn('route.json not found, continuing with empty routes.');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const prodServerOptions = {
|
|
61
|
-
pwd: __dirname,
|
|
62
|
-
routes,
|
|
63
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
|
64
|
-
serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
|
|
65
|
-
plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
|
|
66
|
-
appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
|
|
67
|
-
disableCustomHook: true
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const app = await createProdServer(prodServerOptions)
|
|
71
|
-
|
|
72
|
-
requestHandler = app.getRequestListener();
|
|
73
|
-
|
|
74
|
-
return requestHandler;
|
|
75
|
-
} catch(error) {
|
|
76
|
-
console.error(error);
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
createHandler();
|
|
82
|
-
|
|
83
|
-
module.exports = async(req, res) => {
|
|
84
|
-
if(typeof requestHandler !== 'function'){
|
|
85
|
-
await createHandler();
|
|
86
|
-
}
|
|
87
|
-
return requestHandler(req, res);
|
|
88
|
-
}
|
|
89
|
-
`;
|
|
90
|
-
}
|
|
91
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
-
0 && (module.exports = {
|
|
93
|
-
genVercelEntry
|
|
94
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
|
2
|
-
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
|
3
|
-
function genVercelEntry() {
|
|
4
|
-
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
|
|
5
|
-
var defaultConfig = {
|
|
6
|
-
server: {
|
|
7
|
-
port: 8080
|
|
8
|
-
},
|
|
9
|
-
output: {
|
|
10
|
-
path: "."
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createProdServer } = require('@modern-js/prod-server');\n ".concat(genPluginImportsCode(plugins || []), `
|
|
14
|
-
|
|
15
|
-
if(!process.env.NODE_ENV){
|
|
16
|
-
process.env.NODE_ENV = 'production';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let requestHandler = null;
|
|
20
|
-
async function createHandler() {
|
|
21
|
-
try {
|
|
22
|
-
let routes = [];
|
|
23
|
-
const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
|
|
24
|
-
try {
|
|
25
|
-
await fs.access(routeFilepath);
|
|
26
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
|
27
|
-
const routeSpec = JSON.parse(content);
|
|
28
|
-
routes = routeSpec.routes;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.warn('route.json not found, continuing with empty routes.');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const prodServerOptions = {
|
|
34
|
-
pwd: __dirname,
|
|
35
|
-
routes,
|
|
36
|
-
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n const app = await createProdServer(prodServerOptions)\n\n requestHandler = app.getRequestListener();\n\n return requestHandler;\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n module.exports = async(req, res) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(req, res);\n }\n ");
|
|
37
|
-
}
|
|
38
|
-
export {
|
|
39
|
-
genVercelEntry
|
|
40
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
return `
|
|
13
|
-
|
|
14
|
-
const fs = require('node:fs/promises');
|
|
15
|
-
const path = require('node:path');
|
|
16
|
-
const { createProdServer } = require('@modern-js/prod-server');
|
|
17
|
-
${genPluginImportsCode(plugins || [])}
|
|
18
|
-
|
|
19
|
-
if(!process.env.NODE_ENV){
|
|
20
|
-
process.env.NODE_ENV = 'production';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let requestHandler = null;
|
|
24
|
-
async function createHandler() {
|
|
25
|
-
try {
|
|
26
|
-
let routes = [];
|
|
27
|
-
const routeFilepath = path.join(__dirname, "${ROUTE_SPEC_FILE}");
|
|
28
|
-
try {
|
|
29
|
-
await fs.access(routeFilepath);
|
|
30
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
|
31
|
-
const routeSpec = JSON.parse(content);
|
|
32
|
-
routes = routeSpec.routes;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.warn('route.json not found, continuing with empty routes.');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const prodServerOptions = {
|
|
38
|
-
pwd: __dirname,
|
|
39
|
-
routes,
|
|
40
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
|
41
|
-
serverConfigFile: '${DEFAULT_SERVER_CONFIG}',
|
|
42
|
-
plugins: ${getPluginsCode(plugins || [])},
|
|
43
|
-
appContext: ${appContext ? severAppContextTemplate(appContext) : "undefined"},
|
|
44
|
-
disableCustomHook: true
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const app = await createProdServer(prodServerOptions)
|
|
48
|
-
|
|
49
|
-
requestHandler = app.getRequestListener();
|
|
50
|
-
|
|
51
|
-
return requestHandler;
|
|
52
|
-
} catch(error) {
|
|
53
|
-
console.error(error);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
createHandler();
|
|
59
|
-
|
|
60
|
-
module.exports = async(req, res) => {
|
|
61
|
-
if(typeof requestHandler !== 'function'){
|
|
62
|
-
await createHandler();
|
|
63
|
-
}
|
|
64
|
-
return requestHandler(req, res);
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
genVercelEntry
|
|
70
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|