@modern-js/app-tools 2.49.3-alpha.9 → 2.49.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/analyze/getServerRoutes.js +3 -4
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/utils/routes.js +2 -7
- package/dist/esm/analyze/getServerRoutes.js +4 -5
- package/dist/esm/index.js +1 -3
- package/dist/esm/utils/routes.js +2 -6
- package/dist/esm-node/analyze/getServerRoutes.js +4 -5
- package/dist/esm-node/index.js +1 -3
- package/dist/esm-node/utils/routes.js +2 -6
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +22 -26
- package/dist/cjs/plugins/deploy/dependencies.js +0 -256
- package/dist/cjs/plugins/deploy/index.js +0 -215
- package/dist/cjs/plugins/deploy/platforms/netlify.js +0 -95
- package/dist/cjs/plugins/deploy/platforms/node.js +0 -88
- package/dist/cjs/plugins/deploy/platforms/platform.js +0 -16
- package/dist/cjs/plugins/deploy/platforms/vercel.js +0 -57
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +0 -55
- package/dist/cjs/plugins/deploy/utils.js +0 -150
- package/dist/esm/plugins/deploy/dependencies.js +0 -725
- package/dist/esm/plugins/deploy/index.js +0 -356
- package/dist/esm/plugins/deploy/platforms/netlify.js +0 -41
- package/dist/esm/plugins/deploy/platforms/node.js +0 -39
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +0 -47
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -197
- package/dist/esm/plugins/deploy/utils.js +0 -244
- package/dist/esm-node/plugins/deploy/dependencies.js +0 -222
- package/dist/esm-node/plugins/deploy/index.js +0 -185
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -71
- package/dist/esm-node/plugins/deploy/platforms/node.js +0 -64
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -23
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -63
- package/dist/esm-node/plugins/deploy/utils.js +0 -109
- package/dist/types/plugins/deploy/dependencies.d.ts +0 -1
- package/dist/types/plugins/deploy/index.d.ts +0 -4
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +0 -5
- package/dist/types/plugins/deploy/platforms/node.d.ts +0 -5
- package/dist/types/plugins/deploy/platforms/platform.d.ts +0 -1
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +0 -5
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
- package/dist/types/plugins/deploy/utils.d.ts +0 -27
@@ -1,71 +0,0 @@
|
|
1
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
2
|
-
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
3
|
-
function genNetlifyEntry({ config, plugins, appContext } = {}) {
|
4
|
-
const defaultConfig = {
|
5
|
-
server: {
|
6
|
-
port: 8080
|
7
|
-
},
|
8
|
-
output: {
|
9
|
-
path: "."
|
10
|
-
}
|
11
|
-
};
|
12
|
-
return `
|
13
|
-
|
14
|
-
const fs = require('node:fs/promises');
|
15
|
-
const path = require('node:path');
|
16
|
-
const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');
|
17
|
-
${genPluginImportsCode(plugins || [])}
|
18
|
-
|
19
|
-
let requestHandler = null;
|
20
|
-
|
21
|
-
if(!process.env.NODE_ENV){
|
22
|
-
process.env.NODE_ENV = 'production';
|
23
|
-
}
|
24
|
-
|
25
|
-
async function createHandler() {
|
26
|
-
try {
|
27
|
-
let routes = [];
|
28
|
-
const routeFilepath = path.join(__dirname, "${ROUTE_SPEC_FILE}");
|
29
|
-
try {
|
30
|
-
await fs.access(routeFilepath);
|
31
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
32
|
-
const routeSpec = JSON.parse(content);
|
33
|
-
routes = routeSpec.routes;
|
34
|
-
} catch (error) {
|
35
|
-
console.warn('route.json not found, continuing with empty routes.');
|
36
|
-
}
|
37
|
-
|
38
|
-
const prodServerOptions = {
|
39
|
-
pwd: __dirname,
|
40
|
-
routes,
|
41
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
42
|
-
serverConfigFile: '${DEFAULT_SERVER_CONFIG}',
|
43
|
-
plugins: ${getPluginsCode(plugins || [])},
|
44
|
-
appContext: ${appContext ? severAppContextTemplate(appContext) : "undefined"},
|
45
|
-
disableCustomHook: true
|
46
|
-
}
|
47
|
-
|
48
|
-
requestHandler = await createNetlifyFunction(prodServerOptions)
|
49
|
-
|
50
|
-
return requestHandler
|
51
|
-
} catch(error) {
|
52
|
-
console.error(error);
|
53
|
-
process.exit(1);
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
createHandler();
|
58
|
-
|
59
|
-
const handleRequest = async(request, context) => {
|
60
|
-
if(typeof requestHandler !== 'function'){
|
61
|
-
await createHandler();
|
62
|
-
}
|
63
|
-
return requestHandler(request, context);
|
64
|
-
}
|
65
|
-
|
66
|
-
export default handleRequest;
|
67
|
-
`;
|
68
|
-
}
|
69
|
-
export {
|
70
|
-
genNetlifyEntry
|
71
|
-
};
|
@@ -1,64 +0,0 @@
|
|
1
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
2
|
-
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
3
|
-
function genNodeEntry({ config, plugins, appContext } = {}) {
|
4
|
-
const defaultConfig = {
|
5
|
-
server: {
|
6
|
-
port: 8080
|
7
|
-
},
|
8
|
-
output: {
|
9
|
-
path: "."
|
10
|
-
}
|
11
|
-
};
|
12
|
-
return `
|
13
|
-
|
14
|
-
const fs = require('node:fs/promises');
|
15
|
-
const path = require('node:path');
|
16
|
-
const { createProdServer } = require('@modern-js/prod-server');
|
17
|
-
${genPluginImportsCode(plugins || [])}
|
18
|
-
|
19
|
-
if(!process.env.NODE_ENV){
|
20
|
-
process.env.NODE_ENV = 'production';
|
21
|
-
}
|
22
|
-
|
23
|
-
async function main() {
|
24
|
-
try {
|
25
|
-
let routes = [];
|
26
|
-
const routeFilepath = path.join(__dirname, "${ROUTE_SPEC_FILE}");
|
27
|
-
try {
|
28
|
-
await fs.access(routeFilepath);
|
29
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
30
|
-
const routeSpec = JSON.parse(content);
|
31
|
-
routes = routeSpec.routes;
|
32
|
-
} catch (error) {
|
33
|
-
console.warn('route.json not found, continuing with empty routes.');
|
34
|
-
}
|
35
|
-
|
36
|
-
const prodServerOptions = {
|
37
|
-
pwd: __dirname,
|
38
|
-
routes,
|
39
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
40
|
-
serverConfigFile: '${DEFAULT_SERVER_CONFIG}',
|
41
|
-
plugins: ${getPluginsCode(plugins || [])},
|
42
|
-
appContext: ${appContext ? severAppContextTemplate(appContext) : "undefined"},
|
43
|
-
disableCustomHook: true
|
44
|
-
}
|
45
|
-
|
46
|
-
const app = await createProdServer(prodServerOptions)
|
47
|
-
|
48
|
-
const port = process.env.PORT || 3000;
|
49
|
-
|
50
|
-
app.listen(port, () => {
|
51
|
-
console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');
|
52
|
-
});
|
53
|
-
} catch(error) {
|
54
|
-
console.error(error);
|
55
|
-
process.exit(1);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
main();
|
60
|
-
`;
|
61
|
-
}
|
62
|
-
export {
|
63
|
-
genNodeEntry
|
64
|
-
};
|
File without changes
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import path from "node:path";
|
2
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
3
|
-
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
4
|
-
async function genVercelEntry({ config, plugins, appContext } = {}) {
|
5
|
-
const defaultConfig = {
|
6
|
-
output: {
|
7
|
-
path: "."
|
8
|
-
}
|
9
|
-
};
|
10
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
11
|
-
const dynamicProdOptions = {
|
12
|
-
config: `${JSON.stringify(config || defaultConfig)}`,
|
13
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
14
|
-
plugins: `${getPluginsCode(plugins || [])}`,
|
15
|
-
appContext: `${appContext ? severAppContextTemplate(appContext) : "undefined"}`
|
16
|
-
};
|
17
|
-
let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
|
18
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", ROUTE_SPEC_FILE).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions));
|
19
|
-
return entryCode;
|
20
|
-
}
|
21
|
-
export {
|
22
|
-
genVercelEntry
|
23
|
-
};
|
@@ -1,63 +0,0 @@
|
|
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
|
-
const fs = require("node:fs/promises");
|
8
|
-
const path = require("node:path");
|
9
|
-
const { createProdServer } = require("@modern-js/prod-server");
|
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
|
-
...dynamicProdOptions
|
36
|
-
};
|
37
|
-
const app = await createProdServer(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 (req, res) => {
|
56
|
-
if (!requestHandler) {
|
57
|
-
await createHandler();
|
58
|
-
}
|
59
|
-
return requestHandler(req, res);
|
60
|
-
};
|
61
|
-
}
|
62
|
-
});
|
63
|
-
export default require_vercelEntry();
|
@@ -1,109 +0,0 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import os from "node:os";
|
3
|
-
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
4
|
-
import { parseNodeModulePath } from "mlly";
|
5
|
-
const severAppContextTemplate = (serverAppContext) => {
|
6
|
-
return `{
|
7
|
-
sharedDirectory: ${serverAppContext.sharedDirectory},
|
8
|
-
apiDirectory: ${serverAppContext.apiDirectory},
|
9
|
-
lambdaDirectory: ${serverAppContext.lambdaDirectory},
|
10
|
-
}`;
|
11
|
-
};
|
12
|
-
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
13
|
-
const genPluginImportsCode = (plugins) => {
|
14
|
-
return plugins.map((plugin, index) => `
|
15
|
-
let plugin_${index} = require('${plugin}')
|
16
|
-
plugin_${index} = plugin_${index}.default || plugin_${index}
|
17
|
-
`).join(";\n");
|
18
|
-
};
|
19
|
-
const getProjectUsage = (appDirectory, distDirectory) => {
|
20
|
-
const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
21
|
-
const { routes } = fse.readJSONSync(routeJSON);
|
22
|
-
let useSSR = false;
|
23
|
-
let useAPI = false;
|
24
|
-
routes.forEach((route) => {
|
25
|
-
if (route.isSSR) {
|
26
|
-
useSSR = true;
|
27
|
-
}
|
28
|
-
if (route.isApi) {
|
29
|
-
useAPI = true;
|
30
|
-
}
|
31
|
-
});
|
32
|
-
const useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server");
|
33
|
-
return {
|
34
|
-
useSSR,
|
35
|
-
useAPI,
|
36
|
-
useWebServer
|
37
|
-
};
|
38
|
-
};
|
39
|
-
function applyProductionCondition(exports) {
|
40
|
-
if (!exports || typeof exports === "string") {
|
41
|
-
return;
|
42
|
-
}
|
43
|
-
if (exports.production) {
|
44
|
-
if (typeof exports.production === "string") {
|
45
|
-
exports.default = exports.production;
|
46
|
-
} else {
|
47
|
-
Object.assign(exports, exports.production);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
for (const key in exports) {
|
51
|
-
applyProductionCondition(exports[key]);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
function applyPublicCondition(pkg) {
|
55
|
-
var _pkg_publishConfig;
|
56
|
-
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
57
|
-
var _pkg_publishConfig1;
|
58
|
-
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
const writePackage = async (pkg, version, projectDir, _pkgPath) => {
|
62
|
-
const pkgPath = _pkgPath || pkg.name;
|
63
|
-
for (const src of pkg.versions[version].files) {
|
64
|
-
if (src.includes("node_modules")) {
|
65
|
-
const { subpath } = parseNodeModulePath(src);
|
66
|
-
const dest = path.join(projectDir, "node_modules", pkgPath, subpath);
|
67
|
-
const dirname = path.dirname(dest);
|
68
|
-
await fse.ensureDir(dirname);
|
69
|
-
await fse.copyFile(src, dest);
|
70
|
-
} else {
|
71
|
-
const subpath = path.relative(pkg.versions[version].path, src);
|
72
|
-
const dest = path.join(projectDir, "node_modules", pkgPath, subpath);
|
73
|
-
const dirname = path.dirname(dest);
|
74
|
-
await fse.ensureDir(dirname);
|
75
|
-
await fse.copyFile(src, dest);
|
76
|
-
}
|
77
|
-
}
|
78
|
-
const { pkgJSON } = pkg.versions[version];
|
79
|
-
applyPublicCondition(pkgJSON);
|
80
|
-
const packageJsonPath = path.join(projectDir, "node_modules", pkgPath, "package.json");
|
81
|
-
await fse.ensureDir(path.dirname(packageJsonPath));
|
82
|
-
await fse.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
|
83
|
-
};
|
84
|
-
const isWindows = os.platform() === "win32";
|
85
|
-
const linkPackage = async (from, to, projectRootDir) => {
|
86
|
-
const src = path.join(projectRootDir, "node_modules", from);
|
87
|
-
const dest = path.join(projectRootDir, "node_modules", to);
|
88
|
-
const dstStat = await fse.lstat(dest).catch(() => null);
|
89
|
-
const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
|
90
|
-
if (exists) {
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
await fse.mkdir(path.dirname(dest), {
|
94
|
-
recursive: true
|
95
|
-
});
|
96
|
-
await fse.symlink(path.relative(path.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
|
97
|
-
console.error("Cannot link", from, "to", to, error);
|
98
|
-
});
|
99
|
-
};
|
100
|
-
export {
|
101
|
-
applyProductionCondition,
|
102
|
-
applyPublicCondition,
|
103
|
-
genPluginImportsCode,
|
104
|
-
getPluginsCode,
|
105
|
-
getProjectUsage,
|
106
|
-
linkPackage,
|
107
|
-
severAppContextTemplate,
|
108
|
-
writePackage
|
109
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare const handleDependencies: (appDir: string, serverRootDir: string, include: string[]) => Promise<void>;
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import type { PackageJson } from 'pkg-types';
|
2
|
-
export type ServerAppContext = {
|
3
|
-
sharedDirectory: string;
|
4
|
-
apiDirectory: string;
|
5
|
-
lambdaDirectory: string;
|
6
|
-
metaName: string;
|
7
|
-
};
|
8
|
-
export declare const severAppContextTemplate: (serverAppContext: ServerAppContext) => string;
|
9
|
-
export declare const getPluginsCode: (plugins: string[]) => string;
|
10
|
-
export declare const genPluginImportsCode: (plugins: string[]) => string;
|
11
|
-
export declare const getProjectUsage: (appDirectory: string, distDirectory: string) => {
|
12
|
-
useSSR: boolean;
|
13
|
-
useAPI: boolean;
|
14
|
-
useWebServer: boolean;
|
15
|
-
};
|
16
|
-
export declare function applyProductionCondition(exports: PackageJson['exports']): void;
|
17
|
-
export declare function applyPublicCondition(pkg: PackageJson): void;
|
18
|
-
export type TracedPackage = {
|
19
|
-
name: string;
|
20
|
-
versions: Record<string, {
|
21
|
-
pkgJSON: PackageJson;
|
22
|
-
path: string;
|
23
|
-
files: string[];
|
24
|
-
}>;
|
25
|
-
};
|
26
|
-
export declare const writePackage: (pkg: TracedPackage, version: string, projectDir: string, _pkgPath?: string) => Promise<void>;
|
27
|
-
export declare const linkPackage: (from: string, to: string, projectRootDir: string) => Promise<void>;
|