@modern-js/types 2.69.4 → 3.0.0-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.
package/cli/index.d.ts CHANGED
@@ -27,11 +27,6 @@ export interface Entrypoint {
27
27
  nestedRoutesEntry?: string;
28
28
  pageRoutesEntry?: string;
29
29
  isAutoMount?: boolean;
30
- /**
31
- * @deprecated
32
- * Using customEntry instead.
33
- */
34
- customBootstrap?: string | false;
35
30
  /**
36
31
  * use src/{entryName}/entry.tsx to custom entry
37
32
  */
@@ -82,6 +77,9 @@ export type NestedRouteForCli = NestedRoute<string>;
82
77
 
83
78
  export interface NestedRoute<T = string | (() => JSX.Element)> extends Route {
84
79
  type: 'nested';
80
+ origin: 'file-system' | 'config';
81
+ // Route type to distinguish between page and layout routes
82
+ routeType?: 'page' | 'layout';
85
83
  parentId?: string;
86
84
  data?: string;
87
85
  clientData?: string;
@@ -95,6 +93,7 @@ export interface NestedRoute<T = string | (() => JSX.Element)> extends Route {
95
93
  isRoot?: boolean;
96
94
  config?: string | Record<string, any>;
97
95
  inValidSSRRoute?: boolean;
96
+ params?: string[];
98
97
  }
99
98
 
100
99
  export interface PageRoute extends Route {
@@ -123,27 +122,29 @@ export type SSGRouteOptions =
123
122
  | {
124
123
  url: string;
125
124
  output?: string;
126
- params?: Record<string, any>[];
127
125
  headers?: Record<string, any>;
128
126
  };
129
127
 
130
128
  export type SSGSingleEntryOptions =
131
129
  | boolean
132
130
  | {
133
- preventDefault?: string[];
134
131
  headers?: Record<string, any>;
135
132
  routes?: SSGRouteOptions[];
136
133
  };
137
134
 
138
- export type SSGMultiEntryOptions = Record<string, SSGSingleEntryOptions>;
135
+ export type SSGSingleEntryOptionsFactory = (
136
+ entryName: string,
137
+ ctx: { baseUrl?: string | string[] },
138
+ ) => SSGSingleEntryOptions;
139
+
140
+ export type SSGMultiEntryOptions = Record<
141
+ string,
142
+ SSGSingleEntryOptions | SSGSingleEntryOptionsFactory
143
+ >;
139
144
 
140
145
  export type SSGConfig =
141
146
  | boolean
142
147
  | SSGSingleEntryOptions
143
- | SSGMultiEntryOptions
144
- | ((
145
- entryName: string,
146
- payload: { baseUrl?: string },
147
- ) => SSGSingleEntryOptions);
148
+ | SSGSingleEntryOptionsFactory;
148
149
 
149
150
  export type { Merge } from 'type-fest';
package/common/index.d.ts CHANGED
@@ -12,4 +12,4 @@ export type ServerPlugin = {
12
12
  options?: Record<string, any>;
13
13
  };
14
14
 
15
- export type SSRMode = 'string' | 'stream';
15
+ export type SSRMode = 'string' | 'stream' | false;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.69.4",
18
+ "version": "3.0.0-alpha.0",
19
19
  "types": "./index.d.ts",
20
20
  "exports": {
21
21
  ".": {
@@ -43,13 +43,9 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/babel__core": "^7.20.5",
46
- "@types/jest": "^29",
47
- "@types/node": "^18",
46
+ "@types/node": "^20",
48
47
  "http-proxy-middleware": "^2.0.9",
49
- "jest": "^29",
50
- "type-fest": "2.15.0",
51
- "@scripts/jest-config": "2.66.0",
52
- "@scripts/build": "2.66.0"
48
+ "type-fest": "2.19.0"
53
49
  },
54
50
  "sideEffects": false,
55
51
  "publishConfig": {
@@ -57,7 +53,7 @@
57
53
  "access": "public"
58
54
  },
59
55
  "scripts": {
60
- "test": "jest --passWithNoTests"
56
+ "test": "rstest --passWithNoTests"
61
57
  },
62
58
  "main": ""
63
59
  }
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from '@rstest/core';
2
+
3
+ export default defineConfig({
4
+ globals: true,
5
+ });
@@ -69,6 +69,7 @@ export interface BaseResponseLike {
69
69
  }
70
70
 
71
71
  export type BaseSSRServerContext<T extends 'node' | 'worker' = 'node'> = {
72
+ baseUrl: string;
72
73
  request: {
73
74
  params: Record<string, string>;
74
75
  pathname: string;
@@ -80,10 +81,8 @@ export type BaseSSRServerContext<T extends 'node' | 'worker' = 'node'> = {
80
81
  userAgent?: string;
81
82
  cookie?: string;
82
83
  cookieMap?: Record<string, string>;
83
- [propsName: string]: any;
84
84
  };
85
85
  response: BaseResponseLike;
86
- redirection: { url?: string; status?: number };
87
86
  loadableStats: Record<string, any>;
88
87
  routeManifest?: Record<string, any>;
89
88
  template: string;
@@ -93,46 +92,11 @@ export type BaseSSRServerContext<T extends 'node' | 'worker' = 'node'> = {
93
92
  serverTiming: ServerTiming;
94
93
  reporter?: Reporter;
95
94
  metrics?: Metrics;
96
-
97
- // TODO: remove it
98
- /** @deprecated */
99
- cacheConfig?: any;
100
-
101
- enableUnsafeCtx?: boolean;
102
-
103
95
  nonce?: string;
104
-
105
- /** @deprecated source req */
106
- req?: T extends 'worker' ? Request : ModernServerContext['req'];
107
-
108
- /** @deprecated source res */
109
- res?: T extends 'worker' ? BaseResponseLike : ModernServerContext['res'];
110
-
111
96
  /** SSR type */
112
97
  mode?: SSRMode;
113
-
114
- /** Check if it's spider request */
115
- isSpider?: boolean;
116
98
  };
117
99
 
118
100
  export interface ServerInitHookContext {
119
101
  app?: HttpServer;
120
102
  }
121
-
122
- /**
123
- * This type extends the `serverContext` type and is also compatible with `ServerPluginLegacy`.
124
- * Future implementations should consider it as an extension of the `serverContext` type.
125
- */
126
- export interface ISAppContext {
127
- appDirectory: string;
128
- internalDirectory: string;
129
- apiDirectory?: string;
130
- lambdaDirectory?: string;
131
- distDirectory: string;
132
- sharedDirectory: string;
133
- plugins: {
134
- server?: any;
135
- serverPkg?: any;
136
- }[];
137
- [key: string]: unknown;
138
- }
@@ -1,5 +1,5 @@
1
1
  import type { NodeRequest, NodeResponse } from '@modern-js/server-core/node';
2
- import type { BffProxyOptions, NextFunction } from './utils';
2
+ import type { DevProxyOptions, NextFunction } from './utils';
3
3
 
4
4
  export type DevServerHttpsOptions = boolean | { key: string; cert: string };
5
5
 
@@ -15,59 +15,3 @@ export type ExposeServerApis = {
15
15
  data?: string | boolean | Record<string, any>,
16
16
  ) => void;
17
17
  };
18
-
19
- export type DevServerOptions = {
20
- /** config of hmr client. */
21
- client?: {
22
- path?: string;
23
- port?: string;
24
- host?: string;
25
- protocol?: 'ws' | 'wss';
26
- };
27
- /** Whether to enable gzip compression */
28
- compress?: boolean;
29
- devMiddleware?: {
30
- writeToDisk?: boolean | ((filename: string) => boolean);
31
- outputFileSystem?: Record<string, any>;
32
- };
33
- proxy?: BffProxyOptions;
34
- headers?: Record<string, string | string[]>;
35
- before?: RequestHandler[];
36
- after?: RequestHandler[];
37
- /** Provides the ability to execute a custom function and apply custom middlewares */
38
- setupMiddlewares?: Array<
39
- (
40
- /** Order: `devServer.before` => `unshift` => internal middlewares => `push` => `devServer.after` */
41
- middlewares: {
42
- /** Use the `unshift` method if you want to run a middleware before all other middlewares */
43
- unshift: (...handlers: RequestHandler[]) => void;
44
- /** Use the `push` method if you want to run a middleware after all other middlewares */
45
- push: (...handlers: RequestHandler[]) => void;
46
- },
47
- server: ExposeServerApis,
48
- ) => void
49
- >;
50
- /** Whether to watch files change. */
51
- watch?: boolean;
52
- /** Whether to enable hot reload. */
53
- hot?: boolean;
54
- /** Whether to enable page reload. */
55
- liveReload?: boolean;
56
- /** Whether to enable https. */
57
- https?: DevServerHttpsOptions;
58
- /** see https://github.com/bripkens/connect-history-api-fallback */
59
- historyApiFallback?:
60
- | boolean
61
- | {
62
- index?: string;
63
- verbose?: boolean;
64
- logger?: typeof console.log;
65
- htmlAcceptHeaders?: string[];
66
- disableDotRule?: true;
67
- rewrites?: Array<{
68
- from: RegExp;
69
- to: string | RegExp | function;
70
- }>;
71
- };
72
- [propName: string]: any;
73
- };
package/server/rsc.d.ts CHANGED
@@ -52,70 +52,3 @@ export type ServerManifest = {
52
52
  export type ClientManifest = {
53
53
  [id: string]: ImportManifestEntry;
54
54
  };
55
-
56
- declare module '@modern-js/utils/react-server-dom-webpack/server' {
57
- export const registerClientReference: <T>(
58
- proxyImplementation: any,
59
- id: string,
60
- exportName: string,
61
- ) => ClientReference[];
62
-
63
- export const registerServerReference: <T>(
64
- proxyImplementation: any,
65
- id: string,
66
- exportName: string,
67
- ) => ServerReference[];
68
- }
69
-
70
- declare module '@modern-js/utils/react-server-dom-webpack/server.edge' {
71
- type Options = {
72
- environmentName?: string;
73
- identifierPrefix?: string;
74
- signal?: AbortSignal;
75
- temporaryReferences?: TemporaryReferenceSet;
76
- onError?: ((error: unknown) => void) | undefined;
77
- onPostpone?: ((reason: string) => void) | undefined;
78
- };
79
-
80
- export function renderToReadableStream(
81
- model: ReactClientValue,
82
- webpackMap: ClientManifest,
83
- options?: Options,
84
- ): ReadableStream;
85
- export function decodeReply<T>(
86
- body: string | FormData,
87
- webpackMap?: ServerManifest,
88
- ): Promise<T>;
89
- }
90
-
91
- declare module '@modern-js/utils/react-server-dom-webpack/client' {
92
- type CallServerCallback = <T, A extends unknown[] = unknown[]>(
93
- string,
94
- args: A,
95
- ) => Promise<T>;
96
-
97
- type Options<T> = {
98
- callServer?: CallServerCallback<T>;
99
- temporaryReferences?: TemporaryReferenceSet;
100
- };
101
-
102
- export function createFromFetch<T>(
103
- promiseForResponse: Promise<Response>,
104
- options?: Options<T>,
105
- ): Promise<T>;
106
- export function encodeReply(
107
- value: ReactServerValue,
108
- options?: { temporaryReferences?: TemporaryReferenceSet },
109
- ): Promise<string | URLSearchParams | FormData>;
110
- }
111
-
112
- declare module '@modern-js/utils/react-server-dom-webpack/client.edge' {
113
- export type Options = {
114
- ssrManifest: SSRManifest;
115
- nonce?: string;
116
- };
117
- export function createFromReadableStream<T>(
118
- stream: ReadableStream,
119
- options: Options<T>,
120
- ): Promise<T>;
121
- }
package/server/utils.d.ts CHANGED
@@ -68,12 +68,12 @@ export type ProxyDetail = ProxyOptions & {
68
68
  bypass?: (
69
69
  req: IncomingMessage,
70
70
  res: ServerResponse,
71
- proxyOptions: BffProxyOptions,
71
+ proxyOptions: DevProxyOptions,
72
72
  ) => string | undefined | null | false;
73
73
  context?: ProxyFilter;
74
74
  };
75
75
 
76
- export type BffProxyOptions =
76
+ export type DevProxyOptions =
77
77
  | Record<string, string>
78
78
  | Record<string, ProxyDetail>
79
79
  | ProxyDetail[]
@@ -1,40 +0,0 @@
1
- import type { RequestPayload } from './context';
2
- import type { ServerRoute } from './route';
3
-
4
- type Set<V extends Record<string>> = <Key extends keyof V>(
5
- key: Key,
6
- value: V[Key],
7
- ) => void;
8
-
9
- type Get<V extends Record<string, unknown>> = <Key extends keyof V>(
10
- key: Key,
11
- ) => V[Key];
12
-
13
- type Body = ReadableStream | ArrayBuffer | string | null;
14
-
15
- export type UnstableMiddlewareContext<
16
- V extends Record<string, unknown> = Record<string, unknown>,
17
- > = {
18
- request: Request;
19
- response: Response;
20
- route: Required<Pick<ServerRoute, 'entryName'>>;
21
- get: Get<V & RequestPayload>;
22
- set: Set<V & RequestPayload>;
23
- header: (name: string, value: string, options?: { append?: boolean }) => void;
24
- status: (code: number) => void;
25
- redirect: (location: string, status?: number) => Response;
26
- body: (data: Body, init?: ResponseInit) => Response;
27
- html: (
28
- data: string | Promise<string>,
29
- init?: ResponseInit,
30
- ) => Response | Promise<Response>;
31
- };
32
-
33
- export type UnstableNext = () => Promise<void>;
34
-
35
- export type UnstableMiddleware<
36
- V extends Record<string, unknown> = Record<string, unknown>,
37
- > = (
38
- c: UnstableMiddlewareContext<V>,
39
- next: UnstableNext,
40
- ) => Promise<void | Response>;