From 34ec9910025a4232d709e74e9d126b5b02396478 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 14 Jul 2026 19:28:49 +0000 Subject: [PATCH 1/3] chore(deps): update dependency typescript to v7 --- package.json | 2 +- pnpm-lock.yaml | 225 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 214 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index c384353..b2fc1d8 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "range-parser": "^1.2.1", "router": "^2.2.0", "supertest": "^7.2.2", - "typescript": "^6.0.3" + "typescript": "^7.0.2" }, "peerDependencies": { "@rspack/core": "^2.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c50ce13..dba463b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ importers: version: 2.0.8(hono@4.12.25) '@rslib/core': specifier: ^0.22.1 - version: 0.22.1(typescript@6.0.3) + version: 0.22.1(typescript@7.0.2) '@rslint/core': specifier: ^0.6.1 version: 0.6.1 @@ -87,8 +87,8 @@ importers: specifier: ^7.2.2 version: 7.2.2 typescript: - specifier: ^6.0.3 - version: 6.0.3 + specifier: ^7.0.2 + version: 7.0.2 packages: @@ -842,6 +842,126 @@ packages: '@types/serve-static@2.2.0': resolution: {integrity: sha512-8mam4H1NHLtu7nmtalF7eyBH14QyOASmcxHhSfEoRyr0nP/YdoesEtU+uSRvMe96TW/HPTtkoKqQLl53N7UXMQ==} + '@typescript/typescript-aix-ppc64@7.0.2': + resolution: {integrity: sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==} + engines: {node: '>=16.20.0'} + cpu: [ppc64] + os: [aix] + + '@typescript/typescript-darwin-arm64@7.0.2': + resolution: {integrity: sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [darwin] + + '@typescript/typescript-darwin-x64@7.0.2': + resolution: {integrity: sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [darwin] + + '@typescript/typescript-freebsd-arm64@7.0.2': + resolution: {integrity: sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [freebsd] + + '@typescript/typescript-freebsd-x64@7.0.2': + resolution: {integrity: sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [freebsd] + + '@typescript/typescript-linux-arm64@7.0.2': + resolution: {integrity: sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [linux] + + '@typescript/typescript-linux-arm@7.0.2': + resolution: {integrity: sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==} + engines: {node: '>=16.20.0'} + cpu: [arm] + os: [linux] + + '@typescript/typescript-linux-loong64@7.0.2': + resolution: {integrity: sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==} + engines: {node: '>=16.20.0'} + cpu: [loong64] + os: [linux] + + '@typescript/typescript-linux-mips64el@7.0.2': + resolution: {integrity: sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==} + engines: {node: '>=16.20.0'} + cpu: [mips64el] + os: [linux] + + '@typescript/typescript-linux-ppc64@7.0.2': + resolution: {integrity: sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==} + engines: {node: '>=16.20.0'} + cpu: [ppc64] + os: [linux] + + '@typescript/typescript-linux-riscv64@7.0.2': + resolution: {integrity: sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==} + engines: {node: '>=16.20.0'} + cpu: [riscv64] + os: [linux] + + '@typescript/typescript-linux-s390x@7.0.2': + resolution: {integrity: sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==} + engines: {node: '>=16.20.0'} + cpu: [s390x] + os: [linux] + + '@typescript/typescript-linux-x64@7.0.2': + resolution: {integrity: sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [linux] + + '@typescript/typescript-netbsd-arm64@7.0.2': + resolution: {integrity: sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [netbsd] + + '@typescript/typescript-netbsd-x64@7.0.2': + resolution: {integrity: sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [netbsd] + + '@typescript/typescript-openbsd-arm64@7.0.2': + resolution: {integrity: sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [openbsd] + + '@typescript/typescript-openbsd-x64@7.0.2': + resolution: {integrity: sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [openbsd] + + '@typescript/typescript-sunos-x64@7.0.2': + resolution: {integrity: sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [sunos] + + '@typescript/typescript-win32-arm64@7.0.2': + resolution: {integrity: sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==} + engines: {node: '>=16.20.0'} + cpu: [arm64] + os: [win32] + + '@typescript/typescript-win32-x64@7.0.2': + resolution: {integrity: sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==} + engines: {node: '>=16.20.0'} + cpu: [x64] + os: [win32] + accepts@1.3.8: resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==} engines: {node: '>= 0.6'} @@ -1525,9 +1645,9 @@ packages: resolution: {integrity: sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==} engines: {node: '>= 0.6'} - typescript@6.0.3: - resolution: {integrity: sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==} - engines: {node: '>=14.17'} + typescript@7.0.2: + resolution: {integrity: sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==} + engines: {node: '>=16.20.0'} hasBin: true undici-types@7.16.0: @@ -2173,12 +2293,12 @@ snapshots: transitivePeerDependencies: - '@module-federation/runtime-tools' - '@rslib/core@0.22.1(typescript@6.0.3)': + '@rslib/core@0.22.1(typescript@7.0.2)': dependencies: '@rsbuild/core': 2.0.13 - rsbuild-plugin-dts: 0.22.1(@rsbuild/core@2.0.13)(typescript@6.0.3) + rsbuild-plugin-dts: 0.22.1(@rsbuild/core@2.0.13)(typescript@7.0.2) optionalDependencies: - typescript: 6.0.3 + typescript: 7.0.2 transitivePeerDependencies: - '@module-federation/runtime-tools' - '@typescript/native-preview' @@ -2363,6 +2483,66 @@ snapshots: '@types/http-errors': 2.0.5 '@types/node': 24.12.4 + '@typescript/typescript-aix-ppc64@7.0.2': + optional: true + + '@typescript/typescript-darwin-arm64@7.0.2': + optional: true + + '@typescript/typescript-darwin-x64@7.0.2': + optional: true + + '@typescript/typescript-freebsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-freebsd-x64@7.0.2': + optional: true + + '@typescript/typescript-linux-arm64@7.0.2': + optional: true + + '@typescript/typescript-linux-arm@7.0.2': + optional: true + + '@typescript/typescript-linux-loong64@7.0.2': + optional: true + + '@typescript/typescript-linux-mips64el@7.0.2': + optional: true + + '@typescript/typescript-linux-ppc64@7.0.2': + optional: true + + '@typescript/typescript-linux-riscv64@7.0.2': + optional: true + + '@typescript/typescript-linux-s390x@7.0.2': + optional: true + + '@typescript/typescript-linux-x64@7.0.2': + optional: true + + '@typescript/typescript-netbsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-netbsd-x64@7.0.2': + optional: true + + '@typescript/typescript-openbsd-arm64@7.0.2': + optional: true + + '@typescript/typescript-openbsd-x64@7.0.2': + optional: true + + '@typescript/typescript-sunos-x64@7.0.2': + optional: true + + '@typescript/typescript-win32-arm64@7.0.2': + optional: true + + '@typescript/typescript-win32-x64@7.0.2': + optional: true + accepts@1.3.8: dependencies: mime-types: 2.1.35 @@ -2959,12 +3139,12 @@ snapshots: transitivePeerDependencies: - supports-color - rsbuild-plugin-dts@0.22.1(@rsbuild/core@2.0.13)(typescript@6.0.3): + rsbuild-plugin-dts@0.22.1(@rsbuild/core@2.0.13)(typescript@7.0.2): dependencies: '@ast-grep/napi': 0.37.0 '@rsbuild/core': 2.0.13 optionalDependencies: - typescript: 6.0.3 + typescript: 7.0.2 safer-buffer@2.1.2: {} @@ -3090,7 +3270,28 @@ snapshots: media-typer: 1.1.0 mime-types: 3.0.2 - typescript@6.0.3: {} + typescript@7.0.2: + optionalDependencies: + '@typescript/typescript-aix-ppc64': 7.0.2 + '@typescript/typescript-darwin-arm64': 7.0.2 + '@typescript/typescript-darwin-x64': 7.0.2 + '@typescript/typescript-freebsd-arm64': 7.0.2 + '@typescript/typescript-freebsd-x64': 7.0.2 + '@typescript/typescript-linux-arm': 7.0.2 + '@typescript/typescript-linux-arm64': 7.0.2 + '@typescript/typescript-linux-loong64': 7.0.2 + '@typescript/typescript-linux-mips64el': 7.0.2 + '@typescript/typescript-linux-ppc64': 7.0.2 + '@typescript/typescript-linux-riscv64': 7.0.2 + '@typescript/typescript-linux-s390x': 7.0.2 + '@typescript/typescript-linux-x64': 7.0.2 + '@typescript/typescript-netbsd-arm64': 7.0.2 + '@typescript/typescript-netbsd-x64': 7.0.2 + '@typescript/typescript-openbsd-arm64': 7.0.2 + '@typescript/typescript-openbsd-x64': 7.0.2 + '@typescript/typescript-sunos-x64': 7.0.2 + '@typescript/typescript-win32-arm64': 7.0.2 + '@typescript/typescript-win32-x64': 7.0.2 undici-types@7.16.0: {} From c1ed9a8764ff6104c289e0e44df24bd414479c0b Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 17 Jul 2026 20:08:25 +0800 Subject: [PATCH 2/3] fix: support TypeScript 7 --- src/index.js | 2 +- src/utils/compatibleAPI.js | 2 +- types/index.d.ts | 389 +++++++++++-------------- types/middleware.d.ts | 29 +- types/utils/compatibleAPI.d.ts | 187 ++++++------ types/utils/escapeHtml.d.ts | 2 +- types/utils/etag.d.ts | 2 +- types/utils/getFilenameFromUrl.d.ts | 15 +- types/utils/getPaths.d.ts | 18 +- types/utils/memorize.d.ts | 5 +- types/utils/parseTokenList.d.ts | 2 +- types/utils/ready.d.ts | 8 +- types/utils/setupHooks.d.ts | 16 +- types/utils/setupOutputFileSystem.d.ts | 2 +- types/utils/setupWriteToDisk.d.ts | 2 +- 15 files changed, 322 insertions(+), 359 deletions(-) diff --git a/src/index.js b/src/index.js index 2fe1d5c..839612e 100644 --- a/src/index.js +++ b/src/index.js @@ -52,7 +52,7 @@ const noop = () => {}; */ /** - * @typedef {import("@rspack/core").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem + * @typedef {import("@rspack/core").OutputFileSystem & { createReadStream?: typeof import("fs").createReadStream, statSync: typeof import("fs").statSync, readFileSync: typeof import("fs").readFileSync }} OutputFileSystem */ /** @typedef {ReturnType} Logger */ diff --git a/src/utils/compatibleAPI.js b/src/utils/compatibleAPI.js index 92bdafc..2800981 100644 --- a/src/utils/compatibleAPI.js +++ b/src/utils/compatibleAPI.js @@ -237,7 +237,7 @@ function createReadStreamOrReadFileSync( if (isFsSupportsStream) { bufferOrStream = - /** @type {import("fs").createReadStream} */ + /** @type {typeof import("fs").createReadStream} */ (outputFileSystem.createReadStream)(filename, { start, end, diff --git a/types/index.d.ts b/types/index.d.ts index 805b429..4d8f778 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,173 +1,3 @@ -/** @typedef {import("@rspack/core").Compiler} Compiler */ -/** @typedef {import("@rspack/core").MultiCompiler} MultiCompiler */ -/** @typedef {import("@rspack/core").Configuration} Configuration */ -/** @typedef {import("@rspack/core").Stats} Stats */ -/** @typedef {import("@rspack/core").MultiStats} MultiStats */ -/** @typedef {import("fs").ReadStream} ReadStream */ -/** - * @typedef {object} ExtendedServerResponse - * @property {{ rspack?: { devMiddleware?: Context }, webpack?: { devMiddleware?: Context } }=} locals locals - */ -/** @typedef {import("http").IncomingMessage} IncomingMessage */ -/** @typedef {import("http").ServerResponse & ExtendedServerResponse} ServerResponse */ -/** @typedef {any} EXPECTED_ANY */ -/** @typedef {Function} EXPECTED_FUNCTION */ -/** - * @callback NextFunction - * @param {EXPECTED_ANY=} err error - * @returns {void} - */ -/** - * @typedef {NonNullable} WatchOptions - */ -/** - * @typedef {boolean | Configuration["devServer"] | undefined} DevServerOption - */ -/** - * @typedef {Compiler["watching"]} Watching - */ -/** - * @typedef {ReturnType} MultiWatching - */ -/** - * @typedef {import("@rspack/core").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem - */ -/** @typedef {ReturnType} Logger */ -/** @typedef {{ close(callback: (err?: Error | null | undefined) => void): void }} ClosableWatching */ -/** - * @callback Callback - * @param {(Stats | MultiStats)=} stats - */ -/** - * @typedef {object} ResponseData - * @property {Buffer | ReadStream} data data - * @property {number} byteLength byte length - */ -/** - * @template {IncomingMessage} [RequestInternal=IncomingMessage] - * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @callback ModifyResponseData - * @param {RequestInternal} req req - * @param {ResponseInternal} res res - * @param {Buffer | ReadStream} data data - * @param {number} byteLength byte length - * @returns {ResponseData} - */ -/** - * @template {IncomingMessage} [RequestInternal=IncomingMessage] - * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @typedef {object} Context - * @property {boolean} state state - * @property {Stats | MultiStats | undefined} stats stats - * @property {Callback[]} callbacks callbacks - * @property {Options} options options - * @property {Compiler | MultiCompiler} compiler compiler - * @property {Watching | MultiWatching | undefined} watching watching - * @property {Logger} logger logger - * @property {OutputFileSystem} outputFileSystem output file system - */ -/** - * @template {IncomingMessage} [RequestInternal=IncomingMessage] - * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @typedef {WithoutUndefined, "watching">} FilledContext - */ -/** @typedef {Record | { key: string, value: number | string }[]} NormalizedHeaders */ -/** - * @template {IncomingMessage} [RequestInternal=IncomingMessage] - * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context) => void | undefined | NormalizedHeaders) | undefined} Headers - */ -/** - * @template {IncomingMessage} [RequestInternal = IncomingMessage] - * @template {ServerResponse} [ResponseInternal = ServerResponse] - * @typedef {object} Options - * @property {{ [key: string]: string }=} mimeTypes mime types - * @property {(string | undefined)=} mimeTypeDefault mime type default - * @property {(boolean | ((targetPath: string) => boolean))=} writeToDisk write to disk - * @property {string[]=} methods methods - * @property {Headers=} headers headers - * @property {NonNullable["publicPath"]=} publicPath public path - * @property {Configuration["stats"]=} stats stats - * @property {boolean=} serverSideRender is server side render - * @property {OutputFileSystem=} outputFileSystem output file system - * @property {(boolean | string)=} index index - * @property {ModifyResponseData=} modifyResponseData modify response data - * @property {"weak" | "strong"=} etag options to generate etag header - * @property {boolean=} lastModified options to generate last modified header - * @property {(boolean | number | string | { maxAge?: number, immutable?: boolean })=} cacheControl options to generate cache headers - * @property {boolean=} cacheImmutable enable immutable cache headers for immutable assets (defaults to false when omitted) - */ -/** - * @template {IncomingMessage} [RequestInternal=IncomingMessage] - * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @callback Middleware - * @param {RequestInternal} req request - * @param {ResponseInternal} res response - * @param {NextFunction} next next function - * @returns {Promise} - */ -/** @typedef {import("./utils/getFilenameFromUrl.js").Extra} Extra */ -/** - * @callback GetFilenameFromUrl - * @param {string} url request URL - * @returns {{ filename: string, extra: Extra } | undefined} a filename with additional information, or `undefined` if nothing is found - */ -/** - * @callback WaitUntilValid - * @param {Callback} callback - */ -/** - * @callback Invalidate - * @param {Callback} callback - */ -/** - * @callback Close - * @param {(err: Error | null | undefined) => void} callback - */ -/** - * @template {IncomingMessage} RequestInternal - * @template {ServerResponse} ResponseInternal - * @typedef {object} AdditionalMethods - * @property {GetFilenameFromUrl} getFilenameFromUrl get filename from url - * @property {WaitUntilValid} waitUntilValid wait until valid - * @property {Invalidate} invalidate invalidate - * @property {Close} close close - * @property {Context} context context - */ -/** - * @template {IncomingMessage} [RequestInternal=IncomingMessage] - * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @typedef {Middleware & AdditionalMethods} API - */ -/** - * @template T - * @template {keyof T} K - * @typedef {Omit & Partial} WithOptional - */ -/** - * @template T - * @template {keyof T} K - * @typedef {T & { [P in K]: NonNullable }} WithoutUndefined - */ -/** - * @template {IncomingMessage} [RequestInternal=IncomingMessage] - * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @param {Compiler | MultiCompiler} compiler compiler - * @param {Options=} options options - * @returns {API} rspack dev middleware - */ -export function devMiddleware< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, - ResponseInternal extends ServerResponse = ServerResponse, ->( - compiler: Compiler | MultiCompiler, - options?: Options | undefined, -): API; -export namespace devMiddleware { - export { hapiWrapper }; - export { koaWrapper }; - export { honoWrapper }; -} export type Compiler = import("@rspack/core").Compiler; export type MultiCompiler = import("@rspack/core").MultiCompiler; export type Configuration = import("@rspack/core").Configuration; @@ -201,7 +31,7 @@ export type Watching = Compiler["watching"]; export type MultiWatching = ReturnType; export type OutputFileSystem = import("@rspack/core").OutputFileSystem & { createReadStream?: typeof import("fs").createReadStream; - statSync: import("fs").StatSyncFn; + statSync: typeof import("fs").statSync; readFileSync: typeof import("fs").readFileSync; }; export type Logger = ReturnType; @@ -220,7 +50,7 @@ export type ResponseData = { byteLength: number; }; export type ModifyResponseData< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = ( req: RequestInternal, @@ -229,7 +59,7 @@ export type ModifyResponseData< byteLength: number, ) => ResponseData; export type Context< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = { /** @@ -266,7 +96,7 @@ export type Context< outputFileSystem: OutputFileSystem; }; export type FilledContext< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = WithoutUndefined, "watching">; export type NormalizedHeaders = @@ -276,7 +106,7 @@ export type NormalizedHeaders = value: number | string; }[]; export type Headers< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = | NormalizedHeaders @@ -287,7 +117,7 @@ export type Headers< ) => void | undefined | NormalizedHeaders) | undefined; export type Options< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = { /** @@ -368,7 +198,7 @@ export type Options< cacheImmutable?: boolean | undefined; }; export type Middleware< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = ( req: RequestInternal, @@ -411,7 +241,7 @@ export type AdditionalMethods< context: Context; }; export type API< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = Middleware & AdditionalMethods; @@ -419,70 +249,185 @@ export type WithOptional = Omit & Partial; export type WithoutUndefined = T & { [P in K]: NonNullable; }; -export type HapiPluginBase = { - /** - * register - */ - register: (server: S, options: O) => void | Promise; -}; -export type HapiPlugin = HapiPluginBase & { - pkg: { - name: string; - }; - multiple: boolean; -}; -export type HapiOptions = Options & { - compiler: Compiler | MultiCompiler; -}; +/** @typedef {import("@rspack/core").Compiler} Compiler */ +/** @typedef {import("@rspack/core").MultiCompiler} MultiCompiler */ +/** @typedef {import("@rspack/core").Configuration} Configuration */ +/** @typedef {import("@rspack/core").Stats} Stats */ +/** @typedef {import("@rspack/core").MultiStats} MultiStats */ +/** @typedef {import("fs").ReadStream} ReadStream */ /** - * @template S - * @template O - * @typedef {object} HapiPluginBase - * @property {(server: S, options: O) => void | Promise} register register + * @typedef {object} ExtendedServerResponse + * @property {{ rspack?: { devMiddleware?: Context }, webpack?: { devMiddleware?: Context } }=} locals locals */ +/** @typedef {import("http").IncomingMessage} IncomingMessage */ +/** @typedef {import("http").ServerResponse & ExtendedServerResponse} ServerResponse */ +/** @typedef {any} EXPECTED_ANY */ +/** @typedef {Function} EXPECTED_FUNCTION */ /** - * @template S - * @template O - * @typedef {HapiPluginBase & { pkg: { name: string }, multiple: boolean }} HapiPlugin + * @callback NextFunction + * @param {EXPECTED_ANY=} err error + * @returns {void} + */ +/** + * @typedef {NonNullable} WatchOptions */ /** - * @typedef {Options & { compiler: Compiler | MultiCompiler }} HapiOptions + * @typedef {boolean | Configuration["devServer"] | undefined} DevServerOption */ /** - * @template HapiServer - * @template {HapiOptions} HapiOptionsInternal - * @returns {HapiPlugin} hapi wrapper + * @typedef {Compiler["watching"]} Watching + */ +/** + * @typedef {ReturnType} MultiWatching + */ +/** + * @typedef {import("@rspack/core").OutputFileSystem & { createReadStream?: typeof import("fs").createReadStream, statSync: typeof import("fs").statSync, readFileSync: typeof import("fs").readFileSync }} OutputFileSystem + */ +/** @typedef {ReturnType} Logger */ +/** @typedef {{ close(callback: (err?: Error | null | undefined) => void): void }} ClosableWatching */ +/** + * @callback Callback + * @param {(Stats | MultiStats)=} stats + */ +/** + * @typedef {object} ResponseData + * @property {Buffer | ReadStream} data data + * @property {number} byteLength byte length */ -declare function hapiWrapper< - HapiServer, - HapiOptionsInternal extends HapiOptions, ->(): HapiPlugin; /** * @template {IncomingMessage} [RequestInternal=IncomingMessage] * @template {ServerResponse} [ResponseInternal=ServerResponse] - * @param {Compiler | MultiCompiler} compiler compiler - * @param {Options=} options options - * @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void} kow wrapper + * @callback ModifyResponseData + * @param {RequestInternal} req req + * @param {ResponseInternal} res res + * @param {Buffer | ReadStream} data data + * @param {number} byteLength byte length + * @returns {ResponseData} + */ +/** + * @template {IncomingMessage} [RequestInternal=IncomingMessage] + * @template {ServerResponse} [ResponseInternal=ServerResponse] + * @typedef {object} Context + * @property {boolean} state state + * @property {Stats | MultiStats | undefined} stats stats + * @property {Callback[]} callbacks callbacks + * @property {Options} options options + * @property {Compiler | MultiCompiler} compiler compiler + * @property {Watching | MultiWatching | undefined} watching watching + * @property {Logger} logger logger + * @property {OutputFileSystem} outputFileSystem output file system + */ +/** + * @template {IncomingMessage} [RequestInternal=IncomingMessage] + * @template {ServerResponse} [ResponseInternal=ServerResponse] + * @typedef {WithoutUndefined, "watching">} FilledContext + */ +/** @typedef {Record | { key: string, value: number | string }[]} NormalizedHeaders */ +/** + * @template {IncomingMessage} [RequestInternal=IncomingMessage] + * @template {ServerResponse} [ResponseInternal=ServerResponse] + * @typedef {NormalizedHeaders | ((req: RequestInternal, res: ResponseInternal, context: Context) => void | undefined | NormalizedHeaders) | undefined} Headers + */ +/** + * @template {IncomingMessage} [RequestInternal = IncomingMessage] + * @template {ServerResponse} [ResponseInternal = ServerResponse] + * @typedef {object} Options + * @property {{ [key: string]: string }=} mimeTypes mime types + * @property {(string | undefined)=} mimeTypeDefault mime type default + * @property {(boolean | ((targetPath: string) => boolean))=} writeToDisk write to disk + * @property {string[]=} methods methods + * @property {Headers=} headers headers + * @property {NonNullable["publicPath"]=} publicPath public path + * @property {Configuration["stats"]=} stats stats + * @property {boolean=} serverSideRender is server side render + * @property {OutputFileSystem=} outputFileSystem output file system + * @property {(boolean | string)=} index index + * @property {ModifyResponseData=} modifyResponseData modify response data + * @property {"weak" | "strong"=} etag options to generate etag header + * @property {boolean=} lastModified options to generate last modified header + * @property {(boolean | number | string | { maxAge?: number, immutable?: boolean })=} cacheControl options to generate cache headers + * @property {boolean=} cacheImmutable enable immutable cache headers for immutable assets (defaults to false when omitted) + */ +/** + * @template {IncomingMessage} [RequestInternal=IncomingMessage] + * @template {ServerResponse} [ResponseInternal=ServerResponse] + * @callback Middleware + * @param {RequestInternal} req request + * @param {ResponseInternal} res response + * @param {NextFunction} next next function + * @returns {Promise} + */ +/** @typedef {import("./utils/getFilenameFromUrl.js").Extra} Extra */ +/** + * @callback GetFilenameFromUrl + * @param {string} url request URL + * @returns {{ filename: string, extra: Extra } | undefined} a filename with additional information, or `undefined` if nothing is found + */ +/** + * @callback WaitUntilValid + * @param {Callback} callback + */ +/** + * @callback Invalidate + * @param {Callback} callback + */ +/** + * @callback Close + * @param {(err: Error | null | undefined) => void} callback + */ +/** + * @template {IncomingMessage} RequestInternal + * @template {ServerResponse} ResponseInternal + * @typedef {object} AdditionalMethods + * @property {GetFilenameFromUrl} getFilenameFromUrl get filename from url + * @property {WaitUntilValid} waitUntilValid wait until valid + * @property {Invalidate} invalidate invalidate + * @property {Close} close close + * @property {Context} context context + */ +/** + * @template {IncomingMessage} [RequestInternal=IncomingMessage] + * @template {ServerResponse} [ResponseInternal=ServerResponse] + * @typedef {Middleware & AdditionalMethods} API + */ +/** + * @template T + * @template {keyof T} K + * @typedef {Omit & Partial} WithOptional + */ +/** + * @template T + * @template {keyof T} K + * @typedef {T & { [P in K]: NonNullable }} WithoutUndefined */ -declare function koaWrapper< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, - ResponseInternal extends ServerResponse = ServerResponse, ->( - compiler: Compiler | MultiCompiler, - options?: Options | undefined, -): (ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void; /** * @template {IncomingMessage} [RequestInternal=IncomingMessage] * @template {ServerResponse} [ResponseInternal=ServerResponse] * @param {Compiler | MultiCompiler} compiler compiler * @param {Options=} options options - * @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void} hono wrapper + * @returns {API} rspack dev middleware */ -declare function honoWrapper< - RequestInternal extends IncomingMessage = import("http").IncomingMessage, +declare function rdm< + RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, >( compiler: Compiler | MultiCompiler, options?: Options | undefined, -): (ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void; +): API; +export type HapiPluginBase = { + /** + * register + */ + register: (server: S, options: O) => void | Promise; +}; +export type HapiPlugin = HapiPluginBase & { + pkg: { + name: string; + }; + multiple: boolean; +}; +export type HapiOptions = Options & { + compiler: Compiler | MultiCompiler; +}; +export declare const devMiddleware: typeof rdm; export {}; diff --git a/types/middleware.d.ts b/types/middleware.d.ts index 55ecdf1..b49c150 100644 --- a/types/middleware.d.ts +++ b/types/middleware.d.ts @@ -1,7 +1,15 @@ -export default wrapper; -/** - * send error options - */ +export type NextFunction = import("./index.js").NextFunction; +export type IncomingMessage = import("./index.js").IncomingMessage; +export type ServerResponse = import("./index.js").ServerResponse; +export type NormalizedHeaders = import("./index.js").NormalizedHeaders; +export type FilenameError = + import("./utils/getFilenameFromUrl.js").FilenameError; +export type Extra = import("./utils/getFilenameFromUrl.js").Extra; +export type ReadStream = import("fs").ReadStream; +export type FilenameWithExtra = { + filename: string; + extra: Extra; +}; export type SendErrorOptions< Request extends IncomingMessage, Response extends ServerResponse, @@ -17,18 +25,6 @@ export type SendErrorOptions< | import("./index.js").ModifyResponseData | undefined; }; -export type NextFunction = import("./index.js").NextFunction; -export type IncomingMessage = import("./index.js").IncomingMessage; -export type ServerResponse = import("./index.js").ServerResponse; -export type NormalizedHeaders = import("./index.js").NormalizedHeaders; -export type FilenameError = - import("./utils/getFilenameFromUrl.js").FilenameError; -export type Extra = import("./utils/getFilenameFromUrl.js").Extra; -export type ReadStream = import("fs").ReadStream; -export type FilenameWithExtra = { - filename: string; - extra: Extra; -}; /** * @template {IncomingMessage} Request * @template {ServerResponse} Response @@ -48,3 +44,4 @@ declare function wrapper< >( context: import("./index.js").FilledContext, ): import("./index.js").Middleware; +export default wrapper; diff --git a/types/utils/compatibleAPI.d.ts b/types/utils/compatibleAPI.d.ts index 45e8bab..01c077e 100644 --- a/types/utils/compatibleAPI.d.ts +++ b/types/utils/compatibleAPI.d.ts @@ -1,3 +1,7 @@ +/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ +/** @typedef {import("../index.js").ServerResponse} ServerResponse */ +/** @typedef {import("../index.js").OutputFileSystem} OutputFileSystem */ +/** @typedef {import("../index.js").EXPECTED_ANY} EXPECTED_ANY */ export type IncomingMessage = import("../index.js").IncomingMessage; export type ServerResponse = import("../index.js").ServerResponse; export type OutputFileSystem = import("../index.js").OutputFileSystem; @@ -71,50 +75,6 @@ export type ExpectedServerResponse = { */ setState?: ((name: string, value: EXPECTED_ANY) => void) | undefined; }; -/** - * @param {string} filename filename - * @param {OutputFileSystem} outputFileSystem output file system - * @param {number} start start - * @param {number} end end - * @returns {{ bufferOrStream: (Buffer | import("fs").ReadStream), byteLength: number }} result with buffer or stream and byte length - */ -export function createReadStreamOrReadFileSync( - filename: string, - outputFileSystem: OutputFileSystem, - start: number, - end: number, -): { - bufferOrStream: Buffer | import("fs").ReadStream; - byteLength: number; -}; -/** - * @template {ServerResponse & ExpectedServerResponse} Response - * @param {Response} res res - * @param {(string | Buffer)=} data data - */ -export function finish< - Response extends ServerResponse & ExpectedServerResponse, ->(res: Response, data?: (string | Buffer) | undefined): void; -/** - * @template {ServerResponse & ExpectedServerResponse} Response - * @param {Response} res res - * @returns {boolean} true when headers were sent, otherwise false - */ -export function getHeadersSent< - Response extends ServerResponse & ExpectedServerResponse, ->(res: Response): boolean; -/** - * @template {ServerResponse & ExpectedServerResponse} Response - * @param {Response} res res - * @returns {Response} res res - */ -export function getOutgoing< - Response extends ServerResponse & ExpectedServerResponse, ->(res: Response): Response; -/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ -/** @typedef {import("../index.js").ServerResponse} ServerResponse */ -/** @typedef {import("../index.js").OutputFileSystem} OutputFileSystem */ -/** @typedef {import("../index.js").EXPECTED_ANY} EXPECTED_ANY */ /** * @typedef {object} ExpectedIncomingMessage * @property {((name: string) => string | string[] | undefined)=} getHeader get header extra method @@ -142,7 +102,7 @@ export function getOutgoing< * @param {string} name name * @returns {string | string[] | undefined} request header */ -export function getRequestHeader< +declare function getRequestHeader< Request extends IncomingMessage & ExpectedIncomingMessage, >(req: Request, name: string): string | string[] | undefined; /** @@ -150,7 +110,7 @@ export function getRequestHeader< * @param {Request} req req * @returns {string | undefined} request method */ -export function getRequestMethod< +declare function getRequestMethod< Request extends IncomingMessage & ExpectedIncomingMessage, >(req: Request): string | undefined; /** @@ -158,99 +118,158 @@ export function getRequestMethod< * @param {Request} req req * @returns {string | undefined} request URL */ -export function getRequestURL< +declare function getRequestURL< Request extends IncomingMessage & ExpectedIncomingMessage, >(req: Request): string | undefined; +/** + * @template {ServerResponse & ExpectedServerResponse} Response + * @param {Response} res res + * @param {number} code code + * @returns {void} + */ +declare function setStatusCode< + Response extends ServerResponse & ExpectedServerResponse, +>(res: Response, code: number): void; +/** + * @template {ServerResponse & ExpectedServerResponse} Response + * @param {Response} res res + * @returns {number} status code + */ +declare function getStatusCode< + Response extends ServerResponse & ExpectedServerResponse, +>(res: Response): number; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res * @param {string} name name * @returns {string | string[] | undefined | number} header */ -export function getResponseHeader< +declare function getResponseHeader< Response extends ServerResponse & ExpectedServerResponse, >(res: Response, name: string): string | string[] | undefined | number; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res - * @returns {string[]} header names + * @param {string} name name + * @param {number | string | Readonly} value value + * @returns {Response} response */ -export function getResponseHeaders< +declare function setResponseHeader< Response extends ServerResponse & ExpectedServerResponse, ->(res: Response): string[]; +>( + res: Response, + name: string, + value: number | string | Readonly, +): Response; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res - * @returns {number} status code + * @param {string} name name + * @returns {void} */ -export function getStatusCode< +declare function removeResponseHeader< Response extends ServerResponse & ExpectedServerResponse, ->(res: Response): number; +>(res: Response, name: string): void; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res + * @returns {string[]} header names */ -export function initState< +declare function getResponseHeaders< Response extends ServerResponse & ExpectedServerResponse, ->(res: Response): void; +>(res: Response): string[]; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res - * @param {import("fs").ReadStream} bufferOrStream buffer or stream + * @returns {boolean} true when headers were sent, otherwise false */ -export function pipe( - res: Response, - bufferOrStream: import("fs").ReadStream, -): void; +declare function getHeadersSent< + Response extends ServerResponse & ExpectedServerResponse, +>(res: Response): boolean; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res - * @param {string} name name - * @returns {void} + * @param {import("fs").ReadStream} bufferOrStream buffer or stream */ -export function removeResponseHeader< - Response extends ServerResponse & ExpectedServerResponse, ->(res: Response, name: string): void; +declare function pipe( + res: Response, + bufferOrStream: import("fs").ReadStream, +): void; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res * @param {string | Buffer} bufferOrString buffer or string * @returns {void} */ -export function send( +declare function send( res: Response, bufferOrString: string | Buffer, ): void; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res - * @param {string} name name - * @param {number | string | Readonly} value value - * @returns {Response} response + * @param {(string | Buffer)=} data data */ -export function setResponseHeader< +declare function finish< Response extends ServerResponse & ExpectedServerResponse, ->( - res: Response, - name: string, - value: number | string | Readonly, -): Response; +>(res: Response, data?: (string | Buffer) | undefined): void; +/** + * @param {string} filename filename + * @param {OutputFileSystem} outputFileSystem output file system + * @param {number} start start + * @param {number} end end + * @returns {{ bufferOrStream: (Buffer | import("fs").ReadStream), byteLength: number }} result with buffer or stream and byte length + */ +declare function createReadStreamOrReadFileSync( + filename: string, + outputFileSystem: OutputFileSystem, + start: number, + end: number, +): { + bufferOrStream: Buffer | import("fs").ReadStream; + byteLength: number; +}; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res - * @param {string} name name - * @param {EXPECTED_ANY} value state - * @returns {void} + * @returns {Response} res res */ -export function setState< +declare function getOutgoing< Response extends ServerResponse & ExpectedServerResponse, ->(res: Response, name: string, value: EXPECTED_ANY): void; +>(res: Response): Response; /** * @template {ServerResponse & ExpectedServerResponse} Response * @param {Response} res res - * @param {number} code code + */ +declare function initState< + Response extends ServerResponse & ExpectedServerResponse, +>(res: Response): void; +/** + * @template {ServerResponse & ExpectedServerResponse} Response + * @param {Response} res res + * @param {string} name name + * @param {EXPECTED_ANY} value state * @returns {void} */ -export function setStatusCode< +declare function setState< Response extends ServerResponse & ExpectedServerResponse, ->(res: Response, code: number): void; +>(res: Response, name: string, value: EXPECTED_ANY): void; +export { + createReadStreamOrReadFileSync, + finish, + getHeadersSent, + getOutgoing, + getRequestHeader, + getRequestMethod, + getRequestURL, + getResponseHeader, + getResponseHeaders, + getStatusCode, + initState, + pipe, + removeResponseHeader, + send, + setResponseHeader, + setState, + setStatusCode, +}; diff --git a/types/utils/escapeHtml.d.ts b/types/utils/escapeHtml.d.ts index 57b074b..22a35fc 100644 --- a/types/utils/escapeHtml.d.ts +++ b/types/utils/escapeHtml.d.ts @@ -1,6 +1,6 @@ -export default escapeHtml; /** * @param {string} string raw HTML * @returns {string} escaped HTML */ declare function escapeHtml(string: string): string; +export default escapeHtml; diff --git a/types/utils/etag.d.ts b/types/utils/etag.d.ts index a333e9a..6291870 100644 --- a/types/utils/etag.d.ts +++ b/types/utils/etag.d.ts @@ -1,4 +1,3 @@ -export default etag; export type Stats = import("fs").Stats; export type ReadStream = import("fs").ReadStream; /** @@ -10,3 +9,4 @@ declare function etag(entity: Buffer | ReadStream | Stats): Promise<{ hash: string; buffer?: Buffer; }>; +export default etag; diff --git a/types/utils/getFilenameFromUrl.d.ts b/types/utils/getFilenameFromUrl.d.ts index 82988b3..4f468db 100644 --- a/types/utils/getFilenameFromUrl.d.ts +++ b/types/utils/getFilenameFromUrl.d.ts @@ -1,12 +1,7 @@ -export default getFilenameFromUrl; export type IncomingMessage = import("../index.js").IncomingMessage; export type OutputFileSystem = import("../index.js").OutputFileSystem; export type ServerResponse = import("../index.js").ServerResponse; export type FSStats = import("fs").Stats; -export type FilenameWithExtra = { - filename: string; - extra: Extra; -}; export type Extra = { /** * stats @@ -34,14 +29,18 @@ export type Extra = { * @param {string} input * @returns {string} */ -export class FilenameError extends Error { +declare class FilenameError extends Error { + statusCode: number | undefined; /** * @param {string} message message * @param {number=} code error code */ constructor(message: string, code?: number | undefined); - statusCode: number | undefined; } +export type FilenameWithExtra = { + filename: string; + extra: Extra; +}; /** * @template {IncomingMessage} Request * @template {ServerResponse} Response @@ -56,3 +55,5 @@ declare function getFilenameFromUrl< context: import("../index.js").FilledContext, url: string, ): FilenameWithExtra | undefined; +export { FilenameError }; +export default getFilenameFromUrl; diff --git a/types/utils/getPaths.d.ts b/types/utils/getPaths.d.ts index 8fbe8fb..12d4f15 100644 --- a/types/utils/getPaths.d.ts +++ b/types/utils/getPaths.d.ts @@ -1,12 +1,3 @@ -export default getPaths; -export type Compiler = import("@rspack/core").Compiler; -export type Compilation = import("@rspack/core").Compilation; -export type Stats = import("@rspack/core").Stats; -export type MultiStats = import("@rspack/core").MultiStats; -export type DevServerOption = import("../index.js").DevServerOption; -export type IncomingMessage = import("../index.js").IncomingMessage; -export type OutputFileSystem = import("../index.js").OutputFileSystem; -export type ServerResponse = import("../index.js").ServerResponse; /** @typedef {import("@rspack/core").Compiler} Compiler */ /** @typedef {import("@rspack/core").Compilation} Compilation */ /** @typedef {import("@rspack/core").Stats} Stats */ @@ -15,6 +6,14 @@ export type ServerResponse = import("../index.js").ServerResponse; /** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ /** @typedef {import("../index.js").OutputFileSystem} OutputFileSystem */ /** @typedef {import("../index.js").ServerResponse} ServerResponse */ +export type Compiler = import("@rspack/core").Compiler; +export type Compilation = import("@rspack/core").Compilation; +export type Stats = import("@rspack/core").Stats; +export type MultiStats = import("@rspack/core").MultiStats; +export type DevServerOption = import("../index.js").DevServerOption; +export type IncomingMessage = import("../index.js").IncomingMessage; +export type OutputFileSystem = import("../index.js").OutputFileSystem; +export type ServerResponse = import("../index.js").ServerResponse; /** * @template {IncomingMessage} Request * @template {ServerResponse} Response @@ -32,3 +31,4 @@ declare function getPaths< outputFileSystem: OutputFileSystem; publicPath: string; }[]; +export default getPaths; diff --git a/types/utils/memorize.d.ts b/types/utils/memorize.d.ts index 77ab748..06b8369 100644 --- a/types/utils/memorize.d.ts +++ b/types/utils/memorize.d.ts @@ -1,6 +1,6 @@ -export default memorize; -export type FunctionReturning = (...args: EXPECTED_ANY) => T; +/** @typedef {import("../index.js").EXPECTED_ANY} EXPECTED_ANY */ export type EXPECTED_ANY = import("../index.js").EXPECTED_ANY; +export type FunctionReturning = (...args: EXPECTED_ANY) => T; /** * @template T * @typedef {(...args: EXPECTED_ANY) => T} FunctionReturning @@ -31,3 +31,4 @@ declare function memorize( | undefined, callback?: ((value: T) => T) | undefined, ): FunctionReturning; +export default memorize; diff --git a/types/utils/parseTokenList.d.ts b/types/utils/parseTokenList.d.ts index b14cf2f..9013667 100644 --- a/types/utils/parseTokenList.d.ts +++ b/types/utils/parseTokenList.d.ts @@ -1,7 +1,7 @@ -export default parseTokenList; /** * Parse a HTTP token list. * @param {string} str str * @returns {string[]} tokens */ declare function parseTokenList(str: string): string[]; +export default parseTokenList; diff --git a/types/utils/ready.d.ts b/types/utils/ready.d.ts index 69d45f2..9e20444 100644 --- a/types/utils/ready.d.ts +++ b/types/utils/ready.d.ts @@ -1,10 +1,9 @@ -export default ready; -export type IncomingMessage = import("../index.js").IncomingMessage; -export type ServerResponse = import("../index.js").ServerResponse; -export type Callback = import("../index.js").Callback; /** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ /** @typedef {import("../index.js").ServerResponse} ServerResponse */ /** @typedef {import("../index.js").Callback} Callback */ +export type IncomingMessage = import("../index.js").IncomingMessage; +export type ServerResponse = import("../index.js").ServerResponse; +export type Callback = import("../index.js").Callback; /** * @template {IncomingMessage} Request * @template {ServerResponse} Response @@ -21,3 +20,4 @@ declare function ready< callback: Callback, req?: Request | undefined, ): void; +export default ready; diff --git a/types/utils/setupHooks.d.ts b/types/utils/setupHooks.d.ts index 5b1a14a..9cde1c6 100644 --- a/types/utils/setupHooks.d.ts +++ b/types/utils/setupHooks.d.ts @@ -1,4 +1,10 @@ -export default setupHooks; +/** @typedef {import("@rspack/core").Configuration} Configuration */ +/** @typedef {import("@rspack/core").Compiler} Compiler */ +/** @typedef {import("@rspack/core").MultiCompiler} MultiCompiler */ +/** @typedef {import("@rspack/core").Stats} Stats */ +/** @typedef {import("@rspack/core").MultiStats} MultiStats */ +/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ +/** @typedef {import("../index.js").ServerResponse} ServerResponse */ export type Configuration = import("@rspack/core").Configuration; export type Compiler = import("@rspack/core").Compiler; export type MultiCompiler = import("@rspack/core").MultiCompiler; @@ -14,13 +20,6 @@ export type StatsObjectOptions = Exclude< Configuration["stats"], boolean | string | undefined >; -/** @typedef {import("@rspack/core").Configuration} Configuration */ -/** @typedef {import("@rspack/core").Compiler} Compiler */ -/** @typedef {import("@rspack/core").MultiCompiler} MultiCompiler */ -/** @typedef {import("@rspack/core").Stats} Stats */ -/** @typedef {import("@rspack/core").MultiStats} MultiStats */ -/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ -/** @typedef {import("../index.js").ServerResponse} ServerResponse */ /** @typedef {Configuration["stats"]} StatsOptions */ /** @typedef {{ children: Configuration["stats"][] }} MultiStatsOptions */ /** @typedef {Exclude} StatsObjectOptions */ @@ -38,3 +37,4 @@ declare function setupHooks< "watching" | "outputFileSystem" >, ): void; +export default setupHooks; diff --git a/types/utils/setupOutputFileSystem.d.ts b/types/utils/setupOutputFileSystem.d.ts index 5ae35ca..a22acdf 100644 --- a/types/utils/setupOutputFileSystem.d.ts +++ b/types/utils/setupOutputFileSystem.d.ts @@ -1,4 +1,3 @@ -export default setupOutputFileSystem; export type MultiCompiler = import("@rspack/core").MultiCompiler; export type DevServerOption = import("../index.js").DevServerOption; export type IncomingMessage = import("../index.js").IncomingMessage; @@ -21,3 +20,4 @@ declare function setupOutputFileSystem< "watching" | "outputFileSystem" >, ): void; +export default setupOutputFileSystem; diff --git a/types/utils/setupWriteToDisk.d.ts b/types/utils/setupWriteToDisk.d.ts index ee94e8b..9d4c7f9 100644 --- a/types/utils/setupWriteToDisk.d.ts +++ b/types/utils/setupWriteToDisk.d.ts @@ -1,4 +1,3 @@ -export default setupWriteToDisk; export type Compiler = import("@rspack/core").Compiler; export type MultiCompiler = import("@rspack/core").MultiCompiler; export type Compilation = import("@rspack/core").Compilation; @@ -19,3 +18,4 @@ declare function setupWriteToDisk< "watching" | "outputFileSystem" >, ): void; +export default setupWriteToDisk; From c91131b965f868e520242eb01c923f4efcecf5a5 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 17 Jul 2026 21:26:11 +0800 Subject: [PATCH 3/3] fix: preserve devMiddleware wrapper types --- src/index.js | 7 ++++++ types/index.d.ts | 64 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 839612e..2a6ed75 100644 --- a/src/index.js +++ b/src/index.js @@ -668,4 +668,11 @@ function honoWrapper(compiler, options) { rdm.honoWrapper = honoWrapper; +/** + * @type {typeof rdm & { + * hapiWrapper: typeof hapiWrapper, + * koaWrapper: typeof koaWrapper, + * honoWrapper: typeof honoWrapper, + * }} + */ export const devMiddleware = rdm; diff --git a/types/index.d.ts b/types/index.d.ts index 4d8f778..da1c87e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -429,5 +429,67 @@ export type HapiPlugin = HapiPluginBase & { export type HapiOptions = Options & { compiler: Compiler | MultiCompiler; }; -export declare const devMiddleware: typeof rdm; +/** + * @template S + * @template O + * @typedef {object} HapiPluginBase + * @property {(server: S, options: O) => void | Promise} register register + */ +/** + * @template S + * @template O + * @typedef {HapiPluginBase & { pkg: { name: string }, multiple: boolean }} HapiPlugin + */ +/** + * @typedef {Options & { compiler: Compiler | MultiCompiler }} HapiOptions + */ +/** + * @template HapiServer + * @template {HapiOptions} HapiOptionsInternal + * @returns {HapiPlugin} hapi wrapper + */ +declare function hapiWrapper< + HapiServer, + HapiOptionsInternal extends HapiOptions, +>(): HapiPlugin; +/** + * @template {IncomingMessage} [RequestInternal=IncomingMessage] + * @template {ServerResponse} [ResponseInternal=ServerResponse] + * @param {Compiler | MultiCompiler} compiler compiler + * @param {Options=} options options + * @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void} kow wrapper + */ +declare function koaWrapper< + RequestInternal extends IncomingMessage = IncomingMessage, + ResponseInternal extends ServerResponse = ServerResponse, +>( + compiler: Compiler | MultiCompiler, + options?: Options | undefined, +): (ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void; +/** + * @template {IncomingMessage} [RequestInternal=IncomingMessage] + * @template {ServerResponse} [ResponseInternal=ServerResponse] + * @param {Compiler | MultiCompiler} compiler compiler + * @param {Options=} options options + * @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void} hono wrapper + */ +declare function honoWrapper< + RequestInternal extends IncomingMessage = IncomingMessage, + ResponseInternal extends ServerResponse = ServerResponse, +>( + compiler: Compiler | MultiCompiler, + options?: Options | undefined, +): (ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise | void; +/** + * @type {typeof rdm & { + * hapiWrapper: typeof hapiWrapper, + * koaWrapper: typeof koaWrapper, + * honoWrapper: typeof honoWrapper, + * }} + */ +export declare const devMiddleware: typeof rdm & { + hapiWrapper: typeof hapiWrapper; + koaWrapper: typeof koaWrapper; + honoWrapper: typeof honoWrapper; +}; export {};