@modern-js/app-tools 2.49.1-alpha.6 → 2.49.1-alpha.8
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/plugins/deploy/dependencies.js +10 -11
- package/dist/cjs/plugins/deploy/entrys/vercel.js +3 -1
- package/dist/cjs/plugins/deploy/index.js +30 -30
- package/dist/esm/plugins/deploy/dependencies.js +12 -13
- package/dist/esm/plugins/deploy/entrys/vercel.js +1 -1
- package/dist/esm/plugins/deploy/index.js +59 -51
- package/dist/esm-node/plugins/deploy/dependencies.js +11 -12
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +3 -1
- package/dist/esm-node/plugins/deploy/index.js +30 -30
- package/package.json +10 -10
|
@@ -214,18 +214,17 @@ const handleDependencies = async (appDir, serverRootDir, include) => {
|
|
|
214
214
|
}));
|
|
215
215
|
console.log("multiVersionPkgs111111111", multiVersionPkgs);
|
|
216
216
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
|
217
|
-
const versionEntires = Object.entries(pkgVersions).sort(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
([v1, p1], [v2, p2]) => {
|
|
221
|
-
if (p1.length === 0) {
|
|
222
|
-
return -1;
|
|
223
|
-
}
|
|
224
|
-
if (p2.length === 0) {
|
|
225
|
-
return 1;
|
|
226
|
-
}
|
|
217
|
+
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
|
218
|
+
if (p1.length === 0) {
|
|
219
|
+
return -1;
|
|
227
220
|
}
|
|
228
|
-
|
|
221
|
+
if (p2.length === 0) {
|
|
222
|
+
return 1;
|
|
223
|
+
}
|
|
224
|
+
return import_utils.semver.lt(v1, v2, {
|
|
225
|
+
loose: true
|
|
226
|
+
}) ? 1 : -1;
|
|
227
|
+
});
|
|
229
228
|
for (const [version, parentPkgs] of versionEntires) {
|
|
230
229
|
const pkg = tracedPackages[pkgName];
|
|
231
230
|
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
|
@@ -67,7 +67,9 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
67
67
|
disableCustomHook: true
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
const app = await createProdServer(prodServerOptions)
|
|
71
|
+
|
|
72
|
+
requestHandler = app.getRequestListener();
|
|
71
73
|
|
|
72
74
|
return requestHandler;
|
|
73
75
|
} catch(error) {
|
|
@@ -42,48 +42,49 @@ var deploy_default = () => ({
|
|
|
42
42
|
"@modern-js/plugin-server"
|
|
43
43
|
],
|
|
44
44
|
setup: (api) => {
|
|
45
|
+
const deployTarget = process.env.MODERNJS_DEPLOY || "node";
|
|
45
46
|
return {
|
|
46
47
|
async beforeDeploy() {
|
|
47
|
-
const deployTarget = process.env.MODERNJS_DEPLOY || "node";
|
|
48
48
|
const appContext = api.useAppContext();
|
|
49
49
|
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
|
|
50
|
+
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
|
51
|
+
const needModernServer = useSSR || useAPI || useWebServer;
|
|
50
52
|
const configContext = api.useResolvedConfigContext();
|
|
51
53
|
let outputDirectory = import_path.default.join(appDirectory, ".output");
|
|
52
54
|
let funcsDirectory = outputDirectory;
|
|
53
55
|
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
|
54
|
-
await import_utils.fs.remove(outputDirectory);
|
|
55
56
|
if (deployTarget === "node") {
|
|
56
|
-
await import_utils.fs.
|
|
57
|
-
|
|
58
|
-
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
|
59
|
-
return !src.includes(distStaticDirectory);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
57
|
+
await import_utils.fs.remove(outputDirectory);
|
|
58
|
+
await import_utils.fs.copy(distDirectory, outputDirectory);
|
|
62
59
|
}
|
|
63
60
|
if (deployTarget === "vercel") {
|
|
64
|
-
|
|
61
|
+
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
|
62
|
+
await import_utils.fs.remove(vercelOutput);
|
|
63
|
+
outputDirectory = import_path.default.join(vercelOutput, "output");
|
|
65
64
|
const config2 = {
|
|
66
65
|
version: 3
|
|
67
66
|
};
|
|
68
67
|
await import_utils.fs.ensureDir(outputDirectory);
|
|
69
68
|
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config2);
|
|
70
|
-
|
|
71
|
-
staticDirectory = import_path.default.join(outputDirectory, "static");
|
|
72
|
-
await import_utils.fs.ensureDir(funcsDirectory);
|
|
73
|
-
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
|
74
|
-
filter: (src) => {
|
|
75
|
-
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
|
76
|
-
return !src.includes(distStaticDirectory);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
69
|
+
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
|
79
70
|
await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
if (needModernServer) {
|
|
72
|
+
funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
|
|
73
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
|
74
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
|
75
|
+
filter: (src) => {
|
|
76
|
+
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
|
77
|
+
return !src.includes(distStaticDirectory);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
|
|
81
|
+
runtime: "nodejs16.x",
|
|
82
|
+
handler: "index.js",
|
|
83
|
+
launcherType: "Nodejs",
|
|
84
|
+
shouldAddHelpers: false,
|
|
85
|
+
supportsResponseStreaming: true
|
|
86
|
+
});
|
|
87
|
+
}
|
|
87
88
|
}
|
|
88
89
|
const { bff } = configContext;
|
|
89
90
|
const config = {
|
|
@@ -133,14 +134,13 @@ var deploy_default = () => ({
|
|
|
133
134
|
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
|
137
137
|
const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
|
|
138
|
-
if (
|
|
138
|
+
if (needModernServer) {
|
|
139
139
|
await import_utils.fs.writeFile(entryFilePath, code);
|
|
140
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
|
141
|
+
"@modern-js/prod-server"
|
|
142
|
+
]);
|
|
140
143
|
}
|
|
141
|
-
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
|
142
|
-
"@modern-js/prod-server"
|
|
143
|
-
]);
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
}
|
|
@@ -5,7 +5,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
5
5
|
import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
|
|
6
6
|
import path, { isAbsolute } from "node:path";
|
|
7
7
|
import { nodeFileTrace, resolve } from "@vercel/nft";
|
|
8
|
-
import { fs as fse, pkgUp } from "@modern-js/utils";
|
|
8
|
+
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
|
9
9
|
import { readPackageJSON } from "pkg-types";
|
|
10
10
|
import { parseNodeModulePath } from "mlly";
|
|
11
11
|
import { linkPackage, writePackage } from "./utils";
|
|
@@ -493,19 +493,18 @@ var handleDependencies = function() {
|
|
|
493
493
|
switch (_state2.label) {
|
|
494
494
|
case 0:
|
|
495
495
|
_step_value = _sliced_to_array(_step3.value, 2), pkgName2 = _step_value[0], pkgVersions = _step_value[1];
|
|
496
|
-
versionEntires = Object.entries(pkgVersions).sort(
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
var _param = _sliced_to_array(param, 2), v1 = _param[0], p1 = _param[1], _param1 = _sliced_to_array(param1, 2), v2 = _param1[0], p2 = _param1[1];
|
|
501
|
-
if (p1.length === 0) {
|
|
502
|
-
return -1;
|
|
503
|
-
}
|
|
504
|
-
if (p2.length === 0) {
|
|
505
|
-
return 1;
|
|
506
|
-
}
|
|
496
|
+
versionEntires = Object.entries(pkgVersions).sort(function(param, param1) {
|
|
497
|
+
var _param = _sliced_to_array(param, 2), v1 = _param[0], p1 = _param[1], _param1 = _sliced_to_array(param1, 2), v2 = _param1[0], p2 = _param1[1];
|
|
498
|
+
if (p1.length === 0) {
|
|
499
|
+
return -1;
|
|
507
500
|
}
|
|
508
|
-
|
|
501
|
+
if (p2.length === 0) {
|
|
502
|
+
return 1;
|
|
503
|
+
}
|
|
504
|
+
return semver.lt(v1, v2, {
|
|
505
|
+
loose: true
|
|
506
|
+
}) ? 1 : -1;
|
|
507
|
+
});
|
|
509
508
|
_iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = void 0;
|
|
510
509
|
_state2.label = 1;
|
|
511
510
|
case 1:
|
|
@@ -33,7 +33,7 @@ function genVercelEntry() {
|
|
|
33
33
|
const prodServerOptions = {
|
|
34
34
|
pwd: __dirname,
|
|
35
35
|
routes,
|
|
36
|
-
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n
|
|
36
|
+
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n const app = await createProdServer(prodServerOptions)\n\n requestHandler = app.getRequestListener();\n\n return requestHandler;\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n module.exports = async(req, res) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(req, res);\n }\n ");
|
|
37
37
|
}
|
|
38
38
|
export {
|
|
39
39
|
genVercelEntry
|
|
@@ -12,39 +12,36 @@ function deploy_default() {
|
|
|
12
12
|
"@modern-js/plugin-server"
|
|
13
13
|
],
|
|
14
14
|
setup: function(api) {
|
|
15
|
+
var deployTarget = process.env.MODERNJS_DEPLOY || "node";
|
|
15
16
|
return {
|
|
16
17
|
beforeDeploy: function beforeDeploy() {
|
|
17
18
|
return _async_to_generator(function() {
|
|
18
|
-
var
|
|
19
|
+
var appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, configContext, outputDirectory, funcsDirectory, staticDirectory, vercelOutput, config, bff, config1, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
|
|
19
20
|
return _ts_generator(this, function(_state) {
|
|
20
21
|
switch (_state.label) {
|
|
21
22
|
case 0:
|
|
22
|
-
deployTarget = process.env.MODERNJS_DEPLOY || "node";
|
|
23
23
|
appContext = api.useAppContext();
|
|
24
24
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName;
|
|
25
|
+
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
|
26
|
+
needModernServer = useSSR || useAPI || useWebServer;
|
|
25
27
|
configContext = api.useResolvedConfigContext();
|
|
26
28
|
outputDirectory = path.join(appDirectory, ".output");
|
|
27
29
|
funcsDirectory = outputDirectory;
|
|
28
30
|
staticDirectory = path.join(outputDirectory, "static");
|
|
31
|
+
if (!(deployTarget === "node"))
|
|
32
|
+
return [
|
|
33
|
+
3,
|
|
34
|
+
3
|
|
35
|
+
];
|
|
29
36
|
return [
|
|
30
37
|
4,
|
|
31
38
|
fse.remove(outputDirectory)
|
|
32
39
|
];
|
|
33
40
|
case 1:
|
|
34
41
|
_state.sent();
|
|
35
|
-
if (!(deployTarget === "node"))
|
|
36
|
-
return [
|
|
37
|
-
3,
|
|
38
|
-
3
|
|
39
|
-
];
|
|
40
42
|
return [
|
|
41
43
|
4,
|
|
42
|
-
fse.copy(distDirectory, outputDirectory
|
|
43
|
-
filter: function(src) {
|
|
44
|
-
var distStaticDirectory = path.join(distDirectory, "static");
|
|
45
|
-
return !src.includes(distStaticDirectory);
|
|
46
|
-
}
|
|
47
|
-
})
|
|
44
|
+
fse.copy(distDirectory, outputDirectory)
|
|
48
45
|
];
|
|
49
46
|
case 2:
|
|
50
47
|
_state.sent();
|
|
@@ -53,9 +50,16 @@ function deploy_default() {
|
|
|
53
50
|
if (!(deployTarget === "vercel"))
|
|
54
51
|
return [
|
|
55
52
|
3,
|
|
56
|
-
|
|
53
|
+
11
|
|
57
54
|
];
|
|
58
|
-
|
|
55
|
+
vercelOutput = path.join(appDirectory, ".vercel");
|
|
56
|
+
return [
|
|
57
|
+
4,
|
|
58
|
+
fse.remove(vercelOutput)
|
|
59
|
+
];
|
|
60
|
+
case 4:
|
|
61
|
+
_state.sent();
|
|
62
|
+
outputDirectory = path.join(vercelOutput, "output");
|
|
59
63
|
config = {
|
|
60
64
|
version: 3
|
|
61
65
|
};
|
|
@@ -63,21 +67,32 @@ function deploy_default() {
|
|
|
63
67
|
4,
|
|
64
68
|
fse.ensureDir(outputDirectory)
|
|
65
69
|
];
|
|
66
|
-
case
|
|
70
|
+
case 5:
|
|
67
71
|
_state.sent();
|
|
68
72
|
return [
|
|
69
73
|
4,
|
|
70
74
|
fse.writeJSON(path.join(outputDirectory, "config.json"), config)
|
|
71
75
|
];
|
|
72
|
-
case
|
|
76
|
+
case 6:
|
|
77
|
+
_state.sent();
|
|
78
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
|
79
|
+
return [
|
|
80
|
+
4,
|
|
81
|
+
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
|
82
|
+
];
|
|
83
|
+
case 7:
|
|
73
84
|
_state.sent();
|
|
85
|
+
if (!needModernServer)
|
|
86
|
+
return [
|
|
87
|
+
3,
|
|
88
|
+
11
|
|
89
|
+
];
|
|
74
90
|
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
|
75
|
-
staticDirectory = path.join(outputDirectory, "static");
|
|
76
91
|
return [
|
|
77
92
|
4,
|
|
78
93
|
fse.ensureDir(funcsDirectory)
|
|
79
94
|
];
|
|
80
|
-
case
|
|
95
|
+
case 8:
|
|
81
96
|
_state.sent();
|
|
82
97
|
return [
|
|
83
98
|
4,
|
|
@@ -88,13 +103,7 @@ function deploy_default() {
|
|
|
88
103
|
}
|
|
89
104
|
})
|
|
90
105
|
];
|
|
91
|
-
case
|
|
92
|
-
_state.sent();
|
|
93
|
-
return [
|
|
94
|
-
4,
|
|
95
|
-
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
|
96
|
-
];
|
|
97
|
-
case 8:
|
|
106
|
+
case 9:
|
|
98
107
|
_state.sent();
|
|
99
108
|
return [
|
|
100
109
|
4,
|
|
@@ -106,10 +115,10 @@ function deploy_default() {
|
|
|
106
115
|
supportsResponseStreaming: true
|
|
107
116
|
})
|
|
108
117
|
];
|
|
109
|
-
case 9:
|
|
110
|
-
_state.sent();
|
|
111
|
-
_state.label = 10;
|
|
112
118
|
case 10:
|
|
119
|
+
_state.sent();
|
|
120
|
+
_state.label = 11;
|
|
121
|
+
case 11:
|
|
113
122
|
bff = configContext.bff;
|
|
114
123
|
config1 = {
|
|
115
124
|
output: {
|
|
@@ -130,29 +139,29 @@ function deploy_default() {
|
|
|
130
139
|
case "node":
|
|
131
140
|
return [
|
|
132
141
|
3,
|
|
133
|
-
|
|
142
|
+
12
|
|
134
143
|
];
|
|
135
144
|
case "vercel":
|
|
136
145
|
return [
|
|
137
146
|
3,
|
|
138
|
-
|
|
147
|
+
14
|
|
139
148
|
];
|
|
140
149
|
case "netlify":
|
|
141
150
|
return [
|
|
142
151
|
3,
|
|
143
|
-
|
|
152
|
+
16
|
|
144
153
|
];
|
|
145
154
|
}
|
|
146
155
|
return [
|
|
147
156
|
3,
|
|
148
|
-
|
|
157
|
+
18
|
|
149
158
|
];
|
|
150
|
-
case
|
|
159
|
+
case 12:
|
|
151
160
|
return [
|
|
152
161
|
4,
|
|
153
162
|
import("./entrys/node")
|
|
154
163
|
];
|
|
155
|
-
case
|
|
164
|
+
case 13:
|
|
156
165
|
genNodeEntry = _state.sent().genNodeEntry;
|
|
157
166
|
code = genNodeEntry({
|
|
158
167
|
plugins,
|
|
@@ -161,14 +170,14 @@ function deploy_default() {
|
|
|
161
170
|
});
|
|
162
171
|
return [
|
|
163
172
|
3,
|
|
164
|
-
|
|
173
|
+
19
|
|
165
174
|
];
|
|
166
|
-
case
|
|
175
|
+
case 14:
|
|
167
176
|
return [
|
|
168
177
|
4,
|
|
169
178
|
import("./entrys/vercel")
|
|
170
179
|
];
|
|
171
|
-
case
|
|
180
|
+
case 15:
|
|
172
181
|
genVercelEntry = _state.sent().genVercelEntry;
|
|
173
182
|
code = genVercelEntry({
|
|
174
183
|
plugins,
|
|
@@ -177,14 +186,14 @@ function deploy_default() {
|
|
|
177
186
|
});
|
|
178
187
|
return [
|
|
179
188
|
3,
|
|
180
|
-
|
|
189
|
+
19
|
|
181
190
|
];
|
|
182
|
-
case
|
|
191
|
+
case 16:
|
|
183
192
|
return [
|
|
184
193
|
4,
|
|
185
194
|
import("./entrys/netlify")
|
|
186
195
|
];
|
|
187
|
-
case
|
|
196
|
+
case 17:
|
|
188
197
|
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
|
189
198
|
code = genNetlifyEntry({
|
|
190
199
|
plugins,
|
|
@@ -193,29 +202,26 @@ function deploy_default() {
|
|
|
193
202
|
});
|
|
194
203
|
return [
|
|
195
204
|
3,
|
|
196
|
-
|
|
205
|
+
19
|
|
197
206
|
];
|
|
198
|
-
case
|
|
207
|
+
case 18:
|
|
199
208
|
{
|
|
200
209
|
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
|
201
210
|
}
|
|
202
|
-
_state.label =
|
|
203
|
-
case
|
|
204
|
-
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
|
211
|
+
_state.label = 19;
|
|
212
|
+
case 19:
|
|
205
213
|
entryFilePath = path.join(funcsDirectory, "index.js");
|
|
206
|
-
if (!
|
|
214
|
+
if (!needModernServer)
|
|
207
215
|
return [
|
|
208
216
|
3,
|
|
209
|
-
|
|
217
|
+
22
|
|
210
218
|
];
|
|
211
219
|
return [
|
|
212
220
|
4,
|
|
213
221
|
fse.writeFile(entryFilePath, code)
|
|
214
222
|
];
|
|
215
|
-
case 19:
|
|
216
|
-
_state.sent();
|
|
217
|
-
_state.label = 20;
|
|
218
223
|
case 20:
|
|
224
|
+
_state.sent();
|
|
219
225
|
return [
|
|
220
226
|
4,
|
|
221
227
|
handleDependencies(appDirectory, funcsDirectory, [
|
|
@@ -224,6 +230,8 @@ function deploy_default() {
|
|
|
224
230
|
];
|
|
225
231
|
case 21:
|
|
226
232
|
_state.sent();
|
|
233
|
+
_state.label = 22;
|
|
234
|
+
case 22:
|
|
227
235
|
return [
|
|
228
236
|
2
|
|
229
237
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path, { isAbsolute } from "node:path";
|
|
2
2
|
import { nodeFileTrace, resolve } from "@vercel/nft";
|
|
3
|
-
import { fs as fse, pkgUp } from "@modern-js/utils";
|
|
3
|
+
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
|
4
4
|
import { readPackageJSON } from "pkg-types";
|
|
5
5
|
import { parseNodeModulePath } from "mlly";
|
|
6
6
|
import { linkPackage, writePackage } from "./utils";
|
|
@@ -181,18 +181,17 @@ const handleDependencies = async (appDir, serverRootDir, include) => {
|
|
|
181
181
|
}));
|
|
182
182
|
console.log("multiVersionPkgs111111111", multiVersionPkgs);
|
|
183
183
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
|
184
|
-
const versionEntires = Object.entries(pkgVersions).sort(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
([v1, p1], [v2, p2]) => {
|
|
188
|
-
if (p1.length === 0) {
|
|
189
|
-
return -1;
|
|
190
|
-
}
|
|
191
|
-
if (p2.length === 0) {
|
|
192
|
-
return 1;
|
|
193
|
-
}
|
|
184
|
+
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
|
185
|
+
if (p1.length === 0) {
|
|
186
|
+
return -1;
|
|
194
187
|
}
|
|
195
|
-
|
|
188
|
+
if (p2.length === 0) {
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
return semver.lt(v1, v2, {
|
|
192
|
+
loose: true
|
|
193
|
+
}) ? 1 : -1;
|
|
194
|
+
});
|
|
196
195
|
for (const [version, parentPkgs] of versionEntires) {
|
|
197
196
|
const pkg = tracedPackages[pkgName];
|
|
198
197
|
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
|
@@ -44,7 +44,9 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
44
44
|
disableCustomHook: true
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const app = await createProdServer(prodServerOptions)
|
|
48
|
+
|
|
49
|
+
requestHandler = app.getRequestListener();
|
|
48
50
|
|
|
49
51
|
return requestHandler;
|
|
50
52
|
} catch(error) {
|
|
@@ -9,48 +9,49 @@ var deploy_default = () => ({
|
|
|
9
9
|
"@modern-js/plugin-server"
|
|
10
10
|
],
|
|
11
11
|
setup: (api) => {
|
|
12
|
+
const deployTarget = process.env.MODERNJS_DEPLOY || "node";
|
|
12
13
|
return {
|
|
13
14
|
async beforeDeploy() {
|
|
14
|
-
const deployTarget = process.env.MODERNJS_DEPLOY || "node";
|
|
15
15
|
const appContext = api.useAppContext();
|
|
16
16
|
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
|
|
17
|
+
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
|
18
|
+
const needModernServer = useSSR || useAPI || useWebServer;
|
|
17
19
|
const configContext = api.useResolvedConfigContext();
|
|
18
20
|
let outputDirectory = path.join(appDirectory, ".output");
|
|
19
21
|
let funcsDirectory = outputDirectory;
|
|
20
22
|
let staticDirectory = path.join(outputDirectory, "static");
|
|
21
|
-
await fse.remove(outputDirectory);
|
|
22
23
|
if (deployTarget === "node") {
|
|
23
|
-
await fse.
|
|
24
|
-
|
|
25
|
-
const distStaticDirectory = path.join(distDirectory, "static");
|
|
26
|
-
return !src.includes(distStaticDirectory);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
24
|
+
await fse.remove(outputDirectory);
|
|
25
|
+
await fse.copy(distDirectory, outputDirectory);
|
|
29
26
|
}
|
|
30
27
|
if (deployTarget === "vercel") {
|
|
31
|
-
|
|
28
|
+
const vercelOutput = path.join(appDirectory, ".vercel");
|
|
29
|
+
await fse.remove(vercelOutput);
|
|
30
|
+
outputDirectory = path.join(vercelOutput, "output");
|
|
32
31
|
const config2 = {
|
|
33
32
|
version: 3
|
|
34
33
|
};
|
|
35
34
|
await fse.ensureDir(outputDirectory);
|
|
36
35
|
await fse.writeJSON(path.join(outputDirectory, "config.json"), config2);
|
|
37
|
-
|
|
38
|
-
staticDirectory = path.join(outputDirectory, "static");
|
|
39
|
-
await fse.ensureDir(funcsDirectory);
|
|
40
|
-
await fse.copy(distDirectory, funcsDirectory, {
|
|
41
|
-
filter: (src) => {
|
|
42
|
-
const distStaticDirectory = path.join(distDirectory, "static");
|
|
43
|
-
return !src.includes(distStaticDirectory);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
36
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
|
46
37
|
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
if (needModernServer) {
|
|
39
|
+
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
|
40
|
+
await fse.ensureDir(funcsDirectory);
|
|
41
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
|
42
|
+
filter: (src) => {
|
|
43
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
|
44
|
+
return !src.includes(distStaticDirectory);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
|
48
|
+
runtime: "nodejs16.x",
|
|
49
|
+
handler: "index.js",
|
|
50
|
+
launcherType: "Nodejs",
|
|
51
|
+
shouldAddHelpers: false,
|
|
52
|
+
supportsResponseStreaming: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
54
55
|
}
|
|
55
56
|
const { bff } = configContext;
|
|
56
57
|
const config = {
|
|
@@ -100,14 +101,13 @@ var deploy_default = () => ({
|
|
|
100
101
|
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
|
104
104
|
const entryFilePath = path.join(funcsDirectory, "index.js");
|
|
105
|
-
if (
|
|
105
|
+
if (needModernServer) {
|
|
106
106
|
await fse.writeFile(entryFilePath, code);
|
|
107
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
|
108
|
+
"@modern-js/prod-server"
|
|
109
|
+
]);
|
|
107
110
|
}
|
|
108
|
-
await handleDependencies(appDirectory, funcsDirectory, [
|
|
109
|
-
"@modern-js/prod-server"
|
|
110
|
-
]);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.49.1-alpha.
|
|
18
|
+
"version": "2.49.1-alpha.8",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -79,20 +79,20 @@
|
|
|
79
79
|
"esbuild-register": "^3.5.0",
|
|
80
80
|
"mlly": "^1.6.1",
|
|
81
81
|
"pkg-types": "^1.1.0",
|
|
82
|
-
"@modern-js/core": "2.49.0",
|
|
83
82
|
"@modern-js/plugin": "2.49.0",
|
|
83
|
+
"@modern-js/core": "2.49.0",
|
|
84
84
|
"@modern-js/plugin-i18n": "2.49.0",
|
|
85
|
-
"@modern-js/plugin-lint": "2.49.0",
|
|
86
|
-
"@modern-js/server": "2.49.0",
|
|
87
85
|
"@modern-js/prod-server": "2.49.0",
|
|
88
86
|
"@modern-js/server-core": "2.49.0",
|
|
89
|
-
"@modern-js/server-utils": "2.49.0",
|
|
90
|
-
"@modern-js/types": "2.49.0",
|
|
91
|
-
"@modern-js/rsbuild-plugin-esbuild": "2.49.1",
|
|
92
|
-
"@modern-js/utils": "2.49.0",
|
|
93
|
-
"@modern-js/node-bundle-require": "2.49.0",
|
|
94
87
|
"@modern-js/plugin-data-loader": "2.49.0",
|
|
95
|
-
"@modern-js/
|
|
88
|
+
"@modern-js/node-bundle-require": "2.49.0",
|
|
89
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.49.1",
|
|
90
|
+
"@modern-js/server": "2.49.0",
|
|
91
|
+
"@modern-js/plugin-lint": "2.49.0",
|
|
92
|
+
"@modern-js/types": "2.49.0",
|
|
93
|
+
"@modern-js/uni-builder": "2.49.0",
|
|
94
|
+
"@modern-js/server-utils": "2.49.0",
|
|
95
|
+
"@modern-js/utils": "2.49.0"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@rsbuild/plugin-swc": "0.6.4",
|