Skip to content

feat(DEP0201): add Duplex.toWeb readableType codemod - #570

Open
FrustratedBoy420 wants to merge 2 commits into
nodejs:mainfrom
FrustratedBoy420:feat/dep0201-duplex-toweb-readabletype
Open

FrustratedBoy420 wants to merge 2 commits into
nodejs:mainfrom
FrustratedBoy420:feat/dep0201-duplex-toweb-readabletype

Conversation

@FrustratedBoy420

@FrustratedBoy420 FrustratedBoy420 commented Nov 12, 2026 •

Copy link
Copy Markdown

Closes #559

What

Adds a new recipe, @nodejs/duplex-toweb-readabletype, for DEP0201. The recipe renames the deprecated type option passed to Duplex.toWeb() to readableType.

 import { Duplex } from 'node:stream';

-const pair = Duplex.toWeb(stream, { type: 'bytes' });
+const pair = Duplex.toWeb(stream, { readableType: 'bytes' });

How

  • Resolves Duplex.toWeb from stream and node:stream with getModuleDependencies and resolveBindingPath. This covers CommonJS and ESM, plus namespace, default, destructured, and aliased imports.
  • Only rewrites inline object literals passed as the second argument. Other options and the original value expression are preserved, so the value is still evaluated exactly once.
  • Expands shorthand { type } to { readableType: type } without renaming the variable.
  • Keeps the quote style of string keys ('type' becomes 'readableType').

What it skips (with a warning)

Following the guidance in the issue, the call is left unchanged and a file:line:column warning is printed when the options contain:

  • both type and readableType, because Node.js uses readableType ?? type and removing type could change behaviour;
  • spread elements, computed keys, getters, setters, methods, or duplicate type keys.

Options passed as a variable (Duplex.toWeb(stream, options)) are left unchanged without a warning, because the object may be shared or mutated elsewhere.

Tests

9 fixtures: ESM named, ESM namespace, ESM default, CJS aliased destructuring with shorthand, CJS namespace with string keys, TypeScript, already-migrated code (idempotency), conflicting/unsafe options, and unrelated APIs (Readable.toWeb, a local Duplex, plain objects, a third argument).

  • npm test in the recipe: 9 passed
  • biome lint: clean
  • npm run type-check: clean

AI assistance

This PR was written with help from Claude Code (claude-opus-5-5), following the OpenJS AI Coding Assistants Policy. All commits carry an Assisted-by: Claude Code (claude-opus-5-5) trailer. I take responsibility for this submission.

Rename the deprecated `type` option passed to `Duplex.toWeb()` to
`readableType` in inline options objects. Resolve `Duplex` from `stream`
and `node:stream` across CommonJS and ESM, including namespace, default,
destructured, and aliased imports. Expand shorthand `{ type }` to
`{ readableType: type }`.

Leave calls unchanged and warn when the options contain both keys,
spreads, computed keys, getters, setters, methods, or duplicate `type`
keys, so runtime behaviour is preserved.

Closes nodejs#559

Assisted-by: Claude Code (claude-opus-5-5)
Copilot AI balanced review requested due to automatic review settings November 12, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@AugustinMauroy AugustinMauroy left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you read and apply rule of https://ai-coding-assistants-policy.openjsf.org/

@AugustinMauroy

Copy link
Copy Markdown
Member

in term of code LGMT !

@FrustratedBoy420

Copy link
Copy Markdown
Author

Thanks for the review, @AugustinMauroy, and for pointing me to the policy. I've read it and updated the PR description with an AI assistance section. The commit has a Co-Authored-By: Claude trailer rather than Assisted-by; I'd rather not force-push over your review, so could the squash message use Assisted-by: Claude Code (claude-opus-5-5) instead? Happy to rewrite the commit if you prefer.

@FrustratedBoy420
FrustratedBoy420 force-pushed the feat/dep0201-duplex-toweb-readabletype branch from 8a0d1c3 to 1d03bf2 Compare November 13, 2026 10:03
@FrustratedBoy420

Copy link
Copy Markdown
Author

Update: I've rewritten the commit trailer to Assisted-by: Claude Code (claude-opus-5-5) and force-pushed, so no change to the squash message is needed. The code is unchanged.

@FrustratedBoy420

Copy link
Copy Markdown
Author

Thanks for the review and approval, @AugustinMauroy!

@FrustratedBoy420

This comment was marked as spam.

@FrustratedBoy420

Copy link
Copy Markdown
Author

@brunocroh @JakobJingleheimer this already has an approval from @AugustinMauroy and CI is green. Could one of you give it a second review? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(DEP0201): migrate Duplex.toWeb() options from type to readableType

3 participants