@modern-js/app-tools 2.50.0 → 2.51.0
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/commands/deploy.js +1 -0
- package/dist/cjs/hooks.js +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +217 -0
- package/dist/cjs/plugins/deploy/dependencies/utils.js +165 -0
- package/dist/cjs/plugins/deploy/index.js +64 -0
- package/dist/cjs/plugins/deploy/platforms/netlify.js +136 -0
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +90 -0
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +44 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +148 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +81 -0
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/commands/deploy.js +7 -1
- package/dist/esm/hooks.js +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +580 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +407 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +291 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +124 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +107 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +225 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/commands/deploy.js +1 -0
- package/dist/esm-node/hooks.js +1 -0
- package/dist/esm-node/index.js +3 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +183 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +124 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +102 -0
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +56 -0
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +43 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +114 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/defineConfig.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -0
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +31 -0
- package/dist/types/plugins/deploy/index.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +10 -0
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/utils.d.ts +20 -0
- package/dist/types/types/hooks.d.ts +1 -0
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +26 -22
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
const fs = require("node:fs/promises");
|
3
|
+
const path = require("node:path");
|
4
|
+
const { createNetlifyFunction } = require("@modern-js/prod-server/netlify");
|
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
|
+
appContext: {
|
31
|
+
sharedDirectory: p_sharedDirectory,
|
32
|
+
apiDirectory: p_apiDirectory,
|
33
|
+
lambdaDirectory: p_lambdaDirectory
|
34
|
+
},
|
35
|
+
...dynamicProdOptions
|
36
|
+
};
|
37
|
+
const requestHandler2 = await createNetlifyFunction(prodServerOptions);
|
38
|
+
return requestHandler2;
|
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.default = async (request, context) => {
|
56
|
+
if (!requestHandler) {
|
57
|
+
await createHandler();
|
58
|
+
}
|
59
|
+
return requestHandler(request, context);
|
60
|
+
};
|
@@ -0,0 +1,90 @@
|
|
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 node_exports = {};
|
30
|
+
__export(node_exports, {
|
31
|
+
createNodePreset: () => createNodePreset
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(node_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
|
+
var import_dependencies = require("../dependencies");
|
38
|
+
const createNodePreset = (appContext, config) => {
|
39
|
+
const { appDirectory, distDirectory, serverInternalPlugins } = appContext;
|
40
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
41
|
+
const outputDirectory = import_node_path.default.join(appDirectory, ".output");
|
42
|
+
const staticDirectory = import_node_path.default.join(outputDirectory, "static");
|
43
|
+
const entryFilePath = import_node_path.default.join(outputDirectory, "index.js");
|
44
|
+
return {
|
45
|
+
async prepare() {
|
46
|
+
await import_utils.fs.remove(outputDirectory);
|
47
|
+
},
|
48
|
+
async writeOutput() {
|
49
|
+
await import_utils.fs.copy(distDirectory, outputDirectory);
|
50
|
+
},
|
51
|
+
async genEntry() {
|
52
|
+
var _config_bff;
|
53
|
+
const serverConfig = {
|
54
|
+
server: {
|
55
|
+
port: 8080
|
56
|
+
},
|
57
|
+
bff: {
|
58
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
59
|
+
},
|
60
|
+
output: {
|
61
|
+
path: "."
|
62
|
+
}
|
63
|
+
};
|
64
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
65
|
+
const dynamicProdOptions = {
|
66
|
+
config: serverConfig,
|
67
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
68
|
+
plugins
|
69
|
+
};
|
70
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
71
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
72
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
73
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
74
|
+
},
|
75
|
+
async end() {
|
76
|
+
console.log("Static directory:", import_utils.chalk.blue(import_node_path.default.relative(appDirectory, staticDirectory)));
|
77
|
+
console.log(`You can preview this build by`, import_utils.chalk.blue(`node .output/index`));
|
78
|
+
const filter = (filePath) => {
|
79
|
+
return !filePath.startsWith(staticDirectory);
|
80
|
+
};
|
81
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
|
82
|
+
"@modern-js/prod-server"
|
83
|
+
], filter);
|
84
|
+
}
|
85
|
+
};
|
86
|
+
};
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
88
|
+
0 && (module.exports = {
|
89
|
+
createNodePreset
|
90
|
+
});
|
@@ -0,0 +1,44 @@
|
|
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
|
+
appContext: {
|
29
|
+
sharedDirectory: p_sharedDirectory,
|
30
|
+
apiDirectory: p_apiDirectory,
|
31
|
+
lambdaDirectory: p_lambdaDirectory
|
32
|
+
},
|
33
|
+
...dynamicProdOptions
|
34
|
+
};
|
35
|
+
const app = await createProdServer(prodServerOptions);
|
36
|
+
const port = process.env.PORT || 8080;
|
37
|
+
app.listen({
|
38
|
+
host: "::",
|
39
|
+
port
|
40
|
+
}, () => {
|
41
|
+
console.log(`\x1B[32mServer is listening on http://[::]:${port}`, "\x1B[0m");
|
42
|
+
});
|
43
|
+
}
|
44
|
+
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,148 @@
|
|
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
|
+
createVercelPreset: () => createVercelPreset
|
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_routes = require("../../../utils/routes");
|
37
|
+
var import_utils2 = require("../utils");
|
38
|
+
var import_dependencies = require("../dependencies");
|
39
|
+
const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
40
|
+
const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
|
41
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
42
|
+
const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
|
43
|
+
const outputDirectory = import_node_path.default.join(vercelOutput, "output");
|
44
|
+
const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
|
45
|
+
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
46
|
+
return {
|
47
|
+
async prepare() {
|
48
|
+
await import_utils.fs.remove(vercelOutput);
|
49
|
+
},
|
50
|
+
async writeOutput() {
|
51
|
+
const config = {
|
52
|
+
version: 3,
|
53
|
+
routes: [
|
54
|
+
{
|
55
|
+
src: "/static/(.*)",
|
56
|
+
headers: {
|
57
|
+
"cache-control": "s-maxage=31536000, immutable"
|
58
|
+
},
|
59
|
+
continue: true
|
60
|
+
},
|
61
|
+
{
|
62
|
+
handle: "filesystem"
|
63
|
+
}
|
64
|
+
]
|
65
|
+
};
|
66
|
+
if (!needModernServer) {
|
67
|
+
const { source: { mainEntryName } } = modernConfig;
|
68
|
+
entrypoints.forEach((entry) => {
|
69
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
70
|
+
config.routes.push({
|
71
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
72
|
+
headers: {
|
73
|
+
"cache-control": "s-maxage=0"
|
74
|
+
},
|
75
|
+
dest: `/html/${entry.entryName}/index.html`
|
76
|
+
});
|
77
|
+
});
|
78
|
+
} else {
|
79
|
+
config.routes.push({
|
80
|
+
src: "/(.*)",
|
81
|
+
dest: `/index`
|
82
|
+
});
|
83
|
+
}
|
84
|
+
await import_utils.fs.ensureDir(outputDirectory);
|
85
|
+
await import_utils.fs.writeJSON(import_node_path.default.join(outputDirectory, "config.json"), config, {
|
86
|
+
spaces: 2
|
87
|
+
});
|
88
|
+
const staticDirectory = import_node_path.default.join(outputDirectory, "static/static");
|
89
|
+
await import_utils.fs.copy(import_node_path.default.join(distDirectory, "static"), staticDirectory);
|
90
|
+
if (!needModernServer) {
|
91
|
+
const destHtmlDirectory = import_node_path.default.join(distDirectory, "html");
|
92
|
+
const outputHtmlDirectory = import_node_path.default.join(import_node_path.default.join(outputDirectory, "static"), "html");
|
93
|
+
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
94
|
+
} else {
|
95
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
96
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
97
|
+
filter: (src) => {
|
98
|
+
const distStaticDirectory = import_node_path.default.join(distDirectory, "static");
|
99
|
+
return !src.includes(distStaticDirectory);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
await import_utils.fs.writeJSON(import_node_path.default.join(funcsDirectory, ".vc-config.json"), {
|
103
|
+
runtime: "nodejs16.x",
|
104
|
+
handler: "index.js",
|
105
|
+
launcherType: "Nodejs",
|
106
|
+
shouldAddHelpers: false,
|
107
|
+
supportsResponseStreaming: true
|
108
|
+
});
|
109
|
+
}
|
110
|
+
},
|
111
|
+
async genEntry() {
|
112
|
+
var _modernConfig_bff;
|
113
|
+
if (!needModernServer) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
const serverConfig = {
|
117
|
+
bff: {
|
118
|
+
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
119
|
+
},
|
120
|
+
output: {
|
121
|
+
path: "."
|
122
|
+
}
|
123
|
+
};
|
124
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
125
|
+
const dynamicProdOptions = {
|
126
|
+
config: serverConfig,
|
127
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
128
|
+
plugins
|
129
|
+
};
|
130
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
131
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
132
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
133
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
134
|
+
},
|
135
|
+
async end() {
|
136
|
+
if (!needModernServer) {
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
140
|
+
"@modern-js/prod-server"
|
141
|
+
]);
|
142
|
+
}
|
143
|
+
};
|
144
|
+
};
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
146
|
+
0 && (module.exports = {
|
147
|
+
createVercelPreset
|
148
|
+
});
|
@@ -0,0 +1,60 @@
|
|
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
|
+
appContext: {
|
31
|
+
sharedDirectory: p_sharedDirectory,
|
32
|
+
apiDirectory: p_apiDirectory,
|
33
|
+
lambdaDirectory: p_lambdaDirectory
|
34
|
+
},
|
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
|
+
};
|
@@ -0,0 +1,81 @@
|
|
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 utils_exports = {};
|
30
|
+
__export(utils_exports, {
|
31
|
+
genPluginImportsCode: () => genPluginImportsCode,
|
32
|
+
getPluginsCode: () => getPluginsCode,
|
33
|
+
getProjectUsage: () => getProjectUsage,
|
34
|
+
serverAppContenxtTemplate: () => serverAppContenxtTemplate
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(utils_exports);
|
37
|
+
var import_path = __toESM(require("path"));
|
38
|
+
var import_utils = require("@modern-js/utils");
|
39
|
+
const serverAppContenxtTemplate = (appContext) => {
|
40
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
|
41
|
+
return {
|
42
|
+
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
43
|
+
apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
|
44
|
+
lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
|
45
|
+
metaName
|
46
|
+
};
|
47
|
+
};
|
48
|
+
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
49
|
+
const genPluginImportsCode = (plugins) => {
|
50
|
+
return plugins.map((plugin, index) => `
|
51
|
+
let plugin_${index} = require('${plugin}')
|
52
|
+
plugin_${index} = plugin_${index}.default || plugin_${index}
|
53
|
+
`).join(";\n");
|
54
|
+
};
|
55
|
+
const getProjectUsage = (appDirectory, distDirectory) => {
|
56
|
+
const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
|
57
|
+
const { routes } = import_utils.fs.readJSONSync(routeJSON);
|
58
|
+
let useSSR = false;
|
59
|
+
let useAPI = false;
|
60
|
+
routes.forEach((route) => {
|
61
|
+
if (route.isSSR) {
|
62
|
+
useSSR = true;
|
63
|
+
}
|
64
|
+
if (route.isApi) {
|
65
|
+
useAPI = true;
|
66
|
+
}
|
67
|
+
});
|
68
|
+
const useWebServer = (0, import_utils.isDepExists)(appDirectory, "@modern-js/plugin-server");
|
69
|
+
return {
|
70
|
+
useSSR,
|
71
|
+
useAPI,
|
72
|
+
useWebServer
|
73
|
+
};
|
74
|
+
};
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
76
|
+
0 && (module.exports = {
|
77
|
+
genPluginImportsCode,
|
78
|
+
getPluginsCode,
|
79
|
+
getProjectUsage,
|
80
|
+
serverAppContenxtTemplate
|
81
|
+
});
|
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,
|
@@ -22,9 +22,15 @@ var deploy = function() {
|
|
22
22
|
_state.sent();
|
23
23
|
return [
|
24
24
|
4,
|
25
|
-
hookRunners.
|
25
|
+
hookRunners.deploy(options)
|
26
26
|
];
|
27
27
|
case 3:
|
28
|
+
_state.sent();
|
29
|
+
return [
|
30
|
+
4,
|
31
|
+
hookRunners.afterDeploy(options)
|
32
|
+
];
|
33
|
+
case 4:
|
28
34
|
_state.sent();
|
29
35
|
return [
|
30
36
|
2
|
package/dist/esm/hooks.js
CHANGED
@@ -19,6 +19,7 @@ var hooks = {
|
|
19
19
|
beforeBuild: createAsyncWorkflow(),
|
20
20
|
afterBuild: createAsyncWorkflow(),
|
21
21
|
beforeDeploy: createAsyncWorkflow(),
|
22
|
+
deploy: createAsyncWorkflow(),
|
22
23
|
afterDeploy: createAsyncWorkflow(),
|
23
24
|
beforeRestart: createAsyncWorkflow(),
|
24
25
|
registerDev: createParallelWorkflow(),
|
package/dist/esm/index.js
CHANGED
@@ -12,6 +12,7 @@ import initializePlugin from "./initialize";
|
|
12
12
|
import { hooks } from "./hooks";
|
13
13
|
import { i18n, localeKeys } from "./locale";
|
14
14
|
import serverBuildPlugin from "./plugins/serverBuild";
|
15
|
+
import deployPlugin from "./plugins/deploy";
|
15
16
|
import { restart } from "./utils/restart";
|
16
17
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
17
18
|
import { mergeConfig } from "@modern-js/core";
|
@@ -295,7 +296,8 @@ var appTools = function() {
|
|
295
296
|
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
296
297
|
}),
|
297
298
|
serverBuildPlugin(),
|
298
|
-
lintPlugin()
|
299
|
+
lintPlugin(),
|
300
|
+
deployPlugin()
|
299
301
|
],
|
300
302
|
setup: function(api) {
|
301
303
|
var appContext = api.useAppContext();
|