Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: types #1895

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ const noop = () => {};
* @typedef {ReturnType<MultiCompiler["watch"]>} 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<Compiler["getInfrastructureLogger"]>} Logger */
Expand Down
7 changes: 3 additions & 4 deletions src/utils/compatibleAPI.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
/** @typedef {import("../index").OutputFileSystem} OutputFileSystem */

/**
* @typedef {Object} ExpectedIncomingMessage
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 2 additions & 6 deletions src/utils/getFilenameFromUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export = wdm;
* @typedef {ReturnType<MultiCompiler["watch"]>} 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<Compiler["getInfrastructureLogger"]>} Logger */
/**
Expand Down Expand Up @@ -275,11 +275,10 @@ type NextFunction = (err?: any) => void;
type WatchOptions = NonNullable<Configuration["watchOptions"]>;
type Watching = Compiler["watching"];
type MultiWatching = ReturnType<MultiCompiler["watch"]>;
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<Compiler["getInfrastructureLogger"]>;
type Callback = (
Expand Down
6 changes: 4 additions & 2 deletions types/utils/compatibleAPI.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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,
): {
Expand Down
Loading