Repository navigation
Conversation
--- <!-- Thank you for sending the PR!
This branch has not been deployed
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.
Summary
This PR replaces the deprecated
fs.F_OKalias withfs.constants.F_OKinreact-dev-utils/checkRequiredFiles. It is a one-line change to the runtime code, plus a new unit test file for a utility that had no tests before. Refs #17131.Motivation
checkRequiredFilesruns on everynpm startandnpm run build. Bothpackages/react-scripts/scripts/start.js:50andpackages/react-scripts/scripts/build.js:50call it with[paths.appHtml, paths.appIndexJs]before doing anything else. Inside it,packages/react-dev-utils/checkRequiredFiles.js:19called:The top-level
fs.F_OK,fs.R_OK,fs.W_OKandfs.X_OKaliases are deprecated in Node.js (DEP0176). Current releases emit a deprecation warning when they are accessed, and Node has signaled it will remove them. Anyone runningreact-scriptson a recent Node version gets that warning every time they start the dev server or build. It doesn't come from their code and they can't fix it in their app. It also adds noise to CI logs and can make people think their project is broken.fs.constants.F_OKhas been the documented replacement since Node 6. Bothreact-dev-utilsandreact-scriptsdeclare"node": ">=14"inengines, so every supported runtime has it.What changed
packages/react-dev-utils/checkRequiredFiles.js:fs.accessSync(filePath, fs.F_OK)becomesfs.accessSync(filePath, fs.constants.F_OK). Nothing else in the function changes: the iteration, the return values and the "Could not find a required file." output are all the same.packages/react-dev-utils/__tests__/checkRequiredFiles.test.js(new): unit tests covering the function's existing behavior and making sure it no longer depends on the deprecated alias. See Tests.How it works
fs.constants.F_OKand the oldfs.F_OKalias have the same value (0), soaccessSyncgets the same mode argument as before. The only difference is that the code no longer reads the deprecated property, so Node has no reason to warn.Decisions and alternatives:
F_OKis the default mode forfs.accessSync, sofs.accessSync(filePath)would behave the same. I kept it so the intent ("check that the file exists") is clear to readers and the diff stays minimal.fs.existsSync. That would also work, but it would change how the function is built (try/catch to boolean checks) for no real gain, and it would make the diff harder to review. The goal here is to remove the deprecated API usage without changing behavior.Tests
New file:
packages/react-dev-utils/__tests__/checkRequiredFiles.test.jsEach test creates real files in a fresh temporary directory (
fs.mkdtempSync), deletes it afterwards, and stubsconsole.logso the output can be checked without printing.true, and nothing is logged.[]givestrue, and nothing is logged.false.fs.accessSyncand checks it is called once per file with(file, fs.constants.F_OK), and that the mode is a number.fsobject whoseF_OKgetter returnsundefined, simulating a runtime without the alias. It then checks that the function still returnstrueand thataccessSyncgetsfs.constants.F_OK, notundefined. Recent Node versions definefs.F_OKas non-configurable, so the test builds a prototype-derivedfsinstead of patching the real module.Run them with:
npx jest 'packages/react-dev-utils/__tests__/checkRequiredFiles.test.js'Manual verification steps for reviewers:
npm startandnpm run buildin the monorepo. Confirm the DEP0176 warning aboutfs.F_OKno longer appears.public/index.htmlfrom the app and runnpm startagain. Confirm it still printsCould not find a required file., followed by theName:andSearched in:lines, and exits.Compatibility & risk
fs.constants.F_OKexists on every Node version allowed by the packages'enginesfield (>=14).react-dev-utilsandreact-scriptsdon't need to do anything.jest.isolateModuleswithjest.doMock('fs', ...)and callsjest.dontMock('fs')in afinallyblock. Please confirm this approach to mockingfsfits the repo's Jest setup and doesn't leak into other test files. The cleanup also usesfs.rmSync, which needs Node 14.14 or newer. That's fine for the repo's own test environment, but it is slightly above the>=14floor inengines, which applies to the published packages.