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

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 (38) hide show
  1. package/dist/cjs/analyze/getServerRoutes.js +3 -4
  2. package/dist/cjs/plugins/deploy/entrys/vercel.js +97 -0
  3. package/dist/cjs/plugins/deploy/index.js +24 -53
  4. package/dist/cjs/utils/routes.js +2 -7
  5. package/dist/esm/analyze/getServerRoutes.js +4 -5
  6. package/dist/esm/plugins/deploy/entrys/vercel.js +43 -0
  7. package/dist/esm/plugins/deploy/index.js +74 -118
  8. package/dist/esm/utils/routes.js +2 -6
  9. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  10. package/dist/esm-node/plugins/deploy/entrys/vercel.js +73 -0
  11. package/dist/esm-node/plugins/deploy/index.js +24 -53
  12. package/dist/esm-node/utils/routes.js +2 -6
  13. package/dist/types/plugins/deploy/{platforms → entrys}/vercel.d.ts +3 -2
  14. package/dist/types/utils/routes.d.ts +3 -3
  15. package/package.json +8 -8
  16. package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +0 -36
  17. package/dist/cjs/plugins/deploy/platforms/platform.js +0 -16
  18. package/dist/cjs/plugins/deploy/platforms/vercel.js +0 -57
  19. package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +0 -55
  20. package/dist/esm/plugins/deploy/platforms/nodeEntry.js +0 -99
  21. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  22. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -47
  23. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -197
  24. package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +0 -35
  25. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  26. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -23
  27. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -63
  28. package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +0 -1
  29. package/dist/types/plugins/deploy/platforms/platform.d.ts +0 -1
  30. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  31. /package/dist/cjs/plugins/deploy/{platforms → entrys}/netlify.js +0 -0
  32. /package/dist/cjs/plugins/deploy/{platforms → entrys}/node.js +0 -0
  33. /package/dist/esm/plugins/deploy/{platforms → entrys}/netlify.js +0 -0
  34. /package/dist/esm/plugins/deploy/{platforms → entrys}/node.js +0 -0
  35. /package/dist/esm-node/plugins/deploy/{platforms → entrys}/netlify.js +0 -0
  36. /package/dist/esm-node/plugins/deploy/{platforms → entrys}/node.js +0 -0
  37. /package/dist/types/plugins/deploy/{platforms → entrys}/netlify.d.ts +0 -0
  38. /package/dist/types/plugins/deploy/{platforms → entrys}/node.d.ts +0 -0
@@ -1,4 +1,4 @@
1
1
  import type { IAppContext } from '@modern-js/core';
2
- export declare const generateRoutes: (appContext: IAppContext) => Promise<void>;
3
- export declare const getPathWithoutExt: (filename: string) => string;
4
- export declare const isMainEntry: (entryName: string, mainEntryName?: string) => boolean;
2
+ declare const generateRoutes: (appContext: IAppContext) => Promise<void>;
3
+ declare const getPathWithoutExt: (filename: string) => string;
4
+ export { generateRoutes, getPathWithoutExt };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.3-alpha.10",
18
+ "version": "2.49.3-alpha.2",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -81,19 +81,19 @@
81
81
  "pkg-types": "^1.1.0",
82
82
  "std-env": "^3.7.0",
83
83
  "@modern-js/core": "2.49.2",
84
- "@modern-js/plugin-data-loader": "2.49.2",
85
84
  "@modern-js/plugin": "2.49.2",
86
- "@modern-js/plugin-i18n": "2.49.2",
87
- "@modern-js/plugin-lint": "2.49.2",
85
+ "@modern-js/plugin-data-loader": "2.49.2",
88
86
  "@modern-js/prod-server": "2.49.2",
89
87
  "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
90
- "@modern-js/server-core": "2.49.2",
91
- "@modern-js/uni-builder": "2.49.2",
92
88
  "@modern-js/node-bundle-require": "2.49.2",
89
+ "@modern-js/plugin-i18n": "2.49.2",
90
+ "@modern-js/server-core": "2.49.2",
93
91
  "@modern-js/types": "2.49.2",
92
+ "@modern-js/uni-builder": "2.49.2",
93
+ "@modern-js/plugin-lint": "2.49.2",
94
94
  "@modern-js/utils": "2.49.2",
95
- "@modern-js/server": "2.49.2",
96
- "@modern-js/server-utils": "2.49.2"
95
+ "@modern-js/server-utils": "2.49.2",
96
+ "@modern-js/server": "2.49.2"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@rsbuild/plugin-swc": "0.6.10",
@@ -1,36 +0,0 @@
1
- "use strict";
2
- const fs = require("node:fs/promises");
3
- const path = require("node:path");
4
- const { createProdServer } = require("@modern-js/prod-server");
5
- p_genPluginImportsCode;
6
- if (!process.env.NODE_ENV) {
7
- process.env.NODE_ENV = "production";
8
- }
9
- async function loadRoutes(routeFilepath) {
10
- try {
11
- await fs.access(routeFilepath);
12
- const content = await fs.readFile(routeFilepath, "utf-8");
13
- const routeSpec = JSON.parse(content);
14
- return routeSpec.routes || [];
15
- } catch (error) {
16
- console.warn("route.json not found or invalid, continuing with empty routes.");
17
- return [];
18
- }
19
- }
20
- async function main() {
21
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
22
- const routes = await loadRoutes(routeFilepath);
23
- const dynamicProdOptions = p_dynamicProdOptions;
24
- const prodServerOptions = {
25
- pwd: __dirname,
26
- routes,
27
- disableCustomHook: true,
28
- ...dynamicProdOptions
29
- };
30
- const app = await createProdServer(prodServerOptions);
31
- const port = process.env.PORT || 8080;
32
- app.listen(port, () => {
33
- console.log("\\x1b[32mServer is listening on port", port, "\\x1b[0m");
34
- });
35
- }
36
- main();
@@ -1,16 +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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var platform_exports = {};
16
- module.exports = __toCommonJS(platform_exports);
@@ -1,57 +0,0 @@
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 vercel_exports = {};
30
- __export(vercel_exports, {
31
- genVercelEntry: () => genVercelEntry
32
- });
33
- module.exports = __toCommonJS(vercel_exports);
34
- var import_node_path = __toESM(require("node:path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_utils2 = require("../utils");
37
- async function genVercelEntry({ config, plugins, appContext } = {}) {
38
- const defaultConfig = {
39
- output: {
40
- path: "."
41
- }
42
- };
43
- const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
44
- const dynamicProdOptions = {
45
- config: `${JSON.stringify(config || defaultConfig)}`,
46
- serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
47
- plugins: `${(0, import_utils2.getPluginsCode)(plugins || [])}`,
48
- appContext: `${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"}`
49
- };
50
- let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
51
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions));
52
- return entryCode;
53
- }
54
- // Annotate the CommonJS export names for ESM import in node:
55
- 0 && (module.exports = {
56
- genVercelEntry
57
- });
@@ -1,55 +0,0 @@
1
- "use strict";
2
- const fs = require("node:fs/promises");
3
- const path = require("node:path");
4
- const { createProdServer } = require("@modern-js/prod-server");
5
- p_genPluginImportsCode;
6
- if (!process.env.NODE_ENV) {
7
- process.env.NODE_ENV = "production";
8
- }
9
- let requestHandler = null;
10
- let handlerCreationPromise = null;
11
- async function loadRoutes(routeFilepath) {
12
- try {
13
- await fs.access(routeFilepath);
14
- const content = await fs.readFile(routeFilepath, "utf-8");
15
- const routeSpec = JSON.parse(content);
16
- return routeSpec.routes || [];
17
- } catch (error) {
18
- console.warn("route.json not found or invalid, continuing with empty routes.");
19
- return [];
20
- }
21
- }
22
- async function initServer() {
23
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
24
- const routes = await loadRoutes(routeFilepath);
25
- const dynamicProdOptions = p_dynamicProdOptions;
26
- const prodServerOptions = {
27
- pwd: __dirname,
28
- routes,
29
- disableCustomHook: true,
30
- ...dynamicProdOptions
31
- };
32
- const app = await createProdServer(prodServerOptions);
33
- return app.getRequestListener();
34
- }
35
- async function createHandler() {
36
- if (!handlerCreationPromise) {
37
- handlerCreationPromise = (async () => {
38
- try {
39
- requestHandler = await initServer();
40
- } catch (error) {
41
- console.error("Error creating server:", error);
42
- process.exit(1);
43
- }
44
- })();
45
- }
46
- await handlerCreationPromise;
47
- return requestHandler;
48
- }
49
- createHandler();
50
- module.exports = async (req, res) => {
51
- if (!requestHandler) {
52
- await createHandler();
53
- }
54
- return requestHandler(req, res);
55
- };
@@ -1,99 +0,0 @@
1
- var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
2
- var _object_spread = require("@swc/helpers/_/_object_spread");
3
- var _ts_generator = require("@swc/helpers/_/_ts_generator");
4
- var fs = require("node:fs/promises");
5
- var path = require("node:path");
6
- var createProdServer = require("@modern-js/prod-server").createProdServer;
7
- p_genPluginImportsCode;
8
- if (!process.env.NODE_ENV) {
9
- process.env.NODE_ENV = "production";
10
- }
11
- function loadRoutes(routeFilepath) {
12
- return _loadRoutes.apply(this, arguments);
13
- }
14
- function _loadRoutes() {
15
- _loadRoutes = _async_to_generator._(function(routeFilepath) {
16
- var content, routeSpec, error;
17
- return _ts_generator._(this, function(_state) {
18
- switch (_state.label) {
19
- case 0:
20
- _state.trys.push([
21
- 0,
22
- 3,
23
- ,
24
- 4
25
- ]);
26
- return [
27
- 4,
28
- fs.access(routeFilepath)
29
- ];
30
- case 1:
31
- _state.sent();
32
- return [
33
- 4,
34
- fs.readFile(routeFilepath, "utf-8")
35
- ];
36
- case 2:
37
- content = _state.sent();
38
- routeSpec = JSON.parse(content);
39
- return [
40
- 2,
41
- routeSpec.routes || []
42
- ];
43
- case 3:
44
- error = _state.sent();
45
- console.warn("route.json not found or invalid, continuing with empty routes.");
46
- return [
47
- 2,
48
- []
49
- ];
50
- case 4:
51
- return [
52
- 2
53
- ];
54
- }
55
- });
56
- });
57
- return _loadRoutes.apply(this, arguments);
58
- }
59
- function main() {
60
- return _main.apply(this, arguments);
61
- }
62
- function _main() {
63
- _main = _async_to_generator._(function() {
64
- var routeFilepath, routes, dynamicProdOptions, prodServerOptions, app, port;
65
- return _ts_generator._(this, function(_state) {
66
- switch (_state.label) {
67
- case 0:
68
- routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
69
- return [
70
- 4,
71
- loadRoutes(routeFilepath)
72
- ];
73
- case 1:
74
- routes = _state.sent();
75
- dynamicProdOptions = p_dynamicProdOptions;
76
- prodServerOptions = _object_spread._({
77
- pwd: __dirname,
78
- routes,
79
- disableCustomHook: true
80
- }, dynamicProdOptions);
81
- return [
82
- 4,
83
- createProdServer(prodServerOptions)
84
- ];
85
- case 2:
86
- app = _state.sent();
87
- port = process.env.PORT || 8080;
88
- app.listen(port, function() {
89
- console.log("\\x1b[32mServer is listening on port", port, "\\x1b[0m");
90
- });
91
- return [
92
- 2
93
- ];
94
- }
95
- });
96
- });
97
- return _main.apply(this, arguments);
98
- }
99
- main();
File without changes
@@ -1,47 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import path from "node:path";
4
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
5
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
6
- function genVercelEntry() {
7
- return _genVercelEntry.apply(this, arguments);
8
- }
9
- function _genVercelEntry() {
10
- _genVercelEntry = _async_to_generator(function() {
11
- var _ref, config, plugins, appContext, defaultConfig, pluginImportCode, dynamicProdOptions, entryCode;
12
- var _arguments = arguments;
13
- return _ts_generator(this, function(_state) {
14
- switch (_state.label) {
15
- case 0:
16
- _ref = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
17
- defaultConfig = {
18
- output: {
19
- path: "."
20
- }
21
- };
22
- pluginImportCode = genPluginImportsCode(plugins || []);
23
- dynamicProdOptions = {
24
- config: "".concat(JSON.stringify(config || defaultConfig)),
25
- serverConfigFile: DEFAULT_SERVER_CONFIG,
26
- plugins: "".concat(getPluginsCode(plugins || [])),
27
- appContext: "".concat(appContext ? severAppContextTemplate(appContext) : "undefined")
28
- };
29
- return [
30
- 4,
31
- fse.readFile(path.join(__dirname, "./vercelEntry.js"))
32
- ];
33
- case 1:
34
- entryCode = _state.sent().toString();
35
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions));
36
- return [
37
- 2,
38
- entryCode
39
- ];
40
- }
41
- });
42
- });
43
- return _genVercelEntry.apply(this, arguments);
44
- }
45
- export {
46
- genVercelEntry
47
- };
@@ -1,197 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
- };
5
- var require_vercelEntry = __commonJS({
6
- "src/plugins/deploy/platforms/vercelEntry.js"(exports, module) {
7
- var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
8
- var _object_spread = require("@swc/helpers/_/_object_spread");
9
- var _ts_generator = require("@swc/helpers/_/_ts_generator");
10
- var fs = require("node:fs/promises");
11
- var path = require("node:path");
12
- var createProdServer = require("@modern-js/prod-server").createProdServer;
13
- p_genPluginImportsCode;
14
- if (!process.env.NODE_ENV) {
15
- process.env.NODE_ENV = "production";
16
- }
17
- var requestHandler = null;
18
- var handlerCreationPromise = null;
19
- function loadRoutes(routeFilepath) {
20
- return _loadRoutes.apply(this, arguments);
21
- }
22
- function _loadRoutes() {
23
- _loadRoutes = _async_to_generator._(function(routeFilepath) {
24
- var content, routeSpec, error;
25
- return _ts_generator._(this, function(_state) {
26
- switch (_state.label) {
27
- case 0:
28
- _state.trys.push([
29
- 0,
30
- 3,
31
- ,
32
- 4
33
- ]);
34
- return [
35
- 4,
36
- fs.access(routeFilepath)
37
- ];
38
- case 1:
39
- _state.sent();
40
- return [
41
- 4,
42
- fs.readFile(routeFilepath, "utf-8")
43
- ];
44
- case 2:
45
- content = _state.sent();
46
- routeSpec = JSON.parse(content);
47
- return [
48
- 2,
49
- routeSpec.routes || []
50
- ];
51
- case 3:
52
- error = _state.sent();
53
- console.warn("route.json not found or invalid, continuing with empty routes.");
54
- return [
55
- 2,
56
- []
57
- ];
58
- case 4:
59
- return [
60
- 2
61
- ];
62
- }
63
- });
64
- });
65
- return _loadRoutes.apply(this, arguments);
66
- }
67
- function initServer() {
68
- return _initServer.apply(this, arguments);
69
- }
70
- function _initServer() {
71
- _initServer = _async_to_generator._(function() {
72
- var routeFilepath, routes, dynamicProdOptions, prodServerOptions, app;
73
- return _ts_generator._(this, function(_state) {
74
- switch (_state.label) {
75
- case 0:
76
- routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
77
- return [
78
- 4,
79
- loadRoutes(routeFilepath)
80
- ];
81
- case 1:
82
- routes = _state.sent();
83
- dynamicProdOptions = p_dynamicProdOptions;
84
- prodServerOptions = _object_spread._({
85
- pwd: __dirname,
86
- routes,
87
- disableCustomHook: true
88
- }, dynamicProdOptions);
89
- return [
90
- 4,
91
- createProdServer(prodServerOptions)
92
- ];
93
- case 2:
94
- app = _state.sent();
95
- return [
96
- 2,
97
- app.getRequestListener()
98
- ];
99
- }
100
- });
101
- });
102
- return _initServer.apply(this, arguments);
103
- }
104
- function createHandler() {
105
- return _createHandler.apply(this, arguments);
106
- }
107
- function _createHandler() {
108
- _createHandler = _async_to_generator._(function() {
109
- return _ts_generator._(this, function(_state) {
110
- switch (_state.label) {
111
- case 0:
112
- if (!handlerCreationPromise) {
113
- handlerCreationPromise = _async_to_generator._(function() {
114
- var error;
115
- return _ts_generator._(this, function(_state2) {
116
- switch (_state2.label) {
117
- case 0:
118
- _state2.trys.push([
119
- 0,
120
- 2,
121
- ,
122
- 3
123
- ]);
124
- return [
125
- 4,
126
- initServer()
127
- ];
128
- case 1:
129
- requestHandler = _state2.sent();
130
- return [
131
- 3,
132
- 3
133
- ];
134
- case 2:
135
- error = _state2.sent();
136
- console.error("Error creating server:", error);
137
- process.exit(1);
138
- return [
139
- 3,
140
- 3
141
- ];
142
- case 3:
143
- return [
144
- 2
145
- ];
146
- }
147
- });
148
- })();
149
- }
150
- return [
151
- 4,
152
- handlerCreationPromise
153
- ];
154
- case 1:
155
- _state.sent();
156
- return [
157
- 2,
158
- requestHandler
159
- ];
160
- }
161
- });
162
- });
163
- return _createHandler.apply(this, arguments);
164
- }
165
- createHandler();
166
- module.exports = function() {
167
- var _ref = _async_to_generator._(function(req, res) {
168
- return _ts_generator._(this, function(_state) {
169
- switch (_state.label) {
170
- case 0:
171
- if (!!requestHandler)
172
- return [
173
- 3,
174
- 2
175
- ];
176
- return [
177
- 4,
178
- createHandler()
179
- ];
180
- case 1:
181
- _state.sent();
182
- _state.label = 2;
183
- case 2:
184
- return [
185
- 2,
186
- requestHandler(req, res)
187
- ];
188
- }
189
- });
190
- });
191
- return function(req, res) {
192
- return _ref.apply(this, arguments);
193
- };
194
- }();
195
- }
196
- });
197
- export default require_vercelEntry();
@@ -1,35 +0,0 @@
1
- const fs = require("node:fs/promises");
2
- const path = require("node:path");
3
- const { createProdServer } = require("@modern-js/prod-server");
4
- p_genPluginImportsCode;
5
- if (!process.env.NODE_ENV) {
6
- process.env.NODE_ENV = "production";
7
- }
8
- async function loadRoutes(routeFilepath) {
9
- try {
10
- await fs.access(routeFilepath);
11
- const content = await fs.readFile(routeFilepath, "utf-8");
12
- const routeSpec = JSON.parse(content);
13
- return routeSpec.routes || [];
14
- } catch (error) {
15
- console.warn("route.json not found or invalid, continuing with empty routes.");
16
- return [];
17
- }
18
- }
19
- async function main() {
20
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
21
- const routes = await loadRoutes(routeFilepath);
22
- const dynamicProdOptions = p_dynamicProdOptions;
23
- const prodServerOptions = {
24
- pwd: __dirname,
25
- routes,
26
- disableCustomHook: true,
27
- ...dynamicProdOptions
28
- };
29
- const app = await createProdServer(prodServerOptions);
30
- const port = process.env.PORT || 8080;
31
- app.listen(port, () => {
32
- console.log("\\x1b[32mServer is listening on port", port, "\\x1b[0m");
33
- });
34
- }
35
- main();
@@ -1,23 +0,0 @@
1
- import path from "node:path";
2
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
3
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
4
- async function genVercelEntry({ config, plugins, appContext } = {}) {
5
- const defaultConfig = {
6
- output: {
7
- path: "."
8
- }
9
- };
10
- const pluginImportCode = genPluginImportsCode(plugins || []);
11
- const dynamicProdOptions = {
12
- config: `${JSON.stringify(config || defaultConfig)}`,
13
- serverConfigFile: DEFAULT_SERVER_CONFIG,
14
- plugins: `${getPluginsCode(plugins || [])}`,
15
- appContext: `${appContext ? severAppContextTemplate(appContext) : "undefined"}`
16
- };
17
- let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
18
- entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions));
19
- return entryCode;
20
- }
21
- export {
22
- genVercelEntry
23
- };
@@ -1,63 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
- };
5
- var require_vercelEntry = __commonJS({
6
- "src/plugins/deploy/platforms/vercelEntry.js"(exports, module) {
7
- const fs = require("node:fs/promises");
8
- const path = require("node:path");
9
- const { createProdServer } = require("@modern-js/prod-server");
10
- p_genPluginImportsCode;
11
- if (!process.env.NODE_ENV) {
12
- process.env.NODE_ENV = "production";
13
- }
14
- let requestHandler = null;
15
- let handlerCreationPromise = null;
16
- async function loadRoutes(routeFilepath) {
17
- try {
18
- await fs.access(routeFilepath);
19
- const content = await fs.readFile(routeFilepath, "utf-8");
20
- const routeSpec = JSON.parse(content);
21
- return routeSpec.routes || [];
22
- } catch (error) {
23
- console.warn("route.json not found or invalid, continuing with empty routes.");
24
- return [];
25
- }
26
- }
27
- async function initServer() {
28
- const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
29
- const routes = await loadRoutes(routeFilepath);
30
- const dynamicProdOptions = p_dynamicProdOptions;
31
- const prodServerOptions = {
32
- pwd: __dirname,
33
- routes,
34
- disableCustomHook: true,
35
- ...dynamicProdOptions
36
- };
37
- const app = await createProdServer(prodServerOptions);
38
- return app.getRequestListener();
39
- }
40
- async function createHandler() {
41
- if (!handlerCreationPromise) {
42
- handlerCreationPromise = (async () => {
43
- try {
44
- requestHandler = await initServer();
45
- } catch (error) {
46
- console.error("Error creating server:", error);
47
- process.exit(1);
48
- }
49
- })();
50
- }
51
- await handlerCreationPromise;
52
- return requestHandler;
53
- }
54
- createHandler();
55
- module.exports = async (req, res) => {
56
- if (!requestHandler) {
57
- await createHandler();
58
- }
59
- return requestHandler(req, res);
60
- };
61
- }
62
- });
63
- export default require_vercelEntry();
@@ -1 +0,0 @@
1
- export {};