UNPKG

8.19 kBTypeScriptView Raw
1/// <reference types="node" />
2export = wdm;
3/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
4/** @typedef {import("webpack").Compiler} Compiler */
5/** @typedef {import("webpack").MultiCompiler} MultiCompiler */
6/** @typedef {import("webpack").Configuration} Configuration */
7/** @typedef {import("webpack").Stats} Stats */
8/** @typedef {import("webpack").MultiStats} MultiStats */
9/**
10 * @typedef {Object} ExtendedServerResponse
11 * @property {{ webpack?: { devMiddleware?: Context<IncomingMessage, ServerResponse> } }} [locals]
12 */
13/** @typedef {import("http").IncomingMessage} IncomingMessage */
14/** @typedef {import("http").ServerResponse & ExtendedServerResponse} ServerResponse */
15/**
16 * @callback NextFunction
17 * @param {any} [err]
18 * @return {void}
19 */
20/**
21 * @typedef {NonNullable<Configuration["watchOptions"]>} WatchOptions
22 */
23/**
24 * @typedef {Compiler["watching"]} Watching
25 */
26/**
27 * @typedef {ReturnType<Compiler["watch"]>} MultiWatching
28 */
29/**
30 * @typedef {Compiler["outputFileSystem"] & { createReadStream?: import("fs").createReadStream, statSync?: import("fs").statSync, lstat?: import("fs").lstat, readFileSync?: import("fs").readFileSync }} OutputFileSystem
31 */
32/** @typedef {ReturnType<Compiler["getInfrastructureLogger"]>} Logger */
33/**
34 * @callback Callback
35 * @param {Stats | MultiStats} [stats]
36 */
37/**
38 * @template {IncomingMessage} Request
39 * @template {ServerResponse} Response
40 * @typedef {Object} Context
41 * @property {boolean} state
42 * @property {Stats | MultiStats | undefined} stats
43 * @property {Callback[]} callbacks
44 * @property {Options<Request, Response>} options
45 * @property {Compiler | MultiCompiler} compiler
46 * @property {Watching | MultiWatching} watching
47 * @property {Logger} logger
48 * @property {OutputFileSystem} outputFileSystem
49 */
50/**
51 * @template {IncomingMessage} Request
52 * @template {ServerResponse} Response
53 * @typedef {Record<string, string | number> | Array<{ key: string, value: number | string }> | ((req: Request, res: Response, context: Context<Request, Response>) => void | undefined | Record<string, string | number>) | undefined} Headers
54 */
55/**
56 * @template {IncomingMessage} Request
57 * @template {ServerResponse} Response
58 * @typedef {Object} Options
59 * @property {{[key: string]: string}} [mimeTypes]
60 * @property {boolean | ((targetPath: string) => boolean)} [writeToDisk]
61 * @property {string} [methods]
62 * @property {Headers<Request, Response>} [headers]
63 * @property {NonNullable<Configuration["output"]>["publicPath"]} [publicPath]
64 * @property {Configuration["stats"]} [stats]
65 * @property {boolean} [serverSideRender]
66 * @property {OutputFileSystem} [outputFileSystem]
67 * @property {boolean | string} [index]
68 */
69/**
70 * @template {IncomingMessage} Request
71 * @template {ServerResponse} Response
72 * @callback Middleware
73 * @param {Request} req
74 * @param {Response} res
75 * @param {NextFunction} next
76 * @return {Promise<void>}
77 */
78/**
79 * @callback GetFilenameFromUrl
80 * @param {string} url
81 * @returns {string | undefined}
82 */
83/**
84 * @callback WaitUntilValid
85 * @param {Callback} callback
86 */
87/**
88 * @callback Invalidate
89 * @param {Callback} callback
90 */
91/**
92 * @callback Close
93 * @param {(err: Error | null | undefined) => void} callback
94 */
95/**
96 * @template {IncomingMessage} Request
97 * @template {ServerResponse} Response
98 * @typedef {Object} AdditionalMethods
99 * @property {GetFilenameFromUrl} getFilenameFromUrl
100 * @property {WaitUntilValid} waitUntilValid
101 * @property {Invalidate} invalidate
102 * @property {Close} close
103 * @property {Context<Request, Response>} context
104 */
105/**
106 * @template {IncomingMessage} Request
107 * @template {ServerResponse} Response
108 * @typedef {Middleware<Request, Response> & AdditionalMethods<Request, Response>} API
109 */
110/**
111 * @template {IncomingMessage} Request
112 * @template {ServerResponse} Response
113 * @param {Compiler | MultiCompiler} compiler
114 * @param {Options<Request, Response>} [options]
115 * @returns {API<Request, Response>}
116 */
117declare function wdm<
118 Request_1 extends import("http").IncomingMessage,
119 Response_1 extends ServerResponse
120>(
121 compiler: Compiler | MultiCompiler,
122 options?: Options<Request_1, Response_1> | undefined
123): API<Request_1, Response_1>;
124declare namespace wdm {
125 export {
126 Schema,
127 Compiler,
128 MultiCompiler,
129 Configuration,
130 Stats,
131 MultiStats,
132 ExtendedServerResponse,
133 IncomingMessage,
134 ServerResponse,
135 NextFunction,
136 WatchOptions,
137 Watching,
138 MultiWatching,
139 OutputFileSystem,
140 Logger,
141 Callback,
142 Context,
143 Headers,
144 Options,
145 Middleware,
146 GetFilenameFromUrl,
147 WaitUntilValid,
148 Invalidate,
149 Close,
150 AdditionalMethods,
151 API,
152 };
153}
154type ServerResponse = import("http").ServerResponse & ExtendedServerResponse;
155type Compiler = import("webpack").Compiler;
156type MultiCompiler = import("webpack").MultiCompiler;
157type Options<
158 Request_1 extends import("http").IncomingMessage,
159 Response_1 extends ServerResponse
160> = {
161 mimeTypes?:
162 | {
163 [key: string]: string;
164 }
165 | undefined;
166 writeToDisk?: boolean | ((targetPath: string) => boolean) | undefined;
167 methods?: string | undefined;
168 headers?: Headers<Request, Response>;
169 publicPath?: NonNullable<Configuration["output"]>["publicPath"];
170 stats?: Configuration["stats"];
171 serverSideRender?: boolean | undefined;
172 outputFileSystem?: OutputFileSystem | undefined;
173 index?: string | boolean | undefined;
174};
175type API<
176 Request_1 extends import("http").IncomingMessage,
177 Response_1 extends ServerResponse
178> = Middleware<Request, Response> & AdditionalMethods<Request, Response>;
179type Schema = import("schema-utils/declarations/validate").Schema;
180type Configuration = import("webpack").Configuration;
181type Stats = import("webpack").Stats;
182type MultiStats = import("webpack").MultiStats;
183type ExtendedServerResponse = {
184 locals?:
185 | {
186 webpack?:
187 | {
188 devMiddleware?:
189 | Context<import("http").IncomingMessage, ServerResponse>
190 | undefined;
191 }
192 | undefined;
193 }
194 | undefined;
195};
196type IncomingMessage = import("http").IncomingMessage;
197type NextFunction = (err?: any) => void;
198type WatchOptions = NonNullable<Configuration["watchOptions"]>;
199type Watching = Compiler["watching"];
200type MultiWatching = ReturnType<Compiler["watch"]>;
201type OutputFileSystem = Compiler["outputFileSystem"] & {
202 createReadStream?: typeof import("fs").createReadStream;
203 statSync?: typeof import("fs").statSync;
204 lstat?: typeof import("fs").lstat;
205 readFileSync?: typeof import("fs").readFileSync;
206};
207type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
208type Callback = (
209 stats?: import("webpack").Stats | import("webpack").MultiStats | undefined
210) => any;
211type Context<
212 Request_1 extends import("http").IncomingMessage,
213 Response_1 extends ServerResponse
214> = {
215 state: boolean;
216 stats: Stats | MultiStats | undefined;
217 callbacks: Callback[];
218 options: Options<Request, Response>;
219 compiler: Compiler | MultiCompiler;
220 watching: Watching | MultiWatching;
221 logger: Logger;
222 outputFileSystem: OutputFileSystem;
223};
224type Headers<
225 Request_1 extends import("http").IncomingMessage,
226 Response_1 extends ServerResponse
227> =
228 | Record<string, string | number>
229 | {
230 key: string;
231 value: number | string;
232 }[]
233 | ((
234 req: Request,
235 res: Response,
236 context: Context<Request, Response>
237 ) => void | undefined | Record<string, string | number>)
238 | undefined;
239type Middleware<
240 Request_1 extends import("http").IncomingMessage,
241 Response_1 extends ServerResponse
242> = (req: Request, res: Response, next: NextFunction) => Promise<void>;
243type GetFilenameFromUrl = (url: string) => string | undefined;
244type WaitUntilValid = (callback: Callback) => any;
245type Invalidate = (callback: Callback) => any;
246type Close = (callback: (err: Error | null | undefined) => void) => any;
247type AdditionalMethods<
248 Request_1 extends import("http").IncomingMessage,
249 Response_1 extends ServerResponse
250> = {
251 getFilenameFromUrl: GetFilenameFromUrl;
252 waitUntilValid: WaitUntilValid;
253 invalidate: Invalidate;
254 close: Close;
255 context: Context<Request, Response>;
256};