Skip to content

Commit a68a702

Browse files
committed
feat: migrate SlowBuffer to Buffer.allocUnsafeSlow()
Add codemod to handle deprecated SlowBuffer API migration covering CommonJS, ES6 imports, and usage patterns Closes: #125 (comment)
1 parent b1e9a9d commit a68a702

28 files changed

+634
-0
lines changed

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SlowBuffer to Buffer.allocUnsafeSlow Codemod
2+
3+
This codemod migrates deprecated `SlowBuffer` usage to `Buffer.allocUnsafeSlow()` to handle Node.js DEP0030.
4+
5+
## What it does
6+
7+
This codemod transforms:
8+
9+
1. `SlowBuffer` constructor calls to `Buffer.allocUnsafeSlow()`
10+
2. Direct `SlowBuffer` calls to `Buffer.allocUnsafeSlow()`
11+
3. Import/require statements to use `Buffer` instead of `SlowBuffer`
12+
13+
## Examples
14+
15+
### Before
16+
17+
```javascript
18+
const SlowBuffer = require("buffer").SlowBuffer;
19+
20+
// Using SlowBuffer constructor
21+
const buf1 = new SlowBuffer(1024);
22+
const buf2 = SlowBuffer(512);
23+
24+
// Direct import
25+
const { SlowBuffer } = require("buffer");
26+
const buf3 = new SlowBuffer(256);
27+
```
28+
29+
### After
30+
31+
```javascript
32+
const Buffer = require("buffer").Buffer;
33+
34+
// Using Buffer.allocUnsafeSlow()
35+
const buf1 = Buffer.allocUnsafeSlow(1024);
36+
const buf2 = Buffer.allocUnsafeSlow(512);
37+
38+
// Direct import
39+
const { Buffer } = require("buffer");
40+
const buf3 = Buffer.allocUnsafeSlow(256);
41+
```
42+
43+
### ESM Support
44+
45+
```javascript
46+
// Before
47+
import { SlowBuffer } from "buffer";
48+
const buf = new SlowBuffer(1024);
49+
50+
// After
51+
import { Buffer } from "buffer";
52+
const buf = Buffer.allocUnsafeSlow(1024);
53+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
schema_version: "1.0"
2+
name: "@nodejs/slow-buffer-to-buffer-alloc-unsafe-slow"
3+
version: "1.0.0"
4+
description: Handle DEP0030 via transforming SlowBuffer usage to Buffer.allocUnsafeSlow().
5+
author: lluisemper(Lluis Semper Lloret)
6+
license: MIT
7+
workflow: workflow.yaml
8+
category: migration
9+
10+
targets:
11+
languages:
12+
- javascript
13+
- typescript
14+
15+
keywords:
16+
- transformation
17+
- migration
18+
- buffer
19+
- slowbuffer
20+
21+
registry:
22+
access: public
23+
visibility: public
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@nodejs/slow-buffer-to-buffer-alloc-unsafe-slow",
3+
"version": "1.0.0",
4+
"description": "Handle DEP0030 via transforming SlowBuffer usage to Buffer.allocUnsafeSlow().",
5+
"type": "module",
6+
"scripts": {
7+
"test": "npx codemod jssg test -l typescript ./src/workflow.ts ./"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/nodejs/userland-migrations.git",
12+
"directory": "recipes/slow-buffer-to-buffer-alloc-unsafe-slow",
13+
"bugs": "https://github.com/nodejs/userland-migrations/issues"
14+
},
15+
"author": "lluisemper(Lluis Semper Lloret)",
16+
"license": "MIT",
17+
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/slow-buffer-to-buffer-alloc-unsafe-slow/README.md",
18+
"dependencies": {
19+
"@nodejs/codemod-utils": "*"
20+
},
21+
"devDependencies": {
22+
"@codemod.com/jssg-types": "^1.0.3"
23+
}
24+
}

0 commit comments

Comments
 (0)