Skip to content

Commit da2c24d

Browse files
authoredFeb 16, 2024··
fix: types (#5057)
1 parent 0c4c6b7 commit da2c24d

File tree

2 files changed

+342
-251
lines changed

2 files changed

+342
-251
lines changed
 

‎lib/Server.js

+70-92
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ const schema = require("./options.json");
1818
/** @typedef {import("webpack").Stats} Stats */
1919
/** @typedef {import("webpack").MultiStats} MultiStats */
2020
/** @typedef {import("os").NetworkInterfaceInfo} NetworkInterfaceInfo */
21-
/** @typedef {import("express").Request} Request */
22-
/** @typedef {import("express").Response} Response */
2321
/** @typedef {import("express").NextFunction} NextFunction */
2422
/** @typedef {import("express").RequestHandler} ExpressRequestHandler */
2523
/** @typedef {import("express").ErrorRequestHandler} ExpressErrorRequestHandler */
@@ -42,14 +40,19 @@ const schema = require("./options.json");
4240

4341
/** @typedef {import("https").ServerOptions & { spdy?: { plain?: boolean | undefined, ssl?: boolean | undefined, 'x-forwarded-for'?: string | undefined, protocol?: string | undefined, protocols?: string[] | undefined }}} ServerOptions */
4442

43+
/** @typedef {import("express").Request} Request */
44+
/** @typedef {import("express").Response} Response */
45+
4546
/**
46-
* @template Request, Response
47-
* @typedef {import("webpack-dev-middleware").Options<IncomingMessage, ServerResponse>} DevMiddlewareOptions
47+
* @template {Request} T
48+
* @template {Response} U
49+
* @typedef {import("webpack-dev-middleware").Options<T, U>} DevMiddlewareOptions
4850
*/
4951

5052
/**
51-
* @template Request, Response
52-
* @typedef {import("webpack-dev-middleware").Context<IncomingMessage, ServerResponse>} DevMiddlewareContext
53+
* @template {Request} T
54+
* @template {Response} U
55+
* @typedef {import("webpack-dev-middleware").Context<T, U>} DevMiddlewareContext
5356
*/
5457

5558
/**
@@ -1841,36 +1844,20 @@ class Server {
18411844
const { app, middleware } = this;
18421845

18431846
/** @type {import("express").Application} */
1844-
(app).get(
1845-
"/__webpack_dev_server__/sockjs.bundle.js",
1846-
/**
1847-
* @param {Request} req
1848-
* @param {Response} res
1849-
* @returns {void}
1850-
*/
1851-
(req, res) => {
1852-
res.setHeader("Content-Type", "application/javascript");
1847+
(app).get("/__webpack_dev_server__/sockjs.bundle.js", (req, res) => {
1848+
res.setHeader("Content-Type", "application/javascript");
18531849

1854-
const clientPath = path.join(__dirname, "..", "client");
1850+
const clientPath = path.join(__dirname, "..", "client");
18551851

1856-
res.sendFile(path.join(clientPath, "modules/sockjs-client/index.js"));
1857-
},
1858-
);
1852+
res.sendFile(path.join(clientPath, "modules/sockjs-client/index.js"));
1853+
});
18591854

18601855
/** @type {import("express").Application} */
1861-
(app).get(
1862-
"/webpack-dev-server/invalidate",
1863-
/**
1864-
* @param {Request} _req
1865-
* @param {Response} res
1866-
* @returns {void}
1867-
*/
1868-
(_req, res) => {
1869-
this.invalidate();
1856+
(app).get("/webpack-dev-server/invalidate", (_req, res) => {
1857+
this.invalidate();
18701858

1871-
res.end();
1872-
},
1873-
);
1859+
res.end();
1860+
});
18741861

18751862
/** @type {import("express").Application} */
18761863
(app).get("/webpack-dev-server/open-editor", (req, res) => {
@@ -1886,74 +1873,65 @@ class Server {
18861873
});
18871874

18881875
/** @type {import("express").Application} */
1889-
(app).get(
1890-
"/webpack-dev-server",
1891-
/**
1892-
* @param {Request} req
1893-
* @param {Response} res
1894-
* @returns {void}
1895-
*/
1896-
(req, res) => {
1897-
/** @type {import("webpack-dev-middleware").API<Request, Response>}*/
1898-
(middleware).waitUntilValid((stats) => {
1899-
res.setHeader("Content-Type", "text/html");
1900-
// HEAD requests should not return body content
1901-
if (req.method === "HEAD") {
1902-
res.end();
1903-
return;
1904-
}
1905-
res.write(
1906-
'<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body>',
1907-
);
1876+
(app).get("/webpack-dev-server", (req, res) => {
1877+
/** @type {import("webpack-dev-middleware").API<Request, Response>}*/
1878+
(middleware).waitUntilValid((stats) => {
1879+
res.setHeader("Content-Type", "text/html");
1880+
// HEAD requests should not return body content
1881+
if (req.method === "HEAD") {
1882+
res.end();
1883+
return;
1884+
}
1885+
res.write(
1886+
'<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body>',
1887+
);
19081888

1909-
const statsForPrint =
1910-
typeof (/** @type {MultiStats} */ (stats).stats) !== "undefined"
1911-
? /** @type {MultiStats} */ (stats).toJson().children
1912-
: [/** @type {Stats} */ (stats).toJson()];
1889+
const statsForPrint =
1890+
typeof (/** @type {MultiStats} */ (stats).stats) !== "undefined"
1891+
? /** @type {MultiStats} */ (stats).toJson().children
1892+
: [/** @type {Stats} */ (stats).toJson()];
19131893

1914-
res.write(`<h1>Assets Report:</h1>`);
1894+
res.write(`<h1>Assets Report:</h1>`);
19151895

1916-
/**
1917-
* @type {StatsCompilation[]}
1918-
*/
1919-
(statsForPrint).forEach((item, index) => {
1920-
res.write("<div>");
1921-
1922-
const name =
1923-
// eslint-disable-next-line no-nested-ternary
1924-
typeof item.name !== "undefined"
1925-
? item.name
1926-
: /** @type {MultiStats} */ (stats).stats
1927-
? `unnamed[${index}]`
1928-
: "unnamed";
1929-
1930-
res.write(`<h2>Compilation: ${name}</h2>`);
1931-
res.write("<ul>");
1932-
1933-
const publicPath =
1934-
item.publicPath === "auto" ? "" : item.publicPath;
1935-
1936-
for (const asset of /** @type {NonNullable<StatsCompilation["assets"]>} */ (
1937-
item.assets
1938-
)) {
1939-
const assetName = asset.name;
1940-
const assetURL = `${publicPath}${assetName}`;
1941-
1942-
res.write(
1943-
`<li>
1896+
/**
1897+
* @type {StatsCompilation[]}
1898+
*/
1899+
(statsForPrint).forEach((item, index) => {
1900+
res.write("<div>");
1901+
1902+
const name =
1903+
// eslint-disable-next-line no-nested-ternary
1904+
typeof item.name !== "undefined"
1905+
? item.name
1906+
: /** @type {MultiStats} */ (stats).stats
1907+
? `unnamed[${index}]`
1908+
: "unnamed";
1909+
1910+
res.write(`<h2>Compilation: ${name}</h2>`);
1911+
res.write("<ul>");
1912+
1913+
const publicPath = item.publicPath === "auto" ? "" : item.publicPath;
1914+
1915+
for (const asset of /** @type {NonNullable<StatsCompilation["assets"]>} */ (
1916+
item.assets
1917+
)) {
1918+
const assetName = asset.name;
1919+
const assetURL = `${publicPath}${assetName}`;
1920+
1921+
res.write(
1922+
`<li>
19441923
<strong><a href="${assetURL}" target="_blank">${assetName}</a></strong>
19451924
</li>`,
1946-
);
1947-
}
1948-
1949-
res.write("</ul>");
1950-
res.write("</div>");
1951-
});
1925+
);
1926+
}
19521927

1953-
res.end("</body></html>");
1928+
res.write("</ul>");
1929+
res.write("</div>");
19541930
});
1955-
},
1956-
);
1931+
1932+
res.end("</body></html>");
1933+
});
1934+
});
19571935
}
19581936

19591937
/**

‎types/lib/Server.d.ts

+272-159
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ declare class Server {
4949
link?: undefined;
5050
}
5151
| {
52-
type: string;
52+
type: string /** @typedef {import("express").ErrorRequestHandler} ExpressErrorRequestHandler */;
5353
description: string;
5454
link: string;
5555
cli?: undefined;
5656
}
5757
)[];
5858
description: string;
59-
link: string /** @typedef {import("connect-history-api-fallback").Options} ConnectHistoryApiFallbackOptions */;
59+
link: string;
6060
};
6161
Client: {
6262
description: string;
@@ -78,6 +78,152 @@ declare class Server {
7878
logging: {
7979
$ref: string;
8080
};
81+
/** @typedef {import("net").Socket} Socket */
82+
/** @typedef {import("http").IncomingMessage} IncomingMessage */
83+
/** @typedef {import("http").ServerResponse} ServerResponse */
84+
/** @typedef {import("open").Options} OpenOptions */
85+
/** @typedef {import("https").ServerOptions & { spdy?: { plain?: boolean | undefined, ssl?: boolean | undefined, 'x-forwarded-for'?: string | undefined, protocol?: string | undefined, protocols?: string[] | undefined }}} ServerOptions */
86+
/** @typedef {import("express").Request} Request */
87+
/** @typedef {import("express").Response} Response */
88+
/**
89+
* @template {Request} T
90+
* @template {Response} U
91+
* @typedef {import("webpack-dev-middleware").Options<T, U>} DevMiddlewareOptions
92+
*/
93+
/**
94+
* @template {Request} T
95+
* @template {Response} U
96+
* @typedef {import("webpack-dev-middleware").Context<T, U>} DevMiddlewareContext
97+
*/
98+
/**
99+
* @typedef {"local-ip" | "local-ipv4" | "local-ipv6" | string} Host
100+
*/
101+
/**
102+
* @typedef {number | string | "auto"} Port
103+
*/
104+
/**
105+
* @typedef {Object} WatchFiles
106+
* @property {string | string[]} paths
107+
* @property {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [options]
108+
*/
109+
/**
110+
* @typedef {Object} Static
111+
* @property {string} [directory]
112+
* @property {string | string[]} [publicPath]
113+
* @property {boolean | ServeIndexOptions} [serveIndex]
114+
* @property {ServeStaticOptions} [staticOptions]
115+
* @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [watch]
116+
*/
117+
/**
118+
* @typedef {Object} NormalizedStatic
119+
* @property {string} directory
120+
* @property {string[]} publicPath
121+
* @property {false | ServeIndexOptions} serveIndex
122+
* @property {ServeStaticOptions} staticOptions
123+
* @property {false | WatchOptions} watch
124+
*/
125+
/**
126+
* @typedef {Object} ServerConfiguration
127+
* @property {"http" | "https" | "spdy" | string} [type]
128+
* @property {ServerOptions} [options]
129+
*/
130+
/**
131+
* @typedef {Object} WebSocketServerConfiguration
132+
* @property {"sockjs" | "ws" | string | Function} [type]
133+
* @property {Record<string, any>} [options]
134+
*/
135+
/**
136+
* @typedef {(import("ws").WebSocket | import("sockjs").Connection & { send: import("ws").WebSocket["send"], terminate: import("ws").WebSocket["terminate"], ping: import("ws").WebSocket["ping"] }) & { isAlive?: boolean }} ClientConnection
137+
*/
138+
/**
139+
* @typedef {import("ws").WebSocketServer | import("sockjs").Server & { close: import("ws").WebSocketServer["close"] }} WebSocketServer
140+
*/
141+
/**
142+
* @typedef {{ implementation: WebSocketServer, clients: ClientConnection[] }} WebSocketServerImplementation
143+
*/
144+
/**
145+
* @callback ByPass
146+
* @param {Request} req
147+
* @param {Response} res
148+
* @param {ProxyConfigArrayItem} proxyConfig
149+
*/
150+
/**
151+
* @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem
152+
*/
153+
/**
154+
* @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray
155+
*/
156+
/**
157+
* @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap
158+
*/
159+
/**
160+
* @typedef {Object} OpenApp
161+
* @property {string} [name]
162+
* @property {string[]} [arguments]
163+
*/
164+
/**
165+
* @typedef {Object} Open
166+
* @property {string | string[] | OpenApp} [app]
167+
* @property {string | string[]} [target]
168+
*/
169+
/**
170+
* @typedef {Object} NormalizedOpen
171+
* @property {string} target
172+
* @property {import("open").Options} options
173+
*/
174+
/**
175+
* @typedef {Object} WebSocketURL
176+
* @property {string} [hostname]
177+
* @property {string} [password]
178+
* @property {string} [pathname]
179+
* @property {number | string} [port]
180+
* @property {string} [protocol]
181+
* @property {string} [username]
182+
*/
183+
/**
184+
* @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions
185+
*/
186+
/**
187+
* @typedef {Object} ClientConfiguration
188+
* @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging]
189+
* @property {boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions }} [overlay]
190+
* @property {boolean} [progress]
191+
* @property {boolean | number} [reconnect]
192+
* @property {"ws" | "sockjs" | string} [webSocketTransport]
193+
* @property {string | WebSocketURL} [webSocketURL]
194+
*/
195+
/**
196+
* @typedef {Array<{ key: string; value: string }> | Record<string, string | string[]>} Headers
197+
*/
198+
/**
199+
* @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware
200+
*/
201+
/**
202+
* @typedef {Object} Configuration
203+
* @property {boolean | string} [ipc]
204+
* @property {Host} [host]
205+
* @property {Port} [port]
206+
* @property {boolean | "only"} [hot]
207+
* @property {boolean} [liveReload]
208+
* @property {DevMiddlewareOptions<Request, Response>} [devMiddleware]
209+
* @property {boolean} [compress]
210+
* @property {"auto" | "all" | string | string[]} [allowedHosts]
211+
* @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
212+
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
213+
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
214+
* @property {boolean | string | Static | Array<string | Static>} [static]
215+
* @property {boolean | ServerOptions} [https]
216+
* @property {boolean} [http2]
217+
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
218+
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
219+
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
220+
* @property {boolean | string | Open | Array<string | Open>} [open]
221+
* @property {boolean} [setupExitSignals]
222+
* @property {boolean | ClientConfiguration} [client]
223+
* @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext<Request, Response>) => Headers)} [headers]
224+
* @property {(devServer: Server) => void} [onListening]
225+
* @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares]
226+
*/
81227
overlay: {
82228
$ref: string;
83229
};
@@ -104,139 +250,6 @@ declare class Server {
104250
description: string;
105251
link: string;
106252
};
107-
/**
108-
* @template Request, Response
109-
* @typedef {import("webpack-dev-middleware").Context<IncomingMessage, ServerResponse>} DevMiddlewareContext
110-
*/
111-
/**
112-
* @typedef {"local-ip" | "local-ipv4" | "local-ipv6" | string} Host
113-
*/
114-
/**
115-
* @typedef {number | string | "auto"} Port
116-
*/
117-
/**
118-
* @typedef {Object} WatchFiles
119-
* @property {string | string[]} paths
120-
* @property {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [options]
121-
*/
122-
/**
123-
* @typedef {Object} Static
124-
* @property {string} [directory]
125-
* @property {string | string[]} [publicPath]
126-
* @property {boolean | ServeIndexOptions} [serveIndex]
127-
* @property {ServeStaticOptions} [staticOptions]
128-
* @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [watch]
129-
*/
130-
/**
131-
* @typedef {Object} NormalizedStatic
132-
* @property {string} directory
133-
* @property {string[]} publicPath
134-
* @property {false | ServeIndexOptions} serveIndex
135-
* @property {ServeStaticOptions} staticOptions
136-
* @property {false | WatchOptions} watch
137-
*/
138-
/**
139-
* @typedef {Object} ServerConfiguration
140-
* @property {"http" | "https" | "spdy" | string} [type]
141-
* @property {ServerOptions} [options]
142-
*/
143-
/**
144-
* @typedef {Object} WebSocketServerConfiguration
145-
* @property {"sockjs" | "ws" | string | Function} [type]
146-
* @property {Record<string, any>} [options]
147-
*/
148-
/**
149-
* @typedef {(import("ws").WebSocket | import("sockjs").Connection & { send: import("ws").WebSocket["send"], terminate: import("ws").WebSocket["terminate"], ping: import("ws").WebSocket["ping"] }) & { isAlive?: boolean }} ClientConnection
150-
*/
151-
/**
152-
* @typedef {import("ws").WebSocketServer | import("sockjs").Server & { close: import("ws").WebSocketServer["close"] }} WebSocketServer
153-
*/
154-
/**
155-
* @typedef {{ implementation: WebSocketServer, clients: ClientConnection[] }} WebSocketServerImplementation
156-
*/
157-
/**
158-
* @callback ByPass
159-
* @param {Request} req
160-
* @param {Response} res
161-
* @param {ProxyConfigArrayItem} proxyConfig
162-
*/
163-
/**
164-
* @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem
165-
*/
166-
/**
167-
* @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray
168-
*/
169-
/**
170-
* @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap
171-
*/
172-
/**
173-
* @typedef {Object} OpenApp
174-
* @property {string} [name]
175-
* @property {string[]} [arguments]
176-
*/
177-
/**
178-
* @typedef {Object} Open
179-
* @property {string | string[] | OpenApp} [app]
180-
* @property {string | string[]} [target]
181-
*/
182-
/**
183-
* @typedef {Object} NormalizedOpen
184-
* @property {string} target
185-
* @property {import("open").Options} options
186-
*/
187-
/**
188-
* @typedef {Object} WebSocketURL
189-
* @property {string} [hostname]
190-
* @property {string} [password]
191-
* @property {string} [pathname]
192-
* @property {number | string} [port]
193-
* @property {string} [protocol]
194-
* @property {string} [username]
195-
*/
196-
/**
197-
* @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions
198-
*/
199-
/**
200-
* @typedef {Object} ClientConfiguration
201-
* @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging]
202-
* @property {boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions }} [overlay]
203-
* @property {boolean} [progress]
204-
* @property {boolean | number} [reconnect]
205-
* @property {"ws" | "sockjs" | string} [webSocketTransport]
206-
* @property {string | WebSocketURL} [webSocketURL]
207-
*/
208-
/**
209-
* @typedef {Array<{ key: string; value: string }> | Record<string, string | string[]>} Headers
210-
*/
211-
/**
212-
* @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware
213-
*/
214-
/**
215-
* @typedef {Object} Configuration
216-
* @property {boolean | string} [ipc]
217-
* @property {Host} [host]
218-
* @property {Port} [port]
219-
* @property {boolean | "only"} [hot]
220-
* @property {boolean} [liveReload]
221-
* @property {DevMiddlewareOptions<Request, Response>} [devMiddleware]
222-
* @property {boolean} [compress]
223-
* @property {"auto" | "all" | string | string[]} [allowedHosts]
224-
* @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
225-
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
226-
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
227-
* @property {boolean | string | Static | Array<string | Static>} [static]
228-
* @property {boolean | ServerOptions} [https]
229-
* @property {boolean} [http2]
230-
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
231-
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
232-
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
233-
* @property {boolean | string | Open | Array<string | Open>} [open]
234-
* @property {boolean} [setupExitSignals]
235-
* @property {boolean | ClientConfiguration} [client]
236-
* @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext<Request, Response>) => Headers)} [headers]
237-
* @property {(devServer: Server) => void} [onListening]
238-
* @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares]
239-
*/
240253
ClientOverlay: {
241254
anyOf: (
242255
| {
@@ -282,7 +295,9 @@ declare class Server {
282295
instanceof?: undefined;
283296
}
284297
| {
285-
instanceof: string;
298+
instanceof: string /**
299+
* @typedef {import("ws").WebSocketServer | import("sockjs").Server & { close: import("ws").WebSocketServer["close"] }} WebSocketServer
300+
*/;
286301
description: string;
287302
type?: undefined;
288303
cli?: undefined;
@@ -308,6 +323,69 @@ declare class Server {
308323
)[];
309324
};
310325
trustedTypesPolicyName: {
326+
/**
327+
* @typedef {Object} Open
328+
* @property {string | string[] | OpenApp} [app]
329+
* @property {string | string[]} [target]
330+
*/
331+
/**
332+
* @typedef {Object} NormalizedOpen
333+
* @property {string} target
334+
* @property {import("open").Options} options
335+
*/
336+
/**
337+
* @typedef {Object} WebSocketURL
338+
* @property {string} [hostname]
339+
* @property {string} [password]
340+
* @property {string} [pathname]
341+
* @property {number | string} [port]
342+
* @property {string} [protocol]
343+
* @property {string} [username]
344+
*/
345+
/**
346+
* @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions
347+
*/
348+
/**
349+
* @typedef {Object} ClientConfiguration
350+
* @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging]
351+
* @property {boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions }} [overlay]
352+
* @property {boolean} [progress]
353+
* @property {boolean | number} [reconnect]
354+
* @property {"ws" | "sockjs" | string} [webSocketTransport]
355+
* @property {string | WebSocketURL} [webSocketURL]
356+
*/
357+
/**
358+
* @typedef {Array<{ key: string; value: string }> | Record<string, string | string[]>} Headers
359+
*/
360+
/**
361+
* @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware
362+
*/
363+
/**
364+
* @typedef {Object} Configuration
365+
* @property {boolean | string} [ipc]
366+
* @property {Host} [host]
367+
* @property {Port} [port]
368+
* @property {boolean | "only"} [hot]
369+
* @property {boolean} [liveReload]
370+
* @property {DevMiddlewareOptions<Request, Response>} [devMiddleware]
371+
* @property {boolean} [compress]
372+
* @property {"auto" | "all" | string | string[]} [allowedHosts]
373+
* @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
374+
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
375+
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
376+
* @property {boolean | string | Static | Array<string | Static>} [static]
377+
* @property {boolean | ServerOptions} [https]
378+
* @property {boolean} [http2]
379+
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
380+
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
381+
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
382+
* @property {boolean | string | Open | Array<string | Open>} [open]
383+
* @property {boolean} [setupExitSignals]
384+
* @property {boolean | ClientConfiguration} [client]
385+
* @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext<Request, Response>) => Headers)} [headers]
386+
* @property {(devServer: Server) => void} [onListening]
387+
* @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares]
388+
*/
311389
description: string;
312390
type: string;
313391
};
@@ -461,6 +539,9 @@ declare class Server {
461539
$ref: string;
462540
};
463541
minItems: number;
542+
/**
543+
* @type {Socket[]}
544+
*/
464545
instanceof?: undefined;
465546
}
466547
| {
@@ -560,6 +641,11 @@ declare class Server {
560641
OnListening: {
561642
instanceof: string;
562643
description: string;
644+
/**
645+
* @param {Port} port
646+
* @param {string} host
647+
* @returns {Promise<number | string>}
648+
*/
563649
link: string;
564650
};
565651
Open: {
@@ -586,9 +672,7 @@ declare class Server {
586672
type: string;
587673
cli: {
588674
negatedDescription: string;
589-
} /**
590-
* @type {string | undefined}
591-
*/;
675+
};
592676
};
593677
OpenObject: {
594678
type: string;
@@ -621,11 +705,7 @@ declare class Server {
621705
type: string;
622706
items: {
623707
type: string;
624-
minLength: number /**
625-
* @private
626-
* @param {Compiler} compiler
627-
* @returns bool
628-
*/;
708+
minLength: number;
629709
};
630710
minItems: number;
631711
minLength?: undefined;
@@ -701,11 +781,11 @@ declare class Server {
701781
anyOf: (
702782
| {
703783
type: string;
704-
instanceof?: undefined;
784+
/** @type {WebSocketURL} */ instanceof?: undefined;
705785
}
706786
| {
707787
instanceof: string;
708-
type?: undefined;
788+
/** @type {ClientConfiguration} */ type?: undefined;
709789
}
710790
)[];
711791
};
@@ -985,7 +1065,7 @@ declare class Server {
9851065
directory: {
9861066
type: string;
9871067
minLength: number;
988-
/** @type {MultiCompiler} */ description: string;
1068+
description: string;
9891069
link: string;
9901070
};
9911071
staticOptions: {
@@ -1110,7 +1190,7 @@ declare class Server {
11101190
};
11111191
WatchFilesString: {
11121192
type: string;
1113-
minLength: number;
1193+
/** @type {NormalizedStatic} */ minLength: number;
11141194
};
11151195
WebSocketServer: {
11161196
anyOf: {
@@ -1388,8 +1468,14 @@ declare class Server {
13881468
private setupDevMiddleware;
13891469
middleware:
13901470
| import("webpack-dev-middleware").API<
1391-
import("http").IncomingMessage,
1392-
import("http").ServerResponse<import("http").IncomingMessage>
1471+
import("express").Request<
1472+
import("express-serve-static-core").ParamsDictionary,
1473+
any,
1474+
any,
1475+
qs.ParsedQs,
1476+
Record<string, any>
1477+
>,
1478+
import("express").Response<any, Record<string, any>>
13931479
>
13941480
| null
13951481
| undefined;
@@ -1529,8 +1615,6 @@ declare namespace Server {
15291615
Stats,
15301616
MultiStats,
15311617
NetworkInterfaceInfo,
1532-
Request,
1533-
Response,
15341618
NextFunction,
15351619
ExpressRequestHandler,
15361620
ExpressErrorRequestHandler,
@@ -1551,6 +1635,8 @@ declare namespace Server {
15511635
ServerResponse,
15521636
OpenOptions,
15531637
ServerOptions,
1638+
Request,
1639+
Response,
15541640
DevMiddlewareOptions,
15551641
DevMiddlewareContext,
15561642
Host,
@@ -1596,8 +1682,6 @@ type StatsCompilation = import("webpack").StatsCompilation;
15961682
type Stats = import("webpack").Stats;
15971683
type MultiStats = import("webpack").MultiStats;
15981684
type NetworkInterfaceInfo = import("os").NetworkInterfaceInfo;
1599-
type Request = import("express").Request;
1600-
type Response = import("express").Response;
16011685
type NextFunction = import("express").NextFunction;
16021686
type ExpressRequestHandler = import("express").RequestHandler;
16031687
type ExpressErrorRequestHandler = import("express").ErrorRequestHandler;
@@ -1625,10 +1709,28 @@ type ServerOptions = import("https").ServerOptions & {
16251709
protocols?: string[] | undefined;
16261710
};
16271711
};
1628-
type DevMiddlewareOptions<Request_1, Response_1> =
1629-
import("webpack-dev-middleware").Options<IncomingMessage, ServerResponse>;
1630-
type DevMiddlewareContext<Request_1, Response_1> =
1631-
import("webpack-dev-middleware").Context<IncomingMessage, ServerResponse>;
1712+
type Request = import("express").Request;
1713+
type Response = import("express").Response;
1714+
type DevMiddlewareOptions<
1715+
T extends import("express").Request<
1716+
import("express-serve-static-core").ParamsDictionary,
1717+
any,
1718+
any,
1719+
qs.ParsedQs,
1720+
Record<string, any>
1721+
>,
1722+
U extends import("express").Response<any, Record<string, any>>,
1723+
> = import("webpack-dev-middleware").Options<T, U>;
1724+
type DevMiddlewareContext<
1725+
T extends import("express").Request<
1726+
import("express-serve-static-core").ParamsDictionary,
1727+
any,
1728+
any,
1729+
qs.ParsedQs,
1730+
Record<string, any>
1731+
>,
1732+
U extends import("express").Response<any, Record<string, any>>,
1733+
> = import("webpack-dev-middleware").Context<T, U>;
16321734
type Host = "local-ip" | "local-ipv4" | "local-ipv6" | string;
16331735
type Port = number | string | "auto";
16341736
type WatchFiles = {
@@ -1767,7 +1869,18 @@ type Configuration = {
17671869
port?: Port | undefined;
17681870
hot?: boolean | "only" | undefined;
17691871
liveReload?: boolean | undefined;
1770-
devMiddleware?: DevMiddlewareOptions<Request_1, Response_1> | undefined;
1872+
devMiddleware?:
1873+
| DevMiddlewareOptions<
1874+
import("express").Request<
1875+
import("express-serve-static-core").ParamsDictionary,
1876+
any,
1877+
any,
1878+
qs.ParsedQs,
1879+
Record<string, any>
1880+
>,
1881+
import("express").Response<any, Record<string, any>>
1882+
>
1883+
| undefined;
17711884
compress?: boolean | undefined;
17721885
allowedHosts?: string | string[] | undefined;
17731886
historyApiFallback?:

0 commit comments

Comments
 (0)
Please sign in to comment.