diff --git a/package-lock.json b/package-lock.json index fd6a71ca0..2ef72a69f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,7 +60,7 @@ "strip-ansi": "^6.0.0", "supertest": "^6.1.3", "typescript": "^5.3.3", - "webpack": "^5.90.3" + "webpack": "^5.93.0" }, "engines": { "node": ">= 18.12.0" diff --git a/package.json b/package.json index 64f13bb66..56d574a5c 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "strip-ansi": "^6.0.0", "supertest": "^6.1.3", "typescript": "^5.3.3", - "webpack": "^5.90.3" + "webpack": "^5.93.0" }, "keywords": [ "webpack", diff --git a/src/index.js b/src/index.js index f8c5ea0fb..dc54a75e9 100644 --- a/src/index.js +++ b/src/index.js @@ -45,9 +45,8 @@ const noop = () => {}; * @typedef {ReturnType} MultiWatching */ -// TODO fix me after the next webpack release /** - * @typedef {Object & { createReadStream?: import("fs").createReadStream, statSync?: import("fs").statSync, lstat?: import("fs").lstat, readFileSync?: import("fs").readFileSync }} OutputFileSystem + * @typedef {import("webpack").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem */ /** @typedef {ReturnType} Logger */ diff --git a/src/utils/compatibleAPI.js b/src/utils/compatibleAPI.js index faa52cd70..b86e32481 100644 --- a/src/utils/compatibleAPI.js +++ b/src/utils/compatibleAPI.js @@ -1,5 +1,6 @@ /** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ /** @typedef {import("../index.js").ServerResponse} ServerResponse */ +/** @typedef {import("../index").OutputFileSystem} OutputFileSystem */ /** * @typedef {Object} ExpectedIncomingMessage @@ -196,7 +197,7 @@ function finish(res, data) { /** * @param {string} filename - * @param {import("../index").OutputFileSystem} outputFileSystem + * @param {OutputFileSystem} outputFileSystem * @param {number} start * @param {number} end * @returns {{ bufferOrStream: (Buffer | import("fs").ReadStream), byteLength: number }} @@ -227,9 +228,7 @@ function createReadStreamOrReadFileSync( // Handle files with zero bytes byteLength = end === 0 ? 0 : end - start + 1; } else { - bufferOrStream = - /** @type {import("fs").readFileSync} */ - (outputFileSystem.readFileSync)(filename); + bufferOrStream = outputFileSystem.readFileSync(filename); ({ byteLength } = bufferOrStream); } diff --git a/src/utils/getFilenameFromUrl.js b/src/utils/getFilenameFromUrl.js index 32e4f465b..7dd7ddb80 100644 --- a/src/utils/getFilenameFromUrl.js +++ b/src/utils/getFilenameFromUrl.js @@ -113,9 +113,7 @@ function getFilenameFromUrl(context, url, extra = {}) { try { // eslint-disable-next-line no-param-reassign - extra.stats = - /** @type {import("fs").statSync} */ - (context.outputFileSystem.statSync)(filename); + extra.stats = context.outputFileSystem.statSync(filename); } catch (_ignoreError) { // eslint-disable-next-line no-continue continue; @@ -139,9 +137,7 @@ function getFilenameFromUrl(context, url, extra = {}) { try { // eslint-disable-next-line no-param-reassign - extra.stats = - /** @type {import("fs").statSync} */ - (context.outputFileSystem.statSync)(filename); + extra.stats = context.outputFileSystem.statSync(filename); } catch (__ignoreError) { // eslint-disable-next-line no-continue continue; diff --git a/types/index.d.ts b/types/index.d.ts index 89a6806fd..750074985 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -27,7 +27,7 @@ export = wdm; * @typedef {ReturnType} MultiWatching */ /** - * @typedef {Object & { createReadStream?: import("fs").createReadStream, statSync?: import("fs").statSync, lstat?: import("fs").lstat, readFileSync?: import("fs").readFileSync }} OutputFileSystem + * @typedef {import("webpack").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem */ /** @typedef {ReturnType} Logger */ /** @@ -275,11 +275,10 @@ type NextFunction = (err?: any) => void; type WatchOptions = NonNullable; type Watching = Compiler["watching"]; type MultiWatching = ReturnType; -type OutputFileSystem = Object & { +type OutputFileSystem = import("webpack").OutputFileSystem & { createReadStream?: typeof import("fs").createReadStream; - statSync?: import("fs").StatSyncFn; - lstat?: typeof import("fs").lstat; - readFileSync?: typeof import("fs").readFileSync; + statSync: import("fs").StatSyncFn; + readFileSync: typeof import("fs").readFileSync; }; type Logger = ReturnType; type Callback = ( diff --git a/types/utils/compatibleAPI.d.ts b/types/utils/compatibleAPI.d.ts index 5f16f508e..5a3ab777a 100644 --- a/types/utils/compatibleAPI.d.ts +++ b/types/utils/compatibleAPI.d.ts @@ -1,5 +1,6 @@ export type IncomingMessage = import("../index.js").IncomingMessage; export type ServerResponse = import("../index.js").ServerResponse; +export type OutputFileSystem = import("../index").OutputFileSystem; export type ExpectedIncomingMessage = { getHeader?: ((name: string) => string | string[] | undefined) | undefined; getMethod?: (() => string | undefined) | undefined; @@ -46,6 +47,7 @@ export function getStatusCode< >(res: Response): number; /** @typedef {import("../index.js").IncomingMessage} IncomingMessage */ /** @typedef {import("../index.js").ServerResponse} ServerResponse */ +/** @typedef {import("../index").OutputFileSystem} OutputFileSystem */ /** * @typedef {Object} ExpectedIncomingMessage * @property {(name: string) => string | string[] | undefined} [getHeader] @@ -159,14 +161,14 @@ export function finish< >(res: Response, data?: string | Buffer | undefined): void; /** * @param {string} filename - * @param {import("../index").OutputFileSystem} outputFileSystem + * @param {OutputFileSystem} outputFileSystem * @param {number} start * @param {number} end * @returns {{ bufferOrStream: (Buffer | import("fs").ReadStream), byteLength: number }} */ export function createReadStreamOrReadFileSync( filename: string, - outputFileSystem: import("../index").OutputFileSystem, + outputFileSystem: OutputFileSystem, start: number, end: number, ): {