@modern-js/app-tools 2.49.0 → 2.49.1-alpha.1

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 (32) hide show
  1. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  2. package/dist/cjs/index.js +3 -1
  3. package/dist/cjs/plugins/deploy/dependencies.js +257 -0
  4. package/dist/cjs/plugins/deploy/entrys/netlify.js +95 -0
  5. package/dist/cjs/plugins/deploy/entrys/node.js +88 -0
  6. package/dist/cjs/plugins/deploy/entrys/vercel.js +95 -0
  7. package/dist/cjs/plugins/deploy/index.js +140 -0
  8. package/dist/cjs/plugins/deploy/utils.js +150 -0
  9. package/dist/esm/builder/builder-webpack/index.js +1 -1
  10. package/dist/esm/index.js +3 -1
  11. package/dist/esm/plugins/deploy/dependencies.js +726 -0
  12. package/dist/esm/plugins/deploy/entrys/netlify.js +41 -0
  13. package/dist/esm/plugins/deploy/entrys/node.js +39 -0
  14. package/dist/esm/plugins/deploy/entrys/vercel.js +41 -0
  15. package/dist/esm/plugins/deploy/index.js +219 -0
  16. package/dist/esm/plugins/deploy/utils.js +244 -0
  17. package/dist/esm-node/builder/builder-webpack/index.js +1 -1
  18. package/dist/esm-node/index.js +3 -1
  19. package/dist/esm-node/plugins/deploy/dependencies.js +223 -0
  20. package/dist/esm-node/plugins/deploy/entrys/netlify.js +71 -0
  21. package/dist/esm-node/plugins/deploy/entrys/node.js +64 -0
  22. package/dist/esm-node/plugins/deploy/entrys/vercel.js +71 -0
  23. package/dist/esm-node/plugins/deploy/index.js +110 -0
  24. package/dist/esm-node/plugins/deploy/utils.js +109 -0
  25. package/dist/types/plugins/deploy/dependencies.d.ts +1 -0
  26. package/dist/types/plugins/deploy/entrys/netlify.d.ts +5 -0
  27. package/dist/types/plugins/deploy/entrys/node.d.ts +5 -0
  28. package/dist/types/plugins/deploy/entrys/vercel.d.ts +5 -0
  29. package/dist/types/plugins/deploy/index.d.ts +4 -0
  30. package/dist/types/plugins/deploy/utils.d.ts +27 -0
  31. package/dist/types/types/config/tools.d.ts +1 -1
  32. package/package.json +17 -14
@@ -0,0 +1,140 @@
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_utils2 = require("./utils");
37
+ var import_dependencies = require("./dependencies");
38
+ var deploy_default = () => ({
39
+ name: "@modern-js/plugin-deploy",
40
+ pre: [
41
+ "@modern-js/plugin-bff",
42
+ "@modern-js/plugin-server"
43
+ ],
44
+ setup: (api) => {
45
+ return {
46
+ async beforeDeploy() {
47
+ const deployTarget = process.env.MODERNJS_DEPLOY || "node";
48
+ const appContext = api.useAppContext();
49
+ const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
50
+ const configContext = api.useResolvedConfigContext();
51
+ const outputDirectory = import_path.default.join(appDirectory, ".output");
52
+ let funcsDirectory = outputDirectory;
53
+ let staticDirectory = import_path.default.join(outputDirectory, "static");
54
+ await import_utils.fs.remove(outputDirectory);
55
+ if (deployTarget === "node") {
56
+ await import_utils.fs.copy(distDirectory, outputDirectory, {
57
+ filter: (src) => {
58
+ const distStaticDirectory = import_path.default.join(distDirectory, "static");
59
+ return !src.includes(distStaticDirectory);
60
+ }
61
+ });
62
+ }
63
+ if (deployTarget === "vercel") {
64
+ funcsDirectory = import_path.default.join(outputDirectory, "functions");
65
+ staticDirectory = import_path.default.join(outputDirectory, "static");
66
+ await import_utils.fs.copy(distDirectory, funcsDirectory, {
67
+ filter: (src) => {
68
+ const distStaticDirectory = import_path.default.join(distDirectory, "static");
69
+ return !src.includes(distStaticDirectory);
70
+ }
71
+ });
72
+ await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
73
+ await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
74
+ runtime: "nodejs16.x",
75
+ handler: "index.js",
76
+ launcherType: "Nodejs",
77
+ shouldAddHelpers: false,
78
+ supportsResponseStreaming: true
79
+ });
80
+ }
81
+ const { bff } = configContext;
82
+ const config = {
83
+ output: {
84
+ path: "."
85
+ },
86
+ bff
87
+ };
88
+ const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
89
+ const serverAppContext = {
90
+ sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
91
+ apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
92
+ lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
93
+ metaName
94
+ };
95
+ let code = ``;
96
+ console.log("deployTarget111111111", deployTarget);
97
+ switch (deployTarget) {
98
+ case "node": {
99
+ const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/node")));
100
+ code = genNodeEntry({
101
+ plugins,
102
+ config,
103
+ appContext: serverAppContext
104
+ });
105
+ break;
106
+ }
107
+ case "vercel": {
108
+ const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/vercel")));
109
+ code = genVercelEntry({
110
+ plugins,
111
+ config,
112
+ appContext: serverAppContext
113
+ });
114
+ break;
115
+ }
116
+ case "netlify": {
117
+ const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/netlify")));
118
+ code = genNetlifyEntry({
119
+ plugins,
120
+ config,
121
+ appContext: serverAppContext
122
+ });
123
+ break;
124
+ }
125
+ default: {
126
+ code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
127
+ }
128
+ }
129
+ const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
130
+ const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
131
+ if (useSSR || useAPI || useWebServer) {
132
+ await import_utils.fs.writeFile(entryFilePath, code);
133
+ }
134
+ await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
135
+ "@modern-js/prod-server"
136
+ ]);
137
+ }
138
+ };
139
+ }
140
+ });
@@ -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
+ });
@@ -26,7 +26,7 @@ function _createWebpackBuilderForModern() {
26
26
  _normalizedConfig_tools = normalizedConfig.tools, esbuildOptions = _normalizedConfig_tools.esbuild;
27
27
  return [
28
28
  4,
29
- import("@rsbuild/plugin-esbuild")
29
+ import("@modern-js/rsbuild-plugin-esbuild")
30
30
  ];
31
31
  case 2:
32
32
  pluginEsbuild = _state.sent().pluginEsbuild;
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();