Skip to content

Commit b4c08a1

Browse files
authored
fix: missing type of http proxy middleware options (#12188)
* fix: missing type of http proxy middleware options * fix: missing type of http proxy middleware options * fix: missing type of http proxy middleware options
1 parent 1c2cb29 commit b4c08a1

File tree

3 files changed

+296
-15
lines changed

3 files changed

+296
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"lint:js": "pnpm run lint-ci:js --write",
3434
"lint-ci:js": "biome check --diagnostic-level=warn --no-errors-on-unmatched --max-diagnostics=none --error-on-warnings",
3535
"lint:rs": "cargo clippy --workspace --all-targets",
36-
"lint:type": "rslint --config rslint.json --max-warnings=2233",
36+
"lint:type": "rslint --config rslint.json --max-warnings=2261",
3737
"build:binding:dev": "pnpm --filter @rspack/binding run build:dev",
3838
"build:binding:debug": "pnpm --filter @rspack/binding run build:debug",
3939
"build:binding:ci": "pnpm --filter @rspack/binding run build:ci",

packages/rspack/etc/core.api.md

Lines changed: 146 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type { ExternalObject } from '@rspack/binding';
3333
import { fs } from 'fs';
3434
import { default as fs_2 } from 'graceful-fs';
3535
import { HookMap } from '@rspack/lite-tapable';
36+
import type http from 'http';
3637
import { IncomingMessage } from 'http';
3738
import type { JsAddingRuntimeModule } from '@rspack/binding';
3839
import type { JsAfterEmitData } from '@rspack/binding';
@@ -59,6 +60,7 @@ import type { JsStatsError } from '@rspack/binding';
5960
import * as liteTapable from '@rspack/lite-tapable';
6061
import { Module } from '@rspack/binding';
6162
import type { ModuleGraphConnection } from '@rspack/binding';
63+
import type net from 'net';
6264
import { NormalModule } from '@rspack/binding';
6365
import { RawCopyPattern } from '@rspack/binding';
6466
import { RawCssExtractPluginOption } from '@rspack/binding';
@@ -84,12 +86,14 @@ import { ServerResponse } from 'http';
8486
import { SourceMapDevToolPluginOptions } from '@rspack/binding';
8587
import sources = require('../compiled/webpack-sources');
8688
import { StatSyncFn } from 'fs';
89+
import type stream from 'stream';
8790
import { sync } from '@rspack/binding';
8891
import { SyncBailHook } from '@rspack/lite-tapable';
8992
import { SyncHook } from '@rspack/lite-tapable';
9093
import { SyncWaterfallHook } from '@rspack/lite-tapable';
9194
import type { TransformOutput } from '@rspack/binding';
9295
import { Url } from 'url';
96+
import type url from 'url';
9397

9498
// @public (undocumented)
9599
type Accessibility = "public" | "protected" | "private";
@@ -935,7 +939,7 @@ export class Compilation {
935939
// (undocumented)
936940
getErrors(): WebpackError_2[];
937941
// (undocumented)
938-
getLogger(name: string | (() => string)): Logger;
942+
getLogger(name: string | (() => string)): Logger_2;
939943
// (undocumented)
940944
getPath(filename: string, data?: PathData): string;
941945
// (undocumented)
@@ -1124,7 +1128,7 @@ export class Compiler {
11241128
// (undocumented)
11251129
getCache(name: string): CacheFacade;
11261130
// (undocumented)
1127-
getInfrastructureLogger(name: string | (() => string)): Logger;
1131+
getInfrastructureLogger(name: string | (() => string)): Logger_2;
11281132
// (undocumented)
11291133
hooks: CompilerHooks;
11301134
// (undocumented)
@@ -1734,7 +1738,7 @@ type DevMiddlewareContext<_RequestInternal extends IncomingMessage_2 = IncomingM
17341738
options: any;
17351739
compiler: Compiler | MultiCompiler;
17361740
watching: Watching | MultiWatching_2 | undefined;
1737-
logger: Logger_2;
1741+
logger: Logger;
17381742
outputFileSystem: OutputFileSystem_2;
17391743
};
17401744

@@ -2854,7 +2858,7 @@ export type GeneratorOptionsByModuleTypeKnown = {
28542858
export type GeneratorOptionsByModuleTypeUnknown = Record<string, Record<string, any>>;
28552859

28562860
// @public (undocumented)
2857-
type GetChildLogger = (name: string | (() => string)) => Logger;
2861+
type GetChildLogger = (name: string | (() => string)) => Logger_2;
28582862

28592863
// @public (undocumented)
28602864
export const getNormalizedRspackOptions: (config: RspackOptions) => RspackOptionsNormalized;
@@ -3087,9 +3091,107 @@ export type HtmlRspackPluginOptions = {
30873091
[key: string]: any;
30883092
};
30893093

3094+
// @public (undocumented)
3095+
interface HttpProxyMiddlewareOptions extends HttpProxyServerOptions {
3096+
// (undocumented)
3097+
logLevel?: "debug" | "info" | "warn" | "error" | "silent";
3098+
// (undocumented)
3099+
logProvider?: LogProviderCallback;
3100+
// (undocumented)
3101+
onClose?: OnCloseCallback;
3102+
// (undocumented)
3103+
onError?: OnErrorCallback;
3104+
// (undocumented)
3105+
onOpen?: OnOpenCallback;
3106+
// (undocumented)
3107+
onProxyReq?: OnProxyReqCallback;
3108+
// (undocumented)
3109+
onProxyReqWs?: OnProxyReqWsCallback;
3110+
// (undocumented)
3111+
onProxyRes?: OnProxyResCallback;
3112+
// (undocumented)
3113+
pathRewrite?: {
3114+
[regexp: string]: string;
3115+
} | ((path: string, req: Request_2) => string) | ((path: string, req: Request_2) => Promise<string>);
3116+
// (undocumented)
3117+
router?: {
3118+
[hostOrPath: string]: HttpProxyServerOptions["target"];
3119+
} | ((req: Request_2) => HttpProxyServerOptions["target"]) | ((req: Request_2) => Promise<HttpProxyServerOptions["target"]>);
3120+
}
3121+
30903122
// @public (undocumented)
30913123
type HttpProxyMiddlewareOptionsFilter = any;
30923124

3125+
// @public (undocumented)
3126+
interface HttpProxyServerOptions {
3127+
agent?: any;
3128+
auth?: string | undefined;
3129+
autoRewrite?: boolean | undefined;
3130+
buffer?: stream.Stream | undefined;
3131+
changeOrigin?: boolean | undefined;
3132+
cookieDomainRewrite?: false | string | {
3133+
[oldDomain: string]: string;
3134+
} | undefined;
3135+
cookiePathRewrite?: false | string | {
3136+
[oldPath: string]: string;
3137+
} | undefined;
3138+
followRedirects?: boolean | undefined;
3139+
forward?: HttpProxyTargetUrl | undefined;
3140+
headers?: {
3141+
[header: string]: string;
3142+
} | undefined;
3143+
hostRewrite?: string | undefined;
3144+
ignorePath?: boolean | undefined;
3145+
localAddress?: string | undefined;
3146+
method?: string | undefined;
3147+
prependPath?: boolean | undefined;
3148+
preserveHeaderKeyCase?: boolean | undefined;
3149+
protocolRewrite?: string | undefined;
3150+
proxyTimeout?: number | undefined;
3151+
secure?: boolean | undefined;
3152+
selfHandleResponse?: boolean | undefined;
3153+
ssl?: any;
3154+
target?: HttpProxyTarget | undefined;
3155+
timeout?: number | undefined;
3156+
toProxy?: boolean | undefined;
3157+
ws?: boolean | undefined;
3158+
xfwd?: boolean | undefined;
3159+
}
3160+
3161+
// @public (undocumented)
3162+
type HttpProxyTarget = HttpProxyTargetUrl | HttpProxyTargetDetailed;
3163+
3164+
// @public (undocumented)
3165+
interface HttpProxyTargetDetailed {
3166+
// (undocumented)
3167+
ca?: string | undefined;
3168+
// (undocumented)
3169+
cert?: string | undefined;
3170+
// (undocumented)
3171+
ciphers?: string | undefined;
3172+
// (undocumented)
3173+
host: string;
3174+
// (undocumented)
3175+
hostname?: string | undefined;
3176+
// (undocumented)
3177+
key?: string | undefined;
3178+
// (undocumented)
3179+
passphrase?: string | undefined;
3180+
// (undocumented)
3181+
pfx?: Buffer | string | undefined;
3182+
// (undocumented)
3183+
port: number;
3184+
// (undocumented)
3185+
protocol?: string | undefined;
3186+
// (undocumented)
3187+
secureProtocol?: string | undefined;
3188+
// (undocumented)
3189+
socketPath?: string | undefined;
3190+
}
3191+
3192+
// @public (undocumented)
3193+
type HttpProxyTargetUrl = string | Partial<url.Url>;
3194+
30933195
// @public
30943196
export type HttpUriOptions = HttpUriPluginOptions;
30953197

@@ -4330,7 +4432,7 @@ export interface LoaderContext<OptionsType = {}> {
43304432
getContextDependencies(): string[];
43314433
// (undocumented)
43324434
getDependencies(): string[];
4333-
getLogger(name: string): Logger;
4435+
getLogger(name: string): Logger_2;
43344436
// (undocumented)
43354437
getMissingDependencies(): string[];
43364438
getOptions(schema?: any): OptionsType;
@@ -4467,7 +4569,10 @@ export interface LogEntry {
44674569
type LogFunction = (type: LogTypeEnum, args: any[]) => void;
44684570

44694571
// @public (undocumented)
4470-
class Logger {
4572+
type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
4573+
4574+
// @public (undocumented)
4575+
class Logger_2 {
44714576
// (undocumented)
44724577
[LOG_SYMBOL]: any;
44734578
// (undocumented)
@@ -4518,7 +4623,21 @@ class Logger {
45184623
}
45194624

45204625
// @public (undocumented)
4521-
type Logger_2 = ReturnType<Compiler["getInfrastructureLogger"]>;
4626+
interface LogProvider {
4627+
// (undocumented)
4628+
debug?: Logger;
4629+
// (undocumented)
4630+
error?: Logger;
4631+
// (undocumented)
4632+
info?: Logger;
4633+
// (undocumented)
4634+
log: Logger;
4635+
// (undocumented)
4636+
warn?: Logger;
4637+
}
4638+
4639+
// @public (undocumented)
4640+
type LogProviderCallback = (provider: LogProvider) => LogProvider;
45224641

45234642
// @public
45244643
const LogType: Readonly<{
@@ -4860,7 +4979,7 @@ export class MultiCompiler {
48604979
// (undocumented)
48614980
dependencies: WeakMap<Compiler, string[]>;
48624981
// (undocumented)
4863-
getInfrastructureLogger(name: string): Logger;
4982+
getInfrastructureLogger(name: string): Logger_2;
48644983
// (undocumented)
48654984
hooks: {
48664985
done: liteTapable.SyncHook<MultiStats>;
@@ -5210,6 +5329,24 @@ interface ObjectPattern extends PatternBase {
52105329
// @public (undocumented)
52115330
type ObjectPatternProperty = KeyValuePatternProperty | AssignmentPatternProperty | RestElement;
52125331

5332+
// @public (undocumented)
5333+
type OnCloseCallback = (proxyRes: Response_2, proxySocket: net.Socket, proxyHead: any) => void;
5334+
5335+
// @public (undocumented)
5336+
type OnErrorCallback = (err: Error, req: Request_2, res: Response_2, target?: string | Partial<url.Url>) => void;
5337+
5338+
// @public (undocumented)
5339+
type OnOpenCallback = (proxySocket: net.Socket) => void;
5340+
5341+
// @public (undocumented)
5342+
type OnProxyReqCallback = (proxyReq: http.ClientRequest, req: Request_2, res: Response_2, options: HttpProxyServerOptions) => void;
5343+
5344+
// @public (undocumented)
5345+
type OnProxyReqWsCallback = (proxyReq: http.ClientRequest, req: Request_2, socket: net.Socket, options: HttpProxyServerOptions, head: any) => void;
5346+
5347+
// @public (undocumented)
5348+
type OnProxyResCallback = (proxyRes: http.IncomingMessage, req: Request_2, res: Response_2) => void;
5349+
52135350
// @public (undocumented)
52145351
type Open = (file: PathLike, flags: undefined | string | number, callback: (arg0: null | NodeJS.ErrnoException, arg1?: number) => void) => void;
52155352

@@ -5837,9 +5974,7 @@ type ProxyConfigArrayItem = {
58375974
context?: HttpProxyMiddlewareOptionsFilter;
58385975
} & {
58395976
bypass?: ByPass;
5840-
} & {
5841-
[key: string]: any;
5842-
};
5977+
} & HttpProxyMiddlewareOptions;
58435978

58445979
// @public (undocumented)
58455980
interface PseudoClasses {

0 commit comments

Comments
 (0)