Skip to content

Commit ccd00bb

Browse files
refactor: types (#1895)
1 parent 0f9f398 commit ccd00bb

File tree

7 files changed

+16
-21
lines changed

7 files changed

+16
-21
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"strip-ansi": "^6.0.0",
105105
"supertest": "^6.1.3",
106106
"typescript": "^5.3.3",
107-
"webpack": "^5.90.3"
107+
"webpack": "^5.93.0"
108108
},
109109
"keywords": [
110110
"webpack",

src/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ const noop = () => {};
4545
* @typedef {ReturnType<MultiCompiler["watch"]>} MultiWatching
4646
*/
4747

48-
// TODO fix me after the next webpack release
4948
/**
50-
* @typedef {Object & { createReadStream?: import("fs").createReadStream, statSync?: import("fs").statSync, lstat?: import("fs").lstat, readFileSync?: import("fs").readFileSync }} OutputFileSystem
49+
* @typedef {import("webpack").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem
5150
*/
5251

5352
/** @typedef {ReturnType<Compiler["getInfrastructureLogger"]>} Logger */

src/utils/compatibleAPI.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
22
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
3+
/** @typedef {import("../index").OutputFileSystem} OutputFileSystem */
34

45
/**
56
* @typedef {Object} ExpectedIncomingMessage
@@ -196,7 +197,7 @@ function finish(res, data) {
196197

197198
/**
198199
* @param {string} filename
199-
* @param {import("../index").OutputFileSystem} outputFileSystem
200+
* @param {OutputFileSystem} outputFileSystem
200201
* @param {number} start
201202
* @param {number} end
202203
* @returns {{ bufferOrStream: (Buffer | import("fs").ReadStream), byteLength: number }}
@@ -227,9 +228,7 @@ function createReadStreamOrReadFileSync(
227228
// Handle files with zero bytes
228229
byteLength = end === 0 ? 0 : end - start + 1;
229230
} else {
230-
bufferOrStream =
231-
/** @type {import("fs").readFileSync} */
232-
(outputFileSystem.readFileSync)(filename);
231+
bufferOrStream = outputFileSystem.readFileSync(filename);
233232
({ byteLength } = bufferOrStream);
234233
}
235234

src/utils/getFilenameFromUrl.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ function getFilenameFromUrl(context, url, extra = {}) {
113113

114114
try {
115115
// eslint-disable-next-line no-param-reassign
116-
extra.stats =
117-
/** @type {import("fs").statSync} */
118-
(context.outputFileSystem.statSync)(filename);
116+
extra.stats = context.outputFileSystem.statSync(filename);
119117
} catch (_ignoreError) {
120118
// eslint-disable-next-line no-continue
121119
continue;
@@ -139,9 +137,7 @@ function getFilenameFromUrl(context, url, extra = {}) {
139137

140138
try {
141139
// eslint-disable-next-line no-param-reassign
142-
extra.stats =
143-
/** @type {import("fs").statSync} */
144-
(context.outputFileSystem.statSync)(filename);
140+
extra.stats = context.outputFileSystem.statSync(filename);
145141
} catch (__ignoreError) {
146142
// eslint-disable-next-line no-continue
147143
continue;

types/index.d.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export = wdm;
2727
* @typedef {ReturnType<MultiCompiler["watch"]>} MultiWatching
2828
*/
2929
/**
30-
* @typedef {Object & { createReadStream?: import("fs").createReadStream, statSync?: import("fs").statSync, lstat?: import("fs").lstat, readFileSync?: import("fs").readFileSync }} OutputFileSystem
30+
* @typedef {import("webpack").OutputFileSystem & { createReadStream?: import("fs").createReadStream, statSync: import("fs").statSync, readFileSync: import("fs").readFileSync }} OutputFileSystem
3131
*/
3232
/** @typedef {ReturnType<Compiler["getInfrastructureLogger"]>} Logger */
3333
/**
@@ -275,11 +275,10 @@ type NextFunction = (err?: any) => void;
275275
type WatchOptions = NonNullable<Configuration["watchOptions"]>;
276276
type Watching = Compiler["watching"];
277277
type MultiWatching = ReturnType<MultiCompiler["watch"]>;
278-
type OutputFileSystem = Object & {
278+
type OutputFileSystem = import("webpack").OutputFileSystem & {
279279
createReadStream?: typeof import("fs").createReadStream;
280-
statSync?: import("fs").StatSyncFn;
281-
lstat?: typeof import("fs").lstat;
282-
readFileSync?: typeof import("fs").readFileSync;
280+
statSync: import("fs").StatSyncFn;
281+
readFileSync: typeof import("fs").readFileSync;
283282
};
284283
type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
285284
type Callback = (

types/utils/compatibleAPI.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export type IncomingMessage = import("../index.js").IncomingMessage;
22
export type ServerResponse = import("../index.js").ServerResponse;
3+
export type OutputFileSystem = import("../index").OutputFileSystem;
34
export type ExpectedIncomingMessage = {
45
getHeader?: ((name: string) => string | string[] | undefined) | undefined;
56
getMethod?: (() => string | undefined) | undefined;
@@ -46,6 +47,7 @@ export function getStatusCode<
4647
>(res: Response): number;
4748
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
4849
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
50+
/** @typedef {import("../index").OutputFileSystem} OutputFileSystem */
4951
/**
5052
* @typedef {Object} ExpectedIncomingMessage
5153
* @property {(name: string) => string | string[] | undefined} [getHeader]
@@ -159,14 +161,14 @@ export function finish<
159161
>(res: Response, data?: string | Buffer | undefined): void;
160162
/**
161163
* @param {string} filename
162-
* @param {import("../index").OutputFileSystem} outputFileSystem
164+
* @param {OutputFileSystem} outputFileSystem
163165
* @param {number} start
164166
* @param {number} end
165167
* @returns {{ bufferOrStream: (Buffer | import("fs").ReadStream), byteLength: number }}
166168
*/
167169
export function createReadStreamOrReadFileSync(
168170
filename: string,
169-
outputFileSystem: import("../index").OutputFileSystem,
171+
outputFileSystem: OutputFileSystem,
170172
start: number,
171173
end: number,
172174
): {

0 commit comments

Comments
 (0)