@modern-js/types 2.34.0 → 2.35.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.
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.34.0",
18
+ "version": "2.35.1",
19
19
  "types": "./index.d.ts",
20
20
  "exports": {
21
21
  ".": {
@@ -45,8 +45,8 @@
45
45
  "http-proxy-middleware": "^2.0.4",
46
46
  "jest": "^29",
47
47
  "type-fest": "2.15.0",
48
- "@scripts/build": "2.34.0",
49
- "@scripts/jest-config": "2.34.0"
48
+ "@scripts/jest-config": "2.35.1",
49
+ "@scripts/build": "2.35.1"
50
50
  },
51
51
  "sideEffects": false,
52
52
  "publishConfig": {
@@ -1,4 +1,9 @@
1
- import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
1
+ import {
2
+ IncomingMessage,
3
+ ServerResponse,
4
+ IncomingHttpHeaders,
5
+ Server as HttpServer,
6
+ } from 'http';
2
7
  import qs from 'querystring';
3
8
  import type { SSRMode } from 'common';
4
9
  import { Metrics, Logger, Reporter, ServerTiming } from './utils';
@@ -53,7 +58,13 @@ export interface ModernServerContext {
53
58
  setServerData: (key: string, value: any) => void;
54
59
  }
55
60
 
56
- export type BaseSSRServerContext = {
61
+ export interface BaseResponseLike {
62
+ setHeader: (key: string, value: string) => void;
63
+ status: (code: number) => void;
64
+ locals: Record<string, any>;
65
+ }
66
+
67
+ export type BaseSSRServerContext<T extends 'node' | 'worker' = 'node'> = {
57
68
  request: {
58
69
  params: Record<string, string>;
59
70
  pathname: string;
@@ -62,11 +73,7 @@ export type BaseSSRServerContext = {
62
73
  host: string;
63
74
  [propsName: string]: any;
64
75
  };
65
- response: {
66
- setHeader: (key: string, value: string) => void;
67
- status: (code: number) => void;
68
- locals: Record<string, any>;
69
- };
76
+ response: BaseResponseLike;
70
77
  redirection: { url?: string; status?: number };
71
78
  loadableStats: Record<string, any>;
72
79
  routeManifest?: Record<string, any>;
@@ -97,15 +104,15 @@ export type BaseSSRServerContext = {
97
104
 
98
105
  nonce?: string;
99
106
 
100
- req: ModernServerContext['req'];
107
+ req: T extends 'worker' ? Request : ModernServerContext['req'];
101
108
 
102
- res: ModernServerContext['res'];
109
+ res: T extends 'worker' ? BaseResponseLike : ModernServerContext['res'];
103
110
 
104
111
  mode?: SSRMode; // ssr type
105
112
  };
106
113
 
107
114
  export interface ServerInitHookContext {
108
- app?: httpServer;
115
+ app?: HttpServer;
109
116
  server: ModernServerInterface;
110
117
  }
111
118
 
package/server/route.d.ts CHANGED
@@ -3,7 +3,7 @@ export interface ServerRoute {
3
3
  entryName?: string;
4
4
  // the url path for request match
5
5
  urlPath: string;
6
- // the default resource file to response to route
6
+ // the default asset to response to route
7
7
  entryPath: string;
8
8
  // if route is spa page
9
9
  isSPA?: boolean;