@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,186 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var deploy_exports = {};
30
+ __export(deploy_exports, {
31
+ default: () => deploy_default
32
+ });
33
+ module.exports = __toCommonJS(deploy_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ var import_std_env = require("std-env");
37
+ var import_utils2 = require("./utils");
38
+ var import_dependencies = require("./dependencies");
39
+ var deploy_default = () => ({
40
+ name: "@modern-js/plugin-deploy",
41
+ pre: [
42
+ "@modern-js/plugin-bff",
43
+ "@modern-js/plugin-server"
44
+ ],
45
+ setup: (api) => {
46
+ const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
47
+ return {
48
+ async beforeDeploy(options) {
49
+ const { output: outputPath } = options;
50
+ const appContext = api.useAppContext();
51
+ const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
52
+ const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
53
+ const needModernServer = useSSR || useAPI || useWebServer;
54
+ const configContext = api.useResolvedConfigContext();
55
+ let outputDirectory = import_path.default.resolve(appDirectory, ".output");
56
+ if (outputPath) {
57
+ outputDirectory = import_path.default.isAbsolute(outputPath) ? outputPath : import_path.default.resolve(outputPath);
58
+ }
59
+ let funcsDirectory = outputDirectory;
60
+ let staticDirectory = import_path.default.join(outputDirectory, "static");
61
+ if (deployTarget === "node") {
62
+ await import_utils.fs.remove(outputDirectory);
63
+ await import_utils.fs.copy(distDirectory, outputDirectory);
64
+ }
65
+ if (deployTarget === "vercel") {
66
+ const vercelOutput = import_path.default.join(appDirectory, ".vercel");
67
+ await import_utils.fs.remove(vercelOutput);
68
+ outputDirectory = import_path.default.join(vercelOutput, "output");
69
+ const config2 = {
70
+ version: 3,
71
+ routes: [
72
+ {
73
+ src: "/static/(.*)",
74
+ headers: {
75
+ "cache-control": "s-maxage=31536000, immutable"
76
+ },
77
+ continue: true
78
+ },
79
+ {
80
+ handle: "filesystem"
81
+ }
82
+ ]
83
+ };
84
+ if (!needModernServer) {
85
+ entrypoints.forEach((entry) => {
86
+ config2.routes.push({
87
+ src: `/${entry.entryName}(?:/.*)?`,
88
+ headers: {
89
+ "cache-control": "s-maxage=0"
90
+ },
91
+ dest: `/html/${entry.entryName}/index.html`
92
+ });
93
+ });
94
+ } else {
95
+ config2.routes.push({
96
+ src: "/(.*)",
97
+ dest: `/index`
98
+ });
99
+ }
100
+ await import_utils.fs.ensureDir(outputDirectory);
101
+ await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config2, {
102
+ spaces: 2
103
+ });
104
+ staticDirectory = import_path.default.join(outputDirectory, "static/static");
105
+ await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
106
+ if (!needModernServer) {
107
+ const destHtmlDirectory = import_path.default.join(distDirectory, "html");
108
+ const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
109
+ await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
110
+ } else {
111
+ funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
112
+ await import_utils.fs.ensureDir(funcsDirectory);
113
+ await import_utils.fs.copy(distDirectory, funcsDirectory, {
114
+ filter: (src) => {
115
+ const distStaticDirectory = import_path.default.join(distDirectory, "static");
116
+ return !src.includes(distStaticDirectory);
117
+ }
118
+ });
119
+ await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
120
+ runtime: "nodejs16.x",
121
+ handler: "index.js",
122
+ launcherType: "Nodejs",
123
+ shouldAddHelpers: false,
124
+ supportsResponseStreaming: true
125
+ });
126
+ }
127
+ }
128
+ const { bff } = configContext;
129
+ const config = {
130
+ output: {
131
+ path: "."
132
+ },
133
+ bff
134
+ };
135
+ const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
136
+ const serverAppContext = {
137
+ sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
138
+ apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
139
+ lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
140
+ metaName
141
+ };
142
+ let code = ``;
143
+ console.log("deployTarget111111111", deployTarget);
144
+ switch (deployTarget) {
145
+ case "node": {
146
+ const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/node")));
147
+ code = genNodeEntry({
148
+ plugins,
149
+ config,
150
+ appContext: serverAppContext
151
+ });
152
+ break;
153
+ }
154
+ case "vercel": {
155
+ const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/vercel")));
156
+ code = genVercelEntry({
157
+ plugins,
158
+ config,
159
+ appContext: serverAppContext
160
+ });
161
+ break;
162
+ }
163
+ case "netlify": {
164
+ const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/netlify")));
165
+ code = genNetlifyEntry({
166
+ plugins,
167
+ config,
168
+ appContext: serverAppContext
169
+ });
170
+ break;
171
+ }
172
+ default: {
173
+ code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
174
+ }
175
+ }
176
+ const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
177
+ if (needModernServer) {
178
+ await import_utils.fs.writeFile(entryFilePath, code);
179
+ await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
180
+ "@modern-js/prod-server"
181
+ ]);
182
+ }
183
+ }
184
+ };
185
+ }
186
+ });
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var utils_exports = {};
30
+ __export(utils_exports, {
31
+ applyProductionCondition: () => applyProductionCondition,
32
+ applyPublicCondition: () => applyPublicCondition,
33
+ genPluginImportsCode: () => genPluginImportsCode,
34
+ getPluginsCode: () => getPluginsCode,
35
+ getProjectUsage: () => getProjectUsage,
36
+ linkPackage: () => linkPackage,
37
+ severAppContextTemplate: () => severAppContextTemplate,
38
+ writePackage: () => writePackage
39
+ });
40
+ module.exports = __toCommonJS(utils_exports);
41
+ var import_path = __toESM(require("path"));
42
+ var import_node_os = __toESM(require("node:os"));
43
+ var import_utils = require("@modern-js/utils");
44
+ var import_mlly = require("mlly");
45
+ const severAppContextTemplate = (serverAppContext) => {
46
+ return `{
47
+ sharedDirectory: ${serverAppContext.sharedDirectory},
48
+ apiDirectory: ${serverAppContext.apiDirectory},
49
+ lambdaDirectory: ${serverAppContext.lambdaDirectory},
50
+ }`;
51
+ };
52
+ const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
53
+ const genPluginImportsCode = (plugins) => {
54
+ return plugins.map((plugin, index) => `
55
+ let plugin_${index} = require('${plugin}')
56
+ plugin_${index} = plugin_${index}.default || plugin_${index}
57
+ `).join(";\n");
58
+ };
59
+ const getProjectUsage = (appDirectory, distDirectory) => {
60
+ const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
61
+ const { routes } = import_utils.fs.readJSONSync(routeJSON);
62
+ let useSSR = false;
63
+ let useAPI = false;
64
+ routes.forEach((route) => {
65
+ if (route.isSSR) {
66
+ useSSR = true;
67
+ }
68
+ if (route.isApi) {
69
+ useAPI = true;
70
+ }
71
+ });
72
+ const useWebServer = (0, import_utils.isDepExists)(appDirectory, "@modern-js/plugin-server");
73
+ return {
74
+ useSSR,
75
+ useAPI,
76
+ useWebServer
77
+ };
78
+ };
79
+ function applyProductionCondition(exports) {
80
+ if (!exports || typeof exports === "string") {
81
+ return;
82
+ }
83
+ if (exports.production) {
84
+ if (typeof exports.production === "string") {
85
+ exports.default = exports.production;
86
+ } else {
87
+ Object.assign(exports, exports.production);
88
+ }
89
+ }
90
+ for (const key in exports) {
91
+ applyProductionCondition(exports[key]);
92
+ }
93
+ }
94
+ function applyPublicCondition(pkg) {
95
+ var _pkg_publishConfig;
96
+ if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
97
+ var _pkg_publishConfig1;
98
+ pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
99
+ }
100
+ }
101
+ const writePackage = async (pkg, version, projectDir, _pkgPath) => {
102
+ const pkgPath = _pkgPath || pkg.name;
103
+ for (const src of pkg.versions[version].files) {
104
+ if (src.includes("node_modules")) {
105
+ const { subpath } = (0, import_mlly.parseNodeModulePath)(src);
106
+ const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
107
+ const dirname = import_path.default.dirname(dest);
108
+ await import_utils.fs.ensureDir(dirname);
109
+ await import_utils.fs.copyFile(src, dest);
110
+ } else {
111
+ const subpath = import_path.default.relative(pkg.versions[version].path, src);
112
+ const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
113
+ const dirname = import_path.default.dirname(dest);
114
+ await import_utils.fs.ensureDir(dirname);
115
+ await import_utils.fs.copyFile(src, dest);
116
+ }
117
+ }
118
+ const { pkgJSON } = pkg.versions[version];
119
+ applyPublicCondition(pkgJSON);
120
+ const packageJsonPath = import_path.default.join(projectDir, "node_modules", pkgPath, "package.json");
121
+ await import_utils.fs.ensureDir(import_path.default.dirname(packageJsonPath));
122
+ await import_utils.fs.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
123
+ };
124
+ const isWindows = import_node_os.default.platform() === "win32";
125
+ const linkPackage = async (from, to, projectRootDir) => {
126
+ const src = import_path.default.join(projectRootDir, "node_modules", from);
127
+ const dest = import_path.default.join(projectRootDir, "node_modules", to);
128
+ const dstStat = await import_utils.fs.lstat(dest).catch(() => null);
129
+ const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
130
+ if (exists) {
131
+ return;
132
+ }
133
+ await import_utils.fs.mkdir(import_path.default.dirname(dest), {
134
+ recursive: true
135
+ });
136
+ await import_utils.fs.symlink(import_path.default.relative(import_path.default.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
137
+ console.error("Cannot link", from, "to", to, error);
138
+ });
139
+ };
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ applyProductionCondition,
143
+ applyPublicCondition,
144
+ genPluginImportsCode,
145
+ getPluginsCode,
146
+ getProjectUsage,
147
+ linkPackage,
148
+ severAppContextTemplate,
149
+ writePackage
150
+ });
@@ -73,7 +73,7 @@ const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
73
73
  transpileOnly: true,
74
74
  ignore: [
75
75
  "(?:^|/)node_modules/",
76
- `(?:^|/)${distDir}/`
76
+ `(?:^|/)${import_node_path.default.relative(appDir, distDir)}/`
77
77
  ],
78
78
  ...tsNodeOptions
79
79
  });
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import * as path from "path";
4
4
  import { isHtmlDisabled } from "@rsbuild/shared";
5
5
  import { mergeRsbuildConfig } from "@rsbuild/core";
6
- import { isSSR, fs } from "@modern-js/utils";
6
+ import { fs, isUseSSRBundle } from "@modern-js/utils";
7
7
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
8
8
  import { getServerCombinedModueFile } from "../../../analyze/utils";
9
9
  var builderPluginAdapterSSR = function(options) {
@@ -33,7 +33,7 @@ var builderPluginAdapterSSR = function(options) {
33
33
  builderConfig = api.getNormalizedConfig();
34
34
  normalizedConfig2 = options.normalizedConfig;
35
35
  applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
36
- if (!isSSR(normalizedConfig2))
36
+ if (!isUseSSRBundle(normalizedConfig2))
37
37
  return [
38
38
  3,
39
39
  2
@@ -70,7 +70,17 @@ function createDefaultConfig(appContext) {
70
70
  server,
71
71
  dev,
72
72
  html,
73
- tools: {},
73
+ tools: {
74
+ tsChecker: {
75
+ issue: {
76
+ exclude: [
77
+ {
78
+ file: "**/api/lambda/**/*"
79
+ }
80
+ ]
81
+ }
82
+ }
83
+ },
74
84
  plugins: [],
75
85
  builderPlugins: [],
76
86
  runtime: {},
package/dist/esm/index.js CHANGED
@@ -12,6 +12,7 @@ import initializePlugin from "./initialize";
12
12
  import { hooks } from "./hooks";
13
13
  import { i18n, localeKeys } from "./locale";
14
14
  import serverBuildPlugin from "./plugins/serverBuild";
15
+ import deployPlugin from "./plugins/deploy";
15
16
  import { restart } from "./utils/restart";
16
17
  import { generateWatchFiles } from "./utils/generateWatchFiles";
17
18
  import { mergeConfig } from "@modern-js/core";
@@ -295,7 +296,8 @@ var appTools = function() {
295
296
  bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
296
297
  }),
297
298
  serverBuildPlugin(),
298
- lintPlugin()
299
+ lintPlugin(),
300
+ deployPlugin()
299
301
  ],
300
302
  setup: function(api) {
301
303
  var appContext = api.useAppContext();
@@ -366,7 +368,7 @@ var appTools = function() {
366
368
  }
367
369
  });
368
370
  }));
369
- program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(function() {
371
+ program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).option("-o --output <path>", i18n.t(localeKeys.command.deploy.output)).description(i18n.t(localeKeys.command.deploy.describe)).action(function() {
370
372
  var _ref = _async_to_generator(function(options2) {
371
373
  var build, deploy;
372
374
  return _ts_generator(this, function(_state2) {
@@ -21,7 +21,8 @@ var EN_LOCALE = {
21
21
  describe: "preview the production build locally"
22
22
  },
23
23
  deploy: {
24
- describe: "deploy the application"
24
+ describe: "deploy the application",
25
+ output: "output path"
25
26
  },
26
27
  new: {
27
28
  describe: "enable optional features or add a new entry",
@@ -21,7 +21,8 @@ var ZH_LOCALE = {
21
21
  describe: "启动生产环境服务"
22
22
  },
23
23
  deploy: {
24
- describe: "部署应用"
24
+ describe: "部署应用",
25
+ output: "输出路径"
25
26
  },
26
27
  new: {
27
28
  describe: "Web App 项目中执行生成器",