-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nuxt): Upload sourcemaps generated by Nitro #13382
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d16753d
feat(nuxt): Add sourcemaps from Nitro
s1gr1d 8765634
review comments
s1gr1d 09f5f13
Merge branch 'develop' into sig/nuxt-nitro-sourcemaps
s1gr1d 28efd99
one line comment
s1gr1d e4fe965
Merge branch 'develop' into sig/nuxt-nitro-sourcemaps
s1gr1d 6a94108
Merge branch 'refs/heads/develop' into sig/nuxt-nitro-sourcemaps
s1gr1d a1f3890
add type checks
s1gr1d 3cf9f85
Merge branch 'refs/heads/develop' into sig/nuxt-nitro-sourcemaps
s1gr1d 2b5444a
review comments
s1gr1d cc7713f
Merge branch 'develop' into sig/nuxt-nitro-sourcemaps
s1gr1d 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 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 |
---|---|---|
|
@@ -2,8 +2,14 @@ import type { Nuxt } from '@nuxt/schema'; | |
import { type SentryRollupPluginOptions, sentryRollupPlugin } from '@sentry/rollup-plugin'; | ||
import { type SentryVitePluginOptions, sentryVitePlugin } from '@sentry/vite-plugin'; | ||
import type { NitroConfig } from 'nitropack'; | ||
import type { NullValue } from 'rollup'; | ||
import type { SentryNuxtModuleOptions } from '../common/types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function isNullValue(value: any): value is NullValue { | ||
return value === null || value === undefined; | ||
} | ||
|
||
/** | ||
* Setup source maps for Sentry inside the Nuxt module during build time (in Vite for Nuxt and Rollup for Nitro). | ||
*/ | ||
|
@@ -27,21 +33,25 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu | |
|
||
nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => { | ||
if (sourceMapsEnabled && !nitroConfig.dev) { | ||
if (nitroConfig.rollupConfig) { | ||
// Add Sentry plugin | ||
if (!Array.isArray(nitroConfig.rollupConfig.plugins)) { | ||
nitroConfig.rollupConfig.plugins = nitroConfig.rollupConfig.plugins ? [nitroConfig.rollupConfig.plugins] : []; | ||
} | ||
if (!nitroConfig.rollupConfig) { | ||
nitroConfig.rollupConfig = {}; | ||
} | ||
|
||
if (isNullValue(nitroConfig.rollupConfig.plugins)) { | ||
nitroConfig.rollupConfig.plugins = []; | ||
} else if (!Array.isArray(nitroConfig.rollupConfig.plugins)) { | ||
nitroConfig.rollupConfig.plugins = [nitroConfig.rollupConfig.plugins]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: Maybe we can leave a comment saying something along the lines of " |
||
} | ||
|
||
nitroConfig.rollupConfig.plugins.push(sentryRollupPlugin(getPluginOptions(moduleOptions))); | ||
// Add Sentry plugin | ||
nitroConfig.rollupConfig.plugins.push(sentryRollupPlugin(getPluginOptions(moduleOptions, true))); | ||
|
||
// Enable source maps | ||
nitroConfig.rollupConfig.output = nitroConfig?.rollupConfig?.output || {}; | ||
nitroConfig.rollupConfig.output.sourcemap = true; | ||
nitroConfig.rollupConfig.output.sourcemapExcludeSources = false; // Adding "sourcesContent" to the source map (Nitro sets this eto `true`) | ||
// Enable source maps | ||
nitroConfig.rollupConfig.output = nitroConfig?.rollupConfig?.output || {}; | ||
nitroConfig.rollupConfig.output.sourcemap = true; | ||
nitroConfig.rollupConfig.output.sourcemapExcludeSources = false; // Adding "sourcesContent" to the source map (Nitro sets this eto `true`) | ||
|
||
logDebugInfo(moduleOptions, nitroConfig.rollupConfig.output?.sourcemap); | ||
} | ||
logDebugInfo(moduleOptions, nitroConfig.rollupConfig.output?.sourcemap); | ||
} | ||
}); | ||
} | ||
|
@@ -53,7 +63,10 @@ function normalizePath(path: string): string { | |
return path.replace(/^(\.\.\/)+/, './'); | ||
} | ||
|
||
function getPluginOptions(moduleOptions: SentryNuxtModuleOptions): SentryVitePluginOptions | SentryRollupPluginOptions { | ||
function getPluginOptions( | ||
moduleOptions: SentryNuxtModuleOptions, | ||
isNitro = false, | ||
): SentryVitePluginOptions | SentryRollupPluginOptions { | ||
const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; | ||
|
||
return { | ||
|
@@ -62,7 +75,8 @@ function getPluginOptions(moduleOptions: SentryNuxtModuleOptions): SentryVitePlu | |
authToken: sourceMapsUploadOptions.authToken ?? process.env.SENTRY_AUTH_TOKEN, | ||
telemetry: sourceMapsUploadOptions.telemetry ?? true, | ||
sourcemaps: { | ||
assets: sourceMapsUploadOptions.sourcemaps?.assets ?? ['./.output/public/**/*', './.output/server/**/*'], | ||
assets: | ||
sourceMapsUploadOptions.sourcemaps?.assets ?? isNitro ? ['./.output/server/**/*'] : ['./.output/public/**/*'], | ||
ignore: sourceMapsUploadOptions.sourcemaps?.ignore ?? undefined, | ||
filesToDeleteAfterUpload: sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload ?? undefined, | ||
rewriteSources: (source: string) => normalizePath(source), | ||
|
This file contains 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
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.
l: Personal preference, I would just do
!== null
etc instead of the helper because it is easier to parse mentally but I'll leave it up to you.