@bleedingdev/modern-js-runtime 3.5.0-ultramodern.1 → 3.5.0-ultramodern.11

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 (33) hide show
  1. package/dist/cjs/core/context/public.js +49 -0
  2. package/dist/cjs/core/context/runtime.js +7 -10
  3. package/dist/cjs/index.js +7 -6
  4. package/dist/cjs/router/runtime/hooks.js +7 -6
  5. package/dist/esm/core/context/public.mjs +5 -0
  6. package/dist/esm/core/context/runtime.mjs +3 -6
  7. package/dist/esm/index.mjs +2 -1
  8. package/dist/esm/router/runtime/hooks.mjs +7 -6
  9. package/dist/esm-node/core/context/public.mjs +6 -0
  10. package/dist/esm-node/core/context/runtime.mjs +3 -6
  11. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +2 -2
  12. package/dist/esm-node/core/server/string/loadable.mjs +2 -2
  13. package/dist/esm-node/index.mjs +2 -1
  14. package/dist/esm-node/router/cli/index.mjs +2 -2
  15. package/dist/esm-node/router/runtime/hooks.mjs +7 -6
  16. package/dist/types/boundary-debugger/index.d.ts +1 -1
  17. package/dist/types/common.d.ts +8 -1
  18. package/dist/types/core/context/index.d.ts +24 -8
  19. package/dist/types/core/context/monitors/default.d.ts +10 -2
  20. package/dist/types/core/context/monitors/index.d.ts +1 -1
  21. package/dist/types/core/context/monitors/index.server.d.ts +2 -2
  22. package/dist/types/core/context/public.d.ts +26 -0
  23. package/dist/types/core/context/runtime.d.ts +15 -28
  24. package/dist/types/core/react/index.d.ts +1 -1
  25. package/dist/types/index.d.ts +5 -5
  26. package/dist/types/internal.d.ts +0 -1
  27. package/dist/types/router/runtime/hooks.d.ts +10 -6
  28. package/dist/types/router/runtime/internal.d.ts +1 -1
  29. package/dist/types/router/runtime/plugin.d.ts +1 -1
  30. package/dist/types/router/runtime/plugin.node.d.ts +1 -1
  31. package/dist/types/router/runtime/provider.d.ts +1 -1
  32. package/dist/types/router/runtime/types.d.ts +26 -4
  33. package/package.json +11 -11
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ ReactRuntimeContext: ()=>ReactRuntimeContext,
32
+ RuntimeContext: ()=>RuntimeContext,
33
+ useRuntimeContext: ()=>useRuntimeContext
34
+ });
35
+ const external_react_namespaceObject = require("react");
36
+ const RuntimeContext = (0, external_react_namespaceObject.createContext)({});
37
+ const ReactRuntimeContext = RuntimeContext;
38
+ const useRuntimeContext = ()=>(0, external_react_namespaceObject.useContext)(RuntimeContext);
39
+ exports.ReactRuntimeContext = __webpack_exports__.ReactRuntimeContext;
40
+ exports.RuntimeContext = __webpack_exports__.RuntimeContext;
41
+ exports.useRuntimeContext = __webpack_exports__.useRuntimeContext;
42
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
43
+ "ReactRuntimeContext",
44
+ "RuntimeContext",
45
+ "useRuntimeContext"
46
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
47
+ Object.defineProperty(exports, '__esModule', {
48
+ value: true
49
+ });
@@ -29,16 +29,14 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  InternalRuntimeContext: ()=>InternalRuntimeContext,
32
- ReactRuntimeContext: ()=>ReactRuntimeContext,
33
- RuntimeContext: ()=>RuntimeContext,
32
+ ReactRuntimeContext: ()=>external_public_js_namespaceObject.ReactRuntimeContext,
33
+ RuntimeContext: ()=>external_public_js_namespaceObject.RuntimeContext,
34
34
  getInitialContext: ()=>getInitialContext,
35
- useRuntimeContext: ()=>useRuntimeContext
35
+ useRuntimeContext: ()=>external_public_js_namespaceObject.useRuntimeContext
36
36
  });
37
- const constants_namespaceObject = require("@modern-js/utils/universal/constants");
38
- const external_react_namespaceObject = require("react");
39
- const InternalRuntimeContext = (0, external_react_namespaceObject.createContext)({});
40
- const RuntimeContext = (0, external_react_namespaceObject.createContext)({});
41
- const ReactRuntimeContext = RuntimeContext;
37
+ const external_public_js_namespaceObject = require("./public.js");
38
+ const ROUTE_MANIFEST = '_MODERNJS_ROUTE_MANIFEST';
39
+ const InternalRuntimeContext = external_public_js_namespaceObject.RuntimeContext;
42
40
  const getInitialContext = (isBrowser = true, routeManifest)=>{
43
41
  const requestContext = {
44
42
  request: {},
@@ -46,12 +44,11 @@ const getInitialContext = (isBrowser = true, routeManifest)=>{
46
44
  };
47
45
  return {
48
46
  isBrowser,
49
- routeManifest: routeManifest || "u" > typeof window && window[constants_namespaceObject.ROUTE_MANIFEST],
47
+ routeManifest: routeManifest || "u" > typeof window && window[ROUTE_MANIFEST],
50
48
  requestContext,
51
49
  context: requestContext
52
50
  };
53
51
  };
54
- const useRuntimeContext = ()=>(0, external_react_namespaceObject.useContext)(RuntimeContext);
55
52
  exports.InternalRuntimeContext = __webpack_exports__.InternalRuntimeContext;
56
53
  exports.ReactRuntimeContext = __webpack_exports__.ReactRuntimeContext;
57
54
  exports.RuntimeContext = __webpack_exports__.RuntimeContext;
package/dist/cjs/index.js CHANGED
@@ -28,19 +28,20 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
- RuntimeContext: ()=>index_js_namespaceObject.RuntimeContext,
32
- defineRuntimeConfig: ()=>index_js_namespaceObject.defineRuntimeConfig,
33
- getMonitors: ()=>monitors_index_js_namespaceObject.getMonitors,
31
+ RuntimeContext: ()=>public_js_namespaceObject.RuntimeContext,
32
+ defineRuntimeConfig: ()=>config_js_namespaceObject.defineRuntimeConfig,
33
+ getMonitors: ()=>index_js_namespaceObject.getMonitors,
34
34
  getRequest: ()=>request_index_js_namespaceObject.getRequest,
35
35
  isBrowser: ()=>external_common_js_namespaceObject.isBrowser,
36
36
  redirect: ()=>response_index_js_namespaceObject.redirect,
37
37
  setHeaders: ()=>response_index_js_namespaceObject.setHeaders,
38
38
  setStatus: ()=>response_index_js_namespaceObject.setStatus,
39
- useRuntimeContext: ()=>index_js_namespaceObject.useRuntimeContext
39
+ useRuntimeContext: ()=>public_js_namespaceObject.useRuntimeContext
40
40
  });
41
41
  const external_common_js_namespaceObject = require("./common.js");
42
- const index_js_namespaceObject = require("./core/index.js");
43
- const monitors_index_js_namespaceObject = require("./core/context/monitors/index.js");
42
+ const config_js_namespaceObject = require("./core/config.js");
43
+ const index_js_namespaceObject = require("./core/context/monitors/index.js");
44
+ const public_js_namespaceObject = require("./core/context/public.js");
44
45
  const request_index_js_namespaceObject = require("./core/context/request/index.js");
45
46
  const response_index_js_namespaceObject = require("./core/context/response/index.js");
46
47
  exports.RuntimeContext = __webpack_exports__.RuntimeContext;
@@ -36,12 +36,13 @@ __webpack_require__.d(__webpack_exports__, {
36
36
  onBeforeHydrateRouter: ()=>onBeforeHydrateRouter
37
37
  });
38
38
  const plugin_namespaceObject = require("@modern-js/plugin");
39
- const modifyRoutes = (0, plugin_namespaceObject.createSyncHook)();
40
- const onBeforeCreateRoutes = (0, plugin_namespaceObject.createSyncHook)();
41
- const onBeforeCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
42
- const onAfterCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
43
- const onBeforeHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
44
- const onAfterHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
39
+ const createRouterSyncHook = ()=>(0, plugin_namespaceObject.createSyncHook)();
40
+ const modifyRoutes = createRouterSyncHook();
41
+ const onBeforeCreateRoutes = createRouterSyncHook();
42
+ const onBeforeCreateRouter = createRouterSyncHook();
43
+ const onAfterCreateRouter = createRouterSyncHook();
44
+ const onBeforeHydrateRouter = createRouterSyncHook();
45
+ const onAfterHydrateRouter = createRouterSyncHook();
45
46
  exports.modifyRoutes = __webpack_exports__.modifyRoutes;
46
47
  exports.onAfterCreateRouter = __webpack_exports__.onAfterCreateRouter;
47
48
  exports.onAfterHydrateRouter = __webpack_exports__.onAfterHydrateRouter;
@@ -0,0 +1,5 @@
1
+ import { createContext, useContext } from "react";
2
+ const RuntimeContext = createContext({});
3
+ const ReactRuntimeContext = RuntimeContext;
4
+ const useRuntimeContext = ()=>useContext(RuntimeContext);
5
+ export { ReactRuntimeContext, RuntimeContext, useRuntimeContext };
@@ -1,8 +1,6 @@
1
- import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
2
- import { createContext, useContext } from "react";
3
- const InternalRuntimeContext = createContext({});
4
- const RuntimeContext = createContext({});
5
- const ReactRuntimeContext = RuntimeContext;
1
+ import { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "./public.mjs";
2
+ const ROUTE_MANIFEST = '_MODERNJS_ROUTE_MANIFEST';
3
+ const InternalRuntimeContext = RuntimeContext;
6
4
  const getInitialContext = (isBrowser = true, routeManifest)=>{
7
5
  const requestContext = {
8
6
  request: {},
@@ -15,5 +13,4 @@ const getInitialContext = (isBrowser = true, routeManifest)=>{
15
13
  context: requestContext
16
14
  };
17
15
  };
18
- const useRuntimeContext = ()=>useContext(RuntimeContext);
19
16
  export { InternalRuntimeContext, ReactRuntimeContext, RuntimeContext, getInitialContext, useRuntimeContext };
@@ -1,5 +1,6 @@
1
1
  export { isBrowser } from "./common.mjs";
2
- export { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from "./core/index.mjs";
2
+ export { defineRuntimeConfig } from "./core/config.mjs";
3
3
  export { getMonitors } from "./core/context/monitors/index.mjs";
4
+ export { RuntimeContext, useRuntimeContext } from "./core/context/public.mjs";
4
5
  export { getRequest } from "./core/context/request/index.mjs";
5
6
  export { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
@@ -1,8 +1,9 @@
1
1
  import { createSyncHook } from "@modern-js/plugin";
2
- const modifyRoutes = createSyncHook();
3
- const onBeforeCreateRoutes = createSyncHook();
4
- const onBeforeCreateRouter = createSyncHook();
5
- const onAfterCreateRouter = createSyncHook();
6
- const onBeforeHydrateRouter = createSyncHook();
7
- const onAfterHydrateRouter = createSyncHook();
2
+ const createRouterSyncHook = ()=>createSyncHook();
3
+ const modifyRoutes = createRouterSyncHook();
4
+ const onBeforeCreateRoutes = createRouterSyncHook();
5
+ const onBeforeCreateRouter = createRouterSyncHook();
6
+ const onAfterCreateRouter = createRouterSyncHook();
7
+ const onBeforeHydrateRouter = createRouterSyncHook();
8
+ const onAfterHydrateRouter = createRouterSyncHook();
8
9
  export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter };
@@ -0,0 +1,6 @@
1
+ import "node:module";
2
+ import { createContext, useContext } from "react";
3
+ const RuntimeContext = createContext({});
4
+ const ReactRuntimeContext = RuntimeContext;
5
+ const useRuntimeContext = ()=>useContext(RuntimeContext);
6
+ export { ReactRuntimeContext, RuntimeContext, useRuntimeContext };
@@ -1,9 +1,7 @@
1
1
  import "node:module";
2
- import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
3
- import { createContext, useContext } from "react";
4
- const InternalRuntimeContext = createContext({});
5
- const RuntimeContext = createContext({});
6
- const ReactRuntimeContext = RuntimeContext;
2
+ import { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "./public.mjs";
3
+ const ROUTE_MANIFEST = '_MODERNJS_ROUTE_MANIFEST';
4
+ const InternalRuntimeContext = RuntimeContext;
7
5
  const getInitialContext = (isBrowser = true, routeManifest)=>{
8
6
  const requestContext = {
9
7
  request: {},
@@ -16,5 +14,4 @@ const getInitialContext = (isBrowser = true, routeManifest)=>{
16
14
  context: requestContext
17
15
  };
18
16
  };
19
- const useRuntimeContext = ()=>useContext(RuntimeContext);
20
17
  export { InternalRuntimeContext, ReactRuntimeContext, RuntimeContext, getInitialContext, useRuntimeContext };
@@ -8,11 +8,11 @@ import { buildHtml } from "../shared.mjs";
8
8
  import { checkIsNode, hasStylesheetLink, safeReplace } from "../utils.mjs";
9
9
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
10
10
  import { dirname as __rspack_dirname } from "node:path";
11
- var beforeTemplate_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
11
+ var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
12
12
  const readAsset = async (chunk)=>{
13
13
  const fs = await import("fs/promises");
14
14
  const path = await import("path");
15
- const filepath = path.join(beforeTemplate_dirname, chunk);
15
+ const filepath = path.join(__rspack_import_meta_dirname__, chunk);
16
16
  return fs.readFile(filepath, 'utf-8');
17
17
  };
18
18
  const checkIsInline = (chunk, enableInline)=>{
@@ -5,7 +5,7 @@ import { getMatchedRouteAssets, orderHydrationScriptChunks } from "../scriptOrde
5
5
  import { attributesToString, checkIsNode, hasStylesheetLink } from "../utils.mjs";
6
6
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
7
7
  import { dirname as __rspack_dirname } from "node:path";
8
- var loadable_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
8
+ var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
9
9
  const extname = (uri)=>{
10
10
  if ('string' != typeof uri || !uri.includes('.')) return '';
11
11
  return `.${uri?.split('.').pop()}` || '';
@@ -28,7 +28,7 @@ const checkIsInline = (chunk, enableInline)=>{
28
28
  const readAsset = async (chunk)=>{
29
29
  const fs = await import("fs/promises");
30
30
  const path = await import("path");
31
- const filepath = path.resolve(loadable_dirname, chunk.filename);
31
+ const filepath = path.resolve(__rspack_import_meta_dirname__, chunk.filename);
32
32
  return fs.readFile(filepath, 'utf-8');
33
33
  };
34
34
  class LoadableCollector {
@@ -1,6 +1,7 @@
1
1
  import "node:module";
2
2
  export { isBrowser } from "./common.mjs";
3
- export { RuntimeContext, defineRuntimeConfig, useRuntimeContext } from "./core/index.mjs";
3
+ export { defineRuntimeConfig } from "./core/config.mjs";
4
4
  export { getMonitors } from "./core/context/monitors/index.mjs";
5
+ export { RuntimeContext, useRuntimeContext } from "./core/context/public.mjs";
5
6
  export { getRequest } from "./core/context/request/index.mjs";
6
7
  export { redirect, setHeaders, setStatus } from "./core/context/response/index.mjs";
@@ -7,7 +7,7 @@ import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } f
7
7
  import { updateNestedRoutesSpec } from "./nestedRoutesSpec.mjs";
8
8
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
9
9
  import { dirname as __rspack_dirname } from "node:path";
10
- var cli_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
10
+ var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
11
11
  function isBuiltInRouteEntrypoint(entrypoint) {
12
12
  const entrypointRoutesOwner = getEntrypointRoutesOwner(entrypoint);
13
13
  if (entrypointRoutesOwner) return entrypointRoutesOwner === BUILT_IN_ROUTES_OWNER;
@@ -62,7 +62,7 @@ const routerPlugin = ()=>({
62
62
  source: {
63
63
  include: [
64
64
  /[\\/]node_modules[\\/]react-router[\\/]/,
65
- node_path.resolve(cli_dirname, '../runtime').replace('cjs', 'esm')
65
+ node_path.resolve(__rspack_import_meta_dirname__, '../runtime').replace('cjs', 'esm')
66
66
  ]
67
67
  }
68
68
  }));
@@ -1,9 +1,10 @@
1
1
  import "node:module";
2
2
  import { createSyncHook } from "@modern-js/plugin";
3
- const modifyRoutes = createSyncHook();
4
- const onBeforeCreateRoutes = createSyncHook();
5
- const onBeforeCreateRouter = createSyncHook();
6
- const onAfterCreateRouter = createSyncHook();
7
- const onBeforeHydrateRouter = createSyncHook();
8
- const onAfterHydrateRouter = createSyncHook();
3
+ const createRouterSyncHook = ()=>createSyncHook();
4
+ const modifyRoutes = createRouterSyncHook();
5
+ const onBeforeCreateRoutes = createRouterSyncHook();
6
+ const onBeforeCreateRouter = createRouterSyncHook();
7
+ const onAfterCreateRouter = createRouterSyncHook();
8
+ const onBeforeHydrateRouter = createRouterSyncHook();
9
+ const onAfterHydrateRouter = createRouterSyncHook();
9
10
  export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter };
@@ -1,4 +1,4 @@
1
- import type { RuntimePlugin } from '../core';
1
+ import type { RuntimePlugin } from '../common';
2
2
  export type BoundaryDebugEntry = {
3
3
  appId: string;
4
4
  color?: string;
@@ -1,5 +1,12 @@
1
- import type { RuntimePlugin } from './core/plugin';
2
1
  export declare const isBrowser: () => boolean;
2
+ export type RuntimePlugin<Extends = unknown> = {
3
+ name?: string;
4
+ registryHooks?: Extends extends {
5
+ extendHooks: infer Hooks;
6
+ } ? Hooks : Record<string, unknown>;
7
+ setup?: (...args: any[]) => unknown;
8
+ [key: string]: unknown;
9
+ };
3
10
  export interface RuntimeConfig {
4
11
  plugins?: RuntimePlugin[];
5
12
  [key: string]: any;
@@ -1,8 +1,24 @@
1
- import type { InternalRuntimeContext } from '@modern-js/plugin';
2
- import type { NestedRoute, PageRoute } from '@modern-js/types';
3
1
  import type React from 'react';
4
- import type { RuntimeExtends } from '../plugin/types';
5
2
  import type { ServerPayload } from './serverPayload/index';
3
+ export type RuntimeRoute = {
4
+ children?: RuntimeRoute[];
5
+ routes?: RuntimeRoute[];
6
+ [key: string]: any;
7
+ };
8
+ type RuntimeHookCaller = {
9
+ call: (...args: any[]) => any;
10
+ [key: string]: unknown;
11
+ };
12
+ type RuntimeHooks = Record<string, RuntimeHookCaller>;
13
+ type RuntimePluginAPI = {
14
+ updateRuntimeContext?: (context: unknown) => unknown;
15
+ [key: string]: any;
16
+ };
17
+ type InternalRuntimeContextLike = {
18
+ hooks: RuntimeHooks;
19
+ pluginAPI?: RuntimePluginAPI;
20
+ [key: string]: any;
21
+ };
6
22
  export { DefaultNotFound } from '../../router/runtime/DefaultNotFound';
7
23
  export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, type RouterExtendsHooks, } from '../../router/runtime/hooks';
8
24
  export { applyRouterRuntimeState, applyRouterServerPrepareResult, cleanupRouterRuntimeState, createRouterRuntimeState, createRouterServerSnapshot, getRouterHydrationScripts, getRouterMatchedRouteIds, getRouterRuntimeState, getRouterServerSnapshot, type RouterLifecycleContext, type RouterLifecyclePhase, } from '../../router/runtime/lifecycle';
@@ -20,7 +36,7 @@ interface GlobalContext {
20
36
  /**
21
37
  * nest router and page router config
22
38
  */
23
- routes?: (NestedRoute | PageRoute)[];
39
+ routes?: RuntimeRoute[];
24
40
  /**
25
41
  * nest router init function
26
42
  */
@@ -33,7 +49,7 @@ interface GlobalContext {
33
49
  * Entry basename for routing
34
50
  */
35
51
  basename?: string;
36
- internalRuntimeContext?: InternalRuntimeContext<RuntimeExtends>;
52
+ internalRuntimeContext?: InternalRuntimeContextLike;
37
53
  /**
38
54
  * RSCRoot
39
55
  */
@@ -48,9 +64,9 @@ export declare function getGlobalEnableRsc(): boolean | undefined;
48
64
  export declare function setGlobalContext(context: Omit<GlobalContext, 'internalRuntimeContext'>): void;
49
65
  export declare function getCurrentEntryName(): string | undefined;
50
66
  export declare function getGlobalRSCRoot(): React.ComponentType<{}> | undefined;
51
- export declare function setGlobalInternalRuntimeContext(context: InternalRuntimeContext<RuntimeExtends>): void;
52
- export declare function getGlobalInternalRuntimeContext(): InternalRuntimeContext<Required<import("@modern-js/plugin").RuntimePluginExtends<import("../plugin/types").RuntimeConfig, import("./runtime").TInternalRuntimeContext, {}, {}>>>;
67
+ export declare function setGlobalInternalRuntimeContext(context: InternalRuntimeContextLike): void;
68
+ export declare function getGlobalInternalRuntimeContext(): InternalRuntimeContextLike;
53
69
  export declare function getGlobalApp(): React.ComponentType<{}> | undefined;
54
- export declare function getGlobalRoutes(): undefined | (NestedRoute | PageRoute)[];
70
+ export declare function getGlobalRoutes(): undefined | RuntimeRoute[];
55
71
  export declare function getGlobalLayoutApp(): React.ComponentType<{}> | undefined;
56
72
  export declare function getGlobalBasename(): string | undefined;
@@ -1,2 +1,10 @@
1
- import type { Monitors } from '@modern-js/types';
2
- export declare const defaultMonitors: Omit<Monitors, 'push'>;
1
+ export type RuntimeMonitors = {
2
+ counter: (name: string, ...args: any[]) => void;
3
+ info: (...args: any[]) => void;
4
+ debug: (...args: any[]) => void;
5
+ trace: (...args: any[]) => void;
6
+ warn: (...args: any[]) => void;
7
+ error: (...args: any[]) => void;
8
+ timing: (name: string, dur: number, ...args: any[]) => void;
9
+ };
10
+ export declare const defaultMonitors: RuntimeMonitors;
@@ -1 +1 @@
1
- export declare const getMonitors: () => Omit<import("@modern-js/types").Monitors, "push">;
1
+ export declare const getMonitors: () => import("./default").RuntimeMonitors;
@@ -1,2 +1,2 @@
1
- import type { Monitors } from '@modern-js/types';
2
- export declare const getMonitors: () => Omit<Monitors, 'push'>;
1
+ import { type RuntimeMonitors } from './default';
2
+ export declare const getMonitors: () => RuntimeMonitors;
@@ -0,0 +1,26 @@
1
+ export type RuntimeRequest = Record<string, unknown>;
2
+ export type RuntimeResponse = Record<string, unknown>;
3
+ export type RequestContext = {
4
+ request: RuntimeRequest;
5
+ response: RuntimeResponse;
6
+ };
7
+ export interface TRuntimeContext {
8
+ initialData?: Record<string, unknown>;
9
+ isBrowser: boolean;
10
+ routes?: unknown[];
11
+ requestContext: RequestContext;
12
+ /**
13
+ * @deprecated Use `requestContext` instead
14
+ */
15
+ context: RequestContext;
16
+ [key: string]: unknown;
17
+ }
18
+ export declare const RuntimeContext: import("react").Context<TRuntimeContext>;
19
+ /**
20
+ * deprecated, use RuntimeContext instead
21
+ */
22
+ export declare const ReactRuntimeContext: import("react").Context<TRuntimeContext>;
23
+ /**
24
+ * @deprecated use use(RuntimeContext) instead
25
+ */
26
+ export declare const useRuntimeContext: () => TRuntimeContext;
@@ -1,36 +1,23 @@
1
- import type { RouteObject, StaticHandlerContext } from '@modern-js/runtime-utils/router';
2
- import type { RouteManifest } from '../../router/runtime/types';
3
- import type { RequestContext, SSRServerContext } from '../types';
4
- export interface TRuntimeContext {
5
- initialData?: Record<string, unknown>;
6
- isBrowser: boolean;
7
- routes?: RouteObject[];
8
- requestContext: RequestContext;
9
- /**
10
- * @deprecated Use `requestContext` instead
11
- */
12
- context: RequestContext;
13
- [key: string]: unknown;
14
- }
1
+ import type { Context } from 'react';
2
+ import { type RequestContext, type TRuntimeContext } from './public';
3
+ export type InternalSSRContext = {
4
+ request: RequestContext['request'] & {
5
+ raw?: Request;
6
+ };
7
+ response: RequestContext['response'];
8
+ [key: string]: any;
9
+ };
10
+ export { ReactRuntimeContext, RuntimeContext, type TRuntimeContext, useRuntimeContext, } from './public';
15
11
  /**
16
12
  * InternalRuntimeContext used internally and by plugins
17
13
  */
18
14
  export interface TInternalRuntimeContext extends TRuntimeContext {
19
- routeManifest?: RouteManifest;
20
- routerContext?: StaticHandlerContext;
15
+ routeManifest?: Record<string, unknown>;
16
+ routerContext?: unknown;
21
17
  unstable_getBlockNavState?: () => boolean;
22
- ssrContext?: SSRServerContext;
18
+ ssrContext?: InternalSSRContext;
23
19
  _internalContext?: any;
24
20
  _internalRouterBaseName?: any;
25
21
  }
26
- export declare const InternalRuntimeContext: import("react").Context<TInternalRuntimeContext>;
27
- export declare const RuntimeContext: import("react").Context<TRuntimeContext>;
28
- /**
29
- * deprecated, use RuntimeContext instead
30
- */
31
- export declare const ReactRuntimeContext: import("react").Context<TRuntimeContext>;
32
- export declare const getInitialContext: (isBrowser?: boolean, routeManifest?: RouteManifest) => TInternalRuntimeContext;
33
- /**
34
- * @deprecated use use(RuntimeContext) instead
35
- */
36
- export declare const useRuntimeContext: () => TRuntimeContext;
22
+ export declare const InternalRuntimeContext: Context<TInternalRuntimeContext>;
23
+ export declare const getInitialContext: (isBrowser?: boolean, routeManifest?: Record<string, unknown>) => TInternalRuntimeContext;
@@ -1,2 +1,2 @@
1
1
  import type React from 'react';
2
- export declare function createRoot(UserApp?: React.ComponentType | null): React.ComponentType<any>;
2
+ export declare function createRoot(UserApp?: React.ComponentType | null): any;
@@ -1,10 +1,10 @@
1
- import type { RouterConfig } from './router/internal';
2
- export type { RuntimeConfig } from './common';
1
+ import type { RouterConfig } from './router/runtime/types';
2
+ export type { RuntimeConfig, RuntimePlugin } from './common';
3
3
  export { isBrowser } from './common';
4
- export type { RuntimePlugin } from './core';
5
- export { defineRuntimeConfig, RuntimeContext, useRuntimeContext, } from './core';
4
+ export { defineRuntimeConfig } from './core/config';
6
5
  export { getMonitors } from './core/context/monitors';
6
+ export type { TRuntimeContext } from './core/context/public';
7
+ export { RuntimeContext, useRuntimeContext, } from './core/context/public';
7
8
  export { getRequest } from './core/context/request';
8
9
  export { redirect, setHeaders, setStatus } from './core/context/response';
9
- export type { TRuntimeContext } from './core/context/runtime';
10
10
  export type { RouterConfig };
@@ -1,2 +1 @@
1
1
  export { InternalRuntimeContext, type TInternalRuntimeContext, } from './core/context/runtime';
2
- export type { SSRServerContext } from './core/types';
@@ -1,12 +1,16 @@
1
1
  import type { RouteObject } from '@modern-js/runtime-utils/router';
2
2
  import type { TRuntimeContext } from '../../core/context/runtime';
3
3
  import type { RouterLifecycleContext } from './lifecycle';
4
- declare const modifyRoutes: import("@modern-js/plugin").SyncHook<(routes: RouteObject[]) => RouteObject[]>;
5
- declare const onBeforeCreateRoutes: import("@modern-js/plugin").SyncHook<(context: TRuntimeContext) => void>;
6
- declare const onBeforeCreateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
7
- declare const onAfterCreateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
8
- declare const onBeforeHydrateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
9
- declare const onAfterHydrateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
4
+ export type RouterSyncHook<Handler extends (...args: any[]) => any> = {
5
+ call: (...args: Parameters<Handler>) => ReturnType<Handler>;
6
+ [key: string]: unknown;
7
+ };
8
+ declare const modifyRoutes: RouterSyncHook<(routes: RouteObject[]) => RouteObject[]>;
9
+ declare const onBeforeCreateRoutes: RouterSyncHook<(context: TRuntimeContext) => void>;
10
+ declare const onBeforeCreateRouter: RouterSyncHook<(context: RouterLifecycleContext) => void>;
11
+ declare const onAfterCreateRouter: RouterSyncHook<(context: RouterLifecycleContext) => void>;
12
+ declare const onBeforeHydrateRouter: RouterSyncHook<(context: RouterLifecycleContext) => void>;
13
+ declare const onAfterHydrateRouter: RouterSyncHook<(context: RouterLifecycleContext) => void>;
10
14
  export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, };
11
15
  export type RouterExtendsHooks = {
12
16
  modifyRoutes: typeof modifyRoutes;
@@ -1,4 +1,4 @@
1
- import type { RuntimePlugin } from '../../core';
1
+ import type { RuntimePlugin } from '../../common';
2
2
  import type { RouterExtendsHooks } from './hooks';
3
3
  import type { RouterConfig, SingleRouteConfig } from './types';
4
4
  export declare const routerPlugin: (userConfig?: Partial<RouterConfig>) => RuntimePlugin<{
@@ -1,4 +1,4 @@
1
- import { type RuntimePlugin } from '../../core';
1
+ import type { RuntimePlugin } from '../../common';
2
2
  import type { RouterExtendsHooks } from './hooks';
3
3
  import type { RouterConfig, Routes } from './types';
4
4
  export declare let finalRouteConfig: RouterConfig['routesConfig'];
@@ -1,4 +1,4 @@
1
- import type { RuntimePlugin } from '../../core';
1
+ import type { RuntimePlugin } from '../../common';
2
2
  import type { RouterExtendsHooks } from './hooks';
3
3
  import type { RouterConfig } from './types';
4
4
  export declare const routerPlugin: (userConfig?: Partial<RouterConfig>) => RuntimePlugin<{
@@ -11,7 +11,7 @@
11
11
  * - `@modern-js/plugin-tanstack` registers the `tanstack` provider when its
12
12
  * runtime entry is imported.
13
13
  */
14
- import type { RuntimePlugin } from '../../core';
14
+ import type { RuntimePlugin } from '../../common';
15
15
  import type { RouterExtendsHooks } from './hooks';
16
16
  import type { RouterConfig } from './types';
17
17
  /**
@@ -1,6 +1,12 @@
1
- import type { RequestContext } from '@modern-js/runtime-utils/node';
2
1
  import type { Params, RouteObject, RouteProps } from '@modern-js/runtime-utils/router';
3
- import type { NestedRoute, PageRoute } from '@modern-js/types';
2
+ export type ModernRoute = {
3
+ type: 'nested' | 'page';
4
+ path?: string;
5
+ id?: string;
6
+ component?: React.ComponentType | string;
7
+ children?: ModernRoute[];
8
+ [key: string]: any;
9
+ };
4
10
  export type SingleRouteConfig = RouteProps & {
5
11
  redirect?: string;
6
12
  routes?: SingleRouteConfig[];
@@ -25,7 +31,7 @@ export type RouterConfig = {
25
31
  framework?: RouterFramework;
26
32
  routesConfig: {
27
33
  globalApp?: React.ComponentType<any>;
28
- routes?: (NestedRoute | PageRoute)[];
34
+ routes?: ModernRoute[];
29
35
  };
30
36
  /**
31
37
  * You should not use it
@@ -108,12 +114,28 @@ export type ModernRouteObject = RouteObject & {
108
114
  component?: React.ComponentType | LazyComponentDescriptor;
109
115
  entryCssFiles?: string[];
110
116
  };
117
+ type LoaderContextKey<T = unknown> = {
118
+ symbol: symbol;
119
+ getDefaultValue: () => T;
120
+ };
121
+ interface LoaderRequestGet<P extends Record<string, unknown>> {
122
+ <Key extends keyof P>(key: Key): P[Key];
123
+ <T>(key: LoaderContextKey<T>): T;
124
+ }
125
+ interface LoaderRequestSet<P extends Record<string, unknown>> {
126
+ <Key extends keyof P>(key: Key, value: P[Key]): void;
127
+ <T>(key: LoaderContextKey<T>, value: T): void;
128
+ }
129
+ type LoaderRequestContext<P extends Record<string, unknown> = {}> = {
130
+ get: LoaderRequestGet<P & Record<string, unknown>>;
131
+ set: LoaderRequestSet<P & Record<string, unknown>>;
132
+ };
111
133
  interface DataFunctionArgs<D = any> {
112
134
  request: Request;
113
135
  params: Params;
114
136
  context?: D;
115
137
  }
116
- export type LoaderFunctionArgs<P extends Record<string, unknown> = Record<string, unknown>> = DataFunctionArgs<RequestContext<P>>;
138
+ export type LoaderFunctionArgs<P extends Record<string, unknown> = Record<string, unknown>> = DataFunctionArgs<LoaderRequestContext<P>>;
117
139
  declare type DataFunctionValue = Response | NonNullable<unknown> | null;
118
140
  export type LoaderFunction = <P extends Record<string, unknown> = Record<string, unknown>>(args: LoaderFunctionArgs<P>) => Promise<DataFunctionValue> | DataFunctionValue;
119
141
  export {};
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.1",
20
+ "version": "3.5.0-ultramodern.11",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -240,12 +240,12 @@
240
240
  "react-helmet": "^6.1.0",
241
241
  "react-helmet-async": "3.0.0",
242
242
  "react-is": "^19.2.7",
243
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.1",
244
- "@modern-js/render": "npm:@bleedingdev/modern-js-render@3.5.0-ultramodern.1",
245
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.1",
246
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.1",
247
- "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.5.0-ultramodern.1",
248
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.1"
243
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.11",
244
+ "@modern-js/render": "npm:@bleedingdev/modern-js-render@3.5.0-ultramodern.11",
245
+ "@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.5.0-ultramodern.11",
246
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.11",
247
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.11",
248
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.11"
249
249
  },
250
250
  "peerDependencies": {
251
251
  "react": "^19.2.7",
@@ -253,19 +253,19 @@
253
253
  },
254
254
  "devDependencies": {
255
255
  "@remix-run/web-fetch": "^4.4.2",
256
- "@rsbuild/core": "2.1.0",
257
- "@rslib/core": "0.23.0",
256
+ "@rsbuild/core": "2.1.1",
257
+ "@rslib/core": "0.23.1",
258
258
  "@testing-library/dom": "^10.4.1",
259
259
  "@testing-library/react": "^16.3.2",
260
260
  "@types/invariant": "^2.2.37",
261
261
  "@types/loadable__server": "5.12.11",
262
262
  "@types/node": "^26.0.1",
263
- "@typescript/native-preview": "7.0.0-dev.20260624.1",
263
+ "@typescript/native-preview": "7.0.0-dev.20260628.1",
264
264
  "react": "^19.2.7",
265
265
  "react-dom": "^19.2.7",
266
266
  "ts-node": "^10.9.2",
267
267
  "typescript": "^6.0.3",
268
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.1",
268
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.11",
269
269
  "@scripts/rstest-config": "2.66.0"
270
270
  },
271
271
  "sideEffects": false,