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

Sign up to get free protection for your applications and to get access to all the features.
@@ -163,9 +163,9 @@ var deploy_default = () => ({
163
163
  }
164
164
  const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
165
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)}")`,
166
+ sharedDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, sharedDirectory)),
167
+ apiDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, apiDirectory)),
168
+ lambdaDirectory: import_path.default.join(__dirname, import_path.default.relative(appDirectory, lambdaDirectory)),
169
169
  metaName
170
170
  };
171
171
  let code = ``;
@@ -173,7 +173,7 @@ var deploy_default = () => ({
173
173
  switch (deployTarget) {
174
174
  case "node": {
175
175
  const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
176
- code = genNodeEntry({
176
+ code = await genNodeEntry({
177
177
  plugins,
178
178
  config: modernConfig,
179
179
  appContext: serverAppContext
@@ -191,7 +191,7 @@ var deploy_default = () => ({
191
191
  }
192
192
  case "netlify": {
193
193
  const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
194
- code = genNetlifyEntry({
194
+ code = await genNetlifyEntry({
195
195
  plugins,
196
196
  config: modernConfig,
197
197
  appContext: serverAppContext
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,15 +17,24 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var node_exports = {};
20
30
  __export(node_exports, {
21
31
  genNodeEntry: () => genNodeEntry
22
32
  });
23
33
  module.exports = __toCommonJS(node_exports);
34
+ var import_node_path = __toESM(require("node:path"));
24
35
  var import_utils = require("@modern-js/utils");
25
36
  var import_utils2 = require("../utils");
26
- function genNodeEntry({ config, plugins, appContext } = {}) {
37
+ async function genNodeEntry({ config, plugins, appContext } = {}) {
27
38
  const defaultConfig = {
28
39
  server: {
29
40
  port: 8080
@@ -32,55 +43,24 @@ function genNodeEntry({ config, plugins, appContext } = {}) {
32
43
  path: "."
33
44
  }
34
45
  };
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
- `;
46
+ const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
47
+ const dynamicProdOptions = {
48
+ config: config || defaultConfig,
49
+ serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
50
+ plugins,
51
+ appContext: appContext ? {
52
+ sharedDirectory: appContext.sharedDirectory,
53
+ apiDirectory: appContext.apiDirectory,
54
+ lambdaDirectory: appContext.lambdaDirectory
55
+ } : "undefined"
56
+ };
57
+ let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
58
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace(
59
+ "p_dynamicProdOptions",
60
+ // JSON.stringify(dynamicProdOptions),
61
+ JSON.stringify(dynamicProdOptions)
62
+ );
63
+ return entryCode;
84
64
  }
85
65
  // Annotate the CommonJS export names for ESM import in node:
86
66
  0 && (module.exports = {
@@ -42,13 +42,21 @@ async function genVercelEntry({ config, plugins, appContext } = {}) {
42
42
  };
43
43
  const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
44
44
  const dynamicProdOptions = {
45
- config: `${JSON.stringify(config || defaultConfig)}`,
45
+ config: config || defaultConfig,
46
46
  serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
47
- plugins: `${(0, import_utils2.getPluginsCode)(plugins || [])}`,
48
- appContext: `${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"}`
47
+ plugins,
48
+ appContext: appContext ? {
49
+ sharedDirectory: appContext.sharedDirectory,
50
+ apiDirectory: appContext.apiDirectory,
51
+ lambdaDirectory: appContext.lambdaDirectory
52
+ } : "undefined"
49
53
  };
50
54
  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));
55
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace(
56
+ "p_dynamicProdOptions",
57
+ // JSON.stringify(dynamicProdOptions),
58
+ JSON.stringify(dynamicProdOptions)
59
+ );
52
60
  return entryCode;
53
61
  }
54
62
  // Annotate the CommonJS export names for ESM import in node:
@@ -230,9 +230,9 @@ function deploy_default() {
230
230
  case 18:
231
231
  plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
232
232
  serverAppContext = {
233
- sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
234
- apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
235
- lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
233
+ sharedDirectory: path.join(__dirname, path.relative(appDirectory, sharedDirectory)),
234
+ apiDirectory: path.join(__dirname, path.relative(appDirectory, apiDirectory)),
235
+ lambdaDirectory: path.join(__dirname, path.relative(appDirectory, lambdaDirectory)),
236
236
  metaName
237
237
  };
238
238
  code = "";
@@ -246,17 +246,17 @@ function deploy_default() {
246
246
  case "vercel":
247
247
  return [
248
248
  3,
249
- 21
249
+ 22
250
250
  ];
251
251
  case "netlify":
252
252
  return [
253
253
  3,
254
- 24
254
+ 25
255
255
  ];
256
256
  }
257
257
  return [
258
258
  3,
259
- 26
259
+ 28
260
260
  ];
261
261
  case 19:
262
262
  return [
@@ -265,21 +265,26 @@ function deploy_default() {
265
265
  ];
266
266
  case 20:
267
267
  genNodeEntry = _state.sent().genNodeEntry;
268
- code = genNodeEntry({
269
- plugins,
270
- config: modernConfig,
271
- appContext: serverAppContext
272
- });
273
268
  return [
274
- 3,
275
- 27
269
+ 4,
270
+ genNodeEntry({
271
+ plugins,
272
+ config: modernConfig,
273
+ appContext: serverAppContext
274
+ })
276
275
  ];
277
276
  case 21:
277
+ code = _state.sent();
278
+ return [
279
+ 3,
280
+ 29
281
+ ];
282
+ case 22:
278
283
  return [
279
284
  4,
280
285
  import("./platforms/vercel")
281
286
  ];
282
- case 22:
287
+ case 23:
283
288
  genVercelEntry = _state.sent().genVercelEntry;
284
289
  return [
285
290
  4,
@@ -289,45 +294,50 @@ function deploy_default() {
289
294
  appContext: serverAppContext
290
295
  })
291
296
  ];
292
- case 23:
297
+ case 24:
293
298
  code = _state.sent();
294
299
  return [
295
300
  3,
296
- 27
301
+ 29
297
302
  ];
298
- case 24:
303
+ case 25:
299
304
  return [
300
305
  4,
301
306
  import("./platforms/netlify")
302
307
  ];
303
- case 25:
308
+ case 26:
304
309
  genNetlifyEntry = _state.sent().genNetlifyEntry;
305
- code = genNetlifyEntry({
306
- plugins,
307
- config: modernConfig,
308
- appContext: serverAppContext
309
- });
310
+ return [
311
+ 4,
312
+ genNetlifyEntry({
313
+ plugins,
314
+ config: modernConfig,
315
+ appContext: serverAppContext
316
+ })
317
+ ];
318
+ case 27:
319
+ code = _state.sent();
310
320
  return [
311
321
  3,
312
- 27
322
+ 29
313
323
  ];
314
- case 26:
324
+ case 28:
315
325
  {
316
326
  code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
317
327
  }
318
- _state.label = 27;
319
- case 27:
328
+ _state.label = 29;
329
+ case 29:
320
330
  entryFilePath = path.join(funcsDirectory, "index.js");
321
331
  if (!needModernServer)
322
332
  return [
323
333
  3,
324
- 30
334
+ 32
325
335
  ];
326
336
  return [
327
337
  4,
328
338
  fse.writeFile(entryFilePath, code)
329
339
  ];
330
- case 28:
340
+ case 30:
331
341
  _state.sent();
332
342
  return [
333
343
  4,
@@ -335,10 +345,10 @@ function deploy_default() {
335
345
  "@modern-js/prod-server"
336
346
  ])
337
347
  ];
338
- case 29:
348
+ case 31:
339
349
  _state.sent();
340
- _state.label = 30;
341
- case 30:
350
+ _state.label = 32;
351
+ case 32:
342
352
  return [
343
353
  2
344
354
  ];
@@ -1,38 +1,57 @@
1
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
2
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
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 } from "../utils";
3
6
  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.');
7
+ return _genNodeEntry.apply(this, arguments);
8
+ }
9
+ function _genNodeEntry() {
10
+ _genNodeEntry = _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
+ server: {
19
+ port: 8080
20
+ },
21
+ output: {
22
+ path: "."
23
+ }
24
+ };
25
+ pluginImportCode = genPluginImportsCode(plugins || []);
26
+ dynamicProdOptions = {
27
+ config: config || defaultConfig,
28
+ serverConfigFile: DEFAULT_SERVER_CONFIG,
29
+ plugins,
30
+ appContext: appContext ? {
31
+ sharedDirectory: appContext.sharedDirectory,
32
+ apiDirectory: appContext.apiDirectory,
33
+ lambdaDirectory: appContext.lambdaDirectory
34
+ } : "undefined"
35
+ };
36
+ return [
37
+ 4,
38
+ fse.readFile(path.join(__dirname, "./nodeEntry.js"))
39
+ ];
40
+ case 1:
41
+ entryCode = _state.sent().toString();
42
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace(
43
+ "p_dynamicProdOptions",
44
+ // JSON.stringify(dynamicProdOptions),
45
+ JSON.stringify(dynamicProdOptions)
46
+ );
47
+ return [
48
+ 2,
49
+ entryCode
50
+ ];
30
51
  }
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 ");
52
+ });
53
+ });
54
+ return _genNodeEntry.apply(this, arguments);
36
55
  }
37
56
  export {
38
57
  genNodeEntry
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "node:path";
4
4
  import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
5
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
5
+ import { genPluginImportsCode } from "../utils";
6
6
  function genVercelEntry() {
7
7
  return _genVercelEntry.apply(this, arguments);
8
8
  }
@@ -21,10 +21,14 @@ function _genVercelEntry() {
21
21
  };
22
22
  pluginImportCode = genPluginImportsCode(plugins || []);
23
23
  dynamicProdOptions = {
24
- config: "".concat(JSON.stringify(config || defaultConfig)),
24
+ config: config || defaultConfig,
25
25
  serverConfigFile: DEFAULT_SERVER_CONFIG,
26
- plugins: "".concat(getPluginsCode(plugins || [])),
27
- appContext: "".concat(appContext ? severAppContextTemplate(appContext) : "undefined")
26
+ plugins,
27
+ appContext: appContext ? {
28
+ sharedDirectory: appContext.sharedDirectory,
29
+ apiDirectory: appContext.apiDirectory,
30
+ lambdaDirectory: appContext.lambdaDirectory
31
+ } : "undefined"
28
32
  };
29
33
  return [
30
34
  4,
@@ -32,7 +36,11 @@ function _genVercelEntry() {
32
36
  ];
33
37
  case 1:
34
38
  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));
39
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace(
40
+ "p_dynamicProdOptions",
41
+ // JSON.stringify(dynamicProdOptions),
42
+ JSON.stringify(dynamicProdOptions)
43
+ );
36
44
  return [
37
45
  2,
38
46
  entryCode
@@ -130,9 +130,9 @@ var deploy_default = () => ({
130
130
  }
131
131
  const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
132
132
  const serverAppContext = {
133
- sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
134
- apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
135
- lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
133
+ sharedDirectory: path.join(__dirname, path.relative(appDirectory, sharedDirectory)),
134
+ apiDirectory: path.join(__dirname, path.relative(appDirectory, apiDirectory)),
135
+ lambdaDirectory: path.join(__dirname, path.relative(appDirectory, lambdaDirectory)),
136
136
  metaName
137
137
  };
138
138
  let code = ``;
@@ -140,7 +140,7 @@ var deploy_default = () => ({
140
140
  switch (deployTarget) {
141
141
  case "node": {
142
142
  const { genNodeEntry } = await import("./platforms/node");
143
- code = genNodeEntry({
143
+ code = await genNodeEntry({
144
144
  plugins,
145
145
  config: modernConfig,
146
146
  appContext: serverAppContext
@@ -158,7 +158,7 @@ var deploy_default = () => ({
158
158
  }
159
159
  case "netlify": {
160
160
  const { genNetlifyEntry } = await import("./platforms/netlify");
161
- code = genNetlifyEntry({
161
+ code = await genNetlifyEntry({
162
162
  plugins,
163
163
  config: modernConfig,
164
164
  appContext: serverAppContext
@@ -1,6 +1,7 @@
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 } = {}) {
1
+ import path from "node:path";
2
+ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
3
+ import { genPluginImportsCode } from "../utils";
4
+ async function genNodeEntry({ config, plugins, appContext } = {}) {
4
5
  const defaultConfig = {
5
6
  server: {
6
7
  port: 8080
@@ -9,55 +10,24 @@ function genNodeEntry({ config, plugins, appContext } = {}) {
9
10
  path: "."
10
11
  }
11
12
  };
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
- `;
13
+ const pluginImportCode = genPluginImportsCode(plugins || []);
14
+ const dynamicProdOptions = {
15
+ config: config || defaultConfig,
16
+ serverConfigFile: DEFAULT_SERVER_CONFIG,
17
+ plugins,
18
+ appContext: appContext ? {
19
+ sharedDirectory: appContext.sharedDirectory,
20
+ apiDirectory: appContext.apiDirectory,
21
+ lambdaDirectory: appContext.lambdaDirectory
22
+ } : "undefined"
23
+ };
24
+ let entryCode = (await fse.readFile(path.join(__dirname, "./nodeEntry.js"))).toString();
25
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace(
26
+ "p_dynamicProdOptions",
27
+ // JSON.stringify(dynamicProdOptions),
28
+ JSON.stringify(dynamicProdOptions)
29
+ );
30
+ return entryCode;
61
31
  }
62
32
  export {
63
33
  genNodeEntry
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
3
- import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
3
+ import { genPluginImportsCode } from "../utils";
4
4
  async function genVercelEntry({ config, plugins, appContext } = {}) {
5
5
  const defaultConfig = {
6
6
  output: {
@@ -9,13 +9,21 @@ async function genVercelEntry({ config, plugins, appContext } = {}) {
9
9
  };
10
10
  const pluginImportCode = genPluginImportsCode(plugins || []);
11
11
  const dynamicProdOptions = {
12
- config: `${JSON.stringify(config || defaultConfig)}`,
12
+ config: config || defaultConfig,
13
13
  serverConfigFile: DEFAULT_SERVER_CONFIG,
14
- plugins: `${getPluginsCode(plugins || [])}`,
15
- appContext: `${appContext ? severAppContextTemplate(appContext) : "undefined"}`
14
+ plugins,
15
+ appContext: appContext ? {
16
+ sharedDirectory: appContext.sharedDirectory,
17
+ apiDirectory: appContext.apiDirectory,
18
+ lambdaDirectory: appContext.lambdaDirectory
19
+ } : "undefined"
16
20
  };
17
21
  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));
22
+ entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace(
23
+ "p_dynamicProdOptions",
24
+ // JSON.stringify(dynamicProdOptions),
25
+ JSON.stringify(dynamicProdOptions)
26
+ );
19
27
  return entryCode;
20
28
  }
21
29
  export {
@@ -2,4 +2,4 @@ export declare function genNodeEntry({ config, plugins, appContext, }?: {
2
2
  config?: Record<string, any>;
3
3
  plugins?: string[];
4
4
  appContext?: Record<string, any>;
5
- }): string;
5
+ }): Promise<string>;
@@ -1 +1,5 @@
1
- export {};
1
+ export type AppContext = {
2
+ sharedDirectory: string;
3
+ apiDirectory: string;
4
+ lambdaDirectory: string;
5
+ };
@@ -1,5 +1,8 @@
1
+ import { NormalizedConfig } from '@modern-js/core';
2
+ import { AppTools } from '../../../types';
3
+ import { AppContext } from './platform';
1
4
  export declare function genVercelEntry({ config, plugins, appContext, }?: {
2
- config?: Record<string, any>;
5
+ config?: NormalizedConfig<AppTools>;
3
6
  plugins?: string[];
4
- appContext?: Record<string, any>;
7
+ appContext?: AppContext;
5
8
  }): Promise<string>;
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.12",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -80,20 +80,20 @@
80
80
  "mlly": "^1.6.1",
81
81
  "pkg-types": "^1.1.0",
82
82
  "std-env": "^3.7.0",
83
- "@modern-js/core": "2.49.2",
84
- "@modern-js/plugin-data-loader": "2.49.2",
83
+ "@modern-js/node-bundle-require": "2.49.2",
85
84
  "@modern-js/plugin": "2.49.2",
86
- "@modern-js/plugin-i18n": "2.49.2",
85
+ "@modern-js/plugin-data-loader": "2.49.2",
87
86
  "@modern-js/plugin-lint": "2.49.2",
88
- "@modern-js/prod-server": "2.49.2",
87
+ "@modern-js/plugin-i18n": "2.49.2",
88
+ "@modern-js/server": "2.49.2",
89
89
  "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
90
+ "@modern-js/core": "2.49.2",
91
+ "@modern-js/server-utils": "2.49.2",
92
+ "@modern-js/utils": "2.49.2",
93
+ "@modern-js/types": "2.49.2",
90
94
  "@modern-js/server-core": "2.49.2",
91
95
  "@modern-js/uni-builder": "2.49.2",
92
- "@modern-js/node-bundle-require": "2.49.2",
93
- "@modern-js/types": "2.49.2",
94
- "@modern-js/utils": "2.49.2",
95
- "@modern-js/server": "2.49.2",
96
- "@modern-js/server-utils": "2.49.2"
96
+ "@modern-js/prod-server": "2.49.2"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@rsbuild/plugin-swc": "0.6.10",