@modern-js/app-tools 2.50.0 → 2.51.0
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/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/commands/deploy.js +1 -0
- package/dist/cjs/hooks.js +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +217 -0
- package/dist/cjs/plugins/deploy/dependencies/utils.js +165 -0
- package/dist/cjs/plugins/deploy/index.js +64 -0
- package/dist/cjs/plugins/deploy/platforms/netlify.js +136 -0
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +90 -0
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +44 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +148 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +81 -0
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/commands/deploy.js +7 -1
- package/dist/esm/hooks.js +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +580 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +407 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +291 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +124 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +107 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +225 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/commands/deploy.js +1 -0
- package/dist/esm-node/hooks.js +1 -0
- package/dist/esm-node/index.js +3 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +183 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +124 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +102 -0
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +56 -0
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +43 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +114 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/defineConfig.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -0
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +31 -0
- package/dist/types/plugins/deploy/index.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +10 -0
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/utils.d.ts +20 -0
- package/dist/types/types/hooks.d.ts +1 -0
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +26 -22
@@ -0,0 +1,107 @@
|
|
1
|
+
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
|
2
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
3
|
+
var _ts_generator = require("@swc/helpers/_/_ts_generator");
|
4
|
+
var fs = require("node:fs/promises");
|
5
|
+
var path = require("node:path");
|
6
|
+
var createProdServer = require("@modern-js/prod-server").createProdServer;
|
7
|
+
p_genPluginImportsCode;
|
8
|
+
if (!process.env.NODE_ENV) {
|
9
|
+
process.env.NODE_ENV = "production";
|
10
|
+
}
|
11
|
+
function loadRoutes(routeFilepath) {
|
12
|
+
return _loadRoutes.apply(this, arguments);
|
13
|
+
}
|
14
|
+
function _loadRoutes() {
|
15
|
+
_loadRoutes = _async_to_generator._(function(routeFilepath) {
|
16
|
+
var content, routeSpec, error;
|
17
|
+
return _ts_generator._(this, function(_state) {
|
18
|
+
switch (_state.label) {
|
19
|
+
case 0:
|
20
|
+
_state.trys.push([
|
21
|
+
0,
|
22
|
+
3,
|
23
|
+
,
|
24
|
+
4
|
25
|
+
]);
|
26
|
+
return [
|
27
|
+
4,
|
28
|
+
fs.access(routeFilepath)
|
29
|
+
];
|
30
|
+
case 1:
|
31
|
+
_state.sent();
|
32
|
+
return [
|
33
|
+
4,
|
34
|
+
fs.readFile(routeFilepath, "utf-8")
|
35
|
+
];
|
36
|
+
case 2:
|
37
|
+
content = _state.sent();
|
38
|
+
routeSpec = JSON.parse(content);
|
39
|
+
return [
|
40
|
+
2,
|
41
|
+
routeSpec.routes || []
|
42
|
+
];
|
43
|
+
case 3:
|
44
|
+
error = _state.sent();
|
45
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
46
|
+
return [
|
47
|
+
2,
|
48
|
+
[]
|
49
|
+
];
|
50
|
+
case 4:
|
51
|
+
return [
|
52
|
+
2
|
53
|
+
];
|
54
|
+
}
|
55
|
+
});
|
56
|
+
});
|
57
|
+
return _loadRoutes.apply(this, arguments);
|
58
|
+
}
|
59
|
+
function main() {
|
60
|
+
return _main.apply(this, arguments);
|
61
|
+
}
|
62
|
+
function _main() {
|
63
|
+
_main = _async_to_generator._(function() {
|
64
|
+
var routeFilepath, routes, dynamicProdOptions, prodServerOptions, app, port;
|
65
|
+
return _ts_generator._(this, function(_state) {
|
66
|
+
switch (_state.label) {
|
67
|
+
case 0:
|
68
|
+
routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
69
|
+
return [
|
70
|
+
4,
|
71
|
+
loadRoutes(routeFilepath)
|
72
|
+
];
|
73
|
+
case 1:
|
74
|
+
routes = _state.sent();
|
75
|
+
dynamicProdOptions = p_dynamicProdOptions;
|
76
|
+
prodServerOptions = _object_spread._({
|
77
|
+
pwd: __dirname,
|
78
|
+
routes,
|
79
|
+
disableCustomHook: true,
|
80
|
+
appContext: {
|
81
|
+
sharedDirectory: p_sharedDirectory,
|
82
|
+
apiDirectory: p_apiDirectory,
|
83
|
+
lambdaDirectory: p_lambdaDirectory
|
84
|
+
}
|
85
|
+
}, dynamicProdOptions);
|
86
|
+
return [
|
87
|
+
4,
|
88
|
+
createProdServer(prodServerOptions)
|
89
|
+
];
|
90
|
+
case 2:
|
91
|
+
app = _state.sent();
|
92
|
+
port = process.env.PORT || 8080;
|
93
|
+
app.listen({
|
94
|
+
host: "::",
|
95
|
+
port
|
96
|
+
}, function() {
|
97
|
+
console.log("\x1B[32mServer is listening on http://[::]:".concat(port), "\x1B[0m");
|
98
|
+
});
|
99
|
+
return [
|
100
|
+
2
|
101
|
+
];
|
102
|
+
}
|
103
|
+
});
|
104
|
+
});
|
105
|
+
return _main.apply(this, arguments);
|
106
|
+
}
|
107
|
+
main();
|
File without changes
|
@@ -0,0 +1,225 @@
|
|
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 "node:path";
|
4
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
|
5
|
+
import { isMainEntry } from "../../../utils/routes";
|
6
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
7
|
+
import { handleDependencies } from "../dependencies";
|
8
|
+
var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
9
|
+
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, entrypoints = appContext.entrypoints;
|
10
|
+
var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
11
|
+
var vercelOutput = path.join(appDirectory, ".vercel");
|
12
|
+
var outputDirectory = path.join(vercelOutput, "output");
|
13
|
+
var funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
14
|
+
var entryFilePath = path.join(funcsDirectory, "index.js");
|
15
|
+
return {
|
16
|
+
prepare: function prepare() {
|
17
|
+
return _async_to_generator(function() {
|
18
|
+
return _ts_generator(this, function(_state) {
|
19
|
+
switch (_state.label) {
|
20
|
+
case 0:
|
21
|
+
return [
|
22
|
+
4,
|
23
|
+
fse.remove(vercelOutput)
|
24
|
+
];
|
25
|
+
case 1:
|
26
|
+
_state.sent();
|
27
|
+
return [
|
28
|
+
2
|
29
|
+
];
|
30
|
+
}
|
31
|
+
});
|
32
|
+
})();
|
33
|
+
},
|
34
|
+
writeOutput: function writeOutput() {
|
35
|
+
return _async_to_generator(function() {
|
36
|
+
var config, mainEntryName, staticDirectory, destHtmlDirectory, outputHtmlDirectory;
|
37
|
+
return _ts_generator(this, function(_state) {
|
38
|
+
switch (_state.label) {
|
39
|
+
case 0:
|
40
|
+
config = {
|
41
|
+
version: 3,
|
42
|
+
routes: [
|
43
|
+
{
|
44
|
+
src: "/static/(.*)",
|
45
|
+
headers: {
|
46
|
+
"cache-control": "s-maxage=31536000, immutable"
|
47
|
+
},
|
48
|
+
continue: true
|
49
|
+
},
|
50
|
+
{
|
51
|
+
handle: "filesystem"
|
52
|
+
}
|
53
|
+
]
|
54
|
+
};
|
55
|
+
if (!needModernServer) {
|
56
|
+
mainEntryName = modernConfig.source.mainEntryName;
|
57
|
+
entrypoints.forEach(function(entry) {
|
58
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
59
|
+
config.routes.push({
|
60
|
+
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
61
|
+
headers: {
|
62
|
+
"cache-control": "s-maxage=0"
|
63
|
+
},
|
64
|
+
dest: "/html/".concat(entry.entryName, "/index.html")
|
65
|
+
});
|
66
|
+
});
|
67
|
+
} else {
|
68
|
+
config.routes.push({
|
69
|
+
src: "/(.*)",
|
70
|
+
dest: "/index"
|
71
|
+
});
|
72
|
+
}
|
73
|
+
return [
|
74
|
+
4,
|
75
|
+
fse.ensureDir(outputDirectory)
|
76
|
+
];
|
77
|
+
case 1:
|
78
|
+
_state.sent();
|
79
|
+
return [
|
80
|
+
4,
|
81
|
+
fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
82
|
+
spaces: 2
|
83
|
+
})
|
84
|
+
];
|
85
|
+
case 2:
|
86
|
+
_state.sent();
|
87
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
88
|
+
return [
|
89
|
+
4,
|
90
|
+
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
91
|
+
];
|
92
|
+
case 3:
|
93
|
+
_state.sent();
|
94
|
+
if (!!needModernServer)
|
95
|
+
return [
|
96
|
+
3,
|
97
|
+
5
|
98
|
+
];
|
99
|
+
destHtmlDirectory = path.join(distDirectory, "html");
|
100
|
+
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
101
|
+
return [
|
102
|
+
4,
|
103
|
+
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
104
|
+
];
|
105
|
+
case 4:
|
106
|
+
_state.sent();
|
107
|
+
return [
|
108
|
+
3,
|
109
|
+
9
|
110
|
+
];
|
111
|
+
case 5:
|
112
|
+
return [
|
113
|
+
4,
|
114
|
+
fse.ensureDir(funcsDirectory)
|
115
|
+
];
|
116
|
+
case 6:
|
117
|
+
_state.sent();
|
118
|
+
return [
|
119
|
+
4,
|
120
|
+
fse.copy(distDirectory, funcsDirectory, {
|
121
|
+
filter: function(src) {
|
122
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
123
|
+
return !src.includes(distStaticDirectory);
|
124
|
+
}
|
125
|
+
})
|
126
|
+
];
|
127
|
+
case 7:
|
128
|
+
_state.sent();
|
129
|
+
return [
|
130
|
+
4,
|
131
|
+
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
132
|
+
runtime: "nodejs16.x",
|
133
|
+
handler: "index.js",
|
134
|
+
launcherType: "Nodejs",
|
135
|
+
shouldAddHelpers: false,
|
136
|
+
supportsResponseStreaming: true
|
137
|
+
})
|
138
|
+
];
|
139
|
+
case 8:
|
140
|
+
_state.sent();
|
141
|
+
_state.label = 9;
|
142
|
+
case 9:
|
143
|
+
return [
|
144
|
+
2
|
145
|
+
];
|
146
|
+
}
|
147
|
+
});
|
148
|
+
})();
|
149
|
+
},
|
150
|
+
genEntry: function genEntry() {
|
151
|
+
return _async_to_generator(function() {
|
152
|
+
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, serverAppContext, entryCode;
|
153
|
+
return _ts_generator(this, function(_state) {
|
154
|
+
switch (_state.label) {
|
155
|
+
case 0:
|
156
|
+
if (!needModernServer) {
|
157
|
+
return [
|
158
|
+
2
|
159
|
+
];
|
160
|
+
}
|
161
|
+
serverConfig = {
|
162
|
+
bff: {
|
163
|
+
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
164
|
+
},
|
165
|
+
output: {
|
166
|
+
path: "."
|
167
|
+
}
|
168
|
+
};
|
169
|
+
pluginImportCode = genPluginImportsCode(plugins || []);
|
170
|
+
dynamicProdOptions = {
|
171
|
+
config: serverConfig,
|
172
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
173
|
+
plugins
|
174
|
+
};
|
175
|
+
serverAppContext = serverAppContenxtTemplate(appContext);
|
176
|
+
return [
|
177
|
+
4,
|
178
|
+
fse.readFile(path.join(__dirname, "./vercelEntry.js"))
|
179
|
+
];
|
180
|
+
case 1:
|
181
|
+
entryCode = _state.sent().toString();
|
182
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
183
|
+
return [
|
184
|
+
4,
|
185
|
+
fse.writeFile(entryFilePath, entryCode)
|
186
|
+
];
|
187
|
+
case 2:
|
188
|
+
_state.sent();
|
189
|
+
return [
|
190
|
+
2
|
191
|
+
];
|
192
|
+
}
|
193
|
+
});
|
194
|
+
})();
|
195
|
+
},
|
196
|
+
end: function end() {
|
197
|
+
return _async_to_generator(function() {
|
198
|
+
return _ts_generator(this, function(_state) {
|
199
|
+
switch (_state.label) {
|
200
|
+
case 0:
|
201
|
+
if (!needModernServer) {
|
202
|
+
return [
|
203
|
+
2
|
204
|
+
];
|
205
|
+
}
|
206
|
+
return [
|
207
|
+
4,
|
208
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
209
|
+
"@modern-js/prod-server"
|
210
|
+
])
|
211
|
+
];
|
212
|
+
case 1:
|
213
|
+
_state.sent();
|
214
|
+
return [
|
215
|
+
2
|
216
|
+
];
|
217
|
+
}
|
218
|
+
});
|
219
|
+
})();
|
220
|
+
}
|
221
|
+
};
|
222
|
+
};
|
223
|
+
export {
|
224
|
+
createVercelPreset
|
225
|
+
};
|
@@ -0,0 +1,202 @@
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
4
|
+
};
|
5
|
+
var require_vercelEntry = __commonJS({
|
6
|
+
"src/plugins/deploy/platforms/vercelEntry.js"(exports, module) {
|
7
|
+
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
|
8
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
9
|
+
var _ts_generator = require("@swc/helpers/_/_ts_generator");
|
10
|
+
var fs = require("node:fs/promises");
|
11
|
+
var path = require("node:path");
|
12
|
+
var createProdServer = require("@modern-js/prod-server").createProdServer;
|
13
|
+
p_genPluginImportsCode;
|
14
|
+
if (!process.env.NODE_ENV) {
|
15
|
+
process.env.NODE_ENV = "production";
|
16
|
+
}
|
17
|
+
var requestHandler = null;
|
18
|
+
var handlerCreationPromise = null;
|
19
|
+
function loadRoutes(routeFilepath) {
|
20
|
+
return _loadRoutes.apply(this, arguments);
|
21
|
+
}
|
22
|
+
function _loadRoutes() {
|
23
|
+
_loadRoutes = _async_to_generator._(function(routeFilepath) {
|
24
|
+
var content, routeSpec, error;
|
25
|
+
return _ts_generator._(this, function(_state) {
|
26
|
+
switch (_state.label) {
|
27
|
+
case 0:
|
28
|
+
_state.trys.push([
|
29
|
+
0,
|
30
|
+
3,
|
31
|
+
,
|
32
|
+
4
|
33
|
+
]);
|
34
|
+
return [
|
35
|
+
4,
|
36
|
+
fs.access(routeFilepath)
|
37
|
+
];
|
38
|
+
case 1:
|
39
|
+
_state.sent();
|
40
|
+
return [
|
41
|
+
4,
|
42
|
+
fs.readFile(routeFilepath, "utf-8")
|
43
|
+
];
|
44
|
+
case 2:
|
45
|
+
content = _state.sent();
|
46
|
+
routeSpec = JSON.parse(content);
|
47
|
+
return [
|
48
|
+
2,
|
49
|
+
routeSpec.routes || []
|
50
|
+
];
|
51
|
+
case 3:
|
52
|
+
error = _state.sent();
|
53
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
54
|
+
return [
|
55
|
+
2,
|
56
|
+
[]
|
57
|
+
];
|
58
|
+
case 4:
|
59
|
+
return [
|
60
|
+
2
|
61
|
+
];
|
62
|
+
}
|
63
|
+
});
|
64
|
+
});
|
65
|
+
return _loadRoutes.apply(this, arguments);
|
66
|
+
}
|
67
|
+
function initServer() {
|
68
|
+
return _initServer.apply(this, arguments);
|
69
|
+
}
|
70
|
+
function _initServer() {
|
71
|
+
_initServer = _async_to_generator._(function() {
|
72
|
+
var routeFilepath, routes, dynamicProdOptions, prodServerOptions, app;
|
73
|
+
return _ts_generator._(this, function(_state) {
|
74
|
+
switch (_state.label) {
|
75
|
+
case 0:
|
76
|
+
routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
77
|
+
return [
|
78
|
+
4,
|
79
|
+
loadRoutes(routeFilepath)
|
80
|
+
];
|
81
|
+
case 1:
|
82
|
+
routes = _state.sent();
|
83
|
+
dynamicProdOptions = p_dynamicProdOptions;
|
84
|
+
prodServerOptions = _object_spread._({
|
85
|
+
pwd: __dirname,
|
86
|
+
routes,
|
87
|
+
disableCustomHook: true,
|
88
|
+
appContext: {
|
89
|
+
sharedDirectory: p_sharedDirectory,
|
90
|
+
apiDirectory: p_apiDirectory,
|
91
|
+
lambdaDirectory: p_lambdaDirectory
|
92
|
+
}
|
93
|
+
}, dynamicProdOptions);
|
94
|
+
return [
|
95
|
+
4,
|
96
|
+
createProdServer(prodServerOptions)
|
97
|
+
];
|
98
|
+
case 2:
|
99
|
+
app = _state.sent();
|
100
|
+
return [
|
101
|
+
2,
|
102
|
+
app.getRequestListener()
|
103
|
+
];
|
104
|
+
}
|
105
|
+
});
|
106
|
+
});
|
107
|
+
return _initServer.apply(this, arguments);
|
108
|
+
}
|
109
|
+
function createHandler() {
|
110
|
+
return _createHandler.apply(this, arguments);
|
111
|
+
}
|
112
|
+
function _createHandler() {
|
113
|
+
_createHandler = _async_to_generator._(function() {
|
114
|
+
return _ts_generator._(this, function(_state) {
|
115
|
+
switch (_state.label) {
|
116
|
+
case 0:
|
117
|
+
if (!handlerCreationPromise) {
|
118
|
+
handlerCreationPromise = _async_to_generator._(function() {
|
119
|
+
var error;
|
120
|
+
return _ts_generator._(this, function(_state2) {
|
121
|
+
switch (_state2.label) {
|
122
|
+
case 0:
|
123
|
+
_state2.trys.push([
|
124
|
+
0,
|
125
|
+
2,
|
126
|
+
,
|
127
|
+
3
|
128
|
+
]);
|
129
|
+
return [
|
130
|
+
4,
|
131
|
+
initServer()
|
132
|
+
];
|
133
|
+
case 1:
|
134
|
+
requestHandler = _state2.sent();
|
135
|
+
return [
|
136
|
+
3,
|
137
|
+
3
|
138
|
+
];
|
139
|
+
case 2:
|
140
|
+
error = _state2.sent();
|
141
|
+
console.error("Error creating server:", error);
|
142
|
+
process.exit(1);
|
143
|
+
return [
|
144
|
+
3,
|
145
|
+
3
|
146
|
+
];
|
147
|
+
case 3:
|
148
|
+
return [
|
149
|
+
2
|
150
|
+
];
|
151
|
+
}
|
152
|
+
});
|
153
|
+
})();
|
154
|
+
}
|
155
|
+
return [
|
156
|
+
4,
|
157
|
+
handlerCreationPromise
|
158
|
+
];
|
159
|
+
case 1:
|
160
|
+
_state.sent();
|
161
|
+
return [
|
162
|
+
2,
|
163
|
+
requestHandler
|
164
|
+
];
|
165
|
+
}
|
166
|
+
});
|
167
|
+
});
|
168
|
+
return _createHandler.apply(this, arguments);
|
169
|
+
}
|
170
|
+
createHandler();
|
171
|
+
module.exports = function() {
|
172
|
+
var _ref = _async_to_generator._(function(req, res) {
|
173
|
+
return _ts_generator._(this, function(_state) {
|
174
|
+
switch (_state.label) {
|
175
|
+
case 0:
|
176
|
+
if (!!requestHandler)
|
177
|
+
return [
|
178
|
+
3,
|
179
|
+
2
|
180
|
+
];
|
181
|
+
return [
|
182
|
+
4,
|
183
|
+
createHandler()
|
184
|
+
];
|
185
|
+
case 1:
|
186
|
+
_state.sent();
|
187
|
+
_state.label = 2;
|
188
|
+
case 2:
|
189
|
+
return [
|
190
|
+
2,
|
191
|
+
requestHandler(req, res)
|
192
|
+
];
|
193
|
+
}
|
194
|
+
});
|
195
|
+
});
|
196
|
+
return function(req, res) {
|
197
|
+
return _ref.apply(this, arguments);
|
198
|
+
};
|
199
|
+
}();
|
200
|
+
}
|
201
|
+
});
|
202
|
+
export default require_vercelEntry();
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
3
|
+
var serverAppContenxtTemplate = function(appContext) {
|
4
|
+
var appDirectory = appContext.appDirectory, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName;
|
5
|
+
return {
|
6
|
+
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
7
|
+
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
8
|
+
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
9
|
+
metaName
|
10
|
+
};
|
11
|
+
};
|
12
|
+
var getPluginsCode = function(plugins) {
|
13
|
+
return "[".concat(plugins.map(function(_, index) {
|
14
|
+
return "plugin_".concat(index, "()");
|
15
|
+
}).join(","), "]");
|
16
|
+
};
|
17
|
+
var genPluginImportsCode = function(plugins) {
|
18
|
+
return plugins.map(function(plugin, index) {
|
19
|
+
return "\n let plugin_".concat(index, " = require('").concat(plugin, "')\n plugin_").concat(index, " = plugin_").concat(index, ".default || plugin_").concat(index, "\n ");
|
20
|
+
}).join(";\n");
|
21
|
+
};
|
22
|
+
var getProjectUsage = function(appDirectory, distDirectory) {
|
23
|
+
var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
24
|
+
var routes = fse.readJSONSync(routeJSON).routes;
|
25
|
+
var useSSR = false;
|
26
|
+
var useAPI = false;
|
27
|
+
routes.forEach(function(route) {
|
28
|
+
if (route.isSSR) {
|
29
|
+
useSSR = true;
|
30
|
+
}
|
31
|
+
if (route.isApi) {
|
32
|
+
useAPI = true;
|
33
|
+
}
|
34
|
+
});
|
35
|
+
var useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server");
|
36
|
+
return {
|
37
|
+
useSSR,
|
38
|
+
useAPI,
|
39
|
+
useWebServer
|
40
|
+
};
|
41
|
+
};
|
42
|
+
export {
|
43
|
+
genPluginImportsCode,
|
44
|
+
getPluginsCode,
|
45
|
+
getProjectUsage,
|
46
|
+
serverAppContenxtTemplate
|
47
|
+
};
|
package/dist/esm/utils/routes.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import path from "path";
|
4
|
-
import { fs, ROUTE_SPEC_FILE } from "@modern-js/utils";
|
4
|
+
import { fs, MAIN_ENTRY_NAME, ROUTE_SPEC_FILE } from "@modern-js/utils";
|
5
5
|
var generateRoutes = function() {
|
6
6
|
var _ref = _async_to_generator(function(appContext) {
|
7
7
|
var serverRoutes, distDirectory, output;
|
@@ -32,7 +32,11 @@ var getPathWithoutExt = function(filename) {
|
|
32
32
|
var extname = path.extname(filename);
|
33
33
|
return filename.slice(0, -extname.length);
|
34
34
|
};
|
35
|
+
var isMainEntry = function(entryName, mainEntryName) {
|
36
|
+
return entryName === (mainEntryName || MAIN_ENTRY_NAME);
|
37
|
+
};
|
35
38
|
export {
|
36
39
|
generateRoutes,
|
37
|
-
getPathWithoutExt
|
40
|
+
getPathWithoutExt,
|
41
|
+
isMainEntry
|
38
42
|
};
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import fs from "fs";
|
3
|
-
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY,
|
3
|
+
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
4
|
+
import { isMainEntry } from "../utils/routes";
|
4
5
|
import { walkDirectory } from "./utils";
|
5
6
|
const applyBaseUrl = (baseUrl, routes) => {
|
6
7
|
if (baseUrl) {
|
@@ -73,14 +74,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
73
74
|
const { packageName } = appContext;
|
74
75
|
const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
75
76
|
let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
|
76
|
-
const
|
77
|
-
const entryOptions = getEntryOptions(entryName,
|
77
|
+
const isMain = isMainEntry(entryName, mainEntryName);
|
78
|
+
const entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
|
78
79
|
const isSSR = Boolean(entryOptions);
|
79
80
|
const isWorker = Boolean(workerSSR);
|
80
81
|
const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
|
81
82
|
const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
|
82
83
|
let route = {
|
83
|
-
urlPath: `/${
|
84
|
+
urlPath: `/${isMain ? "" : entryName}`,
|
84
85
|
entryName,
|
85
86
|
entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
|
86
87
|
isSPA: true,
|
package/dist/esm-node/hooks.js
CHANGED
@@ -19,6 +19,7 @@ const hooks = {
|
|
19
19
|
beforeBuild: createAsyncWorkflow(),
|
20
20
|
afterBuild: createAsyncWorkflow(),
|
21
21
|
beforeDeploy: createAsyncWorkflow(),
|
22
|
+
deploy: createAsyncWorkflow(),
|
22
23
|
afterDeploy: createAsyncWorkflow(),
|
23
24
|
beforeRestart: createAsyncWorkflow(),
|
24
25
|
registerDev: createParallelWorkflow(),
|
package/dist/esm-node/index.js
CHANGED
@@ -8,6 +8,7 @@ import initializePlugin from "./initialize";
|
|
8
8
|
import { hooks } from "./hooks";
|
9
9
|
import { i18n, localeKeys } from "./locale";
|
10
10
|
import serverBuildPlugin from "./plugins/serverBuild";
|
11
|
+
import deployPlugin from "./plugins/deploy";
|
11
12
|
import { restart } from "./utils/restart";
|
12
13
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
13
14
|
import { mergeConfig } from "@modern-js/core";
|
@@ -81,7 +82,8 @@ const appTools = (options = {
|
|
81
82
|
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
82
83
|
}),
|
83
84
|
serverBuildPlugin(),
|
84
|
-
lintPlugin()
|
85
|
+
lintPlugin(),
|
86
|
+
deployPlugin()
|
85
87
|
],
|
86
88
|
setup: (api) => {
|
87
89
|
const appContext = api.useAppContext();
|