@modern-js/app-tools 2.49.3-alpha.0 → 2.49.3-alpha.10
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/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
@@ -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,
|
package/dist/cjs/index.js
CHANGED
@@ -154,7 +154,7 @@ const appTools = (options = {
|
|
154
154
|
const { start } = await Promise.resolve().then(() => __toESM(require("./commands/serve")));
|
155
155
|
await start(api);
|
156
156
|
});
|
157
|
-
program.command("deploy").usage("[options]").option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-s --skip-build", import_locale.i18n.t(import_locale.localeKeys.command.shared.skipBuild)).
|
157
|
+
program.command("deploy").usage("[options]").option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-s --skip-build", import_locale.i18n.t(import_locale.localeKeys.command.shared.skipBuild)).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action(async (options2) => {
|
158
158
|
if (!options2.skipBuild) {
|
159
159
|
const { build } = await Promise.resolve().then(() => __toESM(require("./commands/build")));
|
160
160
|
await build(api);
|
package/dist/cjs/locale/en.js
CHANGED
@@ -44,8 +44,7 @@ const EN_LOCALE = {
|
|
44
44
|
describe: "preview the production build locally"
|
45
45
|
},
|
46
46
|
deploy: {
|
47
|
-
describe: "deploy the application"
|
48
|
-
output: "output path"
|
47
|
+
describe: "deploy the application"
|
49
48
|
},
|
50
49
|
new: {
|
51
50
|
describe: "enable optional features or add a new entry",
|
package/dist/cjs/locale/zh.js
CHANGED
@@ -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 = () => ({
|
@@ -45,28 +46,62 @@ var deploy_default = () => ({
|
|
45
46
|
setup: (api) => {
|
46
47
|
const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
|
47
48
|
return {
|
48
|
-
async beforeDeploy(
|
49
|
-
const { output: outputPath } = options;
|
49
|
+
async beforeDeploy() {
|
50
50
|
const appContext = api.useAppContext();
|
51
|
+
const modernConfig = api.useResolvedConfigContext();
|
52
|
+
const { source: { mainEntryName } } = modernConfig;
|
51
53
|
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
52
54
|
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
53
55
|
const needModernServer = useSSR || useAPI || useWebServer;
|
54
|
-
|
55
|
-
let outputDirectory = import_path.default.resolve(appDirectory, ".output");
|
56
|
-
if (outputPath) {
|
57
|
-
outputDirectory = import_path.default.isAbsolute(outputPath) ? outputPath : import_path.default.resolve(outputPath);
|
58
|
-
}
|
56
|
+
let outputDirectory = import_path.default.join(appDirectory, ".output");
|
59
57
|
let funcsDirectory = outputDirectory;
|
60
58
|
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
61
59
|
if (deployTarget === "node") {
|
62
60
|
await import_utils.fs.remove(outputDirectory);
|
63
61
|
await import_utils.fs.copy(distDirectory, outputDirectory);
|
64
62
|
}
|
63
|
+
if (deployTarget === "netlify") {
|
64
|
+
const netlifyOutput = import_path.default.join(appDirectory, ".netlify");
|
65
|
+
funcsDirectory = import_path.default.join(netlifyOutput, "functions");
|
66
|
+
const routes = [];
|
67
|
+
if (!needModernServer) {
|
68
|
+
entrypoints.forEach((entry) => {
|
69
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
70
|
+
routes.push({
|
71
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
72
|
+
dest: `/html/${entry.entryName}/index.html`,
|
73
|
+
status: 200
|
74
|
+
});
|
75
|
+
});
|
76
|
+
} else {
|
77
|
+
routes.push({
|
78
|
+
src: `/*`,
|
79
|
+
dest: `/.netlify/functions/index`,
|
80
|
+
status: 200
|
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
|
+
}
|
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
|
+
await import_utils.fs.remove(outputDirectory);
|
90
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
91
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
92
|
+
filter: (src) => {
|
93
|
+
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
94
|
+
return !src.includes(distStaticDirectory);
|
95
|
+
}
|
96
|
+
});
|
97
|
+
const redirectFilePath = import_path.default.join(distDirectory, "_redirects");
|
98
|
+
await import_utils.fs.writeFile(redirectFilePath, redirectContent);
|
99
|
+
}
|
65
100
|
if (deployTarget === "vercel") {
|
66
101
|
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
67
102
|
await import_utils.fs.remove(vercelOutput);
|
68
103
|
outputDirectory = import_path.default.join(vercelOutput, "output");
|
69
|
-
const
|
104
|
+
const config = {
|
70
105
|
version: 3,
|
71
106
|
routes: [
|
72
107
|
{
|
@@ -83,8 +118,9 @@ var deploy_default = () => ({
|
|
83
118
|
};
|
84
119
|
if (!needModernServer) {
|
85
120
|
entrypoints.forEach((entry) => {
|
86
|
-
|
87
|
-
|
121
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
122
|
+
config.routes.push({
|
123
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
88
124
|
headers: {
|
89
125
|
"cache-control": "s-maxage=0"
|
90
126
|
},
|
@@ -92,13 +128,13 @@ var deploy_default = () => ({
|
|
92
128
|
});
|
93
129
|
});
|
94
130
|
} else {
|
95
|
-
|
131
|
+
config.routes.push({
|
96
132
|
src: "/(.*)",
|
97
133
|
dest: `/index`
|
98
134
|
});
|
99
135
|
}
|
100
136
|
await import_utils.fs.ensureDir(outputDirectory);
|
101
|
-
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, {
|
102
138
|
spaces: 2
|
103
139
|
});
|
104
140
|
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
@@ -125,13 +161,6 @@ var deploy_default = () => ({
|
|
125
161
|
});
|
126
162
|
}
|
127
163
|
}
|
128
|
-
const { bff } = configContext;
|
129
|
-
const config = {
|
130
|
-
output: {
|
131
|
-
path: "."
|
132
|
-
},
|
133
|
-
bff
|
134
|
-
};
|
135
164
|
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
136
165
|
const serverAppContext = {
|
137
166
|
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
@@ -143,28 +172,28 @@ var deploy_default = () => ({
|
|
143
172
|
console.log("deployTarget111111111", deployTarget);
|
144
173
|
switch (deployTarget) {
|
145
174
|
case "node": {
|
146
|
-
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./
|
175
|
+
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
|
147
176
|
code = genNodeEntry({
|
148
177
|
plugins,
|
149
|
-
config,
|
178
|
+
config: modernConfig,
|
150
179
|
appContext: serverAppContext
|
151
180
|
});
|
152
181
|
break;
|
153
182
|
}
|
154
183
|
case "vercel": {
|
155
|
-
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./
|
156
|
-
code = genVercelEntry({
|
184
|
+
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
|
185
|
+
code = await genVercelEntry({
|
157
186
|
plugins,
|
158
|
-
config,
|
187
|
+
config: modernConfig,
|
159
188
|
appContext: serverAppContext
|
160
189
|
});
|
161
190
|
break;
|
162
191
|
}
|
163
192
|
case "netlify": {
|
164
|
-
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./
|
193
|
+
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
|
165
194
|
code = genNetlifyEntry({
|
166
195
|
plugins,
|
167
|
-
config,
|
196
|
+
config: modernConfig,
|
168
197
|
appContext: serverAppContext
|
169
198
|
});
|
170
199
|
break;
|
@@ -0,0 +1,36 @@
|
|
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
|
+
async function loadRoutes(routeFilepath) {
|
10
|
+
try {
|
11
|
+
await fs.access(routeFilepath);
|
12
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
13
|
+
const routeSpec = JSON.parse(content);
|
14
|
+
return routeSpec.routes || [];
|
15
|
+
} catch (error) {
|
16
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
17
|
+
return [];
|
18
|
+
}
|
19
|
+
}
|
20
|
+
async function main() {
|
21
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
22
|
+
const routes = await loadRoutes(routeFilepath);
|
23
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
24
|
+
const prodServerOptions = {
|
25
|
+
pwd: __dirname,
|
26
|
+
routes,
|
27
|
+
disableCustomHook: true,
|
28
|
+
...dynamicProdOptions
|
29
|
+
};
|
30
|
+
const app = await createProdServer(prodServerOptions);
|
31
|
+
const port = process.env.PORT || 8080;
|
32
|
+
app.listen(port, () => {
|
33
|
+
console.log("\\x1b[32mServer is listening on port", port, "\\x1b[0m");
|
34
|
+
});
|
35
|
+
}
|
36
|
+
main();
|
@@ -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
|
+
};
|
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,
|
package/dist/esm/index.js
CHANGED
@@ -368,7 +368,7 @@ var appTools = function() {
|
|
368
368
|
}
|
369
369
|
});
|
370
370
|
}));
|
371
|
-
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)).
|
371
|
+
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(function() {
|
372
372
|
var _ref = _async_to_generator(function(options2) {
|
373
373
|
var build, deploy;
|
374
374
|
return _ts_generator(this, function(_state2) {
|
package/dist/esm/locale/en.js
CHANGED
@@ -21,8 +21,7 @@ var 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",
|