1 | /// <reference types="node" />
|
2 | export = 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 | */
|
117 | declare 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>;
|
124 | declare 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 | }
|
154 | type ServerResponse = import("http").ServerResponse & ExtendedServerResponse;
|
155 | type Compiler = import("webpack").Compiler;
|
156 | type MultiCompiler = import("webpack").MultiCompiler;
|
157 | type 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_1, Response_1>;
|
169 | publicPath?: NonNullable<Configuration["output"]>["publicPath"];
|
170 | stats?: Configuration["stats"];
|
171 | serverSideRender?: boolean | undefined;
|
172 | outputFileSystem?: OutputFileSystem | undefined;
|
173 | index?: string | boolean | undefined;
|
174 | };
|
175 | type API<
|
176 | Request_1 extends import("http").IncomingMessage,
|
177 | Response_1 extends ServerResponse
|
178 | > = Middleware<Request_1, Response_1> &
|
179 | AdditionalMethods<Request_1, Response_1>;
|
180 | type Schema = import("schema-utils/declarations/validate").Schema;
|
181 | type Configuration = import("webpack").Configuration;
|
182 | type Stats = import("webpack").Stats;
|
183 | type MultiStats = import("webpack").MultiStats;
|
184 | type ExtendedServerResponse = {
|
185 | locals?:
|
186 | | {
|
187 | webpack?:
|
188 | | {
|
189 | devMiddleware?:
|
190 | | Context<import("http").IncomingMessage, ServerResponse>
|
191 | | undefined;
|
192 | }
|
193 | | undefined;
|
194 | }
|
195 | | undefined;
|
196 | };
|
197 | type IncomingMessage = import("http").IncomingMessage;
|
198 | type NextFunction = (err?: any) => void;
|
199 | type WatchOptions = NonNullable<Configuration["watchOptions"]>;
|
200 | type Watching = Compiler["watching"];
|
201 | type MultiWatching = ReturnType<Compiler["watch"]>;
|
202 | type OutputFileSystem = Compiler["outputFileSystem"] & {
|
203 | createReadStream?: typeof import("fs").createReadStream;
|
204 | statSync?: typeof import("fs").statSync;
|
205 | lstat?: typeof import("fs").lstat;
|
206 | readFileSync?: typeof import("fs").readFileSync;
|
207 | };
|
208 | type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
|
209 | type Callback = (
|
210 | stats?: import("webpack").Stats | import("webpack").MultiStats | undefined
|
211 | ) => any;
|
212 | type Context<
|
213 | Request_1 extends import("http").IncomingMessage,
|
214 | Response_1 extends ServerResponse
|
215 | > = {
|
216 | state: boolean;
|
217 | stats: Stats | MultiStats | undefined;
|
218 | callbacks: Callback[];
|
219 | options: Options<Request_1, Response_1>;
|
220 | compiler: Compiler | MultiCompiler;
|
221 | watching: Watching | MultiWatching;
|
222 | logger: Logger;
|
223 | outputFileSystem: OutputFileSystem;
|
224 | };
|
225 | type Headers<
|
226 | Request_1 extends import("http").IncomingMessage,
|
227 | Response_1 extends ServerResponse
|
228 | > =
|
229 | | Record<string, string | number>
|
230 | | {
|
231 | key: string;
|
232 | value: number | string;
|
233 | }[]
|
234 | | ((
|
235 | req: Request_1,
|
236 | res: Response_1,
|
237 | context: Context<Request_1, Response_1>
|
238 | ) => void | undefined | Record<string, string | number>)
|
239 | | undefined;
|
240 | type Middleware<
|
241 | Request_1 extends import("http").IncomingMessage,
|
242 | Response_1 extends ServerResponse
|
243 | > = (req: Request_1, res: Response_1, next: NextFunction) => Promise<void>;
|
244 | type GetFilenameFromUrl = (url: string) => string | undefined;
|
245 | type WaitUntilValid = (callback: Callback) => any;
|
246 | type Invalidate = (callback: Callback) => any;
|
247 | type Close = (callback: (err: Error | null | undefined) => void) => any;
|
248 | type AdditionalMethods<
|
249 | Request_1 extends import("http").IncomingMessage,
|
250 | Response_1 extends ServerResponse
|
251 | > = {
|
252 | getFilenameFromUrl: GetFilenameFromUrl;
|
253 | waitUntilValid: WaitUntilValid;
|
254 | invalidate: Invalidate;
|
255 | close: Close;
|
256 | context: Context<Request_1, Response_1>;
|
257 | };
|