@modern-js/app-tools 2.49.3-alpha.0 → 2.49.3-alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/locale/en.js +1 -2
- package/dist/cjs/locale/zh.js +1 -2
- package/dist/cjs/plugins/deploy/index.js +55 -26
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +36 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +57 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +55 -0
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/index.js +1 -1
- package/dist/esm/locale/en.js +1 -2
- package/dist/esm/locale/zh.js +1 -2
- package/dist/esm/plugins/deploy/index.js +120 -61
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +99 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +47 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +197 -0
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/index.js +1 -1
- package/dist/esm-node/locale/en.js +1 -2
- package/dist/esm-node/locale/zh.js +1 -2
- package/dist/esm-node/plugins/deploy/index.js +55 -26
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +35 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +23 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +63 -0
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/locale/en.d.ts +0 -1
- package/dist/types/locale/index.d.ts +0 -2
- package/dist/types/locale/zh.d.ts +0 -1
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +1 -0
- package/dist/types/plugins/deploy/{entrys → platforms}/vercel.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/utils/routes.d.ts +3 -3
- package/dist/types/utils/types.d.ts +0 -1
- package/package.json +10 -10
- package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -94
- package/dist/esm/plugins/deploy/entrys/vercel.js +0 -40
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -70
- /package/dist/cjs/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/cjs/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/esm/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/esm/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/esm-node/plugins/deploy/{entrys → platforms}/netlify.js +0 -0
- /package/dist/esm-node/plugins/deploy/{entrys → platforms}/node.js +0 -0
- /package/dist/types/plugins/deploy/{entrys → platforms}/netlify.d.ts +0 -0
- /package/dist/types/plugins/deploy/{entrys → platforms}/node.d.ts +0 -0
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,
|
package/dist/esm-node/index.js
CHANGED
@@ -115,7 +115,7 @@ const appTools = (options = {
|
|
115
115
|
const { start } = await import("./commands/serve");
|
116
116
|
await start(api);
|
117
117
|
});
|
118
|
-
program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).
|
118
|
+
program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
|
119
119
|
if (!options2.skipBuild) {
|
120
120
|
const { build } = await import("./commands/build");
|
121
121
|
await build(api);
|
@@ -21,8 +21,7 @@ const EN_LOCALE = {
|
|
21
21
|
describe: "preview the production build locally"
|
22
22
|
},
|
23
23
|
deploy: {
|
24
|
-
describe: "deploy the application"
|
25
|
-
output: "output path"
|
24
|
+
describe: "deploy the application"
|
26
25
|
},
|
27
26
|
new: {
|
28
27
|
describe: "enable optional features or add a new entry",
|
@@ -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 = () => ({
|
@@ -12,28 +13,62 @@ var deploy_default = () => ({
|
|
12
13
|
setup: (api) => {
|
13
14
|
const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
14
15
|
return {
|
15
|
-
async beforeDeploy(
|
16
|
-
const { output: outputPath } = options;
|
16
|
+
async beforeDeploy() {
|
17
17
|
const appContext = api.useAppContext();
|
18
|
+
const modernConfig = api.useResolvedConfigContext();
|
19
|
+
const { source: { mainEntryName } } = modernConfig;
|
18
20
|
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
19
21
|
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
20
22
|
const needModernServer = useSSR || useAPI || useWebServer;
|
21
|
-
|
22
|
-
let outputDirectory = path.resolve(appDirectory, ".output");
|
23
|
-
if (outputPath) {
|
24
|
-
outputDirectory = path.isAbsolute(outputPath) ? outputPath : path.resolve(outputPath);
|
25
|
-
}
|
23
|
+
let outputDirectory = path.join(appDirectory, ".output");
|
26
24
|
let funcsDirectory = outputDirectory;
|
27
25
|
let staticDirectory = path.join(outputDirectory, "static");
|
28
26
|
if (deployTarget === "node") {
|
29
27
|
await fse.remove(outputDirectory);
|
30
28
|
await fse.copy(distDirectory, outputDirectory);
|
31
29
|
}
|
30
|
+
if (deployTarget === "netlify") {
|
31
|
+
const netlifyOutput = path.join(appDirectory, ".netlify");
|
32
|
+
funcsDirectory = path.join(netlifyOutput, "functions");
|
33
|
+
const routes = [];
|
34
|
+
if (!needModernServer) {
|
35
|
+
entrypoints.forEach((entry) => {
|
36
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
37
|
+
routes.push({
|
38
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
39
|
+
dest: `/html/${entry.entryName}/index.html`,
|
40
|
+
status: 200
|
41
|
+
});
|
42
|
+
});
|
43
|
+
} else {
|
44
|
+
routes.push({
|
45
|
+
src: `/*`,
|
46
|
+
dest: `/.netlify/functions/index`,
|
47
|
+
status: 200
|
48
|
+
});
|
49
|
+
throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
|
50
|
+
}
|
51
|
+
console.log("routes", routes, needModernServer);
|
52
|
+
const redirectContent = routes.map((route) => {
|
53
|
+
return `${route.src} ${route.dest} ${route.status}`;
|
54
|
+
}).join("\n");
|
55
|
+
console.log("redirectContent", redirectContent);
|
56
|
+
await fse.remove(outputDirectory);
|
57
|
+
await fse.ensureDir(funcsDirectory);
|
58
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
59
|
+
filter: (src) => {
|
60
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
61
|
+
return !src.includes(distStaticDirectory);
|
62
|
+
}
|
63
|
+
});
|
64
|
+
const redirectFilePath = path.join(distDirectory, "_redirects");
|
65
|
+
await fse.writeFile(redirectFilePath, redirectContent);
|
66
|
+
}
|
32
67
|
if (deployTarget === "vercel") {
|
33
68
|
const vercelOutput = path.join(appDirectory, ".vercel");
|
34
69
|
await fse.remove(vercelOutput);
|
35
70
|
outputDirectory = path.join(vercelOutput, "output");
|
36
|
-
const
|
71
|
+
const config = {
|
37
72
|
version: 3,
|
38
73
|
routes: [
|
39
74
|
{
|
@@ -50,8 +85,9 @@ var deploy_default = () => ({
|
|
50
85
|
};
|
51
86
|
if (!needModernServer) {
|
52
87
|
entrypoints.forEach((entry) => {
|
53
|
-
|
54
|
-
|
88
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
89
|
+
config.routes.push({
|
90
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
55
91
|
headers: {
|
56
92
|
"cache-control": "s-maxage=0"
|
57
93
|
},
|
@@ -59,13 +95,13 @@ var deploy_default = () => ({
|
|
59
95
|
});
|
60
96
|
});
|
61
97
|
} else {
|
62
|
-
|
98
|
+
config.routes.push({
|
63
99
|
src: "/(.*)",
|
64
100
|
dest: `/index`
|
65
101
|
});
|
66
102
|
}
|
67
103
|
await fse.ensureDir(outputDirectory);
|
68
|
-
await fse.writeJSON(path.join(outputDirectory, "config.json"),
|
104
|
+
await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
69
105
|
spaces: 2
|
70
106
|
});
|
71
107
|
staticDirectory = path.join(outputDirectory, "static/static");
|
@@ -92,13 +128,6 @@ var deploy_default = () => ({
|
|
92
128
|
});
|
93
129
|
}
|
94
130
|
}
|
95
|
-
const { bff } = configContext;
|
96
|
-
const config = {
|
97
|
-
output: {
|
98
|
-
path: "."
|
99
|
-
},
|
100
|
-
bff
|
101
|
-
};
|
102
131
|
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
103
132
|
const serverAppContext = {
|
104
133
|
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
@@ -110,28 +139,28 @@ var deploy_default = () => ({
|
|
110
139
|
console.log("deployTarget111111111", deployTarget);
|
111
140
|
switch (deployTarget) {
|
112
141
|
case "node": {
|
113
|
-
const { genNodeEntry } = await import("./
|
142
|
+
const { genNodeEntry } = await import("./platforms/node");
|
114
143
|
code = genNodeEntry({
|
115
144
|
plugins,
|
116
|
-
config,
|
145
|
+
config: modernConfig,
|
117
146
|
appContext: serverAppContext
|
118
147
|
});
|
119
148
|
break;
|
120
149
|
}
|
121
150
|
case "vercel": {
|
122
|
-
const { genVercelEntry } = await import("./
|
123
|
-
code = genVercelEntry({
|
151
|
+
const { genVercelEntry } = await import("./platforms/vercel");
|
152
|
+
code = await genVercelEntry({
|
124
153
|
plugins,
|
125
|
-
config,
|
154
|
+
config: modernConfig,
|
126
155
|
appContext: serverAppContext
|
127
156
|
});
|
128
157
|
break;
|
129
158
|
}
|
130
159
|
case "netlify": {
|
131
|
-
const { genNetlifyEntry } = await import("./
|
160
|
+
const { genNetlifyEntry } = await import("./platforms/netlify");
|
132
161
|
code = genNetlifyEntry({
|
133
162
|
plugins,
|
134
|
-
config,
|
163
|
+
config: modernConfig,
|
135
164
|
appContext: serverAppContext
|
136
165
|
});
|
137
166
|
break;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
const fs = require("node:fs/promises");
|
2
|
+
const path = require("node:path");
|
3
|
+
const { createProdServer } = require("@modern-js/prod-server");
|
4
|
+
p_genPluginImportsCode;
|
5
|
+
if (!process.env.NODE_ENV) {
|
6
|
+
process.env.NODE_ENV = "production";
|
7
|
+
}
|
8
|
+
async function loadRoutes(routeFilepath) {
|
9
|
+
try {
|
10
|
+
await fs.access(routeFilepath);
|
11
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
12
|
+
const routeSpec = JSON.parse(content);
|
13
|
+
return routeSpec.routes || [];
|
14
|
+
} catch (error) {
|
15
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
16
|
+
return [];
|
17
|
+
}
|
18
|
+
}
|
19
|
+
async function main() {
|
20
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
21
|
+
const routes = await loadRoutes(routeFilepath);
|
22
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
23
|
+
const prodServerOptions = {
|
24
|
+
pwd: __dirname,
|
25
|
+
routes,
|
26
|
+
disableCustomHook: true,
|
27
|
+
...dynamicProdOptions
|
28
|
+
};
|
29
|
+
const app = await createProdServer(prodServerOptions);
|
30
|
+
const port = process.env.PORT || 8080;
|
31
|
+
app.listen(port, () => {
|
32
|
+
console.log("\\x1b[32mServer is listening on port", port, "\\x1b[0m");
|
33
|
+
});
|
34
|
+
}
|
35
|
+
main();
|
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();
|
@@ -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
|
};
|
@@ -24,7 +24,6 @@ declare const localeKeys: {
|
|
24
24
|
};
|
25
25
|
deploy: {
|
26
26
|
describe: string;
|
27
|
-
output: string;
|
28
27
|
};
|
29
28
|
new: {
|
30
29
|
describe: string;
|
@@ -64,7 +63,6 @@ declare const localeKeys: {
|
|
64
63
|
};
|
65
64
|
deploy: {
|
66
65
|
describe: string;
|
67
|
-
output: string;
|
68
66
|
};
|
69
67
|
new: {
|
70
68
|
describe: string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -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.10",
|
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/
|
84
|
-
"@modern-js/plugin": "2.49.2",
|
83
|
+
"@modern-js/core": "2.49.2",
|
85
84
|
"@modern-js/plugin-data-loader": "2.49.2",
|
85
|
+
"@modern-js/plugin": "2.49.2",
|
86
86
|
"@modern-js/plugin-i18n": "2.49.2",
|
87
|
-
"@modern-js/rsbuild-plugin-esbuild": "2.49.2",
|
88
87
|
"@modern-js/plugin-lint": "2.49.2",
|
89
|
-
"@modern-js/server
|
90
|
-
"@modern-js/
|
91
|
-
"@modern-js/types": "2.49.2",
|
92
|
-
"@modern-js/core": "2.49.2",
|
88
|
+
"@modern-js/prod-server": "2.49.2",
|
89
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.49.2",
|
93
90
|
"@modern-js/server-core": "2.49.2",
|
94
|
-
"@modern-js/utils": "2.49.2",
|
95
91
|
"@modern-js/uni-builder": "2.49.2",
|
96
|
-
"@modern-js/
|
92
|
+
"@modern-js/node-bundle-require": "2.49.2",
|
93
|
+
"@modern-js/types": "2.49.2",
|
94
|
+
"@modern-js/utils": "2.49.2",
|
95
|
+
"@modern-js/server": "2.49.2",
|
96
|
+
"@modern-js/server-utils": "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
|
-
};
|