1 | export = wdm;
|
2 | /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
|
3 | /** @typedef {import("webpack").Compiler} Compiler */
|
4 | /** @typedef {import("webpack").MultiCompiler} MultiCompiler */
|
5 | /** @typedef {import("webpack").Configuration} Configuration */
|
6 | /** @typedef {import("webpack").Stats} Stats */
|
7 | /** @typedef {import("webpack").MultiStats} MultiStats */
|
8 | /** @typedef {import("fs").ReadStream} ReadStream */
|
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<MultiCompiler["watch"]>} MultiWatching
|
28 | */
|
29 | /**
|
30 | * @typedef {import("webpack").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem
|
31 | */
|
32 | /** @typedef {ReturnType<Compiler["getInfrastructureLogger"]>} Logger */
|
33 | /**
|
34 | * @callback Callback
|
35 | * @param {Stats | MultiStats} [stats]
|
36 | */
|
37 | /**
|
38 | * @typedef {Object} ResponseData
|
39 | * @property {Buffer | ReadStream} data
|
40 | * @property {number} byteLength
|
41 | */
|
42 | /**
|
43 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
44 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
45 | * @callback ModifyResponseData
|
46 | * @param {RequestInternal} req
|
47 | * @param {ResponseInternal} res
|
48 | * @param {Buffer | ReadStream} data
|
49 | * @param {number} byteLength
|
50 | * @return {ResponseData}
|
51 | */
|
52 | /**
|
53 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
54 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
55 | * @typedef {Object} Context
|
56 | * @property {boolean} state
|
57 | * @property {Stats | MultiStats | undefined} stats
|
58 | * @property {Callback[]} callbacks
|
59 | * @property {Options<RequestInternal, ResponseInternal>} options
|
60 | * @property {Compiler | MultiCompiler} compiler
|
61 | * @property {Watching | MultiWatching | undefined} watching
|
62 | * @property {Logger} logger
|
63 | * @property {OutputFileSystem} outputFileSystem
|
64 | */
|
65 | /**
|
66 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
67 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
68 | * @typedef {WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">} FilledContext
|
69 | */
|
70 | /** @typedef {Record<string, string | number> | Array<{ key: string, value: number | string }>} NormalizedHeaders */
|
71 | /**
|
72 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
73 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
74 | * @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context<RequestInternal, ResponseInternal>) => void | undefined | NormalizedHeaders) | undefined} Headers
|
75 | */
|
76 | /**
|
77 | * @template {IncomingMessage} [RequestInternal = IncomingMessage]
|
78 | * @template {ServerResponse} [ResponseInternal = ServerResponse]
|
79 | * @typedef {Object} Options
|
80 | * @property {{[key: string]: string}} [mimeTypes]
|
81 | * @property {string | undefined} [mimeTypeDefault]
|
82 | * @property {boolean | ((targetPath: string) => boolean)} [writeToDisk]
|
83 | * @property {string[]} [methods]
|
84 | * @property {Headers<RequestInternal, ResponseInternal>} [headers]
|
85 | * @property {NonNullable<Configuration["output"]>["publicPath"]} [publicPath]
|
86 | * @property {Configuration["stats"]} [stats]
|
87 | * @property {boolean} [serverSideRender]
|
88 | * @property {OutputFileSystem} [outputFileSystem]
|
89 | * @property {boolean | string} [index]
|
90 | * @property {ModifyResponseData<RequestInternal, ResponseInternal>} [modifyResponseData]
|
91 | * @property {"weak" | "strong"} [etag]
|
92 | * @property {boolean} [lastModified]
|
93 | * @property {boolean | number | string | { maxAge?: number, immutable?: boolean }} [cacheControl]
|
94 | * @property {boolean} [cacheImmutable]
|
95 | */
|
96 | /**
|
97 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
98 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
99 | * @callback Middleware
|
100 | * @param {RequestInternal} req
|
101 | * @param {ResponseInternal} res
|
102 | * @param {NextFunction} next
|
103 | * @return {Promise<void>}
|
104 | */
|
105 | /** @typedef {import("./utils/getFilenameFromUrl").Extra} Extra */
|
106 | /**
|
107 | * @callback GetFilenameFromUrl
|
108 | * @param {string} url
|
109 | * @param {Extra=} extra
|
110 | * @returns {string | undefined}
|
111 | */
|
112 | /**
|
113 | * @callback WaitUntilValid
|
114 | * @param {Callback} callback
|
115 | */
|
116 | /**
|
117 | * @callback Invalidate
|
118 | * @param {Callback} callback
|
119 | */
|
120 | /**
|
121 | * @callback Close
|
122 | * @param {(err: Error | null | undefined) => void} callback
|
123 | */
|
124 | /**
|
125 | * @template {IncomingMessage} RequestInternal
|
126 | * @template {ServerResponse} ResponseInternal
|
127 | * @typedef {Object} AdditionalMethods
|
128 | * @property {GetFilenameFromUrl} getFilenameFromUrl
|
129 | * @property {WaitUntilValid} waitUntilValid
|
130 | * @property {Invalidate} invalidate
|
131 | * @property {Close} close
|
132 | * @property {Context<RequestInternal, ResponseInternal>} context
|
133 | */
|
134 | /**
|
135 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
136 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
137 | * @typedef {Middleware<RequestInternal, ResponseInternal> & AdditionalMethods<RequestInternal, ResponseInternal>} API
|
138 | */
|
139 | /**
|
140 | * @template T
|
141 | * @template {keyof T} K
|
142 | * @typedef {Omit<T, K> & Partial<T>} WithOptional
|
143 | */
|
144 | /**
|
145 | * @template T
|
146 | * @template {keyof T} K
|
147 | * @typedef {T & { [P in K]: NonNullable<T[P]> }} WithoutUndefined
|
148 | */
|
149 | /**
|
150 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
151 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
152 | * @param {Compiler | MultiCompiler} compiler
|
153 | * @param {Options<RequestInternal, ResponseInternal>} [options]
|
154 | * @returns {API<RequestInternal, ResponseInternal>}
|
155 | */
|
156 | declare function wdm<
|
157 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
158 | ResponseInternal extends ServerResponse = ServerResponse,
|
159 | >(
|
160 | compiler: Compiler | MultiCompiler,
|
161 | options?: Options<RequestInternal, ResponseInternal> | undefined,
|
162 | ): API<RequestInternal, ResponseInternal>;
|
163 | declare namespace wdm {
|
164 | export {
|
165 | hapiWrapper,
|
166 | koaWrapper,
|
167 | honoWrapper,
|
168 | Schema,
|
169 | Compiler,
|
170 | MultiCompiler,
|
171 | Configuration,
|
172 | Stats,
|
173 | MultiStats,
|
174 | ReadStream,
|
175 | ExtendedServerResponse,
|
176 | IncomingMessage,
|
177 | ServerResponse,
|
178 | NextFunction,
|
179 | WatchOptions,
|
180 | Watching,
|
181 | MultiWatching,
|
182 | OutputFileSystem,
|
183 | Logger,
|
184 | Callback,
|
185 | ResponseData,
|
186 | ModifyResponseData,
|
187 | Context,
|
188 | FilledContext,
|
189 | NormalizedHeaders,
|
190 | Headers,
|
191 | Options,
|
192 | Middleware,
|
193 | Extra,
|
194 | GetFilenameFromUrl,
|
195 | WaitUntilValid,
|
196 | Invalidate,
|
197 | Close,
|
198 | AdditionalMethods,
|
199 | API,
|
200 | WithOptional,
|
201 | WithoutUndefined,
|
202 | HapiPluginBase,
|
203 | HapiPlugin,
|
204 | HapiOptions,
|
205 | };
|
206 | }
|
207 | /**
|
208 | * @template S
|
209 | * @template O
|
210 | * @typedef {Object} HapiPluginBase
|
211 | * @property {(server: S, options: O) => void | Promise<void>} register
|
212 | */
|
213 | /**
|
214 | * @template S
|
215 | * @template O
|
216 | * @typedef {HapiPluginBase<S, O> & { pkg: { name: string }, multiple: boolean }} HapiPlugin
|
217 | */
|
218 | /**
|
219 | * @typedef {Options & { compiler: Compiler | MultiCompiler }} HapiOptions
|
220 | */
|
221 | /**
|
222 | * @template HapiServer
|
223 | * @template {HapiOptions} HapiOptionsInternal
|
224 | * @returns {HapiPlugin<HapiServer, HapiOptionsInternal>}
|
225 | */
|
226 | declare function hapiWrapper<
|
227 | HapiServer,
|
228 | HapiOptionsInternal extends HapiOptions,
|
229 | >(): HapiPlugin<HapiServer, HapiOptionsInternal>;
|
230 | /**
|
231 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
232 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
233 | * @param {Compiler | MultiCompiler} compiler
|
234 | * @param {Options<RequestInternal, ResponseInternal>} [options]
|
235 | * @returns {(ctx: any, next: Function) => Promise<void> | void}
|
236 | */
|
237 | declare function koaWrapper<
|
238 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
239 | ResponseInternal extends ServerResponse = ServerResponse,
|
240 | >(
|
241 | compiler: Compiler | MultiCompiler,
|
242 | options?: Options<RequestInternal, ResponseInternal> | undefined,
|
243 | ): (ctx: any, next: Function) => Promise<void> | void;
|
244 | /**
|
245 | * @template {IncomingMessage} [RequestInternal=IncomingMessage]
|
246 | * @template {ServerResponse} [ResponseInternal=ServerResponse]
|
247 | * @param {Compiler | MultiCompiler} compiler
|
248 | * @param {Options<RequestInternal, ResponseInternal>} [options]
|
249 | * @returns {(ctx: any, next: Function) => Promise<void> | void}
|
250 | */
|
251 | declare function honoWrapper<
|
252 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
253 | ResponseInternal extends ServerResponse = ServerResponse,
|
254 | >(
|
255 | compiler: Compiler | MultiCompiler,
|
256 | options?: Options<RequestInternal, ResponseInternal> | undefined,
|
257 | ): (ctx: any, next: Function) => Promise<void> | void;
|
258 | type Schema = import("schema-utils/declarations/validate").Schema;
|
259 | type Compiler = import("webpack").Compiler;
|
260 | type MultiCompiler = import("webpack").MultiCompiler;
|
261 | type Configuration = import("webpack").Configuration;
|
262 | type Stats = import("webpack").Stats;
|
263 | type MultiStats = import("webpack").MultiStats;
|
264 | type ReadStream = import("fs").ReadStream;
|
265 | type ExtendedServerResponse = {
|
266 | locals?:
|
267 | | {
|
268 | webpack?: {
|
269 | devMiddleware?: Context<IncomingMessage, ServerResponse>;
|
270 | };
|
271 | }
|
272 | | undefined;
|
273 | };
|
274 | type IncomingMessage = import("http").IncomingMessage;
|
275 | type ServerResponse = import("http").ServerResponse & ExtendedServerResponse;
|
276 | type NextFunction = (err?: any) => void;
|
277 | type WatchOptions = NonNullable<Configuration["watchOptions"]>;
|
278 | type Watching = Compiler["watching"];
|
279 | type MultiWatching = ReturnType<MultiCompiler["watch"]>;
|
280 | type OutputFileSystem = import("webpack").OutputFileSystem & {
|
281 | createReadStream?: typeof import("fs").createReadStream;
|
282 | statSync: import("fs").StatSyncFn;
|
283 | readFileSync: typeof import("fs").readFileSync;
|
284 | };
|
285 | type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
|
286 | type Callback = (
|
287 | stats?: import("webpack").Stats | import("webpack").MultiStats | undefined,
|
288 | ) => any;
|
289 | type ResponseData = {
|
290 | data: Buffer | ReadStream;
|
291 | byteLength: number;
|
292 | };
|
293 | type ModifyResponseData<
|
294 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
295 | ResponseInternal extends ServerResponse = ServerResponse,
|
296 | > = (
|
297 | req: RequestInternal,
|
298 | res: ResponseInternal,
|
299 | data: Buffer | ReadStream,
|
300 | byteLength: number,
|
301 | ) => ResponseData;
|
302 | type Context<
|
303 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
304 | ResponseInternal extends ServerResponse = ServerResponse,
|
305 | > = {
|
306 | state: boolean;
|
307 | stats: Stats | MultiStats | undefined;
|
308 | callbacks: Callback[];
|
309 | options: Options<RequestInternal, ResponseInternal>;
|
310 | compiler: Compiler | MultiCompiler;
|
311 | watching: Watching | MultiWatching | undefined;
|
312 | logger: Logger;
|
313 | outputFileSystem: OutputFileSystem;
|
314 | };
|
315 | type FilledContext<
|
316 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
317 | ResponseInternal extends ServerResponse = ServerResponse,
|
318 | > = WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">;
|
319 | type NormalizedHeaders =
|
320 | | Record<string, string | number>
|
321 | | Array<{
|
322 | key: string;
|
323 | value: number | string;
|
324 | }>;
|
325 | type Headers<
|
326 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
327 | ResponseInternal extends ServerResponse = ServerResponse,
|
328 | > =
|
329 | | NormalizedHeaders
|
330 | | ((
|
331 | req: RequestInternal,
|
332 | res: ResponseInternal,
|
333 | context: Context<RequestInternal, ResponseInternal>,
|
334 | ) => void | undefined | NormalizedHeaders)
|
335 | | undefined;
|
336 | type Options<
|
337 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
338 | ResponseInternal extends ServerResponse = ServerResponse,
|
339 | > = {
|
340 | mimeTypes?:
|
341 | | {
|
342 | [key: string]: string;
|
343 | }
|
344 | | undefined;
|
345 | mimeTypeDefault?: string | undefined;
|
346 | writeToDisk?: boolean | ((targetPath: string) => boolean) | undefined;
|
347 | methods?: string[] | undefined;
|
348 | headers?: Headers<RequestInternal, ResponseInternal>;
|
349 | publicPath?: NonNullable<Configuration["output"]>["publicPath"];
|
350 | stats?: Configuration["stats"];
|
351 | serverSideRender?: boolean | undefined;
|
352 | outputFileSystem?: OutputFileSystem | undefined;
|
353 | index?: string | boolean | undefined;
|
354 | modifyResponseData?:
|
355 | | ModifyResponseData<RequestInternal, ResponseInternal>
|
356 | | undefined;
|
357 | etag?: "strong" | "weak" | undefined;
|
358 | lastModified?: boolean | undefined;
|
359 | cacheControl?:
|
360 | | string
|
361 | | number
|
362 | | boolean
|
363 | | {
|
364 | maxAge?: number;
|
365 | immutable?: boolean;
|
366 | }
|
367 | | undefined;
|
368 | cacheImmutable?: boolean | undefined;
|
369 | };
|
370 | type Middleware<
|
371 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
372 | ResponseInternal extends ServerResponse = ServerResponse,
|
373 | > = (
|
374 | req: RequestInternal,
|
375 | res: ResponseInternal,
|
376 | next: NextFunction,
|
377 | ) => Promise<void>;
|
378 | type Extra = import("./utils/getFilenameFromUrl").Extra;
|
379 | type GetFilenameFromUrl = (
|
380 | url: string,
|
381 | extra?: Extra | undefined,
|
382 | ) => string | undefined;
|
383 | type WaitUntilValid = (callback: Callback) => any;
|
384 | type Invalidate = (callback: Callback) => any;
|
385 | type Close = (callback: (err: Error | null | undefined) => void) => any;
|
386 | type AdditionalMethods<
|
387 | RequestInternal extends IncomingMessage,
|
388 | ResponseInternal extends ServerResponse,
|
389 | > = {
|
390 | getFilenameFromUrl: GetFilenameFromUrl;
|
391 | waitUntilValid: WaitUntilValid;
|
392 | invalidate: Invalidate;
|
393 | close: Close;
|
394 | context: Context<RequestInternal, ResponseInternal>;
|
395 | };
|
396 | type API<
|
397 | RequestInternal extends IncomingMessage = import("http").IncomingMessage,
|
398 | ResponseInternal extends ServerResponse = ServerResponse,
|
399 | > = Middleware<RequestInternal, ResponseInternal> &
|
400 | AdditionalMethods<RequestInternal, ResponseInternal>;
|
401 | type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
402 | type WithoutUndefined<T, K extends keyof T> = T & {
|
403 | [P in K]: NonNullable<T[P]>;
|
404 | };
|
405 | type HapiPluginBase<S, O> = {
|
406 | register: (server: S, options: O) => void | Promise<void>;
|
407 | };
|
408 | type HapiPlugin<S, O> = HapiPluginBase<S, O> & {
|
409 | pkg: {
|
410 | name: string;
|
411 | };
|
412 | multiple: boolean;
|
413 | };
|
414 | type HapiOptions = Options & {
|
415 | compiler: Compiler | MultiCompiler;
|
416 | };
|