From fa8c1801131610e5fd2768b6b25894b047d14586 Mon Sep 17 00:00:00 2001 From: Maxim Lepekha Date: Mon, 3 Feb 2025 14:32:54 +0100 Subject: [PATCH] feat(nuxt): add `silent`, `errorHandler`, `release` to `SourceMapsOptions` (#15246) This pull request includes changes to enhance the configuration options for managing Sentry source maps in a Nuxt.js project. The most important changes include adding new options to suppress logs, handle errors during release creation, and manage Sentry releases. Enhancements to Sentry source maps configuration: * [`packages/nuxt/src/common/types.ts`](diffhunk://#diff-199725da81bbdbb2e85f3dfe2b1a2bf453b4c9755059e5050815d7fcde2f59a5R11-R41): Added `silent`, `errorHandler`, and `release` options to the `SourceMapsOptions` type to provide more control over logging, error handling, and release management. * [`packages/nuxt/src/vite/sourceMaps.ts`](diffhunk://#diff-d511a0577f152ed6476e519722483c904cd2878586fdcd27f71c5587036bee37R96-R98): Updated the `getPluginOptions` function to include the new `silent`, `errorHandler`, and `release` options, allowing them to be used during the source maps upload process. Before submitting a pull request, please take a look at our [Contributing](https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md) guidelines and verify: - [x] If you've added code that should be tested, please add tests. - [x] Ensure your code lints and the test suite passes (`yarn lint`) & (`yarn test`). --------- Co-authored-by: Sigrid Huemer <32902192+s1gr1d@users.noreply.github.com> --- packages/nuxt/src/common/types.ts | 44 ++++++++++++++++++++++++++++ packages/nuxt/src/vite/sourceMaps.ts | 6 ++++ 2 files changed, 50 insertions(+) diff --git a/packages/nuxt/src/common/types.ts b/packages/nuxt/src/common/types.ts index 8a9a453ff7db..b646ca9a25e2 100644 --- a/packages/nuxt/src/common/types.ts +++ b/packages/nuxt/src/common/types.ts @@ -8,6 +8,50 @@ export type SentryNuxtClientOptions = Omit[0] & objec export type SentryNuxtServerOptions = Omit[0] & object, 'app'>; type SourceMapsOptions = { + /** + * Suppresses all logs. + * + * @default false + */ + silent?: boolean; + + /** + * 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?: (err: Error) => void; + + /** + * Options related to managing the Sentry releases for a build. + * + * More info: https://docs.sentry.io/product/releases/ + */ + 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 * 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..4f1e1184e637 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -93,6 +93,12 @@ 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: { + name: sourceMapsUploadOptions.release?.name, + ...moduleOptions?.unstable_sentryBundlerPluginOptions?.release, + }, _metaOptions: { telemetry: { metaFramework: 'nuxt',