From d16753d69d9ed1b2b4639d8dd1976f4f8dde3df7 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Wed, 14 Aug 2024 17:53:32 +0200 Subject: [PATCH 1/5] feat(nuxt): Add sourcemaps from Nitro --- packages/nuxt/package.json | 3 +- packages/nuxt/src/vite/sourceMaps.ts | 111 +++++++++++++++++++-------- yarn.lock | 51 ++++++++++-- 3 files changed, 123 insertions(+), 42 deletions(-) diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 2216991b5e6e..20a9b46a1128 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -47,9 +47,10 @@ "@sentry/core": "8.26.0", "@sentry/node": "8.26.0", "@sentry/opentelemetry": "8.26.0", + "@sentry/rollup-plugin": "2.22.1", "@sentry/types": "8.26.0", "@sentry/utils": "8.26.0", - "@sentry/vite-plugin": "2.20.1", + "@sentry/vite-plugin": "2.22.1", "@sentry/vue": "8.26.0" }, "devDependencies": { diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 3518c45409e0..133cd1cf59a9 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -1,52 +1,97 @@ import type { Nuxt } from '@nuxt/schema'; +import { sentryRollupPlugin } from '@sentry/rollup-plugin'; import { sentryVitePlugin } from '@sentry/vite-plugin'; +import type { NitroConfig } from 'nitropack'; import type { SentryNuxtModuleOptions } from '../common/types'; /** * Setup source maps for Sentry inside the Nuxt module during build time. */ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nuxt): void { - nuxt.hook('vite:extendConfig', async (viteInlineConfig, _env) => { - const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; + const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; + const sourceMapsEnabled = sourceMapsUploadOptions.enabled ?? true; - if ((sourceMapsUploadOptions.enabled ?? true) && viteInlineConfig.mode !== 'development') { - const sentryPlugin = sentryVitePlugin({ - org: sourceMapsUploadOptions.org ?? process.env.SENTRY_ORG, - project: sourceMapsUploadOptions.project ?? process.env.SENTRY_PROJECT, - authToken: sourceMapsUploadOptions.authToken ?? process.env.SENTRY_AUTH_TOKEN, - telemetry: sourceMapsUploadOptions.telemetry ?? true, - sourcemaps: { - assets: sourceMapsUploadOptions.sourcemaps?.assets ?? undefined, - ignore: sourceMapsUploadOptions.sourcemaps?.ignore ?? undefined, - filesToDeleteAfterUpload: sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload ?? undefined, - }, - _metaOptions: { - telemetry: { - metaFramework: 'nuxt', - }, - }, - debug: moduleOptions.debug ?? false, - }); + nuxt.hook('vite:extendConfig', async (viteInlineConfig, _env) => { + if (sourceMapsEnabled && viteInlineConfig.mode !== 'development') { + const sentryPlugin = sentryVitePlugin(getPluginOptions(moduleOptions)); + // Add Sentry plugin viteInlineConfig.plugins = viteInlineConfig.plugins || []; viteInlineConfig.plugins.push(sentryPlugin); - const sourceMapsPreviouslyEnabled = viteInlineConfig.build?.sourcemap; + // Enable source maps + viteInlineConfig.build = viteInlineConfig.build || {}; + viteInlineConfig.build.sourcemap = true; - if (moduleOptions.debug && !sourceMapsPreviouslyEnabled) { - // eslint-disable-next-line no-console - console.log('[Sentry]: Enabled source maps generation in the Vite build options.'); - if (!moduleOptions.sourceMapsUploadOptions?.sourcemaps?.filesToDeleteAfterUpload) { - // eslint-disable-next-line no-console - console.warn( - `[Sentry] We recommend setting the \`sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload\` option to clean up source maps after uploading. -[Sentry] Otherwise, source maps might be deployed to production, depending on your configuration`, - ); + logDebugInfo(moduleOptions, viteInlineConfig.build?.sourcemap); + } + }); + + nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => { + if (sourceMapsEnabled && !nitroConfig.dev) { + const sentryPlugin = sentryRollupPlugin(getPluginOptions(moduleOptions)); + + if (nitroConfig.rollupConfig) { + // Add Sentry plugin + if (!Array.isArray(nitroConfig.rollupConfig.plugins)) { + nitroConfig.rollupConfig.plugins = nitroConfig.rollupConfig.plugins ? [nitroConfig.rollupConfig.plugins] : []; } - } + nitroConfig.rollupConfig.plugins.push(sentryPlugin); - viteInlineConfig.build = viteInlineConfig.build || {}; - viteInlineConfig.build.sourcemap = 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); + } } }); } + +/** + * Normalizes the beginning of a path from e.g. ../../../ to ./ + */ +function normalizePath(path: string): string { + return path.replace(/^(\.\.\/)+/, './'); +} + +function getPluginOptions(moduleOptions: SentryNuxtModuleOptions): object { + const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; + + return { + org: sourceMapsUploadOptions.org ?? process.env.SENTRY_ORG, + project: sourceMapsUploadOptions.project ?? process.env.SENTRY_PROJECT, + authToken: sourceMapsUploadOptions.authToken ?? process.env.SENTRY_AUTH_TOKEN, + telemetry: sourceMapsUploadOptions.telemetry ?? true, + sourcemaps: { + assets: sourceMapsUploadOptions.sourcemaps?.assets ?? ['./.output/public/**/*', './.output/server/**/*'], + ignore: sourceMapsUploadOptions.sourcemaps?.ignore ?? undefined, + filesToDeleteAfterUpload: sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload ?? undefined, + rewriteSources: (source: string) => normalizePath(source), + }, + _metaOptions: { + telemetry: { + metaFramework: 'nuxt', + }, + }, + debug: moduleOptions.debug ?? false, + }; +} + +function logDebugInfo(moduleOptions: SentryNuxtModuleOptions, sourceMapsPreviouslyEnabled: boolean): void { + if (moduleOptions.debug && !sourceMapsPreviouslyEnabled) { + // eslint-disable-next-line no-console + console.log('[Sentry]: Enabled source maps generation in the Vite build options.'); + + const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; + + if (!sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload) { + // eslint-disable-next-line no-console + console.warn( + `[Sentry] We recommend setting the \`sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload\` option to clean up source maps after uploading. +[Sentry] Otherwise, source maps might be deployed to production, depending on your configuration`, + ); + } + } +} diff --git a/yarn.lock b/yarn.lock index 481175f8db61..2940a3adc9d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8195,6 +8195,11 @@ resolved "https://registry.yarnpkg.com/@sentry/babel-plugin-component-annotate/-/babel-plugin-component-annotate-2.22.0.tgz#a7e1cc99d1a738d1eb17757341dff4db3a93c2dc" integrity sha512-UzH+NNhgnOo6UFku3C4TEz+pO/yDcIA5FKTJvLbJ7lQwAjsqLs3DZWm4cCA08skICb8mULArF6S/dn5/butVCA== +"@sentry/babel-plugin-component-annotate@2.22.1": + version "2.22.1" + resolved "https://registry.yarnpkg.com/@sentry/babel-plugin-component-annotate/-/babel-plugin-component-annotate-2.22.1.tgz#2877af31f1d0358202593fe6d14141827a2f1e42" + integrity sha512-rQEk8EeCIBQKivWNONllQhd/wGbfuK/WXJRM6TkjeikM3wrqJf4AmIBXoA6eg089DwBFzBaxGjjLWJNHKY440w== + "@sentry/bundler-plugin-core@2.16.0": version "2.16.0" resolved "https://registry.yarnpkg.com/@sentry/bundler-plugin-core/-/bundler-plugin-core-2.16.0.tgz#0c33e7a054fb56e43bd160ac141f71dfebf6dda5" @@ -8251,6 +8256,20 @@ magic-string "0.30.8" unplugin "1.0.1" +"@sentry/bundler-plugin-core@2.22.1": + version "2.22.1" + resolved "https://registry.yarnpkg.com/@sentry/bundler-plugin-core/-/bundler-plugin-core-2.22.1.tgz#a3c984fd0e6a7bc3977cd74a635f6222e69c4ef2" + integrity sha512-RFbS57zfPvUBe4DL/pjt6BWCEyGFkk/n4gLNZQ9Cf2gRdUVW80AtAMZwrlEELrpW1D8kONy6/kvWf0leicHRMg== + dependencies: + "@babel/core" "^7.18.5" + "@sentry/babel-plugin-component-annotate" "2.22.1" + "@sentry/cli" "^2.33.1" + dotenv "^16.3.1" + find-up "^5.0.0" + glob "^9.3.2" + magic-string "0.30.8" + unplugin "1.0.1" + "@sentry/cli-darwin@2.33.0": version "2.33.0" resolved "https://registry.yarnpkg.com/@sentry/cli-darwin/-/cli-darwin-2.33.0.tgz#c0f3352a9e58e4f02deca52f0d5a9bd14b3e4a32" @@ -8359,6 +8378,14 @@ "@sentry/cli-win32-i686" "2.33.1" "@sentry/cli-win32-x64" "2.33.1" +"@sentry/rollup-plugin@2.22.1": + version "2.22.1" + resolved "https://registry.yarnpkg.com/@sentry/rollup-plugin/-/rollup-plugin-2.22.1.tgz#644e6e47d4130bca31a578782813835ca243a484" + integrity sha512-ytioqf5e9lyuDc4G8cK0kMtl6DUUuPaE2ob583esnzEw/X15fpvdJOkBDNbyCtOrArm8me8o5lM47vi6FTv1vA== + dependencies: + "@sentry/bundler-plugin-core" "2.22.1" + unplugin "1.0.1" + "@sentry/vite-plugin@2.19.0": version "2.19.0" resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-2.19.0.tgz#c7938fb13eee15036963b87d7b12c4fc851e488b" @@ -8367,14 +8394,6 @@ "@sentry/bundler-plugin-core" "2.19.0" unplugin "1.0.1" -"@sentry/vite-plugin@2.20.1", "@sentry/vite-plugin@^2.20.1": - version "2.20.1" - resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-2.20.1.tgz#80d5639fca3f68fbf81c316883272ffb34dbc544" - integrity sha512-IOYAJRcV+Uqn0EL8rxcoCvE77PbtGzKjP+B6iIgDZ229AWbpfbpWY8zHCcufwdDzb5PtgOhWWHT74iAsNyij/A== - dependencies: - "@sentry/bundler-plugin-core" "2.20.1" - unplugin "1.0.1" - "@sentry/vite-plugin@2.22.0": version "2.22.0" resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-2.22.0.tgz#09743ac390cf8c1609f2fa6d5424548d0b6f7928" @@ -8383,6 +8402,22 @@ "@sentry/bundler-plugin-core" "2.22.0" unplugin "1.0.1" +"@sentry/vite-plugin@2.22.1": + version "2.22.1" + resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-2.22.1.tgz#66192485440fd7f3726279a6bda2de4e59e6fd13" + integrity sha512-TC+3RIcu0rnxaEPV8ZHjYlRHLx5M9eRDI2il1lFkSguTc0N89n7Tt/aDnFAwtaPG4yqPkhIMpxi7LfXx+YDJ1Q== + dependencies: + "@sentry/bundler-plugin-core" "2.22.1" + unplugin "1.0.1" + +"@sentry/vite-plugin@^2.20.1": + version "2.20.1" + resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-2.20.1.tgz#80d5639fca3f68fbf81c316883272ffb34dbc544" + integrity sha512-IOYAJRcV+Uqn0EL8rxcoCvE77PbtGzKjP+B6iIgDZ229AWbpfbpWY8zHCcufwdDzb5PtgOhWWHT74iAsNyij/A== + dependencies: + "@sentry/bundler-plugin-core" "2.20.1" + unplugin "1.0.1" + "@sentry/webpack-plugin@2.16.0": version "2.16.0" resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-2.16.0.tgz#4764577edb10c9575a8b4ce03135493f995f56b9" From 876563436264c8373760039c60a4f4ce4128c4ea Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Mon, 26 Aug 2024 10:27:05 +0200 Subject: [PATCH 2/5] review comments --- packages/nuxt/src/vite/sourceMaps.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 133cd1cf59a9..fd26d6695126 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -1,11 +1,11 @@ import type { Nuxt } from '@nuxt/schema'; -import { sentryRollupPlugin } from '@sentry/rollup-plugin'; -import { sentryVitePlugin } from '@sentry/vite-plugin'; +import { type SentryRollupPluginOptions, sentryRollupPlugin } from '@sentry/rollup-plugin'; +import { type SentryVitePluginOptions, sentryVitePlugin } from '@sentry/vite-plugin'; import type { NitroConfig } from 'nitropack'; import type { SentryNuxtModuleOptions } from '../common/types'; /** - * Setup source maps for Sentry inside the Nuxt module during build time. + * Setup source maps for Sentry inside the Nuxt module during build time (in Vite for Nuxt and Rollup for Nitro). */ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nuxt): void { const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; @@ -13,11 +13,9 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu nuxt.hook('vite:extendConfig', async (viteInlineConfig, _env) => { if (sourceMapsEnabled && viteInlineConfig.mode !== 'development') { - const sentryPlugin = sentryVitePlugin(getPluginOptions(moduleOptions)); - // Add Sentry plugin viteInlineConfig.plugins = viteInlineConfig.plugins || []; - viteInlineConfig.plugins.push(sentryPlugin); + viteInlineConfig.plugins.push(sentryVitePlugin(getPluginOptions(moduleOptions))); // Enable source maps viteInlineConfig.build = viteInlineConfig.build || {}; @@ -29,14 +27,13 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => { if (sourceMapsEnabled && !nitroConfig.dev) { - const sentryPlugin = sentryRollupPlugin(getPluginOptions(moduleOptions)); - if (nitroConfig.rollupConfig) { // Add Sentry plugin if (!Array.isArray(nitroConfig.rollupConfig.plugins)) { nitroConfig.rollupConfig.plugins = nitroConfig.rollupConfig.plugins ? [nitroConfig.rollupConfig.plugins] : []; } - nitroConfig.rollupConfig.plugins.push(sentryPlugin); + + nitroConfig.rollupConfig.plugins.push(sentryRollupPlugin(getPluginOptions(moduleOptions))); // Enable source maps nitroConfig.rollupConfig.output = nitroConfig?.rollupConfig?.output || {}; @@ -56,7 +53,7 @@ function normalizePath(path: string): string { return path.replace(/^(\.\.\/)+/, './'); } -function getPluginOptions(moduleOptions: SentryNuxtModuleOptions): object { +function getPluginOptions(moduleOptions: SentryNuxtModuleOptions): SentryVitePluginOptions | SentryRollupPluginOptions { const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; return { From 28efd998a23243ba6e785c8e9c5edd8176aaa748 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Tue, 27 Aug 2024 14:05:08 +0200 Subject: [PATCH 3/5] one line comment --- packages/nuxt/src/vite/sourceMaps.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index fd26d6695126..dd67de436eca 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -86,8 +86,7 @@ function logDebugInfo(moduleOptions: SentryNuxtModuleOptions, sourceMapsPrevious if (!sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload) { // eslint-disable-next-line no-console console.warn( - `[Sentry] We recommend setting the \`sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload\` option to clean up source maps after uploading. -[Sentry] Otherwise, source maps might be deployed to production, depending on your configuration`, + '[Sentry] We recommend setting the `sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload` option to clean up source maps after uploading. Otherwise, source maps might be deployed to production, depending on your configuration', ); } } From a1f389004d02269640f9591c475315df05c0fcb6 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Tue, 3 Sep 2024 15:27:59 +0200 Subject: [PATCH 4/5] add type checks --- packages/nuxt/src/vite/sourceMaps.ts | 42 ++++++++++++++++++---------- yarn.lock | 8 ++++++ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index dd67de436eca..3279f6f5e38f 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -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]; + } - 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), diff --git a/yarn.lock b/yarn.lock index 6f2432d7054a..56a6d99ebe70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8302,6 +8302,14 @@ "@sentry/cli-win32-i686" "2.33.1" "@sentry/cli-win32-x64" "2.33.1" +"@sentry/rollup-plugin@2.22.3": + version "2.22.3" + resolved "https://registry.yarnpkg.com/@sentry/rollup-plugin/-/rollup-plugin-2.22.3.tgz#18ab4b7903ee723bee4cf789b38bb3febb05faae" + integrity sha512-I1UsnYzZm5W7/Pyah2yxuMRxmzgf5iDKoptFfMaerpRO5oBhFO3tMnKSLAlYMvuXKRoYkInNv6ckkUcSOF6jig== + dependencies: + "@sentry/bundler-plugin-core" "2.22.3" + unplugin "1.0.1" + "@sentry/vite-plugin@2.22.3", "@sentry/vite-plugin@^2.22.3": version "2.22.3" resolved "https://registry.yarnpkg.com/@sentry/vite-plugin/-/vite-plugin-2.22.3.tgz#b52802412b6f3d8e3e56742afc9624d9babae5b6" From 2b5444aafbb3c7a102817eba7fc42f3973de0256 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Wed, 4 Sep 2024 16:54:58 +0200 Subject: [PATCH 5/5] review comments --- packages/nuxt/src/vite/sourceMaps.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 3279f6f5e38f..18eed2cbcfd8 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -2,14 +2,8 @@ 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). */ @@ -37,9 +31,10 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu nitroConfig.rollupConfig = {}; } - if (isNullValue(nitroConfig.rollupConfig.plugins)) { + if (nitroConfig.rollupConfig.plugins === null || nitroConfig.rollupConfig.plugins === undefined) { nitroConfig.rollupConfig.plugins = []; } else if (!Array.isArray(nitroConfig.rollupConfig.plugins)) { + // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin nitroConfig.rollupConfig.plugins = [nitroConfig.rollupConfig.plugins]; }