@modern-js/app-tools 2.49.3-alpha.9 → 2.49.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. package/dist/cjs/analyze/getServerRoutes.js +3 -4
  2. package/dist/cjs/index.js +1 -3
  3. package/dist/cjs/utils/routes.js +2 -7
  4. package/dist/esm/analyze/getServerRoutes.js +4 -5
  5. package/dist/esm/index.js +1 -3
  6. package/dist/esm/utils/routes.js +2 -6
  7. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  8. package/dist/esm-node/index.js +1 -3
  9. package/dist/esm-node/utils/routes.js +2 -6
  10. package/dist/types/utils/routes.d.ts +3 -3
  11. package/package.json +22 -26
  12. package/dist/cjs/plugins/deploy/dependencies.js +0 -256
  13. package/dist/cjs/plugins/deploy/index.js +0 -215
  14. package/dist/cjs/plugins/deploy/platforms/netlify.js +0 -95
  15. package/dist/cjs/plugins/deploy/platforms/node.js +0 -88
  16. package/dist/cjs/plugins/deploy/platforms/platform.js +0 -16
  17. package/dist/cjs/plugins/deploy/platforms/vercel.js +0 -57
  18. package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +0 -55
  19. package/dist/cjs/plugins/deploy/utils.js +0 -150
  20. package/dist/esm/plugins/deploy/dependencies.js +0 -725
  21. package/dist/esm/plugins/deploy/index.js +0 -356
  22. package/dist/esm/plugins/deploy/platforms/netlify.js +0 -41
  23. package/dist/esm/plugins/deploy/platforms/node.js +0 -39
  24. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  25. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -47
  26. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -197
  27. package/dist/esm/plugins/deploy/utils.js +0 -244
  28. package/dist/esm-node/plugins/deploy/dependencies.js +0 -222
  29. package/dist/esm-node/plugins/deploy/index.js +0 -185
  30. package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -71
  31. package/dist/esm-node/plugins/deploy/platforms/node.js +0 -64
  32. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  33. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -23
  34. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -63
  35. package/dist/esm-node/plugins/deploy/utils.js +0 -109
  36. package/dist/types/plugins/deploy/dependencies.d.ts +0 -1
  37. package/dist/types/plugins/deploy/index.d.ts +0 -4
  38. package/dist/types/plugins/deploy/platforms/netlify.d.ts +0 -5
  39. package/dist/types/plugins/deploy/platforms/node.d.ts +0 -5
  40. package/dist/types/plugins/deploy/platforms/platform.d.ts +0 -1
  41. package/dist/types/plugins/deploy/platforms/vercel.d.ts +0 -5
  42. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  43. package/dist/types/plugins/deploy/utils.d.ts +0 -27
@@ -1,215 +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 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_routes = require("../../utils/routes");
38
- var import_utils2 = require("./utils");
39
- var import_dependencies = require("./dependencies");
40
- var deploy_default = () => ({
41
- name: "@modern-js/plugin-deploy",
42
- pre: [
43
- "@modern-js/plugin-bff",
44
- "@modern-js/plugin-server"
45
- ],
46
- setup: (api) => {
47
- const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
48
- return {
49
- async beforeDeploy() {
50
- const appContext = api.useAppContext();
51
- const modernConfig = api.useResolvedConfigContext();
52
- const { source: { mainEntryName } } = modernConfig;
53
- const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
54
- const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
55
- const needModernServer = useSSR || useAPI || useWebServer;
56
- let outputDirectory = import_path.default.join(appDirectory, ".output");
57
- let funcsDirectory = outputDirectory;
58
- let staticDirectory = import_path.default.join(outputDirectory, "static");
59
- if (deployTarget === "node") {
60
- await import_utils.fs.remove(outputDirectory);
61
- await import_utils.fs.copy(distDirectory, outputDirectory);
62
- }
63
- if (deployTarget === "netlify") {
64
- const netlifyOutput = import_path.default.join(appDirectory, ".netlify");
65
- funcsDirectory = import_path.default.join(netlifyOutput, "functions");
66
- const routes = [];
67
- if (!needModernServer) {
68
- entrypoints.forEach((entry) => {
69
- const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
70
- routes.push({
71
- src: `/${isMain ? "" : `${entry.entryName}/`}*`,
72
- dest: `/html/${entry.entryName}/index.html`,
73
- status: 200
74
- });
75
- });
76
- } else {
77
- routes.push({
78
- src: `/*`,
79
- dest: `/.netlify/functions/index`,
80
- status: 200
81
- });
82
- throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
83
- }
84
- console.log("routes", routes, needModernServer);
85
- const redirectContent = routes.map((route) => {
86
- return `${route.src} ${route.dest} ${route.status}`;
87
- }).join("\n");
88
- console.log("redirectContent", redirectContent);
89
- await import_utils.fs.remove(outputDirectory);
90
- await import_utils.fs.ensureDir(funcsDirectory);
91
- await import_utils.fs.copy(distDirectory, funcsDirectory, {
92
- filter: (src) => {
93
- const distStaticDirectory = import_path.default.join(distDirectory, "static");
94
- return !src.includes(distStaticDirectory);
95
- }
96
- });
97
- const redirectFilePath = import_path.default.join(distDirectory, "_redirects");
98
- await import_utils.fs.writeFile(redirectFilePath, redirectContent);
99
- }
100
- if (deployTarget === "vercel") {
101
- const vercelOutput = import_path.default.join(appDirectory, ".vercel");
102
- await import_utils.fs.remove(vercelOutput);
103
- outputDirectory = import_path.default.join(vercelOutput, "output");
104
- const config = {
105
- version: 3,
106
- routes: [
107
- {
108
- src: "/static/(.*)",
109
- headers: {
110
- "cache-control": "s-maxage=31536000, immutable"
111
- },
112
- continue: true
113
- },
114
- {
115
- handle: "filesystem"
116
- }
117
- ]
118
- };
119
- if (!needModernServer) {
120
- entrypoints.forEach((entry) => {
121
- const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
122
- config.routes.push({
123
- src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
124
- headers: {
125
- "cache-control": "s-maxage=0"
126
- },
127
- dest: `/html/${entry.entryName}/index.html`
128
- });
129
- });
130
- } else {
131
- config.routes.push({
132
- src: "/(.*)",
133
- dest: `/index`
134
- });
135
- }
136
- await import_utils.fs.ensureDir(outputDirectory);
137
- await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config, {
138
- spaces: 2
139
- });
140
- staticDirectory = import_path.default.join(outputDirectory, "static/static");
141
- await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
142
- if (!needModernServer) {
143
- const destHtmlDirectory = import_path.default.join(distDirectory, "html");
144
- const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
145
- await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
146
- } else {
147
- funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
148
- await import_utils.fs.ensureDir(funcsDirectory);
149
- await import_utils.fs.copy(distDirectory, funcsDirectory, {
150
- filter: (src) => {
151
- const distStaticDirectory = import_path.default.join(distDirectory, "static");
152
- return !src.includes(distStaticDirectory);
153
- }
154
- });
155
- await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
156
- runtime: "nodejs16.x",
157
- handler: "index.js",
158
- launcherType: "Nodejs",
159
- shouldAddHelpers: false,
160
- supportsResponseStreaming: true
161
- });
162
- }
163
- }
164
- const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
165
- const serverAppContext = {
166
- sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
167
- apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
168
- lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
169
- metaName
170
- };
171
- let code = ``;
172
- console.log("deployTarget111111111", deployTarget);
173
- switch (deployTarget) {
174
- case "node": {
175
- const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
176
- code = genNodeEntry({
177
- plugins,
178
- config: modernConfig,
179
- appContext: serverAppContext
180
- });
181
- break;
182
- }
183
- case "vercel": {
184
- const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
185
- code = await genVercelEntry({
186
- plugins,
187
- config: modernConfig,
188
- appContext: serverAppContext
189
- });
190
- break;
191
- }
192
- case "netlify": {
193
- const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
194
- code = genNetlifyEntry({
195
- plugins,
196
- config: modernConfig,
197
- appContext: serverAppContext
198
- });
199
- break;
200
- }
201
- default: {
202
- code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
203
- }
204
- }
205
- const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
206
- if (needModernServer) {
207
- await import_utils.fs.writeFile(entryFilePath, code);
208
- await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
209
- "@modern-js/prod-server"
210
- ]);
211
- }
212
- }
213
- };
214
- }
215
- });
@@ -1,95 +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 netlify_exports = {};
20
- __export(netlify_exports, {
21
- genNetlifyEntry: () => genNetlifyEntry
22
- });
23
- module.exports = __toCommonJS(netlify_exports);
24
- var import_utils = require("@modern-js/utils");
25
- var import_utils2 = require("../utils");
26
- function genNetlifyEntry({ config, plugins, appContext } = {}) {
27
- const defaultConfig = {
28
- server: {
29
- port: 8080
30
- },
31
- output: {
32
- path: "."
33
- }
34
- };
35
- return `
36
-
37
- const fs = require('node:fs/promises');
38
- const path = require('node:path');
39
- const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');
40
- ${(0, import_utils2.genPluginImportsCode)(plugins || [])}
41
-
42
- let requestHandler = null;
43
-
44
- if(!process.env.NODE_ENV){
45
- process.env.NODE_ENV = 'production';
46
- }
47
-
48
- async function createHandler() {
49
- try {
50
- let routes = [];
51
- const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
52
- try {
53
- await fs.access(routeFilepath);
54
- const content = await fs.readFile(routeFilepath, "utf-8");
55
- const routeSpec = JSON.parse(content);
56
- routes = routeSpec.routes;
57
- } catch (error) {
58
- console.warn('route.json not found, continuing with empty routes.');
59
- }
60
-
61
- const prodServerOptions = {
62
- pwd: __dirname,
63
- routes,
64
- config: ${JSON.stringify(config || defaultConfig)},
65
- serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
66
- plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
67
- appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
68
- disableCustomHook: true
69
- }
70
-
71
- requestHandler = await createNetlifyFunction(prodServerOptions)
72
-
73
- return requestHandler
74
- } catch(error) {
75
- console.error(error);
76
- process.exit(1);
77
- }
78
- }
79
-
80
- createHandler();
81
-
82
- const handleRequest = async(request, context) => {
83
- if(typeof requestHandler !== 'function'){
84
- await createHandler();
85
- }
86
- return requestHandler(request, context);
87
- }
88
-
89
- export default handleRequest;
90
- `;
91
- }
92
- // Annotate the CommonJS export names for ESM import in node:
93
- 0 && (module.exports = {
94
- genNetlifyEntry
95
- });
@@ -1,88 +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 node_exports = {};
20
- __export(node_exports, {
21
- genNodeEntry: () => genNodeEntry
22
- });
23
- module.exports = __toCommonJS(node_exports);
24
- var import_utils = require("@modern-js/utils");
25
- var import_utils2 = require("../utils");
26
- function genNodeEntry({ config, plugins, appContext } = {}) {
27
- const defaultConfig = {
28
- server: {
29
- port: 8080
30
- },
31
- output: {
32
- path: "."
33
- }
34
- };
35
- return `
36
-
37
- const fs = require('node:fs/promises');
38
- const path = require('node:path');
39
- const { createProdServer } = require('@modern-js/prod-server');
40
- ${(0, import_utils2.genPluginImportsCode)(plugins || [])}
41
-
42
- if(!process.env.NODE_ENV){
43
- process.env.NODE_ENV = 'production';
44
- }
45
-
46
- async function main() {
47
- try {
48
- let routes = [];
49
- const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
50
- try {
51
- await fs.access(routeFilepath);
52
- const content = await fs.readFile(routeFilepath, "utf-8");
53
- const routeSpec = JSON.parse(content);
54
- routes = routeSpec.routes;
55
- } catch (error) {
56
- console.warn('route.json not found, continuing with empty routes.');
57
- }
58
-
59
- const prodServerOptions = {
60
- pwd: __dirname,
61
- routes,
62
- config: ${JSON.stringify(config || defaultConfig)},
63
- serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
64
- plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
65
- appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
66
- disableCustomHook: true
67
- }
68
-
69
- const app = await createProdServer(prodServerOptions)
70
-
71
- const port = process.env.PORT || 3000;
72
-
73
- app.listen(port, () => {
74
- console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');
75
- });
76
- } catch(error) {
77
- console.error(error);
78
- process.exit(1);
79
- }
80
- }
81
-
82
- main();
83
- `;
84
- }
85
- // Annotate the CommonJS export names for ESM import in node:
86
- 0 && (module.exports = {
87
- genNodeEntry
88
- });
@@ -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,150 +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 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
- });