Skip to content

Commit cf367ff

Browse files
committed
feat: add more apis
1 parent 0282784 commit cf367ff

File tree

4 files changed

+122
-93
lines changed

4 files changed

+122
-93
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"tsdown": "^0.6.0",
5454
"tsx": "^4.19.3",
5555
"typescript": "^5.7.3",
56-
"unplugin-quansync": "^0.3.3",
5756
"vitest": "^3.0.7"
5857
},
5958
"engines": {

pnpm-lock.yaml

Lines changed: 0 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 122 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs, {
2+
type symlink as _symlink,
23
type BigIntStats,
34
type BufferEncodingOption,
45
type Dirent,
@@ -9,18 +10,18 @@ import fs, {
910
type RmOptions,
1011
type StatOptions,
1112
type Stats,
13+
type TimeLike,
1214
type WriteFileOptions,
1315
} from 'node:fs'
14-
import { quansync } from 'quansync/macro'
16+
import { quansync, type QuansyncFn } from 'quansync'
1517
import type { Buffer } from 'node:buffer'
16-
import type { QuansyncFn } from 'quansync'
1718

1819
/**
1920
* @link https://nodejs.org/api/fs.html#fspromisesreadfilepath-options
2021
*/
2122
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,
2425
}) as QuansyncFn<
2526
Buffer,
2627
[
@@ -52,20 +53,16 @@ export const writeFile: QuansyncFn<
5253
options?: WriteFileOptions | undefined,
5354
]
5455
> = 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,
6158
})
6259

6360
/**
6461
* @link https://nodejs.org/api/fs.html#fspromisesunlinkpath
6562
*/
6663
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,
6966
})
7067

7168
/**
@@ -75,16 +72,16 @@ export const access: QuansyncFn<
7572
void,
7673
[path: PathLike, mode?: number | undefined]
7774
> = 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,
8077
})
8178

8279
/**
8380
* @link https://nodejs.org/api/fs.html#fspromisesstatpath-options
8481
*/
8582
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,
8885
}) as QuansyncFn<
8986
Stats,
9087
[path: PathLike, opts?: StatOptions & { bigint?: false | undefined }]
@@ -96,8 +93,8 @@ export const stat = quansync({
9693
QuansyncFn<Stats | BigIntStats, [path: PathLike, opts?: StatOptions]>
9794

9895
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,
10198
}) as typeof stat
10299

103100
/**
@@ -107,9 +104,8 @@ export const cp: QuansyncFn<
107104
void,
108105
[src: PathLike, dest: PathLike, mode?: number | undefined]
109106
> = 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,
113109
})
114110

115111
/**
@@ -119,16 +115,16 @@ export const rm: QuansyncFn<
119115
void,
120116
[path: PathLike, options?: RmOptions | undefined]
121117
> = 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,
124120
})
125121

126122
/**
127123
* @link https://nodejs.org/api/fs.html#fspromisesmkdirpath-options
128124
*/
129125
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,
132128
}) as QuansyncFn<
133129
string | undefined,
134130
[path: PathLike, options: MakeDirectoryOptions & { recursive: true }]
@@ -149,17 +145,16 @@ export const mkdir = quansync({
149145
*/
150146
export const rename: QuansyncFn<void, [oldPath: PathLike, newPath: PathLike]> =
151147
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,
155150
})
156151

157152
/**
158153
* @link https://nodejs.org/api/fs.html#fspromisesreaddirpath-options
159154
*/
160155
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,
163158
}) as QuansyncFn<
164159
string[],
165160
[
@@ -214,8 +209,24 @@ export const readdir = quansync({
214209
* @link https://nodejs.org/api/fs.html#fspromisesrealpathpath-options
215210
*/
216211
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,
219230
}) as QuansyncFn<
220231
string,
221232
[path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null]
@@ -225,3 +236,82 @@ export const realpath = quansync({
225236
string | Buffer,
226237
[path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null]
227238
>
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+
>

tsdown.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { defineConfig } from 'tsdown'
2-
import Quansync from 'unplugin-quansync/rolldown'
32

43
export default defineConfig({
54
entry: ['./src/index.ts'],
@@ -8,5 +7,4 @@ export default defineConfig({
87
clean: true,
98
dts: { transformer: 'oxc' },
109
platform: 'node',
11-
plugins: [Quansync()],
1210
})

0 commit comments

Comments
 (0)