@modern-js/app-tools 2.49.1-alpha.1 → 2.49.1-alpha.10
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 +8 -9
- package/dist/cjs/plugins/deploy/index.js +59 -29
- package/dist/esm/plugins/deploy/dependencies.js +12 -13
- package/dist/esm/plugins/deploy/entrys/vercel.js +3 -4
- package/dist/esm/plugins/deploy/index.js +115 -53
- package/dist/esm-node/plugins/deploy/dependencies.js +11 -12
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +8 -9
- package/dist/esm-node/plugins/deploy/index.js +59 -29
- package/package.json +4 -4
|
@@ -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}`;
|
|
@@ -36,15 +36,14 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
36
36
|
|
|
37
37
|
const fs = require('node:fs/promises');
|
|
38
38
|
const path = require('node:path');
|
|
39
|
-
const {
|
|
39
|
+
const { createProdServer } = require('@modern-js/prod-server');
|
|
40
40
|
${(0, import_utils2.genPluginImportsCode)(plugins || [])}
|
|
41
41
|
|
|
42
|
-
let requestHandler = null;
|
|
43
|
-
|
|
44
42
|
if(!process.env.NODE_ENV){
|
|
45
43
|
process.env.NODE_ENV = 'production';
|
|
46
44
|
}
|
|
47
45
|
|
|
46
|
+
let requestHandler = null;
|
|
48
47
|
async function createHandler() {
|
|
49
48
|
try {
|
|
50
49
|
let routes = [];
|
|
@@ -68,9 +67,11 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
68
67
|
disableCustomHook: true
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
const app = await createProdServer(prodServerOptions)
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
requestHandler = app.getRequestListener();
|
|
73
|
+
|
|
74
|
+
return requestHandler;
|
|
74
75
|
} catch(error) {
|
|
75
76
|
console.error(error);
|
|
76
77
|
process.exit(1);
|
|
@@ -79,14 +80,12 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
79
80
|
|
|
80
81
|
createHandler();
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
module.exports = async(req, res) => {
|
|
83
84
|
if(typeof requestHandler !== 'function'){
|
|
84
85
|
await createHandler();
|
|
85
86
|
}
|
|
86
|
-
return requestHandler(
|
|
87
|
+
return requestHandler(req, res);
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
-
export default handleRequest;
|
|
90
89
|
`;
|
|
91
90
|
}
|
|
92
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -42,41 +42,72 @@ 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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
|
62
|
+
await import_utils.fs.remove(vercelOutput);
|
|
63
|
+
outputDirectory = import_path.default.join(vercelOutput, "output");
|
|
64
|
+
const config2 = {
|
|
65
|
+
version: 3,
|
|
66
|
+
routes: [
|
|
67
|
+
{
|
|
68
|
+
src: "/static/(.*)",
|
|
69
|
+
headers: {
|
|
70
|
+
"cache-control": "s-maxage=31536000, immutable"
|
|
71
|
+
},
|
|
72
|
+
continue: true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
handle: "filesystem"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
src: "/(.*)",
|
|
79
|
+
headers: {
|
|
80
|
+
"cache-control": "s-maxage=0"
|
|
81
|
+
},
|
|
82
|
+
dest: "/html/main/index.html"
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
await import_utils.fs.ensureDir(outputDirectory);
|
|
87
|
+
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config2);
|
|
88
|
+
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
|
72
89
|
await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
if (!needModernServer) {
|
|
91
|
+
const destHtmlDirectory = import_path.default.join(distDirectory, "html");
|
|
92
|
+
const outputHtmlDirectory = import_path.default.join(destHtmlDirectory, "html");
|
|
93
|
+
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
|
94
|
+
} else {
|
|
95
|
+
funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
|
|
96
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
|
97
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
|
98
|
+
filter: (src) => {
|
|
99
|
+
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
|
100
|
+
return !src.includes(distStaticDirectory);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
|
|
104
|
+
runtime: "nodejs16.x",
|
|
105
|
+
handler: "index.js",
|
|
106
|
+
launcherType: "Nodejs",
|
|
107
|
+
shouldAddHelpers: false,
|
|
108
|
+
supportsResponseStreaming: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
80
111
|
}
|
|
81
112
|
const { bff } = configContext;
|
|
82
113
|
const config = {
|
|
@@ -126,14 +157,13 @@ var deploy_default = () => ({
|
|
|
126
157
|
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
|
127
158
|
}
|
|
128
159
|
}
|
|
129
|
-
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
|
130
160
|
const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
|
|
131
|
-
if (
|
|
161
|
+
if (needModernServer) {
|
|
132
162
|
await import_utils.fs.writeFile(entryFilePath, code);
|
|
163
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
|
164
|
+
"@modern-js/prod-server"
|
|
165
|
+
]);
|
|
133
166
|
}
|
|
134
|
-
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
|
135
|
-
"@modern-js/prod-server"
|
|
136
|
-
]);
|
|
137
167
|
}
|
|
138
168
|
};
|
|
139
169
|
}
|
|
@@ -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:
|
|
@@ -10,14 +10,13 @@ function genVercelEntry() {
|
|
|
10
10
|
path: "."
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const {
|
|
14
|
-
|
|
15
|
-
let requestHandler = null;
|
|
13
|
+
return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createProdServer } = require('@modern-js/prod-server');\n ".concat(genPluginImportsCode(plugins || []), `
|
|
16
14
|
|
|
17
15
|
if(!process.env.NODE_ENV){
|
|
18
16
|
process.env.NODE_ENV = 'production';
|
|
19
17
|
}
|
|
20
18
|
|
|
19
|
+
let requestHandler = null;
|
|
21
20
|
async function createHandler() {
|
|
22
21
|
try {
|
|
23
22
|
let routes = [];
|
|
@@ -34,7 +33,7 @@ function genVercelEntry() {
|
|
|
34
33
|
const prodServerOptions = {
|
|
35
34
|
pwd: __dirname,
|
|
36
35
|
routes,
|
|
37
|
-
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 ");
|
|
38
37
|
}
|
|
39
38
|
export {
|
|
40
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, destHtmlDirectory, outputHtmlDirectory, 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,26 +50,92 @@ function deploy_default() {
|
|
|
53
50
|
if (!(deployTarget === "vercel"))
|
|
54
51
|
return [
|
|
55
52
|
3,
|
|
56
|
-
|
|
53
|
+
13
|
|
57
54
|
];
|
|
58
|
-
|
|
59
|
-
staticDirectory = path.join(outputDirectory, "static");
|
|
55
|
+
vercelOutput = path.join(appDirectory, ".vercel");
|
|
60
56
|
return [
|
|
61
57
|
4,
|
|
62
|
-
fse.
|
|
63
|
-
filter: function(src) {
|
|
64
|
-
var distStaticDirectory = path.join(distDirectory, "static");
|
|
65
|
-
return !src.includes(distStaticDirectory);
|
|
66
|
-
}
|
|
67
|
-
})
|
|
58
|
+
fse.remove(vercelOutput)
|
|
68
59
|
];
|
|
69
60
|
case 4:
|
|
70
61
|
_state.sent();
|
|
62
|
+
outputDirectory = path.join(vercelOutput, "output");
|
|
63
|
+
config = {
|
|
64
|
+
version: 3,
|
|
65
|
+
routes: [
|
|
66
|
+
{
|
|
67
|
+
src: "/static/(.*)",
|
|
68
|
+
headers: {
|
|
69
|
+
"cache-control": "s-maxage=31536000, immutable"
|
|
70
|
+
},
|
|
71
|
+
continue: true
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
handle: "filesystem"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
src: "/(.*)",
|
|
78
|
+
headers: {
|
|
79
|
+
"cache-control": "s-maxage=0"
|
|
80
|
+
},
|
|
81
|
+
dest: "/html/main/index.html"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
};
|
|
71
85
|
return [
|
|
72
86
|
4,
|
|
73
|
-
fse.
|
|
87
|
+
fse.ensureDir(outputDirectory)
|
|
74
88
|
];
|
|
75
89
|
case 5:
|
|
90
|
+
_state.sent();
|
|
91
|
+
return [
|
|
92
|
+
4,
|
|
93
|
+
fse.writeJSON(path.join(outputDirectory, "config.json"), config)
|
|
94
|
+
];
|
|
95
|
+
case 6:
|
|
96
|
+
_state.sent();
|
|
97
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
|
98
|
+
return [
|
|
99
|
+
4,
|
|
100
|
+
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
|
101
|
+
];
|
|
102
|
+
case 7:
|
|
103
|
+
_state.sent();
|
|
104
|
+
if (!!needModernServer)
|
|
105
|
+
return [
|
|
106
|
+
3,
|
|
107
|
+
9
|
|
108
|
+
];
|
|
109
|
+
destHtmlDirectory = path.join(distDirectory, "html");
|
|
110
|
+
outputHtmlDirectory = path.join(destHtmlDirectory, "html");
|
|
111
|
+
return [
|
|
112
|
+
4,
|
|
113
|
+
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
|
114
|
+
];
|
|
115
|
+
case 8:
|
|
116
|
+
_state.sent();
|
|
117
|
+
return [
|
|
118
|
+
3,
|
|
119
|
+
13
|
|
120
|
+
];
|
|
121
|
+
case 9:
|
|
122
|
+
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
|
123
|
+
return [
|
|
124
|
+
4,
|
|
125
|
+
fse.ensureDir(funcsDirectory)
|
|
126
|
+
];
|
|
127
|
+
case 10:
|
|
128
|
+
_state.sent();
|
|
129
|
+
return [
|
|
130
|
+
4,
|
|
131
|
+
fse.copy(distDirectory, funcsDirectory, {
|
|
132
|
+
filter: function(src) {
|
|
133
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
|
134
|
+
return !src.includes(distStaticDirectory);
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
];
|
|
138
|
+
case 11:
|
|
76
139
|
_state.sent();
|
|
77
140
|
return [
|
|
78
141
|
4,
|
|
@@ -84,12 +147,12 @@ function deploy_default() {
|
|
|
84
147
|
supportsResponseStreaming: true
|
|
85
148
|
})
|
|
86
149
|
];
|
|
87
|
-
case
|
|
150
|
+
case 12:
|
|
88
151
|
_state.sent();
|
|
89
|
-
_state.label =
|
|
90
|
-
case
|
|
152
|
+
_state.label = 13;
|
|
153
|
+
case 13:
|
|
91
154
|
bff = configContext.bff;
|
|
92
|
-
|
|
155
|
+
config1 = {
|
|
93
156
|
output: {
|
|
94
157
|
path: "."
|
|
95
158
|
},
|
|
@@ -108,100 +171,99 @@ function deploy_default() {
|
|
|
108
171
|
case "node":
|
|
109
172
|
return [
|
|
110
173
|
3,
|
|
111
|
-
|
|
174
|
+
14
|
|
112
175
|
];
|
|
113
176
|
case "vercel":
|
|
114
177
|
return [
|
|
115
178
|
3,
|
|
116
|
-
|
|
179
|
+
16
|
|
117
180
|
];
|
|
118
181
|
case "netlify":
|
|
119
182
|
return [
|
|
120
183
|
3,
|
|
121
|
-
|
|
184
|
+
18
|
|
122
185
|
];
|
|
123
186
|
}
|
|
124
187
|
return [
|
|
125
188
|
3,
|
|
126
|
-
|
|
189
|
+
20
|
|
127
190
|
];
|
|
128
|
-
case
|
|
191
|
+
case 14:
|
|
129
192
|
return [
|
|
130
193
|
4,
|
|
131
194
|
import("./entrys/node")
|
|
132
195
|
];
|
|
133
|
-
case
|
|
196
|
+
case 15:
|
|
134
197
|
genNodeEntry = _state.sent().genNodeEntry;
|
|
135
198
|
code = genNodeEntry({
|
|
136
199
|
plugins,
|
|
137
|
-
config,
|
|
200
|
+
config: config1,
|
|
138
201
|
appContext: serverAppContext
|
|
139
202
|
});
|
|
140
203
|
return [
|
|
141
204
|
3,
|
|
142
|
-
|
|
205
|
+
21
|
|
143
206
|
];
|
|
144
|
-
case
|
|
207
|
+
case 16:
|
|
145
208
|
return [
|
|
146
209
|
4,
|
|
147
210
|
import("./entrys/vercel")
|
|
148
211
|
];
|
|
149
|
-
case
|
|
212
|
+
case 17:
|
|
150
213
|
genVercelEntry = _state.sent().genVercelEntry;
|
|
151
214
|
code = genVercelEntry({
|
|
152
215
|
plugins,
|
|
153
|
-
config,
|
|
216
|
+
config: config1,
|
|
154
217
|
appContext: serverAppContext
|
|
155
218
|
});
|
|
156
219
|
return [
|
|
157
220
|
3,
|
|
158
|
-
|
|
221
|
+
21
|
|
159
222
|
];
|
|
160
|
-
case
|
|
223
|
+
case 18:
|
|
161
224
|
return [
|
|
162
225
|
4,
|
|
163
226
|
import("./entrys/netlify")
|
|
164
227
|
];
|
|
165
|
-
case
|
|
228
|
+
case 19:
|
|
166
229
|
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
|
167
230
|
code = genNetlifyEntry({
|
|
168
231
|
plugins,
|
|
169
|
-
config,
|
|
232
|
+
config: config1,
|
|
170
233
|
appContext: serverAppContext
|
|
171
234
|
});
|
|
172
235
|
return [
|
|
173
236
|
3,
|
|
174
|
-
|
|
237
|
+
21
|
|
175
238
|
];
|
|
176
|
-
case
|
|
239
|
+
case 20:
|
|
177
240
|
{
|
|
178
241
|
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
|
179
242
|
}
|
|
180
|
-
_state.label =
|
|
181
|
-
case
|
|
182
|
-
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
|
243
|
+
_state.label = 21;
|
|
244
|
+
case 21:
|
|
183
245
|
entryFilePath = path.join(funcsDirectory, "index.js");
|
|
184
|
-
if (!
|
|
246
|
+
if (!needModernServer)
|
|
185
247
|
return [
|
|
186
248
|
3,
|
|
187
|
-
|
|
249
|
+
24
|
|
188
250
|
];
|
|
189
251
|
return [
|
|
190
252
|
4,
|
|
191
253
|
fse.writeFile(entryFilePath, code)
|
|
192
254
|
];
|
|
193
|
-
case
|
|
255
|
+
case 22:
|
|
194
256
|
_state.sent();
|
|
195
|
-
_state.label = 17;
|
|
196
|
-
case 17:
|
|
197
257
|
return [
|
|
198
258
|
4,
|
|
199
259
|
handleDependencies(appDirectory, funcsDirectory, [
|
|
200
260
|
"@modern-js/prod-server"
|
|
201
261
|
])
|
|
202
262
|
];
|
|
203
|
-
case
|
|
263
|
+
case 23:
|
|
204
264
|
_state.sent();
|
|
265
|
+
_state.label = 24;
|
|
266
|
+
case 24:
|
|
205
267
|
return [
|
|
206
268
|
2
|
|
207
269
|
];
|
|
@@ -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}`;
|
|
@@ -13,15 +13,14 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
13
13
|
|
|
14
14
|
const fs = require('node:fs/promises');
|
|
15
15
|
const path = require('node:path');
|
|
16
|
-
const {
|
|
16
|
+
const { createProdServer } = require('@modern-js/prod-server');
|
|
17
17
|
${genPluginImportsCode(plugins || [])}
|
|
18
18
|
|
|
19
|
-
let requestHandler = null;
|
|
20
|
-
|
|
21
19
|
if(!process.env.NODE_ENV){
|
|
22
20
|
process.env.NODE_ENV = 'production';
|
|
23
21
|
}
|
|
24
22
|
|
|
23
|
+
let requestHandler = null;
|
|
25
24
|
async function createHandler() {
|
|
26
25
|
try {
|
|
27
26
|
let routes = [];
|
|
@@ -45,9 +44,11 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
45
44
|
disableCustomHook: true
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
const app = await createProdServer(prodServerOptions)
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
requestHandler = app.getRequestListener();
|
|
50
|
+
|
|
51
|
+
return requestHandler;
|
|
51
52
|
} catch(error) {
|
|
52
53
|
console.error(error);
|
|
53
54
|
process.exit(1);
|
|
@@ -56,14 +57,12 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
|
|
|
56
57
|
|
|
57
58
|
createHandler();
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
module.exports = async(req, res) => {
|
|
60
61
|
if(typeof requestHandler !== 'function'){
|
|
61
62
|
await createHandler();
|
|
62
63
|
}
|
|
63
|
-
return requestHandler(
|
|
64
|
+
return requestHandler(req, res);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
export default handleRequest;
|
|
67
66
|
`;
|
|
68
67
|
}
|
|
69
68
|
export {
|
|
@@ -9,41 +9,72 @@ 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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
const vercelOutput = path.join(appDirectory, ".vercel");
|
|
29
|
+
await fse.remove(vercelOutput);
|
|
30
|
+
outputDirectory = path.join(vercelOutput, "output");
|
|
31
|
+
const config2 = {
|
|
32
|
+
version: 3,
|
|
33
|
+
routes: [
|
|
34
|
+
{
|
|
35
|
+
src: "/static/(.*)",
|
|
36
|
+
headers: {
|
|
37
|
+
"cache-control": "s-maxage=31536000, immutable"
|
|
38
|
+
},
|
|
39
|
+
continue: true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
handle: "filesystem"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
src: "/(.*)",
|
|
46
|
+
headers: {
|
|
47
|
+
"cache-control": "s-maxage=0"
|
|
48
|
+
},
|
|
49
|
+
dest: "/html/main/index.html"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
await fse.ensureDir(outputDirectory);
|
|
54
|
+
await fse.writeJSON(path.join(outputDirectory, "config.json"), config2);
|
|
55
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
|
39
56
|
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
if (!needModernServer) {
|
|
58
|
+
const destHtmlDirectory = path.join(distDirectory, "html");
|
|
59
|
+
const outputHtmlDirectory = path.join(destHtmlDirectory, "html");
|
|
60
|
+
await fse.copy(destHtmlDirectory, outputHtmlDirectory);
|
|
61
|
+
} else {
|
|
62
|
+
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
|
63
|
+
await fse.ensureDir(funcsDirectory);
|
|
64
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
|
65
|
+
filter: (src) => {
|
|
66
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
|
67
|
+
return !src.includes(distStaticDirectory);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
|
71
|
+
runtime: "nodejs16.x",
|
|
72
|
+
handler: "index.js",
|
|
73
|
+
launcherType: "Nodejs",
|
|
74
|
+
shouldAddHelpers: false,
|
|
75
|
+
supportsResponseStreaming: true
|
|
76
|
+
});
|
|
77
|
+
}
|
|
47
78
|
}
|
|
48
79
|
const { bff } = configContext;
|
|
49
80
|
const config = {
|
|
@@ -93,14 +124,13 @@ var deploy_default = () => ({
|
|
|
93
124
|
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
|
94
125
|
}
|
|
95
126
|
}
|
|
96
|
-
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
|
97
127
|
const entryFilePath = path.join(funcsDirectory, "index.js");
|
|
98
|
-
if (
|
|
128
|
+
if (needModernServer) {
|
|
99
129
|
await fse.writeFile(entryFilePath, code);
|
|
130
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
|
131
|
+
"@modern-js/prod-server"
|
|
132
|
+
]);
|
|
100
133
|
}
|
|
101
|
-
await handleDependencies(appDirectory, funcsDirectory, [
|
|
102
|
-
"@modern-js/prod-server"
|
|
103
|
-
]);
|
|
104
134
|
}
|
|
105
135
|
};
|
|
106
136
|
}
|
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.10",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -82,17 +82,17 @@
|
|
|
82
82
|
"@modern-js/core": "2.49.0",
|
|
83
83
|
"@modern-js/node-bundle-require": "2.49.0",
|
|
84
84
|
"@modern-js/plugin": "2.49.0",
|
|
85
|
+
"@modern-js/plugin-data-loader": "2.49.0",
|
|
85
86
|
"@modern-js/plugin-i18n": "2.49.0",
|
|
86
87
|
"@modern-js/prod-server": "2.49.0",
|
|
87
88
|
"@modern-js/plugin-lint": "2.49.0",
|
|
88
89
|
"@modern-js/server": "2.49.0",
|
|
89
90
|
"@modern-js/rsbuild-plugin-esbuild": "2.49.1",
|
|
90
91
|
"@modern-js/types": "2.49.0",
|
|
92
|
+
"@modern-js/server-utils": "2.49.0",
|
|
91
93
|
"@modern-js/server-core": "2.49.0",
|
|
92
|
-
"@modern-js/utils": "2.49.0",
|
|
93
94
|
"@modern-js/uni-builder": "2.49.0",
|
|
94
|
-
"@modern-js/
|
|
95
|
-
"@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",
|