-
-
Notifications
You must be signed in to change notification settings - Fork 33k
fs: runtime deprecate closing fs.Dir
on garbage collection
#58850
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
base: main
Are you sure you want to change the base?
fs: runtime deprecate closing fs.Dir
on garbage collection
#58850
Conversation
719ebb4
to
39e8ae5
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58850 +/- ##
==========================================
- Coverage 88.28% 88.26% -0.02%
==========================================
Files 701 701
Lines 206774 206787 +13
Branches 39772 39778 +6
==========================================
- Hits 182545 182522 -23
- Misses 16234 16285 +51
+ Partials 7995 7980 -15
🚀 New features to boost your workflow:
|
doc/api/deprecations.md
Outdated
import { opendir } from 'node:fs/promises'; | ||
|
||
{ | ||
await using dir = await opendir('/async/disposable/directory'); | ||
} // Closed by dir[Symbol.asyncDispose]() | ||
|
||
{ | ||
using dir = await opendir('/sync/disposable/directory'); | ||
} // Closed by dir[Symbol.dispose]() | ||
|
||
{ | ||
let dir; | ||
try { | ||
dir = await opendir('/legacy/closeable/directory'); | ||
} finally { | ||
await dir?.close(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is lacking the (IMO) most prominent use-case for opendir
: iterating on it. Can you add a test that iterates on a Dir
and validates that it does not trigger any warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the iteration example in this snippet as well please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, added.
39e8ae5
to
c60424b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We should probably land this as doc-only first, if you can open another PR that lands first, that'd be great, otherwise I can do it for you
Sure, i'll make PR with doc-only version of this (or rather, formalizing already existing runtime warning as deprecation). |
The DEP0137 is going to be End-of-Life in the next major release.
I think we should align closing
fs.Dir
on GC and deprecate it as well. Now that explicit resource management is available, closing dirs properly should become easier for userland.Given that it already spams
Warning
s in stderr, it would make sense to make this deprecation runtime right away.cc @nodejs/fs @nodejs/tsc