Skip to content

Commit 0a1002c

Browse files
committed
stream: promote DEP0201 to runtime deprecation
1 parent 70b3570 commit 0a1002c

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4430,12 +4430,15 @@ import { opendir } from 'node:fs/promises';
44304430
44314431
<!-- YAML
44324432
changes:
4433+
- version: REPLACEME
4434+
pr-url: https://github.com/nodejs/node/pull/62173
4435+
description: Runtime deprecation.
44334436
- version: v25.7.0
44344437
pr-url: https://github.com/nodejs/node/pull/61632
44354438
description: Documentation-only deprecation.
44364439
-->
44374440
4438-
Type: Documentation-only
4441+
Type: Runtime
44394442
44404443
Passing the `type` option to [`Duplex.toWeb()`][] is deprecated. To specify the
44414444
type of the readable half of the constructed readable-writable pair, use the

lib/internal/webstreams/adapters.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const {
7171
} = require('internal/errors');
7272

7373
const {
74+
getDeprecationWarningEmitter,
7475
kEmptyObject,
7576
normalizeEncoding,
7677
} = require('internal/util');
@@ -650,6 +651,12 @@ function newStreamReadableFromReadableStream(readableStream, options = kEmptyObj
650651
return readable;
651652
}
652653

654+
const emitDEP0201 = getDeprecationWarningEmitter(
655+
'DEP0201',
656+
"Passing 'options.type' to Duplex.toWeb() is deprecated. " +
657+
"To specify the ReadableStream type, use 'options.readableType'.",
658+
newReadableWritablePairFromDuplex);
659+
653660
/**
654661
* @typedef {import('./readablestream').ReadableWritablePair
655662
* } ReadableWritablePair
@@ -677,10 +684,15 @@ function newReadableWritablePairFromDuplex(duplex, options = kEmptyObject) {
677684

678685
const readableOptions = {
679686
__proto__: null,
680-
// DEP0201: 'options.type' is a deprecated alias for 'options.readableType'
681-
type: options.readableType ?? options.type,
687+
type: options.readableType,
682688
};
683689

690+
if (options.readableType == null && options.type != null) {
691+
// 'options.type' is a deprecated alias for 'options.readableType'
692+
emitDEP0201();
693+
readableOptions.type = options.type;
694+
}
695+
684696
if (isDestroyed(duplex)) {
685697
const writable = new WritableStream();
686698
const readable = new ReadableStream({ type: readableOptions.type });

test/parallel/test-stream-duplex.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,6 @@ process.on('exit', () => {
157157
// Ensure that the originally-named `options.type` still works as an alias for `options.readableType`
158158
// `getReader({ mode: 'byob' })` throws if the underlying ReadableStream is not a byte stream
159159
Duplex.toWeb(duplex, { type: 'bytes' }).readable.getReader({ mode: 'byob' });
160+
common.expectWarning('DeprecationWarning',
161+
[/Passing 'options\.type' to Duplex\.toWeb\(\) is deprecated/, 'DEP0201']);
160162
}

0 commit comments

Comments
 (0)