@modern-js/app-tools 2.49.3-alpha.14 → 2.49.3-alpha.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/index copy.js +216 -0
- package/dist/cjs/plugins/deploy/index.js +13 -169
- 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 +40 -21
- package/dist/cjs/plugins/deploy/platforms/vercel.js +102 -19
- package/dist/cjs/plugins/deploy/utils.js +10 -8
- package/dist/esm/plugins/deploy/index copy.js +367 -0
- package/dist/esm/plugins/deploy/index.js +17 -314
- 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 +100 -46
- package/dist/esm/plugins/deploy/platforms/vercel.js +203 -43
- package/dist/esm/plugins/deploy/utils.js +9 -3
- package/dist/esm-node/plugins/deploy/index copy.js +186 -0
- package/dist/esm-node/plugins/deploy/index.js +11 -157
- 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 +41 -22
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +103 -20
- package/dist/esm-node/plugins/deploy/utils.js +9 -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 +7 -1
- package/package.json +7 -7
@@ -1,29 +1,48 @@
|
|
1
1
|
import path from "node:path";
|
2
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
3
|
-
import { genPluginImportsCode } from "../utils";
|
4
|
-
|
5
|
-
|
6
|
-
const
|
7
|
-
|
8
|
-
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
|
3
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
4
|
+
import { handleDependencies } from "../dependencies";
|
5
|
+
const createNodePreset = (appContext, config) => {
|
6
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
7
|
+
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
8
|
+
const outputDirectory = path.join(appDirectory, ".output");
|
9
|
+
const entryFilePath = path.join(outputDirectory, "index.js");
|
10
|
+
return {
|
11
|
+
async prepare() {
|
12
|
+
await fse.remove(outputDirectory);
|
9
13
|
},
|
10
|
-
|
11
|
-
|
14
|
+
async writeOutput() {
|
15
|
+
await fse.copy(distDirectory, outputDirectory);
|
12
16
|
},
|
13
|
-
|
14
|
-
|
17
|
+
async genEntry() {
|
18
|
+
var _config_bff;
|
19
|
+
const serverConfig = {
|
20
|
+
server: {
|
21
|
+
port: 8080
|
22
|
+
},
|
23
|
+
bff: {
|
24
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
25
|
+
},
|
26
|
+
output: {
|
27
|
+
path: "."
|
28
|
+
}
|
29
|
+
};
|
30
|
+
const pluginImportCode = genPluginImportsCode(plugins || []);
|
31
|
+
const dynamicProdOptions = {
|
32
|
+
config: serverConfig,
|
33
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
34
|
+
plugins
|
35
|
+
};
|
36
|
+
let entryCode = (await fse.readFile(path.join(__dirname, "./nodeEntry.js"))).toString();
|
37
|
+
const serverAppContext = serverAppContenxtTemplate(appContext);
|
38
|
+
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);
|
39
|
+
await fse.writeFile(entryFilePath, entryCode);
|
40
|
+
await handleDependencies(appDirectory, outputDirectory, [
|
41
|
+
"@modern-js/prod-server"
|
42
|
+
]);
|
15
43
|
}
|
16
44
|
};
|
17
|
-
|
18
|
-
const dynamicProdOptions = {
|
19
|
-
config: serverConfig,
|
20
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
21
|
-
plugins
|
22
|
-
};
|
23
|
-
let entryCode = (await fse.readFile(path.join(__dirname, "./nodeEntry.js"))).toString();
|
24
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", appContext.sharedDirectory).replace("p_apiDirectory", appContext.apiDirectory).replace("p_lambdaDirectory", appContext.lambdaDirectory);
|
25
|
-
return entryCode;
|
26
|
-
}
|
45
|
+
};
|
27
46
|
export {
|
28
|
-
|
47
|
+
createNodePreset
|
29
48
|
};
|
@@ -1,26 +1,109 @@
|
|
1
1
|
import path from "node:path";
|
2
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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 createVercelPreset = (appContext, config, needModernServer) => {
|
7
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
8
|
+
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
9
|
+
const vercelOutput = path.join(appDirectory, ".vercel");
|
10
|
+
const outputDirectory = path.join(vercelOutput, "output");
|
11
|
+
const funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
12
|
+
const entryFilePath = path.join(funcsDirectory, "index.js");
|
13
|
+
return {
|
14
|
+
async prepare() {
|
15
|
+
await fse.remove(vercelOutput);
|
9
16
|
},
|
10
|
-
|
11
|
-
|
17
|
+
async writeOutput() {
|
18
|
+
const config2 = {
|
19
|
+
version: 3,
|
20
|
+
routes: [
|
21
|
+
{
|
22
|
+
src: "/static/(.*)",
|
23
|
+
headers: {
|
24
|
+
"cache-control": "s-maxage=31536000, immutable"
|
25
|
+
},
|
26
|
+
continue: true
|
27
|
+
},
|
28
|
+
{
|
29
|
+
handle: "filesystem"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
};
|
33
|
+
if (!needModernServer) {
|
34
|
+
const { source: { mainEntryName } } = config2;
|
35
|
+
entrypoints.forEach((entry) => {
|
36
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
37
|
+
config2.routes.push({
|
38
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
39
|
+
headers: {
|
40
|
+
"cache-control": "s-maxage=0"
|
41
|
+
},
|
42
|
+
dest: `/html/${entry.entryName}/index.html`
|
43
|
+
});
|
44
|
+
});
|
45
|
+
} else {
|
46
|
+
config2.routes.push({
|
47
|
+
src: "/(.*)",
|
48
|
+
dest: `/index`
|
49
|
+
});
|
50
|
+
}
|
51
|
+
await fse.ensureDir(outputDirectory);
|
52
|
+
await fse.writeJSON(path.join(outputDirectory, "config.json"), config2, {
|
53
|
+
spaces: 2
|
54
|
+
});
|
55
|
+
const staticDirectory = path.join(outputDirectory, "static/static");
|
56
|
+
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
57
|
+
if (!needModernServer) {
|
58
|
+
const destHtmlDirectory = path.join(distDirectory, "html");
|
59
|
+
const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
60
|
+
await fse.copy(destHtmlDirectory, outputHtmlDirectory);
|
61
|
+
} else {
|
62
|
+
await fse.ensureDir(funcsDirectory);
|
63
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
64
|
+
filter: (src) => {
|
65
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
66
|
+
return !src.includes(distStaticDirectory);
|
67
|
+
}
|
68
|
+
});
|
69
|
+
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
70
|
+
runtime: "nodejs16.x",
|
71
|
+
handler: "index.js",
|
72
|
+
launcherType: "Nodejs",
|
73
|
+
shouldAddHelpers: false,
|
74
|
+
supportsResponseStreaming: true
|
75
|
+
});
|
76
|
+
}
|
77
|
+
},
|
78
|
+
async genEntry() {
|
79
|
+
var _config_bff;
|
80
|
+
if (!needModernServer) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
const serverConfig = {
|
84
|
+
bff: {
|
85
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
86
|
+
},
|
87
|
+
output: {
|
88
|
+
path: "."
|
89
|
+
}
|
90
|
+
};
|
91
|
+
const pluginImportCode = genPluginImportsCode(plugins || []);
|
92
|
+
const dynamicProdOptions = {
|
93
|
+
config: serverConfig,
|
94
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
95
|
+
plugins
|
96
|
+
};
|
97
|
+
const serverAppContext = serverAppContenxtTemplate(appContext);
|
98
|
+
let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
|
99
|
+
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);
|
100
|
+
await fse.writeFile(entryFilePath, entryCode);
|
101
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
102
|
+
"@modern-js/prod-server"
|
103
|
+
]);
|
12
104
|
}
|
13
105
|
};
|
14
|
-
|
15
|
-
const dynamicProdOptions = {
|
16
|
-
config: serverConfig,
|
17
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
18
|
-
plugins
|
19
|
-
};
|
20
|
-
let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
|
21
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", appContext.sharedDirectory).replace("p_apiDirectory", appContext.apiDirectory).replace("p_lambdaDirectory", appContext.lambdaDirectory);
|
22
|
-
return entryCode;
|
23
|
-
}
|
106
|
+
};
|
24
107
|
export {
|
25
|
-
|
108
|
+
createVercelPreset
|
26
109
|
};
|
@@ -2,12 +2,14 @@ import path from "path";
|
|
2
2
|
import os from "node:os";
|
3
3
|
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
4
4
|
import { parseNodeModulePath } from "mlly";
|
5
|
-
const
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
const serverAppContenxtTemplate = (appContext) => {
|
6
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
|
7
|
+
return {
|
8
|
+
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
9
|
+
apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
|
10
|
+
lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
|
11
|
+
metaName
|
12
|
+
};
|
11
13
|
};
|
12
14
|
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
13
15
|
const genPluginImportsCode = (plugins) => {
|
@@ -104,6 +106,6 @@ export {
|
|
104
106
|
getPluginsCode,
|
105
107
|
getProjectUsage,
|
106
108
|
linkPackage,
|
107
|
-
|
109
|
+
serverAppContenxtTemplate,
|
108
110
|
writePackage
|
109
111
|
};
|
@@ -1,5 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
plugins?: string[];
|
4
|
-
appContext?: Record<string, any>;
|
5
|
-
}): string;
|
1
|
+
import { CreatePreset } from './platform';
|
2
|
+
export declare const createNetlifyPreset: CreatePreset;
|
@@ -1,8 +1,2 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
import { AppContext } from './platform';
|
4
|
-
export declare function genNodeEntry({ config, plugins, appContext, }: {
|
5
|
-
config?: NormalizedConfig<AppTools>;
|
6
|
-
plugins?: string[];
|
7
|
-
appContext: AppContext;
|
8
|
-
}): Promise<string>;
|
1
|
+
import { CreatePreset } from './platform';
|
2
|
+
export declare const createNodePreset: CreatePreset;
|
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import { IAppContext, NormalizedConfig } from '@modern-js/core';
|
2
|
+
import { AppTools } from '../../../types';
|
3
|
+
export type CreatePreset = (appContext: IAppContext, config: NormalizedConfig<AppTools>, needModernServer?: boolean) => DeployPreset;
|
4
|
+
type DeployPreset = {
|
5
|
+
prepare: () => Promise<void>;
|
6
|
+
writeOutput: () => Promise<void>;
|
7
|
+
genEntry: () => Promise<void>;
|
5
8
|
};
|
9
|
+
export {};
|
@@ -1,8 +1,2 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
import { AppContext } from './platform';
|
4
|
-
export declare function genVercelEntry({ config, plugins, appContext, }: {
|
5
|
-
config?: NormalizedConfig<AppTools>;
|
6
|
-
plugins?: string[];
|
7
|
-
appContext: AppContext;
|
8
|
-
}): Promise<string>;
|
1
|
+
import { CreatePreset } from './platform';
|
2
|
+
export declare const createVercelPreset: CreatePreset;
|
@@ -1,11 +1,17 @@
|
|
1
1
|
import type { PackageJson } from 'pkg-types';
|
2
|
+
import { IAppContext } from '@modern-js/core';
|
2
3
|
export type ServerAppContext = {
|
3
4
|
sharedDirectory: string;
|
4
5
|
apiDirectory: string;
|
5
6
|
lambdaDirectory: string;
|
6
7
|
metaName: string;
|
7
8
|
};
|
8
|
-
export declare const
|
9
|
+
export declare const serverAppContenxtTemplate: (appContext: IAppContext) => {
|
10
|
+
sharedDirectory: string;
|
11
|
+
apiDirectory: string;
|
12
|
+
lambdaDirectory: string;
|
13
|
+
metaName: string;
|
14
|
+
};
|
9
15
|
export declare const getPluginsCode: (plugins: string[]) => string;
|
10
16
|
export declare const genPluginImportsCode: (plugins: string[]) => string;
|
11
17
|
export declare const getProjectUsage: (appDirectory: string, distDirectory: string) => {
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.49.3-alpha.
|
18
|
+
"version": "2.49.3-alpha.15",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -81,19 +81,19 @@
|
|
81
81
|
"pkg-types": "^1.1.0",
|
82
82
|
"std-env": "^3.7.0",
|
83
83
|
"@modern-js/core": "2.49.2",
|
84
|
-
"@modern-js/node-bundle-require": "2.49.2",
|
85
84
|
"@modern-js/plugin": "2.49.2",
|
86
|
-
"@modern-js/plugin-data-loader": "2.49.2",
|
87
|
-
"@modern-js/plugin-lint": "2.49.2",
|
88
|
-
"@modern-js/plugin-i18n": "2.49.2",
|
89
85
|
"@modern-js/prod-server": "2.49.2",
|
86
|
+
"@modern-js/node-bundle-require": "2.49.2",
|
87
|
+
"@modern-js/plugin-i18n": "2.49.2",
|
88
|
+
"@modern-js/plugin-lint": "2.49.2",
|
90
89
|
"@modern-js/rsbuild-plugin-esbuild": "2.49.2",
|
91
90
|
"@modern-js/server-core": "2.49.2",
|
91
|
+
"@modern-js/server": "2.49.2",
|
92
92
|
"@modern-js/server-utils": "2.49.2",
|
93
93
|
"@modern-js/uni-builder": "2.49.2",
|
94
|
+
"@modern-js/utils": "2.49.2",
|
94
95
|
"@modern-js/types": "2.49.2",
|
95
|
-
"@modern-js/
|
96
|
-
"@modern-js/utils": "2.49.2"
|
96
|
+
"@modern-js/plugin-data-loader": "2.49.2"
|
97
97
|
},
|
98
98
|
"devDependencies": {
|
99
99
|
"@rsbuild/plugin-swc": "0.6.10",
|