From bb2fc7ca947ad60d40dc34236e6f9c0d2b6fda4b Mon Sep 17 00:00:00 2001 From: Maxim Lepekha Date: Fri, 31 Jan 2025 12:01:09 +0100 Subject: [PATCH 1/3] feat(nuxt): add `silent`, `errorHandler`, `release` to `SourceMapsOptions` --- packages/nuxt/src/common/types.ts | 31 ++++++++++++++++++++++++++++ packages/nuxt/src/vite/sourceMaps.ts | 3 +++ 2 files changed, 34 insertions(+) diff --git a/packages/nuxt/src/common/types.ts b/packages/nuxt/src/common/types.ts index 8a9a453ff7db..b9b12e6296ae 100644 --- a/packages/nuxt/src/common/types.ts +++ b/packages/nuxt/src/common/types.ts @@ -8,6 +8,37 @@ export type SentryNuxtClientOptions = Omit[0] & objec export type SentryNuxtServerOptions = Omit[0] & object, 'app'>; type SourceMapsOptions = { + /** + * Suppresses all logs. + * + * @default false + */ + silent?: SentryVitePluginOptions['silent']; + + /** + * When an error occurs during release creation or sourcemaps upload, the plugin will call this function. + * + * By default, the plugin will simply throw an error, thereby stopping the bundling process. + * If an `errorHandler` callback is provided, compilation will continue, unless an error is + * thrown in the provided callback. + * + * To allow compilation to continue but still emit a warning, set this option to the following: + * + * ```js + * (err) => { + * console.warn(err); + * } + * ``` + */ + errorHandler?: SentryVitePluginOptions['errorHandler']; + + /** + * Options related to managing the Sentry releases for a build. + * + * More info: https://docs.sentry.io/product/releases/ + */ + release?: SentryVitePluginOptions['release']; + /** * If this flag is `true`, and an auth token is detected, the Sentry SDK will * automatically generate and upload source maps to Sentry during a production build. diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 0b264e822bcc..bf4f1cda3e5a 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -93,6 +93,9 @@ export function getPluginOptions( telemetry: sourceMapsUploadOptions.telemetry ?? true, url: sourceMapsUploadOptions.url ?? process.env.SENTRY_URL, debug: moduleOptions.debug ?? false, + silent: sourceMapsUploadOptions.silent ?? false, + errorHandler: sourceMapsUploadOptions.errorHandler, + release: sourceMapsUploadOptions.release, _metaOptions: { telemetry: { metaFramework: 'nuxt', From d1dab5e989f048f6d80e03c818358824c9e7a4ab Mon Sep 17 00:00:00 2001 From: Maxim Lepekha Date: Fri, 31 Jan 2025 13:00:15 +0100 Subject: [PATCH 2/3] fix: types in SourceMapsOptions --- packages/nuxt/src/common/types.ts | 19 ++++++++++++++++--- packages/nuxt/src/vite/sourceMaps.ts | 4 +++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/common/types.ts b/packages/nuxt/src/common/types.ts index b9b12e6296ae..b646ca9a25e2 100644 --- a/packages/nuxt/src/common/types.ts +++ b/packages/nuxt/src/common/types.ts @@ -13,7 +13,7 @@ type SourceMapsOptions = { * * @default false */ - silent?: SentryVitePluginOptions['silent']; + silent?: boolean; /** * When an error occurs during release creation or sourcemaps upload, the plugin will call this function. @@ -30,14 +30,27 @@ type SourceMapsOptions = { * } * ``` */ - errorHandler?: SentryVitePluginOptions['errorHandler']; + errorHandler?: (err: Error) => void; /** * Options related to managing the Sentry releases for a build. * * More info: https://docs.sentry.io/product/releases/ */ - release?: SentryVitePluginOptions['release']; + release?: { + /** + * Unique identifier for the release you want to create. + * + * This value can also be specified via the `SENTRY_RELEASE` environment variable. + * + * Defaults to automatically detecting a value for your environment. + * This includes values for Cordova, Heroku, AWS CodeBuild, CircleCI, Xcode, and Gradle, and otherwise uses the git `HEAD`'s commit SHA. + * (the latter requires access to git CLI and for the root directory to be a valid repository) + * + * If you didn't provide a value and the plugin can't automatically detect one, no release will be created. + */ + name?: string; + }; /** * If this flag is `true`, and an auth token is detected, the Sentry SDK will diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index bf4f1cda3e5a..39d0982fb18e 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -95,7 +95,9 @@ export function getPluginOptions( debug: moduleOptions.debug ?? false, silent: sourceMapsUploadOptions.silent ?? false, errorHandler: sourceMapsUploadOptions.errorHandler, - release: sourceMapsUploadOptions.release, + release: { + name: sourceMapsUploadOptions.release?.name, + }, _metaOptions: { telemetry: { metaFramework: 'nuxt', From 8ff2fe7846e4151757e1c1a1f9214db83a647964 Mon Sep 17 00:00:00 2001 From: Maxim Lepekha Date: Mon, 3 Feb 2025 11:09:57 +0100 Subject: [PATCH 3/3] fix: set `release` from `unstable_.release` Co-authored-by: Sigrid Huemer <32902192+s1gr1d@users.noreply.github.com> --- packages/nuxt/src/vite/sourceMaps.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 39d0982fb18e..4f1e1184e637 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -97,6 +97,7 @@ export function getPluginOptions( errorHandler: sourceMapsUploadOptions.errorHandler, release: { name: sourceMapsUploadOptions.release?.name, + ...moduleOptions?.unstable_sentryBundlerPluginOptions?.release, }, _metaOptions: { telemetry: {