@modern-js/app-tools 2.49.3-alpha.14 → 2.49.3-alpha.16
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/dependencies.js +1 -11
- package/dist/cjs/plugins/deploy/index copy.js +216 -0
- package/dist/cjs/plugins/deploy/index.js +17 -168
- package/dist/cjs/plugins/deploy/platforms/netlify.js +112 -64
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +43 -21
- package/dist/cjs/plugins/deploy/platforms/vercel.js +102 -19
- package/dist/cjs/plugins/deploy/utils.js +22 -8
- package/dist/esm/plugins/deploy/dependencies.js +1 -46
- package/dist/esm/plugins/deploy/index copy.js +367 -0
- package/dist/esm/plugins/deploy/index.js +21 -313
- package/dist/esm/plugins/deploy/platforms/netlify.js +203 -36
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +105 -46
- package/dist/esm/plugins/deploy/platforms/vercel.js +203 -43
- package/dist/esm/plugins/deploy/utils.js +55 -3
- package/dist/esm-node/plugins/deploy/dependencies.js +1 -11
- package/dist/esm-node/plugins/deploy/index copy.js +186 -0
- package/dist/esm-node/plugins/deploy/index.js +15 -156
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +103 -65
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +44 -22
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +103 -20
- package/dist/esm-node/plugins/deploy/utils.js +20 -7
- package/dist/types/plugins/deploy/index copy.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -5
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -8
- package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -4
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -8
- package/dist/types/plugins/deploy/utils.d.ts +8 -1
- package/package.json +8 -8
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
const fs = require("node:fs/promises");
|
3
|
+
const path = require("node:path");
|
4
|
+
const { createNetlifyFunction } = require("@modern-js/prod-server/netlify");
|
5
|
+
p_genPluginImportsCode;
|
6
|
+
if (!process.env.NODE_ENV) {
|
7
|
+
process.env.NODE_ENV = "production";
|
8
|
+
}
|
9
|
+
let requestHandler = null;
|
10
|
+
let handlerCreationPromise = null;
|
11
|
+
async function loadRoutes(routeFilepath) {
|
12
|
+
try {
|
13
|
+
await fs.access(routeFilepath);
|
14
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
15
|
+
const routeSpec = JSON.parse(content);
|
16
|
+
return routeSpec.routes || [];
|
17
|
+
} catch (error) {
|
18
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
19
|
+
return [];
|
20
|
+
}
|
21
|
+
}
|
22
|
+
async function initServer() {
|
23
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
24
|
+
const routes = await loadRoutes(routeFilepath);
|
25
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
26
|
+
const prodServerOptions = {
|
27
|
+
pwd: __dirname,
|
28
|
+
routes,
|
29
|
+
disableCustomHook: true,
|
30
|
+
appContext: {
|
31
|
+
sharedDirectory: p_sharedDirectory,
|
32
|
+
apiDirectory: p_apiDirectory,
|
33
|
+
lambdaDirectory: p_lambdaDirectory
|
34
|
+
},
|
35
|
+
...dynamicProdOptions
|
36
|
+
};
|
37
|
+
const app = await createNetlifyFunction(prodServerOptions);
|
38
|
+
return app.getRequestListener();
|
39
|
+
}
|
40
|
+
async function createHandler() {
|
41
|
+
if (!handlerCreationPromise) {
|
42
|
+
handlerCreationPromise = (async () => {
|
43
|
+
try {
|
44
|
+
requestHandler = await initServer();
|
45
|
+
} catch (error) {
|
46
|
+
console.error("Error creating server:", error);
|
47
|
+
process.exit(1);
|
48
|
+
}
|
49
|
+
})();
|
50
|
+
}
|
51
|
+
await handlerCreationPromise;
|
52
|
+
return requestHandler;
|
53
|
+
}
|
54
|
+
createHandler();
|
55
|
+
module.exports = async (request, context) => {
|
56
|
+
if (!requestHandler) {
|
57
|
+
await createHandler();
|
58
|
+
}
|
59
|
+
return requestHandler(request, context);
|
60
|
+
};
|
@@ -28,36 +28,58 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var node_exports = {};
|
30
30
|
__export(node_exports, {
|
31
|
-
|
31
|
+
createNodePreset: () => createNodePreset
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(node_exports);
|
34
34
|
var import_node_path = __toESM(require("node:path"));
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
36
|
var import_utils2 = require("../utils");
|
37
|
-
|
38
|
-
|
39
|
-
const
|
40
|
-
|
41
|
-
|
37
|
+
var import_dependencies = require("../dependencies");
|
38
|
+
const createNodePreset = (appContext, config, needModernServer) => {
|
39
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
40
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
41
|
+
const outputDirectory = import_node_path.default.join(appDirectory, ".output");
|
42
|
+
const entryFilePath = import_node_path.default.join(outputDirectory, "index.js");
|
43
|
+
return {
|
44
|
+
async prepare() {
|
45
|
+
await import_utils.fs.remove(outputDirectory);
|
42
46
|
},
|
43
|
-
|
44
|
-
|
47
|
+
async writeOutput() {
|
48
|
+
await import_utils.fs.copy(distDirectory, outputDirectory);
|
45
49
|
},
|
46
|
-
|
47
|
-
|
50
|
+
async genEntry() {
|
51
|
+
var _config_bff;
|
52
|
+
if (!needModernServer) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
const serverConfig = {
|
56
|
+
server: {
|
57
|
+
port: 8080
|
58
|
+
},
|
59
|
+
bff: {
|
60
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
61
|
+
},
|
62
|
+
output: {
|
63
|
+
path: "."
|
64
|
+
}
|
65
|
+
};
|
66
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
67
|
+
const dynamicProdOptions = {
|
68
|
+
config: serverConfig,
|
69
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
70
|
+
plugins
|
71
|
+
};
|
72
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
73
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
74
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
75
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
76
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
|
77
|
+
"@modern-js/prod-server"
|
78
|
+
]);
|
48
79
|
}
|
49
80
|
};
|
50
|
-
|
51
|
-
const dynamicProdOptions = {
|
52
|
-
config: serverConfig,
|
53
|
-
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
54
|
-
plugins
|
55
|
-
};
|
56
|
-
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
57
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", appContext.sharedDirectory).replace("p_apiDirectory", appContext.apiDirectory).replace("p_lambdaDirectory", appContext.lambdaDirectory);
|
58
|
-
return entryCode;
|
59
|
-
}
|
81
|
+
};
|
60
82
|
// Annotate the CommonJS export names for ESM import in node:
|
61
83
|
0 && (module.exports = {
|
62
|
-
|
84
|
+
createNodePreset
|
63
85
|
});
|
@@ -28,33 +28,116 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var vercel_exports = {};
|
30
30
|
__export(vercel_exports, {
|
31
|
-
|
31
|
+
createVercelPreset: () => createVercelPreset
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(vercel_exports);
|
34
34
|
var import_node_path = __toESM(require("node:path"));
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
|
+
var import_routes = require("../../../utils/routes");
|
36
37
|
var import_utils2 = require("../utils");
|
37
|
-
|
38
|
-
|
39
|
-
const
|
40
|
-
|
41
|
-
|
38
|
+
var import_dependencies = require("../dependencies");
|
39
|
+
const createVercelPreset = (appContext, config, needModernServer) => {
|
40
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
41
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
42
|
+
const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
|
43
|
+
const outputDirectory = import_node_path.default.join(vercelOutput, "output");
|
44
|
+
const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
|
45
|
+
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
46
|
+
return {
|
47
|
+
async prepare() {
|
48
|
+
await import_utils.fs.remove(vercelOutput);
|
42
49
|
},
|
43
|
-
|
44
|
-
|
50
|
+
async writeOutput() {
|
51
|
+
const config2 = {
|
52
|
+
version: 3,
|
53
|
+
routes: [
|
54
|
+
{
|
55
|
+
src: "/static/(.*)",
|
56
|
+
headers: {
|
57
|
+
"cache-control": "s-maxage=31536000, immutable"
|
58
|
+
},
|
59
|
+
continue: true
|
60
|
+
},
|
61
|
+
{
|
62
|
+
handle: "filesystem"
|
63
|
+
}
|
64
|
+
]
|
65
|
+
};
|
66
|
+
if (!needModernServer) {
|
67
|
+
const { source: { mainEntryName } } = config2;
|
68
|
+
entrypoints.forEach((entry) => {
|
69
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
70
|
+
config2.routes.push({
|
71
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
72
|
+
headers: {
|
73
|
+
"cache-control": "s-maxage=0"
|
74
|
+
},
|
75
|
+
dest: `/html/${entry.entryName}/index.html`
|
76
|
+
});
|
77
|
+
});
|
78
|
+
} else {
|
79
|
+
config2.routes.push({
|
80
|
+
src: "/(.*)",
|
81
|
+
dest: `/index`
|
82
|
+
});
|
83
|
+
}
|
84
|
+
await import_utils.fs.ensureDir(outputDirectory);
|
85
|
+
await import_utils.fs.writeJSON(import_node_path.default.join(outputDirectory, "config.json"), config2, {
|
86
|
+
spaces: 2
|
87
|
+
});
|
88
|
+
const staticDirectory = import_node_path.default.join(outputDirectory, "static/static");
|
89
|
+
await import_utils.fs.copy(import_node_path.default.join(distDirectory, "static"), staticDirectory);
|
90
|
+
if (!needModernServer) {
|
91
|
+
const destHtmlDirectory = import_node_path.default.join(distDirectory, "html");
|
92
|
+
const outputHtmlDirectory = import_node_path.default.join(import_node_path.default.join(outputDirectory, "static"), "html");
|
93
|
+
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
94
|
+
} else {
|
95
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
96
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
97
|
+
filter: (src) => {
|
98
|
+
const distStaticDirectory = import_node_path.default.join(distDirectory, "static");
|
99
|
+
return !src.includes(distStaticDirectory);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
await import_utils.fs.writeJSON(import_node_path.default.join(funcsDirectory, ".vc-config.json"), {
|
103
|
+
runtime: "nodejs16.x",
|
104
|
+
handler: "index.js",
|
105
|
+
launcherType: "Nodejs",
|
106
|
+
shouldAddHelpers: false,
|
107
|
+
supportsResponseStreaming: true
|
108
|
+
});
|
109
|
+
}
|
110
|
+
},
|
111
|
+
async genEntry() {
|
112
|
+
var _config_bff;
|
113
|
+
if (!needModernServer) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
const serverConfig = {
|
117
|
+
bff: {
|
118
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
119
|
+
},
|
120
|
+
output: {
|
121
|
+
path: "."
|
122
|
+
}
|
123
|
+
};
|
124
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
125
|
+
const dynamicProdOptions = {
|
126
|
+
config: serverConfig,
|
127
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
128
|
+
plugins
|
129
|
+
};
|
130
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
131
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
132
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
133
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
134
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
135
|
+
"@modern-js/prod-server"
|
136
|
+
]);
|
45
137
|
}
|
46
138
|
};
|
47
|
-
|
48
|
-
const dynamicProdOptions = {
|
49
|
-
config: serverConfig,
|
50
|
-
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
51
|
-
plugins
|
52
|
-
};
|
53
|
-
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
54
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", appContext.sharedDirectory).replace("p_apiDirectory", appContext.apiDirectory).replace("p_lambdaDirectory", appContext.lambdaDirectory);
|
55
|
-
return entryCode;
|
56
|
-
}
|
139
|
+
};
|
57
140
|
// Annotate the CommonJS export names for ESM import in node:
|
58
141
|
0 && (module.exports = {
|
59
|
-
|
142
|
+
createVercelPreset
|
60
143
|
});
|
@@ -34,7 +34,8 @@ __export(utils_exports, {
|
|
34
34
|
getPluginsCode: () => getPluginsCode,
|
35
35
|
getProjectUsage: () => getProjectUsage,
|
36
36
|
linkPackage: () => linkPackage,
|
37
|
-
|
37
|
+
readDirRecursive: () => readDirRecursive,
|
38
|
+
serverAppContenxtTemplate: () => serverAppContenxtTemplate,
|
38
39
|
writePackage: () => writePackage
|
39
40
|
});
|
40
41
|
module.exports = __toCommonJS(utils_exports);
|
@@ -42,12 +43,14 @@ var import_path = __toESM(require("path"));
|
|
42
43
|
var import_node_os = __toESM(require("node:os"));
|
43
44
|
var import_utils = require("@modern-js/utils");
|
44
45
|
var import_mlly = require("mlly");
|
45
|
-
const
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
const serverAppContenxtTemplate = (appContext) => {
|
47
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
|
48
|
+
return {
|
49
|
+
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
50
|
+
apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
|
51
|
+
lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
|
52
|
+
metaName
|
53
|
+
};
|
51
54
|
};
|
52
55
|
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
53
56
|
const genPluginImportsCode = (plugins) => {
|
@@ -137,6 +140,16 @@ const linkPackage = async (from, to, projectRootDir) => {
|
|
137
140
|
console.error("Cannot link", from, "to", to, error);
|
138
141
|
});
|
139
142
|
};
|
143
|
+
const readDirRecursive = async (dir) => {
|
144
|
+
const files = await import_utils.fs.readdir(dir, {
|
145
|
+
withFileTypes: true
|
146
|
+
});
|
147
|
+
const filesAndDirs = await Promise.all(files.map(async (file) => {
|
148
|
+
const resPath = import_path.default.resolve(dir, file.name);
|
149
|
+
return file.isDirectory() ? readDirRecursive(resPath) : resPath;
|
150
|
+
}));
|
151
|
+
return filesAndDirs.flat();
|
152
|
+
};
|
140
153
|
// Annotate the CommonJS export names for ESM import in node:
|
141
154
|
0 && (module.exports = {
|
142
155
|
applyProductionCondition,
|
@@ -145,6 +158,7 @@ const linkPackage = async (from, to, projectRootDir) => {
|
|
145
158
|
getPluginsCode,
|
146
159
|
getProjectUsage,
|
147
160
|
linkPackage,
|
148
|
-
|
161
|
+
readDirRecursive,
|
162
|
+
serverAppContenxtTemplate,
|
149
163
|
writePackage
|
150
164
|
});
|
@@ -8,52 +8,7 @@ import { nodeFileTrace, resolve } from "@vercel/nft";
|
|
8
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
|
-
import { linkPackage, writePackage } from "./utils";
|
12
|
-
var readDirRecursive = function() {
|
13
|
-
var _ref = _async_to_generator(function(dir) {
|
14
|
-
var files, filesAndDirs;
|
15
|
-
return _ts_generator(this, function(_state) {
|
16
|
-
switch (_state.label) {
|
17
|
-
case 0:
|
18
|
-
return [
|
19
|
-
4,
|
20
|
-
fse.readdir(dir, {
|
21
|
-
withFileTypes: true
|
22
|
-
})
|
23
|
-
];
|
24
|
-
case 1:
|
25
|
-
files = _state.sent();
|
26
|
-
return [
|
27
|
-
4,
|
28
|
-
Promise.all(files.map(function() {
|
29
|
-
var _ref2 = _async_to_generator(function(file) {
|
30
|
-
var resPath;
|
31
|
-
return _ts_generator(this, function(_state2) {
|
32
|
-
resPath = path.resolve(dir, file.name);
|
33
|
-
return [
|
34
|
-
2,
|
35
|
-
file.isDirectory() ? readDirRecursive(resPath) : resPath
|
36
|
-
];
|
37
|
-
});
|
38
|
-
});
|
39
|
-
return function(file) {
|
40
|
-
return _ref2.apply(this, arguments);
|
41
|
-
};
|
42
|
-
}()))
|
43
|
-
];
|
44
|
-
case 2:
|
45
|
-
filesAndDirs = _state.sent();
|
46
|
-
return [
|
47
|
-
2,
|
48
|
-
filesAndDirs.flat()
|
49
|
-
];
|
50
|
-
}
|
51
|
-
});
|
52
|
-
});
|
53
|
-
return function readDirRecursive2(dir) {
|
54
|
-
return _ref.apply(this, arguments);
|
55
|
-
};
|
56
|
-
}();
|
11
|
+
import { linkPackage, readDirRecursive, writePackage } from "./utils";
|
57
12
|
function isFile(file) {
|
58
13
|
return _isFile.apply(this, arguments);
|
59
14
|
}
|