@modern-js/server-core 2.57.0 → 2.57.1

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.
@@ -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 render_exports = {};
20
30
  __export(render_exports, {
@@ -23,7 +33,6 @@ __export(render_exports, {
23
33
  module.exports = __toCommonJS(render_exports);
24
34
  var import_universal = require("@modern-js/utils/universal");
25
35
  var import_trie_router = require("hono/router/trie-router");
26
- var import_router = require("@modern-js/runtime-utils/router");
27
36
  var import_utils = require("../../utils");
28
37
  var import_constants = require("../../constants");
29
38
  var import_dataHandler = require("./dataHandler");
@@ -155,8 +164,9 @@ async function renderHandler(request, options, mode, onError) {
155
164
  const { nestedRoutesJson } = serverManifest;
156
165
  const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
157
166
  if (routes) {
167
+ const { matchRoutes } = await Promise.resolve().then(() => __toESM(require("@modern-js/runtime-utils/remix-router")));
158
168
  const url = new URL(request.url);
159
- const matchedRoutes = (0, import_router.matchRoutes)(routes, url.pathname, options.routeInfo.urlPath);
169
+ const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
160
170
  if (!matchedRoutes) {
161
171
  response = csrRender(options.html);
162
172
  } else {
@@ -8,7 +8,6 @@ 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 { cutNameByHyphen } from "@modern-js/utils/universal";
10
10
  import { TrieRouter } from "hono/router/trie-router";
11
- import { matchRoutes } from "@modern-js/runtime-utils/router";
12
11
  import { parseQuery, getPathname, createErrorHtml, sortRoutes, transformResponse, onError as onErrorFn, ErrorDigest, parseHeaders } from "../../utils";
13
12
  import { REPLACE_REG, X_MODERNJS_RENDER } from "../../constants";
14
13
  import { dataHandler } from "./dataHandler";
@@ -258,7 +257,7 @@ function renderHandler(request, options, mode, onError) {
258
257
  }
259
258
  function _renderHandler() {
260
259
  _renderHandler = _async_to_generator(function(request, options, mode, onError) {
261
- var _options_config_server, serverData, response, serverManifest, ssrByRouteIds, nestedRoutesJson, routes, url, matchedRoutes, _lastMatch_route, lastMatch, e, newRes, routeInfo;
260
+ var _options_config_server, serverData, response, serverManifest, ssrByRouteIds, nestedRoutesJson, routes, matchRoutes, url, matchedRoutes, _lastMatch_route, lastMatch, e, newRes, routeInfo;
262
261
  function applyExtendHeaders(r, route) {
263
262
  Object.entries(route.responseHeaders || {}).forEach(function(param) {
264
263
  var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
@@ -277,68 +276,82 @@ function _renderHandler() {
277
276
  response = null;
278
277
  serverManifest = options.serverManifest;
279
278
  ssrByRouteIds = (_options_config_server = options.config.server) === null || _options_config_server === void 0 ? void 0 : _options_config_server.ssrByRouteIds;
280
- if (serverManifest.nestedRoutesJson && ssrByRouteIds && (ssrByRouteIds === null || ssrByRouteIds === void 0 ? void 0 : ssrByRouteIds.length) > 0) {
281
- nestedRoutesJson = serverManifest.nestedRoutesJson;
282
- routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
283
- if (routes) {
284
- url = new URL(request.url);
285
- matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
286
- if (!matchedRoutes) {
287
- response = csrRender(options.html);
288
- } else {
289
- ;
290
- lastMatch = matchedRoutes[matchedRoutes.length - 1];
291
- if (!(lastMatch === null || lastMatch === void 0 ? void 0 : (_lastMatch_route = lastMatch.route) === null || _lastMatch_route === void 0 ? void 0 : _lastMatch_route.id) || !ssrByRouteIds.includes(lastMatch.route.id)) {
292
- response = csrRender(options.html);
293
- }
294
- }
279
+ if (!(serverManifest.nestedRoutesJson && ssrByRouteIds && (ssrByRouteIds === null || ssrByRouteIds === void 0 ? void 0 : ssrByRouteIds.length) > 0))
280
+ return [
281
+ 3,
282
+ 2
283
+ ];
284
+ nestedRoutesJson = serverManifest.nestedRoutesJson;
285
+ routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
286
+ if (!routes)
287
+ return [
288
+ 3,
289
+ 2
290
+ ];
291
+ return [
292
+ 4,
293
+ import("@modern-js/runtime-utils/remix-router")
294
+ ];
295
+ case 1:
296
+ matchRoutes = _state.sent().matchRoutes;
297
+ url = new URL(request.url);
298
+ matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
299
+ if (!matchedRoutes) {
300
+ response = csrRender(options.html);
301
+ } else {
302
+ ;
303
+ lastMatch = matchedRoutes[matchedRoutes.length - 1];
304
+ if (!(lastMatch === null || lastMatch === void 0 ? void 0 : (_lastMatch_route = lastMatch.route) === null || _lastMatch_route === void 0 ? void 0 : _lastMatch_route.id) || !ssrByRouteIds.includes(lastMatch.route.id)) {
305
+ response = csrRender(options.html);
295
306
  }
296
307
  }
308
+ _state.label = 2;
309
+ case 2:
297
310
  if (!(mode === "ssr" && !response))
298
311
  return [
299
312
  3,
300
- 6
313
+ 8
301
314
  ];
302
- _state.label = 1;
303
- case 1:
315
+ _state.label = 3;
316
+ case 3:
304
317
  _state.trys.push([
305
- 1,
306
318
  3,
319
+ 5,
307
320
  ,
308
- 5
321
+ 7
309
322
  ]);
310
323
  return [
311
324
  4,
312
325
  ssrRender(request, options)
313
326
  ];
314
- case 2:
327
+ case 4:
315
328
  response = _state.sent();
316
329
  return [
317
330
  3,
318
- 5
331
+ 7
319
332
  ];
320
- case 3:
333
+ case 5:
321
334
  e = _state.sent();
322
335
  return [
323
336
  4,
324
337
  onError(e)
325
338
  ];
326
- case 4:
339
+ case 6:
327
340
  _state.sent();
328
341
  response = csrRender(options.html);
329
342
  return [
330
343
  3,
331
- 5
344
+ 7
332
345
  ];
333
- case 5:
346
+ case 7:
334
347
  return [
335
348
  3,
336
- 7
349
+ 9
337
350
  ];
338
- case 6:
351
+ case 8:
339
352
  response = csrRender(options.html);
340
- _state.label = 7;
341
- case 7:
353
+ _state.label = 9;
354
+ case 9:
342
355
  newRes = transformResponse(response, injectServerData(serverData));
343
356
  routeInfo = options.routeInfo;
344
357
  applyExtendHeaders(newRes, routeInfo);
@@ -1,6 +1,5 @@
1
1
  import { cutNameByHyphen } from "@modern-js/utils/universal";
2
2
  import { TrieRouter } from "hono/router/trie-router";
3
- import { matchRoutes } from "@modern-js/runtime-utils/router";
4
3
  import { parseQuery, getPathname, createErrorHtml, sortRoutes, transformResponse, onError as onErrorFn, ErrorDigest, parseHeaders } from "../../utils";
5
4
  import { REPLACE_REG, X_MODERNJS_RENDER } from "../../constants";
6
5
  import { dataHandler } from "./dataHandler";
@@ -132,6 +131,7 @@ async function renderHandler(request, options, mode, onError) {
132
131
  const { nestedRoutesJson } = serverManifest;
133
132
  const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
134
133
  if (routes) {
134
+ const { matchRoutes } = await import("@modern-js/runtime-utils/remix-router");
135
135
  const url = new URL(request.url);
136
136
  const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
137
137
  if (!matchedRoutes) {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.57.0",
18
+ "version": "2.57.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -52,9 +52,9 @@
52
52
  "@web-std/file": "^3.0.3",
53
53
  "hono": "^3.12.2",
54
54
  "ts-deepmerge": "7.0.0",
55
- "@modern-js/plugin": "2.57.0",
56
- "@modern-js/runtime-utils": "2.57.0",
57
- "@modern-js/utils": "2.57.0"
55
+ "@modern-js/plugin": "2.57.1",
56
+ "@modern-js/runtime-utils": "2.57.1",
57
+ "@modern-js/utils": "2.57.1"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/jest": "^29",
@@ -64,9 +64,9 @@
64
64
  "jest": "^29",
65
65
  "ts-jest": "^29.1.0",
66
66
  "typescript": "^5",
67
- "@modern-js/types": "2.57.0",
68
- "@scripts/build": "2.57.0",
69
- "@scripts/jest-config": "2.57.0"
67
+ "@modern-js/types": "2.57.1",
68
+ "@scripts/build": "2.57.1",
69
+ "@scripts/jest-config": "2.57.1"
70
70
  },
71
71
  "sideEffects": false,
72
72
  "publishConfig": {