-
-
Notifications
You must be signed in to change notification settings - Fork 31
feat(tls-securepair-to-tlssocket): introduce #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
menace31
wants to merge
39
commits into
nodejs:main
Choose a base branch
from
menace31:MaximeD
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
6ef1d20
working version with test and README for TLSSocket
1c4fe70
Merge remote-tracking branch 'origin/main' into MaximeD
c638006
recipes(tls): add tls-securepair-to-tlssocket codemod
485fb15
Merge branch 'main' into MaximeD
menace31 3e43dea
recipes(tls): add tls-securepair-to-tlssocket codemod
3e78f7b
chore: update package-lock.json
2a069ed
Update recipes/tls-securepair-to-tlssocket/README.md
menace31 52de208
Update recipes/tls-securepair-to-tlssocket/README.md
menace31 b12b649
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 fe681b9
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 153faf9
use nodejs mod-utils and remove test.sh
40986bd
use nodejs mod-utils and remove test.sh
0cd5eee
use nodejs mod-utils and remove test.sh
af0f097
codemod-update
a2b7796
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 6f891fe
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 9d501a2
correct new_line in test files
8fbb180
remove disfunctional test
menace31 9cdb7cc
fix windows tests
menace31 91216ec
Merge branch 'MaximeD' of https://github.com/menace31/userland-migrat…
menace31 4148701
restore tests
menace31 700224b
fix tests
menace31 28a3357
fix tests
menace31 9bcc4d9
Merge branch 'main' into MaximeD
menace31 b6a95fa
fix tests
menace31 62a72f7
remove IA comment
menace31 0a1f785
Merge branch 'MaximeD' of https://github.com/menace31/userland-migrat…
menace31 8ffc05c
update package-lock.json
menace31 b18b065
Merge branch 'main' into MaximeD
menace31 9c54544
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 d22e788
pull
menace31 be3ccee
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 43324bf
fix test
menace31 9b0dd42
fix test
menace31 df79099
fix merge
menace31 2560ceb
fix test
menace31 8fd0b6c
doc update
menace31 9d3224c
fix comments
menace31 23e8baa
Merge branch 'main' into MaximeD
menace31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # tls-securepair-to-tlssocket | ||
|
|
||
| Codemod to migrate from the deprecated `tls.SecurePair` class to `tls.TLSSocket` in Node.js applications. `SecurePair` was deprecated and subsequently removed in favor of `TLSSocket`. | ||
|
|
||
| ## What it does | ||
|
|
||
| This codemod transforms usages of `tls.SecurePair` into `tls.TLSSocket`. Since `TLSSocket` wraps an existing socket, the codemod injects a `socket` argument that you may need to define or bind in your context. | ||
|
|
||
| Key transformations: | ||
| - **Constructor:** Replaces `new SecurePair()` with `new TLSSocket(socket)`. | ||
| - **Imports:** Updates `require` and `import` statements from `SecurePair` to `TLSSocket`. | ||
| - **Renaming:** Intelligently renames variables (e.g., `pair` → `socket`, `securePairInstance` → `socketInstance`) while preserving CamelCase. | ||
| - **Cleanup:** Removes deprecated property accesses like `.cleartext` and `.encrypted`. | ||
| - **Annotations:** Adds comments to highlight where manual API verification is needed. | ||
|
|
||
| ## Supports | ||
|
|
||
| - **Module Systems:** | ||
| - CommonJS: `const tls = require('node:tls')` / `const { SecurePair } = ...` | ||
| - ESM: `import tls from 'node:tls'` / `import { SecurePair } ...` | ||
| - **Variable Renaming:** | ||
| - Updates variable declarations: `const pair = ...` → `const socket = ...` | ||
| - Updates references deep in the scope: `pair.on('error')` → `socket.on('error')` | ||
| - Handles naming variations: `myPair` → `mySocket`, `securePair` → `secureSocket`. | ||
| - **Cleanup:** | ||
| - Identifies and removes lines accessing `cleartext` or `encrypted` properties. | ||
| - **Namespace Handling:** | ||
| - Supports both `new tls.SecurePair()` and `new SecurePair()`. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Case 1: CommonJS with namespace access | ||
|
|
||
| ```diff | ||
| const tls = require('node:tls'); | ||
|
|
||
| - const pair = new tls.SecurePair(); | ||
| - const encrypted = pair.encrypted; | ||
| + const socket = new tls.TLSSocket(socket); | ||
| ``` | ||
|
|
||
| ### Case 2: ESM with destructuring | ||
|
|
||
| ```diff | ||
| - import { SecurePair } from 'node:tls'; | ||
| + import { TLSSocket } from 'node:tls'; | ||
|
|
||
| - const myPair = new SecurePair(); | ||
| - myPair.cleartext.write('hello'); | ||
| + const mySocket = new TLSSocket(socket); | ||
| + mySocket.write('hello'); | ||
| ``` | ||
|
|
||
| ### Case 3: Variable renaming across scope | ||
|
|
||
| ```diff | ||
| const tls = require('node:tls'); | ||
|
|
||
| - const securePair = new tls.SecurePair(); | ||
| + const secureSocket = new tls.TLSSocket(socket); | ||
|
|
||
| - securePair.on('error', (err) => { | ||
| + secureSocket.on('error', (err) => { | ||
| console.error(err); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Case 4: Multiple variables with cleanup | ||
|
|
||
| ```diff | ||
| - const { SecurePair } = require('node:tls'); | ||
| + const { TLSSocket } = require('node:tls'); | ||
|
|
||
| - const pair = new SecurePair(); | ||
| - const cleartext = pair.cleartext; | ||
| + const socket = new TLSSocket(socket); | ||
| ``` | ||
|
|
||
| ## Warning | ||
|
|
||
| The tls.TLSSocket constructor requires an existing socket instance (net.Socket) as an argument. This codemod automatically inserts socket as the argument: | ||
| JavaScript | ||
|
|
||
| ```js | ||
| ``` | ||
menace31 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new TLSSocket(socket) | ||
| ``` | ||
|
|
||
| You must ensure that a variable named socket exists in the scope or rename it to match your existing socket variable (e.g., clientSocket, stream, etc.). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| schema_version: "1.0" | ||
| name: "@nodejs/tls-securepair-to-tlssocket" | ||
| version: "1.0.0" | ||
| description: Migrate usages of `tls.SecurePair` to `tls.TLSSocket` where possible. | ||
| author: Maxime Devillet | ||
| license: MIT | ||
| workflow: workflow.yaml | ||
| category: migration | ||
|
|
||
| targets: | ||
| languages: | ||
| - javascript | ||
| - typescript | ||
|
|
||
| keywords: | ||
| - transformation | ||
| - migration | ||
| - tls | ||
| - securepair | ||
|
|
||
| registry: | ||
| access: public | ||
| visibility: public |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "@nodejs/tls-securepair-to-tlssocket", | ||
| "version": "1.0.0", | ||
| "description": "Migrate usages of tls.SecurePair to tls.TLSSocket.", | ||
| "type": "module", | ||
| "scripts": { | ||
| "test": "npx codemod jssg test -l typescript ./src/workflow.ts ./" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/nodejs/userland-migrations.git", | ||
| "directory": "recipes/tls-securepair-to-tlssocket", | ||
| "bugs": "https://github.com/nodejs/userland-migrations/issues" | ||
| }, | ||
| "author": "Maxime Devillet", | ||
| "license": "MIT", | ||
| "homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/tls-securepair-to-tlssocket/README.md", | ||
| "devDependencies": { | ||
| "@codemod.com/jssg-types": "^1.0.9" | ||
| }, | ||
| "dependencies": { | ||
| "@nodejs/codemod-utils": "*", | ||
| "@ast-grep/napi": "^0.40.0" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.