diff --git a/lib/Server.js b/lib/Server.js index 05c3c0ba82..1a7b572d9b 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -379,11 +379,50 @@ class Server { } /** - * @param {string} gateway + * @param {string} gatewayOrFamily or family + * @param {boolean} [isInternal=false] ip should be internal * @returns {string | undefined} */ - static findIp(gateway) { - const gatewayIp = ipaddr.parse(gateway); + static findIp(gatewayOrFamily, isInternal = false) { + if (gatewayOrFamily === "v4" || gatewayOrFamily === "v6") { + let host; + + Object.values(os.networkInterfaces()) + .flatMap((networks) => networks ?? []) + .filter((network) => { + if (!network || !network.address) { + return false; + } + + if (network.family !== `IP${gatewayOrFamily}`) { + return false; + } + + if (network.internal !== isInternal) { + return false; + } + + if (gatewayOrFamily === "v6") { + const range = ipaddr.parse(network.address).range(); + + if (range !== "ipv4Mapped" && range !== "uniqueLocal") { + return false; + } + } + + return network.address; + }) + .forEach((network) => { + host = network.address; + if (host.includes(":")) { + host = `[${host}]`; + } + }); + + return host; + } + + const gatewayIp = ipaddr.parse(gatewayOrFamily); // Look for the matching interface in all local interfaces. for (const addresses of Object.values(os.networkInterfaces())) { @@ -403,32 +442,22 @@ class Server { } } + // TODO remove me in the next major release, we have `findIp` /** * @param {"v4" | "v6"} family * @returns {Promise} */ static async internalIP(family) { - try { - const { gateway } = await require("default-gateway")[family](); - - return Server.findIp(gateway); - } catch { - // ignore - } + return Server.findIp(family); } + // TODO remove me in the next major release, we have `findIp` /** * @param {"v4" | "v6"} family * @returns {string | undefined} */ static internalIPSync(family) { - try { - const { gateway } = require("default-gateway")[family].sync(); - - return Server.findIp(gateway); - } catch { - // ignore - } + return Server.findIp(family); } /** @@ -437,15 +466,11 @@ class Server { */ static async getHostname(hostname) { if (hostname === "local-ip") { - return ( - (await Server.internalIP("v4")) || - (await Server.internalIP("v6")) || - "0.0.0.0" - ); + return Server.findIp("v4") || Server.findIp("v6") || "0.0.0.0"; } else if (hostname === "local-ipv4") { - return (await Server.internalIP("v4")) || "0.0.0.0"; + return Server.findIp("v4") || "0.0.0.0"; } else if (hostname === "local-ipv6") { - return (await Server.internalIP("v6")) || "::"; + return Server.findIp("v6") || "::"; } return hostname; @@ -2777,13 +2802,13 @@ class Server { if (parsedIP.range() === "unspecified") { localhost = prettyPrintURL("localhost"); - const networkIPv4 = await Server.internalIP("v4"); + const networkIPv4 = Server.findIp("v4"); if (networkIPv4) { networkUrlIPv4 = prettyPrintURL(networkIPv4); } - const networkIPv6 = await Server.internalIP("v6"); + const networkIPv6 = Server.findIp("v6"); if (networkIPv6) { networkUrlIPv6 = prettyPrintURL(networkIPv6); diff --git a/package-lock.json b/package-lock.json index e4809f9774..a17d00276b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "colorette": "^2.0.10", "compression": "^1.7.4", "connect-history-api-fallback": "^2.0.0", - "default-gateway": "^6.0.3", "express": "^4.19.2", "graceful-fs": "^4.2.6", "html-entities": "^2.4.0", @@ -53,7 +52,6 @@ "@commitlint/cli": "^19.0.3", "@commitlint/config-conventional": "^19.0.3", "@types/compression": "^1.7.2", - "@types/default-gateway": "^3.0.1", "@types/node": "^20.11.16", "@types/node-forge": "^1.3.1", "@types/sockjs-client": "^1.5.1", @@ -94,7 +92,7 @@ "style-loader": "^4.0.0", "supertest": "^6.1.3", "tcp-port-used": "^1.0.2", - "typescript": "^5.3.3", + "typescript": "^5.5.4", "wait-for-expect": "^3.0.2", "webpack": "^5.91.0", "webpack-cli": "^5.0.1", @@ -4594,12 +4592,6 @@ "@types/node": "*" } }, - "node_modules/@types/default-gateway": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@types/default-gateway/-/default-gateway-3.0.1.tgz", - "integrity": "sha512-tpu0hp+AOIzwdAHyZPzLE5pCf9uT0pb+xZ76T4S7MrY2YTVq918Q7Q2VQ3KCVQqYxM7nxuCK/SL3X97jBEIeKQ==", - "dev": true - }, "node_modules/@types/eslint": { "version": "8.56.10", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.10.tgz", @@ -8020,6 +8012,7 @@ "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -8586,17 +8579,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/default-gateway": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/default-gateway/-/default-gateway-6.0.3.tgz", - "integrity": "sha512-fwSOJsbbNzZ/CUFpqFBqYfYNLj1NbMPm8MMCIzHjC83iSJRBEGmDUxU+WP661BaBQImeC2yHwXtz+P/O9o+XEg==", - "dependencies": { - "execa": "^5.0.0" - }, - "engines": { - "node": ">= 10" - } - }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", @@ -9904,6 +9886,7 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "dev": true, "dependencies": { "cross-spawn": "^7.0.3", "get-stream": "^6.0.0", @@ -10821,6 +10804,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", + "dev": true, "engines": { "node": ">=10" }, @@ -11670,6 +11654,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "dev": true, "engines": { "node": ">=10.17.0" } @@ -12316,6 +12301,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "dev": true, "engines": { "node": ">=8" }, @@ -12441,7 +12427,8 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true }, "node_modules/isobject": { "version": "3.0.1", @@ -15115,7 +15102,8 @@ "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", + "devOptional": true }, "node_modules/merge2": { "version": "1.4.1", @@ -15180,6 +15168,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true, "engines": { "node": ">=6" } @@ -15533,6 +15522,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "dev": true, "dependencies": { "path-key": "^3.0.0" }, @@ -15679,6 +15669,7 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "dev": true, "dependencies": { "mimic-fn": "^2.1.0" }, @@ -15976,6 +15967,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, "engines": { "node": ">=8" } @@ -17416,6 +17408,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, "dependencies": { "shebang-regex": "^3.0.0" }, @@ -17427,6 +17420,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, "engines": { "node": ">=8" } @@ -17459,7 +17453,8 @@ "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true }, "node_modules/sisteransi": { "version": "1.0.5", @@ -18314,6 +18309,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "dev": true, "engines": { "node": ">=6" } @@ -19018,9 +19014,9 @@ "dev": true }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -19620,6 +19616,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "dependencies": { "isexe": "^2.0.0" }, diff --git a/package.json b/package.json index 6d18e6a31a..cd4d526306 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,6 @@ "colorette": "^2.0.10", "compression": "^1.7.4", "connect-history-api-fallback": "^2.0.0", - "default-gateway": "^6.0.3", "express": "^4.19.2", "graceful-fs": "^4.2.6", "html-entities": "^2.4.0", @@ -87,7 +86,6 @@ "@commitlint/cli": "^19.0.3", "@commitlint/config-conventional": "^19.0.3", "@types/compression": "^1.7.2", - "@types/default-gateway": "^3.0.1", "@types/node": "^20.11.16", "@types/node-forge": "^1.3.1", "@types/sockjs-client": "^1.5.1", @@ -128,7 +126,7 @@ "style-loader": "^4.0.0", "supertest": "^6.1.3", "tcp-port-used": "^1.0.2", - "typescript": "^5.3.3", + "typescript": "^5.5.4", "wait-for-expect": "^3.0.2", "webpack": "^5.91.0", "webpack-cli": "^5.0.1", diff --git a/test/cli/host-option.test.js b/test/cli/host-option.test.js index 6355b42df1..f2a0066bc0 100644 --- a/test/cli/host-option.test.js +++ b/test/cli/host-option.test.js @@ -4,8 +4,8 @@ const { testBin, normalizeStderr } = require("../helpers/test-bin"); const port = require("../ports-map")["cli-host"]; const Server = require("../../lib/Server"); -const localIPv4 = Server.internalIPSync("v4"); -const localIPv6 = Server.internalIPSync("v6"); +const localIPv4 = Server.findIp("v4"); +const localIPv6 = Server.findIp("v6"); describe('"host" CLI option', () => { it('should work using "--host 0.0.0.0" (IPv4)', async () => { diff --git a/test/e2e/host.test.js b/test/e2e/host.test.js index 3217127115..a1bb32c091 100644 --- a/test/e2e/host.test.js +++ b/test/e2e/host.test.js @@ -6,8 +6,8 @@ const config = require("../fixtures/client-config/webpack.config"); const runBrowser = require("../helpers/run-browser"); const port = require("../ports-map").host; -const ipv4 = Server.internalIPSync("v4"); -const ipv6 = Server.internalIPSync("v6"); +const ipv4 = Server.findIp("v4"); +const ipv6 = Server.findIp("v6"); // macos requires root for using ip v6 const isMacOS = process.platform === "darwin"; diff --git a/types/bin/cli-flags.d.ts b/types/bin/cli-flags.d.ts index e8553ac5f6..4c50ae6e5a 100644 --- a/types/bin/cli-flags.d.ts +++ b/types/bin/cli-flags.d.ts @@ -6,6 +6,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + values?: undefined; } | { description: string; @@ -152,6 +153,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + negatedDescription?: undefined; } )[]; description: string; @@ -172,6 +174,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + values?: undefined; } )[]; description: string; @@ -247,6 +250,7 @@ declare const _exports: { multiple: boolean; path: string; type: string; + values?: undefined; } )[]; description: string; @@ -302,6 +306,7 @@ declare const _exports: { multiple: boolean; path: string; type: string; + values?: undefined; } )[]; description: string; @@ -316,6 +321,7 @@ declare const _exports: { description: string; negatedDescription: string; path: string; + values?: undefined; } | { type: string; @@ -323,6 +329,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + negatedDescription?: undefined; } )[]; description: string; @@ -515,6 +522,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + values?: undefined; } | { type: string; @@ -559,6 +567,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + negatedDescription?: undefined; } | { type: string; @@ -645,6 +654,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + values?: undefined; } | { type: string; @@ -832,6 +842,7 @@ declare const _exports: { multiple: boolean; description: string; path: string; + negatedDescription?: undefined; } | { type: string; @@ -951,12 +962,15 @@ declare const _exports: { path: string; type: string; values: string[]; + negatedDescription?: undefined; } | { description: string; multiple: boolean; path: string; type: string; + negatedDescription?: undefined; + values?: undefined; } )[]; description: string; @@ -977,6 +991,7 @@ declare const _exports: { multiple: boolean; path: string; type: string; + values?: undefined; } )[]; description: string; diff --git a/types/lib/Server.d.ts b/types/lib/Server.d.ts index 941267eca4..0f0ed815d0 100644 --- a/types/lib/Server.d.ts +++ b/types/lib/Server.d.ts @@ -1,4 +1,3 @@ -/// export = Server; /** * @typedef {Object} BasicApplication @@ -17,7 +16,7 @@ declare class Server< App: { instanceof: string; description: string; - link: string /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */; + link: string; }; AllowedHosts: { anyOf: ( @@ -53,180 +52,6 @@ declare class Server< minLength: number; }; Bonjour: { - /** @typedef {import("connect-history-api-fallback").Options} ConnectHistoryApiFallbackOptions */ - /** @typedef {import("bonjour-service").Bonjour} Bonjour */ - /** @typedef {import("bonjour-service").Service} BonjourOptions */ - /** @typedef {import("http-proxy-middleware").RequestHandler} RequestHandler */ - /** @typedef {import("http-proxy-middleware").Options} HttpProxyMiddlewareOptions */ - /** @typedef {import("http-proxy-middleware").Filter} HttpProxyMiddlewareOptionsFilter */ - /** @typedef {import("serve-index").Options} ServeIndexOptions */ - /** @typedef {import("serve-static").ServeStaticOptions} ServeStaticOptions */ - /** @typedef {import("ipaddr.js").IPv4} IPv4 */ - /** @typedef {import("ipaddr.js").IPv6} IPv6 */ - /** @typedef {import("net").Socket} Socket */ - /** @typedef {import("http").IncomingMessage} IncomingMessage */ - /** @typedef {import("http").ServerResponse} ServerResponse */ - /** @typedef {import("open").Options} OpenOptions */ - /** @typedef {import("express").Application} ExpressApplication */ - /** @typedef {import("express").RequestHandler} ExpressRequestHandler */ - /** @typedef {import("express").ErrorRequestHandler} ExpressErrorRequestHandler */ - /** @typedef {import("express").Request} ExpressRequest */ - /** @typedef {import("express").Response} ExpressResponse */ - /** @typedef {(err?: any) => void} NextFunction */ - /** @typedef {(req: IncomingMessage, res: ServerResponse) => void} SimpleHandleFunction */ - /** @typedef {(req: IncomingMessage, res: ServerResponse, next: NextFunction) => void} NextHandleFunction */ - /** @typedef {(err: any, req: IncomingMessage, res: ServerResponse, next: NextFunction) => void} ErrorHandleFunction */ - /** @typedef {SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction} HandleFunction */ - /** @typedef {import("https").ServerOptions & { spdy?: { plain?: boolean | undefined, ssl?: boolean | undefined, 'x-forwarded-for'?: string | undefined, protocol?: string | undefined, protocols?: string[] | undefined }}} ServerOptions */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {T extends ExpressApplication ? ExpressRequest : IncomingMessage} Request - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {T extends ExpressApplication ? ExpressResponse : ServerResponse} Response - */ - /** - * @template {Request} T - * @template {Response} U - * @typedef {import("webpack-dev-middleware").Options} DevMiddlewareOptions - */ - /** - * @template {Request} T - * @template {Response} U - * @typedef {import("webpack-dev-middleware").Context} DevMiddlewareContext - */ - /** - * @typedef {"local-ip" | "local-ipv4" | "local-ipv6" | string} Host - */ - /** - * @typedef {number | string | "auto"} Port - */ - /** - * @typedef {Object} WatchFiles - * @property {string | string[]} paths - * @property {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [options] - */ - /** - * @typedef {Object} Static - * @property {string} [directory] - * @property {string | string[]} [publicPath] - * @property {boolean | ServeIndexOptions} [serveIndex] - * @property {ServeStaticOptions} [staticOptions] - * @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [watch] - */ - /** - * @typedef {Object} NormalizedStatic - * @property {string} directory - * @property {string[]} publicPath - * @property {false | ServeIndexOptions} serveIndex - * @property {ServeStaticOptions} staticOptions - * @property {false | WatchOptions} watch - */ - /** - * @typedef {Object} ServerConfiguration - * @property {"http" | "https" | "spdy" | string} [type] - * @property {ServerOptions} [options] - */ - /** - * @typedef {Object} WebSocketServerConfiguration - * @property {"sockjs" | "ws" | string | Function} [type] - * @property {Record} [options] - */ - /** - * @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 - */ - /** - * @typedef {import("ws").WebSocketServer | import("sockjs").Server & { close: import("ws").WebSocketServer["close"] }} WebSocketServer - */ - /** - * @typedef {{ implementation: WebSocketServer, clients: ClientConnection[] }} WebSocketServerImplementation - */ - /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArrayItem} proxyConfig - */ - /** - * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem - */ - /** - * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray - */ - /** - * @typedef {Object} OpenApp - * @property {string} [name] - * @property {string[]} [arguments] - */ - /** - * @typedef {Object} Open - * @property {string | string[] | OpenApp} [app] - * @property {string | string[]} [target] - */ - /** - * @typedef {Object} NormalizedOpen - * @property {string} target - * @property {import("open").Options} options - */ - /** - * @typedef {Object} WebSocketURL - * @property {string} [hostname] - * @property {string} [password] - * @property {string} [pathname] - * @property {number | string} [port] - * @property {string} [protocol] - * @property {string} [username] - */ - /** - * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions - */ - /** - * @typedef {Object} ClientConfiguration - * @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging] - * @property {boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions }} [overlay] - * @property {boolean} [progress] - * @property {boolean | number} [reconnect] - * @property {"ws" | "sockjs" | string} [webSocketTransport] - * @property {string | WebSocketURL} [webSocketURL] - */ - /** - * @typedef {Array<{ key: string; value: string }> | Record} Headers - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {T extends ExpressApplication ? ExpressRequestHandler | ExpressErrorRequestHandler : HandleFunction} MiddlewareHandler - */ - /** - * @typedef {{ name?: string, path?: string, middleware: MiddlewareHandler } | MiddlewareHandler } Middleware - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {Object} Configuration - * @property {boolean | string} [ipc] - * @property {Host} [host] - * @property {Port} [port] - * @property {boolean | "only"} [hot] - * @property {boolean} [liveReload] - * @property {DevMiddlewareOptions} [devMiddleware] - * @property {boolean} [compress] - * @property {"auto" | "all" | string | string[]} [allowedHosts] - * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] - * @property {boolean | Record | BonjourOptions} [bonjour] - * @property {string | string[] | WatchFiles | Array} [watchFiles] - * @property {boolean | string | Static | Array} [static] - * @property {boolean | ServerOptions} [https] - * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] - * @property {() => Promise} [app] - * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigArray} [proxy] - * @property {boolean | string | Open | Array} [open] - * @property {boolean} [setupExitSignals] - * @property {boolean | ClientConfiguration} [client] - * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] - * @property {(devServer: Server) => void} [onListening] - * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] - */ anyOf: ( | { type: string; @@ -253,7 +78,7 @@ declare class Server< | { enum: boolean[]; cli: { - negatedDescription: string /** @typedef {import("open").Options} OpenOptions */; + negatedDescription: string; }; type?: undefined; additionalProperties?: undefined; @@ -276,159 +101,6 @@ declare class Server< $ref: string; }; webSocketTransport: { - /** @typedef {(req: IncomingMessage, res: ServerResponse, next: NextFunction) => void} NextHandleFunction */ - /** @typedef {(err: any, req: IncomingMessage, res: ServerResponse, next: NextFunction) => void} ErrorHandleFunction */ - /** @typedef {SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction} HandleFunction */ - /** @typedef {import("https").ServerOptions & { spdy?: { plain?: boolean | undefined, ssl?: boolean | undefined, 'x-forwarded-for'?: string | undefined, protocol?: string | undefined, protocols?: string[] | undefined }}} ServerOptions */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {T extends ExpressApplication ? ExpressRequest : IncomingMessage} Request - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {T extends ExpressApplication ? ExpressResponse : ServerResponse} Response - */ - /** - * @template {Request} T - * @template {Response} U - * @typedef {import("webpack-dev-middleware").Options} DevMiddlewareOptions - */ - /** - * @template {Request} T - * @template {Response} U - * @typedef {import("webpack-dev-middleware").Context} DevMiddlewareContext - */ - /** - * @typedef {"local-ip" | "local-ipv4" | "local-ipv6" | string} Host - */ - /** - * @typedef {number | string | "auto"} Port - */ - /** - * @typedef {Object} WatchFiles - * @property {string | string[]} paths - * @property {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [options] - */ - /** - * @typedef {Object} Static - * @property {string} [directory] - * @property {string | string[]} [publicPath] - * @property {boolean | ServeIndexOptions} [serveIndex] - * @property {ServeStaticOptions} [staticOptions] - * @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [watch] - */ - /** - * @typedef {Object} NormalizedStatic - * @property {string} directory - * @property {string[]} publicPath - * @property {false | ServeIndexOptions} serveIndex - * @property {ServeStaticOptions} staticOptions - * @property {false | WatchOptions} watch - */ - /** - * @typedef {Object} ServerConfiguration - * @property {"http" | "https" | "spdy" | string} [type] - * @property {ServerOptions} [options] - */ - /** - * @typedef {Object} WebSocketServerConfiguration - * @property {"sockjs" | "ws" | string | Function} [type] - * @property {Record} [options] - */ - /** - * @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 - */ - /** - * @typedef {import("ws").WebSocketServer | import("sockjs").Server & { close: import("ws").WebSocketServer["close"] }} WebSocketServer - */ - /** - * @typedef {{ implementation: WebSocketServer, clients: ClientConnection[] }} WebSocketServerImplementation - */ - /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArrayItem} proxyConfig - */ - /** - * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem - */ - /** - * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray - */ - /** - * @typedef {Object} OpenApp - * @property {string} [name] - * @property {string[]} [arguments] - */ - /** - * @typedef {Object} Open - * @property {string | string[] | OpenApp} [app] - * @property {string | string[]} [target] - */ - /** - * @typedef {Object} NormalizedOpen - * @property {string} target - * @property {import("open").Options} options - */ - /** - * @typedef {Object} WebSocketURL - * @property {string} [hostname] - * @property {string} [password] - * @property {string} [pathname] - * @property {number | string} [port] - * @property {string} [protocol] - * @property {string} [username] - */ - /** - * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions - */ - /** - * @typedef {Object} ClientConfiguration - * @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging] - * @property {boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions }} [overlay] - * @property {boolean} [progress] - * @property {boolean | number} [reconnect] - * @property {"ws" | "sockjs" | string} [webSocketTransport] - * @property {string | WebSocketURL} [webSocketURL] - */ - /** - * @typedef {Array<{ key: string; value: string }> | Record} Headers - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {T extends ExpressApplication ? ExpressRequestHandler | ExpressErrorRequestHandler : HandleFunction} MiddlewareHandler - */ - /** - * @typedef {{ name?: string, path?: string, middleware: MiddlewareHandler } | MiddlewareHandler } Middleware - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {Object} Configuration - * @property {boolean | string} [ipc] - * @property {Host} [host] - * @property {Port} [port] - * @property {boolean | "only"} [hot] - * @property {boolean} [liveReload] - * @property {DevMiddlewareOptions} [devMiddleware] - * @property {boolean} [compress] - * @property {"auto" | "all" | string | string[]} [allowedHosts] - * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] - * @property {boolean | Record | BonjourOptions} [bonjour] - * @property {string | string[] | WatchFiles | Array} [watchFiles] - * @property {boolean | string | Static | Array} [static] - * @property {boolean | ServerOptions} [https] - * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] - * @property {() => Promise} [app] - * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigArray} [proxy] - * @property {boolean | string | Open | Array} [open] - * @property {boolean} [setupExitSignals] - * @property {boolean | ClientConfiguration} [client] - * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] - * @property {(devServer: Server) => void} [onListening] - * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] - */ $ref: string; }; webSocketURL: { @@ -529,11 +201,7 @@ declare class Server< ClientProgress: { description: string; link: string; - type: string[] /** - * @typedef {Object} OpenApp - * @property {string} [name] - * @property {string[]} [arguments] - */; + type: string[]; enum: (string | boolean)[]; cli: { negatedDescription: string; @@ -567,43 +235,6 @@ declare class Server< ClientWebSocketTransportEnum: { enum: string[]; }; - /** - * @typedef {Array<{ key: string; value: string }> | Record} Headers - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {T extends ExpressApplication ? ExpressRequestHandler | ExpressErrorRequestHandler : HandleFunction} MiddlewareHandler - */ - /** - * @typedef {{ name?: string, path?: string, middleware: MiddlewareHandler } | MiddlewareHandler } Middleware - */ - /** - * @template {BasicApplication} [T=ExpressApplication] - * @typedef {Object} Configuration - * @property {boolean | string} [ipc] - * @property {Host} [host] - * @property {Port} [port] - * @property {boolean | "only"} [hot] - * @property {boolean} [liveReload] - * @property {DevMiddlewareOptions} [devMiddleware] - * @property {boolean} [compress] - * @property {"auto" | "all" | string | string[]} [allowedHosts] - * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] - * @property {boolean | Record | BonjourOptions} [bonjour] - * @property {string | string[] | WatchFiles | Array} [watchFiles] - * @property {boolean | string | Static | Array} [static] - * @property {boolean | ServerOptions} [https] - * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] - * @property {() => Promise} [app] - * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigArray} [proxy] - * @property {boolean | string | Open | Array} [open] - * @property {boolean} [setupExitSignals] - * @property {boolean | ClientConfiguration} [client] - * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] - * @property {(devServer: Server) => void} [onListening] - * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] - */ ClientWebSocketTransportString: { type: string; minLength: number; @@ -727,9 +358,6 @@ declare class Server< } )[]; description: string; - /** - * @template {BasicApplication} [T=ExpressApplication] - */ link: string; }; HistoryApiFallback: { @@ -832,10 +460,6 @@ declare class Server< items?: undefined; } )[]; - /** - * @param {Host} hostname - * @returns {Promise} - */ description: string; link: string; }; @@ -1011,7 +635,6 @@ declare class Server< requestCert: { type: string; description: string; - /** @type {ServerConfiguration} */ cli: { negatedDescription: string; }; @@ -1165,7 +788,7 @@ declare class Server< } | { type: string; - /** @type {string} */ additionalProperties: boolean; + additionalProperties: boolean; instanceof?: undefined; } )[]; @@ -1262,10 +885,7 @@ declare class Server< )[]; description: string; link: string; - } /** - * @private - * @returns {Compiler["options"]} - */; + }; serveIndex: { anyOf: ( | { @@ -1500,10 +1120,14 @@ declare class Server< */ static isAbsoluteURL(URL: string): boolean; /** - * @param {string} gateway + * @param {string} gatewayOrFamily or family + * @param {boolean} [isInternal=false] ip should be internal * @returns {string | undefined} */ - static findIp(gateway: string): string | undefined; + static findIp( + gatewayOrFamily: string, + isInternal?: boolean | undefined, + ): string | undefined; /** * @param {"v4" | "v6"} family * @returns {Promise} @@ -1846,17 +1470,11 @@ declare namespace Server { BasicApplication, }; } -type Compiler = import("webpack").Compiler; -type FSWatcher = import("chokidar").FSWatcher; -type Socket = import("net").Socket; -type WebSocketServerImplementation = { - implementation: WebSocketServer; - clients: ClientConnection[]; -}; declare class DEFAULT_STATS { private constructor(); } type Schema = import("schema-utils/declarations/validate").Schema; +type Compiler = import("webpack").Compiler; type MultiCompiler = import("webpack").MultiCompiler; type WebpackConfiguration = import("webpack").Configuration; type StatsOptions = import("webpack").StatsOptions; @@ -1865,6 +1483,7 @@ type Stats = import("webpack").Stats; type MultiStats = import("webpack").MultiStats; type NetworkInterfaceInfo = import("os").NetworkInterfaceInfo; type WatchOptions = import("chokidar").WatchOptions; +type FSWatcher = import("chokidar").FSWatcher; type ConnectHistoryApiFallbackOptions = import("connect-history-api-fallback").Options; type Bonjour = import("bonjour-service").Bonjour; @@ -1876,6 +1495,7 @@ type ServeIndexOptions = import("serve-index").Options; type ServeStaticOptions = import("serve-static").ServeStaticOptions; type IPv4 = import("ipaddr.js").IPv4; type IPv6 = import("ipaddr.js").IPv6; +type Socket = import("net").Socket; type IncomingMessage = import("http").IncomingMessage; type ServerResponse = import("http").ServerResponse; type OpenOptions = import("open").Options; @@ -1915,24 +1535,12 @@ type Request = type Response = T extends ExpressApplication ? ExpressResponse : ServerResponse; type DevMiddlewareOptions< - T extends import("express").Request< - import("express-serve-static-core").ParamsDictionary, - any, - any, - qs.ParsedQs, - Record - >, - U extends import("express").Response>, + T extends Request, + U extends Response, > = import("webpack-dev-middleware").Options; type DevMiddlewareContext< - T extends import("express").Request< - import("express-serve-static-core").ParamsDictionary, - any, - any, - qs.ParsedQs, - Record - >, - U extends import("express").Response>, + T extends Request, + U extends Response, > = import("webpack-dev-middleware").Context; type Host = "local-ip" | "local-ipv4" | "local-ipv6" | string; type Port = number | string | "auto"; @@ -1940,9 +1548,9 @@ type WatchFiles = { paths: string | string[]; options?: | (import("chokidar").WatchOptions & { - aggregateTimeout?: number | undefined; + aggregateTimeout?: number; ignored?: WatchOptions["ignored"]; - poll?: number | boolean | undefined; + poll?: number | boolean; }) | undefined; }; @@ -1958,9 +1566,9 @@ type Static = { watch?: | boolean | (import("chokidar").WatchOptions & { - aggregateTimeout?: number | undefined; + aggregateTimeout?: number; ignored?: WatchOptions["ignored"]; - poll?: number | boolean | undefined; + poll?: number | boolean; }) | undefined; }; @@ -1994,6 +1602,10 @@ type WebSocketServer = | (import("sockjs").Server & { close: import("ws").WebSocketServer["close"]; }); +type WebSocketServerImplementation = { + implementation: WebSocketServer; + clients: ClientConnection[]; +}; type ByPass = ( req: Request, res: Response, @@ -2039,9 +1651,9 @@ type ClientConfiguration = { overlay?: | boolean | { - warnings?: OverlayMessageOptions | undefined; - errors?: OverlayMessageOptions | undefined; - runtimeErrors?: OverlayMessageOptions | undefined; + warnings?: OverlayMessageOptions; + errors?: OverlayMessageOptions; + runtimeErrors?: OverlayMessageOptions; } | undefined; progress?: boolean | undefined; diff --git a/types/lib/servers/WebsocketServer.d.ts b/types/lib/servers/WebsocketServer.d.ts index 5a3880f09c..ce8c693789 100644 --- a/types/lib/servers/WebsocketServer.d.ts +++ b/types/lib/servers/WebsocketServer.d.ts @@ -1,4 +1,3 @@ -/// export = WebsocketServer; declare class WebsocketServer extends BaseServer { static heartbeatInterval: number;