@modern-js/server-core 3.7.0 → 3.8.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.
@@ -32,7 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  useHonoContext: ()=>useHonoContext
33
33
  });
34
34
  const storage_js_namespaceObject = require("./utils/storage.js");
35
- const { run, useHonoContext } = (0, storage_js_namespaceObject.createStorage)();
35
+ const { run, useHonoContext } = (0, storage_js_namespaceObject.createStorage)('@modern-js/server-core/hono-context');
36
36
  exports.run = __webpack_exports__.run;
37
37
  exports.useHonoContext = __webpack_exports__.useHonoContext;
38
38
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -43,7 +43,8 @@ var __webpack_exports__ = {};
43
43
  (()=>{
44
44
  __webpack_require__.r(__webpack_exports__);
45
45
  __webpack_require__.d(__webpack_exports__, {
46
- createRender: ()=>createRender
46
+ createRender: ()=>createRender,
47
+ matchRoute: ()=>matchRoute
47
48
  });
48
49
  const universal_namespaceObject = require("@modern-js/utils/universal");
49
50
  const trie_router_namespaceObject = require("hono/router/trie-router");
@@ -76,14 +77,27 @@ var __webpack_exports__ = {};
76
77
  }
77
78
  function matchRoute(router, pathname, entryName) {
78
79
  const matched = router.match('*', pathname);
79
- if (entryName && matched[0].length > 1) {
80
- const matches = matched[0];
81
- const result = matches.find(([route])=>route.entryName === entryName);
82
- return result || [];
80
+ const matchedRoutes = matched[0];
81
+ if (entryName && matchedRoutes.length > 1) {
82
+ for (const [route, params] of matchedRoutes)if (route.entryName === entryName) return [
83
+ route,
84
+ params
85
+ ];
86
+ return [
87
+ void 0,
88
+ {}
89
+ ];
83
90
  }
84
91
  {
85
- const result = matched[0][0];
86
- return result || [];
92
+ const result = matchedRoutes[0];
93
+ if (!result) return [
94
+ void 0,
95
+ {}
96
+ ];
97
+ return [
98
+ result[0],
99
+ result[1]
100
+ ];
87
101
  }
88
102
  }
89
103
  function getHeadersWithoutCookie(headers) {
@@ -260,8 +274,10 @@ var __webpack_exports__ = {};
260
274
  }
261
275
  })();
262
276
  exports.createRender = __webpack_exports__.createRender;
277
+ exports.matchRoute = __webpack_exports__.matchRoute;
263
278
  for(var __rspack_i in __webpack_exports__)if (-1 === [
264
- "createRender"
279
+ "createRender",
280
+ "matchRoute"
265
281
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
266
282
  Object.defineProperty(exports, '__esModule', {
267
283
  value: true
@@ -31,9 +31,19 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  createStorage: ()=>createStorage
32
32
  });
33
33
  const external_async_hooks_namespaceObject = require("async_hooks");
34
- const createStorage = ()=>{
34
+ const getGlobalStorage = (globalKey)=>{
35
+ const registry = globalThis;
36
+ const key = Symbol.for(globalKey);
37
+ let storage = registry[key];
38
+ if (!storage) {
39
+ storage = new external_async_hooks_namespaceObject.AsyncLocalStorage();
40
+ registry[key] = storage;
41
+ }
42
+ return storage;
43
+ };
44
+ const createStorage = (globalKey)=>{
35
45
  let storage;
36
- if (void 0 !== external_async_hooks_namespaceObject.AsyncLocalStorage) storage = new external_async_hooks_namespaceObject.AsyncLocalStorage();
46
+ if (void 0 !== external_async_hooks_namespaceObject.AsyncLocalStorage) storage = globalKey ? getGlobalStorage(globalKey) : new external_async_hooks_namespaceObject.AsyncLocalStorage();
37
47
  const run = (context, cb)=>{
38
48
  if (!storage) throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
39
49
  `);
@@ -1,3 +1,3 @@
1
1
  import { createStorage } from "./utils/storage.mjs";
2
- const { run: run, useHonoContext: useHonoContext } = createStorage();
2
+ const { run: run, useHonoContext: useHonoContext } = createStorage('@modern-js/server-core/hono-context');
3
3
  export { run, useHonoContext };
@@ -36,14 +36,27 @@ function getRouter(routes) {
36
36
  }
37
37
  function matchRoute(router, pathname, entryName) {
38
38
  const matched = router.match('*', pathname);
39
- if (entryName && matched[0].length > 1) {
40
- const matches = matched[0];
41
- const result = matches.find(([route])=>route.entryName === entryName);
42
- return result || [];
39
+ const matchedRoutes = matched[0];
40
+ if (entryName && matchedRoutes.length > 1) {
41
+ for (const [route, params] of matchedRoutes)if (route.entryName === entryName) return [
42
+ route,
43
+ params
44
+ ];
45
+ return [
46
+ void 0,
47
+ {}
48
+ ];
43
49
  }
44
50
  {
45
- const result = matched[0][0];
46
- return result || [];
51
+ const result = matchedRoutes[0];
52
+ if (!result) return [
53
+ void 0,
54
+ {}
55
+ ];
56
+ return [
57
+ result[0],
58
+ result[1]
59
+ ];
47
60
  }
48
61
  }
49
62
  function getHeadersWithoutCookie(headers) {
@@ -218,4 +231,4 @@ async function csrRender(request, options) {
218
231
  });
219
232
  return csrRscRender(request, options);
220
233
  }
221
- export { createRender };
234
+ export { createRender, matchRoute };
@@ -1,7 +1,17 @@
1
1
  import * as __rspack_external_async_hooks from "async_hooks";
2
- const createStorage = ()=>{
2
+ const getGlobalStorage = (globalKey)=>{
3
+ const registry = globalThis;
4
+ const key = Symbol.for(globalKey);
5
+ let storage = registry[key];
6
+ if (!storage) {
7
+ storage = new __rspack_external_async_hooks.AsyncLocalStorage();
8
+ registry[key] = storage;
9
+ }
10
+ return storage;
11
+ };
12
+ const createStorage = (globalKey)=>{
3
13
  let storage;
4
- if (void 0 !== __rspack_external_async_hooks.AsyncLocalStorage) storage = new __rspack_external_async_hooks.AsyncLocalStorage();
14
+ if (void 0 !== __rspack_external_async_hooks.AsyncLocalStorage) storage = globalKey ? getGlobalStorage(globalKey) : new __rspack_external_async_hooks.AsyncLocalStorage();
5
15
  const run = (context, cb)=>{
6
16
  if (!storage) throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
7
17
  `);
@@ -1,4 +1,4 @@
1
1
  import "node:module";
2
2
  import { createStorage } from "./utils/storage.mjs";
3
- const { run: run, useHonoContext: useHonoContext } = createStorage();
3
+ const { run: run, useHonoContext: useHonoContext } = createStorage('@modern-js/server-core/hono-context');
4
4
  export { run, useHonoContext };
@@ -37,14 +37,27 @@ function getRouter(routes) {
37
37
  }
38
38
  function matchRoute(router, pathname, entryName) {
39
39
  const matched = router.match('*', pathname);
40
- if (entryName && matched[0].length > 1) {
41
- const matches = matched[0];
42
- const result = matches.find(([route])=>route.entryName === entryName);
43
- return result || [];
40
+ const matchedRoutes = matched[0];
41
+ if (entryName && matchedRoutes.length > 1) {
42
+ for (const [route, params] of matchedRoutes)if (route.entryName === entryName) return [
43
+ route,
44
+ params
45
+ ];
46
+ return [
47
+ void 0,
48
+ {}
49
+ ];
44
50
  }
45
51
  {
46
- const result = matched[0][0];
47
- return result || [];
52
+ const result = matchedRoutes[0];
53
+ if (!result) return [
54
+ void 0,
55
+ {}
56
+ ];
57
+ return [
58
+ result[0],
59
+ result[1]
60
+ ];
48
61
  }
49
62
  }
50
63
  function getHeadersWithoutCookie(headers) {
@@ -219,4 +232,4 @@ async function csrRender(request, options) {
219
232
  });
220
233
  return csrRscRender(request, options);
221
234
  }
222
- export { createRender };
235
+ export { createRender, matchRoute };
@@ -1,8 +1,18 @@
1
1
  import "node:module";
2
2
  import * as __rspack_external_async_hooks from "async_hooks";
3
- const createStorage = ()=>{
3
+ const getGlobalStorage = (globalKey)=>{
4
+ const registry = globalThis;
5
+ const key = Symbol.for(globalKey);
6
+ let storage = registry[key];
7
+ if (!storage) {
8
+ storage = new __rspack_external_async_hooks.AsyncLocalStorage();
9
+ registry[key] = storage;
10
+ }
11
+ return storage;
12
+ };
13
+ const createStorage = (globalKey)=>{
4
14
  let storage;
5
- if (void 0 !== __rspack_external_async_hooks.AsyncLocalStorage) storage = new __rspack_external_async_hooks.AsyncLocalStorage();
15
+ if (void 0 !== __rspack_external_async_hooks.AsyncLocalStorage) storage = globalKey ? getGlobalStorage(globalKey) : new __rspack_external_async_hooks.AsyncLocalStorage();
6
16
  const run = (context, cb)=>{
7
17
  if (!storage) throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
8
18
  `);
@@ -1,6 +1,8 @@
1
1
  import type { ServerRoute } from '@modern-js/types';
2
+ import type { Router } from 'hono/router';
2
3
  import type { CacheConfig, OnFallback, UserConfig } from '../../types';
3
4
  import type { Render } from '../../types';
5
+ import type { Params } from '../../types/requestHandler';
4
6
  interface CreateRenderOptions {
5
7
  pwd: string;
6
8
  routes: ServerRoute[];
@@ -13,5 +15,7 @@ interface CreateRenderOptions {
13
15
  forceCSRMap?: Map<string, boolean>;
14
16
  nonce?: string;
15
17
  }
18
+ type MatchedRoute = [ServerRoute | undefined, Params];
19
+ export declare function matchRoute(router: Router<ServerRoute>, pathname: string, entryName?: string): MatchedRoute;
16
20
  export declare function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR, forceCSRMap, config, onFallback, }: CreateRenderOptions): Promise<Render>;
17
21
  export {};
@@ -1,4 +1,10 @@
1
1
  export interface DevUserConfig {
2
2
  assetPrefix?: string;
3
+ /**
4
+ * Customize the directory containing the Mock API entry file.
5
+ * Relative paths are resolved from the application directory.
6
+ * @default './config/mock'
7
+ */
8
+ mockDir?: string;
3
9
  }
4
10
  export type DevNormalizedConfig = DevUserConfig;
@@ -1,4 +1,4 @@
1
- declare const createStorage: <T>() => {
1
+ declare const createStorage: <T>(globalKey?: string) => {
2
2
  run: <O>(context: T, cb: () => O | Promise<O>) => Promise<O>;
3
3
  useHonoContext: () => T;
4
4
  };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.7.0",
18
+ "version": "3.8.1",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -71,9 +71,9 @@
71
71
  "flatted": "^3.4.2",
72
72
  "hono": "^4.11.7",
73
73
  "ts-deepmerge": "7.0.3",
74
- "@modern-js/plugin": "3.7.0",
75
- "@modern-js/runtime-utils": "3.7.0",
76
- "@modern-js/utils": "3.7.0"
74
+ "@modern-js/plugin": "3.8.1",
75
+ "@modern-js/runtime-utils": "3.8.1",
76
+ "@modern-js/utils": "3.8.1"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@rslib/core": "0.23.2",
@@ -82,9 +82,9 @@
82
82
  "@types/node": "^20",
83
83
  "http-proxy-middleware": "^2.0.10",
84
84
  "typescript": "^5",
85
- "@scripts/rstest-config": "2.66.0",
86
85
  "@modern-js/rslib": "2.68.10",
87
- "@modern-js/types": "3.7.0"
86
+ "@modern-js/types": "3.8.1",
87
+ "@scripts/rstest-config": "2.66.0"
88
88
  },
89
89
  "sideEffects": false,
90
90
  "publishConfig": {