1
1
import fs , {
2
+ type symlink as _symlink ,
2
3
type BigIntStats ,
3
4
type BufferEncodingOption ,
4
5
type Dirent ,
@@ -9,18 +10,18 @@ import fs, {
9
10
type RmOptions ,
10
11
type StatOptions ,
11
12
type Stats ,
13
+ type TimeLike ,
12
14
type WriteFileOptions ,
13
15
} from 'node:fs'
14
- import { quansync } from 'quansync/macro '
16
+ import { quansync , type QuansyncFn } from 'quansync'
15
17
import type { Buffer } from 'node:buffer'
16
- import type { QuansyncFn } from 'quansync'
17
18
18
19
/**
19
20
* @link https://nodejs.org/api/fs.html#fspromisesreadfilepath-options
20
21
*/
21
22
export const readFile = quansync ( {
22
- sync : ( path , options ) => fs . readFileSync ( path , options ) ,
23
- async : ( path , options ) => fs . promises . readFile ( path , options ) ,
23
+ sync : fs . readFileSync ,
24
+ async : fs . promises . readFile as any ,
24
25
} ) as QuansyncFn <
25
26
Buffer ,
26
27
[
@@ -52,20 +53,16 @@ export const writeFile: QuansyncFn<
52
53
options ?: WriteFileOptions | undefined ,
53
54
]
54
55
> = quansync ( {
55
- sync : (
56
- file : PathLike ,
57
- data : string | NodeJS . ArrayBufferView ,
58
- options ?: WriteFileOptions ,
59
- ) => fs . writeFileSync ( file , data , options ) ,
60
- async : ( file , data , options ) => fs . promises . writeFile ( file , data , options ) ,
56
+ sync : fs . writeFileSync ,
57
+ async : fs . promises . writeFile as any ,
61
58
} )
62
59
63
60
/**
64
61
* @link https://nodejs.org/api/fs.html#fspromisesunlinkpath
65
62
*/
66
63
export const unlink : QuansyncFn < void , [ path : PathLike ] > = quansync ( {
67
- sync : ( path : PathLike ) => fs . unlinkSync ( path ) ,
68
- async : ( path ) => fs . promises . unlink ( path ) ,
64
+ sync : fs . unlinkSync ,
65
+ async : fs . promises . unlink ,
69
66
} )
70
67
71
68
/**
@@ -75,16 +72,16 @@ export const access: QuansyncFn<
75
72
void ,
76
73
[ path : PathLike , mode ?: number | undefined ]
77
74
> = quansync ( {
78
- sync : ( path : PathLike , mode ?: number ) => fs . accessSync ( path , mode ) ,
79
- async : ( path , mode ) => fs . promises . access ( path , mode ) ,
75
+ sync : fs . accessSync ,
76
+ async : fs . promises . access ,
80
77
} )
81
78
82
79
/**
83
80
* @link https://nodejs.org/api/fs.html#fspromisesstatpath-options
84
81
*/
85
82
export const stat = quansync ( {
86
- sync : ( path : PathLike , options ) => fs . statSync ( path , options ) ,
87
- async : ( path , options ) => fs . promises . stat ( path , options ) ,
83
+ sync : fs . statSync ,
84
+ async : fs . promises . stat ,
88
85
} ) as QuansyncFn <
89
86
Stats ,
90
87
[ path : PathLike , opts ?: StatOptions & { bigint ?: false | undefined } ]
@@ -96,8 +93,8 @@ export const stat = quansync({
96
93
QuansyncFn < Stats | BigIntStats , [ path : PathLike , opts ?: StatOptions ] >
97
94
98
95
export const lstat = quansync ( {
99
- sync : ( path : PathLike , options ) => fs . lstatSync ( path , options ) ,
100
- async : ( path , options ) => fs . promises . lstat ( path , options ) ,
96
+ sync : fs . lstatSync ,
97
+ async : fs . promises . lstat ,
101
98
} ) as typeof stat
102
99
103
100
/**
@@ -107,9 +104,8 @@ export const cp: QuansyncFn<
107
104
void ,
108
105
[ src : PathLike , dest : PathLike , mode ?: number | undefined ]
109
106
> = quansync ( {
110
- sync : ( src : PathLike , dest : PathLike , mode ?: number ) =>
111
- fs . copyFileSync ( src , dest , mode ) ,
112
- async : ( src , dest , mode ) => fs . promises . copyFile ( src , dest , mode ) ,
107
+ sync : fs . copyFileSync ,
108
+ async : fs . promises . copyFile ,
113
109
} )
114
110
115
111
/**
@@ -119,16 +115,16 @@ export const rm: QuansyncFn<
119
115
void ,
120
116
[ path : PathLike , options ?: RmOptions | undefined ]
121
117
> = quansync ( {
122
- sync : ( path : PathLike , options ?: RmOptions ) => fs . rmSync ( path , options ) ,
123
- async : ( path , options ) => fs . promises . rm ( path , options ) ,
118
+ sync : fs . rmSync ,
119
+ async : fs . promises . rm ,
124
120
} )
125
121
126
122
/**
127
123
* @link https://nodejs.org/api/fs.html#fspromisesmkdirpath-options
128
124
*/
129
125
export const mkdir = quansync ( {
130
- sync : ( path : PathLike , options ) => fs . mkdirSync ( path , options ) ,
131
- async : ( path , options ) => fs . promises . mkdir ( path , options ) ,
126
+ sync : fs . mkdirSync ,
127
+ async : fs . promises . mkdir ,
132
128
} ) as QuansyncFn <
133
129
string | undefined ,
134
130
[ path : PathLike , options : MakeDirectoryOptions & { recursive : true } ]
@@ -149,17 +145,16 @@ export const mkdir = quansync({
149
145
*/
150
146
export const rename : QuansyncFn < void , [ oldPath : PathLike , newPath : PathLike ] > =
151
147
quansync ( {
152
- sync : ( oldPath : PathLike , newPath : PathLike ) =>
153
- fs . renameSync ( oldPath , newPath ) ,
154
- async : ( oldPath , newPath ) => fs . promises . rename ( oldPath , newPath ) ,
148
+ sync : fs . renameSync ,
149
+ async : fs . promises . rename ,
155
150
} )
156
151
157
152
/**
158
153
* @link https://nodejs.org/api/fs.html#fspromisesreaddirpath-options
159
154
*/
160
155
export const readdir = quansync ( {
161
- sync : ( path : PathLike , options ) => fs . readdirSync ( path , options ) ,
162
- async : ( path , options ) => fs . promises . readdir ( path , options ) ,
156
+ sync : fs . readdirSync ,
157
+ async : fs . promises . readdir ,
163
158
} ) as QuansyncFn <
164
159
string [ ] ,
165
160
[
@@ -214,8 +209,24 @@ export const readdir = quansync({
214
209
* @link https://nodejs.org/api/fs.html#fspromisesrealpathpath-options
215
210
*/
216
211
export const realpath = quansync ( {
217
- sync : ( path : PathLike , options ) => fs . realpathSync ( path , options ) ,
218
- async : ( path , options ) => fs . promises . realpath ( path , options ) ,
212
+ sync : fs . realpathSync ,
213
+ async : fs . promises . realpath ,
214
+ } ) as QuansyncFn <
215
+ string ,
216
+ [ path : PathLike , options ?: ObjectEncodingOptions | BufferEncoding | null ]
217
+ > &
218
+ QuansyncFn < Buffer , [ path : PathLike , options : BufferEncodingOption ] > &
219
+ QuansyncFn <
220
+ string | Buffer ,
221
+ [ path : PathLike , options ?: ObjectEncodingOptions | BufferEncoding | null ]
222
+ >
223
+
224
+ /**
225
+ * @link https://nodejs.org/api/fs.html#fspromisesreadlinkpath-options
226
+ */
227
+ export const readlink = quansync ( {
228
+ sync : fs . readlinkSync ,
229
+ async : fs . promises . readlink ,
219
230
} ) as QuansyncFn <
220
231
string ,
221
232
[ path : PathLike , options ?: ObjectEncodingOptions | BufferEncoding | null ]
@@ -225,3 +236,82 @@ export const realpath = quansync({
225
236
string | Buffer ,
226
237
[ path : PathLike , options ?: ObjectEncodingOptions | BufferEncoding | null ]
227
238
>
239
+
240
+ /**
241
+ * @link https://nodejs.org/api/fs.html#fspromisessymlinktarget-path-type
242
+ */
243
+ export const symlink : QuansyncFn <
244
+ void ,
245
+ [ target : PathLike , path : PathLike , type ?: _symlink . Type | null ]
246
+ > = quansync ( {
247
+ sync : fs . symlinkSync ,
248
+ async : fs . promises . symlink ,
249
+ } )
250
+
251
+ /**
252
+ * @link https://nodejs.org/api/fs.html#fspromiseschownpath-uid-gid
253
+ */
254
+ export const chown : QuansyncFn <
255
+ void ,
256
+ [ path : PathLike , uid : number , gid : number ]
257
+ > = quansync ( {
258
+ sync : fs . chownSync ,
259
+ async : fs . promises . chown ,
260
+ } )
261
+
262
+ /**
263
+ * @link https://nodejs.org/api/fs.html#fspromiseslchownpath-uid-gid
264
+ */
265
+ export const lchown : QuansyncFn <
266
+ void ,
267
+ [ path : PathLike , uid : number , gid : number ]
268
+ > = quansync ( {
269
+ sync : fs . lchownSync ,
270
+ async : fs . promises . lchown ,
271
+ } )
272
+
273
+ /**
274
+ * @link https://nodejs.org/api/fs.html#fspromiseschmodpath-mode
275
+ */
276
+ export const chmod : QuansyncFn < void , [ path : PathLike , mode : Mode ] > = quansync ( {
277
+ sync : fs . chmodSync ,
278
+ async : fs . promises . chmod ,
279
+ } )
280
+
281
+ /**
282
+ * @link https://nodejs.org/api/fs.html#fspromisesutimespath-atime-mtime
283
+ */
284
+ export const utimes : QuansyncFn <
285
+ void ,
286
+ [ path : PathLike , atime : TimeLike , mtime : TimeLike ]
287
+ > = quansync ( {
288
+ sync : fs . utimesSync ,
289
+ async : fs . promises . utimes ,
290
+ } )
291
+
292
+ /**
293
+ * @link https://nodejs.org/api/fs.html#fspromiseslutimespath-atime-mtime
294
+ */
295
+ export const lutimes : QuansyncFn <
296
+ void ,
297
+ [ path : PathLike , atime : TimeLike , mtime : TimeLike ]
298
+ > = quansync ( {
299
+ sync : fs . lutimesSync ,
300
+ async : fs . promises . lutimes ,
301
+ } )
302
+
303
+ /**
304
+ * @link https://nodejs.org/api/fs.html#fspromisesmkdtempprefix-options
305
+ */
306
+ export const mkdtemp = quansync ( {
307
+ sync : fs . mkdtempSync ,
308
+ async : fs . promises . mkdtemp ,
309
+ } ) as QuansyncFn <
310
+ string ,
311
+ [ prefix : string , options ?: ObjectEncodingOptions | BufferEncoding | null ]
312
+ > &
313
+ QuansyncFn < Buffer , [ prefix : string , options : BufferEncodingOption ] > &
314
+ QuansyncFn <
315
+ string | Buffer ,
316
+ [ prefix : string , options ?: ObjectEncodingOptions | BufferEncoding | null ]
317
+ >
0 commit comments