Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port File System APIs in Deno namespace to @std/fs #6255

Open
38 of 49 tasks
kt3k opened this issue Dec 12, 2024 · 7 comments
Open
38 of 49 tasks

Port File System APIs in Deno namespace to @std/fs #6255

kt3k opened this issue Dec 12, 2024 · 7 comments
Labels
enhancement New feature or request fs

Comments

@kt3k
Copy link
Member

kt3k commented Dec 12, 2024

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)

Classes

  • FsFile

Functions

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

@kt3k kt3k added enhancement New feature or request fs labels Dec 12, 2024
@kt3k kt3k pinned this issue Dec 12, 2024
jbronder added a commit to jbronder/deno_std that referenced this issue Jan 8, 2025
jbronder added a commit to jbronder/deno_std that referenced this issue Jan 8, 2025
@eryue0220
Copy link
Contributor

Are unlink and unlinkSync ignored?

@kt3k
Copy link
Member Author

kt3k commented Feb 5, 2025

It looks like Deno doesn't have unlink and unlinkSync. Instead it has remove and removeSync. This list tries to mirror Deno FS APIs.

@eryue0220
Copy link
Contributor

Considering compatibility with Node, should fs.unlink and fs.unlinkSync also be provided?

@kt3k
Copy link
Member Author

kt3k commented Feb 6, 2025

Do you suggest unlink would be an alias to remove?

@eryue0220
Copy link
Contributor

Yes, except for compatibility, link and unlink is a pair, which is make more sense and more understandable than remove. WDYT?

@kt3k
Copy link
Member Author

kt3k commented Feb 6, 2025

Looked at the docs again, (Deno's) remove has an option like recursive (it can remove the entire directory), but unlink (of Node) doesn't. I feel unlink can't replace remove, and it feels like a limited version of remove.

BTW Node.js also has rm which is similar to Deno's remove.

@jbronder
Copy link
Contributor

TLDR: As a general question, should there be stronger checking of arguments when using the new @std/fs APIs under a Node.js runtime?

For example, the symlink and symlinkSync APIs in Node.js accept string | URL | Buffer types for path and target parameters whereas for Deno, the same APIs would require string | URL types (no Buffer) for these parameters. To meet the design intent of @std/fs APIs satisfying Deno's version of this API, would it be sensible to require rejecting/throwing with TypeErrors when passing Buffer objects when using the @std/fs APIs under a Node.js runtime? TypeError Buffer checking would also affect other @std/fs APIs: rename[Sync], realPath[Sync], et al.

Similarly, the Node.js versions of readFile[Sync] and writeFile[Sync] accept string | URL | Buffer | FileHandle/number (number for file descriptors, fd) types for the path parameter. When compared with Deno, path is restricted to string | URL types. TypeErrors would similarly need to be implemented when attempting to pass Buffer and FileHandle/fd types in the @std/fs versions of read[Text]File[Sync] and write[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 TypeError checking for these APIs when running under Node.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fs
Projects
None yet
Development

No branches or pull requests

3 participants