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

feat: add fs/mkdir #2198

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

feat: add fs/mkdir #2198

wants to merge 3 commits into from

Conversation

Daniel777y
Copy link
Contributor

@Daniel777y Daniel777y commented Apr 22, 2024

If applied, this commit will add the package fs/mkdir

Description

What is the purpose of this pull request?

This pull request adds the package fs/mkdir for creating a directory asynchronously and synchronously.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

  • When the recursive option is set to true, I have to handle some potential error, and I mainly borrowed the idea from mkdirp, but I am not sure if these error codes are enough here.
  • This package aligns with the mkdir in node, so it will return undefined in some cases. But I noticed some similar stdlib packages return null, so does mkdir also return null instead of undefined?
  • When generating examples and doctest, sometimes it triggers errors, but I am not sure the reasons.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@Daniel777y
Copy link
Contributor Author

Daniel777y commented Apr 22, 2024

Hi, @kgryte @Planeshifter. I've implemented this package.

The main idea is, if mkdir is called without options argument or the recursive option is false, use the native mkdir. Otherwise, recursively create new directories. This way, I don't need to check the version of node.

Notes:

  • I mainly consulted mkdirp about error handling and polyfill.
  • This package aligns with the latest version of mkdir (usage and return). It also explicitly handle error for sync version (return error object), just like other fs packages in stdlib.
  • This package uses stat and rmdir from fs, which can be replaced with @stdlib/fs/stat and @stdlib/fs/rmdir in the future.
  • It didn't pass two checks because the fixtures directories are not pushed.

I am looking forward to your suggestions.

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In examples/index.js, I used rmdirSync to restore to pass the doctest. I know this is a bad idea but I would like to know what the best practice is.

@Daniel777y
Copy link
Contributor Author

Test report.
image

@Planeshifter Planeshifter self-requested a review May 8, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add fs/mkdir
1 participant