Migrate fs-extra to Node.js fs
ProprietaryReplaces 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, ...), and calls whose last argument's type doesn't say whether it is a callback (any, untyped JavaScript, a union of a function and data, a named type alias), 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.
org. openrewrite. node. migrate. fs-extra. migrate-fs-extra-to-node-fsmod run . --recipe= org. openrewrite. node. migrate. fs-extra. migrate-fs-extra-to-node-fsInstall it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Replace fs-extra
removewithfs.rm - Replace fs-extra
ensureDir/mkdirp/mkdirswithfs.mkdir - Replace fs-extra
pathExistswithfs.access/fs.existsSync - Replace fs-extra
readJsonwithJSON.parseofreadFile - Replace fs-extra
writeJsonwithfs.writeFile - Replace fs-extra
outputFileandoutputJsonwithmkdir+writeFile - Replace fs-extra
ensureFilewithfs.mkdirandfs.writeFile - Replace fs-extra
emptyDirwithmkdirandrmof each entry - Replace fs-extra
movewith a generated helper - Replace fs-extra
copywithfs.cp - Replace fs-extra's re-exported
fsmethods withnode:fs - Find fs-extra usages that need manual migration
- Remove the
fs-extradependency