-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: migrate SlowBuffer to Buffer.allocUnsafeSlow() #193
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
lluisemper
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
lluisemper:main
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
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,27 @@ | ||
# SlowBuffer to Buffer.allocUnsafeSlow Codemod | ||
|
||
This codemod migrates deprecated `SlowBuffer` usage to `Buffer.allocUnsafeSlow()` to handle Node.js [DEP0030](https://nodejs.org/api/deprecations.html#DEP0030). | ||
|
||
## What it does | ||
|
||
This codemod transforms: | ||
|
||
1. `SlowBuffer` constructor calls to `Buffer.allocUnsafeSlow()` | ||
2. Direct `SlowBuffer` calls to `Buffer.allocUnsafeSlow()` | ||
3. Import/require statements be synced with new function | ||
|
||
## Example | ||
|
||
**Before:** | ||
|
||
```javascript | ||
import { SlowBuffer } from "buffer"; | ||
const buf = new SlowBuffer(1024); | ||
``` | ||
|
||
**After:** | ||
|
||
```javascript | ||
import { Buffer } from "buffer"; | ||
const buf = Buffer.allocUnsafeSlow(1024); | ||
``` |
23 changes: 23 additions & 0 deletions
23
recipes/slow-buffer-to-buffer-alloc-unsafe-slow/codemod.yaml
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/slow-buffer-to-buffer-alloc-unsafe-slow" | ||
version: "1.0.0" | ||
description: Handle DEP0030 via transforming SlowBuffer usage to Buffer.allocUnsafeSlow(). | ||
author: lluisemper(Lluis Semper Lloret) | ||
license: MIT | ||
workflow: workflow.yaml | ||
category: migration | ||
|
||
targets: | ||
languages: | ||
- javascript | ||
- typescript | ||
|
||
keywords: | ||
- transformation | ||
- migration | ||
- buffer | ||
- slowbuffer | ||
lluisemper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
registry: | ||
access: public | ||
visibility: public |
24 changes: 24 additions & 0 deletions
24
recipes/slow-buffer-to-buffer-alloc-unsafe-slow/package.json
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,24 @@ | ||
{ | ||
"name": "@nodejs/slow-buffer-to-buffer-alloc-unsafe-slow", | ||
"version": "1.0.0", | ||
"description": "Handle DEP0030 via transforming SlowBuffer usage to Buffer.allocUnsafeSlow().", | ||
"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/slow-buffer-to-buffer-alloc-unsafe-slow", | ||
"bugs": "https://github.com/nodejs/userland-migrations/issues" | ||
}, | ||
"author": "lluisemper(Lluis Semper Lloret)", | ||
"license": "MIT", | ||
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/slow-buffer-to-buffer-alloc-unsafe-slow/README.md", | ||
"dependencies": { | ||
"@nodejs/codemod-utils": "*" | ||
}, | ||
"devDependencies": { | ||
"@codemod.com/jssg-types": "^1.0.3" | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexbit-codemod could you confirm that this keywords is good idea for ours codemods ??? The published codemods only use
transformation
&migration
keywords.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry! Just saw this! and I know it’s already approved so I don’t want to block it. The tags are ok as is, but if you want to make it more useful, here’s a guide for applying tags:
https://go.codemod.com/tags-guide
Tags are optional, but they’ll show up in the codemod registry so users can quickly tell what the codemod is about. Words like
transformation
ormigration
aren’t very helpful. cc @lluisemper @AugustinMauroyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So let's not use it for now