Skip to content

Replace fs-extra calls with native equivalent #726

@troyciesco

Description

@troyciesco

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions