@modern-js/app-tools 2.49.3-alpha.13 → 2.49.3-alpha.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/index copy.js +216 -0
- package/dist/cjs/plugins/deploy/index.js +13 -169
- package/dist/cjs/plugins/deploy/platforms/netlify.js +112 -64
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +41 -18
- package/dist/cjs/plugins/deploy/platforms/vercel.js +103 -16
- package/dist/cjs/plugins/deploy/utils.js +10 -8
- package/dist/esm/plugins/deploy/index copy.js +367 -0
- package/dist/esm/plugins/deploy/index.js +17 -314
- package/dist/esm/plugins/deploy/platforms/netlify.js +203 -36
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +100 -43
- package/dist/esm/plugins/deploy/platforms/vercel.js +203 -40
- package/dist/esm/plugins/deploy/utils.js +9 -3
- package/dist/esm-node/plugins/deploy/index copy.js +186 -0
- package/dist/esm-node/plugins/deploy/index.js +11 -157
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +103 -65
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +42 -19
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +104 -17
- package/dist/esm-node/plugins/deploy/utils.js +9 -7
- package/dist/types/plugins/deploy/index copy.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -5
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -8
- package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -4
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -8
- package/dist/types/plugins/deploy/utils.d.ts +7 -1
- package/package.json +8 -8
@@ -0,0 +1,216 @@
|
|
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 index_copy_exports = {};
|
30
|
+
__export(index_copy_exports, {
|
31
|
+
default: () => index_copy_default
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(index_copy_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
var import_utils = require("@modern-js/utils");
|
36
|
+
var import_std_env = require("std-env");
|
37
|
+
var import_routes = require("../../utils/routes");
|
38
|
+
var import_utils2 = require("./utils");
|
39
|
+
var import_dependencies = require("./dependencies");
|
40
|
+
var index_copy_default = () => ({
|
41
|
+
name: "@modern-js/plugin-deploy",
|
42
|
+
pre: [
|
43
|
+
"@modern-js/plugin-bff",
|
44
|
+
"@modern-js/plugin-server"
|
45
|
+
],
|
46
|
+
setup: (api) => {
|
47
|
+
const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
|
48
|
+
return {
|
49
|
+
async beforeDeploy() {
|
50
|
+
const appContext = api.useAppContext();
|
51
|
+
const modernConfig = api.useResolvedConfigContext();
|
52
|
+
const { source: { mainEntryName } } = modernConfig;
|
53
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
54
|
+
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
55
|
+
const needModernServer = useSSR || useAPI || useWebServer;
|
56
|
+
let outputDirectory = import_path.default.join(appDirectory, ".output");
|
57
|
+
let funcsDirectory = outputDirectory;
|
58
|
+
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
59
|
+
if (deployTarget === "node") {
|
60
|
+
await import_utils.fs.remove(outputDirectory);
|
61
|
+
await import_utils.fs.copy(distDirectory, outputDirectory);
|
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 supported, 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
|
+
}
|
100
|
+
if (deployTarget === "vercel") {
|
101
|
+
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
102
|
+
await import_utils.fs.remove(vercelOutput);
|
103
|
+
outputDirectory = import_path.default.join(vercelOutput, "output");
|
104
|
+
const config = {
|
105
|
+
version: 3,
|
106
|
+
routes: [
|
107
|
+
{
|
108
|
+
src: "/static/(.*)",
|
109
|
+
headers: {
|
110
|
+
"cache-control": "s-maxage=31536000, immutable"
|
111
|
+
},
|
112
|
+
continue: true
|
113
|
+
},
|
114
|
+
{
|
115
|
+
handle: "filesystem"
|
116
|
+
}
|
117
|
+
]
|
118
|
+
};
|
119
|
+
if (!needModernServer) {
|
120
|
+
entrypoints.forEach((entry) => {
|
121
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
122
|
+
config.routes.push({
|
123
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
124
|
+
headers: {
|
125
|
+
"cache-control": "s-maxage=0"
|
126
|
+
},
|
127
|
+
dest: `/html/${entry.entryName}/index.html`
|
128
|
+
});
|
129
|
+
});
|
130
|
+
} else {
|
131
|
+
config.routes.push({
|
132
|
+
src: "/(.*)",
|
133
|
+
dest: `/index`
|
134
|
+
});
|
135
|
+
}
|
136
|
+
await import_utils.fs.ensureDir(outputDirectory);
|
137
|
+
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config, {
|
138
|
+
spaces: 2
|
139
|
+
});
|
140
|
+
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
141
|
+
await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
|
142
|
+
if (!needModernServer) {
|
143
|
+
const destHtmlDirectory = import_path.default.join(distDirectory, "html");
|
144
|
+
const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
|
145
|
+
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
146
|
+
} else {
|
147
|
+
funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
|
148
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
149
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
150
|
+
filter: (src) => {
|
151
|
+
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
152
|
+
return !src.includes(distStaticDirectory);
|
153
|
+
}
|
154
|
+
});
|
155
|
+
await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
|
156
|
+
runtime: "nodejs16.x",
|
157
|
+
handler: "index.js",
|
158
|
+
launcherType: "Nodejs",
|
159
|
+
shouldAddHelpers: false,
|
160
|
+
supportsResponseStreaming: true
|
161
|
+
});
|
162
|
+
}
|
163
|
+
}
|
164
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
165
|
+
const serverAppContext = {
|
166
|
+
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
167
|
+
apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
|
168
|
+
lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
|
169
|
+
metaName
|
170
|
+
};
|
171
|
+
console.log("serverAppContext", serverAppContext);
|
172
|
+
let code = ``;
|
173
|
+
console.log("deployTarget111111111", deployTarget);
|
174
|
+
switch (deployTarget) {
|
175
|
+
case "node": {
|
176
|
+
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
|
177
|
+
code = await genNodeEntry({
|
178
|
+
plugins,
|
179
|
+
config: modernConfig,
|
180
|
+
appContext: serverAppContext
|
181
|
+
});
|
182
|
+
break;
|
183
|
+
}
|
184
|
+
case "vercel": {
|
185
|
+
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
|
186
|
+
code = await genVercelEntry({
|
187
|
+
plugins,
|
188
|
+
config: modernConfig,
|
189
|
+
appContext: serverAppContext
|
190
|
+
});
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
case "netlify": {
|
194
|
+
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
|
195
|
+
code = await genNetlifyEntry({
|
196
|
+
plugins,
|
197
|
+
config: modernConfig,
|
198
|
+
appContext: serverAppContext
|
199
|
+
});
|
200
|
+
break;
|
201
|
+
}
|
202
|
+
default: {
|
203
|
+
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
|
207
|
+
if (needModernServer) {
|
208
|
+
await import_utils.fs.writeFile(entryFilePath, code);
|
209
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
210
|
+
"@modern-js/prod-server"
|
211
|
+
]);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
};
|
215
|
+
}
|
216
|
+
});
|
@@ -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,26 +15,15 @@ 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
|
39
|
-
var import_dependencies = require("./dependencies");
|
25
|
+
var import_utils = require("./utils");
|
26
|
+
var import_node = require("./platforms/node");
|
40
27
|
var deploy_default = () => ({
|
41
28
|
name: "@modern-js/plugin-deploy",
|
42
29
|
pre: [
|
@@ -48,168 +35,25 @@ var deploy_default = () => ({
|
|
48
35
|
return {
|
49
36
|
async beforeDeploy() {
|
50
37
|
const appContext = api.useAppContext();
|
38
|
+
const { appDirectory, distDirectory } = appContext;
|
51
39
|
const modernConfig = api.useResolvedConfigContext();
|
52
|
-
const {
|
53
|
-
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
54
|
-
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
40
|
+
const { useSSR, useAPI, useWebServer } = (0, import_utils.getProjectUsage)(appDirectory, distDirectory);
|
55
41
|
const needModernServer = useSSR || useAPI || useWebServer;
|
56
|
-
let
|
57
|
-
let funcsDirectory = outputDirectory;
|
58
|
-
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
59
|
-
if (deployTarget === "node") {
|
60
|
-
await import_utils.fs.remove(outputDirectory);
|
61
|
-
await import_utils.fs.copy(distDirectory, outputDirectory);
|
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
|
-
}
|
100
|
-
if (deployTarget === "vercel") {
|
101
|
-
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
102
|
-
await import_utils.fs.remove(vercelOutput);
|
103
|
-
outputDirectory = import_path.default.join(vercelOutput, "output");
|
104
|
-
const config = {
|
105
|
-
version: 3,
|
106
|
-
routes: [
|
107
|
-
{
|
108
|
-
src: "/static/(.*)",
|
109
|
-
headers: {
|
110
|
-
"cache-control": "s-maxage=31536000, immutable"
|
111
|
-
},
|
112
|
-
continue: true
|
113
|
-
},
|
114
|
-
{
|
115
|
-
handle: "filesystem"
|
116
|
-
}
|
117
|
-
]
|
118
|
-
};
|
119
|
-
if (!needModernServer) {
|
120
|
-
entrypoints.forEach((entry) => {
|
121
|
-
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
122
|
-
config.routes.push({
|
123
|
-
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
124
|
-
headers: {
|
125
|
-
"cache-control": "s-maxage=0"
|
126
|
-
},
|
127
|
-
dest: `/html/${entry.entryName}/index.html`
|
128
|
-
});
|
129
|
-
});
|
130
|
-
} else {
|
131
|
-
config.routes.push({
|
132
|
-
src: "/(.*)",
|
133
|
-
dest: `/index`
|
134
|
-
});
|
135
|
-
}
|
136
|
-
await import_utils.fs.ensureDir(outputDirectory);
|
137
|
-
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config, {
|
138
|
-
spaces: 2
|
139
|
-
});
|
140
|
-
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
141
|
-
await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
|
142
|
-
if (!needModernServer) {
|
143
|
-
const destHtmlDirectory = import_path.default.join(distDirectory, "html");
|
144
|
-
const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
|
145
|
-
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
146
|
-
} else {
|
147
|
-
funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
|
148
|
-
await import_utils.fs.ensureDir(funcsDirectory);
|
149
|
-
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
150
|
-
filter: (src) => {
|
151
|
-
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
152
|
-
return !src.includes(distStaticDirectory);
|
153
|
-
}
|
154
|
-
});
|
155
|
-
await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
|
156
|
-
runtime: "nodejs16.x",
|
157
|
-
handler: "index.js",
|
158
|
-
launcherType: "Nodejs",
|
159
|
-
shouldAddHelpers: false,
|
160
|
-
supportsResponseStreaming: true
|
161
|
-
});
|
162
|
-
}
|
163
|
-
}
|
164
|
-
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
165
|
-
const serverAppContext = {
|
166
|
-
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
167
|
-
apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
|
168
|
-
lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
|
169
|
-
metaName
|
170
|
-
};
|
171
|
-
console.log("serverAppContext", serverAppContext);
|
172
|
-
let code = ``;
|
173
|
-
console.log("deployTarget111111111", deployTarget);
|
42
|
+
let deployPreset;
|
174
43
|
switch (deployTarget) {
|
175
|
-
case "node":
|
176
|
-
|
177
|
-
code = await genNodeEntry({
|
178
|
-
plugins,
|
179
|
-
config: modernConfig,
|
180
|
-
appContext: serverAppContext
|
181
|
-
});
|
44
|
+
case "node":
|
45
|
+
deployPreset = (0, import_node.createNodePreset)(appContext, modernConfig, needModernServer);
|
182
46
|
break;
|
183
|
-
|
184
|
-
|
185
|
-
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
|
186
|
-
code = await genVercelEntry({
|
187
|
-
plugins,
|
188
|
-
config: modernConfig,
|
189
|
-
appContext: serverAppContext
|
190
|
-
});
|
191
|
-
break;
|
192
|
-
}
|
193
|
-
case "netlify": {
|
194
|
-
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
|
195
|
-
code = await genNetlifyEntry({
|
196
|
-
plugins,
|
197
|
-
config: modernConfig,
|
198
|
-
appContext: serverAppContext
|
199
|
-
});
|
47
|
+
case "vercel":
|
48
|
+
deployPreset = (0, import_node.createNodePreset)(appContext, modernConfig, needModernServer);
|
200
49
|
break;
|
201
|
-
}
|
202
50
|
default: {
|
203
|
-
|
51
|
+
throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");
|
204
52
|
}
|
205
53
|
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
210
|
-
"@modern-js/prod-server"
|
211
|
-
]);
|
212
|
-
}
|
54
|
+
await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
55
|
+
await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
56
|
+
await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
213
57
|
}
|
214
58
|
};
|
215
59
|
}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
8
|
var __export = (target, all) => {
|
7
9
|
for (var name in all)
|
@@ -15,81 +17,127 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
}
|
16
18
|
return to;
|
17
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
|
+
));
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
29
|
var netlify_exports = {};
|
20
30
|
__export(netlify_exports, {
|
21
|
-
|
31
|
+
createNetlifyPreset: () => createNetlifyPreset
|
22
32
|
});
|
23
33
|
module.exports = __toCommonJS(netlify_exports);
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
24
35
|
var import_utils = require("@modern-js/utils");
|
36
|
+
var import_routes = require("../../../utils/routes");
|
25
37
|
var import_utils2 = require("../utils");
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
38
|
+
var import_dependencies = require("../dependencies");
|
39
|
+
const createNetlifyPreset = (appContext, config, needModernServer) => {
|
40
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
41
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
42
|
+
const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
|
43
|
+
const outputDirectory = import_node_path.default.join(netlifyOutput, "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(netlifyOutput);
|
30
49
|
},
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
async writeOutput() {
|
51
|
+
const config2 = {
|
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 } } = config2;
|
68
|
+
entrypoints.forEach((entry) => {
|
69
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
70
|
+
config2.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
|
+
config2.routes.push({
|
80
|
+
src: "/(.*)",
|
81
|
+
dest: `/index`
|
82
|
+
});
|
59
83
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
84
|
+
await import_utils.fs.ensureDir(outputDirectory);
|
85
|
+
await import_utils.fs.writeJSON(import_node_path.default.join(outputDirectory, "config.json"), config2, {
|
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
|
+
});
|
69
109
|
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
110
|
+
},
|
111
|
+
async genEntry() {
|
112
|
+
var _config_bff;
|
113
|
+
if (!needModernServer) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
const serverConfig = {
|
117
|
+
bff: {
|
118
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_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
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlifyEntry.js"))).toString();
|
131
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
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
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
135
|
+
"@modern-js/prod-server"
|
136
|
+
]);
|
85
137
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
export default handleRequest;
|
90
|
-
`;
|
91
|
-
}
|
138
|
+
};
|
139
|
+
};
|
92
140
|
// Annotate the CommonJS export names for ESM import in node:
|
93
141
|
0 && (module.exports = {
|
94
|
-
|
142
|
+
createNetlifyPreset
|
95
143
|
});
|