Skip to content

feat(react-native): skip patch native files when expo CNG#1211

Open
uragirii wants to merge 3 commits intogetsentry:masterfrom
uragirii:feat/expo-cng-check
Open

feat(react-native): skip patch native files when expo CNG#1211
uragirii wants to merge 3 commits intogetsentry:masterfrom
uragirii:feat/expo-cng-check

Conversation

@uragirii
Copy link

@uragirii uragirii commented Feb 8, 2026

Description

  • Adds check to see if you are in Expo CNG to skip the native file patching
  • Checks if ios and android folders are in .gitignore
  • Skips the step and prints a log to show that step is skipped
  • Added Sentry tracking for this
  • As this is my first contribution, please let me know if I missed something
image

AI Disclosure

  • The tests in this PR are written by Claude Code Sonnet 4.5.
  • Actual implemention of the feature is done by me, only *.test.ts files are generated based on my code

Comment on lines +201 to +210
export const isExpoCNG = async (): Promise<boolean> => {
const nativeFoldersExist = fs.existsSync('ios') || fs.existsSync('android');

if (!nativeFoldersExist) {
// Definitely CNG and using prebuild steps
return true;
}

return await areNativeFoldersInGitignore();
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The areNativeFoldersInGitignore function incorrectly requires both 'ios' and 'android' folders in .gitignore, causing single-platform Expo CNG projects to be misidentified.
Severity: HIGH

Suggested Fix

Modify areNativeFoldersInGitignore to only check for the presence of existing native folders in .gitignore. The function should first determine which native folders (ios or android) exist on the filesystem and then verify that only those existing folders are included in the gitignore file.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/react-native/expo.ts#L201-L210

Potential issue: The `isExpoCNG` function incorrectly identifies single-platform Expo
CNG projects (e.g., with only an 'ios' folder) as non-CNG. This occurs because its
helper function, `areNativeFoldersInGitignore`, uses `.every()` to require that both
'ios' and 'android' folders are present in the `.gitignore` file. For a valid
single-platform project, this check will always fail because one of the native folders
does not exist and is therefore not in `.gitignore`. This causes `isExpoCNG` to return
`false`, leading to incorrect attempts to patch native files that should be treated as
immutable build artifacts.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.


return NATIVE_FOLDERS.every((folder) => {
return lines.some((line) => {
const lineWithoutComment = line.split('#')[0].trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitignore parser incorrectly strips mid-line hash characters

Low Severity

The line.split('#')[0] approach treats # anywhere on a line as a comment delimiter. Per the gitignore spec, # only starts a comment when it's the first non-whitespace character on the line — mid-line # is a literal part of the pattern. A gitignore entry like ios # native would be incorrectly parsed as matching ios, even though git treats the entire string (including the #) as a literal pattern. This could cause a false positive for isExpoCNG, leading to native file patching being skipped when it shouldn't be. A simpler approach — checking if the trimmed line starts with # to identify comment lines — would match gitignore semantics correctly.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant