stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

feat: add `fs/mkdir`

Open C0ldSmi1e opened this issue 1 year ago • 2 comments

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:

  • resolves #2116

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

C0ldSmi1e avatar Apr 22 '24 07:04 C0ldSmi1e

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!

C0ldSmi1e avatar Apr 22 '24 07:04 C0ldSmi1e

Test report. image

C0ldSmi1e avatar Apr 24 '24 06:04 C0ldSmi1e