@@ -4104,6 +4104,52 @@ The `node:_http_agent`, `node:_http_client`, `node:_http_common`, `node:_http_in
4104
4104
` node:_http_outgoing ` and ` node:_http_server ` modules are deprecated as they should be considered
4105
4105
an internal nodejs implementation rather than a public facing API, use ` node:http ` instead.
4106
4106
4107
+ ### DEP0200: Closing fs.Dir on garbage collection
4108
+
4109
+ <!-- YAML
4110
+ changes:
4111
+ - version: REPLACEME
4112
+ pr-url: https://github.com/nodejs/node/pull/59839
4113
+ description: Documentation-only deprecation.
4114
+ -->
4115
+
4116
+ Type: Runtime
4117
+
4118
+ Allowing a [ ` fs.Dir ` ] [ ] object to be closed on garbage collection is
4119
+ deprecated. In the future, doing so might result in a thrown error that will
4120
+ terminate the process.
4121
+
4122
+ Please ensure that all ` fs.Dir ` objects are explicitly closed using
4123
+ ` Dir.prototype.close() ` or ` using ` keyword:
4124
+
4125
+ ``` mjs
4126
+ import { opendir } from ' node:fs/promises' ;
4127
+
4128
+ {
4129
+ await using dir = await opendir (' /async/disposable/directory' );
4130
+ } // Closed by dir[Symbol.asyncDispose]()
4131
+
4132
+ {
4133
+ using dir = await opendir (' /sync/disposable/directory' );
4134
+ } // Closed by dir[Symbol.dispose]()
4135
+
4136
+ {
4137
+ const dir = await opendir (' /unconditionally/iterated/directory' );
4138
+ for await (const entry of dir ) {
4139
+ // process an entry
4140
+ } // Closed by iterator
4141
+ }
4142
+
4143
+ {
4144
+ let dir;
4145
+ try {
4146
+ dir = await opendir (' /legacy/closeable/directory' );
4147
+ } finally {
4148
+ await dir? .close ();
4149
+ }
4150
+ }
4151
+ ` ` `
4152
+
4107
4153
[DEP0142]: #dep0142-repl_builtinlibs
4108
4154
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
4109
4155
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
@@ -4159,6 +4205,7 @@ an internal nodejs implementation rather than a public facing API, use `node:htt
4159
4205
[` ecdh .setPublicKey ()` ]: crypto.md#ecdhsetpublickeypublickey-encoding
4160
4206
[` emitter .listenerCount (eventName)` ]: events.md#emitterlistenercounteventname-listener
4161
4207
[` events .listenerCount (emitter, eventName)` ]: events.md#eventslistenercountemitter-eventname
4208
+ [` fs .Dir ` ]: fs.md#class-fsdir
4162
4209
[` fs .FileHandle ` ]: fs.md#class-filehandle
4163
4210
[` fs .access ()` ]: fs.md#fsaccesspath-mode-callback
4164
4211
[` fs .appendFile ()` ]: fs.md#fsappendfilepath-data-options-callback
0 commit comments