Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions packages/rspack/etc/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { ExternalObject } from '@rspack/binding';
import { fs } from 'fs';
import { default as fs_2 } from 'graceful-fs';
import { HookMap } from '@rspack/lite-tapable';
import { IncomingMessage as IncomingMessage_2 } from 'http';
import { IncomingMessage } from 'http';
import { inspect } from 'node:util';
import type { JsAddingRuntimeModule } from '@rspack/binding';
import type { JsAfterEmitData } from '@rspack/binding';
Expand Down Expand Up @@ -85,7 +85,7 @@ import { Server } from 'net';
import { Server as Server_2 } from 'tls';
import { Server as Server_3 } from 'http';
import { ServerOptions as ServerOptions_2 } from 'https';
import { ServerResponse as ServerResponse_2 } from 'http';
import { ServerResponse } from 'http';
import { SourceMapDevToolPluginOptions } from '@rspack/binding';
import sources = require('../compiled/webpack-sources');
import { StatSyncFn } from 'fs';
Expand Down Expand Up @@ -1808,7 +1808,7 @@ export { Dependency }
type DependencyLocation = any;

// @public (undocumented)
type DevMiddlewareContext<RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse> = {
type DevMiddlewareContext<RequestInternal extends IncomingMessage_2 = IncomingMessage_2, ResponseInternal extends ServerResponse_2 = ServerResponse_2> = {
state: boolean;
stats: Stats | MultiStats | undefined;
callbacks: Callback_2[];
Expand All @@ -1820,7 +1820,7 @@ type DevMiddlewareContext<RequestInternal extends IncomingMessage = IncomingMess
};

// @public (undocumented)
type DevMiddlewareOptions<RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse> = {
type DevMiddlewareOptions<RequestInternal extends IncomingMessage_2 = IncomingMessage_2, ResponseInternal extends ServerResponse_2 = ServerResponse_2> = {
mimeTypes?: {
[key: string]: string;
} | undefined;
Expand All @@ -1847,6 +1847,9 @@ type DevMiddlewareOptions<RequestInternal extends IncomingMessage = IncomingMess
export interface DevServer extends DevServerOptions {
}

// @public (undocumented)
export type DevServerMiddleware<RequestInternal extends Request_2 = Request_2, ResponseInternal extends Response_2 = Response_2> = MiddlewareObject<RequestInternal, ResponseInternal> | MiddlewareHandler<RequestInternal, ResponseInternal>;

// @public (undocumented)
type DevServerOptions<A extends BasicApplication = BasicApplication, S extends BasicServer = Server_3<IncomingMessage, ServerResponse>> = {
ipc?: string | boolean | undefined;
Expand All @@ -1870,7 +1873,7 @@ type DevServerOptions<A extends BasicApplication = BasicApplication, S extends B
client?: boolean | ClientConfiguration | undefined;
headers?: Headers_2 | ((req: Request_2, res: Response_2, context: DevMiddlewareContext<Request_2, Response_2> | undefined) => Headers_2) | undefined;
onListening?: ((devServer: Server_4) => void) | undefined;
setupMiddlewares?: ((middlewares: Middleware[], devServer: Server_4) => Middleware[]) | undefined;
setupMiddlewares?: ((middlewares: DevServerMiddleware[], devServer: Server_4) => DevServerMiddleware[]) | undefined;
};

// @public
Expand Down Expand Up @@ -3249,7 +3252,7 @@ interface ImportNamespaceSpecifier extends Node_4, HasSpan {
type ImportSpecifier = NamedImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier;

// @public (undocumented)
type IncomingMessage = IncomingMessage_2;
type IncomingMessage_2 = IncomingMessage;

// @public
export type Incremental = {
Expand Down Expand Up @@ -4133,7 +4136,7 @@ interface LabeledStatement extends Node_4, HasSpan {
export type Layer = string | null;

// @public (undocumented)
const lazyCompilationMiddleware: (compiler: Compiler, userOptions?: LazyCompilationOptions | boolean) => Middleware;
const lazyCompilationMiddleware: (compiler: Compiler, userOptions?: LazyCompilationOptions | boolean) => DevServerMiddleware;

// @public
export type LazyCompilationOptions = {
Expand Down Expand Up @@ -4626,16 +4629,13 @@ interface MethodProperty extends PropBase, Fn {
}

// @public (undocumented)
type Middleware = MiddlewareObject | MiddlewareHandler;

// @public (undocumented)
type MiddlewareHandler = any;
type MiddlewareHandler<RequestInternal extends Request_2 = Request_2, ResponseInternal extends Response_2 = Response_2> = (req: RequestInternal, res: ResponseInternal, next: NextFunction) => void | Promise<void>;

// @public (undocumented)
type MiddlewareObject = {
type MiddlewareObject<RequestInternal extends Request_2 = Request_2, ResponseInternal extends Response_2 = Response_2> = {
name?: string;
path?: string;
middleware: MiddlewareHandler;
middleware: MiddlewareHandler<RequestInternal, ResponseInternal>;
};

// @public (undocumented)
Expand All @@ -4648,7 +4648,7 @@ type MkdirSync = (path: PathLike, options: MakeDirectoryOptions) => undefined |
export type Mode = "development" | "production" | "none";

// @public (undocumented)
type ModifyResponseData<RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse> = (req: RequestInternal, res: ResponseInternal, data: Buffer | ReadStream, byteLength: number) => ResponseData;
type ModifyResponseData<RequestInternal extends IncomingMessage_2 = IncomingMessage_2, ResponseInternal extends ServerResponse_2 = ServerResponse_2> = (req: RequestInternal, res: ResponseInternal, data: Buffer | ReadStream, byteLength: number) => ResponseData;

export { Module }

Expand Down Expand Up @@ -6016,7 +6016,7 @@ const RemoveDuplicateModulesPlugin: {
};

// @public (undocumented)
type Request_2 = IncomingMessage;
type Request_2 = IncomingMessage_2;

// @public
export type Resolve = ResolveOptions;
Expand Down Expand Up @@ -6121,7 +6121,7 @@ export type ResourceDataWithData = ResourceData & {
};

// @public (undocumented)
type Response_2 = ServerResponse;
type Response_2 = ServerResponse_2;

// @public (undocumented)
type ResponseData = {
Expand Down Expand Up @@ -6587,6 +6587,7 @@ declare namespace rspackExports {
Watch,
WatchOptions,
DevServer,
DevServerMiddleware,
IgnoreWarnings,
Profile,
Amd,
Expand Down Expand Up @@ -7034,7 +7035,7 @@ type ServerOptions = ServerOptions_2 & {
};

// @public (undocumented)
type ServerResponse = ServerResponse_2;
type ServerResponse_2 = ServerResponse;

// @public (undocumented)
type ServerType<A extends BasicApplication = BasicApplication, S extends BasicServer = Server_3<IncomingMessage, ServerResponse>> = "http" | "https" | "spdy" | "http2" | string | ((arg0: ServerOptions, arg1: A) => S);
Expand Down
46 changes: 36 additions & 10 deletions packages/rspack/src/config/devServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
type MultiWatching = MultiCompiler["watch"];
type BasicServer = import("net").Server | import("tls").Server;

type ReadStream = typeof import("fs").ReadStream;
type IncomingMessage = typeof import("http").IncomingMessage;
type ServerResponse = typeof import("http").ServerResponse;
type ReadStream = import("fs").ReadStream;
type IncomingMessage = import("http").IncomingMessage;
type ServerResponse = import("http").ServerResponse;
type ServerOptions = import("https").ServerOptions & {
spdy?: {
plain?: boolean | undefined;
Expand Down Expand Up @@ -143,7 +143,10 @@ type Static = {

type ServerType<
A extends BasicApplication = BasicApplication,
S extends BasicServer = import("http").Server<IncomingMessage, ServerResponse>
S extends BasicServer = import("http").Server<
typeof import("http").IncomingMessage,
typeof import("http").ServerResponse
>
> =
| "http"
| "https"
Expand All @@ -154,7 +157,10 @@ type ServerType<

type ServerConfiguration<
A extends BasicApplication = BasicApplication,
S extends BasicServer = import("http").Server<IncomingMessage, ServerResponse>
S extends BasicServer = import("http").Server<
typeof import("http").IncomingMessage,
typeof import("http").ServerResponse
>
> = {
type?: ServerType<A, S> | undefined;
options?: ServerOptions | undefined;
Expand Down Expand Up @@ -202,13 +208,30 @@ type DevMiddlewareContext<
};
type Server = any;

type MiddlewareHandler = any;
type MiddlewareObject = {
type MiddlewareHandler<
RequestInternal extends Request = Request,
ResponseInternal extends Response = Response
> = (
req: RequestInternal,
res: ResponseInternal,
next: NextFunction
) => void | Promise<void>;

type MiddlewareObject<
RequestInternal extends Request = Request,
ResponseInternal extends Response = Response
> = {
name?: string;
path?: string;
middleware: MiddlewareHandler;
middleware: MiddlewareHandler<RequestInternal, ResponseInternal>;
};
export type Middleware = MiddlewareObject | MiddlewareHandler;
export type Middleware<
RequestInternal extends Request = Request,
ResponseInternal extends Response = Response
> =
| MiddlewareObject<RequestInternal, ResponseInternal>
| MiddlewareHandler<RequestInternal, ResponseInternal>;

type OpenApp = {
name?: string | undefined;
arguments?: string[] | undefined;
Expand Down Expand Up @@ -244,7 +267,10 @@ type ClientConfiguration = {

export type DevServerOptions<
A extends BasicApplication = BasicApplication,
S extends BasicServer = import("http").Server<IncomingMessage, ServerResponse>
S extends BasicServer = import("http").Server<
typeof import("http").IncomingMessage,
typeof import("http").ServerResponse
>
> = {
ipc?: string | boolean | undefined;
host?: string | undefined;
Expand Down
2 changes: 2 additions & 0 deletions packages/rspack/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2749,6 +2749,8 @@ export type WatchOptions = {
* Options for devServer, it based on `webpack-dev-server@5`
* */
export interface DevServer extends DevServerOptions {}

export type { Middleware as DevServerMiddleware } from "./devServer";
//#endregion

//#region IgnoreWarnings
Expand Down
Loading