diff --git a/package.json b/package.json index 8527a9a..bd84c7f 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "tsdown": "^0.6.0", "tsx": "^4.19.3", "typescript": "^5.7.3", - "unplugin-quansync": "^0.3.3", "vitest": "^3.0.7" }, "engines": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 00e7e2f..2236a66 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,9 +42,6 @@ importers: typescript: specifier: ^5.7.3 version: 5.7.3 - unplugin-quansync: - specifier: ^0.3.3 - version: 0.3.3(quansync@0.2.4) vitest: specifier: ^3.0.7 version: 3.0.7(@types/debug@4.1.12)(@types/node@22.13.5)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.7.0) @@ -58,23 +55,10 @@ packages: resolution: {integrity: sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==} engines: {node: '>=6.9.0'} - '@babel/helper-string-parser@7.25.9': - resolution: {integrity: sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==} - engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.25.9': resolution: {integrity: sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==} engines: {node: '>=6.9.0'} - '@babel/parser@7.26.9': - resolution: {integrity: sha512-81NWa1njQblgZbQHxWHpxxCzNsa3ZwvFqpUg7P+NNUU6f3UU2jBEg4OlF/J6rl8+PQGh1q6/zWScd001YwcA5A==} - engines: {node: '>=6.0.0'} - hasBin: true - - '@babel/types@7.26.9': - resolution: {integrity: sha512-Y3IR1cRnOxOCDvMmNiym7XpXQ93iGDDPHx+Zj+NM+rg0fBaShfQLkg+hKPaZCEvg5N/LeCo4+Rj/i3FuJsIQaw==} - engines: {node: '>=6.9.0'} - '@emnapi/core@1.3.1': resolution: {integrity: sha512-pVGjBIt1Y6gg3EJN8jTcfpP/+uuRksIo055oE/OBkDNcjZqVbfkWCksG1Jp4yZnj3iKWyWX8fdG/j6UDYPbFog==} @@ -759,10 +743,6 @@ packages: resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} engines: {node: '>=12'} - ast-kit@1.4.0: - resolution: {integrity: sha512-BlGeOw73FDsX7z0eZE/wuuafxYoek2yzNJ6l6A1nsb4+z/p87TOPbHaWuN53kFKNuUXiCQa2M+xLF71IqQmRSw==} - engines: {node: '>=16.14.0'} - balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -1412,10 +1392,6 @@ packages: loupe@3.1.3: resolution: {integrity: sha512-kkIp7XSkP78ZxJEsSxW3712C6teJVoeHHwgo9zJ380de7IYyJ2ISlxojcH2pC5OFLewESmnRi/+XCDIEEVyoug==} - magic-string-ast@0.7.0: - resolution: {integrity: sha512-686fgAHaJY7wLTFEq7nnKqeQrhqmXB19d1HnqT35Ci7BN6hbAYLZUezTQ062uUHM7ggZEQlqJ94Ftls+KDXU8Q==} - engines: {node: '>=16.14.0'} - magic-string@0.30.17: resolution: {integrity: sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==} @@ -2026,12 +2002,6 @@ packages: typescript: optional: true - unplugin-quansync@0.3.3: - resolution: {integrity: sha512-bsO/xUbR7PAh6yb5CcCwLROsTUxUKLGIm1klXsMbtvV0NOVpOJTOB526KRnoLcx5ZmGLd5Y9kl2Sxz+0GUN3yA==} - engines: {node: '>=18.12.0'} - peerDependencies: - quansync: '>=0.2.2' - unplugin-unused@0.4.1: resolution: {integrity: sha512-qPZXTaViFcUJIIQ6KeivWD5dgvyimnubylap86PJELJpcdizOJ8ASgNfipm9QXiZyN6sBUu8o265Q5qqpYifDA==} engines: {node: '>=18.12.0'} @@ -2196,19 +2166,8 @@ snapshots: js-tokens: 4.0.0 picocolors: 1.1.1 - '@babel/helper-string-parser@7.25.9': {} - '@babel/helper-validator-identifier@7.25.9': {} - '@babel/parser@7.26.9': - dependencies: - '@babel/types': 7.26.9 - - '@babel/types@7.26.9': - dependencies: - '@babel/helper-string-parser': 7.25.9 - '@babel/helper-validator-identifier': 7.25.9 - '@emnapi/core@1.3.1': dependencies: '@emnapi/wasi-threads': 1.0.1 @@ -2814,11 +2773,6 @@ snapshots: assertion-error@2.0.1: {} - ast-kit@1.4.0: - dependencies: - '@babel/parser': 7.26.9 - pathe: 2.0.3 - balanced-match@1.0.2: {} boolbase@1.0.0: {} @@ -3534,10 +3488,6 @@ snapshots: loupe@3.1.3: {} - magic-string-ast@0.7.0: - dependencies: - magic-string: 0.30.17 - magic-string@0.30.17: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 @@ -4367,14 +4317,6 @@ snapshots: transitivePeerDependencies: - supports-color - unplugin-quansync@0.3.3(quansync@0.2.4): - dependencies: - ast-kit: 1.4.0 - magic-string-ast: 0.7.0 - quansync: 0.2.4 - unplugin: 2.2.0 - unplugin-utils: 0.2.4 - unplugin-unused@0.4.1: dependencies: js-tokens: 9.0.1 diff --git a/src/index.ts b/src/index.ts index f57c4b1..01c43fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import fs, { + type symlink as _symlink, type BigIntStats, type BufferEncodingOption, type Dirent, @@ -9,18 +10,18 @@ import fs, { type RmOptions, type StatOptions, type Stats, + type TimeLike, type WriteFileOptions, } from 'node:fs' -import { quansync } from 'quansync/macro' +import { quansync, type QuansyncFn } from 'quansync' import type { Buffer } from 'node:buffer' -import type { QuansyncFn } from 'quansync' /** * @link https://nodejs.org/api/fs.html#fspromisesreadfilepath-options */ export const readFile = quansync({ - sync: (path, options) => fs.readFileSync(path, options), - async: (path, options) => fs.promises.readFile(path, options), + sync: fs.readFileSync, + async: fs.promises.readFile as any, }) as QuansyncFn< Buffer, [ @@ -52,20 +53,16 @@ export const writeFile: QuansyncFn< options?: WriteFileOptions | undefined, ] > = quansync({ - sync: ( - file: PathLike, - data: string | NodeJS.ArrayBufferView, - options?: WriteFileOptions, - ) => fs.writeFileSync(file, data, options), - async: (file, data, options) => fs.promises.writeFile(file, data, options), + sync: fs.writeFileSync, + async: fs.promises.writeFile as any, }) /** * @link https://nodejs.org/api/fs.html#fspromisesunlinkpath */ export const unlink: QuansyncFn = quansync({ - sync: (path: PathLike) => fs.unlinkSync(path), - async: (path) => fs.promises.unlink(path), + sync: fs.unlinkSync, + async: fs.promises.unlink, }) /** @@ -75,16 +72,16 @@ export const access: QuansyncFn< void, [path: PathLike, mode?: number | undefined] > = quansync({ - sync: (path: PathLike, mode?: number) => fs.accessSync(path, mode), - async: (path, mode) => fs.promises.access(path, mode), + sync: fs.accessSync, + async: fs.promises.access, }) /** * @link https://nodejs.org/api/fs.html#fspromisesstatpath-options */ export const stat = quansync({ - sync: (path: PathLike, options) => fs.statSync(path, options), - async: (path, options) => fs.promises.stat(path, options), + sync: fs.statSync, + async: fs.promises.stat, }) as QuansyncFn< Stats, [path: PathLike, opts?: StatOptions & { bigint?: false | undefined }] @@ -96,8 +93,8 @@ export const stat = quansync({ QuansyncFn export const lstat = quansync({ - sync: (path: PathLike, options) => fs.lstatSync(path, options), - async: (path, options) => fs.promises.lstat(path, options), + sync: fs.lstatSync, + async: fs.promises.lstat, }) as typeof stat /** @@ -107,9 +104,8 @@ export const cp: QuansyncFn< void, [src: PathLike, dest: PathLike, mode?: number | undefined] > = quansync({ - sync: (src: PathLike, dest: PathLike, mode?: number) => - fs.copyFileSync(src, dest, mode), - async: (src, dest, mode) => fs.promises.copyFile(src, dest, mode), + sync: fs.copyFileSync, + async: fs.promises.copyFile, }) /** @@ -119,16 +115,16 @@ export const rm: QuansyncFn< void, [path: PathLike, options?: RmOptions | undefined] > = quansync({ - sync: (path: PathLike, options?: RmOptions) => fs.rmSync(path, options), - async: (path, options) => fs.promises.rm(path, options), + sync: fs.rmSync, + async: fs.promises.rm, }) /** * @link https://nodejs.org/api/fs.html#fspromisesmkdirpath-options */ export const mkdir = quansync({ - sync: (path: PathLike, options) => fs.mkdirSync(path, options), - async: (path, options) => fs.promises.mkdir(path, options), + sync: fs.mkdirSync, + async: fs.promises.mkdir, }) as QuansyncFn< string | undefined, [path: PathLike, options: MakeDirectoryOptions & { recursive: true }] @@ -149,17 +145,16 @@ export const mkdir = quansync({ */ export const rename: QuansyncFn = quansync({ - sync: (oldPath: PathLike, newPath: PathLike) => - fs.renameSync(oldPath, newPath), - async: (oldPath, newPath) => fs.promises.rename(oldPath, newPath), + sync: fs.renameSync, + async: fs.promises.rename, }) /** * @link https://nodejs.org/api/fs.html#fspromisesreaddirpath-options */ export const readdir = quansync({ - sync: (path: PathLike, options) => fs.readdirSync(path, options), - async: (path, options) => fs.promises.readdir(path, options), + sync: fs.readdirSync, + async: fs.promises.readdir, }) as QuansyncFn< string[], [ @@ -214,8 +209,24 @@ export const readdir = quansync({ * @link https://nodejs.org/api/fs.html#fspromisesrealpathpath-options */ export const realpath = quansync({ - sync: (path: PathLike, options) => fs.realpathSync(path, options), - async: (path, options) => fs.promises.realpath(path, options), + sync: fs.realpathSync, + async: fs.promises.realpath, +}) as QuansyncFn< + string, + [path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null] +> & + QuansyncFn & + QuansyncFn< + string | Buffer, + [path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null] + > + +/** + * @link https://nodejs.org/api/fs.html#fspromisesreadlinkpath-options + */ +export const readlink = quansync({ + sync: fs.readlinkSync, + async: fs.promises.readlink, }) as QuansyncFn< string, [path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null] @@ -225,3 +236,82 @@ export const realpath = quansync({ string | Buffer, [path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null] > + +/** + * @link https://nodejs.org/api/fs.html#fspromisessymlinktarget-path-type + */ +export const symlink: QuansyncFn< + void, + [target: PathLike, path: PathLike, type?: _symlink.Type | null] +> = quansync({ + sync: fs.symlinkSync, + async: fs.promises.symlink, +}) + +/** + * @link https://nodejs.org/api/fs.html#fspromiseschownpath-uid-gid + */ +export const chown: QuansyncFn< + void, + [path: PathLike, uid: number, gid: number] +> = quansync({ + sync: fs.chownSync, + async: fs.promises.chown, +}) + +/** + * @link https://nodejs.org/api/fs.html#fspromiseslchownpath-uid-gid + */ +export const lchown: QuansyncFn< + void, + [path: PathLike, uid: number, gid: number] +> = quansync({ + sync: fs.lchownSync, + async: fs.promises.lchown, +}) + +/** + * @link https://nodejs.org/api/fs.html#fspromiseschmodpath-mode + */ +export const chmod: QuansyncFn = quansync({ + sync: fs.chmodSync, + async: fs.promises.chmod, +}) + +/** + * @link https://nodejs.org/api/fs.html#fspromisesutimespath-atime-mtime + */ +export const utimes: QuansyncFn< + void, + [path: PathLike, atime: TimeLike, mtime: TimeLike] +> = quansync({ + sync: fs.utimesSync, + async: fs.promises.utimes, +}) + +/** + * @link https://nodejs.org/api/fs.html#fspromiseslutimespath-atime-mtime + */ +export const lutimes: QuansyncFn< + void, + [path: PathLike, atime: TimeLike, mtime: TimeLike] +> = quansync({ + sync: fs.lutimesSync, + async: fs.promises.lutimes, +}) + +/** + * @link https://nodejs.org/api/fs.html#fspromisesmkdtempprefix-options + */ +export const mkdtemp = quansync({ + sync: fs.mkdtempSync, + async: fs.promises.mkdtemp, +}) as QuansyncFn< + string, + [prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null] +> & + QuansyncFn & + QuansyncFn< + string | Buffer, + [prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null] + > diff --git a/tsdown.config.ts b/tsdown.config.ts index 628decb..eb27675 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -1,5 +1,4 @@ import { defineConfig } from 'tsdown' -import Quansync from 'unplugin-quansync/rolldown' export default defineConfig({ entry: ['./src/index.ts'], @@ -8,5 +7,4 @@ export default defineConfig({ clean: true, dts: { transformer: 'oxc' }, platform: 'node', - plugins: [Quansync()], })