@modern-js/prod-server 2.35.0 → 2.36.0

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 (151) hide show
  1. package/dist/cjs/constants.js +33 -27
  2. package/dist/cjs/index.js +41 -33
  3. package/dist/cjs/libs/context/context.js +86 -36
  4. package/dist/cjs/libs/context/index.js +27 -17
  5. package/dist/cjs/libs/hook-api/base.js +49 -30
  6. package/dist/cjs/libs/hook-api/index.js +36 -28
  7. package/dist/cjs/libs/hook-api/index.worker.js +39 -31
  8. package/dist/cjs/libs/hook-api/route.js +28 -11
  9. package/dist/cjs/libs/hook-api/template.js +27 -17
  10. package/dist/cjs/libs/hook-api/templateForStream.js +31 -14
  11. package/dist/cjs/libs/loadConfig.js +46 -29
  12. package/dist/cjs/libs/metrics.js +24 -7
  13. package/dist/cjs/libs/preload/flushServerHeader.js +30 -13
  14. package/dist/cjs/libs/preload/index.js +22 -5
  15. package/dist/cjs/libs/preload/parseLinks.js +54 -30
  16. package/dist/cjs/libs/preload/shouldFlushServerHeader.js +25 -15
  17. package/dist/cjs/libs/preload/transformLinks2String.js +27 -11
  18. package/dist/cjs/libs/proxy.js +29 -19
  19. package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +40 -22
  20. package/dist/cjs/libs/render/cache/__tests__/cache.test.js +33 -41
  21. package/dist/cjs/libs/render/cache/__tests__/cacheable.js +24 -7
  22. package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +24 -7
  23. package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +24 -7
  24. package/dist/cjs/libs/render/cache/index.js +30 -18
  25. package/dist/cjs/libs/render/cache/page-caches/index.js +26 -9
  26. package/dist/cjs/libs/render/cache/page-caches/lru.js +39 -13
  27. package/dist/cjs/libs/render/cache/spr.js +62 -44
  28. package/dist/cjs/libs/render/cache/type.js +15 -3
  29. package/dist/cjs/libs/render/cache/util.js +49 -36
  30. package/dist/cjs/libs/render/index.js +56 -30
  31. package/dist/cjs/libs/render/measure.js +27 -17
  32. package/dist/cjs/libs/render/reader.js +50 -35
  33. package/dist/cjs/libs/render/ssr.js +52 -26
  34. package/dist/cjs/libs/render/static.js +44 -18
  35. package/dist/cjs/libs/render/type.js +24 -7
  36. package/dist/cjs/libs/render/utils.js +29 -19
  37. package/dist/cjs/libs/reporter.js +24 -7
  38. package/dist/cjs/libs/route/index.js +30 -20
  39. package/dist/cjs/libs/route/matcher.js +37 -20
  40. package/dist/cjs/libs/route/route.js +34 -17
  41. package/dist/cjs/libs/serveFile.js +40 -21
  42. package/dist/cjs/libs/serverTiming.js +27 -10
  43. package/dist/cjs/renderHtml.js +17 -20
  44. package/dist/cjs/server/index.js +74 -50
  45. package/dist/cjs/server/modernServer.js +136 -113
  46. package/dist/cjs/server/modernServerSplit.js +29 -12
  47. package/dist/cjs/type.js +15 -3
  48. package/dist/cjs/utils.js +41 -38
  49. package/dist/cjs/workerServer.js +48 -39
  50. package/dist/esm/constants.js +14 -6
  51. package/dist/esm/index.js +11 -5
  52. package/dist/esm/libs/context/context.js +33 -6
  53. package/dist/esm/libs/context/index.js +5 -2
  54. package/dist/esm/libs/hook-api/base.js +6 -2
  55. package/dist/esm/libs/hook-api/index.js +11 -5
  56. package/dist/esm/libs/hook-api/index.worker.js +16 -10
  57. package/dist/esm/libs/hook-api/route.js +4 -1
  58. package/dist/esm/libs/hook-api/template.js +6 -2
  59. package/dist/esm/libs/hook-api/templateForStream.js +4 -1
  60. package/dist/esm/libs/loadConfig.js +8 -3
  61. package/dist/esm/libs/metrics.js +3 -1
  62. package/dist/esm/libs/preload/flushServerHeader.js +9 -6
  63. package/dist/esm/libs/preload/parseLinks.js +13 -11
  64. package/dist/esm/libs/preload/shouldFlushServerHeader.js +6 -2
  65. package/dist/esm/libs/preload/transformLinks2String.js +5 -3
  66. package/dist/esm/libs/proxy.js +9 -5
  67. package/dist/esm/libs/render/cache/__tests__/cache.test.js +12 -12
  68. package/dist/esm/libs/render/cache/__tests__/cacheable.js +4 -1
  69. package/dist/esm/libs/render/cache/__tests__/error-configuration.js +4 -1
  70. package/dist/esm/libs/render/cache/__tests__/matched-cache.js +4 -1
  71. package/dist/esm/libs/render/cache/index.js +6 -3
  72. package/dist/esm/libs/render/cache/page-caches/index.js +5 -2
  73. package/dist/esm/libs/render/cache/page-caches/lru.js +4 -1
  74. package/dist/esm/libs/render/cache/spr.js +13 -9
  75. package/dist/esm/libs/render/cache/type.js +0 -1
  76. package/dist/esm/libs/render/cache/util.js +18 -8
  77. package/dist/esm/libs/render/index.js +17 -11
  78. package/dist/esm/libs/render/measure.js +15 -11
  79. package/dist/esm/libs/render/reader.js +17 -10
  80. package/dist/esm/libs/render/ssr.js +11 -8
  81. package/dist/esm/libs/render/static.js +5 -2
  82. package/dist/esm/libs/render/type.js +4 -1
  83. package/dist/esm/libs/render/utils.js +6 -2
  84. package/dist/esm/libs/reporter.js +4 -1
  85. package/dist/esm/libs/route/index.js +5 -2
  86. package/dist/esm/libs/route/matcher.js +6 -3
  87. package/dist/esm/libs/route/route.js +4 -1
  88. package/dist/esm/libs/serveFile.js +6 -2
  89. package/dist/esm/libs/serverTiming.js +4 -1
  90. package/dist/esm/renderHtml.js +133 -124
  91. package/dist/esm/server/index.js +14 -13
  92. package/dist/esm/server/modernServer.js +39 -47
  93. package/dist/esm/server/modernServerSplit.js +4 -1
  94. package/dist/esm/type.js +0 -1
  95. package/dist/esm/utils.js +23 -12
  96. package/dist/esm/workerServer.js +25 -22
  97. package/dist/esm-node/constants.js +14 -6
  98. package/dist/esm-node/index.js +11 -5
  99. package/dist/esm-node/libs/context/context.js +33 -6
  100. package/dist/esm-node/libs/context/index.js +5 -2
  101. package/dist/esm-node/libs/hook-api/base.js +6 -2
  102. package/dist/esm-node/libs/hook-api/index.js +10 -4
  103. package/dist/esm-node/libs/hook-api/index.worker.js +10 -4
  104. package/dist/esm-node/libs/hook-api/route.js +4 -1
  105. package/dist/esm-node/libs/hook-api/template.js +6 -2
  106. package/dist/esm-node/libs/hook-api/templateForStream.js +4 -1
  107. package/dist/esm-node/libs/loadConfig.js +8 -3
  108. package/dist/esm-node/libs/metrics.js +3 -1
  109. package/dist/esm-node/libs/preload/flushServerHeader.js +6 -3
  110. package/dist/esm-node/libs/preload/parseLinks.js +11 -9
  111. package/dist/esm-node/libs/preload/shouldFlushServerHeader.js +6 -2
  112. package/dist/esm-node/libs/preload/transformLinks2String.js +5 -3
  113. package/dist/esm-node/libs/proxy.js +6 -2
  114. package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +7 -12
  115. package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +4 -1
  116. package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +4 -1
  117. package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +4 -1
  118. package/dist/esm-node/libs/render/cache/index.js +5 -3
  119. package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -1
  120. package/dist/esm-node/libs/render/cache/page-caches/lru.js +4 -1
  121. package/dist/esm-node/libs/render/cache/spr.js +7 -4
  122. package/dist/esm-node/libs/render/cache/type.js +0 -1
  123. package/dist/esm-node/libs/render/cache/util.js +18 -8
  124. package/dist/esm-node/libs/render/index.js +7 -3
  125. package/dist/esm-node/libs/render/measure.js +6 -2
  126. package/dist/esm-node/libs/render/reader.js +13 -7
  127. package/dist/esm-node/libs/render/ssr.js +4 -1
  128. package/dist/esm-node/libs/render/static.js +4 -1
  129. package/dist/esm-node/libs/render/type.js +4 -1
  130. package/dist/esm-node/libs/render/utils.js +6 -2
  131. package/dist/esm-node/libs/reporter.js +4 -1
  132. package/dist/esm-node/libs/route/index.js +5 -2
  133. package/dist/esm-node/libs/route/matcher.js +6 -3
  134. package/dist/esm-node/libs/route/route.js +4 -1
  135. package/dist/esm-node/libs/serveFile.js +6 -2
  136. package/dist/esm-node/libs/serverTiming.js +4 -1
  137. package/dist/esm-node/renderHtml.js +72 -63
  138. package/dist/esm-node/server/index.js +11 -10
  139. package/dist/esm-node/server/modernServer.js +29 -28
  140. package/dist/esm-node/server/modernServerSplit.js +4 -1
  141. package/dist/esm-node/type.js +0 -1
  142. package/dist/esm-node/utils.js +20 -9
  143. package/dist/esm-node/workerServer.js +12 -9
  144. package/dist/types/libs/context/context.d.ts +2 -1
  145. package/dist/types/type.d.ts +1 -0
  146. package/dist/types/utils.d.ts +1 -1
  147. package/package.json +9 -8
  148. package/dist/cjs/libs/logger.js +0 -123
  149. package/dist/esm/libs/logger.js +0 -125
  150. package/dist/esm-node/libs/logger.js +0 -106
  151. package/dist/types/libs/logger.d.ts +0 -61
@@ -17,8 +17,8 @@ var createCacheItem = function() {
17
17
  return [
18
18
  2,
19
19
  {
20
- content: content,
21
- mtime: mtime
20
+ content,
21
+ mtime
22
22
  }
23
23
  ];
24
24
  });
@@ -27,7 +27,7 @@ var createCacheItem = function() {
27
27
  return _ref.apply(this, arguments);
28
28
  };
29
29
  }();
30
- export var LruReader = /* @__PURE__ */ function() {
30
+ var LruReader = /* @__PURE__ */ function() {
31
31
  "use strict";
32
32
  function LruReader2() {
33
33
  _class_call_check(this, LruReader2);
@@ -67,7 +67,7 @@ export var LruReader = /* @__PURE__ */ function() {
67
67
  return [
68
68
  2,
69
69
  {
70
- content: content
70
+ content
71
71
  }
72
72
  ];
73
73
  }
@@ -155,9 +155,9 @@ export var LruReader = /* @__PURE__ */ function() {
155
155
  return LruReader2;
156
156
  }();
157
157
  var reader = new LruReader();
158
- export var readFile = function() {
158
+ var readFile = function() {
159
159
  var _ref = _async_to_generator(function(filepath) {
160
- var _file, file;
160
+ var file;
161
161
  return _ts_generator(this, function(_state) {
162
162
  switch (_state.label) {
163
163
  case 0:
@@ -169,7 +169,7 @@ export var readFile = function() {
169
169
  file = _state.sent();
170
170
  return [
171
171
  2,
172
- (_file = file) === null || _file === void 0 ? void 0 : _file.content
172
+ file === null || file === void 0 ? void 0 : file.content
173
173
  ];
174
174
  }
175
175
  });
@@ -178,12 +178,19 @@ export var readFile = function() {
178
178
  return _ref.apply(this, arguments);
179
179
  };
180
180
  }();
181
- export var updateFile = function() {
181
+ var updateFile = function() {
182
182
  reader.update();
183
183
  };
184
- export var init = function(fs) {
184
+ var init = function(fs) {
185
185
  reader.init(fs);
186
186
  };
187
- export var close = function() {
187
+ var close = function() {
188
188
  reader.close();
189
189
  };
190
+ export {
191
+ LruReader,
192
+ close,
193
+ init,
194
+ readFile,
195
+ updateFile
196
+ };
@@ -5,7 +5,7 @@ import { fs, mime, LOADABLE_STATS_FILE, ROUTE_MANIFEST_FILE, SERVER_RENDER_FUNCT
5
5
  import cache from "./cache";
6
6
  import { createLogger, createMetrics } from "./measure";
7
7
  import { injectServerDataStream, injectServerData } from "./utils";
8
- export var render = function() {
8
+ var render = function() {
9
9
  var _ref = _async_to_generator(function(ctx, renderOptions, runner) {
10
10
  var _ctx_res, urlPath, bundle, distDir, template, entryName, staticGenerate, _renderOptions_enableUnsafeCtx, enableUnsafeCtx, nonce, bundleJS, loadableUri, loadableStats, routesManifestUri, routeManifest, context, bundleJSContent, serverRender, content, _context_redirection, url, _context_redirection_status, status;
11
11
  return _ts_generator(this, function(_state) {
@@ -37,19 +37,19 @@ export var render = function() {
37
37
  locals: ((_ctx_res = ctx.res) === null || _ctx_res === void 0 ? void 0 : _ctx_res.locals) || {}
38
38
  },
39
39
  redirection: {},
40
- template: template,
41
- loadableStats: loadableStats,
42
- routeManifest: routeManifest,
43
- entryName: entryName,
44
- staticGenerate: staticGenerate,
40
+ template,
41
+ loadableStats,
42
+ routeManifest,
43
+ entryName,
44
+ staticGenerate,
45
45
  logger: void 0,
46
46
  metrics: void 0,
47
47
  reporter: ctx.reporter,
48
48
  serverTiming: ctx.serverTiming,
49
49
  req: ctx.req,
50
50
  res: ctx.res,
51
- enableUnsafeCtx: enableUnsafeCtx,
52
- nonce: nonce
51
+ enableUnsafeCtx,
52
+ nonce
53
53
  };
54
54
  context.logger = createLogger(context, ctx.logger);
55
55
  context.metrics = createMetrics(context, ctx.metrics);
@@ -107,3 +107,6 @@ export var render = function() {
107
107
  return _ref.apply(this, arguments);
108
108
  };
109
109
  }();
110
+ export {
111
+ render
112
+ };
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
4
  import { mime } from "@modern-js/utils";
5
5
  import { readFile } from "./reader";
6
- export function handleDirectory(ctx, entryPath, urlPath) {
6
+ function handleDirectory(ctx, entryPath, urlPath) {
7
7
  return _handleDirectory.apply(this, arguments);
8
8
  }
9
9
  function _handleDirectory() {
@@ -80,7 +80,7 @@ function _handleDirectory() {
80
80
  return [
81
81
  2,
82
82
  {
83
- content: content,
83
+ content,
84
84
  contentType: contentType || ""
85
85
  }
86
86
  ];
@@ -95,3 +95,6 @@ var trimLeft = function(str, prefix) {
95
95
  }
96
96
  return str;
97
97
  };
98
+ export {
99
+ handleDirectory
100
+ };
@@ -1,6 +1,9 @@
1
- export var RenderLevel;
1
+ var RenderLevel;
2
2
  (function(RenderLevel2) {
3
3
  RenderLevel2[RenderLevel2["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
4
4
  RenderLevel2[RenderLevel2["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
5
5
  RenderLevel2[RenderLevel2["SERVER_RENDER"] = 2] = "SERVER_RENDER";
6
6
  })(RenderLevel || (RenderLevel = {}));
7
+ export {
8
+ RenderLevel
9
+ };
@@ -1,12 +1,16 @@
1
1
  import { TemplateAPI } from "../hook-api/template";
2
2
  import { templateInjectableStream } from "../hook-api/templateForStream";
3
- export var injectServerData = function(content, context) {
3
+ var injectServerData = function(content, context) {
4
4
  var template = new TemplateAPI(content);
5
5
  template.prependHead('<script type="application/json" id="__MODERN_SERVER_DATA__">'.concat(JSON.stringify(context.serverData), "</script>"));
6
6
  return template.get();
7
7
  };
8
- export var injectServerDataStream = function(content, context) {
8
+ var injectServerDataStream = function(content, context) {
9
9
  return content.pipe(templateInjectableStream({
10
10
  prependHead: '<script type="application/json" id="__MODERN_SERVER_DATA__">'.concat(JSON.stringify(context.serverData), "</script>")
11
11
  }));
12
12
  };
13
+ export {
14
+ injectServerData,
15
+ injectServerDataStream
16
+ };
@@ -1,4 +1,4 @@
1
- export var defaultReporter = {
1
+ var defaultReporter = {
2
2
  init: function init() {
3
3
  },
4
4
  reportError: function reportError() {
@@ -10,3 +10,6 @@ export var defaultReporter = {
10
10
  reportWarn: function reportWarn() {
11
11
  }
12
12
  };
13
+ export {
14
+ defaultReporter
15
+ };
@@ -2,7 +2,7 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
2
  import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
3
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
4
  import { RouteMatcher } from "./matcher";
5
- export var RouteMatchManager = /* @__PURE__ */ function() {
5
+ var RouteMatchManager = /* @__PURE__ */ function() {
6
6
  "use strict";
7
7
  function RouteMatchManager2() {
8
8
  _class_call_check(this, RouteMatchManager2);
@@ -110,4 +110,7 @@ export var RouteMatchManager = /* @__PURE__ */ function() {
110
110
  ]);
111
111
  return RouteMatchManager2;
112
112
  }();
113
- export { RouteMatcher };
113
+ export {
114
+ RouteMatchManager,
115
+ RouteMatcher
116
+ };
@@ -19,7 +19,7 @@ var toPath = function(reg, params) {
19
19
  return fn(params);
20
20
  };
21
21
  var regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
22
- export var RouteMatcher = /* @__PURE__ */ function() {
22
+ var RouteMatcher = /* @__PURE__ */ function() {
23
23
  "use strict";
24
24
  function RouteMatcher2(spec) {
25
25
  _class_call_check(this, RouteMatcher2);
@@ -65,9 +65,9 @@ export var RouteMatcher = /* @__PURE__ */ function() {
65
65
  if (!this.urlReg) {
66
66
  return this.urlPath.length;
67
67
  } else {
68
- var _result_, _result;
68
+ var _result_;
69
69
  var result = this.urlReg.exec(pathname);
70
- return ((_result = result) === null || _result === void 0 ? void 0 : (_result_ = _result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
70
+ return (result === null || result === void 0 ? void 0 : (_result_ = result[0]) === null || _result_ === void 0 ? void 0 : _result_.length) || null;
71
71
  }
72
72
  }
73
73
  )
@@ -123,3 +123,6 @@ export var RouteMatcher = /* @__PURE__ */ function() {
123
123
  ]);
124
124
  return RouteMatcher2;
125
125
  }();
126
+ export {
127
+ RouteMatcher
128
+ };
@@ -1,6 +1,6 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
2
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
3
- export var ModernRoute = function ModernRoute2(routeSpec) {
3
+ var ModernRoute = function ModernRoute2(routeSpec) {
4
4
  "use strict";
5
5
  _class_call_check(this, ModernRoute2);
6
6
  _define_property(this, "entryName", void 0);
@@ -21,3 +21,6 @@ export var ModernRoute = function ModernRoute2(routeSpec) {
21
21
  this.bundle = routeSpec.bundle || "";
22
22
  this.responseHeaders = routeSpec.responseHeaders;
23
23
  };
24
+ export {
25
+ ModernRoute
26
+ };
@@ -14,7 +14,7 @@ var removedPrefix = function(req, prefix) {
14
14
  };
15
15
  }
16
16
  };
17
- export var faviconFallbackHandler = function(context, next) {
17
+ var faviconFallbackHandler = function(context, next) {
18
18
  if (context.url === "/favicon.ico") {
19
19
  context.res.statusCode = 204;
20
20
  context.res.end();
@@ -22,7 +22,7 @@ export var faviconFallbackHandler = function(context, next) {
22
22
  next();
23
23
  }
24
24
  };
25
- export var createStaticFileHandler = function(rules) {
25
+ var createStaticFileHandler = function(rules) {
26
26
  var assetPrefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "/";
27
27
  return function() {
28
28
  var _ref = (
@@ -62,3 +62,7 @@ export var createStaticFileHandler = function(rules) {
62
62
  };
63
63
  }();
64
64
  };
65
+ export {
66
+ createStaticFileHandler,
67
+ faviconFallbackHandler
68
+ };
@@ -2,7 +2,7 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
2
  import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
3
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
4
  var SERVER_TIMING = "Server-Timing";
5
- export var ServerTiming = /* @__PURE__ */ function() {
5
+ var ServerTiming = /* @__PURE__ */ function() {
6
6
  "use strict";
7
7
  function ServerTiming2(res, meta) {
8
8
  _class_call_check(this, ServerTiming2);
@@ -25,3 +25,6 @@ export var ServerTiming = /* @__PURE__ */ function() {
25
25
  ]);
26
26
  return ServerTiming2;
27
27
  }();
28
+ export {
29
+ ServerTiming
30
+ };
@@ -1,3 +1,7 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
1
5
  import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
2
6
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
3
7
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
@@ -11,131 +15,136 @@ import { Readable } from "stream";
11
15
  import { Socket } from "net";
12
16
  import { Server } from "./server";
13
17
  import { isRedirect } from "./utils";
14
- var IncomingMessageLike = /* @__PURE__ */ function(Readable2) {
15
- "use strict";
16
- _inherits(IncomingMessageLike2, Readable2);
17
- var _super = _create_super(IncomingMessageLike2);
18
- function IncomingMessageLike2(param) {
19
- var method = param.method, url = param.url, headers = param.headers;
20
- _class_call_check(this, IncomingMessageLike2);
21
- var _this;
22
- _this = _super.call(this);
23
- _define_property(_assert_this_initialized(_this), "headers", void 0);
24
- _define_property(_assert_this_initialized(_this), "method", void 0);
25
- _define_property(_assert_this_initialized(_this), "url", void 0);
26
- _define_property(_assert_this_initialized(_this), "socket", void 0);
27
- _this.socket = new Socket();
28
- _this.headers = headers || {};
29
- _this.headers.host = "localhost:8080";
30
- _this.method = method || "get";
31
- _this.url = url;
32
- return _this;
33
- }
34
- return IncomingMessageLike2;
35
- }(Readable);
36
- var ServerResponseLike = /* @__PURE__ */ function(OutgoingMessage2) {
37
- "use strict";
38
- _inherits(ServerResponseLike2, OutgoingMessage2);
39
- var _super = _create_super(ServerResponseLike2);
40
- function ServerResponseLike2() {
41
- _class_call_check(this, ServerResponseLike2);
42
- var _this;
43
- _this = _super.call(this);
44
- _define_property(_assert_this_initialized(_this), "statusCode", void 0);
45
- _define_property(_assert_this_initialized(_this), "data", void 0);
46
- _this.statusCode = 200;
47
- _this.data = [];
48
- return _this;
49
- }
50
- _create_class(ServerResponseLike2, [
51
- {
52
- key: "end",
53
- value: function end(chunk, _encoding, cb) {
54
- this.data.push(chunk.toString());
55
- cb && cb();
56
- this.emit("finish");
57
- return this;
18
+ var require_renderHtml = __commonJS({
19
+ "src/renderHtml.ts"(exports, module) {
20
+ var IncomingMessageLike = /* @__PURE__ */ function(Readable2) {
21
+ "use strict";
22
+ _inherits(IncomingMessageLike2, Readable2);
23
+ var _super = _create_super(IncomingMessageLike2);
24
+ function IncomingMessageLike2(param) {
25
+ var method = param.method, url = param.url, headers = param.headers;
26
+ _class_call_check(this, IncomingMessageLike2);
27
+ var _this;
28
+ _this = _super.call(this);
29
+ _define_property(_assert_this_initialized(_this), "headers", void 0);
30
+ _define_property(_assert_this_initialized(_this), "method", void 0);
31
+ _define_property(_assert_this_initialized(_this), "url", void 0);
32
+ _define_property(_assert_this_initialized(_this), "socket", void 0);
33
+ _this.socket = new Socket();
34
+ _this.headers = headers || {};
35
+ _this.headers.host = "localhost:8080";
36
+ _this.method = method || "get";
37
+ _this.url = url;
38
+ return _this;
58
39
  }
59
- }
60
- ]);
61
- return ServerResponseLike2;
62
- }(OutgoingMessage);
63
- var CustomServer = /* @__PURE__ */ function(Server2) {
64
- "use strict";
65
- _inherits(CustomServer2, Server2);
66
- var _super = _create_super(CustomServer2);
67
- function CustomServer2() {
68
- _class_call_check(this, CustomServer2);
69
- return _super.apply(this, arguments);
70
- }
71
- _create_class(CustomServer2, [
72
- {
73
- key: "render",
74
- value: function render(req, res, _url) {
75
- var _this = this;
76
- return _async_to_generator(function() {
77
- var handler;
78
- return _ts_generator(this, function(_state) {
79
- handler = _this.getRequestHandler();
80
- handler(req, res);
81
- return [
82
- 2,
83
- null
84
- ];
85
- });
86
- })();
40
+ return IncomingMessageLike2;
41
+ }(Readable);
42
+ var ServerResponseLike = /* @__PURE__ */ function(OutgoingMessage2) {
43
+ "use strict";
44
+ _inherits(ServerResponseLike2, OutgoingMessage2);
45
+ var _super = _create_super(ServerResponseLike2);
46
+ function ServerResponseLike2() {
47
+ _class_call_check(this, ServerResponseLike2);
48
+ var _this;
49
+ _this = _super.call(this);
50
+ _define_property(_assert_this_initialized(_this), "statusCode", void 0);
51
+ _define_property(_assert_this_initialized(_this), "data", void 0);
52
+ _this.statusCode = 200;
53
+ _this.data = [];
54
+ return _this;
87
55
  }
88
- }
89
- ]);
90
- return CustomServer2;
91
- }(Server);
92
- function renderHtml(_) {
93
- return _renderHtml.apply(this, arguments);
94
- }
95
- function _renderHtml() {
96
- _renderHtml = _async_to_generator(function(param) {
97
- var url, method, headers, body, serverOptions, req, res, customServer;
98
- return _ts_generator(this, function(_state) {
99
- switch (_state.label) {
100
- case 0:
101
- url = param.url, method = param.method, headers = param.headers, body = param.body, serverOptions = param.serverOptions;
102
- req = new IncomingMessageLike({
103
- method: method,
104
- url: url,
105
- headers: headers
106
- });
107
- if (body) {
108
- req.push(body);
109
- req.push(null);
56
+ _create_class(ServerResponseLike2, [
57
+ {
58
+ key: "end",
59
+ value: function end(chunk, _encoding, cb) {
60
+ this.data.push(chunk.toString());
61
+ cb && cb();
62
+ this.emit("finish");
63
+ return this;
110
64
  }
111
- res = new ServerResponseLike();
112
- customServer = new CustomServer(serverOptions);
113
- return [
114
- 4,
115
- customServer.init({
116
- disableHttpServer: true
117
- })
118
- ];
119
- case 1:
120
- _state.sent();
121
- customServer.render(req, res);
122
- return [
123
- 2,
124
- new Promise(function(resolve) {
125
- res.addListener("finish", function() {
126
- resolve({
127
- headers: res.getHeaders(),
128
- redirected: isRedirect(res.statusCode),
129
- status: res.statusCode,
130
- url: url,
131
- body: res.data.join()
132
- });
133
- });
134
- })
135
- ];
65
+ }
66
+ ]);
67
+ return ServerResponseLike2;
68
+ }(OutgoingMessage);
69
+ var CustomServer = /* @__PURE__ */ function(Server2) {
70
+ "use strict";
71
+ _inherits(CustomServer2, Server2);
72
+ var _super = _create_super(CustomServer2);
73
+ function CustomServer2() {
74
+ _class_call_check(this, CustomServer2);
75
+ return _super.apply(this, arguments);
136
76
  }
137
- });
138
- });
139
- return _renderHtml.apply(this, arguments);
140
- }
141
- module.exports = renderHtml;
77
+ _create_class(CustomServer2, [
78
+ {
79
+ key: "render",
80
+ value: function render(req, res, _url) {
81
+ var _this = this;
82
+ return _async_to_generator(function() {
83
+ var handler;
84
+ return _ts_generator(this, function(_state) {
85
+ handler = _this.getRequestHandler();
86
+ handler(req, res);
87
+ return [
88
+ 2,
89
+ null
90
+ ];
91
+ });
92
+ })();
93
+ }
94
+ }
95
+ ]);
96
+ return CustomServer2;
97
+ }(Server);
98
+ function renderHtml(_) {
99
+ return _renderHtml.apply(this, arguments);
100
+ }
101
+ function _renderHtml() {
102
+ _renderHtml = _async_to_generator(function(param) {
103
+ var url, method, headers, body, serverOptions, req, res, customServer;
104
+ return _ts_generator(this, function(_state) {
105
+ switch (_state.label) {
106
+ case 0:
107
+ url = param.url, method = param.method, headers = param.headers, body = param.body, serverOptions = param.serverOptions;
108
+ req = new IncomingMessageLike({
109
+ method,
110
+ url,
111
+ headers
112
+ });
113
+ if (body) {
114
+ req.push(body);
115
+ req.push(null);
116
+ }
117
+ res = new ServerResponseLike();
118
+ customServer = new CustomServer(serverOptions);
119
+ return [
120
+ 4,
121
+ customServer.init({
122
+ disableHttpServer: true
123
+ })
124
+ ];
125
+ case 1:
126
+ _state.sent();
127
+ customServer.render(req, res);
128
+ return [
129
+ 2,
130
+ new Promise(function(resolve) {
131
+ res.addListener("finish", function() {
132
+ resolve({
133
+ headers: res.getHeaders(),
134
+ redirected: isRedirect(res.statusCode),
135
+ status: res.statusCode,
136
+ url,
137
+ body: res.data.join()
138
+ });
139
+ });
140
+ })
141
+ ];
142
+ }
143
+ });
144
+ });
145
+ return _renderHtml.apply(this, arguments);
146
+ }
147
+ module.exports = renderHtml;
148
+ }
149
+ });
150
+ export default require_renderHtml();
@@ -7,13 +7,13 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
7
7
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
8
8
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
9
9
  import path from "path";
10
- import { fs, Logger, SHARED_DIR, OUTPUT_CONFIG_FILE, dotenv, dotenvExpand, INTERNAL_SERVER_PLUGINS } from "@modern-js/utils";
10
+ import { fs, createLogger, SHARED_DIR, OUTPUT_CONFIG_FILE, dotenv, dotenvExpand, INTERNAL_SERVER_PLUGINS, ensureAbsolutePath } from "@modern-js/utils";
11
11
  import { serverManager, AppContext, ConfigContext, loadPlugins } from "@modern-js/server-core";
12
12
  import { metrics as defaultMetrics } from "../libs/metrics";
13
13
  import { loadConfig, getServerConfigPath, requireConfig } from "../libs/loadConfig";
14
14
  import { debug } from "../utils";
15
15
  import { createProdServer } from "./modernServerSplit";
16
- export var Server = /* @__PURE__ */ function() {
16
+ var Server = /* @__PURE__ */ function() {
17
17
  "use strict";
18
18
  function Server2(options) {
19
19
  _class_call_check(this, Server2);
@@ -23,7 +23,7 @@ export var Server = /* @__PURE__ */ function() {
23
23
  _define_property(this, "app", void 0);
24
24
  _define_property(this, "runner", void 0);
25
25
  _define_property(this, "serverConfig", void 0);
26
- options.logger = options.logger || new Logger({
26
+ options.logger = options.logger || createLogger({
27
27
  level: "warn"
28
28
  });
29
29
  options.metrics = options.metrics || defaultMetrics;
@@ -198,11 +198,11 @@ export var Server = /* @__PURE__ */ function() {
198
198
  pwd = options.pwd, config = options.config;
199
199
  serverConfig = _this.serverConfig;
200
200
  finalServerConfig = _this.runConfigHook(runner, serverConfig);
201
- resolvedConfigPath = path.join(pwd, config.output.path || "dist", OUTPUT_CONFIG_FILE);
201
+ resolvedConfigPath = ensureAbsolutePath(pwd, path.join(config.output.path || "dist", OUTPUT_CONFIG_FILE));
202
202
  options.config = loadConfig({
203
203
  cliConfig: config,
204
204
  serverConfig: finalServerConfig,
205
- resolvedConfigPath: resolvedConfigPath
205
+ resolvedConfigPath
206
206
  });
207
207
  return [
208
208
  2
@@ -230,8 +230,7 @@ export var Server = /* @__PURE__ */ function() {
230
230
  key: "listen",
231
231
  value: function listen(options, listener) {
232
232
  var callback = function() {
233
- var _listener;
234
- (_listener = listener) === null || _listener === void 0 ? void 0 : _listener();
233
+ listener === null || listener === void 0 ? void 0 : listener();
235
234
  };
236
235
  if (typeof options === "object") {
237
236
  if (process.env.PORT) {
@@ -283,7 +282,7 @@ export var Server = /* @__PURE__ */ function() {
283
282
  _options_internalPlugins = options.internalPlugins, internalPlugins = _options_internalPlugins === void 0 ? INTERNAL_SERVER_PLUGINS : _options_internalPlugins, pwd = options.pwd, _options_plugins = options.plugins, plugins = _options_plugins === void 0 ? [] : _options_plugins;
284
283
  serverPlugins = _this.serverConfig.plugins || [];
285
284
  loadedPlugins = loadPlugins(pwd, _to_consumable_array(serverPlugins).concat(_to_consumable_array(plugins)), {
286
- internalPlugins: internalPlugins
285
+ internalPlugins
287
286
  });
288
287
  debug("plugins", loadedPlugins);
289
288
  loadedPlugins.forEach(function(p) {
@@ -327,7 +326,6 @@ export var Server = /* @__PURE__ */ function() {
327
326
  {
328
327
  key: "initAppContext",
329
328
  value: function initAppContext() {
330
- var _appContext, _appContext1, _appContext2;
331
329
  var options = this.options;
332
330
  var appDirectory = options.pwd, _options_plugins = options.plugins, plugins = _options_plugins === void 0 ? [] : _options_plugins, config = options.config, appContext = options.appContext;
333
331
  var serverPlugins = plugins.map(function(p) {
@@ -336,10 +334,10 @@ export var Server = /* @__PURE__ */ function() {
336
334
  };
337
335
  });
338
336
  return {
339
- appDirectory: appDirectory,
340
- apiDirectory: (_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.apiDirectory,
341
- lambdaDirectory: (_appContext1 = appContext) === null || _appContext1 === void 0 ? void 0 : _appContext1.lambdaDirectory,
342
- sharedDirectory: ((_appContext2 = appContext) === null || _appContext2 === void 0 ? void 0 : _appContext2.sharedDirectory) || path.resolve(appDirectory, SHARED_DIR),
337
+ appDirectory,
338
+ apiDirectory: appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory,
339
+ lambdaDirectory: appContext === null || appContext === void 0 ? void 0 : appContext.lambdaDirectory,
340
+ sharedDirectory: (appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory) || path.resolve(appDirectory, SHARED_DIR),
343
341
  distDirectory: path.join(appDirectory, config.output.path || "dist"),
344
342
  plugins: serverPlugins
345
343
  };
@@ -413,3 +411,6 @@ export var Server = /* @__PURE__ */ function() {
413
411
  ]);
414
412
  return Server2;
415
413
  }();
414
+ export {
415
+ Server
416
+ };