From 0a1002cf697440b5b3e52a6b496f14930ef06ba2 Mon Sep 17 00:00:00 2001 From: Renegade334 Date: Mon, 9 Mar 2026 21:33:40 +0000 Subject: [PATCH] stream: promote DEP0201 to runtime deprecation --- doc/api/deprecations.md | 5 ++++- lib/internal/webstreams/adapters.js | 16 ++++++++++++++-- test/parallel/test-stream-duplex.js | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 892ecb9f2b4fc6..683efd69c7fe30 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -4430,12 +4430,15 @@ import { opendir } from 'node:fs/promises'; -Type: Documentation-only +Type: Runtime Passing the `type` option to [`Duplex.toWeb()`][] is deprecated. To specify the type of the readable half of the constructed readable-writable pair, use the diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index 1ffb19b4f59a31..188f715a62d3c1 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -71,6 +71,7 @@ const { } = require('internal/errors'); const { + getDeprecationWarningEmitter, kEmptyObject, normalizeEncoding, } = require('internal/util'); @@ -650,6 +651,12 @@ function newStreamReadableFromReadableStream(readableStream, options = kEmptyObj return readable; } +const emitDEP0201 = getDeprecationWarningEmitter( + 'DEP0201', + "Passing 'options.type' to Duplex.toWeb() is deprecated. " + + "To specify the ReadableStream type, use 'options.readableType'.", + newReadableWritablePairFromDuplex); + /** * @typedef {import('./readablestream').ReadableWritablePair * } ReadableWritablePair @@ -677,10 +684,15 @@ function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) { const readableOptions = { __proto__: null, - // DEP0201: 'options.type' is a deprecated alias for 'options.readableType' - type: options.readableType ?? options.type, + type: options.readableType, }; + if (options.readableType == null && options.type != null) { + // 'options.type' is a deprecated alias for 'options.readableType' + emitDEP0201(); + readableOptions.type = options.type; + } + if (isDestroyed(duplex)) { const writable = new WritableStream(); const readable = new ReadableStream({ type: readableOptions.type }); diff --git a/test/parallel/test-stream-duplex.js b/test/parallel/test-stream-duplex.js index 862e1fec0baf6c..de67290a7e76cd 100644 --- a/test/parallel/test-stream-duplex.js +++ b/test/parallel/test-stream-duplex.js @@ -157,4 +157,6 @@ process.on('exit', () => { // Ensure that the originally-named `options.type` still works as an alias for `options.readableType` // `getReader({ mode: 'byob' })` throws if the underlying ReadableStream is not a byte stream Duplex.toWeb(duplex, { type: 'bytes' }).readable.getReader({ mode: 'byob' }); + common.expectWarning('DeprecationWarning', + [/Passing 'options\.type' to Duplex\.toWeb\(\) is deprecated/, 'DEP0201']); }