@modern-js/server-core 2.58.1 → 2.58.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 (49) hide show
  1. package/dist/cjs/adapters/node/helper/loadCache.js +2 -2
  2. package/dist/cjs/adapters/node/helper/loadConfig.js +10 -10
  3. package/dist/cjs/adapters/node/helper/loadPlugin.js +4 -4
  4. package/dist/cjs/adapters/node/node.js +2 -2
  5. package/dist/cjs/adapters/node/plugins/resource.js +9 -14
  6. package/dist/cjs/plugins/customServer/index.js +9 -3
  7. package/dist/cjs/plugins/render/render.js +2 -1
  8. package/dist/cjs/utils/warmup.js +1 -11
  9. package/dist/esm/adapters/node/helper/loadCache.js +35 -10
  10. package/dist/esm/adapters/node/helper/loadConfig.js +118 -22
  11. package/dist/esm/adapters/node/helper/loadPlugin.js +51 -9
  12. package/dist/esm/adapters/node/plugins/resource.js +31 -16
  13. package/dist/esm/plugins/customServer/index.js +11 -5
  14. package/dist/esm/plugins/render/render.js +2 -1
  15. package/dist/esm-node/adapters/node/helper/loadCache.js +2 -2
  16. package/dist/esm-node/adapters/node/helper/loadConfig.js +11 -11
  17. package/dist/esm-node/adapters/node/helper/loadPlugin.js +5 -5
  18. package/dist/esm-node/adapters/node/plugins/resource.js +10 -15
  19. package/dist/esm-node/plugins/customServer/index.js +9 -3
  20. package/dist/esm-node/plugins/render/render.js +2 -1
  21. package/dist/types/adapters/node/helper/loadCache.d.ts +2 -2
  22. package/dist/types/adapters/node/helper/loadConfig.d.ts +2 -2
  23. package/dist/types/adapters/node/helper/loadPlugin.d.ts +3 -3
  24. package/dist/types/adapters/node/hono.d.ts +1 -1
  25. package/dist/types/adapters/node/node.d.ts +2 -2
  26. package/dist/types/adapters/node/plugins/nodeServer.d.ts +1 -1
  27. package/dist/types/adapters/node/plugins/resource.d.ts +1 -1
  28. package/dist/types/adapters/node/plugins/static.d.ts +1 -1
  29. package/dist/types/plugins/customServer/base.d.ts +1 -1
  30. package/dist/types/plugins/customServer/context.d.ts +3 -3
  31. package/dist/types/plugins/customServer/index.d.ts +3 -3
  32. package/dist/types/plugins/default.d.ts +2 -2
  33. package/dist/types/plugins/favicon.d.ts +1 -1
  34. package/dist/types/plugins/processedBy.d.ts +1 -1
  35. package/dist/types/plugins/render/dataHandler.d.ts +1 -1
  36. package/dist/types/plugins/render/index.d.ts +1 -1
  37. package/dist/types/plugins/render/render.d.ts +2 -2
  38. package/dist/types/plugins/render/ssrCache.d.ts +1 -1
  39. package/dist/types/plugins/render/ssrRender.d.ts +2 -2
  40. package/dist/types/serverBase.d.ts +1 -1
  41. package/dist/types/types/config/index.d.ts +8 -8
  42. package/dist/types/types/config/tools.d.ts +2 -2
  43. package/dist/types/types/plugin.d.ts +6 -6
  44. package/dist/types/types/requestHandler.d.ts +2 -2
  45. package/dist/types/types/server.d.ts +1 -1
  46. package/dist/types/utils/entry.d.ts +1 -1
  47. package/dist/types/utils/serverConfig.d.ts +1 -1
  48. package/dist/types/utils/transformStream.d.ts +1 -1
  49. package/package.json +7 -7
@@ -34,9 +34,9 @@ module.exports = __toCommonJS(loadCache_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
36
  const CACHE_FILENAME = "cache";
37
- function loadCacheConfig(pwd) {
37
+ async function loadCacheConfig(pwd) {
38
38
  const serverCacheFilepath = import_path.default.resolve(pwd, import_utils.SERVER_DIR, CACHE_FILENAME);
39
- const mod = (0, import_utils.requireExistModule)(serverCacheFilepath, {
39
+ const mod = await (0, import_utils.requireExistModule)(serverCacheFilepath, {
40
40
  interop: false
41
41
  });
42
42
  if (mod === null || mod === void 0 ? void 0 : mod.cacheOption) {
@@ -35,30 +35,30 @@ module.exports = __toCommonJS(loadConfig_exports);
35
35
  var import_path = __toESM(require("path"));
36
36
  var import_utils = require("@modern-js/utils");
37
37
  var import_flatted = require("flatted");
38
- const requireConfig = (serverConfigPath) => {
38
+ const requireConfig = async (serverConfigPath) => {
39
39
  if (import_utils.fs.pathExistsSync(serverConfigPath)) {
40
- return (0, import_utils.compatRequire)(serverConfigPath);
40
+ return (0, import_utils.compatibleRequire)(serverConfigPath);
41
41
  }
42
42
  return void 0;
43
43
  };
44
- function loadServerConfigNew(serverConfigPath) {
45
- const mod = (0, import_utils.requireExistModule)(serverConfigPath);
44
+ async function loadServerConfigNew(serverConfigPath) {
45
+ const mod = await (0, import_utils.requireExistModule)(serverConfigPath);
46
46
  if (mod) {
47
47
  return mod;
48
48
  }
49
49
  return void 0;
50
50
  }
51
- function loadServerConfigOld(pwd, configFile) {
52
- const serverConfigPath = import_path.default.join(pwd, `${configFile}.js`);
53
- const serverConfig = requireConfig(serverConfigPath);
51
+ async function loadServerConfigOld(pwd, configFile) {
52
+ const serverConfigPath = import_path.default.join(pwd, `${configFile}.cjs`);
53
+ const serverConfig = await requireConfig(serverConfigPath);
54
54
  return serverConfig;
55
55
  }
56
- function loadServerRuntimeConfig(pwd, oldServerFile = import_utils.DEFAULT_SERVER_CONFIG, newServerConfigPath) {
57
- const newServerConfig = newServerConfigPath && loadServerConfigNew(newServerConfigPath);
56
+ async function loadServerRuntimeConfig(pwd, oldServerFile = import_utils.DEFAULT_SERVER_CONFIG, newServerConfigPath) {
57
+ const newServerConfig = newServerConfigPath && await loadServerConfigNew(newServerConfigPath);
58
58
  if (newServerConfig) {
59
59
  return newServerConfig;
60
60
  }
61
- const oldServerConfig = loadServerConfigOld(pwd, oldServerFile);
61
+ const oldServerConfig = await loadServerConfigOld(pwd, oldServerFile);
62
62
  return oldServerConfig;
63
63
  }
64
64
  function loadServerCliConfig(pwd, defaultConfig = {}) {
@@ -22,15 +22,15 @@ __export(loadPlugin_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(loadPlugin_exports);
24
24
  var import_utils = require("@modern-js/utils");
25
- function resolveServerPlugin(plugin, appDirectory) {
25
+ async function resolveServerPlugin(plugin, appDirectory) {
26
26
  const { name, options } = plugin;
27
27
  const pluginPath = (0, import_utils.tryResolve)(name, appDirectory);
28
- const module2 = (0, import_utils.compatRequire)(pluginPath);
28
+ const module2 = await (0, import_utils.compatibleRequire)(pluginPath);
29
29
  const pluginInstance = module2(options);
30
30
  return pluginInstance;
31
31
  }
32
- function loadServerPlugins(serverPlugins, appDirectory) {
33
- const instances = serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory));
32
+ async function loadServerPlugins(serverPlugins, appDirectory) {
33
+ const instances = await Promise.all(serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory)));
34
34
  return instances;
35
35
  }
36
36
  // Annotate the CommonJS export names for ESM import in node:
@@ -128,10 +128,10 @@ const createNodeServer = async (requestHandler, httpsOptions) => {
128
128
  const requestListener = getRequestListener(requestHandler);
129
129
  let nodeServer;
130
130
  if (httpsOptions) {
131
- const { createServer } = await Promise.resolve().then(() => __toESM(require("node:https")));
131
+ const { createServer } = await import("node:https");
132
132
  nodeServer = createServer(httpsOptions, requestListener);
133
133
  } else {
134
- const { createServer } = await Promise.resolve().then(() => __toESM(require("node:http")));
134
+ const { createServer } = await import("node:http");
135
135
  nodeServer = createServer(requestListener);
136
136
  }
137
137
  nodeServer.getRequestListener = () => requestListener;
@@ -64,22 +64,17 @@ function injectTemplates(pwd, routes) {
64
64
  await next();
65
65
  };
66
66
  }
67
- const dynamicImport = (filePath) => {
68
- try {
69
- const module2 = require(filePath);
70
- return Promise.resolve(module2);
71
- } catch (e) {
72
- return Promise.reject(e);
73
- }
74
- };
75
67
  const loadBundle = async (filepath, logger) => {
76
68
  if (!await import_utils.fs.pathExists(filepath)) {
77
69
  return void 0;
78
70
  }
79
- return dynamicImport(filepath).catch((e) => {
80
- logger === null || logger === void 0 ? void 0 : logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
71
+ try {
72
+ const module2 = await (0, import_utils.compatibleRequire)(filepath, false);
73
+ return module2;
74
+ } catch (e) {
75
+ logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
81
76
  return void 0;
82
- });
77
+ }
83
78
  };
84
79
  async function getServerManifest(pwd, routes, logger) {
85
80
  const loaderBundles = {};
@@ -94,11 +89,11 @@ async function getServerManifest(pwd, routes, logger) {
94
89
  loaderBundle && (loaderBundles[entryName] = loaderBundle);
95
90
  }));
96
91
  const loadableUri = import_path.default.join(pwd, import_utils.LOADABLE_STATS_FILE);
97
- const loadableStats = await Promise.resolve().then(() => __toESM(require(loadableUri))).catch((_) => ({}));
92
+ const loadableStats = await (0, import_utils.compatibleRequire)(loadableUri).catch((_) => ({}));
98
93
  const routesManifestUri = import_path.default.join(pwd, import_utils.ROUTE_MANIFEST_FILE);
99
- const routeManifest = await Promise.resolve().then(() => __toESM(require(routesManifestUri))).catch((_) => ({}));
94
+ const routeManifest = await (0, import_utils.compatibleRequire)(routesManifestUri).catch((_) => ({}));
100
95
  const nestedRoutesJsonPath = import_path.default.join(pwd, import_utils.NESTED_ROUTE_SPEC_FILE);
101
- const nestedRoutesJson = await Promise.resolve().then(() => __toESM(require(nestedRoutesJsonPath))).catch((_) => ({}));
96
+ const nestedRoutesJson = await (0, import_utils.compatibleRequire)(nestedRoutesJsonPath).catch((_) => ({}));
102
97
  return {
103
98
  loaderBundles,
104
99
  renderBundles,
@@ -65,7 +65,14 @@ class CustomServer {
65
65
  if (current !== entryName) {
66
66
  const rewriteRoute = routes.find((route) => route.entryName === current);
67
67
  if (rewriteRoute) {
68
- return this.serverBase.request(rewriteRoute.urlPath);
68
+ const { headers, method, signal } = c.req.raw;
69
+ const url2 = new URL(c.req.url);
70
+ const newUrl = new URL(rewriteRoute.urlPath, url2.origin);
71
+ return this.serverBase.request(newUrl, {
72
+ headers,
73
+ method,
74
+ signal
75
+ }, c.env);
69
76
  }
70
77
  }
71
78
  if (c.finalized) {
@@ -175,8 +182,7 @@ async function createMiddlewareContextFromHono(c) {
175
182
  "GET",
176
183
  "HEAD"
177
184
  ].includes(method) && !rawRequest.body && c.env.node.req) {
178
- const streamPath = "../../adapters/node/polyfills/stream";
179
- const { createReadableStreamFromReadable } = await Promise.resolve().then(() => __toESM(require(streamPath)));
185
+ const { createReadableStreamFromReadable } = await import("../../adapters/node/polyfills/stream.js");
180
186
  const init = {
181
187
  body: createReadableStreamFromReadable(c.env.node.req),
182
188
  headers: rawRequest.headers,
@@ -37,6 +37,7 @@ var import_utils = require("../../utils");
37
37
  var import_constants = require("../../constants");
38
38
  var import_dataHandler = require("./dataHandler");
39
39
  var import_ssrRender = require("./ssrRender");
40
+ var import_utils2 = require("@modern-js/utils");
40
41
  const DYNAMIC_ROUTE_REG = /\/:./;
41
42
  function getRouter(routes) {
42
43
  const dynamicRoutes = [];
@@ -164,7 +165,7 @@ async function renderHandler(request, options, mode, onError) {
164
165
  const { nestedRoutesJson } = serverManifest;
165
166
  const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
166
167
  if (routes) {
167
- const { matchRoutes } = await Promise.resolve().then(() => __toESM(require("@modern-js/runtime-utils/remix-router")));
168
+ const { matchRoutes } = await (0, import_utils2.compatibleRequire)(require.resolve("@modern-js/runtime-utils/remix-router"), false);
168
169
  const url = new URL(request.url);
169
170
  const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
170
171
  if (!matchedRoutes) {
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var warmup_exports = {};
30
20
  __export(warmup_exports, {
@@ -33,7 +23,7 @@ __export(warmup_exports, {
33
23
  module.exports = __toCommonJS(warmup_exports);
34
24
  function warmup(bundles) {
35
25
  bundles.forEach((bundle) => {
36
- bundle && Promise.resolve().then(() => __toESM(require(bundle))).catch((_) => {
26
+ bundle && import(bundle).catch((_) => {
37
27
  });
38
28
  });
39
29
  }
@@ -1,18 +1,43 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
1
3
  import path from "path";
2
4
  import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
3
5
  var CACHE_FILENAME = "cache";
4
6
  function loadCacheConfig(pwd) {
5
- var serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
6
- var mod = requireExistModule(serverCacheFilepath, {
7
- interop: false
7
+ return _loadCacheConfig.apply(this, arguments);
8
+ }
9
+ function _loadCacheConfig() {
10
+ _loadCacheConfig = _async_to_generator(function(pwd) {
11
+ var serverCacheFilepath, mod;
12
+ return _ts_generator(this, function(_state) {
13
+ switch (_state.label) {
14
+ case 0:
15
+ serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
16
+ return [
17
+ 4,
18
+ requireExistModule(serverCacheFilepath, {
19
+ interop: false
20
+ })
21
+ ];
22
+ case 1:
23
+ mod = _state.sent();
24
+ if (mod === null || mod === void 0 ? void 0 : mod.cacheOption) {
25
+ return [
26
+ 2,
27
+ {
28
+ strategy: mod.cacheOption,
29
+ container: mod.customContainer
30
+ }
31
+ ];
32
+ }
33
+ return [
34
+ 2,
35
+ void 0
36
+ ];
37
+ }
38
+ });
8
39
  });
9
- if (mod === null || mod === void 0 ? void 0 : mod.cacheOption) {
10
- return {
11
- strategy: mod.cacheOption,
12
- container: mod.customContainer
13
- };
14
- }
15
- return void 0;
40
+ return _loadCacheConfig.apply(this, arguments);
16
41
  }
17
42
  export {
18
43
  loadCacheConfig
@@ -1,32 +1,128 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
1
3
  import path from "path";
2
- import { compatRequire, fs, DEFAULT_SERVER_CONFIG, requireExistModule, ensureAbsolutePath, OUTPUT_CONFIG_FILE, lodash as _ } from "@modern-js/utils";
4
+ import { fs, DEFAULT_SERVER_CONFIG, requireExistModule, ensureAbsolutePath, OUTPUT_CONFIG_FILE, lodash as _, compatibleRequire } from "@modern-js/utils";
3
5
  import { parse } from "flatted";
4
- var requireConfig = function(serverConfigPath) {
5
- if (fs.pathExistsSync(serverConfigPath)) {
6
- return compatRequire(serverConfigPath);
7
- }
8
- return void 0;
9
- };
6
+ var requireConfig = function() {
7
+ var _ref = _async_to_generator(function(serverConfigPath) {
8
+ return _ts_generator(this, function(_state) {
9
+ if (fs.pathExistsSync(serverConfigPath)) {
10
+ return [
11
+ 2,
12
+ compatibleRequire(serverConfigPath)
13
+ ];
14
+ }
15
+ return [
16
+ 2,
17
+ void 0
18
+ ];
19
+ });
20
+ });
21
+ return function requireConfig2(serverConfigPath) {
22
+ return _ref.apply(this, arguments);
23
+ };
24
+ }();
10
25
  function loadServerConfigNew(serverConfigPath) {
11
- var mod = requireExistModule(serverConfigPath);
12
- if (mod) {
13
- return mod;
14
- }
15
- return void 0;
26
+ return _loadServerConfigNew.apply(this, arguments);
27
+ }
28
+ function _loadServerConfigNew() {
29
+ _loadServerConfigNew = _async_to_generator(function(serverConfigPath) {
30
+ var mod;
31
+ return _ts_generator(this, function(_state) {
32
+ switch (_state.label) {
33
+ case 0:
34
+ return [
35
+ 4,
36
+ requireExistModule(serverConfigPath)
37
+ ];
38
+ case 1:
39
+ mod = _state.sent();
40
+ if (mod) {
41
+ return [
42
+ 2,
43
+ mod
44
+ ];
45
+ }
46
+ return [
47
+ 2,
48
+ void 0
49
+ ];
50
+ }
51
+ });
52
+ });
53
+ return _loadServerConfigNew.apply(this, arguments);
16
54
  }
17
55
  function loadServerConfigOld(pwd, configFile) {
18
- var serverConfigPath = path.join(pwd, "".concat(configFile, ".js"));
19
- var serverConfig = requireConfig(serverConfigPath);
20
- return serverConfig;
56
+ return _loadServerConfigOld.apply(this, arguments);
57
+ }
58
+ function _loadServerConfigOld() {
59
+ _loadServerConfigOld = _async_to_generator(function(pwd, configFile) {
60
+ var serverConfigPath, serverConfig;
61
+ return _ts_generator(this, function(_state) {
62
+ switch (_state.label) {
63
+ case 0:
64
+ serverConfigPath = path.join(pwd, "".concat(configFile, ".cjs"));
65
+ return [
66
+ 4,
67
+ requireConfig(serverConfigPath)
68
+ ];
69
+ case 1:
70
+ serverConfig = _state.sent();
71
+ return [
72
+ 2,
73
+ serverConfig
74
+ ];
75
+ }
76
+ });
77
+ });
78
+ return _loadServerConfigOld.apply(this, arguments);
21
79
  }
22
80
  function loadServerRuntimeConfig(pwd) {
23
- var oldServerFile = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_SERVER_CONFIG, newServerConfigPath = arguments.length > 2 ? arguments[2] : void 0;
24
- var newServerConfig = newServerConfigPath && loadServerConfigNew(newServerConfigPath);
25
- if (newServerConfig) {
26
- return newServerConfig;
27
- }
28
- var oldServerConfig = loadServerConfigOld(pwd, oldServerFile);
29
- return oldServerConfig;
81
+ return _loadServerRuntimeConfig.apply(this, arguments);
82
+ }
83
+ function _loadServerRuntimeConfig() {
84
+ _loadServerRuntimeConfig = _async_to_generator(function(pwd) {
85
+ var oldServerFile, newServerConfigPath, newServerConfig, _tmp, oldServerConfig;
86
+ var _arguments = arguments;
87
+ return _ts_generator(this, function(_state) {
88
+ switch (_state.label) {
89
+ case 0:
90
+ oldServerFile = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : DEFAULT_SERVER_CONFIG, newServerConfigPath = _arguments.length > 2 ? _arguments[2] : void 0;
91
+ _tmp = newServerConfigPath;
92
+ if (!_tmp)
93
+ return [
94
+ 3,
95
+ 2
96
+ ];
97
+ return [
98
+ 4,
99
+ loadServerConfigNew(newServerConfigPath)
100
+ ];
101
+ case 1:
102
+ _tmp = _state.sent();
103
+ _state.label = 2;
104
+ case 2:
105
+ newServerConfig = _tmp;
106
+ if (newServerConfig) {
107
+ return [
108
+ 2,
109
+ newServerConfig
110
+ ];
111
+ }
112
+ return [
113
+ 4,
114
+ loadServerConfigOld(pwd, oldServerFile)
115
+ ];
116
+ case 3:
117
+ oldServerConfig = _state.sent();
118
+ return [
119
+ 2,
120
+ oldServerConfig
121
+ ];
122
+ }
123
+ });
124
+ });
125
+ return _loadServerRuntimeConfig.apply(this, arguments);
30
126
  }
31
127
  function loadServerCliConfig(pwd) {
32
128
  var defaultConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
@@ -1,16 +1,58 @@
1
- import { compatRequire, tryResolve } from "@modern-js/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 { compatibleRequire, tryResolve } from "@modern-js/utils";
2
4
  function resolveServerPlugin(plugin, appDirectory) {
3
- var name = plugin.name, options = plugin.options;
4
- var pluginPath = tryResolve(name, appDirectory);
5
- var module = compatRequire(pluginPath);
6
- var pluginInstance = module(options);
7
- return pluginInstance;
5
+ return _resolveServerPlugin.apply(this, arguments);
6
+ }
7
+ function _resolveServerPlugin() {
8
+ _resolveServerPlugin = _async_to_generator(function(plugin, appDirectory) {
9
+ var name, options, pluginPath, module, pluginInstance;
10
+ return _ts_generator(this, function(_state) {
11
+ switch (_state.label) {
12
+ case 0:
13
+ name = plugin.name, options = plugin.options;
14
+ pluginPath = tryResolve(name, appDirectory);
15
+ return [
16
+ 4,
17
+ compatibleRequire(pluginPath)
18
+ ];
19
+ case 1:
20
+ module = _state.sent();
21
+ pluginInstance = module(options);
22
+ return [
23
+ 2,
24
+ pluginInstance
25
+ ];
26
+ }
27
+ });
28
+ });
29
+ return _resolveServerPlugin.apply(this, arguments);
8
30
  }
9
31
  function loadServerPlugins(serverPlugins, appDirectory) {
10
- var instances = serverPlugins.map(function(plugin) {
11
- return resolveServerPlugin(plugin, appDirectory);
32
+ return _loadServerPlugins.apply(this, arguments);
33
+ }
34
+ function _loadServerPlugins() {
35
+ _loadServerPlugins = _async_to_generator(function(serverPlugins, appDirectory) {
36
+ var instances;
37
+ return _ts_generator(this, function(_state) {
38
+ switch (_state.label) {
39
+ case 0:
40
+ return [
41
+ 4,
42
+ Promise.all(serverPlugins.map(function(plugin) {
43
+ return resolveServerPlugin(plugin, appDirectory);
44
+ }))
45
+ ];
46
+ case 1:
47
+ instances = _state.sent();
48
+ return [
49
+ 2,
50
+ instances
51
+ ];
52
+ }
53
+ });
12
54
  });
13
- return instances;
55
+ return _loadServerPlugins.apply(this, arguments);
14
56
  }
15
57
  export {
16
58
  loadServerPlugins
@@ -3,7 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import path from "path";
5
5
  import { fileReader } from "@modern-js/runtime-utils/fileReader";
6
- import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs } from "@modern-js/utils";
6
+ import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs, compatibleRequire } from "@modern-js/utils";
7
7
  function getHtmlTemplates(pwd, routes) {
8
8
  return _getHtmlTemplates.apply(this, arguments);
9
9
  }
@@ -110,16 +110,9 @@ function injectTemplates(pwd, routes) {
110
110
  };
111
111
  }();
112
112
  }
113
- var dynamicImport = function(filePath) {
114
- try {
115
- var module = require(filePath);
116
- return Promise.resolve(module);
117
- } catch (e) {
118
- return Promise.reject(e);
119
- }
120
- };
121
113
  var loadBundle = function() {
122
114
  var _ref = _async_to_generator(function(filepath, logger) {
115
+ var module, e;
123
116
  return _ts_generator(this, function(_state) {
124
117
  switch (_state.label) {
125
118
  case 0:
@@ -134,12 +127,34 @@ var loadBundle = function() {
134
127
  void 0
135
128
  ];
136
129
  }
130
+ _state.label = 2;
131
+ case 2:
132
+ _state.trys.push([
133
+ 2,
134
+ 4,
135
+ ,
136
+ 5
137
+ ]);
138
+ return [
139
+ 4,
140
+ compatibleRequire(filepath, false)
141
+ ];
142
+ case 3:
143
+ module = _state.sent();
137
144
  return [
138
145
  2,
139
- dynamicImport(filepath).catch(function(e) {
140
- logger === null || logger === void 0 ? void 0 : logger.error("Load ".concat(filepath, " bundle failed, error = %s"), _instanceof(e, Error) ? e.stack || e.message : e);
141
- return void 0;
142
- })
146
+ module
147
+ ];
148
+ case 4:
149
+ e = _state.sent();
150
+ logger.error("Load ".concat(filepath, " bundle failed, error = %s"), _instanceof(e, Error) ? e.stack || e.message : e);
151
+ return [
152
+ 2,
153
+ void 0
154
+ ];
155
+ case 5:
156
+ return [
157
+ 2
143
158
  ];
144
159
  }
145
160
  });
@@ -202,7 +217,7 @@ function _getServerManifest() {
202
217
  loadableUri = path.join(pwd, LOADABLE_STATS_FILE);
203
218
  return [
204
219
  4,
205
- import(loadableUri).catch(function(_) {
220
+ compatibleRequire(loadableUri).catch(function(_) {
206
221
  return {};
207
222
  })
208
223
  ];
@@ -211,7 +226,7 @@ function _getServerManifest() {
211
226
  routesManifestUri = path.join(pwd, ROUTE_MANIFEST_FILE);
212
227
  return [
213
228
  4,
214
- import(routesManifestUri).catch(function(_) {
229
+ compatibleRequire(routesManifestUri).catch(function(_) {
215
230
  return {};
216
231
  })
217
232
  ];
@@ -220,7 +235,7 @@ function _getServerManifest() {
220
235
  nestedRoutesJsonPath = path.join(pwd, NESTED_ROUTE_SPEC_FILE);
221
236
  return [
222
237
  4,
223
- import(nestedRoutesJsonPath).catch(function(_) {
238
+ compatibleRequire(nestedRoutesJsonPath).catch(function(_) {
224
239
  return {};
225
240
  })
226
241
  ];
@@ -36,7 +36,7 @@ var CustomServer = /* @__PURE__ */ function() {
36
36
  var _this = this;
37
37
  return function() {
38
38
  var _ref = _async_to_generator(function(c, next) {
39
- var routeInfo, monitors, baseHookCtx, afterMatchCtx, getCost, cost, _afterMatchCtx_router, url, status, current, rewriteRoute, afterStreamingRenderContext, afterRenderCtx, getCost1, cost1, newBody;
39
+ var routeInfo, monitors, baseHookCtx, afterMatchCtx, getCost, cost, _afterMatchCtx_router, url, status, current, rewriteRoute, _c_req_raw, headers, method, signal, url1, newUrl, afterStreamingRenderContext, afterRenderCtx, getCost1, cost1, newBody;
40
40
  return _ts_generator(this, function(_state) {
41
41
  switch (_state.label) {
42
42
  case 0:
@@ -70,9 +70,16 @@ var CustomServer = /* @__PURE__ */ function() {
70
70
  return route.entryName === current;
71
71
  });
72
72
  if (rewriteRoute) {
73
+ _c_req_raw = c.req.raw, headers = _c_req_raw.headers, method = _c_req_raw.method, signal = _c_req_raw.signal;
74
+ url1 = new URL(c.req.url);
75
+ newUrl = new URL(rewriteRoute.urlPath, url1.origin);
73
76
  return [
74
77
  2,
75
- _this.serverBase.request(rewriteRoute.urlPath)
78
+ _this.serverBase.request(newUrl, {
79
+ headers,
80
+ method,
81
+ signal
82
+ }, c.env)
76
83
  ];
77
84
  }
78
85
  }
@@ -281,7 +288,7 @@ function createMiddlewareContextFromHono(c) {
281
288
  }
282
289
  function _createMiddlewareContextFromHono() {
283
290
  _createMiddlewareContextFromHono = _async_to_generator(function(c) {
284
- var loaderContext, rawRequest, method, streamPath, createReadableStreamFromReadable, init;
291
+ var loaderContext, rawRequest, method, createReadableStreamFromReadable, init;
285
292
  return _ts_generator(this, function(_state) {
286
293
  switch (_state.label) {
287
294
  case 0:
@@ -296,10 +303,9 @@ function _createMiddlewareContextFromHono() {
296
303
  3,
297
304
  2
298
305
  ];
299
- streamPath = "../../adapters/node/polyfills/stream";
300
306
  return [
301
307
  4,
302
- import(streamPath)
308
+ import("../../adapters/node/polyfills/stream.js")
303
309
  ];
304
310
  case 1:
305
311
  createReadableStreamFromReadable = _state.sent().createReadableStreamFromReadable;
@@ -12,6 +12,7 @@ import { parseQuery, getPathname, createErrorHtml, sortRoutes, transformResponse
12
12
  import { REPLACE_REG, X_MODERNJS_RENDER } from "../../constants";
13
13
  import { dataHandler } from "./dataHandler";
14
14
  import { ssrRender } from "./ssrRender";
15
+ import { compatibleRequire } from "@modern-js/utils";
15
16
  var DYNAMIC_ROUTE_REG = /\/:./;
16
17
  function getRouter(routes) {
17
18
  var dynamicRoutes = [];
@@ -290,7 +291,7 @@ function _renderHandler() {
290
291
  ];
291
292
  return [
292
293
  4,
293
- import("@modern-js/runtime-utils/remix-router")
294
+ compatibleRequire(require.resolve("@modern-js/runtime-utils/remix-router"), false)
294
295
  ];
295
296
  case 1:
296
297
  matchRoutes = _state.sent().matchRoutes;
@@ -1,9 +1,9 @@
1
1
  import path from "path";
2
2
  import { SERVER_DIR, requireExistModule } from "@modern-js/utils";
3
3
  const CACHE_FILENAME = "cache";
4
- function loadCacheConfig(pwd) {
4
+ async function loadCacheConfig(pwd) {
5
5
  const serverCacheFilepath = path.resolve(pwd, SERVER_DIR, CACHE_FILENAME);
6
- const mod = requireExistModule(serverCacheFilepath, {
6
+ const mod = await requireExistModule(serverCacheFilepath, {
7
7
  interop: false
8
8
  });
9
9
  if (mod === null || mod === void 0 ? void 0 : mod.cacheOption) {
@@ -1,30 +1,30 @@
1
1
  import path from "path";
2
- import { compatRequire, fs, DEFAULT_SERVER_CONFIG, requireExistModule, ensureAbsolutePath, OUTPUT_CONFIG_FILE, lodash as _ } from "@modern-js/utils";
2
+ import { fs, DEFAULT_SERVER_CONFIG, requireExistModule, ensureAbsolutePath, OUTPUT_CONFIG_FILE, lodash as _, compatibleRequire } from "@modern-js/utils";
3
3
  import { parse } from "flatted";
4
- const requireConfig = (serverConfigPath) => {
4
+ const requireConfig = async (serverConfigPath) => {
5
5
  if (fs.pathExistsSync(serverConfigPath)) {
6
- return compatRequire(serverConfigPath);
6
+ return compatibleRequire(serverConfigPath);
7
7
  }
8
8
  return void 0;
9
9
  };
10
- function loadServerConfigNew(serverConfigPath) {
11
- const mod = requireExistModule(serverConfigPath);
10
+ async function loadServerConfigNew(serverConfigPath) {
11
+ const mod = await requireExistModule(serverConfigPath);
12
12
  if (mod) {
13
13
  return mod;
14
14
  }
15
15
  return void 0;
16
16
  }
17
- function loadServerConfigOld(pwd, configFile) {
18
- const serverConfigPath = path.join(pwd, `${configFile}.js`);
19
- const serverConfig = requireConfig(serverConfigPath);
17
+ async function loadServerConfigOld(pwd, configFile) {
18
+ const serverConfigPath = path.join(pwd, `${configFile}.cjs`);
19
+ const serverConfig = await requireConfig(serverConfigPath);
20
20
  return serverConfig;
21
21
  }
22
- function loadServerRuntimeConfig(pwd, oldServerFile = DEFAULT_SERVER_CONFIG, newServerConfigPath) {
23
- const newServerConfig = newServerConfigPath && loadServerConfigNew(newServerConfigPath);
22
+ async function loadServerRuntimeConfig(pwd, oldServerFile = DEFAULT_SERVER_CONFIG, newServerConfigPath) {
23
+ const newServerConfig = newServerConfigPath && await loadServerConfigNew(newServerConfigPath);
24
24
  if (newServerConfig) {
25
25
  return newServerConfig;
26
26
  }
27
- const oldServerConfig = loadServerConfigOld(pwd, oldServerFile);
27
+ const oldServerConfig = await loadServerConfigOld(pwd, oldServerFile);
28
28
  return oldServerConfig;
29
29
  }
30
30
  function loadServerCliConfig(pwd, defaultConfig = {}) {
@@ -1,13 +1,13 @@
1
- import { compatRequire, tryResolve } from "@modern-js/utils";
2
- function resolveServerPlugin(plugin, appDirectory) {
1
+ import { compatibleRequire, tryResolve } from "@modern-js/utils";
2
+ async function resolveServerPlugin(plugin, appDirectory) {
3
3
  const { name, options } = plugin;
4
4
  const pluginPath = tryResolve(name, appDirectory);
5
- const module = compatRequire(pluginPath);
5
+ const module = await compatibleRequire(pluginPath);
6
6
  const pluginInstance = module(options);
7
7
  return pluginInstance;
8
8
  }
9
- function loadServerPlugins(serverPlugins, appDirectory) {
10
- const instances = serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory));
9
+ async function loadServerPlugins(serverPlugins, appDirectory) {
10
+ const instances = await Promise.all(serverPlugins.map((plugin) => resolveServerPlugin(plugin, appDirectory)));
11
11
  return instances;
12
12
  }
13
13
  export {
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { fileReader } from "@modern-js/runtime-utils/fileReader";
3
- import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs } from "@modern-js/utils";
3
+ import { LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, fs, compatibleRequire } from "@modern-js/utils";
4
4
  async function getHtmlTemplates(pwd, routes) {
5
5
  const htmls = await Promise.all(routes.map(async (route) => {
6
6
  let html;
@@ -27,22 +27,17 @@ function injectTemplates(pwd, routes) {
27
27
  await next();
28
28
  };
29
29
  }
30
- const dynamicImport = (filePath) => {
31
- try {
32
- const module = require(filePath);
33
- return Promise.resolve(module);
34
- } catch (e) {
35
- return Promise.reject(e);
36
- }
37
- };
38
30
  const loadBundle = async (filepath, logger) => {
39
31
  if (!await fs.pathExists(filepath)) {
40
32
  return void 0;
41
33
  }
42
- return dynamicImport(filepath).catch((e) => {
43
- logger === null || logger === void 0 ? void 0 : logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
34
+ try {
35
+ const module = await compatibleRequire(filepath, false);
36
+ return module;
37
+ } catch (e) {
38
+ logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
44
39
  return void 0;
45
- });
40
+ }
46
41
  };
47
42
  async function getServerManifest(pwd, routes, logger) {
48
43
  const loaderBundles = {};
@@ -57,11 +52,11 @@ async function getServerManifest(pwd, routes, logger) {
57
52
  loaderBundle && (loaderBundles[entryName] = loaderBundle);
58
53
  }));
59
54
  const loadableUri = path.join(pwd, LOADABLE_STATS_FILE);
60
- const loadableStats = await import(loadableUri).catch((_) => ({}));
55
+ const loadableStats = await compatibleRequire(loadableUri).catch((_) => ({}));
61
56
  const routesManifestUri = path.join(pwd, ROUTE_MANIFEST_FILE);
62
- const routeManifest = await import(routesManifestUri).catch((_) => ({}));
57
+ const routeManifest = await compatibleRequire(routesManifestUri).catch((_) => ({}));
63
58
  const nestedRoutesJsonPath = path.join(pwd, NESTED_ROUTE_SPEC_FILE);
64
- const nestedRoutesJson = await import(nestedRoutesJsonPath).catch((_) => ({}));
59
+ const nestedRoutesJson = await compatibleRequire(nestedRoutesJsonPath).catch((_) => ({}));
65
60
  return {
66
61
  loaderBundles,
67
62
  renderBundles,
@@ -31,7 +31,14 @@ class CustomServer {
31
31
  if (current !== entryName) {
32
32
  const rewriteRoute = routes.find((route) => route.entryName === current);
33
33
  if (rewriteRoute) {
34
- return this.serverBase.request(rewriteRoute.urlPath);
34
+ const { headers, method, signal } = c.req.raw;
35
+ const url2 = new URL(c.req.url);
36
+ const newUrl = new URL(rewriteRoute.urlPath, url2.origin);
37
+ return this.serverBase.request(newUrl, {
38
+ headers,
39
+ method,
40
+ signal
41
+ }, c.env);
35
42
  }
36
43
  }
37
44
  if (c.finalized) {
@@ -141,8 +148,7 @@ async function createMiddlewareContextFromHono(c) {
141
148
  "GET",
142
149
  "HEAD"
143
150
  ].includes(method) && !rawRequest.body && c.env.node.req) {
144
- const streamPath = "../../adapters/node/polyfills/stream";
145
- const { createReadableStreamFromReadable } = await import(streamPath);
151
+ const { createReadableStreamFromReadable } = await import("../../adapters/node/polyfills/stream.js");
146
152
  const init = {
147
153
  body: createReadableStreamFromReadable(c.env.node.req),
148
154
  headers: rawRequest.headers,
@@ -4,6 +4,7 @@ import { parseQuery, getPathname, createErrorHtml, sortRoutes, transformResponse
4
4
  import { REPLACE_REG, X_MODERNJS_RENDER } from "../../constants";
5
5
  import { dataHandler } from "./dataHandler";
6
6
  import { ssrRender } from "./ssrRender";
7
+ import { compatibleRequire } from "@modern-js/utils";
7
8
  const DYNAMIC_ROUTE_REG = /\/:./;
8
9
  function getRouter(routes) {
9
10
  const dynamicRoutes = [];
@@ -131,7 +132,7 @@ async function renderHandler(request, options, mode, onError) {
131
132
  const { nestedRoutesJson } = serverManifest;
132
133
  const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
133
134
  if (routes) {
134
- const { matchRoutes } = await import("@modern-js/runtime-utils/remix-router");
135
+ const { matchRoutes } = await compatibleRequire(require.resolve("@modern-js/runtime-utils/remix-router"), false);
135
136
  const url = new URL(request.url);
136
137
  const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
137
138
  if (!matchedRoutes) {
@@ -1,2 +1,2 @@
1
- import { CacheConfig } from '../../../types';
2
- export declare function loadCacheConfig(pwd: string): CacheConfig | undefined;
1
+ import type { CacheConfig } from '../../../types';
2
+ export declare function loadCacheConfig(pwd: string): Promise<CacheConfig | undefined>;
@@ -1,3 +1,3 @@
1
- import { CliConfig, ServerConfig, UserConfig } from '../../../types';
2
- export declare function loadServerRuntimeConfig(pwd: string, oldServerFile?: string, newServerConfigPath?: string): ServerConfig | undefined;
1
+ import type { CliConfig, ServerConfig, UserConfig } from '../../../types';
2
+ export declare function loadServerRuntimeConfig(pwd: string, oldServerFile?: string, newServerConfigPath?: string): Promise<ServerConfig | undefined>;
3
3
  export declare function loadServerCliConfig(pwd: string, defaultConfig?: UserConfig): CliConfig;
@@ -1,3 +1,3 @@
1
- import { ServerPlugin } from '@modern-js/types';
2
- import { ServerPlugin as ServerPluginInstance } from '../../../types';
3
- export declare function loadServerPlugins(serverPlugins: ServerPlugin[], appDirectory: string): ServerPluginInstance[];
1
+ import type { ServerPlugin } from '@modern-js/types';
2
+ import type { ServerPlugin as ServerPluginInstance } from '../../../types';
3
+ export declare function loadServerPlugins(serverPlugins: ServerPlugin[], appDirectory: string): Promise<ServerPluginInstance[]>;
@@ -1,4 +1,4 @@
1
- import { NodeRequest, NodeResponse, Context, HonoRequest, ServerEnv, Middleware, Next, ServerManifest } from '../../types';
1
+ import type { NodeRequest, NodeResponse, Context, HonoRequest, ServerEnv, Middleware, Next, ServerManifest } from '../../types';
2
2
  type NodeBindings = {
3
3
  node: {
4
4
  req: NodeRequest & {
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Server as NodeServer } from 'node:http';
3
+ import { type Server as NodeServer } from 'node:http';
4
4
  import type { Server as NodeHttpsServer } from 'node:https';
5
- import { NodeRequest, NodeResponse, RequestHandler } from '../../types';
5
+ import type { NodeRequest, NodeResponse, RequestHandler } from '../../types';
6
6
  export { writeReadableStreamToWritable } from './polyfills';
7
7
  export declare const createWebRequest: (req: NodeRequest, res: NodeResponse, body?: BodyInit) => Request;
8
8
  export declare const sendResponse: (response: Response, res: NodeResponse) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { ServerPlugin, NodeServer } from '../../../types';
1
+ import type { ServerPlugin, NodeServer } from '../../../types';
2
2
  export declare const injectNodeSeverPlugin: ({ nodeServer, }: {
3
3
  nodeServer: NodeServer;
4
4
  }) => ServerPlugin;
@@ -1,5 +1,5 @@
1
1
  import type { Logger, ServerRoute } from '@modern-js/types';
2
- import { Middleware, ServerEnv, ServerManifest, ServerPlugin } from '../../../types';
2
+ import type { Middleware, ServerEnv, ServerManifest, ServerPlugin } from '../../../types';
3
3
  export declare function getHtmlTemplates(pwd: string, routes: ServerRoute[]): Promise<Record<string, string>>;
4
4
  export declare function injectTemplates(pwd: string, routes?: ServerRoute[]): Middleware<ServerEnv>;
5
5
  export declare function getServerManifest(pwd: string, routes: ServerRoute[], logger: Logger): Promise<ServerManifest>;
@@ -1,4 +1,4 @@
1
- import { ServerRoute } from '@modern-js/types';
1
+ import type { ServerRoute } from '@modern-js/types';
2
2
  import type { OutputNormalizedConfig, HtmlNormalizedConfig, Middleware, ServerPlugin } from '../../../types';
3
3
  export declare const serverStaticPlugin: () => ServerPlugin;
4
4
  export type PublicMiddlwareOptions = {
@@ -1,4 +1,4 @@
1
- import { HookContext } from '@modern-js/types';
1
+ import type { HookContext } from '@modern-js/types';
2
2
  import type { Context, ServerEnv } from '../../types';
3
3
  export type ResArgs = {
4
4
  status?: number;
@@ -1,7 +1,7 @@
1
- import { AfterMatchContext, AfterRenderContext, MiddlewareContext, AfterStreamingRenderContext, ServerRoute, HookContext } from '@modern-js/types';
2
- import { Context, ServerEnv } from '../../types';
1
+ import type { AfterMatchContext, AfterRenderContext, MiddlewareContext, AfterStreamingRenderContext, ServerRoute, HookContext } from '@modern-js/types';
2
+ import type { Context, ServerEnv } from '../../types';
3
3
  import type { ServerNodeEnv } from '../../adapters/node/hono';
4
- import { ResArgs } from './base';
4
+ import { type ResArgs } from './base';
5
5
  export declare function getAfterMatchCtx(entryName: string, baseHookCtx: HookContext): AfterMatchContext;
6
6
  export declare function getAfterRenderCtx(c: Context, baseHookCtx: HookContext, route: Partial<ServerRoute>): Promise<AfterRenderContext>;
7
7
  export declare function createCustomMiddlewaresCtx(c: Context<ServerNodeEnv & ServerEnv>, locals: Record<string, any>, resArgs?: ResArgs): MiddlewareContext;
@@ -1,6 +1,6 @@
1
- import { ServerRoute, UnstableMiddleware } from '@modern-js/types';
2
- import { ServerBase } from '../../serverBase';
3
- import { ServerHookRunner, Middleware, ServerEnv } from '../../types';
1
+ import type { ServerRoute, UnstableMiddleware } from '@modern-js/types';
2
+ import type { ServerBase } from '../../serverBase';
3
+ import type { ServerHookRunner, Middleware, ServerEnv } from '../../types';
4
4
  import type { ServerNodeEnv } from '../../adapters/node/hono';
5
5
  export declare class CustomServer {
6
6
  private runner;
@@ -1,6 +1,6 @@
1
- import { Logger } from '@modern-js/types';
1
+ import type { Logger } from '@modern-js/types';
2
2
  import type { ServerPlugin } from '../types';
3
- import { InjectRenderHandlerOptions } from './render';
3
+ import { type InjectRenderHandlerOptions } from './render';
4
4
  export type CreateDefaultPluginsOptions = InjectRenderHandlerOptions & {
5
5
  logger?: Logger;
6
6
  };
@@ -1,2 +1,2 @@
1
- import { ServerPlugin } from '../types';
1
+ import type { ServerPlugin } from '../types';
2
2
  export declare const faviconPlugin: () => ServerPlugin;
@@ -1,2 +1,2 @@
1
- import { ServerPlugin } from '../types';
1
+ import type { ServerPlugin } from '../types';
2
2
  export declare const processedByPlugin: () => ServerPlugin;
@@ -1,5 +1,5 @@
1
1
  import type { ServerRoute } from '@modern-js/types';
2
- import { SSRRenderOptions } from './ssrRender';
2
+ import type { SSRRenderOptions } from './ssrRender';
3
3
  export declare const dataHandler: (request: Request, { routeInfo, serverRoutes, reporter, onError, onTiming, serverManifest, }: SSRRenderOptions & {
4
4
  serverRoutes: ServerRoute[];
5
5
  }) => Promise<Response | void>;
@@ -1,3 +1,3 @@
1
- import { ServerPlugin } from '../../types';
1
+ import type { ServerPlugin } from '../../types';
2
2
  export * from './inject';
3
3
  export declare const renderPlugin: () => ServerPlugin;
@@ -1,6 +1,6 @@
1
- import { Logger, Metrics, Reporter, ServerRoute } from '@modern-js/types';
1
+ import type { Logger, Metrics, Reporter, ServerRoute } from '@modern-js/types';
2
2
  import type { CacheConfig, FallbackReason, UserConfig } from '../../types';
3
- import { Render } from '../../types';
3
+ import type { Render } from '../../types';
4
4
  export type OnFallback = (reason: FallbackReason, utils: {
5
5
  logger: Logger;
6
6
  metrics?: Metrics;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { IncomingMessage } from 'http';
3
3
  import type { CacheControl, CacheOption, Container } from '@modern-js/types';
4
- import { RequestHandler, RequestHandlerOptions } from '../../types/requestHandler';
4
+ import type { RequestHandler, RequestHandlerOptions } from '../../types/requestHandler';
5
5
  export type CacheStatus = 'hit' | 'stale' | 'expired' | 'miss';
6
6
  type MaybeAsync<T> = Promise<T> | T;
7
7
  export declare function matchCacheControl(cacheOption?: CacheOption, req?: IncomingMessage): MaybeAsync<CacheControl | undefined | false>;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import type { IncomingMessage } from 'http';
3
3
  import type { Reporter, ServerRoute, Logger, Metrics } from '@modern-js/types';
4
- import { OnError, OnTiming, Params } from '../../types/requestHandler';
5
- import { CacheConfig, ServerManifest, UserConfig } from '../../types';
4
+ import type { OnError, OnTiming, Params } from '../../types/requestHandler';
5
+ import type { CacheConfig, ServerManifest, UserConfig } from '../../types';
6
6
  export interface SSRRenderOptions {
7
7
  pwd: string;
8
8
  html: string;
@@ -1,4 +1,4 @@
1
- import { ServerRoute } from '@modern-js/types';
1
+ import type { ServerRoute } from '@modern-js/types';
2
2
  import { Hono } from 'hono';
3
3
  import type { Env, ServerConfig, ServerHookRunner, ServerPlugin } from './types';
4
4
  import type { CliConfig } from './types/config';
@@ -1,11 +1,11 @@
1
- import { BffNormalizedConfig, BffUserConfig } from './bff';
2
- import { DevNormalizedConfig, DevUserConfig } from './dev';
3
- import { HtmlNormalizedConfig, HtmlUserConfig } from './html';
4
- import { OutputNormalizedConfig, OutputUserConfig } from './output';
5
- import { SecurityNormalizedConfig, SecurityUserConfig } from './security';
6
- import { ServerNormalizedConfig, ServerUserConfig } from './server';
7
- import { SourceNormalizedConfig, SourceUserConfig } from './source';
8
- import { ToolsNormalizedConfig, ToolsUserConfig } from './tools';
1
+ import type { BffNormalizedConfig, BffUserConfig } from './bff';
2
+ import type { DevNormalizedConfig, DevUserConfig } from './dev';
3
+ import type { HtmlNormalizedConfig, HtmlUserConfig } from './html';
4
+ import type { OutputNormalizedConfig, OutputUserConfig } from './output';
5
+ import type { SecurityNormalizedConfig, SecurityUserConfig } from './security';
6
+ import type { ServerNormalizedConfig, ServerUserConfig } from './server';
7
+ import type { SourceNormalizedConfig, SourceUserConfig } from './source';
8
+ import type { ToolsNormalizedConfig, ToolsUserConfig } from './tools';
9
9
  export * from './bff';
10
10
  export * from './html';
11
11
  export * from './output';
@@ -1,5 +1,5 @@
1
- import { BabelTransformOptions } from '@modern-js/types/common';
2
- import { ConfigChain } from './share';
1
+ import type { BabelTransformOptions } from '@modern-js/types/common';
2
+ import type { ConfigChain } from './share';
3
3
  type ToolsBabelConfig = ConfigChain<BabelTransformOptions, any>;
4
4
  export interface ToolsUserConfig {
5
5
  babel?: ToolsBabelConfig;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  /** Hooks */
3
3
  import type { Server as NodeServer, IncomingMessage, ServerResponse } from 'http';
4
- import { AsyncWaterfall, ParallelWorkflow, ToRunners, ToThreads, CommonAPI, PluginOptions, AsyncSetup, createContext, AsyncPipeline } from '@modern-js/plugin';
5
- import { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, CacheOption, Container, HttpMethodDecider, ISAppContext, Logger, Metrics, MiddlewareContext, Reporter, ServerRoute, UnstableMiddleware } from '@modern-js/types';
6
- import { MiddlewareHandler } from 'hono';
7
- import { UserConfig } from './config';
8
- import { Render } from './render';
4
+ import type { AsyncWaterfall, ParallelWorkflow, ToRunners, ToThreads, CommonAPI, PluginOptions, AsyncSetup, createContext, AsyncPipeline } from '@modern-js/plugin';
5
+ import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, CacheOption, Container, HttpMethodDecider, ISAppContext, Logger, Metrics, MiddlewareContext, Reporter, ServerRoute, UnstableMiddleware } from '@modern-js/types';
6
+ import type { MiddlewareHandler } from 'hono';
7
+ import type { UserConfig } from './config';
8
+ import type { Render } from './render';
9
9
  export type ChangeEvent = 'add' | 'change' | 'unlink';
10
10
  export interface Change {
11
11
  filename: string;
@@ -116,7 +116,7 @@ declare module '@modern-js/types' {
116
116
  }
117
117
  export type NodeRequest = IncomingMessage;
118
118
  export type NodeResponse = ServerResponse;
119
- export { NodeServer };
119
+ export type { NodeServer };
120
120
  export type AppContext = ReturnType<typeof createContext<ISAppContext>>;
121
121
  export type ConfigContext = ReturnType<typeof createContext<ServerConfig>>;
122
122
  export type ServerPluginAPI = {
@@ -1,5 +1,5 @@
1
- import { Metrics, Reporter, ServerRoute, Logger } from '@modern-js/types';
2
- import { ServerUserConfig } from './config';
1
+ import type { Metrics, Reporter, ServerRoute, Logger } from '@modern-js/types';
2
+ import type { ServerUserConfig } from './config';
3
3
  export type Resource = {
4
4
  loadableStats: Record<string, any>;
5
5
  routeManifest: Record<string, any>;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { Readable } from 'node:stream';
3
3
  import type { Metrics, Logger, Reporter, BaseSSRServerContext, ServerRoute, NestedRoute, Monitors } from '@modern-js/types';
4
- import { RequestHandler as BundleRequestHandler, OnError, OnTiming } from './requestHandler';
4
+ import type { RequestHandler as BundleRequestHandler, OnError, OnTiming } from './requestHandler';
5
5
  export type SSRServerContext = BaseSSRServerContext & {
6
6
  staticGenerate?: boolean;
7
7
  };
@@ -1,2 +1,2 @@
1
- import { ServerRoute } from '@modern-js/types';
1
+ import type { ServerRoute } from '@modern-js/types';
2
2
  export declare const sortRoutes: (route1: ServerRoute, route2: ServerRoute) => number;
@@ -1,4 +1,4 @@
1
- import { CliConfig, ServerConfig } from '../types';
1
+ import type { CliConfig, ServerConfig } from '../types';
2
2
  /**
3
3
  * 对配置进行合并,cliConfig 与 serverConfig 进行深合并
4
4
  */
@@ -1,4 +1,4 @@
1
- import { MaybeAsync } from '@modern-js/plugin';
1
+ import type { MaybeAsync } from '@modern-js/plugin';
2
2
  type TransformCb = (tempalte: string) => MaybeAsync<string>;
3
3
  export declare function createTransformStream(fn?: TransformCb): TransformStream<any, any>;
4
4
  export declare function transformResponse(response: Response, transformCb: Array<TransformCb> | TransformCb): Response;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.58.1",
18
+ "version": "2.58.2",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -53,9 +53,9 @@
53
53
  "flatted": "^3.2.9",
54
54
  "hono": "^3.12.2",
55
55
  "ts-deepmerge": "7.0.0",
56
- "@modern-js/plugin": "2.58.1",
57
- "@modern-js/runtime-utils": "2.58.1",
58
- "@modern-js/utils": "2.58.1"
56
+ "@modern-js/plugin": "2.58.2",
57
+ "@modern-js/runtime-utils": "2.58.2",
58
+ "@modern-js/utils": "2.58.2"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/jest": "^29",
@@ -65,9 +65,9 @@
65
65
  "jest": "^29",
66
66
  "ts-jest": "^29.1.0",
67
67
  "typescript": "^5",
68
- "@modern-js/types": "2.58.1",
69
- "@scripts/build": "2.58.1",
70
- "@scripts/jest-config": "2.58.1"
68
+ "@modern-js/types": "2.58.2",
69
+ "@scripts/build": "2.58.2",
70
+ "@scripts/jest-config": "2.58.2"
71
71
  },
72
72
  "sideEffects": false,
73
73
  "publishConfig": {