@modern-js/app-tools 2.49.3-alpha.2 → 2.49.3-alpha.20
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/plugins/deploy/dependencies.js +1 -12
- package/dist/cjs/plugins/deploy/index.js +25 -147
- package/dist/cjs/plugins/deploy/platforms/netlify.js +120 -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 +41 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +145 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +22 -8
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/plugins/deploy/dependencies.js +1 -47
- package/dist/esm/plugins/deploy/index.js +66 -245
- package/dist/esm/plugins/deploy/platforms/netlify.js +182 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +122 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +104 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +220 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +55 -3
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/plugins/deploy/dependencies.js +1 -12
- package/dist/esm-node/plugins/deploy/index.js +24 -136
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +86 -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 +40 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +111 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +20 -7
- package/dist/esm-node/utils/routes.js +6 -2
- 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 +8 -1
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +21 -21
- package/dist/cjs/plugins/deploy/entrys/netlify.js +0 -95
- package/dist/cjs/plugins/deploy/entrys/node.js +0 -88
- package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -97
- package/dist/esm/plugins/deploy/entrys/netlify.js +0 -41
- package/dist/esm/plugins/deploy/entrys/node.js +0 -39
- package/dist/esm/plugins/deploy/entrys/vercel.js +0 -43
- package/dist/esm-node/plugins/deploy/entrys/netlify.js +0 -71
- package/dist/esm-node/plugins/deploy/entrys/node.js +0 -64
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -73
- package/dist/types/plugins/deploy/entrys/netlify.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/node.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/vercel.d.ts +0 -6
@@ -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();
|
@@ -4,8 +4,14 @@ import path from "path";
|
|
4
4
|
import os from "node:os";
|
5
5
|
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
6
6
|
import { parseNodeModulePath } from "mlly";
|
7
|
-
var
|
8
|
-
|
7
|
+
var serverAppContenxtTemplate = function(appContext) {
|
8
|
+
var appDirectory = appContext.appDirectory, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName;
|
9
|
+
return {
|
10
|
+
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
11
|
+
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
12
|
+
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
13
|
+
metaName
|
14
|
+
};
|
9
15
|
};
|
10
16
|
var getPluginsCode = function(plugins) {
|
11
17
|
return "[".concat(plugins.map(function(_, index) {
|
@@ -232,6 +238,51 @@ var linkPackage = function() {
|
|
232
238
|
return _ref.apply(this, arguments);
|
233
239
|
};
|
234
240
|
}();
|
241
|
+
var readDirRecursive = function() {
|
242
|
+
var _ref = _async_to_generator(function(dir) {
|
243
|
+
var files, filesAndDirs;
|
244
|
+
return _ts_generator(this, function(_state) {
|
245
|
+
switch (_state.label) {
|
246
|
+
case 0:
|
247
|
+
return [
|
248
|
+
4,
|
249
|
+
fse.readdir(dir, {
|
250
|
+
withFileTypes: true
|
251
|
+
})
|
252
|
+
];
|
253
|
+
case 1:
|
254
|
+
files = _state.sent();
|
255
|
+
return [
|
256
|
+
4,
|
257
|
+
Promise.all(files.map(function() {
|
258
|
+
var _ref2 = _async_to_generator(function(file) {
|
259
|
+
var resPath;
|
260
|
+
return _ts_generator(this, function(_state2) {
|
261
|
+
resPath = path.resolve(dir, file.name);
|
262
|
+
return [
|
263
|
+
2,
|
264
|
+
file.isDirectory() ? readDirRecursive(resPath) : resPath
|
265
|
+
];
|
266
|
+
});
|
267
|
+
});
|
268
|
+
return function(file) {
|
269
|
+
return _ref2.apply(this, arguments);
|
270
|
+
};
|
271
|
+
}()))
|
272
|
+
];
|
273
|
+
case 2:
|
274
|
+
filesAndDirs = _state.sent();
|
275
|
+
return [
|
276
|
+
2,
|
277
|
+
filesAndDirs.flat()
|
278
|
+
];
|
279
|
+
}
|
280
|
+
});
|
281
|
+
});
|
282
|
+
return function readDirRecursive2(dir) {
|
283
|
+
return _ref.apply(this, arguments);
|
284
|
+
};
|
285
|
+
}();
|
235
286
|
export {
|
236
287
|
applyProductionCondition,
|
237
288
|
applyPublicCondition,
|
@@ -239,6 +290,7 @@ export {
|
|
239
290
|
getPluginsCode,
|
240
291
|
getProjectUsage,
|
241
292
|
linkPackage,
|
242
|
-
|
293
|
+
readDirRecursive,
|
294
|
+
serverAppContenxtTemplate,
|
243
295
|
writePackage
|
244
296
|
};
|
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,
|
@@ -3,17 +3,7 @@ import { nodeFileTrace, resolve } from "@vercel/nft";
|
|
3
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
|
-
import { linkPackage, writePackage } from "./utils";
|
7
|
-
const readDirRecursive = async (dir) => {
|
8
|
-
const files = await fse.readdir(dir, {
|
9
|
-
withFileTypes: true
|
10
|
-
});
|
11
|
-
const filesAndDirs = await Promise.all(files.map(async (file) => {
|
12
|
-
const resPath = path.resolve(dir, file.name);
|
13
|
-
return file.isDirectory() ? readDirRecursive(resPath) : resPath;
|
14
|
-
}));
|
15
|
-
return filesAndDirs.flat();
|
16
|
-
};
|
6
|
+
import { linkPackage, readDirRecursive, writePackage } from "./utils";
|
17
7
|
async function isFile(file) {
|
18
8
|
try {
|
19
9
|
const stat = await fse.stat(file);
|
@@ -179,7 +169,6 @@ const handleDependencies = async (appDir, serverRootDir, include) => {
|
|
179
169
|
const version = Object.keys(pkg.versions)[0];
|
180
170
|
return writePackage(pkg, version, serverRootDir);
|
181
171
|
}));
|
182
|
-
console.log("multiVersionPkgs111111111", multiVersionPkgs);
|
183
172
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
184
173
|
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
185
174
|
if (p1.length === 0) {
|
@@ -1,8 +1,23 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
3
1
|
import { provider } from "std-env";
|
4
2
|
import { getProjectUsage } from "./utils";
|
5
|
-
import {
|
3
|
+
import { createNodePreset } from "./platforms/node";
|
4
|
+
import { createVercelPreset } from "./platforms/vercel";
|
5
|
+
import { createNetlifyPreset } from "./platforms/netlify";
|
6
|
+
const deployPresets = {
|
7
|
+
node: createNodePreset,
|
8
|
+
vercel: createVercelPreset,
|
9
|
+
netlify: createNetlifyPreset
|
10
|
+
};
|
11
|
+
async function getDeployPreset(appContext, modernConfig, deployTarget) {
|
12
|
+
const { appDirectory, distDirectory } = appContext;
|
13
|
+
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
14
|
+
const needModernServer = useSSR || useAPI || useWebServer;
|
15
|
+
const createPreset = deployPresets[deployTarget];
|
16
|
+
if (!createPreset) {
|
17
|
+
throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
|
18
|
+
}
|
19
|
+
return createPreset(appContext, modernConfig, needModernServer);
|
20
|
+
}
|
6
21
|
var deploy_default = () => ({
|
7
22
|
name: "@modern-js/plugin-deploy",
|
8
23
|
pre: [
|
@@ -14,139 +29,12 @@ var deploy_default = () => ({
|
|
14
29
|
return {
|
15
30
|
async beforeDeploy() {
|
16
31
|
const appContext = api.useAppContext();
|
17
|
-
const
|
18
|
-
const
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
let staticDirectory = path.join(outputDirectory, "static");
|
24
|
-
if (deployTarget === "node") {
|
25
|
-
await fse.remove(outputDirectory);
|
26
|
-
await fse.copy(distDirectory, outputDirectory);
|
27
|
-
}
|
28
|
-
if (deployTarget === "vercel") {
|
29
|
-
const vercelOutput = path.join(appDirectory, ".vercel");
|
30
|
-
await fse.remove(vercelOutput);
|
31
|
-
outputDirectory = path.join(vercelOutput, "output");
|
32
|
-
const config2 = {
|
33
|
-
version: 3,
|
34
|
-
routes: [
|
35
|
-
{
|
36
|
-
src: "/static/(.*)",
|
37
|
-
headers: {
|
38
|
-
"cache-control": "s-maxage=31536000, immutable"
|
39
|
-
},
|
40
|
-
continue: true
|
41
|
-
},
|
42
|
-
{
|
43
|
-
handle: "filesystem"
|
44
|
-
}
|
45
|
-
]
|
46
|
-
};
|
47
|
-
if (!needModernServer) {
|
48
|
-
entrypoints.forEach((entry) => {
|
49
|
-
config2.routes.push({
|
50
|
-
src: `/${entry.entryName}(?:/.*)?`,
|
51
|
-
headers: {
|
52
|
-
"cache-control": "s-maxage=0"
|
53
|
-
},
|
54
|
-
dest: `/html/${entry.entryName}/index.html`
|
55
|
-
});
|
56
|
-
});
|
57
|
-
} else {
|
58
|
-
config2.routes.push({
|
59
|
-
src: "/(.*)",
|
60
|
-
dest: `/index`
|
61
|
-
});
|
62
|
-
}
|
63
|
-
await fse.ensureDir(outputDirectory);
|
64
|
-
await fse.writeJSON(path.join(outputDirectory, "config.json"), config2, {
|
65
|
-
spaces: 2
|
66
|
-
});
|
67
|
-
staticDirectory = path.join(outputDirectory, "static/static");
|
68
|
-
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
69
|
-
if (!needModernServer) {
|
70
|
-
const destHtmlDirectory = path.join(distDirectory, "html");
|
71
|
-
const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
72
|
-
await fse.copy(destHtmlDirectory, outputHtmlDirectory);
|
73
|
-
} else {
|
74
|
-
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
75
|
-
await fse.ensureDir(funcsDirectory);
|
76
|
-
await fse.copy(distDirectory, funcsDirectory, {
|
77
|
-
filter: (src) => {
|
78
|
-
const distStaticDirectory = path.join(distDirectory, "static");
|
79
|
-
return !src.includes(distStaticDirectory);
|
80
|
-
}
|
81
|
-
});
|
82
|
-
const apiDirectory2 = path.join(funcsDirectory, "api");
|
83
|
-
if (await fse.pathExists(apiDirectory2)) {
|
84
|
-
await fse.rename(apiDirectory2, path.join(funcsDirectory, "_api"));
|
85
|
-
}
|
86
|
-
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
87
|
-
runtime: "nodejs16.x",
|
88
|
-
handler: "index.js",
|
89
|
-
launcherType: "Nodejs",
|
90
|
-
shouldAddHelpers: false,
|
91
|
-
supportsResponseStreaming: true
|
92
|
-
});
|
93
|
-
}
|
94
|
-
}
|
95
|
-
const { bff } = configContext;
|
96
|
-
const config = {
|
97
|
-
output: {
|
98
|
-
path: "."
|
99
|
-
},
|
100
|
-
bff
|
101
|
-
};
|
102
|
-
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
103
|
-
const serverAppContext = {
|
104
|
-
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
105
|
-
apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
|
106
|
-
lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
|
107
|
-
metaName
|
108
|
-
};
|
109
|
-
let code = ``;
|
110
|
-
console.log("deployTarget111111111", deployTarget);
|
111
|
-
switch (deployTarget) {
|
112
|
-
case "node": {
|
113
|
-
const { genNodeEntry } = await import("./entrys/node");
|
114
|
-
code = genNodeEntry({
|
115
|
-
plugins,
|
116
|
-
config,
|
117
|
-
appContext: serverAppContext
|
118
|
-
});
|
119
|
-
break;
|
120
|
-
}
|
121
|
-
case "vercel": {
|
122
|
-
const { genVercelEntry } = await import("./entrys/vercel");
|
123
|
-
code = genVercelEntry({
|
124
|
-
plugins,
|
125
|
-
config,
|
126
|
-
appContext: serverAppContext
|
127
|
-
});
|
128
|
-
break;
|
129
|
-
}
|
130
|
-
case "netlify": {
|
131
|
-
const { genNetlifyEntry } = await import("./entrys/netlify");
|
132
|
-
code = genNetlifyEntry({
|
133
|
-
plugins,
|
134
|
-
config,
|
135
|
-
appContext: serverAppContext
|
136
|
-
});
|
137
|
-
break;
|
138
|
-
}
|
139
|
-
default: {
|
140
|
-
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
141
|
-
}
|
142
|
-
}
|
143
|
-
const entryFilePath = path.join(funcsDirectory, "index.js");
|
144
|
-
if (needModernServer) {
|
145
|
-
await fse.writeFile(entryFilePath, code);
|
146
|
-
await handleDependencies(appDirectory, funcsDirectory, [
|
147
|
-
"@modern-js/prod-server"
|
148
|
-
]);
|
149
|
-
}
|
32
|
+
const modernConfig = api.useResolvedConfigContext();
|
33
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
34
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
35
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
36
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
37
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
|
150
38
|
}
|
151
39
|
};
|
152
40
|
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import path from "node:path";
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
|
3
|
+
import { isMainEntry } from "../../../utils/routes";
|
4
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
5
|
+
import { handleDependencies } from "../dependencies";
|
6
|
+
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
7
|
+
const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
|
8
|
+
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
9
|
+
const netlifyOutput = path.join(appDirectory, ".netlify");
|
10
|
+
const funcsDirectory = path.join(netlifyOutput, "functions");
|
11
|
+
const entryFilePath = path.join(funcsDirectory, "index.js");
|
12
|
+
return {
|
13
|
+
async prepare() {
|
14
|
+
await fse.remove(netlifyOutput);
|
15
|
+
},
|
16
|
+
async writeOutput() {
|
17
|
+
const routes = [];
|
18
|
+
const { source: { mainEntryName } } = modernConfig;
|
19
|
+
if (!needModernServer) {
|
20
|
+
entrypoints.forEach((entry) => {
|
21
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
22
|
+
routes.push({
|
23
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
24
|
+
dest: `/html/${entry.entryName}/index.html`,
|
25
|
+
status: 200
|
26
|
+
});
|
27
|
+
});
|
28
|
+
} else {
|
29
|
+
routes.push({
|
30
|
+
src: "/*",
|
31
|
+
dest: `/.netlify/functions/index`,
|
32
|
+
status: 200
|
33
|
+
});
|
34
|
+
}
|
35
|
+
const redirectContent = routes.map((route) => {
|
36
|
+
return `${route.src} ${route.dest} ${route.status}`;
|
37
|
+
}).join("\n");
|
38
|
+
if (needModernServer) {
|
39
|
+
await fse.ensureDir(funcsDirectory);
|
40
|
+
await fse.copy(distDirectory, 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
|
+
}
|
48
|
+
const redirectFilePath = path.join(distDirectory, "_redirects");
|
49
|
+
await fse.writeFile(redirectFilePath, redirectContent);
|
50
|
+
},
|
51
|
+
async genEntry() {
|
52
|
+
var _modernConfig_bff;
|
53
|
+
if (!needModernServer) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
const serverConfig = {
|
57
|
+
bff: {
|
58
|
+
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
59
|
+
},
|
60
|
+
output: {
|
61
|
+
path: "."
|
62
|
+
}
|
63
|
+
};
|
64
|
+
const pluginImportCode = genPluginImportsCode(plugins || []);
|
65
|
+
const dynamicProdOptions = {
|
66
|
+
config: serverConfig,
|
67
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
68
|
+
plugins
|
69
|
+
};
|
70
|
+
let entryCode = (await fse.readFile(path.join(__dirname, "./netlifyEntry.js"))).toString();
|
71
|
+
const serverAppContext = serverAppContenxtTemplate(appContext);
|
72
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
73
|
+
await fse.writeFile(entryFilePath, entryCode);
|
74
|
+
},
|
75
|
+
async end() {
|
76
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
77
|
+
"@modern-js/prod-server"
|
78
|
+
]);
|
79
|
+
const netlifyNodeModules = path.join(netlifyOutput, "node_modules");
|
80
|
+
await fse.move(path.join(funcsDirectory, "node_modules"), netlifyNodeModules);
|
81
|
+
}
|
82
|
+
};
|
83
|
+
};
|
84
|
+
export {
|
85
|
+
createNetlifyPreset
|
86
|
+
};
|
@@ -0,0 +1,68 @@
|
|
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_netlifyEntry = __commonJS({
|
6
|
+
"src/plugins/deploy/platforms/netlifyEntry.js"(exports, module) {
|
7
|
+
const fs = require("node:fs/promises");
|
8
|
+
const path = require("node:path");
|
9
|
+
const { createNetlifyFunction } = require("@modern-js/prod-server/netlify");
|
10
|
+
p_genPluginImportsCode;
|
11
|
+
if (!process.env.NODE_ENV) {
|
12
|
+
process.env.NODE_ENV = "production";
|
13
|
+
}
|
14
|
+
let requestHandler = null;
|
15
|
+
let handlerCreationPromise = null;
|
16
|
+
async function loadRoutes(routeFilepath) {
|
17
|
+
try {
|
18
|
+
await fs.access(routeFilepath);
|
19
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
20
|
+
const routeSpec = JSON.parse(content);
|
21
|
+
return routeSpec.routes || [];
|
22
|
+
} catch (error) {
|
23
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
24
|
+
return [];
|
25
|
+
}
|
26
|
+
}
|
27
|
+
async function initServer() {
|
28
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
29
|
+
const routes = await loadRoutes(routeFilepath);
|
30
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
31
|
+
const prodServerOptions = {
|
32
|
+
pwd: __dirname,
|
33
|
+
routes,
|
34
|
+
disableCustomHook: true,
|
35
|
+
appContext: {
|
36
|
+
sharedDirectory: p_sharedDirectory,
|
37
|
+
apiDirectory: p_apiDirectory,
|
38
|
+
lambdaDirectory: p_lambdaDirectory
|
39
|
+
},
|
40
|
+
...dynamicProdOptions
|
41
|
+
};
|
42
|
+
const requestHandler2 = await createNetlifyFunction(prodServerOptions);
|
43
|
+
return requestHandler2;
|
44
|
+
}
|
45
|
+
async function createHandler() {
|
46
|
+
if (!handlerCreationPromise) {
|
47
|
+
handlerCreationPromise = (async () => {
|
48
|
+
try {
|
49
|
+
requestHandler = await initServer();
|
50
|
+
} catch (error) {
|
51
|
+
console.error("Error creating server:", error);
|
52
|
+
process.exit(1);
|
53
|
+
}
|
54
|
+
})();
|
55
|
+
}
|
56
|
+
await handlerCreationPromise;
|
57
|
+
return requestHandler;
|
58
|
+
}
|
59
|
+
createHandler();
|
60
|
+
module.exports.default = async (request, context) => {
|
61
|
+
if (!requestHandler) {
|
62
|
+
await createHandler();
|
63
|
+
}
|
64
|
+
return requestHandler(request, context);
|
65
|
+
};
|
66
|
+
}
|
67
|
+
});
|
68
|
+
export default require_netlifyEntry();
|