@modern-js/app-tools 2.49.3-alpha.13 → 2.49.3-alpha.15

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.
Files changed (29) hide show
  1. package/dist/cjs/plugins/deploy/index copy.js +216 -0
  2. package/dist/cjs/plugins/deploy/index.js +13 -169
  3. package/dist/cjs/plugins/deploy/platforms/netlify.js +112 -64
  4. package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
  5. package/dist/cjs/plugins/deploy/platforms/node.js +41 -18
  6. package/dist/cjs/plugins/deploy/platforms/vercel.js +103 -16
  7. package/dist/cjs/plugins/deploy/utils.js +10 -8
  8. package/dist/esm/plugins/deploy/index copy.js +367 -0
  9. package/dist/esm/plugins/deploy/index.js +17 -314
  10. package/dist/esm/plugins/deploy/platforms/netlify.js +203 -36
  11. package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
  12. package/dist/esm/plugins/deploy/platforms/node.js +100 -43
  13. package/dist/esm/plugins/deploy/platforms/vercel.js +203 -40
  14. package/dist/esm/plugins/deploy/utils.js +9 -3
  15. package/dist/esm-node/plugins/deploy/index copy.js +186 -0
  16. package/dist/esm-node/plugins/deploy/index.js +11 -157
  17. package/dist/esm-node/plugins/deploy/platforms/netlify.js +103 -65
  18. package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
  19. package/dist/esm-node/plugins/deploy/platforms/node.js +42 -19
  20. package/dist/esm-node/plugins/deploy/platforms/vercel.js +104 -17
  21. package/dist/esm-node/plugins/deploy/utils.js +9 -7
  22. package/dist/types/plugins/deploy/index copy.d.ts +4 -0
  23. package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -5
  24. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
  25. package/dist/types/plugins/deploy/platforms/node.d.ts +2 -8
  26. package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -4
  27. package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -8
  28. package/dist/types/plugins/deploy/utils.d.ts +7 -1
  29. package/package.json +8 -8
@@ -1,25 +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
- async function genNodeEntry({ config, plugins, appContext }) {
5
- const defaultConfig = {
6
- server: {
7
- port: 8080
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);
8
13
  },
9
- output: {
10
- path: "."
14
+ async writeOutput() {
15
+ await fse.copy(distDirectory, outputDirectory);
16
+ },
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
+ ]);
11
43
  }
12
44
  };
13
- const pluginImportCode = genPluginImportsCode(plugins || []);
14
- const dynamicProdOptions = {
15
- config: config || defaultConfig,
16
- serverConfigFile: DEFAULT_SERVER_CONFIG,
17
- plugins
18
- };
19
- let entryCode = (await fse.readFile(path.join(__dirname, "./nodeEntry.js"))).toString();
20
- 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);
21
- return entryCode;
22
- }
45
+ };
23
46
  export {
24
- genNodeEntry
47
+ createNodePreset
25
48
  };
@@ -1,22 +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 { genPluginImportsCode } from "../utils";
4
- async function genVercelEntry({ config, plugins, appContext }) {
5
- const defaultConfig = {
6
- output: {
7
- 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 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);
16
+ },
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
+ ]);
8
104
  }
9
105
  };
10
- const pluginImportCode = genPluginImportsCode(plugins || []);
11
- const dynamicProdOptions = {
12
- config: config || defaultConfig,
13
- serverConfigFile: DEFAULT_SERVER_CONFIG,
14
- plugins
15
- };
16
- let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
17
- 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);
18
- return entryCode;
19
- }
106
+ };
20
107
  export {
21
- genVercelEntry
108
+ createVercelPreset
22
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 severAppContextTemplate = (serverAppContext) => {
6
- return `{
7
- sharedDirectory: ${serverAppContext.sharedDirectory},
8
- apiDirectory: ${serverAppContext.apiDirectory},
9
- lambdaDirectory: ${serverAppContext.lambdaDirectory},
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
- severAppContextTemplate,
109
+ serverAppContenxtTemplate,
108
110
  writePackage
109
111
  };
@@ -0,0 +1,4 @@
1
+ import { CliPlugin } from '@modern-js/core';
2
+ import { AppTools } from '../../types';
3
+ declare const _default: () => CliPlugin<AppTools>;
4
+ export default _default;
@@ -1,5 +1,2 @@
1
- export declare function genNetlifyEntry({ config, plugins, appContext, }?: {
2
- config?: Record<string, any>;
3
- plugins?: string[];
4
- appContext?: Record<string, any>;
5
- }): string;
1
+ import { CreatePreset } from './platform';
2
+ export declare const createNetlifyPreset: CreatePreset;
@@ -0,0 +1,2 @@
1
+ declare function _exports(request: any, context: any): Promise<any>;
2
+ export = _exports;
@@ -1,8 +1,2 @@
1
- import { NormalizedConfig } from '@modern-js/core';
2
- import { AppTools } from '../../../types';
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
- export type AppContext = {
2
- sharedDirectory: string;
3
- apiDirectory: string;
4
- lambdaDirectory: string;
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 { NormalizedConfig } from '@modern-js/core';
2
- import { AppTools } from '../../../types';
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 severAppContextTemplate: (serverAppContext: ServerAppContext) => string;
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.13",
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",
@@ -80,20 +80,20 @@
80
80
  "mlly": "^1.6.1",
81
81
  "pkg-types": "^1.1.0",
82
82
  "std-env": "^3.7.0",
83
- "@modern-js/node-bundle-require": "2.49.2",
84
- "@modern-js/plugin-data-loader": "2.49.2",
85
83
  "@modern-js/core": "2.49.2",
84
+ "@modern-js/plugin": "2.49.2",
85
+ "@modern-js/prod-server": "2.49.2",
86
+ "@modern-js/node-bundle-require": "2.49.2",
86
87
  "@modern-js/plugin-i18n": "2.49.2",
87
88
  "@modern-js/plugin-lint": "2.49.2",
88
- "@modern-js/prod-server": "2.49.2",
89
89
  "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
90
- "@modern-js/plugin": "2.49.2",
91
- "@modern-js/server": "2.49.2",
92
90
  "@modern-js/server-core": "2.49.2",
93
- "@modern-js/uni-builder": "2.49.2",
91
+ "@modern-js/server": "2.49.2",
94
92
  "@modern-js/server-utils": "2.49.2",
93
+ "@modern-js/uni-builder": "2.49.2",
94
+ "@modern-js/utils": "2.49.2",
95
95
  "@modern-js/types": "2.49.2",
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",