This recipe transforms the usage of fs.truncate() to fs.ftruncate() when a file descriptor is used instead of a file path.
Deprecation
Node.js deprecated using fs.truncate() with a file descriptor argument. Use fs.ftruncate() instead when working with file descriptors.
See DEP0081 for more details.
Usage
Run this codemod with:
Before/After
What It Does
- Replaces
truncate with ftruncate when imported from node:fs or fs
- Updates function calls from
truncate(fd, ...) to ftruncate(fd, ...)
- Applies to callback, synchronous, and promise-based APIs
This codemod only updates cases where a file descriptor is passed. If you’re using fs.truncate() with a file path string, no changes will be made.
When working with file descriptors, always use the f-prefixed variants of file system methods: ftruncate(), fchmod(), fstat(), etc.