Skip to content

fix(cli): Find the App file in the React Native wizard - #2604

Open
antonis wants to merge 1 commit into
mainfrom
antonis/fix-rn-wizard-app-file
Open

antonis wants to merge 1 commit into
mainfrom
antonis/fix-rn-wizard-app-file

Conversation

@antonis

@antonis antonis commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes getsentry/sentry-react-native#7149.

sentry wizard reactNative prints "Could not find main App file" on a fresh bare React Native app and on a fresh Expo app. It then shows the Sentry.init and Sentry.wrap snippets to paste by hand, and never adds them.

Root cause

  • Regression from the port. getMainAppFilePath() uses upstream's pattern {.,./src,./app}/+(@(App|_layout).@(j|t|cj|mj)s?(x)). Upstream ran it with glob; the port runs it with tinyglobby (Port sentry-wizard into the CLI as sentry wizard #2511). tinyglobby handles the extglobs, but matches nothing for a . inside braces ({.,src}/App.tsx finds no file, ./App.tsx does). So the pattern found nothing, even a root App.tsx.
  • Gap from before the port. The Expo SDK 58 template puts its layout at src/app/_layout.tsx, outside ., src, and app.

The existing test mocks getFirstMatchedPath, so the pattern itself was never run.

Key Changes

  • getMainAppFilePath() globs {App,_layout}.{js,jsx,ts,tsx,cjs,mjs} in ., src, app, then src/app, one directory at a time; the first match wins. This keeps upstream's priority, adds src/app last, and makes the order deterministic. It drops cjsx/mjsx, which aren't React Native entry files.
  • New test/lib/wizard/react-native/main-app-file.test.ts runs the lookup against the real filesystem and tinyglobby, in a temporary directory per layout: the bare RN 0.88 root App.tsx, Expo SDK 58's src/app/_layout.tsx, app/_layout.tsx, src/App.js, App.jsx, and src/app/_layout.js. It also checks the order and that node_modules and lib/ are ignored. Against the old lookup, 7 of its 8 tests fail.

Verification

  • React Native wizard tests (157) pass.
  • CLI typecheck (src, test) and pnpm run lint pass.
  • End to end, with the wizard run from this branch (sentry wizard <org>/<project> reactNative, default answers):
    • Fresh bare React Native 0.88.1 app (@react-native-community/cli init): "Added Sentry.init to App.tsx" and "Added Sentry.wrap to App.tsx". The app typechecks with no errors.
    • Fresh Expo SDK 58 app (create-expo-app): "Added Sentry.init to src/app/_layout.tsx" and "Added Sentry.wrap to src/app/_layout.tsx" (export default Sentry.wrap(function TabLayout() {…})).
    • Before this change, both printed "Could not find main App file" and only showed the snippets.

🤖 Generated with Claude Code

`sentry wizard reactNative` printed "Could not find main App file" on a
fresh bare React Native app and a fresh Expo app, so it never added
`Sentry.init` or `Sentry.wrap`.

The lookup pattern `{.,./src,./app}/+(@(App|_layout).…)` came from
upstream, where `glob` ran it. `tinyglobby` matches nothing for a `.`
inside braces, so the pattern found no file, even a root `App.tsx`.
The Expo SDK 58 template also puts its layout at `src/app/_layout.tsx`,
which the pattern never covered.

Search `.`, `src`, `app`, then `src/app` with one glob each. A new test
runs the lookup against the real filesystem for the template layouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 30, 2026 2:39pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 30, 2026 2:39pm UTC

Request Review

@antonis
antonis marked this pull request as ready for review November 30, 2026 14:43
@antonis
antonis requested review from BYK and a balanced review from Copilot November 30, 2026 14:43
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the React Native app-file discovery changes.

No open issues 🎉

What changed in this PR

Fixes React Native wizard app-file discovery after the switch to tinyglobby, allowing automatic Sentry setup for standard React Native and Expo layouts.

Changes:

  • Searches supported directories individually with explicit precedence, adding src/app for newer Expo templates.
  • Adds real-filesystem tests covering supported layouts, directory precedence, and ignored paths.
File Description
packages/​cli/​test/​lib/​wizard/​react-native/​main-app-file.test.ts Adds discovery regression tests using the real glob helper.
packages/​cli/​src/​lib/​wizard/​react-native/​javascript.ts Replaces the combined directory glob with ordered lookups and adds src/app support.

Review effort: Balanced

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — a6a1c0a6 Deployed Nov 30, 2026 by vercel[bot]
Preview – sentry-local — a6a1c0a6 Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sentry wizard reactNative never adds Sentry.init: the App file lookup finds nothing

2 participants