← All recipes
Moderne licensed

Migrate fs-extra to Node.js fs

Recipe IDorg.openrewrite.node.migrate.fs-extra.migrate-fs-extra-to-node-fsArtifact@openrewrite/recipes-nodejs

Replaces fs-extra with the Node.js standard library (node:fs, node:fs/promises, node:path). fs-extra's own methods (remove, ensureDir, pathExists, readJson, writeJson, outputFile, outputJson, ensureFile, copy, emptyDir) are rewritten to their native equivalents and the fs methods fs-extra re-exports are bound from node:fs or node:fs/promises directly. move becomes a call to a helper written into the same file, since rename alone doesn't create the destination's parent, refuse an existing destination, or work across devices. Calls without a faithful native equivalent (ensureSymlink, ensureLink, ...) are left in place and listed in the FsExtraManualMigrationSteps data table. fs-extra and @types/fs-extra are removed from each package.json whose sources no longer use it. Tests that mock or spy on fs-extra itself (vi.mock('fs-extra'), vi.spyOn(fs, 'outputFile'), ...) keep watching a module the migrated code no longer calls, so they fail until they mock node:fs / node:fs/promises instead. Every such site is listed in the data table; migrate them together with the code they cover.

Composite recipefs-extraProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.node.migrate.fs-extra.migrate-fs-extra-to-node-fs

If the recipe isn’t available locally, install it with:

mod config recipes npm install @openrewrite/recipes-nodejs

Definition

This recipe runs the following recipes in order.