@modern-js/app-tools 2.49.2 → 2.49.3-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) 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 +3 -1
  4. package/dist/cjs/plugins/deploy/dependencies.js +256 -0
  5. package/dist/cjs/plugins/deploy/entrys/netlify.js +95 -0
  6. package/dist/cjs/plugins/deploy/entrys/node.js +88 -0
  7. package/dist/cjs/plugins/deploy/entrys/vercel.js +97 -0
  8. package/dist/cjs/plugins/deploy/index.js +186 -0
  9. package/dist/cjs/plugins/deploy/utils.js +150 -0
  10. package/dist/cjs/utils/register.js +1 -1
  11. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  12. package/dist/esm/config/default.js +11 -1
  13. package/dist/esm/index.js +3 -1
  14. package/dist/esm/plugins/deploy/dependencies.js +725 -0
  15. package/dist/esm/plugins/deploy/entrys/netlify.js +41 -0
  16. package/dist/esm/plugins/deploy/entrys/node.js +39 -0
  17. package/dist/esm/plugins/deploy/entrys/vercel.js +43 -0
  18. package/dist/esm/plugins/deploy/index.js +312 -0
  19. package/dist/esm/plugins/deploy/utils.js +244 -0
  20. package/dist/esm/utils/register.js +1 -1
  21. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  22. package/dist/esm-node/config/default.js +11 -1
  23. package/dist/esm-node/index.js +3 -1
  24. package/dist/esm-node/plugins/deploy/dependencies.js +222 -0
  25. package/dist/esm-node/plugins/deploy/entrys/netlify.js +71 -0
  26. package/dist/esm-node/plugins/deploy/entrys/node.js +64 -0
  27. package/dist/esm-node/plugins/deploy/entrys/vercel.js +73 -0
  28. package/dist/esm-node/plugins/deploy/index.js +156 -0
  29. package/dist/esm-node/plugins/deploy/utils.js +109 -0
  30. package/dist/esm-node/utils/register.js +1 -1
  31. package/dist/types/plugins/deploy/dependencies.d.ts +1 -0
  32. package/dist/types/plugins/deploy/entrys/netlify.d.ts +5 -0
  33. package/dist/types/plugins/deploy/entrys/node.d.ts +5 -0
  34. package/dist/types/plugins/deploy/entrys/vercel.d.ts +6 -0
  35. package/dist/types/plugins/deploy/index.d.ts +4 -0
  36. package/dist/types/plugins/deploy/utils.d.ts +27 -0
  37. package/package.json +18 -14
@@ -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() {
49
+ const appContext = api.useAppContext();
50
+ const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
51
+ const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
52
+ const needModernServer = useSSR || useAPI || useWebServer;
53
+ const configContext = api.useResolvedConfigContext();
54
+ let outputDirectory = import_path.default.join(appDirectory, ".output");
55
+ let funcsDirectory = outputDirectory;
56
+ let staticDirectory = import_path.default.join(outputDirectory, "static");
57
+ if (deployTarget === "node") {
58
+ await import_utils.fs.remove(outputDirectory);
59
+ await import_utils.fs.copy(distDirectory, outputDirectory);
60
+ }
61
+ if (deployTarget === "vercel") {
62
+ const vercelOutput = import_path.default.join(appDirectory, ".vercel");
63
+ await import_utils.fs.remove(vercelOutput);
64
+ outputDirectory = import_path.default.join(vercelOutput, "output");
65
+ const config2 = {
66
+ version: 3,
67
+ routes: [
68
+ {
69
+ src: "/static/(.*)",
70
+ headers: {
71
+ "cache-control": "s-maxage=31536000, immutable"
72
+ },
73
+ continue: true
74
+ },
75
+ {
76
+ handle: "filesystem"
77
+ }
78
+ ]
79
+ };
80
+ if (!needModernServer) {
81
+ entrypoints.forEach((entry) => {
82
+ config2.routes.push({
83
+ src: `/${entry.entryName}(?:/.*)?`,
84
+ headers: {
85
+ "cache-control": "s-maxage=0"
86
+ },
87
+ dest: `/html/${entry.entryName}/index.html`
88
+ });
89
+ });
90
+ } else {
91
+ config2.routes.push({
92
+ src: "/(.*)",
93
+ dest: `/index`
94
+ });
95
+ }
96
+ await import_utils.fs.ensureDir(outputDirectory);
97
+ await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config2, {
98
+ spaces: 2
99
+ });
100
+ staticDirectory = import_path.default.join(outputDirectory, "static/static");
101
+ await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
102
+ if (!needModernServer) {
103
+ const destHtmlDirectory = import_path.default.join(distDirectory, "html");
104
+ const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
105
+ await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
106
+ } else {
107
+ funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
108
+ await import_utils.fs.ensureDir(funcsDirectory);
109
+ await import_utils.fs.copy(distDirectory, funcsDirectory, {
110
+ filter: (src) => {
111
+ const distStaticDirectory = import_path.default.join(distDirectory, "static");
112
+ return !src.includes(distStaticDirectory);
113
+ }
114
+ });
115
+ const apiDirectory2 = import_path.default.join(funcsDirectory, "api");
116
+ if (await import_utils.fs.pathExists(apiDirectory2)) {
117
+ await import_utils.fs.rename(apiDirectory2, import_path.default.join(funcsDirectory, "_api"));
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();