@modern-js/app-tools 2.49.3-alpha.2 → 2.49.3-alpha.20
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/plugins/deploy/dependencies.js +1 -12
- package/dist/cjs/plugins/deploy/index.js +25 -147
- package/dist/cjs/plugins/deploy/platforms/netlify.js +120 -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 +41 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +145 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +22 -8
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/plugins/deploy/dependencies.js +1 -47
- package/dist/esm/plugins/deploy/index.js +66 -245
- package/dist/esm/plugins/deploy/platforms/netlify.js +182 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +122 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +104 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +220 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +55 -3
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/plugins/deploy/dependencies.js +1 -12
- package/dist/esm-node/plugins/deploy/index.js +24 -136
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +86 -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 +40 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +111 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +20 -7
- package/dist/esm-node/utils/routes.js +6 -2
- 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 +8 -1
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +21 -21
- package/dist/cjs/plugins/deploy/entrys/netlify.js +0 -95
- package/dist/cjs/plugins/deploy/entrys/node.js +0 -88
- package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -97
- package/dist/esm/plugins/deploy/entrys/netlify.js +0 -41
- package/dist/esm/plugins/deploy/entrys/node.js +0 -39
- package/dist/esm/plugins/deploy/entrys/vercel.js +0 -43
- package/dist/esm-node/plugins/deploy/entrys/netlify.js +0 -71
- package/dist/esm-node/plugins/deploy/entrys/node.js +0 -64
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -73
- package/dist/types/plugins/deploy/entrys/netlify.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/node.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/vercel.d.ts +0 -6
@@ -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,
|
@@ -37,16 +37,6 @@ var import_utils = require("@modern-js/utils");
|
|
37
37
|
var import_pkg_types = require("pkg-types");
|
38
38
|
var import_mlly = require("mlly");
|
39
39
|
var import_utils2 = require("./utils");
|
40
|
-
const readDirRecursive = async (dir) => {
|
41
|
-
const files = await import_utils.fs.readdir(dir, {
|
42
|
-
withFileTypes: true
|
43
|
-
});
|
44
|
-
const filesAndDirs = await Promise.all(files.map(async (file) => {
|
45
|
-
const resPath = import_node_path.default.resolve(dir, file.name);
|
46
|
-
return file.isDirectory() ? readDirRecursive(resPath) : resPath;
|
47
|
-
}));
|
48
|
-
return filesAndDirs.flat();
|
49
|
-
};
|
50
40
|
async function isFile(file) {
|
51
41
|
try {
|
52
42
|
const stat = await import_utils.fs.stat(file);
|
@@ -59,7 +49,7 @@ async function isFile(file) {
|
|
59
49
|
}
|
60
50
|
}
|
61
51
|
const findEntryFiles = async (rootDir) => {
|
62
|
-
const files = await readDirRecursive(rootDir);
|
52
|
+
const files = await (0, import_utils2.readDirRecursive)(rootDir);
|
63
53
|
return files;
|
64
54
|
};
|
65
55
|
const handleDependencies = async (appDir, serverRootDir, include) => {
|
@@ -212,7 +202,6 @@ const handleDependencies = async (appDir, serverRootDir, include) => {
|
|
212
202
|
const version = Object.keys(pkg.versions)[0];
|
213
203
|
return (0, import_utils2.writePackage)(pkg, version, serverRootDir);
|
214
204
|
}));
|
215
|
-
console.log("multiVersionPkgs111111111", multiVersionPkgs);
|
216
205
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
217
206
|
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
218
207
|
if (p1.length === 0) {
|
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
7
|
for (var name in all)
|
@@ -17,25 +15,32 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
19
|
var deploy_exports = {};
|
30
20
|
__export(deploy_exports, {
|
31
21
|
default: () => deploy_default
|
32
22
|
});
|
33
23
|
module.exports = __toCommonJS(deploy_exports);
|
34
|
-
var import_path = __toESM(require("path"));
|
35
|
-
var import_utils = require("@modern-js/utils");
|
36
24
|
var import_std_env = require("std-env");
|
37
|
-
var
|
38
|
-
var
|
25
|
+
var import_utils = require("./utils");
|
26
|
+
var import_node = require("./platforms/node");
|
27
|
+
var import_vercel = require("./platforms/vercel");
|
28
|
+
var import_netlify = require("./platforms/netlify");
|
29
|
+
const deployPresets = {
|
30
|
+
node: import_node.createNodePreset,
|
31
|
+
vercel: import_vercel.createVercelPreset,
|
32
|
+
netlify: import_netlify.createNetlifyPreset
|
33
|
+
};
|
34
|
+
async function getDeployPreset(appContext, modernConfig, deployTarget) {
|
35
|
+
const { appDirectory, distDirectory } = appContext;
|
36
|
+
const { useSSR, useAPI, useWebServer } = (0, import_utils.getProjectUsage)(appDirectory, distDirectory);
|
37
|
+
const needModernServer = useSSR || useAPI || useWebServer;
|
38
|
+
const createPreset = deployPresets[deployTarget];
|
39
|
+
if (!createPreset) {
|
40
|
+
throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
|
41
|
+
}
|
42
|
+
return createPreset(appContext, modernConfig, needModernServer);
|
43
|
+
}
|
39
44
|
var deploy_default = () => ({
|
40
45
|
name: "@modern-js/plugin-deploy",
|
41
46
|
pre: [
|
@@ -47,139 +52,12 @@ var deploy_default = () => ({
|
|
47
52
|
return {
|
48
53
|
async beforeDeploy() {
|
49
54
|
const appContext = api.useAppContext();
|
50
|
-
const
|
51
|
-
const
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
57
|
-
if (deployTarget === "node") {
|
58
|
-
await import_utils.fs.remove(outputDirectory);
|
59
|
-
await import_utils.fs.copy(distDirectory, outputDirectory);
|
60
|
-
}
|
61
|
-
if (deployTarget === "vercel") {
|
62
|
-
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
63
|
-
await import_utils.fs.remove(vercelOutput);
|
64
|
-
outputDirectory = import_path.default.join(vercelOutput, "output");
|
65
|
-
const config2 = {
|
66
|
-
version: 3,
|
67
|
-
routes: [
|
68
|
-
{
|
69
|
-
src: "/static/(.*)",
|
70
|
-
headers: {
|
71
|
-
"cache-control": "s-maxage=31536000, immutable"
|
72
|
-
},
|
73
|
-
continue: true
|
74
|
-
},
|
75
|
-
{
|
76
|
-
handle: "filesystem"
|
77
|
-
}
|
78
|
-
]
|
79
|
-
};
|
80
|
-
if (!needModernServer) {
|
81
|
-
entrypoints.forEach((entry) => {
|
82
|
-
config2.routes.push({
|
83
|
-
src: `/${entry.entryName}(?:/.*)?`,
|
84
|
-
headers: {
|
85
|
-
"cache-control": "s-maxage=0"
|
86
|
-
},
|
87
|
-
dest: `/html/${entry.entryName}/index.html`
|
88
|
-
});
|
89
|
-
});
|
90
|
-
} else {
|
91
|
-
config2.routes.push({
|
92
|
-
src: "/(.*)",
|
93
|
-
dest: `/index`
|
94
|
-
});
|
95
|
-
}
|
96
|
-
await import_utils.fs.ensureDir(outputDirectory);
|
97
|
-
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config2, {
|
98
|
-
spaces: 2
|
99
|
-
});
|
100
|
-
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
101
|
-
await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
|
102
|
-
if (!needModernServer) {
|
103
|
-
const destHtmlDirectory = import_path.default.join(distDirectory, "html");
|
104
|
-
const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
|
105
|
-
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
106
|
-
} else {
|
107
|
-
funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
|
108
|
-
await import_utils.fs.ensureDir(funcsDirectory);
|
109
|
-
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
110
|
-
filter: (src) => {
|
111
|
-
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
112
|
-
return !src.includes(distStaticDirectory);
|
113
|
-
}
|
114
|
-
});
|
115
|
-
const apiDirectory2 = import_path.default.join(funcsDirectory, "api");
|
116
|
-
if (await import_utils.fs.pathExists(apiDirectory2)) {
|
117
|
-
await import_utils.fs.rename(apiDirectory2, import_path.default.join(funcsDirectory, "_api"));
|
118
|
-
}
|
119
|
-
await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
|
120
|
-
runtime: "nodejs16.x",
|
121
|
-
handler: "index.js",
|
122
|
-
launcherType: "Nodejs",
|
123
|
-
shouldAddHelpers: false,
|
124
|
-
supportsResponseStreaming: true
|
125
|
-
});
|
126
|
-
}
|
127
|
-
}
|
128
|
-
const { bff } = configContext;
|
129
|
-
const config = {
|
130
|
-
output: {
|
131
|
-
path: "."
|
132
|
-
},
|
133
|
-
bff
|
134
|
-
};
|
135
|
-
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
136
|
-
const serverAppContext = {
|
137
|
-
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
138
|
-
apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
|
139
|
-
lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
|
140
|
-
metaName
|
141
|
-
};
|
142
|
-
let code = ``;
|
143
|
-
console.log("deployTarget111111111", deployTarget);
|
144
|
-
switch (deployTarget) {
|
145
|
-
case "node": {
|
146
|
-
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/node")));
|
147
|
-
code = genNodeEntry({
|
148
|
-
plugins,
|
149
|
-
config,
|
150
|
-
appContext: serverAppContext
|
151
|
-
});
|
152
|
-
break;
|
153
|
-
}
|
154
|
-
case "vercel": {
|
155
|
-
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/vercel")));
|
156
|
-
code = genVercelEntry({
|
157
|
-
plugins,
|
158
|
-
config,
|
159
|
-
appContext: serverAppContext
|
160
|
-
});
|
161
|
-
break;
|
162
|
-
}
|
163
|
-
case "netlify": {
|
164
|
-
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/netlify")));
|
165
|
-
code = genNetlifyEntry({
|
166
|
-
plugins,
|
167
|
-
config,
|
168
|
-
appContext: serverAppContext
|
169
|
-
});
|
170
|
-
break;
|
171
|
-
}
|
172
|
-
default: {
|
173
|
-
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
174
|
-
}
|
175
|
-
}
|
176
|
-
const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
|
177
|
-
if (needModernServer) {
|
178
|
-
await import_utils.fs.writeFile(entryFilePath, code);
|
179
|
-
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
180
|
-
"@modern-js/prod-server"
|
181
|
-
]);
|
182
|
-
}
|
55
|
+
const modernConfig = api.useResolvedConfigContext();
|
56
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
57
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
58
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
59
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
60
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
|
183
61
|
}
|
184
62
|
};
|
185
63
|
}
|
@@ -0,0 +1,120 @@
|
|
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 netlify_exports = {};
|
30
|
+
__export(netlify_exports, {
|
31
|
+
createNetlifyPreset: () => createNetlifyPreset
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(netlify_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 createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
40
|
+
const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
|
41
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
42
|
+
const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
|
43
|
+
const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
|
44
|
+
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
45
|
+
return {
|
46
|
+
async prepare() {
|
47
|
+
await import_utils.fs.remove(netlifyOutput);
|
48
|
+
},
|
49
|
+
async writeOutput() {
|
50
|
+
const routes = [];
|
51
|
+
const { source: { mainEntryName } } = modernConfig;
|
52
|
+
if (!needModernServer) {
|
53
|
+
entrypoints.forEach((entry) => {
|
54
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
55
|
+
routes.push({
|
56
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
57
|
+
dest: `/html/${entry.entryName}/index.html`,
|
58
|
+
status: 200
|
59
|
+
});
|
60
|
+
});
|
61
|
+
} else {
|
62
|
+
routes.push({
|
63
|
+
src: "/*",
|
64
|
+
dest: `/.netlify/functions/index`,
|
65
|
+
status: 200
|
66
|
+
});
|
67
|
+
}
|
68
|
+
const redirectContent = routes.map((route) => {
|
69
|
+
return `${route.src} ${route.dest} ${route.status}`;
|
70
|
+
}).join("\n");
|
71
|
+
if (needModernServer) {
|
72
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
73
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory);
|
74
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
75
|
+
filter: (src) => {
|
76
|
+
const distStaticDirectory = import_node_path.default.join(distDirectory, `static`);
|
77
|
+
return !src.includes(distStaticDirectory);
|
78
|
+
}
|
79
|
+
});
|
80
|
+
}
|
81
|
+
const redirectFilePath = import_node_path.default.join(distDirectory, "_redirects");
|
82
|
+
await import_utils.fs.writeFile(redirectFilePath, redirectContent);
|
83
|
+
},
|
84
|
+
async genEntry() {
|
85
|
+
var _modernConfig_bff;
|
86
|
+
if (!needModernServer) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
const serverConfig = {
|
90
|
+
bff: {
|
91
|
+
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
92
|
+
},
|
93
|
+
output: {
|
94
|
+
path: "."
|
95
|
+
}
|
96
|
+
};
|
97
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
98
|
+
const dynamicProdOptions = {
|
99
|
+
config: serverConfig,
|
100
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
101
|
+
plugins
|
102
|
+
};
|
103
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlifyEntry.js"))).toString();
|
104
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
105
|
+
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);
|
106
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
107
|
+
},
|
108
|
+
async end() {
|
109
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
110
|
+
"@modern-js/prod-server"
|
111
|
+
]);
|
112
|
+
const netlifyNodeModules = import_node_path.default.join(netlifyOutput, "node_modules");
|
113
|
+
await import_utils.fs.move(import_node_path.default.join(funcsDirectory, "node_modules"), netlifyNodeModules);
|
114
|
+
}
|
115
|
+
};
|
116
|
+
};
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
118
|
+
0 && (module.exports = {
|
119
|
+
createNetlifyPreset
|
120
|
+
});
|
@@ -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, needModernServer) => {
|
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
|
+
if (!needModernServer) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
const serverConfig = {
|
57
|
+
server: {
|
58
|
+
port: 8080
|
59
|
+
},
|
60
|
+
bff: {
|
61
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
62
|
+
},
|
63
|
+
output: {
|
64
|
+
path: "."
|
65
|
+
}
|
66
|
+
};
|
67
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
68
|
+
const dynamicProdOptions = {
|
69
|
+
config: serverConfig,
|
70
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
71
|
+
plugins
|
72
|
+
};
|
73
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
74
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
75
|
+
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);
|
76
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
77
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
|
78
|
+
"@modern-js/prod-server"
|
79
|
+
]);
|
80
|
+
},
|
81
|
+
async end() {
|
82
|
+
console.log("Static directory:", import_utils.chalk.blue(import_node_path.default.relative(appDirectory, staticDirectory)));
|
83
|
+
console.log(`You can preview this build by`, import_utils.chalk.blue(`node .output/index`));
|
84
|
+
}
|
85
|
+
};
|
86
|
+
};
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
88
|
+
0 && (module.exports = {
|
89
|
+
createNodePreset
|
90
|
+
});
|
@@ -0,0 +1,41 @@
|
|
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(port, () => {
|
38
|
+
console.log("\x1B[32mServer is listening on port", port, "\x1B[0m");
|
39
|
+
});
|
40
|
+
}
|
41
|
+
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);
|