Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add historyApiFallback option #930

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: run build cmd
drudrum authored and Aleksey Druzhinin committed Mar 9, 2023
commit e47ffe6aa1480579c90c7c4cb5ef9c74102b0264
242 changes: 132 additions & 110 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -116,128 +116,150 @@ export = wdm;
* @param {Options<RequestInternal, ResponseInternal>} [options]
* @returns {API<RequestInternal, ResponseInternal>}
*/
declare function wdm<RequestInternal extends import('http').IncomingMessage, ResponseInternal extends ServerResponse>(
compiler: Compiler | MultiCompiler,
options?: Options<RequestInternal, ResponseInternal> | undefined
declare function wdm<
RequestInternal extends import("http").IncomingMessage,
ResponseInternal extends ServerResponse
>(
compiler: Compiler | MultiCompiler,
options?: Options<RequestInternal, ResponseInternal> | undefined
): API<RequestInternal, ResponseInternal>;
declare namespace wdm {
export {
Schema,
Compiler,
MultiCompiler,
Configuration,
Stats,
MultiStats,
ExtendedServerResponse,
IncomingMessage,
ServerResponse,
NextFunction,
WatchOptions,
Watching,
MultiWatching,
OutputFileSystem,
Logger,
Callback,
Context,
Headers,
Options,
Middleware,
GetFilenameFromUrl,
WaitUntilValid,
Invalidate,
Close,
AdditionalMethods,
API,
};
export {
Schema,
Compiler,
MultiCompiler,
Configuration,
Stats,
MultiStats,
ExtendedServerResponse,
IncomingMessage,
ServerResponse,
NextFunction,
WatchOptions,
Watching,
MultiWatching,
OutputFileSystem,
Logger,
Callback,
Context,
Headers,
Options,
Middleware,
GetFilenameFromUrl,
WaitUntilValid,
Invalidate,
Close,
AdditionalMethods,
API,
};
}
type ServerResponse = import('http').ServerResponse & ExtendedServerResponse;
type Compiler = import('webpack').Compiler;
type MultiCompiler = import('webpack').MultiCompiler;
type Options<RequestInternal extends import('http').IncomingMessage, ResponseInternal extends ServerResponse> = {
mimeTypes?:
| {
[key: string]: string;
}
| undefined;
writeToDisk?: boolean | ((targetPath: string) => boolean) | undefined;
methods?: string | undefined;
headers?: Headers<RequestInternal, ResponseInternal>;
publicPath?: NonNullable<Configuration['output']>['publicPath'];
stats?: Configuration['stats'];
serverSideRender?: boolean | undefined;
outputFileSystem?: OutputFileSystem | undefined;
index?: string | boolean | undefined;
historyApiFallback?: boolean | undefined;
type ServerResponse = import("http").ServerResponse & ExtendedServerResponse;
type Compiler = import("webpack").Compiler;
type MultiCompiler = import("webpack").MultiCompiler;
type Options<
RequestInternal extends import("http").IncomingMessage,
ResponseInternal extends ServerResponse
> = {
mimeTypes?:
| {
[key: string]: string;
}
| undefined;
writeToDisk?: boolean | ((targetPath: string) => boolean) | undefined;
methods?: string | undefined;
headers?: Headers<RequestInternal, ResponseInternal>;
publicPath?: NonNullable<Configuration["output"]>["publicPath"];
stats?: Configuration["stats"];
serverSideRender?: boolean | undefined;
outputFileSystem?: OutputFileSystem | undefined;
index?: string | boolean | undefined;
historyApiFallback?: boolean | undefined;
};
type API<RequestInternal extends import('http').IncomingMessage, ResponseInternal extends ServerResponse> = Middleware<
RequestInternal,
ResponseInternal
> &
AdditionalMethods<RequestInternal, ResponseInternal>;
type Schema = import('schema-utils/declarations/validate').Schema;
type Configuration = import('webpack').Configuration;
type Stats = import('webpack').Stats;
type MultiStats = import('webpack').MultiStats;
type API<
RequestInternal extends import("http").IncomingMessage,
ResponseInternal extends ServerResponse
> = Middleware<RequestInternal, ResponseInternal> &
AdditionalMethods<RequestInternal, ResponseInternal>;
type Schema = import("schema-utils/declarations/validate").Schema;
type Configuration = import("webpack").Configuration;
type Stats = import("webpack").Stats;
type MultiStats = import("webpack").MultiStats;
type ExtendedServerResponse = {
locals?:
| {
webpack?:
| {
devMiddleware?: Context<import('http').IncomingMessage, ServerResponse> | undefined;
}
| undefined;
}
| undefined;
locals?:
| {
webpack?:
| {
devMiddleware?:
| Context<import("http").IncomingMessage, ServerResponse>
| undefined;
}
| undefined;
}
| undefined;
};
type IncomingMessage = import('http').IncomingMessage;
type IncomingMessage = import("http").IncomingMessage;
type NextFunction = (err?: any) => void;
type WatchOptions = NonNullable<Configuration['watchOptions']>;
type Watching = Compiler['watching'];
type MultiWatching = ReturnType<Compiler['watch']>;
type OutputFileSystem = Compiler['outputFileSystem'] & {
createReadStream?: typeof import('fs').createReadStream;
statSync?: import('fs').StatSyncFn;
lstat?: typeof import('fs').lstat;
existsSync?: typeof import('fs').existsSync;
readFileSync?: typeof import('fs').readFileSync;
type WatchOptions = NonNullable<Configuration["watchOptions"]>;
type Watching = Compiler["watching"];
type MultiWatching = ReturnType<Compiler["watch"]>;
type OutputFileSystem = Compiler["outputFileSystem"] & {
createReadStream?: typeof import("fs").createReadStream;
statSync?: import("fs").StatSyncFn;
lstat?: typeof import("fs").lstat;
existsSync?: typeof import("fs").existsSync;
readFileSync?: typeof import("fs").readFileSync;
};
type Logger = ReturnType<Compiler['getInfrastructureLogger']>;
type Callback = (stats?: import('webpack').Stats | import('webpack').MultiStats | undefined) => any;
type Context<RequestInternal extends import('http').IncomingMessage, ResponseInternal extends ServerResponse> = {
state: boolean;
stats: Stats | MultiStats | undefined;
callbacks: Callback[];
options: Options<RequestInternal, ResponseInternal>;
compiler: Compiler | MultiCompiler;
watching: Watching | MultiWatching;
logger: Logger;
outputFileSystem: OutputFileSystem;
type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
type Callback = (
stats?: import("webpack").Stats | import("webpack").MultiStats | undefined
) => any;
type Context<
RequestInternal extends import("http").IncomingMessage,
ResponseInternal extends ServerResponse
> = {
state: boolean;
stats: Stats | MultiStats | undefined;
callbacks: Callback[];
options: Options<RequestInternal, ResponseInternal>;
compiler: Compiler | MultiCompiler;
watching: Watching | MultiWatching;
logger: Logger;
outputFileSystem: OutputFileSystem;
};
type Headers<RequestInternal extends import('http').IncomingMessage, ResponseInternal extends ServerResponse> =
| Record<string, string | number>
| {
key: string;
value: number | string;
}[]
| ((
req: RequestInternal,
res: ResponseInternal,
context: Context<RequestInternal, ResponseInternal>
) => void | undefined | Record<string, string | number>)
| undefined;
type Middleware<RequestInternal extends import('http').IncomingMessage, ResponseInternal extends ServerResponse> = (
req: RequestInternal,
res: ResponseInternal,
next: NextFunction
type Headers<
RequestInternal extends import("http").IncomingMessage,
ResponseInternal extends ServerResponse
> =
| Record<string, string | number>
| {
key: string;
value: number | string;
}[]
| ((
req: RequestInternal,
res: ResponseInternal,
context: Context<RequestInternal, ResponseInternal>
) => void | undefined | Record<string, string | number>)
| undefined;
type Middleware<
RequestInternal extends import("http").IncomingMessage,
ResponseInternal extends ServerResponse
> = (
req: RequestInternal,
res: ResponseInternal,
next: NextFunction
) => Promise<void>;
type GetFilenameFromUrl = (url: string) => string | undefined;
type WaitUntilValid = (callback: Callback) => any;
type Invalidate = (callback: Callback) => any;
type Close = (callback: (err: Error | null | undefined) => void) => any;
type AdditionalMethods<RequestInternal extends import('http').IncomingMessage, ResponseInternal extends ServerResponse> = {
getFilenameFromUrl: GetFilenameFromUrl;
waitUntilValid: WaitUntilValid;
invalidate: Invalidate;
close: Close;
context: Context<RequestInternal, ResponseInternal>;
type AdditionalMethods<
RequestInternal extends import("http").IncomingMessage,
ResponseInternal extends ServerResponse
> = {
getFilenameFromUrl: GetFilenameFromUrl;
waitUntilValid: WaitUntilValid;
invalidate: Invalidate;
close: Close;
context: Context<RequestInternal, ResponseInternal>;
};
17 changes: 10 additions & 7 deletions types/middleware.d.ts
Original file line number Diff line number Diff line change
@@ -6,12 +6,15 @@ export = wrapper;
* @param {import("./index.js").Context<Request, Response>} context
* @return {import("./index.js").Middleware<Request, Response>}
*/
declare function wrapper<Request_1 extends import('http').IncomingMessage, Response_1 extends import('./index.js').ServerResponse>(
context: import('./index.js').Context<Request_1, Response_1>
): import('./index.js').Middleware<Request_1, Response_1>;
declare function wrapper<
Request_1 extends import("http").IncomingMessage,
Response_1 extends import("./index.js").ServerResponse
>(
context: import("./index.js").Context<Request_1, Response_1>
): import("./index.js").Middleware<Request_1, Response_1>;
declare namespace wrapper {
export { NextFunction, IncomingMessage, ServerResponse };
export { NextFunction, IncomingMessage, ServerResponse };
}
type NextFunction = import('./index.js').NextFunction;
type IncomingMessage = import('./index.js').IncomingMessage;
type ServerResponse = import('./index.js').ServerResponse;
type NextFunction = import("./index.js").NextFunction;
type IncomingMessage = import("./index.js").IncomingMessage;
type ServerResponse = import("./index.js").ServerResponse;
54 changes: 30 additions & 24 deletions types/utils/compatibleAPI.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/// <reference types="node" />
export type IncomingMessage = import('../index.js').IncomingMessage;
export type ServerResponse = import('../index.js').ServerResponse;
export type IncomingMessage = import("../index.js").IncomingMessage;
export type ServerResponse = import("../index.js").ServerResponse;
export type ExpectedRequest = {
get: (name: string) => string | undefined;
get: (name: string) => string | undefined;
};
export type ExpectedResponse = {
get: (name: string) => string | string[] | undefined;
set: (name: string, value: number | string | string[]) => void;
status: (status: number) => void;
send: (data: any) => void;
get: (name: string) => string | string[] | undefined;
set: (name: string, value: number | string | string[]) => void;
status: (status: number) => void;
send: (data: any) => void;
};
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
@@ -28,42 +28,45 @@ export type ExpectedResponse = {
* @param {Response} res
* @returns {string[]}
*/
export function getHeaderNames<Response_1 extends import('../index.js').ServerResponse>(res: Response_1): string[];
export function getHeaderNames<
Response_1 extends import("../index.js").ServerResponse
>(res: Response_1): string[];
/**
* @template {IncomingMessage} Request
* @param {Request} req
* @param {string} name
* @returns {string | undefined}
*/
export function getHeaderFromRequest<Request_1 extends import('http').IncomingMessage>(req: Request_1, name: string): string | undefined;
export function getHeaderFromRequest<
Request_1 extends import("http").IncomingMessage
>(req: Request_1, name: string): string | undefined;
/**
* @template {ServerResponse} Response
* @param {Response} res
* @param {string} name
* @returns {number | string | string[] | undefined}
*/
export function getHeaderFromResponse<Response_1 extends import('../index.js').ServerResponse>(
res: Response_1,
name: string
): number | string | string[] | undefined;
export function getHeaderFromResponse<
Response_1 extends import("../index.js").ServerResponse
>(res: Response_1, name: string): number | string | string[] | undefined;
/**
* @template {ServerResponse} Response
* @param {Response} res
* @param {string} name
* @param {number | string | string[]} value
* @returns {void}
*/
export function setHeaderForResponse<Response_1 extends import('../index.js').ServerResponse>(
res: Response_1,
name: string,
value: number | string | string[]
): void;
export function setHeaderForResponse<
Response_1 extends import("../index.js").ServerResponse
>(res: Response_1, name: string, value: number | string | string[]): void;
/**
* @template {ServerResponse} Response
* @param {Response} res
* @param {number} code
*/
export function setStatusCode<Response_1 extends import('../index.js').ServerResponse>(res: Response_1, code: number): void;
export function setStatusCode<
Response_1 extends import("../index.js").ServerResponse
>(res: Response_1, code: number): void;
/**
* @template {IncomingMessage} Request
* @template {ServerResponse} Response
@@ -72,9 +75,12 @@ export function setStatusCode<Response_1 extends import('../index.js').ServerRes
* @param {string | Buffer | import("fs").ReadStream} bufferOtStream
* @param {number} byteLength
*/
export function send<Request_1 extends import('http').IncomingMessage, Response_1 extends import('../index.js').ServerResponse>(
req: Request_1,
res: Response_1,
bufferOtStream: string | Buffer | import('fs').ReadStream,
byteLength: number
export function send<
Request_1 extends import("http").IncomingMessage,
Response_1 extends import("../index.js").ServerResponse
>(
req: Request_1,
res: Response_1,
bufferOtStream: string | Buffer | import("fs").ReadStream,
byteLength: number
): void;
Loading