Skip to content

Commit 48798a1

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 48798a1

28 files changed

+608
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SlowBuffer to Buffer.allocUnsafeSlow Codemod
2+
3+
This codemod migrates deprecated `SlowBuffer` usage to `Buffer.allocUnsafeSlow()` to handle Node.js [DEP0030](https://nodejs.org/api/deprecations.html#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 be synced with new function
12+
13+
## Example
14+
15+
**Before:**
16+
17+
```javascript
18+
import { SlowBuffer } from "buffer";
19+
const buf = new SlowBuffer(1024);
20+
```
21+
22+
**After:**
23+
24+
```javascript
25+
import { Buffer } from "buffer";
26+
const buf = Buffer.allocUnsafeSlow(1024);
27+
```
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)