This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Repository navigation
feat(react-native): add gradle command #1192
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ## Examples | ||
|
|
||
| ```bash | ||
| # Upload a bundle + sourcemap by debug ID (called by the Gradle plugin) | ||
| sentry react-native gradle \ | ||
| --bundle index.android.bundle \ | ||
| --sourcemap index.android.bundle.map | ||
|
|
||
| # Also associate with a release and distribution(s) | ||
| sentry react-native gradle \ | ||
| --bundle index.android.bundle \ | ||
| --sourcemap index.android.bundle.map \ | ||
| --release com.example.app@1.0.0 \ | ||
| --dist 1000 | ||
| ``` | ||
|
|
||
| ## Important Notes | ||
|
|
||
| - `react-native gradle` is normally invoked automatically by the | ||
| [sentry-android-gradle-plugin](https://docs.sentry.io/platforms/react-native/sourcemaps/); | ||
| you rarely run it by hand. | ||
| - It injects a debug ID into both the bundle and its sourcemap, then uploads | ||
| them under the `~/<filename>` convention. Without `--release` the files are | ||
| matched by debug ID; with `--release` they are also uploaded for each | ||
| `--dist`. | ||
| - Indexed RAM bundles are not supported — use a plain or Hermes bundle. | ||
| - The CLI always waits for server-side assembly; `--wait`/`--wait-for` are | ||
| accepted for backward compatibility but do not change behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
plugins/sentry-cli/skills/sentry-cli/references/react-native.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- | ||
| name: sentry-cli-react-native | ||
| version: 0.39.0-dev.0 | ||
| description: Upload React Native sourcemaps from build steps | ||
| requires: | ||
| bins: ["sentry"] | ||
| auth: true | ||
| --- | ||
|
|
||
| # React-native Commands | ||
|
|
||
| Upload React Native sourcemaps from build steps | ||
|
|
||
| ### `sentry react-native gradle` | ||
|
|
||
| Upload a React Native bundle + sourcemap (Gradle build step) | ||
|
|
||
| **Flags:** | ||
| - `--sourcemap <value> - Path to the sourcemap to upload` | ||
| - `--bundle <value> - Path to the bundle to upload` | ||
| - `--release <value> - Release version to publish to` | ||
| - `--dist <value>... - Distribution(s) to publish (repeatable; requires --release)` | ||
| - `--wait - Accepted for compatibility (the CLI always waits for assembly)` | ||
| - `--wait-for <value> - Accepted for compatibility (the CLI always waits for assembly)` | ||
|
|
||
| **Examples:** | ||
|
|
||
| ```bash | ||
| # Upload a bundle + sourcemap by debug ID (called by the Gradle plugin) | ||
| sentry react-native gradle \ | ||
| --bundle index.android.bundle \ | ||
| --sourcemap index.android.bundle.map | ||
|
|
||
| # Also associate with a release and distribution(s) | ||
| sentry react-native gradle \ | ||
| --bundle index.android.bundle \ | ||
| --sourcemap index.android.bundle.map \ | ||
| --release com.example.app@1.0.0 \ | ||
| --dist 1000 | ||
| ``` | ||
|
|
||
| All commands also support `--json`, `--fields`, `--help`, `--log-level`, and `--verbose` flags. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| /** | ||
| * sentry react-native gradle | ||
| * | ||
| * Upload a React Native bundle + sourcemap during a Gradle build step (invoked | ||
| * by the sentry-android-gradle-plugin). Injects a debug ID into the bundle and | ||
| * its sourcemap, then uploads both as artifacts under the `~/<filename>` | ||
| * convention — with debug-ID-only matching, or per release/distribution. | ||
| * | ||
| * Mirrors the legacy `sentry-cli react-native gradle`. | ||
| */ | ||
|
|
||
| import { readFile, stat } from "node:fs/promises"; | ||
| import { basename, resolve } from "node:path"; | ||
| import type { SentryContext } from "../../context.js"; | ||
| import type { ArtifactFile } from "../../lib/api/sourcemaps.js"; | ||
| import { uploadSourcemaps } from "../../lib/api/sourcemaps.js"; | ||
| import { buildCommand } from "../../lib/command.js"; | ||
| import { ContextError, ValidationError } from "../../lib/errors.js"; | ||
| import { mdKvTable, renderMarkdown } from "../../lib/formatters/markdown.js"; | ||
| import { CommandOutput } from "../../lib/formatters/output.js"; | ||
| import { logger } from "../../lib/logger.js"; | ||
| import { resolveOrgAndProject } from "../../lib/resolve-target.js"; | ||
| import { injectDebugId } from "../../lib/sourcemap/debug-id.js"; | ||
|
|
||
| const log = logger.withTag("react-native.gradle"); | ||
|
|
||
| const USAGE_HINT = | ||
| "sentry react-native gradle --sourcemap <path> --bundle <path>"; | ||
|
|
||
| /** Little-endian magic (0xFB0BD1E5) that starts an indexed RAM bundle. */ | ||
| const RAM_BUNDLE_MAGIC = [0xe5, 0xd1, 0x0b, 0xfb]; | ||
|
|
||
| /** Flags accepted by `react-native gradle`. */ | ||
| type GradleFlags = { | ||
| sourcemap: string; | ||
| bundle: string; | ||
| release?: string; | ||
| dist?: string[]; | ||
| wait?: boolean; | ||
| "wait-for"?: number; | ||
| }; | ||
|
|
||
| /** Structured result for the gradle upload. */ | ||
| type GradleResult = { | ||
| bundle: string; | ||
| sourcemap: string; | ||
| debugId: string; | ||
| release?: string; | ||
| dist?: string[]; | ||
| /** Number of upload operations performed (one per distribution). */ | ||
| uploads: number; | ||
| }; | ||
|
|
||
| /** Human-readable summary. */ | ||
| function formatGradleResult(data: GradleResult): string { | ||
| const rows: [string, string][] = [ | ||
| ["Bundle", data.bundle], | ||
| ["Sourcemap", data.sourcemap], | ||
| ["Debug ID", data.debugId], | ||
| ]; | ||
| if (data.release) { | ||
| rows.push(["Release", data.release]); | ||
| } | ||
| if (data.dist && data.dist.length > 0) { | ||
| rows.push(["Distributions", data.dist.join(", ")]); | ||
| } | ||
| return renderMarkdown(mdKvTable(rows)); | ||
| } | ||
|
|
||
| /** Ensure a path exists and is a regular file. */ | ||
| async function assertFile(path: string, label: string): Promise<void> { | ||
| const info = await stat(path).catch(() => null); | ||
| if (!info?.isFile()) { | ||
| throw new ValidationError(`${label} not found: ${path}`, label); | ||
| } | ||
| } | ||
|
|
||
| /** Reject indexed RAM bundles, which cannot carry an injected debug ID. */ | ||
| async function assertNotRamBundle(bundlePath: string): Promise<void> { | ||
| const handle = await readFile(bundlePath); | ||
| const isRamBundle = | ||
| handle.length >= RAM_BUNDLE_MAGIC.length && | ||
| RAM_BUNDLE_MAGIC.every((byte, i) => handle[i] === byte); | ||
| if (isRamBundle) { | ||
| throw new ValidationError( | ||
| "Indexed RAM bundles are not supported. Use a plain or Hermes bundle.", | ||
| "bundle" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** Build the artifact list for a debug-ID-injected bundle + sourcemap pair. */ | ||
| function buildArtifacts( | ||
| bundlePath: string, | ||
| sourcemapPath: string, | ||
| debugId: string | ||
| ): ArtifactFile[] { | ||
| const bundleName = basename(bundlePath); | ||
| const sourcemapName = basename(sourcemapPath); | ||
| return [ | ||
| { | ||
| path: bundlePath, | ||
| debugId, | ||
| type: "minified_source", | ||
| url: `~/${bundleName}`, | ||
| sourcemapFilename: sourcemapName, | ||
| }, | ||
| { | ||
| path: sourcemapPath, | ||
| debugId, | ||
| type: "source_map", | ||
| url: `~/${sourcemapName}`, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| export const gradleCommand = buildCommand({ | ||
| docs: { | ||
| brief: "Upload a React Native bundle + sourcemap (Gradle build step)", | ||
| fullDescription: | ||
| "Upload a React Native bundle and sourcemap during a Gradle build step " + | ||
| "(invoked by the sentry-android-gradle-plugin). A debug ID is injected " + | ||
| "into both files and they are uploaded under the `~/<filename>` " + | ||
| "convention.\n\n" + | ||
| "Without `--release`, files are matched by debug ID. With `--release`, " + | ||
| "they are also uploaded for each `--dist`.\n\n" + | ||
| "Note: the CLI always waits for server-side assembly; `--wait`/" + | ||
| "`--wait-for` are accepted for compatibility.", | ||
| }, | ||
| output: { | ||
| human: formatGradleResult, | ||
| }, | ||
| parameters: { | ||
| flags: { | ||
| sourcemap: { | ||
| kind: "parsed", | ||
| parse: String, | ||
| brief: "Path to the sourcemap to upload", | ||
| }, | ||
| bundle: { | ||
| kind: "parsed", | ||
| parse: String, | ||
| brief: "Path to the bundle to upload", | ||
| }, | ||
| release: { | ||
| kind: "parsed", | ||
| parse: String, | ||
| brief: "Release version to publish to", | ||
| optional: true, | ||
| }, | ||
| dist: { | ||
| kind: "parsed", | ||
| parse: String, | ||
| variadic: true, | ||
| brief: "Distribution(s) to publish (repeatable; requires --release)", | ||
| optional: true, | ||
| }, | ||
| wait: { | ||
| kind: "boolean", | ||
| brief: "Accepted for compatibility (the CLI always waits for assembly)", | ||
| optional: true, | ||
| }, | ||
| "wait-for": { | ||
| kind: "parsed", | ||
| parse: Number, | ||
| brief: "Accepted for compatibility (the CLI always waits for assembly)", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| }, | ||
| async *func(this: SentryContext, flags: GradleFlags) { | ||
| const bundlePath = resolve(this.cwd, flags.bundle); | ||
| const sourcemapPath = resolve(this.cwd, flags.sourcemap); | ||
| await assertFile(bundlePath, "bundle"); | ||
| await assertFile(sourcemapPath, "sourcemap"); | ||
| await assertNotRamBundle(bundlePath); | ||
|
|
||
| const resolved = await resolveOrgAndProject({ | ||
| cwd: this.cwd, | ||
| usageHint: USAGE_HINT, | ||
| }); | ||
| if (!resolved) { | ||
| throw new ContextError("Organization and project", USAGE_HINT); | ||
| } | ||
| const { org, project } = resolved; | ||
|
|
||
| log.info("Processing React Native sourcemaps for Sentry upload."); | ||
| const { debugId } = await injectDebugId(bundlePath, sourcemapPath); | ||
| const files = buildArtifacts(bundlePath, sourcemapPath, debugId); | ||
|
|
||
| const dists = flags.dist ?? []; | ||
| let uploads = 0; | ||
| if (flags.release && dists.length > 0) { | ||
| for (const dist of dists) { | ||
| log.info( | ||
| `Uploading sourcemaps for release ${flags.release} distribution ${dist}` | ||
| ); | ||
| await uploadSourcemaps({ | ||
| org, | ||
| project, | ||
| release: flags.release, | ||
| dist, | ||
| files, | ||
| }); | ||
| uploads += 1; | ||
| } | ||
| } else { | ||
| await uploadSourcemaps({ org, project, release: flags.release, files }); | ||
|
Check warning on line 208 in src/commands/react-native/gradle.ts
|
||
| uploads = 1; | ||
| } | ||
|
|
||
| yield new CommandOutput<GradleResult>({ | ||
| bundle: bundlePath, | ||
| sourcemap: sourcemapPath, | ||
| debugId, | ||
| release: flags.release, | ||
| dist: dists.length > 0 ? dists : undefined, | ||
| uploads, | ||
| }); | ||
| return { | ||
| hint: `Uploaded ${uploads} artifact set(s) with debug ID ${debugId}.`, | ||
| }; | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * sentry react-native | ||
| * | ||
| * Route map for React Native build-tool integration commands. | ||
| */ | ||
|
|
||
| import { buildRouteMap } from "../../lib/route-map.js"; | ||
| import { gradleCommand } from "./gradle.js"; | ||
|
|
||
| export const reactNativeRoute = buildRouteMap({ | ||
| routes: { | ||
| gradle: gradleCommand, | ||
| }, | ||
| docs: { | ||
| brief: "Upload React Native sourcemaps from build steps", | ||
| fullDescription: | ||
| "Integrations for uploading React Native bundles and sourcemaps from " + | ||
| "native build steps (Gradle/Xcode).", | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dist flag ignored without release
Medium Severity
When
--distis passed without--release, the command still lists distributions in its output but callsuploadSourcemapswithoutdist, so artifacts are uploaded as a debug-ID-only set. The--disthelp text says it requires--release, but nothing enforces that.Reviewed by Cursor Bugbot for commit d780f7f. Configure here.