Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4430,12 +4430,15 @@ import { opendir } from 'node:fs/promises';
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/62173
description: Runtime deprecation.
- version: v25.7.0
pr-url: https://github.com/nodejs/node/pull/61632
description: Documentation-only deprecation.
-->
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
Expand Down
16 changes: 14 additions & 2 deletions lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const {
} = require('internal/errors');

const {
getDeprecationWarningEmitter,
kEmptyObject,
normalizeEncoding,
} = require('internal/util');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 });
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-stream-duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Loading