Skip to content

Commit e9539d1

Browse files
fix(types): support Node 20 filesystem implementation declarations
1 parent c7d1190 commit e9539d1

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎lib/fs/fs.js‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,16 @@ const { ABSOLUTE_PATH_REGEXP } = require("../util/identifier");
387387
* @typedef {(pathLike: PathLike, callback: NoParamCallback) => void} Unlink
388388
*/
389389

390+
/**
391+
* @typedef {NonNullable<Exclude<Parameters<typeof import("fs").createReadStream>[1], BufferEncoding | undefined>["fs"]>} NodeReadStreamFSImplementation
392+
*/
393+
390394
/**
391395
* Defines the create read stream fs implementation type used by this module.
392-
* @typedef {import("fs").CreateReadStreamFSImplementation} CreateReadStreamFSImplementation
396+
* @typedef {object} CreateReadStreamFSImplementation
397+
* @property {NodeReadStreamFSImplementation["open"]=} open
398+
* @property {NodeReadStreamFSImplementation["close"]=} close
399+
* @property {NodeReadStreamFSImplementation["read"]} read
393400
*/
394401

395402
/**
@@ -471,9 +478,17 @@ const { ABSOLUTE_PATH_REGEXP } = require("../util/identifier");
471478
* @typedef {import("fs").FSImplementation} FSImplementation
472479
*/
473480

481+
/**
482+
* @typedef {NonNullable<Exclude<Parameters<typeof import("fs").createWriteStream>[1], BufferEncoding | undefined>["fs"]>} NodeWriteStreamFSImplementation
483+
*/
484+
474485
/**
475486
* Defines the create write stream fs implementation type used by this module.
476-
* @typedef {import("fs").CreateWriteStreamFSImplementation} CreateWriteStreamFSImplementation
487+
* @typedef {object} CreateWriteStreamFSImplementation
488+
* @property {NodeWriteStreamFSImplementation["open"]=} open
489+
* @property {NodeWriteStreamFSImplementation["close"]=} close
490+
* @property {NodeWriteStreamFSImplementation["write"]} write
491+
* @property {NodeWriteStreamFSImplementation["writev"]=} writev
477492
*/
478493

479494
/**

‎types.d.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ import {
9191
WithStatement,
9292
YieldExpression
9393
} from "estree";
94-
import {
95-
CreateReadStreamFSImplementation,
96-
CreateWriteStreamFSImplementation
97-
} from "fs";
9894
import { FileHandle } from "fs/promises";
9995
import {
10096
Server as ServerImportHttp,
@@ -5963,8 +5959,27 @@ declare interface CopyTransformCacheKeys {
59635959
[index: string]: any;
59645960
}
59655961
type CreateData = NormalModuleCreateData & { settings: ModuleSettings };
5962+
5963+
/**
5964+
* Defines the create read stream fs implementation type used by this module.
5965+
*/
5966+
declare interface CreateReadStreamFSImplementation {
5967+
open?: (...args: any[]) => any;
5968+
close?: (...args: any[]) => any;
5969+
read: (...args: any[]) => any;
5970+
}
59665971
type CreateStatsOptionsContext = KnownCreateStatsOptionsContext &
59675972
Record<string, any>;
5973+
5974+
/**
5975+
* Defines the create write stream fs implementation type used by this module.
5976+
*/
5977+
declare interface CreateWriteStreamFSImplementation {
5978+
open?: (...args: any[]) => any;
5979+
close?: (...args: any[]) => any;
5980+
write: (...args: any[]) => any;
5981+
writev?: (...args: any[]) => any;
5982+
}
59685983
type CreatedObject<T, F> = T extends ChunkGroupInfoWithName[]
59695984
? Record<string, StatsChunkGroup>
59705985
: T extends (infer V)[]

0 commit comments

Comments
 (0)