@modern-js/app-tools 2.49.3-alpha.15 → 2.49.3-alpha.17
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/dependencies.js +1 -12
- package/dist/cjs/plugins/deploy/index.js +22 -18
- package/dist/cjs/plugins/deploy/platforms/netlify.js +23 -50
- package/dist/cjs/plugins/deploy/platforms/node.js +10 -2
- package/dist/cjs/plugins/deploy/platforms/vercel.js +9 -9
- package/dist/cjs/plugins/deploy/utils.js +12 -0
- package/dist/esm/plugins/deploy/dependencies.js +1 -47
- package/dist/esm/plugins/deploy/index.js +84 -21
- package/dist/esm/plugins/deploy/platforms/netlify.js +31 -77
- package/dist/esm/plugins/deploy/platforms/node.js +20 -3
- package/dist/esm/plugins/deploy/platforms/vercel.js +10 -10
- package/dist/esm/plugins/deploy/utils.js +46 -0
- package/dist/esm-node/plugins/deploy/dependencies.js +1 -12
- package/dist/esm-node/plugins/deploy/index.js +22 -18
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +23 -50
- package/dist/esm-node/plugins/deploy/platforms/node.js +11 -3
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +9 -9
- package/dist/esm-node/plugins/deploy/utils.js +11 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +4 -3
- package/dist/types/plugins/deploy/utils.d.ts +1 -0
- package/package.json +7 -7
- package/dist/cjs/plugins/deploy/index copy.js +0 -216
- package/dist/esm/plugins/deploy/index copy.js +0 -367
- package/dist/esm-node/plugins/deploy/index copy.js +0 -186
- package/dist/types/plugins/deploy/index copy.d.ts +0 -4
@@ -1,186 +0,0 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
3
|
-
import { provider } from "std-env";
|
4
|
-
import { isMainEntry } from "../../utils/routes";
|
5
|
-
import { getProjectUsage } from "./utils";
|
6
|
-
import { handleDependencies } from "./dependencies";
|
7
|
-
var index_copy_default = () => ({
|
8
|
-
name: "@modern-js/plugin-deploy",
|
9
|
-
pre: [
|
10
|
-
"@modern-js/plugin-bff",
|
11
|
-
"@modern-js/plugin-server"
|
12
|
-
],
|
13
|
-
setup: (api) => {
|
14
|
-
const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
15
|
-
return {
|
16
|
-
async beforeDeploy() {
|
17
|
-
const appContext = api.useAppContext();
|
18
|
-
const modernConfig = api.useResolvedConfigContext();
|
19
|
-
const { source: { mainEntryName } } = modernConfig;
|
20
|
-
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
21
|
-
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
22
|
-
const needModernServer = useSSR || useAPI || useWebServer;
|
23
|
-
let outputDirectory = path.join(appDirectory, ".output");
|
24
|
-
let funcsDirectory = outputDirectory;
|
25
|
-
let staticDirectory = path.join(outputDirectory, "static");
|
26
|
-
if (deployTarget === "node") {
|
27
|
-
await fse.remove(outputDirectory);
|
28
|
-
await fse.copy(distDirectory, outputDirectory);
|
29
|
-
}
|
30
|
-
if (deployTarget === "netlify") {
|
31
|
-
const netlifyOutput = path.join(appDirectory, ".netlify");
|
32
|
-
funcsDirectory = path.join(netlifyOutput, "functions");
|
33
|
-
const routes = [];
|
34
|
-
if (!needModernServer) {
|
35
|
-
entrypoints.forEach((entry) => {
|
36
|
-
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
37
|
-
routes.push({
|
38
|
-
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
39
|
-
dest: `/html/${entry.entryName}/index.html`,
|
40
|
-
status: 200
|
41
|
-
});
|
42
|
-
});
|
43
|
-
} else {
|
44
|
-
routes.push({
|
45
|
-
src: `/*`,
|
46
|
-
dest: `/.netlify/functions/index`,
|
47
|
-
status: 200
|
48
|
-
});
|
49
|
-
throw new Error("Currently on the Netlify platform, only CSR projects are supported, Support for SSR and BFF projects will be available later");
|
50
|
-
}
|
51
|
-
console.log("routes", routes, needModernServer);
|
52
|
-
const redirectContent = routes.map((route) => {
|
53
|
-
return `${route.src} ${route.dest} ${route.status}`;
|
54
|
-
}).join("\n");
|
55
|
-
console.log("redirectContent", redirectContent);
|
56
|
-
await fse.remove(outputDirectory);
|
57
|
-
await fse.ensureDir(funcsDirectory);
|
58
|
-
await fse.copy(distDirectory, funcsDirectory, {
|
59
|
-
filter: (src) => {
|
60
|
-
const distStaticDirectory = path.join(distDirectory, "static");
|
61
|
-
return !src.includes(distStaticDirectory);
|
62
|
-
}
|
63
|
-
});
|
64
|
-
const redirectFilePath = path.join(distDirectory, "_redirects");
|
65
|
-
await fse.writeFile(redirectFilePath, redirectContent);
|
66
|
-
}
|
67
|
-
if (deployTarget === "vercel") {
|
68
|
-
const vercelOutput = path.join(appDirectory, ".vercel");
|
69
|
-
await fse.remove(vercelOutput);
|
70
|
-
outputDirectory = path.join(vercelOutput, "output");
|
71
|
-
const config = {
|
72
|
-
version: 3,
|
73
|
-
routes: [
|
74
|
-
{
|
75
|
-
src: "/static/(.*)",
|
76
|
-
headers: {
|
77
|
-
"cache-control": "s-maxage=31536000, immutable"
|
78
|
-
},
|
79
|
-
continue: true
|
80
|
-
},
|
81
|
-
{
|
82
|
-
handle: "filesystem"
|
83
|
-
}
|
84
|
-
]
|
85
|
-
};
|
86
|
-
if (!needModernServer) {
|
87
|
-
entrypoints.forEach((entry) => {
|
88
|
-
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
89
|
-
config.routes.push({
|
90
|
-
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
91
|
-
headers: {
|
92
|
-
"cache-control": "s-maxage=0"
|
93
|
-
},
|
94
|
-
dest: `/html/${entry.entryName}/index.html`
|
95
|
-
});
|
96
|
-
});
|
97
|
-
} else {
|
98
|
-
config.routes.push({
|
99
|
-
src: "/(.*)",
|
100
|
-
dest: `/index`
|
101
|
-
});
|
102
|
-
}
|
103
|
-
await fse.ensureDir(outputDirectory);
|
104
|
-
await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
105
|
-
spaces: 2
|
106
|
-
});
|
107
|
-
staticDirectory = path.join(outputDirectory, "static/static");
|
108
|
-
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
109
|
-
if (!needModernServer) {
|
110
|
-
const destHtmlDirectory = path.join(distDirectory, "html");
|
111
|
-
const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
112
|
-
await fse.copy(destHtmlDirectory, outputHtmlDirectory);
|
113
|
-
} else {
|
114
|
-
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
115
|
-
await fse.ensureDir(funcsDirectory);
|
116
|
-
await fse.copy(distDirectory, funcsDirectory, {
|
117
|
-
filter: (src) => {
|
118
|
-
const distStaticDirectory = path.join(distDirectory, "static");
|
119
|
-
return !src.includes(distStaticDirectory);
|
120
|
-
}
|
121
|
-
});
|
122
|
-
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
123
|
-
runtime: "nodejs16.x",
|
124
|
-
handler: "index.js",
|
125
|
-
launcherType: "Nodejs",
|
126
|
-
shouldAddHelpers: false,
|
127
|
-
supportsResponseStreaming: true
|
128
|
-
});
|
129
|
-
}
|
130
|
-
}
|
131
|
-
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
132
|
-
const serverAppContext = {
|
133
|
-
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
134
|
-
apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
|
135
|
-
lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
|
136
|
-
metaName
|
137
|
-
};
|
138
|
-
console.log("serverAppContext", serverAppContext);
|
139
|
-
let code = ``;
|
140
|
-
console.log("deployTarget111111111", deployTarget);
|
141
|
-
switch (deployTarget) {
|
142
|
-
case "node": {
|
143
|
-
const { genNodeEntry } = await import("./platforms/node");
|
144
|
-
code = await genNodeEntry({
|
145
|
-
plugins,
|
146
|
-
config: modernConfig,
|
147
|
-
appContext: serverAppContext
|
148
|
-
});
|
149
|
-
break;
|
150
|
-
}
|
151
|
-
case "vercel": {
|
152
|
-
const { genVercelEntry } = await import("./platforms/vercel");
|
153
|
-
code = await genVercelEntry({
|
154
|
-
plugins,
|
155
|
-
config: modernConfig,
|
156
|
-
appContext: serverAppContext
|
157
|
-
});
|
158
|
-
break;
|
159
|
-
}
|
160
|
-
case "netlify": {
|
161
|
-
const { genNetlifyEntry } = await import("./platforms/netlify");
|
162
|
-
code = await genNetlifyEntry({
|
163
|
-
plugins,
|
164
|
-
config: modernConfig,
|
165
|
-
appContext: serverAppContext
|
166
|
-
});
|
167
|
-
break;
|
168
|
-
}
|
169
|
-
default: {
|
170
|
-
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
171
|
-
}
|
172
|
-
}
|
173
|
-
const entryFilePath = path.join(funcsDirectory, "index.js");
|
174
|
-
if (needModernServer) {
|
175
|
-
await fse.writeFile(entryFilePath, code);
|
176
|
-
await handleDependencies(appDirectory, funcsDirectory, [
|
177
|
-
"@modern-js/prod-server"
|
178
|
-
]);
|
179
|
-
}
|
180
|
-
}
|
181
|
-
};
|
182
|
-
}
|
183
|
-
});
|
184
|
-
export {
|
185
|
-
index_copy_default as default
|
186
|
-
};
|