@modern-js/app-tools 2.49.3-alpha.2 → 2.49.3-alpha.20

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 (58) hide show
  1. package/dist/cjs/analyze/getServerRoutes.js +4 -3
  2. package/dist/cjs/plugins/deploy/dependencies.js +1 -12
  3. package/dist/cjs/plugins/deploy/index.js +25 -147
  4. package/dist/cjs/plugins/deploy/platforms/netlify.js +120 -0
  5. package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
  6. package/dist/cjs/plugins/deploy/platforms/node.js +90 -0
  7. package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +41 -0
  8. package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
  9. package/dist/cjs/plugins/deploy/platforms/vercel.js +145 -0
  10. package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
  11. package/dist/cjs/plugins/deploy/utils.js +22 -8
  12. package/dist/cjs/utils/routes.js +7 -2
  13. package/dist/esm/analyze/getServerRoutes.js +5 -4
  14. package/dist/esm/plugins/deploy/dependencies.js +1 -47
  15. package/dist/esm/plugins/deploy/index.js +66 -245
  16. package/dist/esm/plugins/deploy/platforms/netlify.js +182 -0
  17. package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
  18. package/dist/esm/plugins/deploy/platforms/node.js +122 -0
  19. package/dist/esm/plugins/deploy/platforms/nodeEntry.js +104 -0
  20. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  21. package/dist/esm/plugins/deploy/platforms/vercel.js +220 -0
  22. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
  23. package/dist/esm/plugins/deploy/utils.js +55 -3
  24. package/dist/esm/utils/routes.js +6 -2
  25. package/dist/esm-node/analyze/getServerRoutes.js +5 -4
  26. package/dist/esm-node/plugins/deploy/dependencies.js +1 -12
  27. package/dist/esm-node/plugins/deploy/index.js +24 -136
  28. package/dist/esm-node/plugins/deploy/platforms/netlify.js +86 -0
  29. package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
  30. package/dist/esm-node/plugins/deploy/platforms/node.js +56 -0
  31. package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +40 -0
  32. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  33. package/dist/esm-node/plugins/deploy/platforms/vercel.js +111 -0
  34. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
  35. package/dist/esm-node/plugins/deploy/utils.js +20 -7
  36. package/dist/esm-node/utils/routes.js +6 -2
  37. package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -0
  38. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
  39. package/dist/types/plugins/deploy/platforms/node.d.ts +2 -0
  40. package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
  41. package/dist/types/plugins/deploy/platforms/platform.d.ts +10 -0
  42. package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -0
  43. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
  44. package/dist/types/plugins/deploy/utils.d.ts +8 -1
  45. package/dist/types/utils/routes.d.ts +3 -3
  46. package/package.json +21 -21
  47. package/dist/cjs/plugins/deploy/entrys/netlify.js +0 -95
  48. package/dist/cjs/plugins/deploy/entrys/node.js +0 -88
  49. package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -97
  50. package/dist/esm/plugins/deploy/entrys/netlify.js +0 -41
  51. package/dist/esm/plugins/deploy/entrys/node.js +0 -39
  52. package/dist/esm/plugins/deploy/entrys/vercel.js +0 -43
  53. package/dist/esm-node/plugins/deploy/entrys/netlify.js +0 -71
  54. package/dist/esm-node/plugins/deploy/entrys/node.js +0 -64
  55. package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -73
  56. package/dist/types/plugins/deploy/entrys/netlify.d.ts +0 -5
  57. package/dist/types/plugins/deploy/entrys/node.d.ts +0 -5
  58. package/dist/types/plugins/deploy/entrys/vercel.d.ts +0 -6
@@ -1,97 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var vercel_exports = {};
20
- __export(vercel_exports, {
21
- genVercelEntry: () => genVercelEntry
22
- });
23
- module.exports = __toCommonJS(vercel_exports);
24
- var import_utils = require("@modern-js/utils");
25
- var import_utils2 = require("../utils");
26
- function genVercelEntry({ config, plugins, appContext } = {}) {
27
- const defaultConfig = {
28
- server: {
29
- port: 8080
30
- },
31
- output: {
32
- path: "."
33
- }
34
- };
35
- if (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) {
36
- appContext.apiDirectory = appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory.replace(/\/api$/, "/_api");
37
- }
38
- return `
39
-
40
- const fs = require('node:fs/promises');
41
- const path = require('node:path');
42
- const { createProdServer } = require('@modern-js/prod-server');
43
- ${(0, import_utils2.genPluginImportsCode)(plugins || [])}
44
-
45
- if(!process.env.NODE_ENV){
46
- process.env.NODE_ENV = 'production';
47
- }
48
-
49
- let requestHandler = null;
50
- async function createHandler() {
51
- try {
52
- let routes = [];
53
- const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
54
- try {
55
- await fs.access(routeFilepath);
56
- const content = await fs.readFile(routeFilepath, "utf-8");
57
- const routeSpec = JSON.parse(content);
58
- routes = routeSpec.routes;
59
- } catch (error) {
60
- console.warn('route.json not found, continuing with empty routes.');
61
- }
62
-
63
- const prodServerOptions = {
64
- pwd: __dirname,
65
- routes,
66
- config: ${JSON.stringify(config || defaultConfig)},
67
- serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
68
- plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
69
- appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
70
- disableCustomHook: true
71
- }
72
-
73
- const app = await createProdServer(prodServerOptions)
74
-
75
- requestHandler = app.getRequestListener();
76
-
77
- return requestHandler;
78
- } catch(error) {
79
- console.error(error);
80
- process.exit(1);
81
- }
82
- }
83
-
84
- createHandler();
85
-
86
- module.exports = async(req, res) => {
87
- if(typeof requestHandler !== 'function'){
88
- await createHandler();
89
- }
90
- return requestHandler(req, res);
91
- }
92
- `;
93
- }
94
- // Annotate the CommonJS export names for ESM import in node:
95
- 0 && (module.exports = {
96
- genVercelEntry
97
- });
@@ -1,41 +0,0 @@
1
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
2
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
3
- function genNetlifyEntry() {
4
- var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
5
- var defaultConfig = {
6
- server: {
7
- port: 8080
8
- },
9
- output: {
10
- path: "."
11
- }
12
- };
13
- return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');\n ".concat(genPluginImportsCode(plugins || []), `
14
-
15
- let requestHandler = null;
16
-
17
- if(!process.env.NODE_ENV){
18
- process.env.NODE_ENV = 'production';
19
- }
20
-
21
- async function createHandler() {
22
- try {
23
- let routes = [];
24
- const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
25
- try {
26
- await fs.access(routeFilepath);
27
- const content = await fs.readFile(routeFilepath, "utf-8");
28
- const routeSpec = JSON.parse(content);
29
- routes = routeSpec.routes;
30
- } catch (error) {
31
- console.warn('route.json not found, continuing with empty routes.');
32
- }
33
-
34
- const prodServerOptions = {
35
- pwd: __dirname,
36
- routes,
37
- config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n requestHandler = await createNetlifyFunction(prodServerOptions)\n\n return requestHandler\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n const handleRequest = async(request, context) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(request, context);\n }\n\n export default handleRequest;\n ");
38
- }
39
- export {
40
- genNetlifyEntry
41
- };
@@ -1,39 +0,0 @@
1
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
2
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
3
- function genNodeEntry() {
4
- var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
5
- var defaultConfig = {
6
- server: {
7
- port: 8080
8
- },
9
- output: {
10
- path: "."
11
- }
12
- };
13
- return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createProdServer } = require('@modern-js/prod-server');\n ".concat(genPluginImportsCode(plugins || []), `
14
-
15
- if(!process.env.NODE_ENV){
16
- process.env.NODE_ENV = 'production';
17
- }
18
-
19
- async function main() {
20
- try {
21
- let routes = [];
22
- const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
23
- try {
24
- await fs.access(routeFilepath);
25
- const content = await fs.readFile(routeFilepath, "utf-8");
26
- const routeSpec = JSON.parse(content);
27
- routes = routeSpec.routes;
28
- } catch (error) {
29
- console.warn('route.json not found, continuing with empty routes.');
30
- }
31
-
32
- const prodServerOptions = {
33
- pwd: __dirname,
34
- routes,
35
- config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n const app = await createProdServer(prodServerOptions)\n\n const port = process.env.PORT || 3000;\n\n app.listen(port, () => {\n console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');\n });\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n main();\n ");
36
- }
37
- export {
38
- genNodeEntry
39
- };
@@ -1,43 +0,0 @@
1
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
2
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
3
- function genVercelEntry() {
4
- var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
5
- var defaultConfig = {
6
- server: {
7
- port: 8080
8
- },
9
- output: {
10
- path: "."
11
- }
12
- };
13
- if (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) {
14
- appContext.apiDirectory = appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory.replace(/\/api$/, "/_api");
15
- }
16
- return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createProdServer } = require('@modern-js/prod-server');\n ".concat(genPluginImportsCode(plugins || []), `
17
-
18
- if(!process.env.NODE_ENV){
19
- process.env.NODE_ENV = 'production';
20
- }
21
-
22
- let requestHandler = null;
23
- async function createHandler() {
24
- try {
25
- let routes = [];
26
- const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
27
- try {
28
- await fs.access(routeFilepath);
29
- const content = await fs.readFile(routeFilepath, "utf-8");
30
- const routeSpec = JSON.parse(content);
31
- routes = routeSpec.routes;
32
- } catch (error) {
33
- console.warn('route.json not found, continuing with empty routes.');
34
- }
35
-
36
- const prodServerOptions = {
37
- pwd: __dirname,
38
- routes,
39
- config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n const app = await createProdServer(prodServerOptions)\n\n requestHandler = app.getRequestListener();\n\n return requestHandler;\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n module.exports = async(req, res) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(req, res);\n }\n ");
40
- }
41
- export {
42
- genVercelEntry
43
- };
@@ -1,71 +0,0 @@
1
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
2
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
3
- function genNetlifyEntry({ config, plugins, appContext } = {}) {
4
- const defaultConfig = {
5
- server: {
6
- port: 8080
7
- },
8
- output: {
9
- path: "."
10
- }
11
- };
12
- return `
13
-
14
- const fs = require('node:fs/promises');
15
- const path = require('node:path');
16
- const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');
17
- ${genPluginImportsCode(plugins || [])}
18
-
19
- let requestHandler = null;
20
-
21
- if(!process.env.NODE_ENV){
22
- process.env.NODE_ENV = 'production';
23
- }
24
-
25
- async function createHandler() {
26
- try {
27
- let routes = [];
28
- const routeFilepath = path.join(__dirname, "${ROUTE_SPEC_FILE}");
29
- try {
30
- await fs.access(routeFilepath);
31
- const content = await fs.readFile(routeFilepath, "utf-8");
32
- const routeSpec = JSON.parse(content);
33
- routes = routeSpec.routes;
34
- } catch (error) {
35
- console.warn('route.json not found, continuing with empty routes.');
36
- }
37
-
38
- const prodServerOptions = {
39
- pwd: __dirname,
40
- routes,
41
- config: ${JSON.stringify(config || defaultConfig)},
42
- serverConfigFile: '${DEFAULT_SERVER_CONFIG}',
43
- plugins: ${getPluginsCode(plugins || [])},
44
- appContext: ${appContext ? severAppContextTemplate(appContext) : "undefined"},
45
- disableCustomHook: true
46
- }
47
-
48
- requestHandler = await createNetlifyFunction(prodServerOptions)
49
-
50
- return requestHandler
51
- } catch(error) {
52
- console.error(error);
53
- process.exit(1);
54
- }
55
- }
56
-
57
- createHandler();
58
-
59
- const handleRequest = async(request, context) => {
60
- if(typeof requestHandler !== 'function'){
61
- await createHandler();
62
- }
63
- return requestHandler(request, context);
64
- }
65
-
66
- export default handleRequest;
67
- `;
68
- }
69
- export {
70
- genNetlifyEntry
71
- };
@@ -1,64 +0,0 @@
1
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
2
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
3
- function genNodeEntry({ config, plugins, appContext } = {}) {
4
- const defaultConfig = {
5
- server: {
6
- port: 8080
7
- },
8
- output: {
9
- path: "."
10
- }
11
- };
12
- return `
13
-
14
- const fs = require('node:fs/promises');
15
- const path = require('node:path');
16
- const { createProdServer } = require('@modern-js/prod-server');
17
- ${genPluginImportsCode(plugins || [])}
18
-
19
- if(!process.env.NODE_ENV){
20
- process.env.NODE_ENV = 'production';
21
- }
22
-
23
- async function main() {
24
- try {
25
- let routes = [];
26
- const routeFilepath = path.join(__dirname, "${ROUTE_SPEC_FILE}");
27
- try {
28
- await fs.access(routeFilepath);
29
- const content = await fs.readFile(routeFilepath, "utf-8");
30
- const routeSpec = JSON.parse(content);
31
- routes = routeSpec.routes;
32
- } catch (error) {
33
- console.warn('route.json not found, continuing with empty routes.');
34
- }
35
-
36
- const prodServerOptions = {
37
- pwd: __dirname,
38
- routes,
39
- config: ${JSON.stringify(config || defaultConfig)},
40
- serverConfigFile: '${DEFAULT_SERVER_CONFIG}',
41
- plugins: ${getPluginsCode(plugins || [])},
42
- appContext: ${appContext ? severAppContextTemplate(appContext) : "undefined"},
43
- disableCustomHook: true
44
- }
45
-
46
- const app = await createProdServer(prodServerOptions)
47
-
48
- const port = process.env.PORT || 3000;
49
-
50
- app.listen(port, () => {
51
- console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');
52
- });
53
- } catch(error) {
54
- console.error(error);
55
- process.exit(1);
56
- }
57
- }
58
-
59
- main();
60
- `;
61
- }
62
- export {
63
- genNodeEntry
64
- };
@@ -1,73 +0,0 @@
1
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
2
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
3
- function genVercelEntry({ config, plugins, appContext } = {}) {
4
- const defaultConfig = {
5
- server: {
6
- port: 8080
7
- },
8
- output: {
9
- path: "."
10
- }
11
- };
12
- if (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) {
13
- appContext.apiDirectory = appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory.replace(/\/api$/, "/_api");
14
- }
15
- return `
16
-
17
- const fs = require('node:fs/promises');
18
- const path = require('node:path');
19
- const { createProdServer } = require('@modern-js/prod-server');
20
- ${genPluginImportsCode(plugins || [])}
21
-
22
- if(!process.env.NODE_ENV){
23
- process.env.NODE_ENV = 'production';
24
- }
25
-
26
- let requestHandler = null;
27
- async function createHandler() {
28
- try {
29
- let routes = [];
30
- const routeFilepath = path.join(__dirname, "${ROUTE_SPEC_FILE}");
31
- try {
32
- await fs.access(routeFilepath);
33
- const content = await fs.readFile(routeFilepath, "utf-8");
34
- const routeSpec = JSON.parse(content);
35
- routes = routeSpec.routes;
36
- } catch (error) {
37
- console.warn('route.json not found, continuing with empty routes.');
38
- }
39
-
40
- const prodServerOptions = {
41
- pwd: __dirname,
42
- routes,
43
- config: ${JSON.stringify(config || defaultConfig)},
44
- serverConfigFile: '${DEFAULT_SERVER_CONFIG}',
45
- plugins: ${getPluginsCode(plugins || [])},
46
- appContext: ${appContext ? severAppContextTemplate(appContext) : "undefined"},
47
- disableCustomHook: true
48
- }
49
-
50
- const app = await createProdServer(prodServerOptions)
51
-
52
- requestHandler = app.getRequestListener();
53
-
54
- return requestHandler;
55
- } catch(error) {
56
- console.error(error);
57
- process.exit(1);
58
- }
59
- }
60
-
61
- createHandler();
62
-
63
- module.exports = async(req, res) => {
64
- if(typeof requestHandler !== 'function'){
65
- await createHandler();
66
- }
67
- return requestHandler(req, res);
68
- }
69
- `;
70
- }
71
- export {
72
- genVercelEntry
73
- };
@@ -1,5 +0,0 @@
1
- export declare function genNetlifyEntry({ config, plugins, appContext, }?: {
2
- config?: Record<string, any>;
3
- plugins?: string[];
4
- appContext?: Record<string, any>;
5
- }): string;
@@ -1,5 +0,0 @@
1
- export declare function genNodeEntry({ config, plugins, appContext, }?: {
2
- config?: Record<string, any>;
3
- plugins?: string[];
4
- appContext?: Record<string, any>;
5
- }): string;
@@ -1,6 +0,0 @@
1
- import { ServerAppContext } from '../utils';
2
- export declare function genVercelEntry({ config, plugins, appContext, }?: {
3
- config?: Record<string, any>;
4
- plugins?: string[];
5
- appContext?: ServerAppContext;
6
- }): string;