@modern-js/server-core 2.56.2 → 2.57.1-alpha.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 (49) hide show
  1. package/dist/cjs/adapters/node/helper/loadConfig.js +2 -2
  2. package/dist/cjs/adapters/node/plugins/resource.js +4 -1
  3. package/dist/cjs/{plugins/customServer/loader.js → helper.js} +6 -5
  4. package/dist/cjs/index.js +3 -0
  5. package/dist/cjs/plugins/customServer/base.js +3 -0
  6. package/dist/cjs/plugins/customServer/index.js +2 -5
  7. package/dist/cjs/plugins/default.js +42 -0
  8. package/dist/cjs/plugins/index.js +6 -6
  9. package/dist/cjs/plugins/monitors.js +4 -3
  10. package/dist/cjs/plugins/render/index.js +10 -34
  11. package/dist/cjs/plugins/render/inject.js +75 -0
  12. package/dist/cjs/plugins/render/render.js +33 -2
  13. package/dist/esm/adapters/node/helper/loadConfig.js +2 -2
  14. package/dist/esm/adapters/node/plugins/resource.js +13 -3
  15. package/dist/esm/{plugins/customServer/loader.js → helper.js} +3 -2
  16. package/dist/esm/index.js +2 -0
  17. package/dist/esm/plugins/customServer/base.js +3 -0
  18. package/dist/esm/plugins/customServer/index.js +1 -3
  19. package/dist/esm/plugins/default.js +19 -0
  20. package/dist/esm/plugins/index.js +5 -5
  21. package/dist/esm/plugins/monitors.js +3 -3
  22. package/dist/esm/plugins/render/index.js +27 -70
  23. package/dist/esm/plugins/render/inject.js +85 -0
  24. package/dist/esm/plugins/render/render.js +50 -16
  25. package/dist/esm-node/adapters/node/helper/loadConfig.js +2 -2
  26. package/dist/esm-node/adapters/node/plugins/resource.js +5 -2
  27. package/dist/esm-node/{plugins/customServer/loader.js → helper.js} +3 -2
  28. package/dist/esm-node/index.js +2 -0
  29. package/dist/esm-node/plugins/customServer/base.js +3 -0
  30. package/dist/esm-node/plugins/customServer/index.js +1 -3
  31. package/dist/esm-node/plugins/default.js +18 -0
  32. package/dist/esm-node/plugins/index.js +5 -5
  33. package/dist/esm-node/plugins/monitors.js +4 -3
  34. package/dist/esm-node/plugins/render/index.js +7 -32
  35. package/dist/esm-node/plugins/render/inject.js +50 -0
  36. package/dist/esm-node/plugins/render/render.js +23 -2
  37. package/dist/types/{plugins/customServer/loader.d.ts → helper.d.ts} +1 -1
  38. package/dist/types/index.d.ts +1 -0
  39. package/dist/types/plugins/customServer/index.d.ts +0 -1
  40. package/dist/types/plugins/default.d.ts +7 -0
  41. package/dist/types/plugins/index.d.ts +3 -3
  42. package/dist/types/plugins/monitors.d.ts +2 -2
  43. package/dist/types/plugins/render/index.d.ts +3 -16
  44. package/dist/types/plugins/render/inject.d.ts +7 -0
  45. package/dist/types/types/config/output.d.ts +0 -1
  46. package/dist/types/types/config/server.d.ts +4 -0
  47. package/dist/types/types/plugin.d.ts +10 -0
  48. package/dist/types/types/server.d.ts +1 -0
  49. package/package.json +7 -7
@@ -117,14 +117,35 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
117
117
  };
118
118
  }
119
119
  async function renderHandler(request, options, mode, onError) {
120
+ var _options_config_server;
120
121
  const serverData = {
121
122
  router: {
122
123
  baseUrl: options.routeInfo.urlPath,
123
124
  params: options.params
124
125
  }
125
126
  };
126
- let response;
127
- if (mode === "ssr") {
127
+ let response = null;
128
+ const { serverManifest } = options;
129
+ const ssrByRouteIds = (_options_config_server = options.config.server) === null || _options_config_server === void 0 ? void 0 : _options_config_server.ssrByRouteIds;
130
+ if (serverManifest.nestedRoutesJson && ssrByRouteIds && (ssrByRouteIds === null || ssrByRouteIds === void 0 ? void 0 : ssrByRouteIds.length) > 0) {
131
+ const { nestedRoutesJson } = serverManifest;
132
+ const routes = nestedRoutesJson === null || nestedRoutesJson === void 0 ? void 0 : nestedRoutesJson[options.routeInfo.entryName];
133
+ if (routes) {
134
+ const { matchRoutes } = await import("@modern-js/runtime-utils/remix-router");
135
+ const url = new URL(request.url);
136
+ const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
137
+ if (!matchedRoutes) {
138
+ response = csrRender(options.html);
139
+ } else {
140
+ var _lastMatch_route;
141
+ const lastMatch = matchedRoutes[matchedRoutes.length - 1];
142
+ 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)) {
143
+ response = csrRender(options.html);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ if (mode === "ssr" && !response) {
128
149
  try {
129
150
  response = await ssrRender(request, options);
130
151
  } catch (e) {
@@ -1,4 +1,4 @@
1
- import type { Context } from '../../types';
1
+ import type { Context } from './types';
2
2
  type LoaderContext = Map<string, unknown>;
3
3
  type Var = {
4
4
  loaderContext: LoaderContext;
@@ -4,6 +4,7 @@ export type { ServerBase, ServerBaseOptions } from './serverBase';
4
4
  export { createServerBase } from './serverBase';
5
5
  export { PluginManager, type PluginManagerOptions } from './pluginManager';
6
6
  export type { Middleware, Context, Next, HonoRequest as InternalRequest, ServerEnv, ServerManifest, } from './types';
7
+ export { getLoaderCtx } from './helper';
7
8
  export * from './plugins';
8
9
  export * from './types/plugin';
9
10
  export * from './types/render';
@@ -2,7 +2,6 @@ import { ServerRoute, UnstableMiddleware } from '@modern-js/types';
2
2
  import { ServerBase } from '../../serverBase';
3
3
  import { ServerHookRunner, Middleware, ServerEnv } from '../../types';
4
4
  import type { ServerNodeEnv } from '../../adapters/node/hono';
5
- export { getLoaderCtx } from './loader';
6
5
  export declare class CustomServer {
7
6
  private runner;
8
7
  private serverMiddlewarePromise;
@@ -0,0 +1,7 @@
1
+ import { Logger } from '@modern-js/types';
2
+ import type { ServerPlugin } from '../types';
3
+ import { InjectRenderHandlerOptions } from './render';
4
+ export type CreateDefaultPluginsOptions = InjectRenderHandlerOptions & {
5
+ logger?: Logger;
6
+ };
7
+ export declare function createDefaultPlugins(options?: CreateDefaultPluginsOptions): ServerPlugin[];
@@ -1,6 +1,6 @@
1
- export { renderPlugin, getRenderHandler, type RenderPluginOptions, type GetRenderHandlerOptions, } from './render';
1
+ export { renderPlugin, injectRenderHandlerPlugin, type InjectRenderHandlerOptions, getRenderHandler, } from './render';
2
2
  export { faviconPlugin } from './favicon';
3
+ export { injectServerTiming, injectloggerPluigin } from './monitors';
3
4
  export { processedByPlugin } from './processedBy';
4
- export { getLoaderCtx } from './customServer';
5
5
  export { logPlugin } from './log';
6
- export { initMonitorsPlugin, injectServerTiming, injectloggerPluigin, } from './monitors';
6
+ export { createDefaultPlugins, type CreateDefaultPluginsOptions, } from './default';
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from '@modern-js/types';
2
2
  import type { Context, Next, ServerEnv, ServerPlugin } from '../types';
3
3
  export declare const initMonitorsPlugin: () => ServerPlugin;
4
- export declare const injectloggerPluigin: (logger: Logger) => ServerPlugin;
5
- export declare const injectServerTiming: (metaName?: string) => ServerPlugin;
4
+ export declare const injectloggerPluigin: (inputLogger?: Logger) => ServerPlugin;
5
+ export declare const injectServerTiming: () => ServerPlugin;
6
6
  export declare function initReporter(entryName: string): (c: Context<ServerEnv>, next: Next) => Promise<void>;
@@ -1,16 +1,3 @@
1
- import { ServerRoute } from '@modern-js/types';
2
- import { ServerPlugin, Render, UserConfig, CacheConfig } from '../../types';
3
- export interface RenderPluginOptions {
4
- staticGenerate?: boolean;
5
- cacheConfig?: CacheConfig;
6
- }
7
- export declare const renderPlugin: (options?: RenderPluginOptions) => ServerPlugin;
8
- export interface GetRenderHandlerOptions {
9
- pwd: string;
10
- routes: ServerRoute[];
11
- config: UserConfig;
12
- cacheConfig?: CacheConfig;
13
- staticGenerate?: boolean;
14
- metaName?: string;
15
- }
16
- export declare function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate, }: GetRenderHandlerOptions): Promise<Render>;
1
+ import { ServerPlugin } from '../../types';
2
+ export * from './inject';
3
+ export declare const renderPlugin: () => ServerPlugin;
@@ -0,0 +1,7 @@
1
+ import type { CacheConfig, GetRenderHandlerOptions, Render, ServerPlugin } from '../../types';
2
+ export interface InjectRenderHandlerOptions {
3
+ staticGenerate?: boolean;
4
+ cacheConfig?: CacheConfig;
5
+ }
6
+ export declare const injectRenderHandlerPlugin: ({ staticGenerate, cacheConfig, }: InjectRenderHandlerOptions) => ServerPlugin;
7
+ export declare function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate, }: GetRenderHandlerOptions): Promise<Render>;
@@ -12,7 +12,6 @@ export interface OutputUserConfig {
12
12
  };
13
13
  enableInlineRouteManifests?: boolean;
14
14
  disableInlineRouteManifests?: boolean;
15
- path?: string;
16
15
  assetPrefix?: string;
17
16
  polyfill?: 'entry' | 'usage' | 'ua' | 'off';
18
17
  /**
@@ -41,6 +41,10 @@ export type SSR = boolean | {
41
41
  export type SSRByEntries = Record<string, SSR>;
42
42
  export interface ServerUserConfig {
43
43
  routes?: Routes;
44
+ /**
45
+ * Experimenal, it is not recommended to use it now
46
+ */
47
+ ssrByRouteIds?: string[];
44
48
  publicRoutes?: Record<string, string>;
45
49
  ssr?: SSR;
46
50
  ssrByEntries?: SSRByEntries;
@@ -96,10 +96,20 @@ type Middleware = {
96
96
  before?: Array<Middleware['name']>;
97
97
  order?: MiddlewareOrder;
98
98
  };
99
+ export interface GetRenderHandlerOptions {
100
+ pwd: string;
101
+ routes: ServerRoute[];
102
+ config: UserConfig;
103
+ cacheConfig?: CacheConfig;
104
+ staticGenerate?: boolean;
105
+ metaName?: string;
106
+ }
99
107
  declare module '@modern-js/types' {
100
108
  interface ISAppContext {
101
109
  middlewares: Middleware[];
102
110
  metaName: string;
111
+ getRenderOptions?: GetRenderHandlerOptions;
112
+ render?: Render;
103
113
  routes?: ServerRoute[];
104
114
  nodeServer?: NodeServer;
105
115
  }
@@ -28,6 +28,7 @@ export type ServerManifest = {
28
28
  renderBundles?: Record<string, ServerRenderBundle>;
29
29
  loadableStats?: Record<string, any>;
30
30
  routeManifest?: Record<string, any>;
31
+ nestedRoutesJson?: Record<string, any>;
31
32
  };
32
33
  type ServerVariables = {
33
34
  /** @deprecated */
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.56.2",
18
+ "version": "2.57.1-alpha.0",
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.56.2",
56
- "@modern-js/runtime-utils": "2.56.2",
57
- "@modern-js/utils": "2.56.2"
55
+ "@modern-js/plugin": "2.57.0",
56
+ "@modern-js/utils": "2.57.0",
57
+ "@modern-js/runtime-utils": "2.57.0"
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.56.2",
68
- "@scripts/build": "2.56.2",
69
- "@scripts/jest-config": "2.56.2"
67
+ "@scripts/build": "2.57.0",
68
+ "@modern-js/types": "2.57.0",
69
+ "@scripts/jest-config": "2.57.0"
70
70
  },
71
71
  "sideEffects": false,
72
72
  "publishConfig": {