Repository navigation
Port File System APIs in Deno namespace to @std/fs #6255
Copy link
Copy link
Open
Labels
Description
We aim to make @std/fs cross-runtime (ref #4313). To achieve that we need to port FS APIs from Deno namespace (with Node.js compatibility)
- Deno FS APIs https://docs.deno.com/api/deno/file-system
- deno-shim https://github.com/denoland/node_shims/tree/main/packages/shim-deno/src/deno/stable/functions
Classes
- FsFile feat(fs/unstable): add open, openSync, and FsFile class #6524
- close feat(fs/unstable): add open, openSync, and FsFile class #6524
- isTerminal feat(fs/unstable): add open, openSync, and FsFile class #6524
- lock
- lockSync
- read feat(fs/unstable): add open, openSync, and FsFile class #6524
- readSync feat(fs/unstable): add open, openSync, and FsFile class #6524
- setRaw
- stat feat(fs/unstable): add open, openSync, and FsFile class #6524
- statSync feat(fs/unstable): add open, openSync, and FsFile class #6524
- sync feat(fs/unstable): add open, openSync, and FsFile class #6524
- syncSync feat(fs/unstable): add open, openSync, and FsFile class #6524
- syncData feat(fs/unstable): add open, openSync, and FsFile class #6524
- syncDataSync feat(fs/unstable): add open, openSync, and FsFile class #6524
- truncate feat(fs/unstable): add open, openSync, and FsFile class #6524
- truncateSync feat(fs/unstable): add open, openSync, and FsFile class #6524
- unlock
- utime feat(fs/unstable): add open, openSync, and FsFile class #6524
- utimeSync feat(fs/unstable): add open, openSync, and FsFile class #6524
- write feat(fs/unstable): add open, openSync, and FsFile class #6524
- writeSync feat(fs/unstable): add open, openSync, and FsFile class #6524
Functions
- chmod feat(fs/unstable): add chmod and chmodSync #6343
- chmodSync feat(fs/unstable): add chmod and chmodSync #6343
- chown feat(fs/unstable): add chown and chownSync #6552
- chownSync feat(fs/unstable): add chown and chownSync #6552
- copyFile feat(fs/unstable): add
copyFileandcopyFileSync#6425 - copyFileSync feat(fs/unstable): add
copyFileandcopyFileSync#6425 - create feat(fs/unstable): add create and createSync #6600
- createSync feat(fs/unstable): add create and createSync #6600
- link feat(fs/unstable): add link and linkSync #6369
- linkSync feat(fs/unstable): add link and linkSync #6369
- lstat feat(fs/unstable): add
fs.lstat#6276 - lstatSync feat(fs/unstable): add statSync and lstatSync #6300
- makeTempDir feat(fs/unstable): add makeTempDir and makeTempDirSync #6391
- makeTempDirSync feat(fs/unstable): add makeTempDir and makeTempDirSync #6391
- makeTempFile feat(fs/unstable): add makeTempFile and makeTempFileSync #6469
- makeTempFileSync feat(fs/unstable): add makeTempFile and makeTempFileSync #6469
- mkdir feat(fs/unstable): add mkdir and mkdirSync #6436
- mkdirSync feat(fs/unstable): add mkdir and mkdirSync #6436
- open feat(fs/unstable): add open, openSync, and FsFile class #6524
- openSync feat(fs/unstable): add open, openSync, and FsFile class #6524
- readDir feat(fs/unstable): add readDir #6338
- readDirSync feat(fs/unstable): add readDirSync #6381
- readFile feat(fs/unstable): add readFile and readFileSync #6394
- readFileSync feat(fs/unstable): add readFile and readFileSync #6394
- readLink feat(fs/unstable): add readLink and readLinkSync #6373
- readLinkSync feat(fs/unstable): add readLink and readLinkSync #6373
- readTextFile feat(fs/unstable): add readTextFileSync and readTextFile #6405
- readTextFileSync feat(fs/unstable): add readTextFileSync and readTextFile #6405
- realPath feat(fs/unstable): add realPath and realPathSync #6366
- realPathSync feat(fs/unstable): add realPath and realPathSync #6366
- remove feat(fs/unstable): add
removeandremoveSyncapi. #6438 - removeSync feat(fs/unstable): add
removeandremoveSyncapi. #6438 - rename feat(fs/unstable): add rename #6379
- renameSync feat(fs/unstable): add renameSync #6396
- stat feat(fs/unstable): add
fs.stat#6258 - statSync feat(fs/unstable): add statSync and lstatSync #6300
- symlink feat(fs/unstable): add symlink and symlinkSync #6352
- symlinkSync feat(fs/unstable): add symlink and symlinkSync #6352
- truncate feat(fs/unstable): add truncate and truncateSync #6416
- truncateSync feat(fs/unstable): add truncate and truncateSync #6416
- umask feat(fs/unstable): add umask #6454
- utime feat(fs/unstable): add utime and utimeSync #6446
- utimeSync feat(fs/unstable): add utime and utimeSync #6446
- watchFs
- writeFile feat(fs/unstable): add writeFile and writeFileSync #6444
- writeFileSync feat(fs/unstable): add writeFile and writeFileSync #6444
- writeTextFile feat(fs/unstable): add writeTextFile and writeTextFileSync #6463
- writeTextFileSync feat(fs/unstable): add writeTextFile and writeTextFileSync #6463
shim-deno package already implements Node.js compatible Deno APIs. We can borrow the code from there for the Node.js compatibility part https://github.com/denoland/node_shims/tree/main/packages/shim-deno
Reactions are currently unavailable
Activity
feat(fs/unstable): added DirEntry type and conversion function denola…
feat(fs/unstable): added readDir function and test denoland#6255
feat(fs/unstable): added import references for readDir denoland#6255
eryue0220 commentedon Feb 5, 2025
Are
unlinkandunlinkSyncignored?kt3k commentedon Feb 5, 2025
It looks like Deno doesn't have
unlinkandunlinkSync. Instead it hasremoveandremoveSync. This list tries to mirror Deno FS APIs.eryue0220 commentedon Feb 5, 2025
Considering compatibility with Node, should
fs.unlinkandfs.unlinkSyncalso be provided?kt3k commentedon Feb 6, 2025
Do you suggest
unlinkwould be an alias toremove?eryue0220 commentedon Feb 6, 2025
Yes, except for compatibility,
linkandunlinkis a pair, which is make more sense and more understandable thanremove. WDYT?kt3k commentedon Feb 6, 2025
Looked at the docs again, (Deno's)
removehas an option likerecursive(it can remove the entire directory), butunlink(of Node) doesn't. I feelunlinkcan't replaceremove, and it feels like a limited version ofremove.BTW Node.js also has
rmwhich is similar to Deno'sremove.jbronder commentedon Feb 16, 2025
TLDR: As a general question, should there be stronger checking of arguments when using the new
@std/fsAPIs under a Node.js runtime?For example, the
symlinkandsymlinkSyncAPIs in Node.js acceptstring | URL | Buffertypes forpathandtargetparameters whereas for Deno, the same APIs would requirestring | URLtypes (noBuffer) for these parameters. To meet the design intent of@std/fsAPIs satisfying Deno's version of this API, would it be sensible to require rejecting/throwing withTypeErrors when passingBufferobjects when using the@std/fsAPIs under a Node.js runtime?TypeErrorBufferchecking would also affect other@std/fsAPIs:rename[Sync],realPath[Sync], et al.Similarly, the Node.js versions of
readFile[Sync]andwriteFile[Sync]acceptstring | URL | Buffer | FileHandle/number(numberfor file descriptors,fd) types for thepathparameter. When compared with Deno,pathis restricted tostring | URLtypes.TypeErrors would similarly need to be implemented when attempting to passBufferandFileHandle/fdtypes in the@std/fsversions ofread[Text]File[Sync]andwrite[Text]File[Sync]when running Node.js.I can either share a proposed approach for error checking here or in a forthcoming PR, whichever you prefer. I'd also be curious to know what your thoughts are about adding
TypeErrorchecking for these APIs when running under Node.js.