Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
81 changes: 48 additions & 33 deletions package-lock.json

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

33 changes: 33 additions & 0 deletions recipes/fs-truncate-fd-deprecation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# DEP0081: `fs.truncate()` using a file descriptor

This recipe transforms the usage of `fs.truncate()` to `fs.ftruncateSync()` when a file descriptor is used.

See [DEP0081](https://nodejs.org/api/deprecations.html#DEP0081).

## Example

**Before:**
```js
const { truncate, open, close } = require('node:fs');

open('file.txt', 'w', (err, fd) => {
if (err) throw err;
truncate(fd, 10, (err) => {
if (err) throw err;
close(fd, () => {});
});
});
```

**After:**
```js
const { ftruncate, open, close } = require('node:fs');

open('file.txt', 'w', (err, fd) => {
if (err) throw err;
ftruncate(fd, 10, (err) => {
if (err) throw err;
close(fd, () => {});
});
});
```
21 changes: 21 additions & 0 deletions recipes/fs-truncate-fd-deprecation/codemod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
schema_version: "1.0"
name: "@nodejs/fs-truncate-fd-deprecation"
version: 1.0.0
description: Handle DEP0081 via transforming `truncate` to `ftruncateSync` when using a file descriptor.
author: Augustin Mauroy
license: MIT
workflow: workflow.yaml
category: migration

targets:
languages:
- javascript
- typescript

keywords:
- transformation
- migration

registry:
access: public
visibility: public
24 changes: 24 additions & 0 deletions recipes/fs-truncate-fd-deprecation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@nodejs/fs-truncate-fd-deprecation",
"version": "1.0.0",
"description": "Handle DEP0081 via transforming `truncate` to `ftruncateSync` when using a file descriptor.",
"type": "module",
"scripts": {
"test": "npx codemod@next jssg test -l typescript ./src/workflow.ts ./"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nodejs/userland-migrations.git",
"directory": "recipes/fs-truncate-fd-deprecation",
"bugs": "https://github.com/nodejs/userland-migrations/issues"
},
"author": "Augustin Mauroy",
"license": "MIT",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/fs-truncate-fd-deprecation/README.md",
"devDependencies": {
"@codemod.com/jssg-types": "^1.0.3"
},
"dependencies": {
"@nodejs/codemod-utils": "*"
}
}
Loading
Loading