-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
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?
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 702 702
Lines 206760 206773 +13
Branches 39776 39777 +1
==========================================
- Hits 182531 182508 -23
- Misses 16235 16269 +34
- Partials 7994 7996 +2
🚀 New features to boost your workflow:
|
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). |
741088b
to
8ff0b20
Compare
@nodejs/tsc do we want this in v25.x? If so, we'd need at least one more approval |
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