stream: promote DEP0201 to runtime deprecation by Renegade334 · Pull Request #62173 · nodejs/node · GitHub
Skip to content
Merged
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
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
Loading