Skip to content
Open
Show file tree
Hide file tree
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
Nov 27, 2025
1c4fe70
Merge remote-tracking branch 'origin/main' into MaximeD
Nov 27, 2025
c638006
recipes(tls): add tls-securepair-to-tlssocket codemod
Dec 5, 2025
485fb15
Merge branch 'main' into MaximeD
menace31 Dec 5, 2025
3e43dea
recipes(tls): add tls-securepair-to-tlssocket codemod
Dec 5, 2025
3e78f7b
chore: update package-lock.json
Dec 5, 2025
2a069ed
Update recipes/tls-securepair-to-tlssocket/README.md
menace31 Dec 10, 2025
52de208
Update recipes/tls-securepair-to-tlssocket/README.md
menace31 Dec 10, 2025
b12b649
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 Dec 10, 2025
fe681b9
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 Dec 10, 2025
153faf9
use nodejs mod-utils and remove test.sh
Dec 10, 2025
40986bd
use nodejs mod-utils and remove test.sh
Dec 10, 2025
0cd5eee
use nodejs mod-utils and remove test.sh
Dec 10, 2025
af0f097
codemod-update
Dec 11, 2025
a2b7796
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 Dec 12, 2025
6f891fe
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 Dec 12, 2025
9d501a2
correct new_line in test files
Dec 12, 2025
8fbb180
remove disfunctional test
menace31 Dec 16, 2025
9cdb7cc
fix windows tests
menace31 Dec 16, 2025
91216ec
Merge branch 'MaximeD' of https://github.com/menace31/userland-migrat…
menace31 Dec 16, 2025
4148701
restore tests
menace31 Dec 16, 2025
700224b
fix tests
menace31 Dec 16, 2025
28a3357
fix tests
menace31 Dec 16, 2025
9bcc4d9
Merge branch 'main' into MaximeD
menace31 Dec 16, 2025
b6a95fa
fix tests
menace31 Dec 16, 2025
62a72f7
remove IA comment
menace31 Dec 16, 2025
0a1f785
Merge branch 'MaximeD' of https://github.com/menace31/userland-migrat…
menace31 Dec 16, 2025
8ffc05c
update package-lock.json
menace31 Dec 16, 2025
b18b065
Merge branch 'main' into MaximeD
menace31 Dec 17, 2025
9c54544
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 Dec 18, 2025
d22e788
pull
menace31 Dec 18, 2025
be3ccee
Update recipes/tls-securepair-to-tlssocket/src/workflow.ts
menace31 Dec 18, 2025
43324bf
fix test
menace31 Dec 18, 2025
9b0dd42
fix test
menace31 Dec 18, 2025
df79099
fix merge
menace31 Dec 18, 2025
2560ceb
fix test
menace31 Dec 18, 2025
8fd0b6c
doc update
menace31 Dec 23, 2025
9d3224c
fix comments
menace31 Dec 23, 2025
23e8baa
Merge branch 'main' into MaximeD
menace31 Dec 27, 2025
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
30 changes: 16 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions recipes/tls-securepair-to-tlssocket/README.md
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
```
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.).
23 changes: 23 additions & 0 deletions recipes/tls-securepair-to-tlssocket/codemod.yaml
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
25 changes: 25 additions & 0 deletions recipes/tls-securepair-to-tlssocket/package.json
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"
}
}
Loading
Loading