Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/content/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ cli/
│ │ ├── org/ # list, view
│ │ ├── proguard/ # upload, uuid
│ │ ├── project/ # create, delete, list, view
│ │ ├── react-native/# gradle
│ │ ├── release/ # archive, create, delete, deploy, deploys, finalize, list, propose-version, restore, set-commits, view
│ │ ├── replay/ # list, view
│ │ ├── repo/ # list
Expand Down
28 changes: 28 additions & 0 deletions docs/src/fragments/commands/react-native.md
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.
8 changes: 8 additions & 0 deletions plugins/sentry-cli/skills/sentry-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,14 @@ Work with ProGuard/R8 mapping files

→ Full flags and examples: `references/proguard.md`

### React-native

Upload React Native sourcemaps from build steps

- `sentry react-native gradle` — Upload a React Native bundle + sourcemap (Gradle build step)

→ Full flags and examples: `references/react-native.md`

### Replay

Search and inspect Session Replays
Expand Down
42 changes: 42 additions & 0 deletions plugins/sentry-cli/skills/sentry-cli/references/react-native.md
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.
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { listCommand as orgListCommand } from "./commands/org/list.js";
import { proguardRoute } from "./commands/proguard/index.js";
import { projectRoute } from "./commands/project/index.js";
import { listCommand as projectListCommand } from "./commands/project/list.js";
import { reactNativeRoute } from "./commands/react-native/index.js";
import { releaseRoute } from "./commands/release/index.js";
import { listCommand as releaseListCommand } from "./commands/release/list.js";
import { replayRoute } from "./commands/replay/index.js";
Expand Down Expand Up @@ -109,6 +110,7 @@ export const routes = buildRouteMap({
org: orgRoute,
project: projectRoute,
proguard: proguardRoute,
"react-native": reactNativeRoute,
replay: replayRoute,
release: releaseRoute,
repo: repoRoute,
Expand Down
224 changes: 224 additions & 0 deletions src/commands/react-native/gradle.ts
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

View check run for this annotation

@sentry/warden / warden: find-bugs

`--dist` without `--release` is silently ignored instead of rejected

When `--dist` is supplied without `--release`, the condition at line 193 is false so all distributions are silently dropped and only a single debug-ID-only upload is performed, contradicting the flag's documented requirement of `--release`.
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.

Dist flag ignored without release

Medium Severity

When --dist is passed without --release, the command still lists distributions in its output but calls uploadSourcemaps without dist, so artifacts are uploaded as a debug-ID-only set. The --dist help text says it requires --release, but nothing enforces that.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d780f7f. Configure here.


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}.`,
};
},
});
20 changes: 20 additions & 0 deletions src/commands/react-native/index.ts
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).",
},
});
Loading
Loading