Modernize: Replace fs-extra with native APIs#32296
Merged
Merged
Conversation
…/replace-node-native
ndelangen
approved these changes
Sep 4, 2025
|
View your CI Pipeline Execution ↗ for commit 9bb3db0
☁️ Nx Cloud last updated this comment at |
fs-extra with native
fs-extra with native fs-extra with native APIs
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR modernizes the scripts directory by replacing the fs-extra dependency with native Node.js filesystem APIs. This reduces the dependency footprint and aligns with modern Node.js best practices by leveraging built-in functionality available since Node.js 14+.
Key changes include:
- Replacing all
fs-extraimports withnode:fs/promisesimports across 35+ files - Implementing custom utility functions to replicate specific
fs-extrafunctionality where needed - Removing
fs-extrafrom package.json dependencies and ESLint banned dependencies
Reviewed Changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/utils/yarn.ts | Replace readJSON/writeJSON with manual JSON parsing/stringifying |
| scripts/utils/tools.ts | Replace pathExists and readJson with native access and readFile |
| scripts/utils/paths.ts | Replace pathExists with custom implementation using access |
| scripts/utils/package-json.ts | Replace readJSON/writeJSON with native file operations |
| scripts/utils/filterExistsInCodeDir.ts | Replace pathExists with custom implementation |
| scripts/tasks/sandbox.ts | Replace pathExists and remove with access and rm |
| scripts/tasks/sandbox-parts.ts | Replace multiple fs-extra functions with native equivalents and custom utilities |
| scripts/tasks/publish.ts | Replace pathExists with custom implementation |
| scripts/tasks/install.ts | Replace pathExists and remove with access and rm |
| scripts/tasks/generate.ts | Replace pathExists and remove with access and rm |
| scripts/tasks/compile.ts | Replace readFile import with native equivalent |
| scripts/tasks/build.ts | Replace pathExists with custom implementation |
| scripts/task.ts | Replace outputFile and pathExists with custom implementations |
| scripts/sandbox/utils/yarn.ts | Replace move, remove with rename, rm |
| scripts/sandbox/utils/template.ts | Replace readFile import with native equivalent |
| scripts/sandbox/publish.ts | Replace copy, emptyDir, remove with native equivalents and custom utilities |
| scripts/sandbox/generate.ts | Replace multiple fs-extra functions with native equivalents and custom utilities |
| scripts/run-registry.ts | Replace pathExists, readJSON, remove with native equivalents |
| scripts/reset.js | Replace remove with rm |
| scripts/release/ files | Replace readFile, readJson, writeJson with native equivalents across multiple release scripts |
| scripts/package.json | Remove fs-extra and @types/fs-extra dependencies |
| scripts/get-template.ts | Replace pathExists and readFile with native equivalents |
| scripts/get-report-message.ts | Replace readJson with native file operations |
| scripts/combine-compodoc.ts | Replace fs-extra imports with native equivalents |
| scripts/check-package.ts | Replace readJSON with native file operations |
| scripts/build-package.ts | Replace readJSON with native file operations |
| scripts/bench/utils.ts | Replace multiple fs-extra functions with native equivalents |
Comments suppressed due to low confidence (1)
scripts/reset.js:1
- The function
removeis not defined. The import statement importsrmfromnode:fs/promises, but the code still callsremove(uri). This should be changed torm(uri, { force: true, recursive: true }).
import { spawn } from 'node:child_process';
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
24 tasks
23 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #20228
What I did
This PR replaces
fs-extrawith the native APIs.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Run
yarn testandyarn build-packageunder thescripts/directory.Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>Greptile Summary
This PR systematically replaces the
fs-extradependency with native Node.js filesystem APIs across the entire scripts directory. The migration touches 35+ files and removesfs-extrafrom the package.json dependencies. Key changes include:fs-extraimports are replaced withnode:fs/promisesimports (readFile,writeFile,rm,cp,access, etc.)fs-extrafunctionality:pathExists()usingaccess()with try-catch error handlingreadJson()usingreadFile()+JSON.parse()emptyDir()usingmkdir()+readdir()+rm()outputFile()usingmkdir(dirname())+writeFile()readJson/writeJsonwith manualreadFile/writeFile+JSON.parse/JSON.stringifycopywithcp,removewithrm,movewithrename,ensureDirwithmkdirfs-extrafs-extrafrom the banned dependencies listThis change aligns with modern Node.js best practices of leveraging native APIs when equivalent functionality exists, reducing the dependency footprint from 1 external package to 0. The migration affects build scripts, release automation, sandbox generation, and various utility functions throughout the development toolchain. All changes maintain functional equivalence while using only built-in Node.js capabilities available since Node.js 14+.
Confidence score: 2/5
scripts/reset.jsthat will throw a ReferenceErrorscripts/reset.jswhich callsremove(uri)on line 45 but only importsrm()from native APIs