@modern-js/app-tools 2.49.1 → 2.49.3-alpha.0

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 (47) hide show
  1. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  2. package/dist/cjs/config/default.js +11 -1
  3. package/dist/cjs/index.js +4 -2
  4. package/dist/cjs/locale/en.js +2 -1
  5. package/dist/cjs/locale/zh.js +2 -1
  6. package/dist/cjs/plugins/deploy/dependencies.js +256 -0
  7. package/dist/cjs/plugins/deploy/entrys/netlify.js +95 -0
  8. package/dist/cjs/plugins/deploy/entrys/node.js +88 -0
  9. package/dist/cjs/plugins/deploy/entrys/vercel.js +94 -0
  10. package/dist/cjs/plugins/deploy/index.js +186 -0
  11. package/dist/cjs/plugins/deploy/utils.js +150 -0
  12. package/dist/cjs/utils/register.js +1 -1
  13. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  14. package/dist/esm/config/default.js +11 -1
  15. package/dist/esm/index.js +4 -2
  16. package/dist/esm/locale/en.js +2 -1
  17. package/dist/esm/locale/zh.js +2 -1
  18. package/dist/esm/plugins/deploy/dependencies.js +725 -0
  19. package/dist/esm/plugins/deploy/entrys/netlify.js +41 -0
  20. package/dist/esm/plugins/deploy/entrys/node.js +39 -0
  21. package/dist/esm/plugins/deploy/entrys/vercel.js +40 -0
  22. package/dist/esm/plugins/deploy/index.js +297 -0
  23. package/dist/esm/plugins/deploy/utils.js +244 -0
  24. package/dist/esm/utils/register.js +1 -1
  25. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  26. package/dist/esm-node/config/default.js +11 -1
  27. package/dist/esm-node/index.js +4 -2
  28. package/dist/esm-node/locale/en.js +2 -1
  29. package/dist/esm-node/locale/zh.js +2 -1
  30. package/dist/esm-node/plugins/deploy/dependencies.js +222 -0
  31. package/dist/esm-node/plugins/deploy/entrys/netlify.js +71 -0
  32. package/dist/esm-node/plugins/deploy/entrys/node.js +64 -0
  33. package/dist/esm-node/plugins/deploy/entrys/vercel.js +70 -0
  34. package/dist/esm-node/plugins/deploy/index.js +156 -0
  35. package/dist/esm-node/plugins/deploy/utils.js +109 -0
  36. package/dist/esm-node/utils/register.js +1 -1
  37. package/dist/types/locale/en.d.ts +1 -0
  38. package/dist/types/locale/index.d.ts +2 -0
  39. package/dist/types/locale/zh.d.ts +1 -0
  40. package/dist/types/plugins/deploy/dependencies.d.ts +1 -0
  41. package/dist/types/plugins/deploy/entrys/netlify.d.ts +5 -0
  42. package/dist/types/plugins/deploy/entrys/node.d.ts +5 -0
  43. package/dist/types/plugins/deploy/entrys/vercel.d.ts +5 -0
  44. package/dist/types/plugins/deploy/index.d.ts +4 -0
  45. package/dist/types/plugins/deploy/utils.d.ts +27 -0
  46. package/dist/types/utils/types.d.ts +1 -0
  47. package/package.json +26 -22
@@ -0,0 +1,109 @@
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
+ };
@@ -40,7 +40,7 @@ const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
40
40
  transpileOnly: true,
41
41
  ignore: [
42
42
  "(?:^|/)node_modules/",
43
- `(?:^|/)${distDir}/`
43
+ `(?:^|/)${path.relative(appDir, distDir)}/`
44
44
  ],
45
45
  ...tsNodeOptions
46
46
  });
@@ -22,6 +22,7 @@ export declare const EN_LOCALE: {
22
22
  };
23
23
  deploy: {
24
24
  describe: string;
25
+ output: string;
25
26
  };
26
27
  new: {
27
28
  describe: string;
@@ -24,6 +24,7 @@ declare const localeKeys: {
24
24
  };
25
25
  deploy: {
26
26
  describe: string;
27
+ output: string;
27
28
  };
28
29
  new: {
29
30
  describe: string;
@@ -63,6 +64,7 @@ declare const localeKeys: {
63
64
  };
64
65
  deploy: {
65
66
  describe: string;
67
+ output: string;
66
68
  };
67
69
  new: {
68
70
  describe: string;
@@ -22,6 +22,7 @@ export declare const ZH_LOCALE: {
22
22
  };
23
23
  deploy: {
24
24
  describe: string;
25
+ output: string;
25
26
  };
26
27
  new: {
27
28
  describe: string;
@@ -0,0 +1 @@
1
+ export declare const handleDependencies: (appDir: string, serverRootDir: string, include: string[]) => Promise<void>;
@@ -0,0 +1,5 @@
1
+ export declare function genNetlifyEntry({ config, plugins, appContext, }?: {
2
+ config?: Record<string, any>;
3
+ plugins?: string[];
4
+ appContext?: Record<string, any>;
5
+ }): string;
@@ -0,0 +1,5 @@
1
+ export declare function genNodeEntry({ config, plugins, appContext, }?: {
2
+ config?: Record<string, any>;
3
+ plugins?: string[];
4
+ appContext?: Record<string, any>;
5
+ }): string;
@@ -0,0 +1,5 @@
1
+ export declare function genVercelEntry({ config, plugins, appContext, }?: {
2
+ config?: Record<string, any>;
3
+ plugins?: string[];
4
+ appContext?: Record<string, any>;
5
+ }): string;
@@ -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;
@@ -0,0 +1,27 @@
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>;
@@ -10,6 +10,7 @@ export type BuildOptions = {
10
10
  };
11
11
  export type DeployOptions = {
12
12
  config?: string;
13
+ output?: string;
13
14
  skipBuild?: boolean;
14
15
  };
15
16
  export type StartOptions = {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.1",
18
+ "version": "2.49.3-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -69,30 +69,34 @@
69
69
  "@babel/parser": "^7.22.15",
70
70
  "@babel/traverse": "^7.23.2",
71
71
  "@babel/types": "^7.23.0",
72
- "@rsbuild/plugin-node-polyfill": "0.6.6",
73
- "@rsbuild/shared": "0.6.6",
74
- "@rsbuild/core": "0.6.6",
72
+ "@rsbuild/plugin-node-polyfill": "0.6.10",
73
+ "@rsbuild/shared": "0.6.10",
74
+ "@rsbuild/core": "0.6.10",
75
+ "@swc/helpers": "0.5.3",
76
+ "@vercel/nft": "^0.26.4",
75
77
  "es-module-lexer": "^1.1.0",
76
78
  "esbuild": "0.17.19",
77
- "@swc/helpers": "0.5.3",
78
79
  "esbuild-register": "^3.5.0",
79
- "@modern-js/core": "2.49.1",
80
- "@modern-js/node-bundle-require": "2.49.1",
81
- "@modern-js/plugin": "2.49.1",
82
- "@modern-js/plugin-data-loader": "2.49.1",
83
- "@modern-js/plugin-i18n": "2.49.1",
84
- "@modern-js/prod-server": "2.49.1",
85
- "@modern-js/plugin-lint": "2.49.1",
86
- "@modern-js/server-utils": "2.49.1",
87
- "@modern-js/server-core": "2.49.1",
88
- "@modern-js/server": "2.49.1",
89
- "@modern-js/types": "2.49.1",
90
- "@modern-js/utils": "2.49.1",
91
- "@modern-js/uni-builder": "2.49.1",
92
- "@modern-js/rsbuild-plugin-esbuild": "2.49.1"
80
+ "mlly": "^1.6.1",
81
+ "pkg-types": "^1.1.0",
82
+ "std-env": "^3.7.0",
83
+ "@modern-js/node-bundle-require": "2.49.2",
84
+ "@modern-js/plugin": "2.49.2",
85
+ "@modern-js/plugin-data-loader": "2.49.2",
86
+ "@modern-js/plugin-i18n": "2.49.2",
87
+ "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
88
+ "@modern-js/plugin-lint": "2.49.2",
89
+ "@modern-js/server-utils": "2.49.2",
90
+ "@modern-js/server": "2.49.2",
91
+ "@modern-js/types": "2.49.2",
92
+ "@modern-js/core": "2.49.2",
93
+ "@modern-js/server-core": "2.49.2",
94
+ "@modern-js/utils": "2.49.2",
95
+ "@modern-js/uni-builder": "2.49.2",
96
+ "@modern-js/prod-server": "2.49.2"
93
97
  },
94
98
  "devDependencies": {
95
- "@rsbuild/plugin-swc": "0.6.6",
99
+ "@rsbuild/plugin-swc": "0.6.10",
96
100
  "@types/babel__traverse": "7.18.5",
97
101
  "@types/jest": "^29",
98
102
  "@types/node": "^14",
@@ -101,8 +105,8 @@
101
105
  "tsconfig-paths": "^4.2.0",
102
106
  "typescript": "^5",
103
107
  "webpack": "^5.91.0",
104
- "@scripts/build": "2.49.1",
105
- "@scripts/jest-config": "2.49.1"
108
+ "@scripts/build": "2.49.2",
109
+ "@scripts/jest-config": "2.49.2"
106
110
  },
107
111
  "sideEffects": false,
108
112
  "publishConfig": {