Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upfeature-request - add [lazy] option `mkdirRecursive` to fs.writeFile[Sync] and fs.appendFile[Sync] #35775
Conversation
…and fs.writeFile[Sync]
|
Welcome @kaizhu256 and thanks for the pull request. I'm going to put this into Draft mode while it's being discussed. It will need tests and documentation before we can land it. |


Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesthis is proof-of-concept to implement feature-request #33559. if feedback is positive/viable, then i will proceed with adding documentation, tests, and other checklist items.
motivation
this feature is intended to improve ergonomics/simplify-scripting-tasks when:
in above tasks, user often has no deterministic-knowledge on directory-structure before file-creation.
this feature allows user to lazily create ad-hoc directory-structures as need during file-creation using ergonomic syntax:
performance impact and benchmark
the benchmark (in windows 10) comparing this pr-branch against master-branch shows no-performance-impact on fs.writeFile[Sync] or fs.appendFile[Sync] when option
{ mkdirRecursive: true }is not used.when option
{ mkdirRecursive: true }is enabled:at lazy-adhoc-directory-creation (vs eager-determistic-directory-creation)
at lazy-adhoc-directory-creation (vs eager-determistic-directory-creation)
windows benchmark result
the following results should be reproducible by following benchmark instructions at https://github.com/kaizhu256/node/tree/benchmark.fs.writeFile.mkdirRecursive#run-windows-benchmark
bikeshed of name
mkdirRecursivewhen scripting the benchmark, i realized the name
mkdirRecursiveis tedious to type. it also doesn't convey the lazy-nature of this operation, or the-pattribute. am open to other naming suggestions (e.g.{ mkdirp: true })