@modern-js/runtime 2.53.0 → 2.54.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.
Files changed (123) hide show
  1. package/dist/cjs/{runtimeContext.js → cli/constants.js} +6 -10
  2. package/dist/cjs/cli/entry.js +42 -0
  3. package/dist/cjs/cli/index.js +10 -0
  4. package/dist/cjs/core/compatible.js +13 -29
  5. package/dist/cjs/core/{appConfig.js → config.js} +6 -4
  6. package/dist/cjs/core/context/index.js +28 -0
  7. package/dist/cjs/core/context/runtime.js +42 -0
  8. package/dist/cjs/core/index.js +8 -12
  9. package/dist/cjs/core/loader/useLoader.js +2 -2
  10. package/dist/cjs/core/{plugin.js → plugin/base.js} +5 -25
  11. package/dist/cjs/core/plugin/index.js +39 -0
  12. package/dist/cjs/core/plugin/runner.js +42 -0
  13. package/dist/cjs/index.js +2 -4
  14. package/dist/cjs/router/cli/code/getClientRoutes/getRoutes.js +197 -0
  15. package/dist/cjs/router/cli/code/getClientRoutes/getRoutesLegacy.js +195 -0
  16. package/dist/cjs/router/cli/code/getClientRoutes/index.js +31 -0
  17. package/dist/cjs/router/cli/code/getClientRoutes/utils.js +59 -0
  18. package/dist/cjs/router/cli/code/index.js +134 -0
  19. package/dist/cjs/router/cli/code/makeLegalIdentifier.js +37 -0
  20. package/dist/cjs/router/cli/code/nestedRoutes.js +294 -0
  21. package/dist/cjs/router/cli/code/templates.js +371 -0
  22. package/dist/cjs/router/cli/code/utils.js +143 -0
  23. package/dist/cjs/router/cli/constants.js +83 -0
  24. package/dist/cjs/router/cli/entry.js +87 -0
  25. package/dist/cjs/router/cli/handler.js +71 -0
  26. package/dist/cjs/router/cli/index.js +25 -0
  27. package/dist/cjs/router/runtime/plugin.js +7 -4
  28. package/dist/cjs/router/runtime/plugin.node.js +12 -5
  29. package/dist/cjs/ssr/index.node.js +1 -0
  30. package/dist/cjs/state/runtime/plugin.js +3 -2
  31. package/dist/esm/cli/constants.js +4 -0
  32. package/dist/esm/cli/entry.js +14 -0
  33. package/dist/esm/cli/index.js +10 -0
  34. package/dist/esm/core/compatible.js +11 -30
  35. package/dist/esm/core/{appConfig.js → config.js} +4 -1
  36. package/dist/esm/core/context/index.js +4 -0
  37. package/dist/esm/core/context/runtime.js +18 -0
  38. package/dist/esm/core/index.js +4 -6
  39. package/dist/esm/core/loader/useLoader.js +1 -1
  40. package/dist/esm/core/plugin/base.js +21 -0
  41. package/dist/esm/core/plugin/index.js +15 -0
  42. package/dist/esm/core/plugin/runner.js +17 -0
  43. package/dist/esm/index.js +2 -3
  44. package/dist/esm/router/cli/code/getClientRoutes/getRoutes.js +185 -0
  45. package/dist/esm/router/cli/code/getClientRoutes/getRoutesLegacy.js +183 -0
  46. package/dist/esm/router/cli/code/getClientRoutes/index.js +6 -0
  47. package/dist/esm/router/cli/code/getClientRoutes/utils.js +28 -0
  48. package/dist/esm/router/cli/code/index.js +214 -0
  49. package/dist/esm/router/cli/code/makeLegalIdentifier.js +15 -0
  50. package/dist/esm/router/cli/code/nestedRoutes.js +397 -0
  51. package/dist/esm/router/cli/code/templates.js +417 -0
  52. package/dist/esm/router/cli/code/utils.js +212 -0
  53. package/dist/esm/router/cli/constants.js +47 -0
  54. package/dist/esm/router/cli/entry.js +57 -0
  55. package/dist/esm/router/cli/handler.js +103 -0
  56. package/dist/esm/router/cli/index.js +57 -0
  57. package/dist/esm/router/runtime/plugin.js +7 -4
  58. package/dist/esm/router/runtime/plugin.node.js +13 -6
  59. package/dist/esm/ssr/index.node.js +1 -0
  60. package/dist/esm/state/runtime/plugin.js +3 -2
  61. package/dist/esm-node/cli/constants.js +4 -0
  62. package/dist/esm-node/cli/entry.js +8 -0
  63. package/dist/esm-node/cli/index.js +9 -0
  64. package/dist/esm-node/core/compatible.js +12 -28
  65. package/dist/esm-node/core/{appConfig.js → config.js} +2 -1
  66. package/dist/esm-node/core/context/index.js +4 -0
  67. package/dist/esm-node/core/context/runtime.js +16 -0
  68. package/dist/esm-node/core/index.js +4 -6
  69. package/dist/esm-node/core/loader/useLoader.js +1 -1
  70. package/dist/esm-node/core/plugin/base.js +19 -0
  71. package/dist/esm-node/core/plugin/index.js +13 -0
  72. package/dist/esm-node/core/plugin/runner.js +17 -0
  73. package/dist/esm-node/index.js +2 -3
  74. package/dist/esm-node/router/cli/code/getClientRoutes/getRoutes.js +163 -0
  75. package/dist/esm-node/router/cli/code/getClientRoutes/getRoutesLegacy.js +161 -0
  76. package/dist/esm-node/router/cli/code/getClientRoutes/index.js +6 -0
  77. package/dist/esm-node/router/cli/code/getClientRoutes/utils.js +22 -0
  78. package/dist/esm-node/router/cli/code/index.js +100 -0
  79. package/dist/esm-node/router/cli/code/makeLegalIdentifier.js +13 -0
  80. package/dist/esm-node/router/cli/code/nestedRoutes.js +258 -0
  81. package/dist/esm-node/router/cli/code/templates.js +335 -0
  82. package/dist/esm-node/router/cli/code/utils.js +101 -0
  83. package/dist/esm-node/router/cli/constants.js +47 -0
  84. package/dist/esm-node/router/cli/entry.js +50 -0
  85. package/dist/esm-node/router/cli/handler.js +36 -0
  86. package/dist/esm-node/router/cli/index.js +22 -0
  87. package/dist/esm-node/router/runtime/plugin.js +7 -4
  88. package/dist/esm-node/router/runtime/plugin.node.js +12 -5
  89. package/dist/esm-node/ssr/index.node.js +1 -0
  90. package/dist/esm-node/state/runtime/plugin.js +3 -2
  91. package/dist/types/cli/constants.d.ts +1 -0
  92. package/dist/types/cli/entry.d.ts +1 -0
  93. package/dist/types/cli/index.d.ts +1 -0
  94. package/dist/types/core/compatible.d.ts +7 -3
  95. package/dist/types/core/config.d.ts +14 -0
  96. package/dist/types/core/context/index.d.ts +1 -0
  97. package/dist/types/{runtimeContext.d.ts → core/context/runtime.d.ts} +5 -4
  98. package/dist/types/core/index.d.ts +4 -4
  99. package/dist/types/core/plugin/base.d.ts +80 -0
  100. package/dist/types/core/plugin/index.d.ts +29 -0
  101. package/dist/types/core/plugin/runner.d.ts +26 -0
  102. package/dist/types/index.d.ts +2 -2
  103. package/dist/types/router/cli/code/getClientRoutes/getRoutes.d.ts +8 -0
  104. package/dist/types/router/cli/code/getClientRoutes/getRoutesLegacy.d.ts +9 -0
  105. package/dist/types/router/cli/code/getClientRoutes/index.d.ts +2 -0
  106. package/dist/types/router/cli/code/getClientRoutes/utils.d.ts +5 -0
  107. package/dist/types/router/cli/code/index.d.ts +6 -0
  108. package/dist/types/router/cli/code/makeLegalIdentifier.d.ts +1 -0
  109. package/dist/types/router/cli/code/nestedRoutes.d.ts +7 -0
  110. package/dist/types/router/cli/code/templates.d.ts +14 -0
  111. package/dist/types/router/cli/code/utils.d.ts +12 -0
  112. package/dist/types/router/cli/constants.d.ts +32 -0
  113. package/dist/types/router/cli/entry.d.ts +5 -0
  114. package/dist/types/router/cli/handler.d.ts +5 -0
  115. package/dist/types/router/cli/index.d.ts +3 -1
  116. package/dist/types/ssr/serverRender/types.d.ts +3 -0
  117. package/package.json +37 -11
  118. package/dist/esm/core/plugin.js +0 -59
  119. package/dist/esm/runtimeContext.js +0 -7
  120. package/dist/esm-node/core/plugin.js +0 -37
  121. package/dist/esm-node/runtimeContext.js +0 -7
  122. package/dist/types/core/appConfig.d.ts +0 -4
  123. package/dist/types/core/plugin.d.ts +0 -204
@@ -0,0 +1,47 @@
1
+ const PAGES_DIR_NAME = "pages";
2
+ const NESTED_ROUTES_DIR = "routes";
3
+ const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
4
+ const LOADER_EXPORT_NAME = "loader";
5
+ const ACTION_EXPORT_NAME = "action";
6
+ const TEMP_LOADERS_DIR = "__loaders__";
7
+ const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
8
+ const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
9
+ const FILE_SYSTEM_ROUTES_INDEX = "index";
10
+ const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
11
+ const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
12
+ const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
13
+ const NESTED_ROUTE = {
14
+ LAYOUT_FILE: "layout",
15
+ LAYOUT_CONFIG_FILE: "layout.config",
16
+ LAYOUT_LOADER_FILE: "layout.loader",
17
+ LAYOUT_DATA_FILE: "layout.data",
18
+ LAYOUT_CLIENT_LOADER: "layout.data.client",
19
+ PAGE_FILE: "page",
20
+ PAGE_CONFIG_FILE: "page.config",
21
+ PAGE_LOADER_FILE: "page.loader",
22
+ PAGE_DATA_FILE: "page.data",
23
+ PAGE_CLIENT_LOADER: "page.data.client",
24
+ SPLATE_FILE: "$",
25
+ SPLATE_CONFIG_FILE: "$.config",
26
+ SPLATE_LOADER_FILE: "$.loader",
27
+ SPLATE_DATA_FILE: "$.data",
28
+ SPLATE_CLIENT_DATA: "$.data.client",
29
+ LOADING_FILE: "loading",
30
+ ERROR_FILE: "error",
31
+ LOADER_FILE: "loader"
32
+ };
33
+ export {
34
+ ACTION_EXPORT_NAME,
35
+ FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
36
+ FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
37
+ FILE_SYSTEM_ROUTES_FILE_NAME,
38
+ FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
39
+ FILE_SYSTEM_ROUTES_IGNORED_REGEX,
40
+ FILE_SYSTEM_ROUTES_INDEX,
41
+ FILE_SYSTEM_ROUTES_LAYOUT,
42
+ LOADER_EXPORT_NAME,
43
+ NESTED_ROUTE,
44
+ NESTED_ROUTES_DIR,
45
+ PAGES_DIR_NAME,
46
+ TEMP_LOADERS_DIR
47
+ };
@@ -0,0 +1,50 @@
1
+ import path from "path";
2
+ import { JS_EXTENSIONS, findExists, fs, isRouterV5 } from "@modern-js/utils";
3
+ import { FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, NESTED_ROUTES_DIR, PAGES_DIR_NAME } from "./constants";
4
+ const hasPages = (dir) => fs.existsSync(path.join(dir, PAGES_DIR_NAME));
5
+ const hasNestedRoutes = (dir) => fs.existsSync(path.join(dir, NESTED_ROUTES_DIR));
6
+ const isRouteEntry = (dir) => {
7
+ if (hasNestedRoutes(dir)) {
8
+ return path.join(dir, NESTED_ROUTES_DIR);
9
+ }
10
+ if (hasPages(dir)) {
11
+ return path.join(dir, PAGES_DIR_NAME);
12
+ }
13
+ return false;
14
+ };
15
+ const modifyEntrypoints = (entrypoints, config = {}) => {
16
+ return entrypoints.map((entrypoint) => {
17
+ if (!entrypoint.isAutoMount) {
18
+ return entrypoint;
19
+ }
20
+ const isHasNestedRoutes = hasNestedRoutes(entrypoint.absoluteEntryDir);
21
+ const isHasPages = hasPages(entrypoint.absoluteEntryDir);
22
+ if (!isHasNestedRoutes && !isHasPages) {
23
+ return entrypoint;
24
+ }
25
+ if (entrypoint.fileSystemRoutes && !isRouterV5(config)) {
26
+ entrypoint.nestedRoutesEntry = entrypoint.entry;
27
+ } else if (!entrypoint.fileSystemRoutes) {
28
+ entrypoint.fileSystemRoutes = {
29
+ globalApp: findExists(JS_EXTENSIONS.map((ext) => path.resolve(entrypoint.absoluteEntryDir, `./${PAGES_DIR_NAME}/${FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
30
+ };
31
+ if (isHasPages) {
32
+ entrypoint.entry = path.join(entrypoint.absoluteEntryDir, PAGES_DIR_NAME);
33
+ entrypoint.pageRoutesEntry = entrypoint.entry;
34
+ }
35
+ if (isHasNestedRoutes) {
36
+ entrypoint.entry = path.join(entrypoint.absoluteEntryDir, NESTED_ROUTES_DIR);
37
+ entrypoint.nestedRoutesEntry = entrypoint.entry;
38
+ }
39
+ } else {
40
+ throw Error("Custom entries with conventional routing not support use react router v5!");
41
+ }
42
+ return entrypoint;
43
+ });
44
+ };
45
+ export {
46
+ hasNestedRoutes,
47
+ hasPages,
48
+ isRouteEntry,
49
+ modifyEntrypoints
50
+ };
@@ -0,0 +1,36 @@
1
+ import path from "path";
2
+ import { cloneDeep } from "@modern-js/utils/lodash";
3
+ import { modifyEntrypoints } from "./entry";
4
+ import { isPageComponentFile } from "./code/utils";
5
+ let originEntrypoints = [];
6
+ async function handleModifyEntrypoints(api, entrypoints) {
7
+ const config = api.useResolvedConfigContext();
8
+ const newEntryPoints = modifyEntrypoints(entrypoints, config);
9
+ const appContext = api.useAppContext();
10
+ const resolvedConfig = api.useResolvedConfigContext();
11
+ appContext.entrypoints = newEntryPoints;
12
+ originEntrypoints = cloneDeep(newEntryPoints);
13
+ const { generateCode } = await import("./code");
14
+ await generateCode(appContext, resolvedConfig, entrypoints, api);
15
+ return newEntryPoints;
16
+ }
17
+ async function handleFileChange(api, e) {
18
+ const appContext = api.useAppContext();
19
+ const { appDirectory, entrypoints } = appContext;
20
+ const { filename, eventType } = e;
21
+ const nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
22
+ const pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
23
+ const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
24
+ const absoluteFilePath = path.resolve(appDirectory, filename);
25
+ const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
26
+ if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
27
+ const resolvedConfig = api.useResolvedConfigContext();
28
+ const { generateCode } = await import("./code");
29
+ const entrypoints2 = cloneDeep(originEntrypoints);
30
+ await generateCode(appContext, resolvedConfig, entrypoints2, api);
31
+ }
32
+ }
33
+ export {
34
+ handleFileChange,
35
+ handleModifyEntrypoints
36
+ };
@@ -1,4 +1,8 @@
1
1
  import { getEntryOptions, createRuntimeExportsUtils, isRouterV5 as isV5 } from "@modern-js/utils";
2
+ import { isRouteEntry } from "./entry";
3
+ import { handleFileChange, handleModifyEntrypoints } from "./handler";
4
+ import { isRouteEntry as isRouteEntry2 } from "./entry";
5
+ import { handleFileChange as handleFileChange2, handleModifyEntrypoints as handleModifyEntrypoints2 } from "./handler";
2
6
  const PLUGIN_IDENTIFIER = "router";
3
7
  const ROUTES_IDENTIFIER = "routes";
4
8
  const routerPlugin = () => ({
@@ -10,6 +14,12 @@ const routerPlugin = () => ({
10
14
  const runtimeConfigMap = /* @__PURE__ */ new Map();
11
15
  let pluginsExportsUtils;
12
16
  return {
17
+ checkEntryPoint({ path, entry }) {
18
+ return {
19
+ path,
20
+ entry: entry || isRouteEntry(path)
21
+ };
22
+ },
13
23
  config() {
14
24
  const appContext = api.useAppContext();
15
25
  pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
@@ -29,6 +39,12 @@ const routerPlugin = () => ({
29
39
  }
30
40
  };
31
41
  },
42
+ async modifyEntrypoints({ entrypoints }) {
43
+ const newEntryPoints = await handleModifyEntrypoints(api, entrypoints);
44
+ return {
45
+ entrypoints: newEntryPoints
46
+ };
47
+ },
32
48
  modifyEntryImports({ entrypoint, imports }) {
33
49
  const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
34
50
  const userConfig = api.useResolvedConfigContext();
@@ -80,6 +96,9 @@ const routerPlugin = () => ({
80
96
  if (!isV5(userConfig)) {
81
97
  pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/runtime/router'`);
82
98
  }
99
+ },
100
+ async fileChange(e) {
101
+ await handleFileChange(api, e);
83
102
  }
84
103
  };
85
104
  }
@@ -87,5 +106,8 @@ const routerPlugin = () => ({
87
106
  var cli_default = routerPlugin;
88
107
  export {
89
108
  cli_default as default,
109
+ handleFileChange2 as handleFileChange,
110
+ handleModifyEntrypoints2 as handleModifyEntrypoints,
111
+ isRouteEntry2 as isRouteEntry,
90
112
  routerPlugin
91
113
  };
@@ -55,10 +55,11 @@ const routerPlugin = ({
55
55
  context
56
56
  });
57
57
  },
58
- hoc: ({ App }, next) => {
58
+ hoc: ({ App, config }, next) => {
59
59
  if (!finalRouteConfig && !createRoutes) {
60
60
  return next({
61
- App
61
+ App,
62
+ config
62
63
  });
63
64
  }
64
65
  const getRouteApp = () => {
@@ -132,11 +133,13 @@ const routerPlugin = ({
132
133
  }
133
134
  if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
134
135
  return next({
135
- App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
136
+ App: hoistNonReactStatics(RouteApp, routesConfig.globalApp),
137
+ config
136
138
  });
137
139
  }
138
140
  return next({
139
- App: RouteApp
141
+ App: RouteApp,
142
+ config
140
143
  });
141
144
  },
142
145
  pickContext: ({ context, pickedContext }, next) => {
@@ -53,7 +53,7 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
53
53
  context
54
54
  });
55
55
  }
56
- const { request, mode: ssrMode, nonce } = context.ssrContext;
56
+ const { request, mode: ssrMode, nonce, loaderFailureMode = "errorBoundary" } = context.ssrContext;
57
57
  const baseUrl = originalBaseUrl || request.baseUrl;
58
58
  const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
59
59
  const { reporter, serverTiming } = context.ssrContext;
@@ -83,6 +83,10 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
83
83
  if (routerContext instanceof Response) {
84
84
  return routerContext;
85
85
  }
86
+ if (routerContext.statusCode >= 500 && routerContext.statusCode < 600 && loaderFailureMode === "clientRender") {
87
+ routerContext.statusCode = 200;
88
+ throw routerContext.errors[0];
89
+ }
86
90
  const router = createStaticRouter(routes, routerContext);
87
91
  context.remixRouter = router;
88
92
  context.routerContext = routerContext;
@@ -92,10 +96,11 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
92
96
  context
93
97
  });
94
98
  },
95
- hoc: ({ App }, next) => {
99
+ hoc: ({ App, config }, next) => {
96
100
  if (!routesConfig) {
97
101
  return next({
98
- App
102
+ App,
103
+ config
99
104
  });
100
105
  }
101
106
  const getRouteApp = () => {
@@ -122,11 +127,13 @@ const routerPlugin = ({ basename = "", originalBaseUrl = "", routesConfig, creat
122
127
  const RouteApp = getRouteApp();
123
128
  if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
124
129
  return next({
125
- App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
130
+ App: hoistNonReactStatics(RouteApp, routesConfig.globalApp),
131
+ config
126
132
  });
127
133
  }
128
134
  return next({
129
- App: RouteApp
135
+ App: RouteApp,
136
+ config
130
137
  });
131
138
  },
132
139
  pickContext: ({ context, pickedContext }, next) => {
@@ -18,6 +18,7 @@ const ssr = (config = {}) => ({
18
18
  context.ssrContext.request = formatServer(request);
19
19
  context.ssrContext.mode = config.mode;
20
20
  context.ssrContext.tracker = createSSRTracker(context.ssrContext);
21
+ context.ssrContext.loaderFailureMode = config.loaderFailureMode;
21
22
  if (!context.ssrContext.htmlModifiers) {
22
23
  context.ssrContext.htmlModifiers = [];
23
24
  }
@@ -35,7 +35,7 @@ const state = (config) => ({
35
35
  setup: () => {
36
36
  const storeConfig = getStoreConfig(config);
37
37
  return {
38
- hoc({ App }, next) {
38
+ hoc({ App, config: config2 }, next) {
39
39
  const getStateApp = (props) => {
40
40
  const context = useContext(RuntimeReactContext);
41
41
  return /* @__PURE__ */ _jsx(Provider, {
@@ -47,7 +47,8 @@ const state = (config) => ({
47
47
  });
48
48
  };
49
49
  return next({
50
- App: hoistNonReactStatics(getStateApp, App)
50
+ App: hoistNonReactStatics(getStateApp, App),
51
+ config: config2
51
52
  });
52
53
  },
53
54
  init({ context }, next) {
@@ -0,0 +1 @@
1
+ export declare const APP_FILE_NAME = "App";
@@ -0,0 +1 @@
1
+ export declare const isRuntimeEntry: (dir: string) => string | false;
@@ -1,3 +1,4 @@
1
1
  import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ export { isRuntimeEntry } from './entry';
2
3
  export declare const runtimePlugin: () => CliPlugin<AppTools>;
3
4
  export default runtimePlugin;
@@ -1,13 +1,17 @@
1
1
  import React from 'react';
2
2
  import type { Renderer } from 'react-dom';
3
3
  import type { hydrateRoot, createRoot } from 'react-dom/client';
4
- import { RuntimeContext, TRuntimeContext } from '../runtimeContext';
5
- import { Plugin } from './plugin';
4
+ import { RuntimeContext, TRuntimeContext } from './context/runtime';
5
+ import { Plugin, runtime } from './plugin';
6
6
  export type CreateAppOptions = {
7
7
  plugins: Plugin[];
8
+ /**
9
+ * In the test cases, we need to execute multiple createApp instances simultaneously, and they must not share the runtime.
10
+ */
11
+ runtime?: typeof runtime;
8
12
  props?: any;
9
13
  };
10
- export declare const createApp: ({ plugins, props: globalProps, }: CreateAppOptions) => (App?: React.ComponentType<any>) => React.ComponentType<any>;
14
+ export declare const createApp: ({ plugins, runtime, props: globalProps, }: CreateAppOptions) => (App?: React.ComponentType<any>) => React.ComponentType<any>;
11
15
  type BootStrap<T = unknown> = (App: React.ComponentType, id: string | HTMLElement | RuntimeContext, root?: any, ReactDOM?: {
12
16
  render?: Renderer;
13
17
  hydrate?: Renderer;
@@ -0,0 +1,14 @@
1
+ import type React from 'react';
2
+ import { AppConfig } from '../common';
3
+ import { Plugin } from './plugin';
4
+ export declare const getConfig: (Component: React.ComponentType<any>) => AppConfig | undefined;
5
+ export declare const defineConfig: (Component: React.ComponentType<any>, config: AppConfig) => React.ComponentType<any>;
6
+ interface RuntimeConfig {
7
+ plugins: Plugin[];
8
+ }
9
+ /**
10
+ * This function helps you to autocomplete configuration types.
11
+ * It accepts a direct config object, or a function that returns a config.
12
+ */
13
+ export declare const defineRuntimeConfig: (config: RuntimeConfig) => RuntimeConfig;
14
+ export {};
@@ -0,0 +1 @@
1
+ export { RuntimeReactContext } from './runtime';
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { Store } from '@modern-js-reduck/store';
3
3
  import { type StaticHandlerContext, type Router, type RouterState } from '@modern-js/runtime-utils/remix-router';
4
- import { createLoaderManager } from './core/loader/loaderManager';
5
- import { runtime } from './core/plugin';
6
- import { RouteManifest } from './router/runtime/types';
7
- import { SSRServerContext } from './ssr/serverRender/types';
4
+ import { createLoaderManager } from '../loader/loaderManager';
5
+ import { PluginRunner, runtime } from '../plugin';
6
+ import { RouteManifest } from '../../router/runtime/types';
7
+ import { SSRServerContext } from '../../ssr/serverRender/types';
8
8
  export interface BaseRuntimeContext {
9
9
  initialData?: Record<string, unknown>;
10
10
  loaderManager: ReturnType<typeof createLoaderManager>;
@@ -40,3 +40,4 @@ export interface BaseTRuntimeContext {
40
40
  export interface TRuntimeContext extends BaseTRuntimeContext {
41
41
  [key: string]: any;
42
42
  }
43
+ export declare const getInitialContext: (runner: PluginRunner) => RuntimeContext;
@@ -1,9 +1,9 @@
1
- export { createPlugin, createRuntime, runtime, registerInit } from './plugin';
1
+ export { runtime } from './plugin';
2
2
  export type { Plugin } from './plugin';
3
- export { defineConfig, getConfig } from './appConfig';
3
+ export { defineConfig, getConfig, defineRuntimeConfig } from './config';
4
4
  export * from './compatible';
5
- export type { TRuntimeContext, RuntimeContext } from '../runtimeContext';
6
- export { RuntimeReactContext, ServerRouterContext } from '../runtimeContext';
5
+ export type { RuntimeContext } from './context/runtime';
6
+ export { RuntimeReactContext, ServerRouterContext } from './context/runtime';
7
7
  export * from './loader';
8
8
  export type { SSRData, SSRContainer } from './types';
9
9
  export * from '@modern-js/plugin';
@@ -0,0 +1,80 @@
1
+ /// <reference types="react" />
2
+ import { PluginOptions, Setup } from '@modern-js/plugin';
3
+ import { RuntimeContext, TRuntimeContext } from '../context/runtime';
4
+ export interface AppProps {
5
+ }
6
+ declare const runtimeHooks: {
7
+ hoc: import("@modern-js/plugin").Pipeline<{
8
+ App: React.ComponentType<any>;
9
+ config: Record<string, any>;
10
+ }, import("react").ComponentType<any>>;
11
+ init: import("@modern-js/plugin").AsyncPipeline<{
12
+ context: RuntimeContext;
13
+ }, RuntimeContext>;
14
+ client: import("@modern-js/plugin").AsyncPipeline<{
15
+ App: React.ComponentType<any>;
16
+ readonly context: RuntimeContext;
17
+ ModernRender: (App: React.ReactElement) => void;
18
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
19
+ }, void>;
20
+ server: import("@modern-js/plugin").AsyncPipeline<{
21
+ App: React.ComponentType<any>;
22
+ readonly context: RuntimeContext;
23
+ }, string>;
24
+ pickContext: import("@modern-js/plugin").Pipeline<{
25
+ context: RuntimeContext;
26
+ pickedContext: TRuntimeContext;
27
+ }, TRuntimeContext>;
28
+ };
29
+ /** All hooks of runtime plugin. */
30
+ export type RuntimeHooks = typeof runtimeHooks;
31
+ /** Plugin options of a runtime plugin. */
32
+ export type Plugin = PluginOptions<RuntimeHooks, Setup<RuntimeHooks>>;
33
+ export declare const createRuntime: () => import("@modern-js/plugin").Manager<{
34
+ hoc: import("@modern-js/plugin").Pipeline<{
35
+ App: React.ComponentType<any>;
36
+ config: Record<string, any>;
37
+ }, import("react").ComponentType<any>>;
38
+ init: import("@modern-js/plugin").AsyncPipeline<{
39
+ context: RuntimeContext;
40
+ }, RuntimeContext>;
41
+ client: import("@modern-js/plugin").AsyncPipeline<{
42
+ App: React.ComponentType<any>;
43
+ readonly context: RuntimeContext;
44
+ ModernRender: (App: React.ReactElement) => void;
45
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
46
+ }, void>;
47
+ server: import("@modern-js/plugin").AsyncPipeline<{
48
+ App: React.ComponentType<any>;
49
+ readonly context: RuntimeContext;
50
+ }, string>;
51
+ pickContext: import("@modern-js/plugin").Pipeline<{
52
+ context: RuntimeContext;
53
+ pickedContext: TRuntimeContext;
54
+ }, TRuntimeContext>;
55
+ }, Record<string, never>>;
56
+ export declare const runtime: import("@modern-js/plugin").Manager<{
57
+ hoc: import("@modern-js/plugin").Pipeline<{
58
+ App: React.ComponentType<any>;
59
+ config: Record<string, any>;
60
+ }, import("react").ComponentType<any>>;
61
+ init: import("@modern-js/plugin").AsyncPipeline<{
62
+ context: RuntimeContext;
63
+ }, RuntimeContext>;
64
+ client: import("@modern-js/plugin").AsyncPipeline<{
65
+ App: React.ComponentType<any>;
66
+ readonly context: RuntimeContext;
67
+ ModernRender: (App: React.ReactElement) => void;
68
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
69
+ }, void>;
70
+ server: import("@modern-js/plugin").AsyncPipeline<{
71
+ App: React.ComponentType<any>;
72
+ readonly context: RuntimeContext;
73
+ }, string>;
74
+ pickContext: import("@modern-js/plugin").Pipeline<{
75
+ context: RuntimeContext;
76
+ pickedContext: TRuntimeContext;
77
+ }, TRuntimeContext>;
78
+ }, Record<string, never>>;
79
+ export type PluginRunner = ReturnType<typeof runtime.init>;
80
+ export {};
@@ -0,0 +1,29 @@
1
+ /// <reference types="react" />
2
+ import { runtime, Plugin } from './base';
3
+ export * from './base';
4
+ export interface RuntimeConfig {
5
+ plugins: Plugin[];
6
+ }
7
+ export declare function registerPlugin(internalPlugins: Plugin[], runtimeConfig?: RuntimeConfig, customRuntime?: typeof runtime): import("@modern-js/plugin").ToRunners<{
8
+ hoc: import("@modern-js/plugin").Pipeline<{
9
+ App: import("react").ComponentType<any>;
10
+ config: Record<string, any>;
11
+ }, import("react").ComponentType<any>>;
12
+ init: import("@modern-js/plugin").AsyncPipeline<{
13
+ context: import("..").RuntimeContext;
14
+ }, import("..").RuntimeContext>;
15
+ client: import("@modern-js/plugin").AsyncPipeline<{
16
+ App: import("react").ComponentType<any>;
17
+ readonly context: import("..").RuntimeContext;
18
+ ModernRender: (App: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) => void;
19
+ ModernHydrate: (App: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, callback?: (() => void) | undefined) => void;
20
+ }, void>;
21
+ server: import("@modern-js/plugin").AsyncPipeline<{
22
+ App: import("react").ComponentType<any>;
23
+ readonly context: import("..").RuntimeContext;
24
+ }, string>;
25
+ pickContext: import("@modern-js/plugin").Pipeline<{
26
+ context: import("..").RuntimeContext;
27
+ pickedContext: import("../context/runtime").TRuntimeContext;
28
+ }, import("../context/runtime").TRuntimeContext>;
29
+ }>;
@@ -0,0 +1,26 @@
1
+ /// <reference types="react" />
2
+ import { PluginRunner } from './base';
3
+ export declare function setGlobalRunner(runner: PluginRunner): void;
4
+ export declare function getGlobalRunner(): import("@modern-js/plugin").ToRunners<{
5
+ hoc: import("@modern-js/plugin").Pipeline<{
6
+ App: import("react").ComponentType<any>;
7
+ config: Record<string, any>;
8
+ }, import("react").ComponentType<any>>;
9
+ init: import("@modern-js/plugin").AsyncPipeline<{
10
+ context: import("..").RuntimeContext;
11
+ }, import("..").RuntimeContext>;
12
+ client: import("@modern-js/plugin").AsyncPipeline<{
13
+ App: import("react").ComponentType<any>;
14
+ readonly context: import("..").RuntimeContext;
15
+ ModernRender: (App: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) => void;
16
+ ModernHydrate: (App: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, callback?: (() => void) | undefined) => void;
17
+ }, void>;
18
+ server: import("@modern-js/plugin").AsyncPipeline<{
19
+ App: import("react").ComponentType<any>;
20
+ readonly context: import("..").RuntimeContext;
21
+ }, string>;
22
+ pickContext: import("@modern-js/plugin").Pipeline<{
23
+ context: import("..").RuntimeContext;
24
+ pickedContext: import("../context/runtime").TRuntimeContext;
25
+ }, import("../context/runtime").TRuntimeContext>;
26
+ }>;
@@ -3,7 +3,7 @@ import type { RouterConfig } from './router';
3
3
  export type { Plugin } from './core';
4
4
  export type { AppConfig } from './common';
5
5
  export { isBrowser } from './common';
6
- export type { BaseRuntimeContext, RuntimeContext, BaseTRuntimeContext, TRuntimeContext, } from './runtimeContext';
6
+ export type { BaseRuntimeContext, RuntimeContext, BaseTRuntimeContext, } from './core/context/runtime';
7
7
  export type { RuntimeUserConfig } from './config';
8
- export { createApp, createPlugin, useLoader, bootstrap, RuntimeReactContext, defineConfig, registerInit, useRuntimeContext, } from './core';
8
+ export { createApp, useLoader, bootstrap, RuntimeReactContext, defineConfig, defineRuntimeConfig, useRuntimeContext, } from './core';
9
9
  export { StateConfig, RouterConfig };
@@ -0,0 +1,8 @@
1
+ import type { Entrypoint, NestedRouteForCli, PageRoute } from '@modern-js/types';
2
+ export declare const getClientRoutes: ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias, }: {
3
+ entrypoint: Entrypoint;
4
+ srcDirectory: string;
5
+ srcAlias: string;
6
+ internalDirectory: string;
7
+ internalDirAlias: string;
8
+ }) => (NestedRouteForCli | PageRoute)[];
@@ -0,0 +1,9 @@
1
+ import type { Entrypoint, RouteLegacy } from '@modern-js/types';
2
+ export type { RouteLegacy as Route };
3
+ export declare const getClientRoutes: ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias, }: {
4
+ entrypoint: Entrypoint;
5
+ srcDirectory: string;
6
+ srcAlias: string;
7
+ internalDirectory: string;
8
+ internalDirAlias: string;
9
+ }) => RouteLegacy[];
@@ -0,0 +1,2 @@
1
+ export { getClientRoutes } from './getRoutes';
2
+ export { getClientRoutes as getClientRoutesLegacy } from './getRoutesLegacy';
@@ -0,0 +1,5 @@
1
+ declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
2
+ export { debug };
3
+ export declare const findLayout: (dir: string) => string | false;
4
+ export declare const getRouteWeight: (route: string) => number;
5
+ export declare const shouldSkip: (file: string) => boolean;
@@ -0,0 +1,6 @@
1
+ import { IAppContext, PluginAPI } from '@modern-js/core';
2
+ import type { Entrypoint } from '@modern-js/types';
3
+ import { AppNormalizedConfig, AppTools, ImportStatement } from '@modern-js/app-tools';
4
+ export declare const generateCode: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>) => Promise<{
5
+ importsStatemets: Map<string, ImportStatement[]>;
6
+ }>;
@@ -0,0 +1 @@
1
+ export declare function makeLegalIdentifier(str: string): string;
@@ -0,0 +1,7 @@
1
+ import type { NestedRouteForCli } from '@modern-js/types';
2
+ export declare const getRouteId: (componentPath: string, routesDir: string, entryName: string, isMainEntry: boolean) => string;
3
+ export declare const optimizeRoute: (routeTree: NestedRouteForCli) => NestedRouteForCli[];
4
+ export declare const walk: (dirname: string, rootDir: string, alias: {
5
+ name: string;
6
+ basename: string;
7
+ }, entryName: string, isMainEntry: boolean, oldVersion: boolean) => Promise<NestedRouteForCli | NestedRouteForCli[] | null>;
@@ -0,0 +1,14 @@
1
+ import type { Entrypoint, NestedRouteForCli, PageRoute, RouteLegacy, SSRMode } from '@modern-js/types';
2
+ import type { AppNormalizedConfig, IAppContext } from '@modern-js/app-tools';
3
+ export declare const routesForServer: ({ routes, }: {
4
+ routes: (NestedRouteForCli | PageRoute)[];
5
+ }) => string;
6
+ export declare const fileSystemRoutes: ({ routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks, }: {
7
+ routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
8
+ ssrMode?: SSRMode | undefined;
9
+ nestedRoutesEntry?: string | undefined;
10
+ entryName: string;
11
+ internalDirectory: string;
12
+ splitRouteChunks?: boolean | undefined;
13
+ }) => Promise<string>;
14
+ export declare function ssrLoaderCombinedModule(entrypoints: Entrypoint[], entrypoint: Entrypoint, config: AppNormalizedConfig<'shared'>, appContext: IAppContext): string | null;
@@ -0,0 +1,12 @@
1
+ export declare const walkDirectory: (dir: string) => string[];
2
+ export declare const isPageComponentFile: (filePath: string) => boolean;
3
+ export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
4
+ export declare const parseModule: ({ source, filename, }: {
5
+ source: string;
6
+ filename: string;
7
+ }) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
8
+ export declare const hasLoader: (filename: string, source?: string) => Promise<boolean>;
9
+ export declare const hasAction: (filename: string, source?: string) => Promise<boolean>;
10
+ export declare const getServerLoadersFile: (internalDirectory: string, entryName: string) => string;
11
+ export declare const getServerCombinedModueFile: (internalDirectory: string, entryName: string) => string;
12
+ export declare const getPathWithoutExt: (filename: string) => string;