@@ -21,19 +21,6 @@ const {
21
21
22
22
/** @typedef {(err: ErrorWithDetail | null, res?: string | false, req?: ResolveRequest) => void } ResolveCallback */
23
23
24
- /**
25
- * @typedef {Object } FileSystemStats
26
- * @property {function(): boolean } isDirectory
27
- * @property {function(): boolean } isFile
28
- */
29
-
30
- /**
31
- * @typedef {Object } FileSystemDirent
32
- * @property {Buffer | string } name
33
- * @property {function(): boolean } isDirectory
34
- * @property {function(): boolean } isFile
35
- */
36
-
37
24
/**
38
25
* @typedef {Object } PossibleFileSystemError
39
26
* @property {string= } code
@@ -45,38 +32,244 @@ const {
45
32
/**
46
33
* @template T
47
34
* @callback FileSystemCallback
48
- * @param {PossibleFileSystemError & Error | null | undefined } err
35
+ * @param {PossibleFileSystemError & Error | null } err
49
36
* @param {T= } result
50
37
*/
51
38
52
- /** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | import("fs").Dirent[]=): void } DirentArrayCallback */
39
+ /**
40
+ * @typedef {string | Buffer | URL } PathLike
41
+ */
42
+
43
+ /**
44
+ * @typedef {PathLike | number } PathOrFileDescriptor
45
+ */
46
+
47
+ /**
48
+ * @typedef {Object } ObjectEncodingOptions
49
+ * @property {BufferEncoding | null | undefined } [encoding]
50
+ */
51
+
52
+ /** @typedef {function(NodeJS.ErrnoException | null, string=): void } StringCallback */
53
+ /** @typedef {function(NodeJS.ErrnoException | null, Buffer=): void } BufferCallback */
54
+ /** @typedef {function(NodeJS.ErrnoException | null, (string | Buffer)=): void } StringOrBufferCallback */
55
+ /** @typedef {function(NodeJS.ErrnoException | null, IStats=): void } StatsCallback */
56
+ /** @typedef {function(NodeJS.ErrnoException | null, IBigIntStats=): void } BigIntStatsCallback */
57
+ /** @typedef {function(NodeJS.ErrnoException | null, (IStats | IBigIntStats)=): void } StatsOrBigIntStatsCallback */
58
+ /** @typedef {function(NodeJS.ErrnoException | Error | null, JsonObject=): void } ReadJsonCallback */
59
+ /** @typedef {function(NodeJS.ErrnoException | null, string[]=): void } ReaddirStringCallback */
60
+ /** @typedef {function(NodeJS.ErrnoException | null, Buffer[]=): void } ReaddirBufferCallback */
61
+ /** @typedef {function(NodeJS.ErrnoException | null, (string[] | Buffer[])=): void } ReaddirStringOrBufferCallback */
62
+ /** @typedef {function(NodeJS.ErrnoException | null, Dirent[]=): void } ReaddirDirentCallback */
63
+
64
+ /**
65
+ * @template T
66
+ * @typedef {Object } IStatsBase
67
+ * @property {() => boolean } isFile
68
+ * @property {() => boolean } isDirectory
69
+ * @property {() => boolean } isBlockDevice
70
+ * @property {() => boolean } isCharacterDevice
71
+ * @property {() => boolean } isSymbolicLink
72
+ * @property {() => boolean } isFIFO
73
+ * @property {() => boolean } isSocket
74
+ * @property {T } dev
75
+ * @property {T } ino
76
+ * @property {T } mode
77
+ * @property {T } nlink
78
+ * @property {T } uid
79
+ * @property {T } gid
80
+ * @property {T } rdev
81
+ * @property {T } size
82
+ * @property {T } blksize
83
+ * @property {T } blocks
84
+ * @property {T } atimeMs
85
+ * @property {T } mtimeMs
86
+ * @property {T } ctimeMs
87
+ * @property {T } birthtimeMs
88
+ * @property {Date } atime
89
+ * @property {Date } mtime
90
+ * @property {Date } ctime
91
+ * @property {Date } birthtime
92
+ */
93
+
94
+ /**
95
+ * @typedef {IStatsBase<number> } IStats
96
+ */
97
+
98
+ /**
99
+ * @typedef {IStatsBase<bigint> & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint } } IBigIntStats
100
+ */
101
+
102
+ /**
103
+ * @typedef {Object } Dirent
104
+ * @property {() => boolean } isFile
105
+ * @property {() => boolean } isDirectory
106
+ * @property {() => boolean } isBlockDevice
107
+ * @property {() => boolean } isCharacterDevice
108
+ * @property {() => boolean } isSymbolicLink
109
+ * @property {() => boolean } isFIFO
110
+ * @property {() => boolean } isSocket
111
+ * @property {string } name
112
+ * @property {string } path
113
+ */
114
+
115
+ /**
116
+ * @typedef {Object } StatOptions
117
+ * @property {(boolean | undefined)= } bigint
118
+ */
119
+
120
+ /**
121
+ * @typedef {Object } StatSyncOptions
122
+ * @property {(boolean | undefined)= } bigint
123
+ * @property {(boolean | undefined)= } throwIfNoEntry
124
+ */
125
+
126
+ /**
127
+ * @typedef {{
128
+ * (path: PathOrFileDescriptor, options: ({ encoding?: null | undefined, flag?: string | undefined } & import("events").Abortable) | undefined | null, callback: BufferCallback): void;
129
+ * (path: PathOrFileDescriptor, options: ({ encoding: BufferEncoding, flag?: string | undefined } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void;
130
+ * (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { flag?: string | undefined } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void;
131
+ * (path: PathOrFileDescriptor, callback: BufferCallback): void;
132
+ * }} ReadFile
133
+ */
134
+
135
+ /**
136
+ * @typedef {ObjectEncodingOptions | BufferEncoding | undefined | null } EncodingOption
137
+ */
138
+
139
+ /**
140
+ * @typedef {'buffer'| { encoding: 'buffer' } } BufferEncodingOption
141
+ */
142
+
143
+ /**
144
+ * @typedef {{
145
+ * (path: PathOrFileDescriptor, options?: { encoding?: null | undefined, flag?: string | undefined } | null): Buffer;
146
+ * (path: PathOrFileDescriptor, options: { encoding: BufferEncoding, flag?: string | undefined } | BufferEncoding): string;
147
+ * (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { flag?: string | undefined }) | BufferEncoding | null): string | Buffer;
148
+ * }} ReadFileSync
149
+ */
150
+
151
+ /**
152
+ * @typedef {{
153
+ * (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: ReaddirStringCallback): void;
154
+ * (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer', callback: ReaddirBufferCallback): void;
155
+ * (path: PathLike, callback: ReaddirStringCallback): void;
156
+ * (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: ReaddirStringOrBufferCallback): void;
157
+ * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: ReaddirDirentCallback): void;
158
+ * }} Readdir
159
+ */
160
+
161
+ /**
162
+ * @typedef {{
163
+ * (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | null): string[];
164
+ * (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer'): Buffer[];
165
+ * (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[];
166
+ * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[];
167
+ * }} ReaddirSync
168
+
169
+ /**
170
+ * @typedef {function(PathOrFileDescriptor, ReadJsonCallback): void } ReadJson
171
+ */
172
+
173
+ /**
174
+ * @typedef {function(PathOrFileDescriptor): JsonObject } ReadJsonSync
175
+ */
176
+
177
+ /**
178
+ * @typedef {{
179
+ * (path: PathLike, options: EncodingOption, callback: StringCallback): void;
180
+ * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void;
181
+ * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void;
182
+ * (path: PathLike, callback: StringCallback): void;
183
+ * }} Readlink
184
+ */
185
+
186
+ /**
187
+ * @typedef {{
188
+ * (path: PathLike, options?: EncodingOption): string;
189
+ * (path: PathLike, options: BufferEncodingOption): Buffer;
190
+ * (path: PathLike, options?: EncodingOption): string | Buffer;
191
+ * }} ReadlinkSync
192
+ */
193
+
194
+ /**
195
+ * @typedef {{
196
+ * (path: PathLike, callback: StatsCallback): void;
197
+ * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void;
198
+ * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void;
199
+ * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void;
200
+ * }} LStat
201
+ */
202
+
203
+ /**
204
+ * @typedef {{
205
+ * (path: PathLike, options?: undefined): IStats;
206
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined;
207
+ * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined;
208
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats;
209
+ * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats;
210
+ * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats;
211
+ * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined;
212
+ * }} LStatSync
213
+ */
214
+
215
+ /**
216
+ * @typedef {{
217
+ * (path: PathLike, callback: StatsCallback): void;
218
+ * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void;
219
+ * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void;
220
+ * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void;
221
+ * }} Stat
222
+ */
223
+
224
+ /**
225
+ * @typedef {{
226
+ * (path: PathLike, options?: undefined): IStats;
227
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined;
228
+ * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined;
229
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats;
230
+ * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats;
231
+ * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats;
232
+ * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined;
233
+ * }} StatSync
234
+ */
235
+
236
+ /**
237
+ * @typedef {{
238
+ * (path: PathLike, options: EncodingOption, callback: StringCallback): void;
239
+ * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void;
240
+ * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void;
241
+ * (path: PathLike, callback: StringCallback): void;
242
+ * }} RealPath
243
+ */
53
244
54
245
/**
55
- * @typedef {Object } ReaddirOptions
56
- * @property {BufferEncoding | null | 'buffer' } [encoding]
57
- * @property {boolean | undefined } [withFileTypes=false]
246
+ * @typedef {{
247
+ * (path: PathLike, options?: EncodingOption): string;
248
+ * (path: PathLike, options: BufferEncodingOption): Buffer;
249
+ * (path: PathLike, options?: EncodingOption): string | Buffer;
250
+ * }} RealPathSync
58
251
*/
59
252
60
253
/**
61
254
* @typedef {Object } FileSystem
62
- * @property {(function(string, FileSystemCallback<Buffer | string>): void) & function(string, object, FileSystemCallback<Buffer | string>): void } readFile
63
- * @property {function(string, (ReaddirOptions | BufferEncoding | null | undefined | 'buffer' | DirentArrayCallback)=, DirentArrayCallback=): void } readdir
64
- * @property {((function(string, FileSystemCallback<object>): void) & function(string, object, FileSystemCallback<object>): void) = } readJson
65
- * @property {(function(string, FileSystemCallback<Buffer | string>): void) & function(string, object, FileSystemCallback<Buffer | string>): void } readlink
66
- * @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void = } lstat
67
- * @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void } stat
68
- * @property {(function(string, FileSystemCallback<Buffer | string>): void) & function(string, object, FileSystemCallback<Buffer | string>): void = } realpath
255
+ * @property {ReadFile } readFile
256
+ * @property {Readdir } readdir
257
+ * @property {ReadJson = } readJson
258
+ * @property {Readlink } readlink
259
+ * @property {LStat = } lstat
260
+ * @property {Stat } stat
261
+ * @property {RealPath = } realpath
69
262
*/
70
263
71
264
/**
72
265
* @typedef {Object } SyncFileSystem
73
- * @property {function(string, object=): Buffer | string } readFileSync
74
- * @property {function(string, object=): (Buffer | string)[] | FileSystemDirent[] } readdirSync
75
- * @property {(function(string, object=): object) = } readJsonSync
76
- * @property {function(string, object=): Buffer | string } readlinkSync
77
- * @property {function(string, object=): FileSystemStats = } lstatSync
78
- * @property {function(string, object=): FileSystemStats } statSync
79
- * @property {function(string, object=): string | Buffer = } realpathSync
266
+ * @property {ReadFileSync } readFileSync
267
+ * @property {ReaddirSync } readdirSync
268
+ * @property {ReadJsonSync = } readJsonSync
269
+ * @property {ReadlinkSync } readlinkSync
270
+ * @property {LStatSync = } lstatSync
271
+ * @property {StatSync } statSync
272
+ * @property {RealPathSync = } realpathSync
80
273
*/
81
274
82
275
/**
0 commit comments