fs-extra can be fully replaced with native Node.js APIs.
Below is a quick pass at finding the usage and what needs to be replaced (may be incomplete):
Methods used
| Method |
Uses |
Native replacement |
Drop-in? |
readdir() |
3 |
fs/promises.readdir() |
Yes |
readFile() |
2 |
fs/promises.readFile() |
Yes |
remove() |
6 |
fs/promises.rm(path, {recursive: true, force: true}) |
Yes |
pathExists() |
5 |
fs/promises.access() wrapped in try/catch |
No — needs helper or inline try/catch |
Files to update
lib/read-theme.js
readdir() — drop-in
readFile() — drop-in
remove() — replace with fs/promises.rm(path, {recursive: true, force: true})
lib/checker.js
remove() — replace with fs/promises.rm(path, {recursive: true, force: true})
app/index.js
remove() — replace with fs/promises.rm(path, {recursive: true, force: true})
test/general.test.js
readdir() — drop-in
pathExists() — replace with fs/promises.access() + try/catch
remove() — replace with fs/promises.rm(path, {recursive: true, force: true})
test/read-zip.test.js
pathExists() — replace with fs/promises.access() + try/catch
remove() — replace with fs/promises.rm(path, {recursive: true, force: true})
test/read-theme.test.js
readdir() — mocked via vi.spyOn, update spy target to fs/promises
readFile() — mocked via vi.spyOn, update spy target to fs/promises
pathExists() replacement
fs-extra's pathExists() has no direct native equivalent. Options:
// Option A: inline
async function pathExists(p) {
try {
await fs.access(p);
return true;
} catch {
return false;
}
}
// Option B: just use access() directly and catch where needed
After migration
- Remove
fs-extra from package.json dependencies
- Replace all
require('fs-extra') with require('fs/promises') (or require('fs') where sync methods are needed)
fs-extracan be fully replaced with native Node.js APIs.Below is a quick pass at finding the usage and what needs to be replaced (may be incomplete):
Methods used
readdir()fs/promises.readdir()readFile()fs/promises.readFile()remove()fs/promises.rm(path, {recursive: true, force: true})pathExists()fs/promises.access()wrapped in try/catchFiles to update
lib/read-theme.js
readdir()— drop-inreadFile()— drop-inremove()— replace withfs/promises.rm(path, {recursive: true, force: true})lib/checker.js
remove()— replace withfs/promises.rm(path, {recursive: true, force: true})app/index.js
remove()— replace withfs/promises.rm(path, {recursive: true, force: true})test/general.test.js
readdir()— drop-inpathExists()— replace withfs/promises.access()+ try/catchremove()— replace withfs/promises.rm(path, {recursive: true, force: true})test/read-zip.test.js
pathExists()— replace withfs/promises.access()+ try/catchremove()— replace withfs/promises.rm(path, {recursive: true, force: true})test/read-theme.test.js
readdir()— mocked viavi.spyOn, update spy target tofs/promisesreadFile()— mocked viavi.spyOn, update spy target tofs/promisespathExists() replacement
fs-extra'spathExists()has no direct native equivalent. Options:After migration
fs-extrafrompackage.jsondependenciesrequire('fs-extra')withrequire('fs/promises')(orrequire('fs')where sync methods are needed)