feat(DEP0194): migrate http2 priority signalling#246
feat(DEP0194): migrate http2 priority signalling#246AugustinMauroy wants to merge 17 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new codemod recipe to handle Node.js deprecation DEP0194 by automatically removing HTTP/2 priority-related options and methods from codebases. The codemod removes priority properties from http2.connect(), session.request(), and client.settings() calls, as well as entire stream.priority() method invocations.
Key Changes:
- Implements AST transformation logic to detect and remove deprecated HTTP/2 priority signaling code
- Provides comprehensive test coverage for CommonJS and ESM imports across multiple usage scenarios
- Includes complete recipe configuration and documentation
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| recipes/http2-priority-signaling/src/workflow.ts | Core transformation logic implementing removal of priority-related code |
| recipes/http2-priority-signaling/workflow.yaml | Workflow configuration defining the codemod execution |
| recipes/http2-priority-signaling/package.json | Package metadata and dependencies |
| recipes/http2-priority-signaling/codemod.yaml | Codemod registry configuration |
| recipes/http2-priority-signaling/README.md | Documentation explaining the codemod's purpose and usage |
| recipes/http2-priority-signaling/tests/input/*.js | Test input files covering different priority removal scenarios |
| recipes/http2-priority-signaling/tests/expected/*.js | Expected output files showing correct transformation results |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Bruno I tried to solve issue that you had found but idk if there are a better way to accomplish that. |
In #248, I handled a very similar scenario. What I did there was identify the function that returns directory objects, track those variables, and check if their methods were invoked. I think you need to do something similar here with the session/stream. For example, identify the variable named session, get the scope where it’s defined, and check if that variable uses the deprecated method within that scope. const http2 = require('node:http2')
function ex() {
let session = http2.connect(/* ... */)
session.settigns(/* ... */)
}
let session = {
settings: () => console.log('this function cannot be removed/updated by codemod')
}
let anyName = {
settings: () => console.log('this function cannot be removed/updated by codemod')
}
session.settings()
anyName.settings()To do that, you probably need something like this:
|
|
Normally it's fine, but I admit it's more complex than expected. |
If we're not sure, let's ask someone who would know rather than guess. Perhaps James Snell? |
http2-priority-signaling): introduce|
It's been a bit since I've thought about this but generally lgtm. |
|
Thank you @jasnell 🙏 |
brunocroh
left a comment
There was a problem hiding this comment.
I leave some nitpicking coments, but feel free to land it, it is g2g
Co-Authored-By: Bruno Rodrigues <swe@brunocroh.com>
| import { | ||
| getNodeImportStatements, | ||
| getNodeImportCalls, | ||
| } from '@nodejs/codemod-utils/ast-grep/import-statement'; |
There was a problem hiding this comment.
nit: getModuleDependencies
| ...getNodeImportCalls(root, 'http2'), | ||
| ]; | ||
|
|
||
| // If any import do nothing |
There was a problem hiding this comment.
| // If any import do nothing | |
| // If no imports, nothing to do |
| ...rootNode.findAll({ rule: { pattern: '$HTTP2.connect($$$_ARGS)' } }), | ||
| // Also include direct calls when `connect` is imported as a named binding or alias (e.g., `connect(...)` or `bar(...)`). | ||
| ...Array.from(connectCallees).flatMap((callee) => { | ||
| // If callee already includes a dot (e.g., http2.connect), the pattern above already matches it. |
There was a problem hiding this comment.
| // If callee already includes a dot (e.g., http2.connect), the pattern above already matches it. | |
| // If callee already includes a dot (e.g., http2.connect), the pattern above already matched it. |
| while (n && n.kind() !== 'variable_declarator') { | ||
| n = n.parent(); | ||
| } |
There was a problem hiding this comment.
nit for consistency
| while (n && n.kind() !== 'variable_declarator') { | |
| n = n.parent(); | |
| } | |
| while (n && n.kind() !== 'variable_declarator') n = n.parent(); |
| while (n && n.kind() !== 'variable_declarator') { | ||
| n = n.parent(); | ||
| } | ||
| if (!n) continue; |
There was a problem hiding this comment.
nit: helps break it up visually
| if (!n) continue; | |
| if (!n) continue; | |
| } | ||
| if (!n) continue; | ||
| const nameNode = (n as SgNode<Js, 'variable_declarator'>).field('name'); | ||
| if (!nameNode) continue; |
There was a problem hiding this comment.
same nit
| if (!nameNode) continue; | |
| if (!nameNode) continue; | |
I'm not sure if I correctly get, how the deprecation should be handled so here my thing.Resolves #243