Repository navigation
feat(react-native): add xcode command - #1193
Conversation
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.
|
| bundle: report.packager_bundle_path, | ||
| sourcemap: report.packager_sourcemap_path, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 67e8285. Configure here.
There was a problem hiding this comment.
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.
Codecov Results 📊❌ Patch coverage is 78.80%. Project has 5324 uncovered lines. Files with missing lines (3)
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 +30Generated by Codecov Action |
- 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.
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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; | ||
| } |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit c174d10. Configure here.
| if (!filename) { | ||
| return fromEnvVars(env); | ||
| } | ||
| const path = join(cwd, env.PROJECT_DIR ?? ".", filename); |
There was a problem hiding this comment.
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_DIRin 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'sjoindoes not treat later absolute segments as roots.- The resulting path is not found →
readFilethrows → thecatchblock falls back tofromEnvVars(env), silently skipping plist-based Xcode variable expansion (e.g.$(PRODUCT_BUNDLE_IDENTIFIER)inCFBundleIdentifier). - The test suite never exercises a real absolute
PROJECT_DIR; it leaves the variable unset so the default"."makesjoin(dir, '.', 'Info.plist')work correctly, masking the regression. - Fix: replace
join(cwd, env.PROJECT_DIR ?? '.', filename)withresolve(env.PROJECT_DIR ?? cwd, filename)(usingpath.resolve).
Identified by Warden find-bugs · M96-G9C


Ports
react-native xcodefrom 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)NODE_BINARY/HERMES_CLI_PATH(via__SENTRY_RN_WRAP_XCODE_CALL, dispatched at the top ofbin.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.--allow-fetch— downloads the bundle + sourcemap from the running packager (waits up to 10s), then uploads.Release/distribution come from
SENTRY_RELEASE/SENTRY_DISTor the appInfo.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— theNODE_BINARY/hermesc shim: parses the RNbundle/ram-bundle/export:embed, Hermes-emit-binary, andcompose-source-maps.jsinvocations; adds a--sourcemap-outputwhen 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 vianode:sea.src/lib/react-native/xcode-env.ts—findNode/findHermesc,expandXcodeVars($(VAR)/${VAR}with:rfc1034identifier/:identifier), a minimal XMLInfo.plistparser, and release/dist resolution.src/commands/react-native/xcode.ts— the three-modeexecuteflow; reusesinjectDebugId+uploadSourcemaps(same~/<filename>artifact convention asreact-native gradle).Documented limitations vs legacy
Info.plistC preprocessing (INFOPLIST_PREPROCESS) andxcodebuild-based discovery outside an Xcode build are not supported — setSENTRY_RELEASE/SENTRY_DISTin those cases.--wait/--wait-forare 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-outputinjection, Hermes debug-id copy,SENTRY_RN_NO_DEBUG_ID.Smoke-verified the
bin.tswrap dispatch end-to-end.typecheck/lint/check:deps/check:fragments/check:errorspass; full suite 8401 passed.