From 9b2ae286adeba0cc8bf3ef8ecd1a9e418328f990 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 31 May 2025 09:40:27 -0700 Subject: [PATCH 1/2] fs: move fs stream open method to eol The `open()` method on fs read and write streams has been deprecated for many years. It's time to remove it while still allowing the open method to be monkeypatched since that's still apparently a thing. --- doc/api/deprecations.md | 5 ++++- lib/internal/fs/streams.js | 13 +------------ test/parallel/test-fs-read-stream-patch-open.js | 15 ++------------- test/parallel/test-fs-write-stream-patch-open.js | 15 +++------------ 4 files changed, 10 insertions(+), 38 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index c0f762c54860a6..7a30ad62bc1c82 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2807,12 +2807,15 @@ an officially supported API. -Type: Runtime +Type: End-of-Life [`WriteStream.open()`][] and [`ReadStream.open()`][] are undocumented internal APIs that do not make sense to use in userland. File streams should always be diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 43f06d0104de61..79345a656ebdeb 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -19,7 +19,6 @@ const { ERR_SYSTEM_ERROR, } = require('internal/errors').codes; const { - deprecate, kEmptyObject, } = require('internal/util'); const { @@ -52,7 +51,7 @@ function _construct(callback) { return; } - if (stream.open !== openWriteFs && stream.open !== openReadFs) { + if (typeof stream.open === 'function') { // Backwards compat for monkey patching open(). const orgEmit = stream.emit; stream.emit = function(...args) { @@ -238,11 +237,6 @@ ObjectDefineProperty(ReadStream.prototype, 'autoClose', { }, }); -const openReadFs = deprecate(function() { - // Noop. -}, 'ReadStream.prototype.open() is deprecated', 'DEP0135'); -ReadStream.prototype.open = openReadFs; - ReadStream.prototype._construct = _construct; ReadStream.prototype._read = function(n) { @@ -407,11 +401,6 @@ ObjectDefineProperty(WriteStream.prototype, 'autoClose', { }, }); -const openWriteFs = deprecate(function() { - // Noop. -}, 'WriteStream.prototype.open() is deprecated', 'DEP0135'); -WriteStream.prototype.open = openWriteFs; - WriteStream.prototype._construct = _construct; function writeAll(data, size, pos, cb, retries = 0) { diff --git a/test/parallel/test-fs-read-stream-patch-open.js b/test/parallel/test-fs-read-stream-patch-open.js index 6fa97737b187a3..fbca4f578d4cf0 100644 --- a/test/parallel/test-fs-read-stream-patch-open.js +++ b/test/parallel/test-fs-read-stream-patch-open.js @@ -2,16 +2,5 @@ const common = require('../common'); const fs = require('fs'); -common.expectWarning( - 'DeprecationWarning', - 'ReadStream.prototype.open() is deprecated', 'DEP0135'); -const s = fs.createReadStream('asd') - // We don't care about errors in this test. - .on('error', () => {}); -s.open(); - -process.nextTick(() => { - // Allow overriding open(). - fs.ReadStream.prototype.open = common.mustCall(); - fs.createReadStream('asd'); -}); +fs.ReadStream.prototype.open = common.mustCall(); +fs.createReadStream('asd'); diff --git a/test/parallel/test-fs-write-stream-patch-open.js b/test/parallel/test-fs-write-stream-patch-open.js index 9e7bb06af528a5..88c4db469d5de2 100644 --- a/test/parallel/test-fs-write-stream-patch-open.js +++ b/test/parallel/test-fs-write-stream-patch-open.js @@ -22,15 +22,6 @@ if (process.argv[2] !== 'child') { } // Child - -common.expectWarning( - 'DeprecationWarning', - 'WriteStream.prototype.open() is deprecated', 'DEP0135'); -const s = fs.createWriteStream(`${tmpdir.path}/out`); -s.open(); - -process.nextTick(() => { - // Allow overriding open(). - fs.WriteStream.prototype.open = common.mustCall(); - fs.createWriteStream('asd'); -}); +// Allow overriding open(). +fs.WriteStream.prototype.open = common.mustCall(); +fs.createWriteStream('asd'); From 493fb053927491d34edbaef67eabc02994d7f5fc Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 31 May 2025 09:44:06 -0700 Subject: [PATCH 2/2] Update doc/api/deprecations.md --- doc/api/deprecations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 7a30ad62bc1c82..a70bc6d7e14240 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2808,7 +2808,7 @@ an officially supported API.