@modern-js/app-tools 2.49.3-alpha.14 → 2.49.3-alpha.16
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 -11
- package/dist/cjs/plugins/deploy/index copy.js +216 -0
- package/dist/cjs/plugins/deploy/index.js +17 -168
- 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 +43 -21
- package/dist/cjs/plugins/deploy/platforms/vercel.js +102 -19
- package/dist/cjs/plugins/deploy/utils.js +22 -8
- package/dist/esm/plugins/deploy/dependencies.js +1 -46
- package/dist/esm/plugins/deploy/index copy.js +367 -0
- package/dist/esm/plugins/deploy/index.js +21 -313
- 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 +105 -46
- package/dist/esm/plugins/deploy/platforms/vercel.js +203 -43
- package/dist/esm/plugins/deploy/utils.js +55 -3
- package/dist/esm-node/plugins/deploy/dependencies.js +1 -11
- package/dist/esm-node/plugins/deploy/index copy.js +186 -0
- package/dist/esm-node/plugins/deploy/index.js +15 -156
- 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 +44 -22
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +103 -20
- package/dist/esm-node/plugins/deploy/utils.js +20 -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 +8 -1
- package/package.json +8 -8
@@ -0,0 +1,367 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import path from "path";
|
4
|
+
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
5
|
+
import { provider } from "std-env";
|
6
|
+
import { isMainEntry } from "../../utils/routes";
|
7
|
+
import { getProjectUsage } from "./utils";
|
8
|
+
import { handleDependencies } from "./dependencies";
|
9
|
+
function index_copy_default() {
|
10
|
+
return {
|
11
|
+
name: "@modern-js/plugin-deploy",
|
12
|
+
pre: [
|
13
|
+
"@modern-js/plugin-bff",
|
14
|
+
"@modern-js/plugin-server"
|
15
|
+
],
|
16
|
+
setup: function(api) {
|
17
|
+
var deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
18
|
+
return {
|
19
|
+
beforeDeploy: function beforeDeploy() {
|
20
|
+
return _async_to_generator(function() {
|
21
|
+
var appContext, modernConfig, mainEntryName, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, outputDirectory, funcsDirectory, staticDirectory, netlifyOutput, routes, redirectContent, redirectFilePath, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
|
22
|
+
return _ts_generator(this, function(_state) {
|
23
|
+
switch (_state.label) {
|
24
|
+
case 0:
|
25
|
+
appContext = api.useAppContext();
|
26
|
+
modernConfig = api.useResolvedConfigContext();
|
27
|
+
mainEntryName = modernConfig.source.mainEntryName;
|
28
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
|
29
|
+
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
30
|
+
needModernServer = useSSR || useAPI || useWebServer;
|
31
|
+
outputDirectory = path.join(appDirectory, ".output");
|
32
|
+
funcsDirectory = outputDirectory;
|
33
|
+
staticDirectory = path.join(outputDirectory, "static");
|
34
|
+
if (!(deployTarget === "node"))
|
35
|
+
return [
|
36
|
+
3,
|
37
|
+
3
|
38
|
+
];
|
39
|
+
return [
|
40
|
+
4,
|
41
|
+
fse.remove(outputDirectory)
|
42
|
+
];
|
43
|
+
case 1:
|
44
|
+
_state.sent();
|
45
|
+
return [
|
46
|
+
4,
|
47
|
+
fse.copy(distDirectory, outputDirectory)
|
48
|
+
];
|
49
|
+
case 2:
|
50
|
+
_state.sent();
|
51
|
+
_state.label = 3;
|
52
|
+
case 3:
|
53
|
+
if (!(deployTarget === "netlify"))
|
54
|
+
return [
|
55
|
+
3,
|
56
|
+
8
|
57
|
+
];
|
58
|
+
netlifyOutput = path.join(appDirectory, ".netlify");
|
59
|
+
funcsDirectory = path.join(netlifyOutput, "functions");
|
60
|
+
routes = [];
|
61
|
+
if (!needModernServer) {
|
62
|
+
entrypoints.forEach(function(entry) {
|
63
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
64
|
+
routes.push({
|
65
|
+
src: "/".concat(isMain ? "" : "".concat(entry.entryName, "/"), "*"),
|
66
|
+
dest: "/html/".concat(entry.entryName, "/index.html"),
|
67
|
+
status: 200
|
68
|
+
});
|
69
|
+
});
|
70
|
+
} else {
|
71
|
+
routes.push({
|
72
|
+
src: "/*",
|
73
|
+
dest: "/.netlify/functions/index",
|
74
|
+
status: 200
|
75
|
+
});
|
76
|
+
throw new Error("Currently on the Netlify platform, only CSR projects are supported, Support for SSR and BFF projects will be available later");
|
77
|
+
}
|
78
|
+
console.log("routes", routes, needModernServer);
|
79
|
+
redirectContent = routes.map(function(route) {
|
80
|
+
return "".concat(route.src, " ").concat(route.dest, " ").concat(route.status);
|
81
|
+
}).join("\n");
|
82
|
+
console.log("redirectContent", redirectContent);
|
83
|
+
return [
|
84
|
+
4,
|
85
|
+
fse.remove(outputDirectory)
|
86
|
+
];
|
87
|
+
case 4:
|
88
|
+
_state.sent();
|
89
|
+
return [
|
90
|
+
4,
|
91
|
+
fse.ensureDir(funcsDirectory)
|
92
|
+
];
|
93
|
+
case 5:
|
94
|
+
_state.sent();
|
95
|
+
return [
|
96
|
+
4,
|
97
|
+
fse.copy(distDirectory, funcsDirectory, {
|
98
|
+
filter: function(src) {
|
99
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
100
|
+
return !src.includes(distStaticDirectory);
|
101
|
+
}
|
102
|
+
})
|
103
|
+
];
|
104
|
+
case 6:
|
105
|
+
_state.sent();
|
106
|
+
redirectFilePath = path.join(distDirectory, "_redirects");
|
107
|
+
return [
|
108
|
+
4,
|
109
|
+
fse.writeFile(redirectFilePath, redirectContent)
|
110
|
+
];
|
111
|
+
case 7:
|
112
|
+
_state.sent();
|
113
|
+
_state.label = 8;
|
114
|
+
case 8:
|
115
|
+
if (!(deployTarget === "vercel"))
|
116
|
+
return [
|
117
|
+
3,
|
118
|
+
18
|
119
|
+
];
|
120
|
+
vercelOutput = path.join(appDirectory, ".vercel");
|
121
|
+
return [
|
122
|
+
4,
|
123
|
+
fse.remove(vercelOutput)
|
124
|
+
];
|
125
|
+
case 9:
|
126
|
+
_state.sent();
|
127
|
+
outputDirectory = path.join(vercelOutput, "output");
|
128
|
+
config = {
|
129
|
+
version: 3,
|
130
|
+
routes: [
|
131
|
+
{
|
132
|
+
src: "/static/(.*)",
|
133
|
+
headers: {
|
134
|
+
"cache-control": "s-maxage=31536000, immutable"
|
135
|
+
},
|
136
|
+
continue: true
|
137
|
+
},
|
138
|
+
{
|
139
|
+
handle: "filesystem"
|
140
|
+
}
|
141
|
+
]
|
142
|
+
};
|
143
|
+
if (!needModernServer) {
|
144
|
+
entrypoints.forEach(function(entry) {
|
145
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
146
|
+
config.routes.push({
|
147
|
+
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
148
|
+
headers: {
|
149
|
+
"cache-control": "s-maxage=0"
|
150
|
+
},
|
151
|
+
dest: "/html/".concat(entry.entryName, "/index.html")
|
152
|
+
});
|
153
|
+
});
|
154
|
+
} else {
|
155
|
+
config.routes.push({
|
156
|
+
src: "/(.*)",
|
157
|
+
dest: "/index"
|
158
|
+
});
|
159
|
+
}
|
160
|
+
return [
|
161
|
+
4,
|
162
|
+
fse.ensureDir(outputDirectory)
|
163
|
+
];
|
164
|
+
case 10:
|
165
|
+
_state.sent();
|
166
|
+
return [
|
167
|
+
4,
|
168
|
+
fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
169
|
+
spaces: 2
|
170
|
+
})
|
171
|
+
];
|
172
|
+
case 11:
|
173
|
+
_state.sent();
|
174
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
175
|
+
return [
|
176
|
+
4,
|
177
|
+
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
178
|
+
];
|
179
|
+
case 12:
|
180
|
+
_state.sent();
|
181
|
+
if (!!needModernServer)
|
182
|
+
return [
|
183
|
+
3,
|
184
|
+
14
|
185
|
+
];
|
186
|
+
destHtmlDirectory = path.join(distDirectory, "html");
|
187
|
+
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
188
|
+
return [
|
189
|
+
4,
|
190
|
+
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
191
|
+
];
|
192
|
+
case 13:
|
193
|
+
_state.sent();
|
194
|
+
return [
|
195
|
+
3,
|
196
|
+
18
|
197
|
+
];
|
198
|
+
case 14:
|
199
|
+
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
200
|
+
return [
|
201
|
+
4,
|
202
|
+
fse.ensureDir(funcsDirectory)
|
203
|
+
];
|
204
|
+
case 15:
|
205
|
+
_state.sent();
|
206
|
+
return [
|
207
|
+
4,
|
208
|
+
fse.copy(distDirectory, funcsDirectory, {
|
209
|
+
filter: function(src) {
|
210
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
211
|
+
return !src.includes(distStaticDirectory);
|
212
|
+
}
|
213
|
+
})
|
214
|
+
];
|
215
|
+
case 16:
|
216
|
+
_state.sent();
|
217
|
+
return [
|
218
|
+
4,
|
219
|
+
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
220
|
+
runtime: "nodejs16.x",
|
221
|
+
handler: "index.js",
|
222
|
+
launcherType: "Nodejs",
|
223
|
+
shouldAddHelpers: false,
|
224
|
+
supportsResponseStreaming: true
|
225
|
+
})
|
226
|
+
];
|
227
|
+
case 17:
|
228
|
+
_state.sent();
|
229
|
+
_state.label = 18;
|
230
|
+
case 18:
|
231
|
+
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
232
|
+
serverAppContext = {
|
233
|
+
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
234
|
+
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
235
|
+
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
236
|
+
metaName
|
237
|
+
};
|
238
|
+
console.log("serverAppContext", serverAppContext);
|
239
|
+
code = "";
|
240
|
+
console.log("deployTarget111111111", deployTarget);
|
241
|
+
switch (deployTarget) {
|
242
|
+
case "node":
|
243
|
+
return [
|
244
|
+
3,
|
245
|
+
19
|
246
|
+
];
|
247
|
+
case "vercel":
|
248
|
+
return [
|
249
|
+
3,
|
250
|
+
22
|
251
|
+
];
|
252
|
+
case "netlify":
|
253
|
+
return [
|
254
|
+
3,
|
255
|
+
25
|
256
|
+
];
|
257
|
+
}
|
258
|
+
return [
|
259
|
+
3,
|
260
|
+
28
|
261
|
+
];
|
262
|
+
case 19:
|
263
|
+
return [
|
264
|
+
4,
|
265
|
+
import("./platforms/node")
|
266
|
+
];
|
267
|
+
case 20:
|
268
|
+
genNodeEntry = _state.sent().genNodeEntry;
|
269
|
+
return [
|
270
|
+
4,
|
271
|
+
genNodeEntry({
|
272
|
+
plugins,
|
273
|
+
config: modernConfig,
|
274
|
+
appContext: serverAppContext
|
275
|
+
})
|
276
|
+
];
|
277
|
+
case 21:
|
278
|
+
code = _state.sent();
|
279
|
+
return [
|
280
|
+
3,
|
281
|
+
29
|
282
|
+
];
|
283
|
+
case 22:
|
284
|
+
return [
|
285
|
+
4,
|
286
|
+
import("./platforms/vercel")
|
287
|
+
];
|
288
|
+
case 23:
|
289
|
+
genVercelEntry = _state.sent().genVercelEntry;
|
290
|
+
return [
|
291
|
+
4,
|
292
|
+
genVercelEntry({
|
293
|
+
plugins,
|
294
|
+
config: modernConfig,
|
295
|
+
appContext: serverAppContext
|
296
|
+
})
|
297
|
+
];
|
298
|
+
case 24:
|
299
|
+
code = _state.sent();
|
300
|
+
return [
|
301
|
+
3,
|
302
|
+
29
|
303
|
+
];
|
304
|
+
case 25:
|
305
|
+
return [
|
306
|
+
4,
|
307
|
+
import("./platforms/netlify")
|
308
|
+
];
|
309
|
+
case 26:
|
310
|
+
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
311
|
+
return [
|
312
|
+
4,
|
313
|
+
genNetlifyEntry({
|
314
|
+
plugins,
|
315
|
+
config: modernConfig,
|
316
|
+
appContext: serverAppContext
|
317
|
+
})
|
318
|
+
];
|
319
|
+
case 27:
|
320
|
+
code = _state.sent();
|
321
|
+
return [
|
322
|
+
3,
|
323
|
+
29
|
324
|
+
];
|
325
|
+
case 28:
|
326
|
+
{
|
327
|
+
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
328
|
+
}
|
329
|
+
_state.label = 29;
|
330
|
+
case 29:
|
331
|
+
entryFilePath = path.join(funcsDirectory, "index.js");
|
332
|
+
if (!needModernServer)
|
333
|
+
return [
|
334
|
+
3,
|
335
|
+
32
|
336
|
+
];
|
337
|
+
return [
|
338
|
+
4,
|
339
|
+
fse.writeFile(entryFilePath, code)
|
340
|
+
];
|
341
|
+
case 30:
|
342
|
+
_state.sent();
|
343
|
+
return [
|
344
|
+
4,
|
345
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
346
|
+
"@modern-js/prod-server"
|
347
|
+
])
|
348
|
+
];
|
349
|
+
case 31:
|
350
|
+
_state.sent();
|
351
|
+
_state.label = 32;
|
352
|
+
case 32:
|
353
|
+
return [
|
354
|
+
2
|
355
|
+
];
|
356
|
+
}
|
357
|
+
});
|
358
|
+
})();
|
359
|
+
}
|
360
|
+
};
|
361
|
+
}
|
362
|
+
};
|
363
|
+
}
|
364
|
+
;
|
365
|
+
export {
|
366
|
+
index_copy_default as default
|
367
|
+
};
|