feat(nitro): Handle sourcemap preparation and upload#19304
feat(nitro): Handle sourcemap preparation and upload#19304logaretm wants to merge 13 commits intoawad/create-nitro-sdk-metadatafrom
Conversation
Codecov Results 📊Generated by Codecov Action |
size-limit report 📦
|
1923dda to
be2f037
Compare
0d86a79 to
9f6254a
Compare
be2f037 to
3b30e36
Compare
9f6254a to
63a2175
Compare
3b30e36 to
36c96b6
Compare
d3e3ae1 to
a24cad5
Compare
|
This pull request has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you apply the label |
3cf1515 to
342ea3b
Compare
a24cad5 to
1583866
Compare
342ea3b to
8d44437
Compare
a967e7a to
00bd835
Compare
There was a problem hiding this comment.
Pull request overview
Adds build-time sourcemap generation + post-build sourcemap (and debug ID) handling to the @sentry/nitro SDK by wiring Nitro’s compiled hook to @sentry/bundler-plugin-core.
Changes:
- Introduces
packages/nitro/src/sourceMaps.tsto configure Nitro sourcemap settings and to run a post-build upload flow viacreateSentryBuildPluginManager. - Threads
SentryNitroOptionsthrough module setup so sourcemap behavior can be configured fromwithSentryConfig/setupSentryNitroModule. - Adds Vitest coverage for option-shaping and basic hook registration behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/nitro/src/sourceMaps.ts | New sourcemap config + post-build hook which injects debug IDs and uploads sourcemaps via bundler-plugin-core |
| packages/nitro/test/sourceMaps.test.ts | New unit tests for plugin option building, config mutation, and hook registration |
| packages/nitro/src/module.ts | Passes Sentry options into module setup to enable sourcemap handling |
| packages/nitro/src/config.ts | Defines SentryNitroOptions from bundler-plugin-core options and enables sourcemap config during module setup |
| packages/nitro/rollup.npm.config.mjs | Marks @sentry/bundler-plugin-core as external in the package build |
| packages/nitro/package.json | Adds @sentry/bundler-plugin-core dependency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
492a81a to
7bf357b
Compare
0173b17 to
6b8d4d7
Compare
7bf357b to
2b2c36b
Compare
Implements HTTP server instrumentation for both `h3` and `srvx` by listening to their tracing channel events. - `h3` TC PR: h3js/h3#1251 - `srvx` TC PR: h3js/srvx#141 Closes #18123 --- **This PR is part of a stack:** - #20358 - #19224 - #19225 👈 - #19304 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2b2c36b to
d3328c8
Compare
Implements HTTP server instrumentation for both `h3` and `srvx` by listening to their tracing channel events. - `h3` TC PR: h3js/h3#1251 - `srvx` TC PR: h3js/srvx#141 Closes #18123 --- **This PR is part of a stack:** - #20358 - #19224 - #19225 👈 - #19304 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4cd6415 to
47d85ab
Compare
d3328c8 to
25e2ec0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 25e2ec0. Configure here.
Implements HTTP server instrumentation for both `h3` and `srvx` by listening to their tracing channel events. - `h3` TC PR: h3js/h3#1251 - `srvx` TC PR: h3js/srvx#141 Closes #18123 --- **This PR is part of a stack:** - #20358 - #19224 - #19225 👈 - #19304 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47d85ab to
fa580dd
Compare
…is set When `sourcemaps.disable` is `'disable-upload'`, the plugin should still inject debug IDs and keep `.map` files so users can upload them manually. Previously, both `injectDebugIds()` and `deleteArtifacts()` were incorrectly gated or ungated, causing debug IDs to be skipped and source maps to be deleted even in the manual-upload workflow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Derive `SentryNitroOptions` from `BuildTimeOptionsBase` (from `@sentry/core`) instead of picking from the bundler plugin's internal `Options` type. This provides a stable public API that follows this repo's semver, rather than exposing bundler-plugin-specific fields like `_metaOptions` and top-level `disable`. Key changes: - `url` option renamed to `sentryUrl` (consistent with other SDKs) - Top-level `disable` removed (use `sourcemaps.disable` instead) - `_metaOptions` no longer user-configurable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ing `true` Previously, `configureSourcemapSettings` unconditionally set `config.sourcemap = true`, overriding the user's explicit `false`. This could expose source maps publicly when users intentionally disabled them. Now follows the same 3-case pattern as other meta-framework SDKs (Nuxt): 1. User disabled (false) → keep their setting, warn about unminified errors 2. User enabled (true) → keep their setting 3. User didn't set (undefined) → enable for Sentry Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
`configureSourcemapSettings` runs at build time, but the `debug` logger from `@sentry/core` is only initialized by `Sentry.init()` at runtime. Switch to `console.warn`/`console.log` so build-time warnings (e.g. source maps explicitly disabled) are actually visible to developers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The `rewriteSources` option was hardcoded to `normalizePath`, silently discarding any custom function provided by the user. Now falls back to `normalizePath` only when the user doesn't provide their own function, matching the behavior of other meta-framework SDKs (Nuxt, Next.js). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously `filesToDeleteAfterUpload` defaulted to `['**/*.map']` unconditionally, deleting user-generated source maps even when the user explicitly set `sourcemap: true` in their Nitro config. Now the default only applies when Sentry was the one to enable sourcemap generation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Nitro spawns a nested Nitro instance for prerendering with the user's `modules` array re-installed, which caused the Sentry module to run twice and upload source maps + create a release twice per build. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ff591f3 to
14b31ea
Compare
| nitro.hooks.hook('compiled', async (_nitro: Nitro) => { | ||
| await handleSourceMapUpload(_nitro, options, sentryEnabledSourcemaps); | ||
| }); |
There was a problem hiding this comment.
Bug: The compiled hook in setupSourceMaps is registered even when config.sourcemap is false, causing source map processing to run unnecessarily on builds without sourcemaps.
Severity: MEDIUM
Suggested Fix
Add an early return in setupSourceMaps to prevent the hook from being registered when sourcemaps are disabled. This can be done by checking the sentryEnabledSourcemaps parameter at the beginning of the function and returning if it's false.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/nitro/src/sourceMaps.ts#L27-L29
Potential issue: When a user sets `config.sourcemap = false` in their Nitro
configuration, the `setupSourceMaps` function still registers a `compiled` hook. As a
result, when the build completes, `handleSourceMapUpload` is executed. This function
then calls `injectDebugIds` on a build output directory that contains no sourcemap
files, because their generation was disabled. This can lead to errors, unnecessary
processing, or confusing log output. The function lacks an early exit condition to check
if sourcemaps are disabled.

Adds automatic sourcemap handling to the Nitro SDK, using
@sentry/bundler-plugin-corefor builder-agnostic post-build upload.Nitro uses rollup or rolldown, so it made sense to make it as agnostic as possible.
Closes #17992
This PR is part of a stack: