Skip to content

feat(cli): add iOS, Apple Snapshots and React Native to sentry wizard - #2544

Open
sentry-junior[bot] wants to merge 20 commits into
mainfrom
feat/cli-wizard-apple-react-native
Open

sentry-junior[bot] wants to merge 20 commits into
mainfrom
feat/cli-wizard-apple-react-native

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2511. Stacked on #2520.

This ports the ios, appleSnapshots and reactNative flows of @sentry/wizard 9.1.0 (src/apple/, src/apple/snapshots/, src/react-native/) and their tests to packages/cli/src/lib/wizard/ and packages/cli/test/lib/wizard/. All three are registered in WIZARD_RUNNERS and run as sentry wizard [<org>/<project>] ios|appleSnapshots|reactNative. They add no flags. The upstream Apple flags (--app-target, --hosted-test-target, --non-interactive, --xcode-project-dir) are not carried over. The wizards look for the Xcode project in the current directory and prompt for the project, app target and hosted XCTest target. When stdin is not a terminal (isatty(0), the same check as auto-login), Apple Snapshots picks the only target or fails with the choices instead of prompting.

No sentry-cli binary. After v4, sentry.io/get-cli installs sentry (getsentry/sentry#132672), so these flows use only v4 commands:

  • The Xcode build phase follows fix(apple): support the v4 sentry CLI in iOS and snapshots flows sentry-wizard#1403:
    • It exports PATH (installer and Homebrew dirs), SENTRY_ORG and SENTRY_PROJECT.
    • It checks for a v4 sentry with sentry debug-files --help, then runs sentry debug-files upload [--include-sources] "$DWARF_DSYM_FOLDER_PATH".
    • Without an installed sentry, it runs npx --yes sentry debug-files upload. Failures show up as Xcode warnings, and it warns with the v4 install command only when neither sentry nor npx is found. There is no sentry-cli fallback.
  • installSentryCLI/hasSentryCLI are not ported. check-installed-cli.ts only checks that sentry is on the PATH that Xcode build phases see. If it isn't but npx is, the wizard notes that builds will use npx sentry. If neither is, it prints the Homebrew, curl (cli.sentry.dev/install) and npm install commands.
  • .sentryclirc stays, because v4 reads it. It now gets [defaults] org/project next to [auth] token. The CI hint names SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT and SENTRY_URL.
  • The Apple Snapshots preflight and hint use sentry snapshots upload … --app-id. v4 has no --org/--project flags there, so the hint uses env vars.
  • Detection of existing upload scripts (Apple xcode-manager, React Native xcode.ts) recognizes both the v2 and the v4 command forms.
  • The React Native issues link uses buildProjectIssuesUrl, so it points at the host you're logged in to.

Dependencies.

  • xml-js is gone. apple/snapshots/xml-scan.ts is a small scanner, with tests, for the two shapes the Snapshots flow reads: scheme TestAction BlueprintNames and xcschememanagement.plist keys.
  • xcode stays as a devDependency, with local typings in src/lib/wizard/xcode.d.ts. It goes away with the post-v4 init/wizard unification (Unify the sentry init and sentry wizard setup flows #2510).
  • recast and magicast also stay.

Overlap with sibling ports. These shared helpers are ported at upstream's paths, since other flows may port them too:

  • utils/files.ts and utils/find-files-with-extension.ts. Upstream has two findFilesWithExtensions, and both are kept as they are.
  • utils/abort-if-sportlight-not-supported.ts.
  • utils/bash.ts, with only execute, which pod install needs.

React Native needs nothing from src/android/ or src/sourcemaps/.

Fixtures. The Xcode project fixtures are in test/fixtures/wizard/apple/.

Not ported, or different from sentry-wizard.

  • No CLI flags for the project dir or the targets; the wizard prompts for them instead.
  • No sentry-cli fallback in the build phase. Install CLI nightlies from Toolkit GHCR #1403 keeps one.
  • The fastlane sentry_debug_files_upload / sentry_upload_snapshots actions are left as they are. They come from fastlane-plugin-sentry, which still runs sentry-cli.
  • React Native still writes sentry.properties and uses the SDK's bundled @sentry/cli scripts for Xcode and Gradle uploads. Those scripts belong to the SDK.
  • Spotlight (SENTRY_SPOTLIGHT) is still not supported for iOS or React Native, same as upstream.

Resolved in review: v4 already prefers a stored sentry auth login over the .sentryclirc token; the build phase falls back to npx sentry; fastlane and RN SDK v4 follow-ups get their own issues; the fixtures stay in test/fixtures/wizard/apple/.

via @BYK.

--

View Session [Sentry]

sentry-junior Bot and others added 13 commits November 26, 2026 11:48
Start moving getsentry/sentry-wizard into the CLI as `sentry wizard`.
This adds the command with the `@sentry/wizard` integrations and flags
(`-i`, `--url`, `--org`, `--project`, `--saas`, `--spotlight`, and the
rest), the shared wizard helpers, and the Next.js flow. The other
integrations report that they are not available in this version yet.

The wizard logs in with the CLI's own login: a stored `sentry auth
login` session, an agent handoff, or the device flow, instead of the
`account/settings/wizard/<hash>` browser flow. It then picks or creates
the project, reads its DSN, and creates an org auth token for source map
uploads. Telemetry goes through the CLI's client.

`sentry init` stays the agent setup guide; its help now points to
`sentry wizard` for the interactive setup.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Port `ast-utils` and `url` from getsentry/sentry-wizard into
`src/lib/wizard/utils/`. The SvelteKit, Remix, React Router, Angular,
Nuxt, source maps, Cloudflare, React Native and Android wizards all use
them, so they land once here and the platform PRs that follow build on
them in parallel.

`ast-utils` edits recast ASTs, so recast and ast-types become direct
dev dependencies; both already came in through magicast.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`sentry wizard` logs in with the CLI's login, which has no sign-up or
partner step, so `--signup`, `--promo-code` and `--coming-from` no longer
do anything. Passing one now fails with a message that points to
https://sentry.io/signup/ instead of being accepted silently.

`promoCode` and `comingFrom` leave `WizardOptions`, the welcome banner and
`setupCI`, which loses its Vercel partner branch. The help text and the
docs say which `@sentry/wizard` flags were removed.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…st-helpers

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
- Skip the `.sentryclirc` URL check, like `sentry init`: the wizard picks
  its instance (`--url`, `--saas` or a prompt) before it logs in.
- Use the stored login's instance for `sentryUrl` when none was chosen,
  and log in again when the stored login is for another instance.
- Link self-hosted users to `/settings/<org>/auth-tokens/`.
- Leave an unparseable MCP config alone (show the copy-paste fallback),
  and let a cancel inside the MCP setup stop the wizard.
- Resolve `catalog:` and `catalog:default` against both pnpm default
  catalog forms.
- Find an existing `SENTRY_AUTH_TOKEN` after the comment header of
  `.env.sentry-build-plugin`, so re-runs don't add a second one.
- Run Windows formatters with Node in the standalone binary, where
  `process.execPath` is `sentry`.
- Ask before updating an `@sentry/nextjs` listed in devDependencies, and
  treat an unknown SDK version as the `^11` the wizard installs.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…st-helpers

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Address review feedback on the shared wizard helpers:

- Enable unicorn/no-array-for-each repo-wide and convert every
  .forEach call site to for...of, including getLastRequireIndex.
- Add buildProjectIssuesUrl to lib/sentry-urls.ts, built on
  getOrgBaseUrl like buildEventSearchUrl, and delete the
  wizard-specific wizard/utils/url.ts.
- Move findFile into lib/dsn/fs-utils.ts and build it on
  isRegularFile, so a directory or FIFO with a matching name is
  skipped. It is async now.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`sentry wizard [<org>/<project>] [<integration>]` replaces the
`@sentry/wizard` flags, with the target first like other commands.

- The integration is a positional, one at a time. A bare integration id
  is never read as a target, and a single bare word is always read as an
  integration, so a project or org spelled like one is written
  `my-org/nextjs`, `nextjs/` or `/nextjs`.
- The target parses with the CLI's org/project grammar and resolves after
  login with `resolveOrgOptionalTarget`, like other commands. Without one
  the org and project pickers run, with no detection.
- `-f/--force` is the only flag. It sets both `forceInstall` and
  `ignoreGitChanges`.
- The instance comes from `SENTRY_URL` or the stored login, so the
  SaaS/self-hosted prompt, `--url`, `--saas` and `skipRcUrlCheck` go.
- Spotlight mode follows `SENTRY_SPOTLIGHT`, telemetry follows
  `isTelemetryEnabled()`, and debug output goes through the CLI logger
  (`--verbose`, `--log-level`).
- Every other `@sentry/wizard` flag and `SENTRY_WIZARD_*` variable is
  gone, hidden ones included, with `disableTelemetryForRun` and
  `rejectRemovedFlags`.

A test pins the wizard's own flags to `force`, and `check:env-coverage`
(part of `ci:policy`) fails when any file under `src/` names
`SENTRY_WIZARD_`.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Re-export buildProjectIssuesUrl from lib/sentry-web-urls.ts through
withSentryBaseUrl(getApiBaseUrl()), like the other user-facing link
builders, so self-hosted and regional logins get links on the host they
are authenticated against.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Port the `ios`, `appleSnapshots` and `reactNative` flows of
@sentry/wizard 9.1.0 into `sentry wizard`, with their tests and Xcode
fixtures, and register them in WIZARD_RUNNERS. The command gains the
Apple flags of the old wizard (`--app-target`, `--hosted-test-target`,
`--non-interactive`, hidden `--xcode-project-dir`), so existing
`npx @sentry/wizard -i ios ...` command lines keep parsing.

The flows no longer depend on the `sentry-cli` binary, because
sentry.io/get-cli installs `sentry` once v4 ships:

- The Xcode build phase runs `sentry debug-files upload` with
  SENTRY_ORG and SENTRY_PROJECT exported, checks for a v4 `sentry`
  with `sentry debug-files --help`, and turns failures into Xcode
  warnings with v4 install instructions.
- The wizard checks only that `sentry` is on the PATH Xcode build
  phases see, and prints the Homebrew, curl and npm install commands
  when it is not. It no longer installs a CLI itself.
- `.sentryclirc` gets `[defaults]` org and project next to the token,
  since v4 reads both.
- The Apple Snapshots hint and preflight use `sentry snapshots upload`.
- Existing-script detection recognizes both the v2 and v4 command
  forms, in the Apple and React Native Xcode code.

xml-js is replaced by a small scanner for the two XML shapes the
Snapshots flow reads (scheme TestAction blueprints and
xcschememanagement.plist keys). xcode stays as a devDependency until
the init/wizard unification.
…rs' into feat/cli-wizard-apple-react-native

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…eat/cli-wizard-apple-react-native

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>

# Conflicts:
#	packages/cli/plugins/sentry-cli/skills/sentry-cli/references/wizard.md
#	packages/cli/src/commands/wizard.ts
`sentry wizard` takes `[<org>/<project>] [<integration>]` and `-f/--force`
only, so the Apple flags this port added (`--app-target`,
`--hosted-test-target`, `--non-interactive`, hidden `--xcode-project-dir`)
go away.

- The Apple wizards look for the Xcode project in the current directory
  and prompt for the project, app target and hosted XCTest target, as
  `@sentry/wizard` does without those flags.
- Apple Snapshots runs non-interactively when stdin is not a terminal
  (`isatty(0)`, the CLI's auto-login check): it picks the only target or
  fails with the choices instead of prompting.
- React Native links to the project's issues with `buildProjectIssuesUrl`
  from `lib/sentry-web-urls.ts`, now that `wizard/utils/url.ts` is gone.
- `Array#forEach` loops become `for…of` for `unicorn/no-array-for-each`.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 26, 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 27, 2026 5:22pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 27, 2026 5:22pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📊 MCP Server Token Cost Report

Summary

  • Total Tokens: 68772 tokens
  • Tool Count: 77 tools
  • Average: 893 tokens/tool

Per-Tool Breakdown

Tool Tokens % of Total
get_issue_details 3967 5.8%
get_alert_rule 2245 3.3%
find_releases 1805 2.6%
get_issue_activity 1759 2.6%
update_alert_rule 1653 2.4%
get_replay_details 1602 2.3%
create_alert_rule 1506 2.2%
get_monitor_details 1501 2.2%
update_metric_monitor 1479 2.2%
create_metric_monitor 1458 2.1%
get_event_stacktrace 1381 2%
update_issue 1380 2%
render_sentry_chart 1362 2%
get_snapshot 1308 1.9%
get_profile 1291 1.9%
get_agent_conversation_details 1278 1.9%
find_monitors 1261 1.8%
search_logs 1248 1.8%
search_traces 1246 1.8%
get_alert_options 1236 1.8%
search_profiles 1228 1.8%
search_metrics 1216 1.8%
search_errors 1214 1.8%
get_profile_details 1200 1.7%
find_related_issues 1171 1.7%
get_uptime_monitor_details 1163 1.7%
create_monitor 1135 1.7%
onboarding_status_update 1109 1.6%
search_issue_events 1103 1.6%
search_replays 1095 1.6%
render_issue_chart 1061 1.5%
get_release_details 1056 1.5%
get_dashboard_details 1052 1.5%
search_attributes 1012 1.5%
search_issues 977 1.4%
search_docs 973 1.4%
find_alert_rules 908 1.3%
update_uptime_monitor 873 1.3%
create_uptime_monitor 871 1.3%
search_agent_conversations 830 1.2%
find_dropped_events 819 1.2%
get_metric_monitor_details 797 1.2%
create_project 793 1.2%
update_dsn 765 1.1%
get_issue_user_reports 630 0.9%
get_latest_base_snapshot 623 0.9%
find_dashboards 553 0.8%
link_issue 545 0.8%
find_uptime_monitors 537 0.8%
get_issue_breadcrumbs 492 0.7%
unlink_issue 476 0.7%
find_metric_monitors 471 0.7%
get_issue_tag_values 469 0.7%
update_project 441 0.6%
get_sentry_resource 429 0.6%
submit_feedback_to_sentry_team 426 0.6%
add_issue_note 404 0.6%
delete_monitor_environment 363 0.5%
find_teams 351 0.5%
find_projects 346 0.5%
delete_alert_rule 345 0.5%
delete_uptime_monitor 333 0.5%
delete_metric_monitor 331 0.5%
create_dsn 326 0.5%
add_team_to_project 324 0.5%
remove_team_from_project 320 0.5%
find_dsns 319 0.5%
find_organizations 311 0.5%
get_snapshot_image 302 0.4%
analyze_issue_with_seer 300 0.4%
get_event_attachment 299 0.4%
get_trace_details 282 0.4%
create_team 266 0.4%
get_span_details 263 0.4%
whoami 261 0.4%
get_sentry_mcp_info 142 0.2%
get_doc 102 0.1%

Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better.

MCP Apps views

Each ui:// view as a host receives it from resources/read.

View MIME type Raw Gzip Brotli Budget % of budget
ui://sentry/chart/v6.html text/html;profile=mcp-app 19,249 B 7,913 B 7,014 B 24,576 B 78.3%

The budget applies to raw bytes, and the view's generator fails over it.

`tsc -p script` follows script imports into the wizard's Xcode code but
did not include `src/lib/wizard/xcode.d.ts`, so `xcode` had no types
there and `pnpm run typecheck` failed. List it next to `global.d.ts`,
as test/tsconfig.json already does.

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Token source in Xcode: the build phase authenticates with the project's .sentryclirc token. Should it prefer a stored sentry auth login (or SENTRY_FORCE_ENV_TOKEN) instead?

If it can, yes?

When sentry isn't on the PATH Xcode sees (for example, the wizard ran via npx sentry wizard), we only print install commands. Should the wizard offer to install sentry?

Yes, maybe? Or the commands can also use npx which sounds better?

Should fastlane-plugin-sentry and the React Native SDK's upload scripts get v4 follow-ups, and who owns them?

Yes.

Is test/fixtures/wizard/apple/ the right place for the fixtures?

Yes

When no v4 `sentry` is on the PATH an Xcode build phase sees, the
generated upload phase now runs `npx --yes sentry debug-files upload`,
so a project set up with `npx sentry wizard` uploads debug symbols
without installing the CLI first. It only warns when neither `sentry`
nor `npx` is found.

The wizard's preflight matches: it notes that builds will use
`npx sentry` (and how to install the CLI for faster builds) when only
`npx` is in reach, and warns as before when neither is. Existing-phase
detection keys on `debug-files upload`, since the command now runs
through `"$@"`.
@vercel
vercel Bot temporarily deployed to Preview – sentry-local November 27, 2026 12:31 Inactive
@sentry-junior

sentry-junior Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Here's where the four answers landed:

  1. Token source: v4 already does this. A stored sentry auth login wins over SENTRY_AUTH_TOKEN and .sentryclirc tokens by default, so on a logged-in Mac the build phase uses the login. The org token in .sentryclirc only applies where there's no login (CI, teammates) or with SENTRY_FORCE_ENV_TOKEN=1. No change.
  2. npx: when sentry isn't on the PATH Xcode sees, the build phase now runs npx --yes sentry debug-files upload, and it only warns when neither sentry nor npx is there. The wizard notes that builds will use npx sentry and how to install the CLI for faster builds. There's no install prompt, and the npx fallback ships unpinned. (23942973)
  3. fastlane and React Native SDK: follow-up issues are being filed in getsentry/sentry-fastlane-plugin and getsentry/sentry-react-native.
  4. Fixtures: they stay in test/fixtures/wizard/apple/.

@sentry-junior
sentry-junior Bot requested a review from BYK November 27, 2026 12:32
Base automatically changed from feat/cli-wizard-shared-ast-helpers to main November 27, 2026 14:04
#2519 and #2520 were squash-merged, so this PR's base
is now main. Resolved the add/add conflicts: run.ts keeps this branch's
runner registrations (main's copy equals the old base), and
project-data.ts and its test take main's copy, with the #2559
context-scoped origin trust fix (this branch didn't change them).

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…e wizard

CodeQL flagged two patterns in the Apple wizard port:
- xml-scan stripped comments, CDATA and declarations in one pass, so
  removing one span could leave another behind (`<<!-- x -->!-- … -->`).
  It now strips until nothing changes.
- The pbxproj shell-script quoting escaped `"` but not `\`, so a
  backslash in a script could break out of the quoted string. One
  `quotePbxString` helper now escapes backslashes first, for both the
  add and update paths. Today's template has no backslashes, so the
  generated build phase is unchanged.

dependency-review flagged uuid@7.0.3 (GHSA-w5hq-g745-h8pq), which xcode@3
pins. xcode only calls `uuid.v4()`, but a scoped `xcode@3>uuid` override
moves it to the patched 11.1.1, which still ships CommonJS.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…d RN wizards

Warden flagged these in code ported unchanged from sentry-wizard 9.1.0:
- readXcodeBuildSettings ran `xcodebuild -project "<path>"` through
  execSync, so a `.xcodeproj` named with `$(…)` ran commands on the
  wizard host. It now uses execFileSync with an argument list.
- configureFastlane didn't wrap its confirm in abortIfCancelled, so
  Ctrl+C returned a truthy symbol and the wizard edited the Fastfile.
- The manual metro.config.js snippet had a stray `"` after the
  `@react-native/metro-config` require.

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

…ative wizard

When the app file has no import to anchor on, show the copy-paste
snippet instead of reporting that Sentry.init was added.

@cursor cursor Bot 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.

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

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b53a30f. Configure here.

): string {
return js.replace(
// The last import statement, with or without a trailing semicolon.
/^([^]*)(import\s+[^;]*?(?:;|['"])[ \t]*$)/m,

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.

Import regex matches non-import quotes

Medium Severity

The ASI import regex treats a trailing quote as the end of an import. Because the prefix is greedy, the last line in the file that contains import and then a quote or semicolon at end of line wins. Comments, string literals, and quoted words inside a multiline import all match, so Sentry.init can be injected inside a function or in the middle of an import and the wizard still reports success.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b53a30f. Configure here.

Comment on lines +1394 to +1414
// The default is '<group>'
const fileRefSourceTree = fileRef.obj.sourceTree?.replace(/"/g, "") ?? "";
switch (fileRefSourceTree) {
case "<absolute>":
return fileRef.obj.path.replace(/"/g, "");
case "<group>":
return this.resolveAbsoluteFilePathRelativeToGroup(fileRef);
case "BUILT_PRODUCTS_DIR":
return this.resolveAbsoluteFilePathRelativeToBuiltProductsDir(fileRef);
case "SOURCE_ROOT":
return this.resolveAbsoluteFilePathRelativeToSourceRoot(fileRef);
case "SDKROOT":
return this.resolveAbsoluteFilePathRelativeToSdkRoot(fileRef);
case "DEVELOPER_DIR":
return this.resolveAbsoluteFilePathRelativeToDeveloperDir(fileRef);
default:
debug(
`Unknown source tree '${fileRef.obj.sourceTree}' for build file: ${fileRef.obj.path}`,
);
return undefined;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing sourceTree on a PBXFileReference drops its default <group> file

When a PBXFileReference omits sourceTree, the resolver treats the valid <group> default as unknown and drops the file path, so the iOS wizard can miss that Swift source and fail to inject the Sentry initialization snippet.

Evidence
  • resolveAbsolutePathOfFileReference says the default is <group>, but converts a missing sourceTree to "" and returns undefined from the default branch.
  • resolveAbsolutePathOfGroup handles a missing sourceTree by defaulting it to <group>, confirming the intended resolution behavior for omitted values.
  • findFilesInSourceBuildPhase skips references whose path resolves to undefined; getSourceFilesForTarget passes that file list to injectCodeSnippet, which cannot inject into a file it did not discover.

Identified by Warden · code-review · QYR-4J8

Comment on lines +101 to +152
if (hasSentryContent(mod.$ast as t.Program)) {
const shouldContinue = await confirmPathMetroConfig();
if (!shouldContinue) {
await showInstructions();
return false;
}
}

const configExpression = getModuleExportsAssignmentRight(
mod.$ast as t.Program,
);
if (!configExpression) {
clack.log.warn(
"Could not find Metro config, please follow the manual steps.",
);
reportCliError(new Error("Could not find Metro config."));
await showInstructions();
return false;
}

const wrappedConfig = wrapWithSentryConfig(configExpression);

const replacedModuleExportsRight = replaceModuleExportsRight(
mod.$ast as t.Program,
wrappedConfig,
);
if (!replacedModuleExportsRight) {
clack.log.warn(
"Could not automatically wrap the config export, please follow the manual steps.",
);
reportCliError(
new Error("Could not automatically wrap the config export."),
);
await showInstructions();
return false;
}

const addedSentryMetroImport = addSentryMetroRequireToMetroConfig(
mod.$ast as t.Program,
);
if (!addedSentryMetroImport) {
clack.log.warn(
"Could not add `@sentry/react-native/metro` import to Metro config, please follow the manual steps.",
);
reportCliError(
new Error(
"Could not add `@sentry/react-native/metro` import to Metro config.",
),
);
await showInstructions();
return false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Confirming a Metro config re-patch duplicates the Sentry binding

If a bare React Native Metro config already contains Sentry setup and the user confirms modification, the wizard wraps the existing export and unconditionally inserts another const { withSentryConfig } declaration. The saved file then fails JavaScript parsing with a duplicate lexical binding, preventing Metro from loading.

Evidence
  • The bare React Native wizard calls patchMetroWithSentryConfig; when hasSentryContent detects an @sentry/ string, the user can confirm modification and the function continues without removing existing Sentry setup.
  • The export lookup accepts an existing withSentryConfig(...) call, which is wrapped again; addSentryMetroRequireToMetroConfig unconditionally inserts another const { withSentryConfig } = require(...) declaration.
  • patchMetroWithSentryConfig writes the modified AST after this path succeeds, so an already-patched config is saved with duplicate top-level const bindings and cannot be parsed by Metro.

Identified by Warden · code-review · 89L-WE8

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — b53a30fe Deployed Nov 27, 2026 by vercel[bot]
Preview – sentry-local — b53a30fe Deployed Nov 27, 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.

2 participants