Skip to content

feat: add sentry sourcemap inject and sentry sourcemap upload commands#547

Merged
BYK merged 8 commits intomainfrom
feat/sourcemap-cli-commands
Mar 24, 2026
Merged

feat: add sentry sourcemap inject and sentry sourcemap upload commands#547
BYK merged 8 commits intomainfrom
feat/sourcemap-cli-commands

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 24, 2026

Summary

Add user-facing CLI commands for sourcemap management, completing the native sourcemap toolchain started in #543.

New Commands

sentry sourcemap inject <dir>

  • Scans a directory recursively for JS files (.js/.mjs/.cjs) and their companion .map files
  • Injects Sentry debug IDs into each pair (idempotent — skips files that already have debug IDs)
  • Supports --ext for custom extensions, --dry-run for preview
  • Skips node_modules and hidden directories

sentry sourcemap upload [org/project/]<dir>

  • Uploads sourcemaps to Sentry using the chunk-upload + assemble protocol (from feat: native debug ID injection and sourcemap upload #543)
  • Supports --release and --url-prefix flags
  • Auto-detects org/project from DSN/config or accepts explicit org/project/ prefix
  • Both --json output and human-readable output supported

Code Changes

  • Moved debug ID functions from script/debug-id.tssrc/lib/sourcemap/debug-id.ts (canonical location)
  • script/debug-id.ts becomes a thin re-export (build scripts still import from here)
  • Added src/lib/sourcemap/inject.ts for directory scanning + injection
  • Registered sourcemap route in app.ts with sourcemaps plural alias
  • Generated SKILL.md and reference docs

Usage Examples

# Inject debug IDs into build output
sentry sourcemap inject ./dist

# Preview what would be modified
sentry sourcemap inject ./dist --dry-run

# Upload to Sentry
sentry sourcemap upload ./dist
sentry sourcemap upload my-org/my-project/./dist --release 1.0.0

Depends on: #543 (merged)

…mands

Add user-facing CLI commands for sourcemap management:

- `sentry sourcemap inject <dir>` — Scans a directory for JS files
  and their companion .map files, injects Sentry debug IDs for
  reliable sourcemap resolution. Supports --ext for custom extensions
  and --dry-run for preview.

- `sentry sourcemap upload [org/project/]<dir>` — Uploads sourcemaps
  to Sentry using the chunk-upload + assemble protocol. Supports
  --release and --url-prefix flags. Auto-detects org/project from
  DSN/config or accepts explicit org/project/ prefix.

Code organization:
- Moved debug ID functions from script/debug-id.ts to
  src/lib/sourcemap/debug-id.ts (the canonical location).
  script/debug-id.ts is now a thin re-export.
- Added src/lib/sourcemap/inject.ts for directory scanning + injection.
- Registered `sourcemap` route in app.ts with `sourcemaps` plural alias.
- Generated SKILL.md and reference docs for new commands.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Add sentry sourcemap inject and sentry sourcemap upload commands by BYK in #547
  • Native debug ID injection and sourcemap upload by BYK in #543

Internal Changes 🔧

Coverage

  • Use informational-patch input instead of sed hack by BYK in #544
  • Make checks informational on release branches by BYK in #541

Other

  • (ci) Upgrade GitHub Actions to Node 24 runtime by BYK in #542
  • (issue-list) Use collapse parameter to skip unused Snuba queries by BYK in #545
  • Regenerate skill files by github-actions[bot] in ec1ffe28

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2026

PR Preview Action v1.8.1

QR code for preview link

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

Built to branch gh-pages at 2026-03-24 08:17 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

- Rewrite upload command to take <directory> as a plain positional arg
  instead of using parseSlashSeparatedArg (which breaks on paths with
  slashes like ./dist). Org/project resolved via auto-detection cascade.
- injectDebugId now returns { debugId, wasInjected } so callers can
  distinguish newly injected files from pre-existing ones. This fixes
  the inject command's modified/skipped counts always showing 100%/0%.
- Register 'sourcemaps' as a duplicate route (not just a PLURAL_TO_SINGULAR
  entry) so 'sentry sourcemaps inject/upload' actually works.
- Regenerated SKILL.md for the updated upload command signature.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2026

Codecov Results 📊

126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1028 uncovered lines.
✅ Project coverage is 96.06%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    96.03%    96.06%    +0.03%
==========================================
  Files          186       192        +6
  Lines        25929     26084      +155
  Branches         0         0         —
==========================================
+ Hits         24899     25056      +157
- Misses        1030      1028        -2
- Partials         0         0         —

Generated by Codecov Action

BYK and others added 2 commits March 24, 2026 01:25
- Use path.relative() from the upload directory to construct artifact
  URLs, preserving subdirectory structure (e.g., static/js/main.js
  instead of just main.js). Prevents collisions for same-named files
  in different directories.
- Hide the 'sourcemaps' alias route in --help output.
Use path.basename() for sourcemap filename extraction and
path.relative() with backslash normalization for URLs.
Prevents broken URLs on Windows where path separators are
backslashes.
- Dry-run now reads the JS file to check for existing //# debugId=
  comments, correctly distinguishing 'would inject' from 'already
  has debug ID' in the modified/skipped counts.
- Removed dead 'debugId !== (dry run)' filter in upload command
  since upload never uses dry-run.
Copy link

@cursor cursor bot left a comment

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.

Fix All in Cursor

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

- Export EXISTING_DEBUGID_RE from debug-id.ts and import in inject.ts
  instead of maintaining duplicate regex definitions.
- Clarify upload command docs: it automatically injects debug IDs
  into files that don't already have them.
@BYK BYK closed this Mar 24, 2026
@BYK BYK reopened this Mar 24, 2026
@BYK BYK merged commit 9eac5c0 into main Mar 24, 2026
22 checks passed
@BYK BYK deleted the feat/sourcemap-cli-commands branch March 24, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant