Skip to main content
Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.Contact Sales

Migrate fs-extra to Node.js fs

Recipe IDorg.openrewrite.node.migrate.fs-extra.migrate-fs-extra-to-node-fs
Artifact@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 that declares them, with the lock file updated to match. They are removed even where a call listed in the data table still uses fs-extra, so migrate those before building. 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 recipeOpenRewritefs-extraModerne Proprietary License
Try in PlatformTry this recipe in the Moderne platform. Not a user yet? You’ll get a no-setup demo environment, with nothing to install or configure.

Usage​

Run this recipe

In order to run JavaScript recipes, you will need to use the Moderne CLI. For JavaScript specific configuration instructions, please see our configuring JavaScript guide.

This recipe calls into other OpenRewrite packages as it runs. You will need to install all of the following packages before running it:

RELEASE resolves to the newest release and LATEST to the newest build of any kind, including snapshots. Either one lets mod config recipes upgrade pull in later versions without editing this command; a pinned version stays where you put it.

Install the recipe packages
mod config recipes npm install @openrewrite/recipes-nodejs
mod config recipes jar install org.openrewrite:rewrite-javascript:RELEASE

Then, you can run the recipe via:

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