@modern-js/app-tools 2.48.5-alpha.0 → 2.48.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,8 +23,6 @@ __export(dev_exports, {
23
23
  module.exports = __toCommonJS(dev_exports);
24
24
  var import_core = require("@modern-js/core");
25
25
  var import_utils = require("@modern-js/utils");
26
- var import_server = require("@modern-js/server");
27
- var import_prod_server = require("@modern-js/prod-server");
28
26
  var import_printInstructions = require("../utils/printInstructions");
29
27
  var import_createServer = require("../utils/createServer");
30
28
  var import_routes = require("../utils/routes");
@@ -43,7 +41,7 @@ const dev = async (api, options, devServerOptions = {}) => {
43
41
  cliOptions: options
44
42
  };
45
43
  import_core.ResolvedConfigContext.set(normalizedConfig);
46
- const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
44
+ const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName } = appContext;
47
45
  await (0, import_config.buildServerConfig)({
48
46
  appDirectory,
49
47
  distDirectory,
@@ -57,7 +55,6 @@ const dev = async (api, options, devServerOptions = {}) => {
57
55
  await (0, import_routes.generateRoutes)(appContext);
58
56
  const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
59
57
  const serverOptions = {
60
- metaName,
61
58
  dev: {
62
59
  port,
63
60
  https: normalizedConfig.dev.https,
@@ -65,32 +62,37 @@ const dev = async (api, options, devServerOptions = {}) => {
65
62
  ...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
66
63
  },
67
64
  appContext: {
68
- appDirectory,
65
+ metaName,
66
+ appDirectory: appContext.appDirectory,
67
+ sharedDirectory: appContext.sharedDirectory,
69
68
  apiDirectory: appContext.apiDirectory,
70
- lambdaDirectory: appContext.lambdaDirectory,
71
- sharedDirectory: appContext.sharedDirectory
69
+ lambdaDirectory: appContext.lambdaDirectory
72
70
  },
73
- routes: serverRoutes,
74
71
  pwd: appDirectory,
75
72
  config: normalizedConfig,
76
73
  serverConfigFile,
77
- internalPlugins: serverInternalPlugins,
74
+ internalPlugins: (0, import_createServer.injectDataLoaderPlugin)(serverInternalPlugins),
78
75
  ...devServerOptions
79
76
  };
80
77
  if (apiOnly) {
81
78
  var _normalizedConfig_dev;
82
- const app = await (0, import_server.createDevServer)(serverOptions, import_prod_server.initProdMiddlewares);
79
+ const app = await (0, import_createServer.createServer)({
80
+ ...serverOptions,
81
+ compiler: null
82
+ });
83
83
  const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || import_utils.DEFAULT_DEV_HOST;
84
84
  app.listen({
85
85
  port,
86
86
  host
87
- }, () => {
87
+ }, async (err) => {
88
+ if (err) {
89
+ throw err;
90
+ }
88
91
  (0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
89
92
  });
90
93
  } else {
91
94
  const { server } = await appContext.builder.startDevServer({
92
- serverOptions,
93
- initProdMiddlewares: import_prod_server.initProdMiddlewares
95
+ serverOptions
94
96
  });
95
97
  (0, import_createServer.setServer)(server);
96
98
  }
@@ -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,6 +17,14 @@ 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 serve_exports = {};
20
30
  __export(serve_exports, {
@@ -22,25 +32,21 @@ __export(serve_exports, {
22
32
  });
23
33
  module.exports = __toCommonJS(serve_exports);
24
34
  var import_utils = require("@modern-js/utils");
25
- var import_prod_server = require("@modern-js/prod-server");
35
+ var import_prod_server = __toESM(require("@modern-js/prod-server"));
26
36
  var import_printInstructions = require("../utils/printInstructions");
37
+ var import_createServer = require("../utils/createServer");
27
38
  var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
28
39
  const start = async (api) => {
29
40
  var _userConfig_source, _userConfig_output_distPath;
30
41
  const appContext = api.useAppContext();
31
42
  const userConfig = api.useResolvedConfigContext();
32
43
  const hookRunners = api.useHookRunners();
33
- const { distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes } = appContext;
44
+ const { appDirectory, port, serverConfigFile, metaName } = appContext;
34
45
  import_utils.logger.info(`Starting production server...`);
35
46
  const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
36
- let runMode;
37
- if (apiOnly) {
38
- runMode = "apiOnly";
39
- }
40
47
  const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
41
- const app = await (0, import_prod_server.createProdServer)({
42
- metaName,
43
- pwd: distDirectory,
48
+ const app = await (0, import_prod_server.default)({
49
+ pwd: appDirectory,
44
50
  config: {
45
51
  ...userConfig,
46
52
  dev: userConfig.dev,
@@ -49,18 +55,20 @@ const start = async (api) => {
49
55
  ...userConfig.output || {}
50
56
  }
51
57
  },
52
- routes: serverRoutes,
53
58
  appContext: {
54
- appDirectory,
59
+ metaName,
55
60
  sharedDirectory: (0, import_utils.getTargetDir)(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
56
61
  apiDirectory: (0, import_utils.getTargetDir)(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
57
62
  lambdaDirectory: (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
58
63
  },
59
64
  serverConfigFile,
60
- internalPlugins: serverInternalPlugins,
61
- runMode
65
+ internalPlugins: (0, import_createServer.injectDataLoaderPlugin)(serverInternalPlugins),
66
+ apiOnly
62
67
  });
63
- app.listen(port, async () => {
68
+ app.listen(port, async (err) => {
69
+ if (err) {
70
+ throw err;
71
+ }
64
72
  await (0, import_printInstructions.printInstructions)(hookRunners, appContext, userConfig);
65
73
  });
66
74
  };
@@ -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,17 +17,25 @@ 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 createServer_exports = {};
20
30
  __export(createServer_exports, {
21
31
  closeServer: () => closeServer,
22
32
  createServer: () => createServer,
23
33
  getServer: () => getServer,
34
+ injectDataLoaderPlugin: () => injectDataLoaderPlugin,
24
35
  setServer: () => setServer
25
36
  });
26
37
  module.exports = __toCommonJS(createServer_exports);
27
38
  var import_server = require("@modern-js/server");
28
- var import_prod_server = require("@modern-js/prod-server");
29
39
  let server = null;
30
40
  const getServer = () => server;
31
41
  const setServer = (newServer) => {
@@ -33,21 +43,33 @@ const setServer = (newServer) => {
33
43
  };
34
44
  const closeServer = async () => {
35
45
  if (server) {
36
- server.close();
46
+ await server.close();
37
47
  server = null;
38
48
  }
39
49
  };
40
50
  const createServer = async (options) => {
41
51
  if (server) {
42
- server.close();
52
+ await server.close();
43
53
  }
44
- server = await (0, import_server.createDevServer)(options, import_prod_server.initProdMiddlewares);
45
- return server;
54
+ server = new import_server.Server(options);
55
+ const app = await server.init();
56
+ return app;
57
+ };
58
+ const injectDataLoaderPlugin = (internalPlugins) => {
59
+ const DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
60
+ return {
61
+ ...internalPlugins,
62
+ "@modern-js/plugin-data-loader": {
63
+ path: DataLoaderPlugin,
64
+ forced: true
65
+ }
66
+ };
46
67
  };
47
68
  // Annotate the CommonJS export names for ESM import in node:
48
69
  0 && (module.exports = {
49
70
  closeServer,
50
71
  createServer,
51
72
  getServer,
73
+ injectDataLoaderPlugin,
52
74
  setServer
53
75
  });
@@ -21,10 +21,10 @@ __export(env_exports, {
21
21
  getAutoInjectEnv: () => getAutoInjectEnv
22
22
  });
23
23
  module.exports = __toCommonJS(env_exports);
24
- var import_universal = require("@modern-js/utils/universal");
24
+ var import_utils = require("@modern-js/utils");
25
25
  function getAutoInjectEnv(appContext) {
26
26
  const { metaName } = appContext;
27
- const prefix = `${(0, import_universal.cutNameByHyphen)(metaName)}_`.toUpperCase();
27
+ const prefix = `${(0, import_utils.cutNameByHyphen)(metaName)}_`.toUpperCase();
28
28
  const envReg = new RegExp(`^${prefix}`);
29
29
  return Object.keys(process.env).reduce((prev, key) => {
30
30
  const value = process.env[key];
@@ -4,16 +4,14 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { ResolvedConfigContext } from "@modern-js/core";
6
6
  import { DEFAULT_DEV_HOST } from "@modern-js/utils";
7
- import { createDevServer } from "@modern-js/server";
8
- import { initProdMiddlewares } from "@modern-js/prod-server";
9
7
  import { printInstructions } from "../utils/printInstructions";
10
- import { setServer } from "../utils/createServer";
8
+ import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
11
9
  import { generateRoutes } from "../utils/routes";
12
10
  import { buildServerConfig } from "../utils/config";
13
11
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
14
12
  var dev = function() {
15
13
  var _ref = _async_to_generator(function(api, options) {
16
- var devServerOptions, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
14
+ var devServerOptions, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
17
15
  var _arguments = arguments;
18
16
  return _ts_generator(this, function(_state) {
19
17
  switch (_state.label) {
@@ -29,7 +27,7 @@ var dev = function() {
29
27
  cliOptions: options
30
28
  });
31
29
  ResolvedConfigContext.set(normalizedConfig);
32
- appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
30
+ appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName;
33
31
  return [
34
32
  4,
35
33
  buildServerConfig({
@@ -63,23 +61,22 @@ var dev = function() {
63
61
  case 4:
64
62
  serverInternalPlugins = _state.sent();
65
63
  serverOptions = _object_spread({
66
- metaName,
67
64
  dev: _object_spread({
68
65
  port,
69
66
  https: normalizedConfig.dev.https,
70
67
  host: normalizedConfig.dev.host
71
68
  }, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
72
69
  appContext: {
73
- appDirectory,
70
+ metaName,
71
+ appDirectory: appContext.appDirectory,
72
+ sharedDirectory: appContext.sharedDirectory,
74
73
  apiDirectory: appContext.apiDirectory,
75
- lambdaDirectory: appContext.lambdaDirectory,
76
- sharedDirectory: appContext.sharedDirectory
74
+ lambdaDirectory: appContext.lambdaDirectory
77
75
  },
78
- routes: serverRoutes,
79
76
  pwd: appDirectory,
80
77
  config: normalizedConfig,
81
78
  serverConfigFile,
82
- internalPlugins: serverInternalPlugins
79
+ internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
83
80
  }, devServerOptions);
84
81
  if (!apiOnly)
85
82
  return [
@@ -88,7 +85,9 @@ var dev = function() {
88
85
  ];
89
86
  return [
90
87
  4,
91
- createDevServer(serverOptions, initProdMiddlewares)
88
+ createServer(_object_spread_props(_object_spread({}, serverOptions), {
89
+ compiler: null
90
+ }))
92
91
  ];
93
92
  case 5:
94
93
  app = _state.sent();
@@ -97,8 +96,21 @@ var dev = function() {
97
96
  port,
98
97
  host
99
98
  }, function() {
100
- printInstructions(hookRunners, appContext, normalizedConfig);
101
- });
99
+ var _ref2 = _async_to_generator(function(err) {
100
+ return _ts_generator(this, function(_state2) {
101
+ if (err) {
102
+ throw err;
103
+ }
104
+ printInstructions(hookRunners, appContext, normalizedConfig);
105
+ return [
106
+ 2
107
+ ];
108
+ });
109
+ });
110
+ return function(err) {
111
+ return _ref2.apply(this, arguments);
112
+ };
113
+ }());
102
114
  return [
103
115
  3,
104
116
  8
@@ -107,8 +119,7 @@ var dev = function() {
107
119
  return [
108
120
  4,
109
121
  appContext.builder.startDevServer({
110
- serverOptions,
111
- initProdMiddlewares
122
+ serverOptions
112
123
  })
113
124
  ];
114
125
  case 7:
@@ -3,19 +3,20 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
6
- import { createProdServer } from "@modern-js/prod-server";
6
+ import server from "@modern-js/prod-server";
7
7
  import { printInstructions } from "../utils/printInstructions";
8
+ import { injectDataLoaderPlugin } from "../utils/createServer";
8
9
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
9
10
  var start = function() {
10
11
  var _ref = _async_to_generator(function(api) {
11
- var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes, apiOnly, runMode, serverInternalPlugins, app;
12
+ var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, metaName, apiOnly, serverInternalPlugins, app;
12
13
  return _ts_generator(this, function(_state) {
13
14
  switch (_state.label) {
14
15
  case 0:
15
16
  appContext = api.useAppContext();
16
17
  userConfig = api.useResolvedConfigContext();
17
18
  hookRunners = api.useHookRunners();
18
- distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
19
+ appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName;
19
20
  logger.info("Starting production server...");
20
21
  return [
21
22
  4,
@@ -23,9 +24,6 @@ var start = function() {
23
24
  ];
24
25
  case 1:
25
26
  apiOnly = _state.sent();
26
- if (apiOnly) {
27
- runMode = "apiOnly";
28
- }
29
27
  return [
30
28
  4,
31
29
  getServerInternalPlugins(api)
@@ -34,45 +32,51 @@ var start = function() {
34
32
  serverInternalPlugins = _state.sent();
35
33
  return [
36
34
  4,
37
- createProdServer({
38
- metaName,
39
- pwd: distDirectory,
35
+ server({
36
+ pwd: appDirectory,
40
37
  config: _object_spread_props(_object_spread({}, userConfig), {
41
38
  dev: userConfig.dev,
42
39
  output: _object_spread({
43
40
  path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
44
41
  }, userConfig.output || {})
45
42
  }),
46
- routes: serverRoutes,
47
43
  appContext: {
48
- appDirectory,
44
+ metaName,
49
45
  sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
50
46
  apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
51
47
  lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
52
48
  },
53
49
  serverConfigFile,
54
- internalPlugins: serverInternalPlugins,
55
- runMode
50
+ internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
51
+ apiOnly
56
52
  })
57
53
  ];
58
54
  case 3:
59
55
  app = _state.sent();
60
- app.listen(port, /* @__PURE__ */ _async_to_generator(function() {
61
- return _ts_generator(this, function(_state2) {
62
- switch (_state2.label) {
63
- case 0:
64
- return [
65
- 4,
66
- printInstructions(hookRunners, appContext, userConfig)
67
- ];
68
- case 1:
69
- _state2.sent();
70
- return [
71
- 2
72
- ];
73
- }
56
+ app.listen(port, function() {
57
+ var _ref2 = _async_to_generator(function(err) {
58
+ return _ts_generator(this, function(_state2) {
59
+ switch (_state2.label) {
60
+ case 0:
61
+ if (err) {
62
+ throw err;
63
+ }
64
+ return [
65
+ 4,
66
+ printInstructions(hookRunners, appContext, userConfig)
67
+ ];
68
+ case 1:
69
+ _state2.sent();
70
+ return [
71
+ 2
72
+ ];
73
+ }
74
+ });
74
75
  });
75
- }));
76
+ return function(err) {
77
+ return _ref2.apply(this, arguments);
78
+ };
79
+ }());
76
80
  return [
77
81
  2
78
82
  ];
@@ -1,7 +1,8 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
2
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { createDevServer } from "@modern-js/server";
4
- import { initProdMiddlewares } from "@modern-js/prod-server";
5
+ import { Server } from "@modern-js/server";
5
6
  var server = null;
6
7
  var getServer = function() {
7
8
  return server;
@@ -12,13 +13,26 @@ var setServer = function(newServer) {
12
13
  var closeServer = function() {
13
14
  var _ref = _async_to_generator(function() {
14
15
  return _ts_generator(this, function(_state) {
15
- if (server) {
16
- server.close();
17
- server = null;
16
+ switch (_state.label) {
17
+ case 0:
18
+ if (!server)
19
+ return [
20
+ 3,
21
+ 2
22
+ ];
23
+ return [
24
+ 4,
25
+ server.close()
26
+ ];
27
+ case 1:
28
+ _state.sent();
29
+ server = null;
30
+ _state.label = 2;
31
+ case 2:
32
+ return [
33
+ 2
34
+ ];
18
35
  }
19
- return [
20
- 2
21
- ];
22
36
  });
23
37
  });
24
38
  return function closeServer2() {
@@ -27,21 +41,33 @@ var closeServer = function() {
27
41
  }();
28
42
  var createServer = function() {
29
43
  var _ref = _async_to_generator(function(options) {
44
+ var app;
30
45
  return _ts_generator(this, function(_state) {
31
46
  switch (_state.label) {
32
47
  case 0:
33
- if (server) {
34
- server.close();
35
- }
48
+ if (!server)
49
+ return [
50
+ 3,
51
+ 2
52
+ ];
36
53
  return [
37
54
  4,
38
- createDevServer(options, initProdMiddlewares)
55
+ server.close()
39
56
  ];
40
57
  case 1:
41
- server = _state.sent();
58
+ _state.sent();
59
+ _state.label = 2;
60
+ case 2:
61
+ server = new Server(options);
62
+ return [
63
+ 4,
64
+ server.init()
65
+ ];
66
+ case 3:
67
+ app = _state.sent();
42
68
  return [
43
69
  2,
44
- server
70
+ app
45
71
  ];
46
72
  }
47
73
  });
@@ -50,9 +76,19 @@ var createServer = function() {
50
76
  return _ref.apply(this, arguments);
51
77
  };
52
78
  }();
79
+ var injectDataLoaderPlugin = function(internalPlugins) {
80
+ var DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
81
+ return _object_spread_props(_object_spread({}, internalPlugins), {
82
+ "@modern-js/plugin-data-loader": {
83
+ path: DataLoaderPlugin,
84
+ forced: true
85
+ }
86
+ });
87
+ };
53
88
  export {
54
89
  closeServer,
55
90
  createServer,
56
91
  getServer,
92
+ injectDataLoaderPlugin,
57
93
  setServer
58
94
  };
@@ -1,4 +1,4 @@
1
- import { cutNameByHyphen } from "@modern-js/utils/universal";
1
+ import { cutNameByHyphen } from "@modern-js/utils";
2
2
  function getAutoInjectEnv(appContext) {
3
3
  var metaName = appContext.metaName;
4
4
  var prefix = "".concat(cutNameByHyphen(metaName), "_").toUpperCase();
@@ -1,9 +1,7 @@
1
1
  import { ResolvedConfigContext } from "@modern-js/core";
2
2
  import { DEFAULT_DEV_HOST } from "@modern-js/utils";
3
- import { createDevServer } from "@modern-js/server";
4
- import { initProdMiddlewares } from "@modern-js/prod-server";
5
3
  import { printInstructions } from "../utils/printInstructions";
6
- import { setServer } from "../utils/createServer";
4
+ import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
7
5
  import { generateRoutes } from "../utils/routes";
8
6
  import { buildServerConfig } from "../utils/config";
9
7
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
@@ -20,7 +18,7 @@ const dev = async (api, options, devServerOptions = {}) => {
20
18
  cliOptions: options
21
19
  };
22
20
  ResolvedConfigContext.set(normalizedConfig);
23
- const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
21
+ const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName } = appContext;
24
22
  await buildServerConfig({
25
23
  appDirectory,
26
24
  distDirectory,
@@ -34,7 +32,6 @@ const dev = async (api, options, devServerOptions = {}) => {
34
32
  await generateRoutes(appContext);
35
33
  const serverInternalPlugins = await getServerInternalPlugins(api);
36
34
  const serverOptions = {
37
- metaName,
38
35
  dev: {
39
36
  port,
40
37
  https: normalizedConfig.dev.https,
@@ -42,32 +39,37 @@ const dev = async (api, options, devServerOptions = {}) => {
42
39
  ...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
43
40
  },
44
41
  appContext: {
45
- appDirectory,
42
+ metaName,
43
+ appDirectory: appContext.appDirectory,
44
+ sharedDirectory: appContext.sharedDirectory,
46
45
  apiDirectory: appContext.apiDirectory,
47
- lambdaDirectory: appContext.lambdaDirectory,
48
- sharedDirectory: appContext.sharedDirectory
46
+ lambdaDirectory: appContext.lambdaDirectory
49
47
  },
50
- routes: serverRoutes,
51
48
  pwd: appDirectory,
52
49
  config: normalizedConfig,
53
50
  serverConfigFile,
54
- internalPlugins: serverInternalPlugins,
51
+ internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
55
52
  ...devServerOptions
56
53
  };
57
54
  if (apiOnly) {
58
55
  var _normalizedConfig_dev;
59
- const app = await createDevServer(serverOptions, initProdMiddlewares);
56
+ const app = await createServer({
57
+ ...serverOptions,
58
+ compiler: null
59
+ });
60
60
  const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
61
61
  app.listen({
62
62
  port,
63
63
  host
64
- }, () => {
64
+ }, async (err) => {
65
+ if (err) {
66
+ throw err;
67
+ }
65
68
  printInstructions(hookRunners, appContext, normalizedConfig);
66
69
  });
67
70
  } else {
68
71
  const { server } = await appContext.builder.startDevServer({
69
- serverOptions,
70
- initProdMiddlewares
72
+ serverOptions
71
73
  });
72
74
  setServer(server);
73
75
  }
@@ -1,23 +1,19 @@
1
1
  import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
2
- import { createProdServer } from "@modern-js/prod-server";
2
+ import server from "@modern-js/prod-server";
3
3
  import { printInstructions } from "../utils/printInstructions";
4
+ import { injectDataLoaderPlugin } from "../utils/createServer";
4
5
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
5
6
  const start = async (api) => {
6
7
  var _userConfig_source, _userConfig_output_distPath;
7
8
  const appContext = api.useAppContext();
8
9
  const userConfig = api.useResolvedConfigContext();
9
10
  const hookRunners = api.useHookRunners();
10
- const { distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes } = appContext;
11
+ const { appDirectory, port, serverConfigFile, metaName } = appContext;
11
12
  logger.info(`Starting production server...`);
12
13
  const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
13
- let runMode;
14
- if (apiOnly) {
15
- runMode = "apiOnly";
16
- }
17
14
  const serverInternalPlugins = await getServerInternalPlugins(api);
18
- const app = await createProdServer({
19
- metaName,
20
- pwd: distDirectory,
15
+ const app = await server({
16
+ pwd: appDirectory,
21
17
  config: {
22
18
  ...userConfig,
23
19
  dev: userConfig.dev,
@@ -26,18 +22,20 @@ const start = async (api) => {
26
22
  ...userConfig.output || {}
27
23
  }
28
24
  },
29
- routes: serverRoutes,
30
25
  appContext: {
31
- appDirectory,
26
+ metaName,
32
27
  sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
33
28
  apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
34
29
  lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
35
30
  },
36
31
  serverConfigFile,
37
- internalPlugins: serverInternalPlugins,
38
- runMode
32
+ internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
33
+ apiOnly
39
34
  });
40
- app.listen(port, async () => {
35
+ app.listen(port, async (err) => {
36
+ if (err) {
37
+ throw err;
38
+ }
41
39
  await printInstructions(hookRunners, appContext, userConfig);
42
40
  });
43
41
  };
@@ -1,5 +1,4 @@
1
- import { createDevServer } from "@modern-js/server";
2
- import { initProdMiddlewares } from "@modern-js/prod-server";
1
+ import { Server } from "@modern-js/server";
3
2
  let server = null;
4
3
  const getServer = () => server;
5
4
  const setServer = (newServer) => {
@@ -7,20 +6,32 @@ const setServer = (newServer) => {
7
6
  };
8
7
  const closeServer = async () => {
9
8
  if (server) {
10
- server.close();
9
+ await server.close();
11
10
  server = null;
12
11
  }
13
12
  };
14
13
  const createServer = async (options) => {
15
14
  if (server) {
16
- server.close();
15
+ await server.close();
17
16
  }
18
- server = await createDevServer(options, initProdMiddlewares);
19
- return server;
17
+ server = new Server(options);
18
+ const app = await server.init();
19
+ return app;
20
+ };
21
+ const injectDataLoaderPlugin = (internalPlugins) => {
22
+ const DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
23
+ return {
24
+ ...internalPlugins,
25
+ "@modern-js/plugin-data-loader": {
26
+ path: DataLoaderPlugin,
27
+ forced: true
28
+ }
29
+ };
20
30
  };
21
31
  export {
22
32
  closeServer,
23
33
  createServer,
24
34
  getServer,
35
+ injectDataLoaderPlugin,
25
36
  setServer
26
37
  };
@@ -1,4 +1,4 @@
1
- import { cutNameByHyphen } from "@modern-js/utils/universal";
1
+ import { cutNameByHyphen } from "@modern-js/utils";
2
2
  function getAutoInjectEnv(appContext) {
3
3
  const { metaName } = appContext;
4
4
  const prefix = `${cutNameByHyphen(metaName)}_`.toUpperCase();
@@ -1,10 +1,12 @@
1
- /// <reference types="node" />
2
- /// <reference types="node/http" />
3
- /// <reference types="@modern-js/server-core/dist/types/core/server" />
4
- /// <reference types="@modern-js/server-core/src/core/server" />
5
- import type { Server } from 'node:http';
6
- import { ModernDevServerOptions } from '@modern-js/server';
7
- export declare const getServer: () => Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | null;
1
+ import { Server, ModernDevServerOptions } from '@modern-js/server';
2
+ import type { InternalPlugins } from '@modern-js/types';
3
+ export declare const getServer: () => Server | null;
8
4
  export declare const setServer: (newServer: Server) => void;
9
5
  export declare const closeServer: () => Promise<void>;
10
6
  export declare const createServer: (options: ModernDevServerOptions) => Promise<Server>;
7
+ export declare const injectDataLoaderPlugin: (internalPlugins: InternalPlugins) => {
8
+ '@modern-js/plugin-data-loader': {
9
+ path: string;
10
+ forced: boolean;
11
+ };
12
+ };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.48.5-alpha.0",
18
+ "version": "2.48.5",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -76,19 +76,19 @@
76
76
  "es-module-lexer": "^1.1.0",
77
77
  "esbuild": "0.17.19",
78
78
  "@swc/helpers": "0.5.3",
79
- "@modern-js/uni-builder": "2.48.4",
80
- "@modern-js/plugin": "2.48.4",
81
- "@modern-js/core": "2.48.4",
82
- "@modern-js/plugin-i18n": "2.48.4",
83
- "@modern-js/node-bundle-require": "2.48.4",
84
- "@modern-js/plugin-lint": "2.48.4",
85
- "@modern-js/prod-server": "2.48.4",
86
- "@modern-js/server": "2.48.4",
87
- "@modern-js/types": "2.48.4",
88
- "@modern-js/utils": "2.48.4",
89
- "@modern-js/plugin-data-loader": "2.48.4",
90
- "@modern-js/server-utils": "2.48.5-alpha.0",
91
- "@modern-js/server-core": "2.48.5-alpha.1"
79
+ "@modern-js/uni-builder": "2.48.5",
80
+ "@modern-js/node-bundle-require": "2.48.5",
81
+ "@modern-js/core": "2.48.5",
82
+ "@modern-js/plugin-data-loader": "2.48.5",
83
+ "@modern-js/plugin": "2.48.5",
84
+ "@modern-js/plugin-lint": "2.48.5",
85
+ "@modern-js/plugin-i18n": "2.48.5",
86
+ "@modern-js/prod-server": "2.48.5",
87
+ "@modern-js/server-utils": "2.48.5",
88
+ "@modern-js/server": "2.48.5",
89
+ "@modern-js/types": "2.48.5",
90
+ "@modern-js/utils": "2.48.5",
91
+ "@modern-js/server-core": "2.48.5"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@rsbuild/plugin-swc": "0.5.4",
@@ -98,8 +98,8 @@
98
98
  "jest": "^29",
99
99
  "typescript": "^5",
100
100
  "webpack": "^5.91.0",
101
- "@scripts/build": "2.48.4",
102
- "@scripts/jest-config": "2.48.4"
101
+ "@scripts/jest-config": "2.48.5",
102
+ "@scripts/build": "2.48.5"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {