Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

feat(react-native): add xcode command - #1193

Merged
BYK merged 3 commits into
mainfrom
byk/feat/react-native-xcode
Jul 3, 2026
Merged

BYK merged 3 commits into
mainfrom
byk/feat/react-native-xcode

Conversation

@BYK

@BYK BYK commented Jul 3, 2026

Copy link
Copy Markdown
Member

Ports react-native xcode from the legacy CLI — the final gap. Uploads React Native sourcemaps from an Xcode "Bundle React Native code and images" build phase.

Modes (parity with sentry-cli react-native xcode)

  • release build — wraps the RN build script: this CLI stands in for NODE_BINARY/HERMES_CLI_PATH (via __SENTRY_RN_WRAP_XCODE_CALL, dispatched at the top of bin.ts), so the produced bundle + sourcemap — including the Hermes combined sourcemap — are captured from a JSON report, then a debug ID is injected and both are uploaded.
  • simulator build + --allow-fetch — downloads the bundle + sourcemap from the running packager (waits up to 10s), then uploads.
  • debug build — just runs the build script.

Release/distribution come from SENTRY_RELEASE/SENTRY_DIST or the app Info.plist (<CFBundleIdentifier>@<CFBundleShortVersionString>+<CFBundleVersion>), unless --no-auto-release. Extra build-script args are accepted as trailing positionals.

Implementation

  • src/lib/react-native/wrap-call.ts — the NODE_BINARY/hermesc shim: parses the RN bundle/ram-bundle/export:embed, Hermes -emit-binary, and compose-source-maps.js invocations; adds a --sourcemap-output when missing; forwards to the real tool; copies the packager debug ID into the Hermes combined sourcemap; writes the report. SEA-vs-npm argv layout handled via node:sea.
  • src/lib/react-native/xcode-env.ts — findNode/findHermesc, expandXcodeVars ($(VAR)/${VAR} with :rfc1034identifier/:identifier), a minimal XML Info.plist parser, and release/dist resolution.
  • src/commands/react-native/xcode.ts — the three-mode execute flow; reuses injectDebugId + uploadSourcemaps (same ~/<filename> artifact convention as react-native gradle).

Documented limitations vs legacy

  • Info.plist C preprocessing (INFOPLIST_PREPROCESS) and xcodebuild-based discovery outside an Xcode build are not supported — set SENTRY_RELEASE/SENTRY_DIST in those cases.
  • Indexed RAM bundles are unsupported. --wait/--wait-for are accepted for compatibility (the CLI always waits for assembly).

Tests (23 new)

  • xcode-env: expandXcodeVars (incl. modifiers), plist parsing, discoverInfoPlist (file + env-var fallback), resolveReleaseAndDist.
  • wrap-call: bundle/hermes/compose parsing, --sourcemap-output injection, Hermes debug-id copy, SENTRY_RN_NO_DEBUG_ID.
  • command: need-Xcode error, debug passthrough (no upload), release wrap→report→upload (asserts artifacts + release/dist), no-sourcemaps warning.

Smoke-verified the bin.ts wrap dispatch end-to-end. typecheck/lint/check:deps/check:fragments/check:errors pass; full suite 8401 passed.

Port `react-native xcode` from the legacy CLI. Uploads React Native sourcemaps
from an Xcode build phase, in three modes:

- release build: wraps the RN build script (this CLI stands in for NODE_BINARY /
  HERMES_CLI_PATH via __SENTRY_RN_WRAP_XCODE_CALL, dispatched in bin.ts) to
  capture the produced bundle + sourcemap (incl. the Hermes combined sourcemap),
  then injects a debug ID and uploads.
- simulator build with --allow-fetch: downloads bundle + sourcemap from the
  packager, then uploads.
- debug build: just runs the build script.

Release/dist come from SENTRY_RELEASE/SENTRY_DIST or the app Info.plist
(<bundleId>@<version>+<build>), unless --no-auto-release.

New: src/commands/react-native/xcode.ts, src/lib/react-native/{wrap-call,xcode-env}.ts;
bin.ts wrap dispatch. Tests: xcode-env (plist/expand/release), wrap-call (bundle/
hermes/compose parsing + debug-id copy), command modes.

Limitations vs legacy (documented): Info.plist C preprocessing and
xcodebuild-outside-Xcode discovery are unsupported (set SENTRY_RELEASE/DIST);
indexed RAM bundles unsupported.
@github-actions

github-actions Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1193/

Built to branch gh-pages at 2026-07-03 14:26 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Comment thread src/commands/react-native/xcode.ts Resolved
Comment thread src/commands/react-native/xcode.ts Resolved
Comment thread src/commands/react-native/xcode.ts Resolved
bundle: report.packager_bundle_path,
sourcemap: report.packager_sourcemap_path,
},
};

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.

Hermes build falls back to packager

High Severity

If Hermes emits a bundle but the combined Hermes sourcemap path is missing from the report, the command silently uploads the Metro packager JS bundle and map instead of the Hermes output the app embeds.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 67e8285. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This matches the legacy CLI exactly: it uses the Hermes bundle + combined sourcemap only when BOTH are present, else the packager bundle + map. In a real build compose-source-maps always runs after hermesc, so 'hermes bundle without hermes sourcemap' doesn't occur; falling back to a hermes bundle + packager map would be worse (mismatched). Kept for parity.

@github-actions

github-actions Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

❌ Patch coverage is 78.80%. Project has 5324 uncovered lines.
❌ Project coverage is 81.76%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
src/commands/react-native/xcode.ts 71.22% ⚠️ 40 Missing and 18 partials
src/lib/react-native/wrap-call.ts 80.72% ⚠️ 16 Missing and 15 partials
src/lib/react-native/xcode-env.ts 93.44% ⚠️ 4 Missing and 4 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    81.86%    81.76%     -0.1%
==========================================
  Files          420       423        +3
  Lines        28910     29194      +284
  Branches     18765     18980      +215
==========================================
+ Hits         23666     23870      +204
- Misses        5244      5324       +80
- Partials      1938      1968       +30

Generated by Codecov Action

Comment thread src/lib/react-native/wrap-call.ts Resolved
- Cursor (High): do NOT re-inject a debug id into the xcode bundle — a release
  build's bundle may be Hermes bytecode, which a JS snippet corrupts. Read the
  existing debug id from the sourcemap (put there by the Metro/Sentry plugin and
  copied into the Hermes sourcemap by the wrapper) instead.
- Cursor (Medium): a failed wrapped build no longer publishes artifacts
  (matches the legacy CLI's exit-on-nonzero before upload).
- Cursor (Medium): packager fetch now checks HTTP status; a 404/500 body is not
  saved + uploaded.
- Warden: a signal-killed wrapped process now reports a non-zero status (was 0)
  in both wrap-call and the build-script runner.

Tests: sourcemap-derived debug id (bundle never mutated), no-upload on build
failure, signal-kill status. Extracted preparePair/classifyInvocation helpers to
stay under the complexity limit.
Comment thread src/commands/react-native/xcode.ts Resolved
Cursor (High): in wrap mode, NODE_BINARY/HERMES_CLI_PATH were set to
process.execPath. That's the CLI only for the SEA binary; under an npm install
execPath is Node, so RN would run plain node (never re-entering the wrapper) and
HERMES_CLI_PATH=node would break Hermes.

Fix: SEA still uses execPath directly; npm generates a small shim
(`exec "<node>" "<cli-script>" "$@"`) so `$NODE_BINARY <args>` re-enters the CLI
with __SENTRY_RN_WRAP_XCODE_CALL. Exported isSea() from wrap-call for detection.
Test asserts NODE_BINARY points at the shim in a non-SEA run.

@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 and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

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 c174d10. Configure here.

} else {
await uploadSourcemaps({ org, project, release, files });
uploads = 1;
}

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.

Missing RAM bundle upload guard

Medium Severity

The Xcode path uploads bundle/sourcemap pairs without checking for indexed RAM bundles. react-native gradle rejects that format before upload, and docs list it as unsupported, but uploadPair always calls uploadSourcemaps after a wrapped or fetched build. A ram-bundle build can still produce artifacts and send them to Sentry with misleading success.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c174d10. Configure here.

if (!filename) {
return fromEnvVars(env);
}
const path = join(cwd, env.PROJECT_DIR ?? ".", filename);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

path.join mangles absolute PROJECT_DIR, silently breaking Info.plist discovery in real Xcode builds

Use path.resolve instead of path.join here; join prepends cwd even when PROJECT_DIR is already absolute (as it always is in a live Xcode build phase), producing a wrong path that causes readFile to fail and the code to silently fall back to env-var-only resolution.

Evidence
  • PROJECT_DIR in a real Xcode build is an absolute path (e.g. /Users/foo/MyApp).
  • path.join('/cwd', '/Users/foo/MyApp', 'MyApp/Info.plist') → /cwd/Users/foo/MyApp/MyApp/Info.plist; Node's join does not treat later absolute segments as roots.
  • The resulting path is not found → readFile throws → the catch block falls back to fromEnvVars(env), silently skipping plist-based Xcode variable expansion (e.g. $(PRODUCT_BUNDLE_IDENTIFIER) in CFBundleIdentifier).
  • The test suite never exercises a real absolute PROJECT_DIR; it leaves the variable unset so the default "." makes join(dir, '.', 'Info.plist') work correctly, masking the regression.
  • Fix: replace join(cwd, env.PROJECT_DIR ?? '.', filename) with resolve(env.PROJECT_DIR ?? cwd, filename) (using path.resolve).

Identified by Warden find-bugs · M96-G9C

@BYK
BYK merged commit 3944810 into main Jul 3, 2026
32 checks passed
@BYK
BYK deleted the byk/feat/react-native-xcode branch July 3, 2026 14:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant