diff --git a/packages/core/src/build-time-plugins/buildTimeOptionsBase.ts b/packages/core/src/build-time-plugins/buildTimeOptionsBase.ts index fbb8afd3b9fe..826ec0a4ae4c 100644 --- a/packages/core/src/build-time-plugins/buildTimeOptionsBase.ts +++ b/packages/core/src/build-time-plugins/buildTimeOptionsBase.ts @@ -84,6 +84,23 @@ export interface BuildTimeOptionsBase { */ 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; + /** * Enable debug information logs about the SDK during build-time. * Enabling this will give you, for example, logs about source maps. @@ -184,7 +201,9 @@ export type UnstableRollupPluginOptions = { interface SourceMapsOptions { /** - * If this flag is `true`, any functionality related to source maps will be disabled. + * If this flag is `true`, any functionality related to source maps will be disabled. This includes the automatic upload of source maps. + * + * By default (`false`), the plugin automatically uploads source maps during a production build if a Sentry auth token is detected. * * @default false */ diff --git a/packages/nuxt/.eslintrc.js b/packages/nuxt/.eslintrc.js index a22f9710cf6b..e6ea40d78d05 100644 --- a/packages/nuxt/.eslintrc.js +++ b/packages/nuxt/.eslintrc.js @@ -7,7 +7,7 @@ module.exports = { { files: ['vite.config.ts'], parserOptions: { - project: ['tsconfig.test.json'], + project: ['tsconfig.vite.json'], }, }, ], diff --git a/packages/nuxt/src/common/types.ts b/packages/nuxt/src/common/types.ts index 599b564f62a2..96d69354937c 100644 --- a/packages/nuxt/src/common/types.ts +++ b/packages/nuxt/src/common/types.ts @@ -1,3 +1,4 @@ +import type { BuildTimeOptionsBase } from '@sentry/core'; import type { init as initNode } from '@sentry/node'; import type { SentryRollupPluginOptions } from '@sentry/rollup-plugin'; import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; @@ -26,6 +27,7 @@ type SourceMapsOptions = { * Suppresses all logs. * * @default false + * @deprecated Use option `silent` instead of `sourceMapsUploadOptions.silent` */ silent?: boolean; @@ -43,6 +45,8 @@ type SourceMapsOptions = { * console.warn(err); * } * ``` + * + * @deprecated Use option `errorHandler` instead of `sourceMapsUploadOptions.errorHandler` */ errorHandler?: (err: Error) => void; @@ -50,6 +54,8 @@ type SourceMapsOptions = { * Options related to managing the Sentry releases for a build. * * More info: https://docs.sentry.io/product/releases/ + * + * @deprecated Use option `release` instead of `sourceMapsUploadOptions.release` */ release?: { /** @@ -62,6 +68,8 @@ type SourceMapsOptions = { * (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. + * + * @deprecated Use `release.name` instead of `sourceMapsUploadOptions.release.name` */ name?: string; }; @@ -71,6 +79,7 @@ type SourceMapsOptions = { * automatically generate and upload source maps to Sentry during a production build. * * @default true + * @deprecated Use option `sourcemaps.disable` instead of `sourceMapsUploadOptions.enabled` */ enabled?: boolean; @@ -81,12 +90,14 @@ type SourceMapsOptions = { * * To create an auth token, follow this guide: * @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens + * @deprecated Use option `authToken` instead of `sourceMapsUploadOptions.authToken` */ authToken?: string; /** * The organization slug of your Sentry organization. * Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable. + * @deprecated Use option `org` instead of `sourceMapsUploadOptions.org` */ org?: string; @@ -94,12 +105,15 @@ type SourceMapsOptions = { * The URL of your Sentry instance if you're using self-hosted Sentry. * * @default https://sentry.io by default the plugin will point towards the Sentry SaaS URL + * @deprecated Use `sentryUrl` instead of `sourceMapsUploadOptions.url` */ url?: string; /** * The project slug of your Sentry project. * Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable. + * + * @deprecated Use option `project` instead of `sourceMapsUploadOptions.project` */ project?: string; @@ -108,11 +122,14 @@ type SourceMapsOptions = { * It will not collect any sensitive or user-specific data. * * @default true + * @deprecated Use option `telemetry` instead of `sourceMapsUploadOptions.telemetry` */ telemetry?: boolean; /** * Options related to sourcemaps + * + * @deprecated Use option `sourcemaps` instead of `sourceMapsUploadOptions.sourcemaps` */ sourcemaps?: { /** @@ -124,6 +141,8 @@ type SourceMapsOptions = { * * The globbing patterns must follow the implementation of the `glob` package. * @see https://www.npmjs.com/package/glob#glob-primer + * + * @deprecated Use option `sourcemaps.assets` instead of `sourceMapsUploadOptions.sourcemaps.assets` */ assets?: string | Array; @@ -134,6 +153,8 @@ type SourceMapsOptions = { * or the default value for `assets` are uploaded. * * The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob) + * + * @deprecated Use option `sourcemaps.ignore` instead of `sourceMapsUploadOptions.sourcemaps.ignore` */ ignore?: string | Array; @@ -144,6 +165,8 @@ type SourceMapsOptions = { * @default [] - By default no files are deleted. * * The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob) + * + * @deprecated Use option `sourcemaps.filesToDeleteAfterUpload` instead of `sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload` */ filesToDeleteAfterUpload?: string | Array; }; @@ -152,7 +175,7 @@ type SourceMapsOptions = { /** * Build options for the Sentry module. These options are used during build-time by the Sentry SDK. */ -export type SentryNuxtModuleOptions = { +export type SentryNuxtModuleOptions = BuildTimeOptionsBase & { /** * Enable the Sentry Nuxt Module. * @@ -165,15 +188,12 @@ export type SentryNuxtModuleOptions = { * * These options are always read from the `sentry` module options in the `nuxt.config.(js|ts). * Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files. + * + * @deprecated This option was deprecated as it adds unnecessary nesting. + * Put the options one level higher to the root-level of the `sentry` module options. */ sourceMapsUploadOptions?: SourceMapsOptions; - /** - * Enable debug functionality of the SDK during build-time. - * Enabling this will give you, for example, logs about source maps. - */ - debug?: boolean; - /** * * Enables (partial) server tracing by automatically injecting Sentry for environments where modifying the node option `--import` is not possible. diff --git a/packages/nuxt/src/vite/sourceMaps.ts b/packages/nuxt/src/vite/sourceMaps.ts index 176690734339..0e35ba1175ce 100644 --- a/packages/nuxt/src/vite/sourceMaps.ts +++ b/packages/nuxt/src/vite/sourceMaps.ts @@ -17,10 +17,20 @@ export type SourceMapSetting = boolean | 'hidden' | 'inline'; * 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 { + // TODO(v11): remove deprecated options (also from SentryNuxtModuleOptions type) + const isDebug = moduleOptions.debug; + // eslint-disable-next-line deprecation/deprecation const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; - const sourceMapsEnabled = sourceMapsUploadOptions.enabled ?? true; + + const sourceMapsEnabled = + moduleOptions.sourcemaps?.disable === true + ? false + : moduleOptions.sourcemaps?.disable === false + ? true + : // eslint-disable-next-line deprecation/deprecation + sourceMapsUploadOptions.enabled ?? true; // In case we overwrite the source map settings, we default to deleting the files let shouldDeleteFilesFallback = { client: true, server: true }; @@ -42,6 +52,8 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu if ( isDebug && + !moduleOptions.sourcemaps?.filesToDeleteAfterUpload && + // eslint-disable-next-line deprecation/deprecation !sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload && (shouldDeleteFilesFallback.client || shouldDeleteFilesFallback.server) ) { @@ -134,10 +146,13 @@ function normalizePath(path: string): string { * * Only exported for Testing purposes. */ +// todo(v11): This "eslint-disable" can be removed again once we remove deprecated options. +// eslint-disable-next-line complexity export function getPluginOptions( moduleOptions: SentryNuxtModuleOptions, shouldDeleteFilesFallback?: { client: boolean; server: boolean }, ): SentryVitePluginOptions | SentryRollupPluginOptions { + // eslint-disable-next-line deprecation/deprecation const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {}; const shouldDeleteFilesAfterUpload = shouldDeleteFilesFallback?.client || shouldDeleteFilesFallback?.server; @@ -148,10 +163,17 @@ export function getPluginOptions( : []), ]; - if ( - typeof sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload === 'undefined' && - shouldDeleteFilesAfterUpload - ) { + // Check for filesToDeleteAfterUpload in new location first, then deprecated location + const sourcemapsOptions = moduleOptions.sourcemaps || {}; + // eslint-disable-next-line deprecation/deprecation + const deprecatedSourcemapsOptions = sourceMapsUploadOptions.sourcemaps || {}; + + const filesToDeleteAfterUpload = + sourcemapsOptions.filesToDeleteAfterUpload ?? + // eslint-disable-next-line deprecation/deprecation + deprecatedSourcemapsOptions.filesToDeleteAfterUpload; + + if (typeof filesToDeleteAfterUpload === 'undefined' && shouldDeleteFilesAfterUpload) { consoleSandbox(() => { // eslint-disable-next-line no-console console.log( @@ -164,16 +186,28 @@ export function getPluginOptions( } 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, - url: sourceMapsUploadOptions.url ?? process.env.SENTRY_URL, + // eslint-disable-next-line deprecation/deprecation + org: moduleOptions.org ?? sourceMapsUploadOptions.org ?? process.env.SENTRY_ORG, + // eslint-disable-next-line deprecation/deprecation + project: moduleOptions.project ?? sourceMapsUploadOptions.project ?? process.env.SENTRY_PROJECT, + // eslint-disable-next-line deprecation/deprecation + authToken: moduleOptions.authToken ?? sourceMapsUploadOptions.authToken ?? process.env.SENTRY_AUTH_TOKEN, + // eslint-disable-next-line deprecation/deprecation + telemetry: moduleOptions.telemetry ?? sourceMapsUploadOptions.telemetry ?? true, + // eslint-disable-next-line deprecation/deprecation + url: moduleOptions.sentryUrl ?? sourceMapsUploadOptions.url ?? process.env.SENTRY_URL, + headers: moduleOptions.headers, debug: moduleOptions.debug ?? false, - silent: sourceMapsUploadOptions.silent ?? false, - errorHandler: sourceMapsUploadOptions.errorHandler, + // eslint-disable-next-line deprecation/deprecation + silent: moduleOptions.silent ?? sourceMapsUploadOptions.silent ?? false, + // eslint-disable-next-line deprecation/deprecation + errorHandler: moduleOptions.errorHandler ?? sourceMapsUploadOptions.errorHandler, + bundleSizeOptimizations: moduleOptions.bundleSizeOptimizations, // todo: test if this can be overridden by the user release: { - name: sourceMapsUploadOptions.release?.name, + // eslint-disable-next-line deprecation/deprecation + name: moduleOptions.release?.name ?? sourceMapsUploadOptions.release?.name, + // Support all release options from BuildTimeOptionsBase + ...moduleOptions.release, ...moduleOptions?.unstable_sentryBundlerPluginOptions?.release, }, _metaOptions: { @@ -184,13 +218,16 @@ export function getPluginOptions( ...moduleOptions?.unstable_sentryBundlerPluginOptions, sourcemaps: { + disable: moduleOptions.sourcemaps?.disable, // The server/client files are in different places depending on the nitro preset (e.g. '.output/server' or '.netlify/functions-internal/server') // We cannot determine automatically how the build folder looks like (depends on the preset), so we have to accept that source maps are uploaded multiple times (with the vitePlugin for Nuxt and the rollupPlugin for Nitro). // If we could know where the server/client assets are located, we could do something like this (based on the Nitro preset): isNitro ? ['./.output/server/**/*'] : ['./.output/public/**/*'], - assets: sourceMapsUploadOptions.sourcemaps?.assets ?? undefined, - ignore: sourceMapsUploadOptions.sourcemaps?.ignore ?? undefined, - filesToDeleteAfterUpload: sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload - ? sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload + // eslint-disable-next-line deprecation/deprecation + assets: sourcemapsOptions.assets ?? deprecatedSourcemapsOptions.assets ?? undefined, + // eslint-disable-next-line deprecation/deprecation + ignore: sourcemapsOptions.ignore ?? deprecatedSourcemapsOptions.ignore ?? undefined, + filesToDeleteAfterUpload: filesToDeleteAfterUpload + ? filesToDeleteAfterUpload : shouldDeleteFilesFallback?.server || shouldDeleteFilesFallback?.client ? fallbackFilesToDelete : undefined, diff --git a/packages/nuxt/test/vite/buildOptions.test-d.ts b/packages/nuxt/test/vite/buildOptions.test-d.ts new file mode 100644 index 000000000000..ac2adde02ece --- /dev/null +++ b/packages/nuxt/test/vite/buildOptions.test-d.ts @@ -0,0 +1,129 @@ +import { describe, expectTypeOf, it } from 'vitest'; +import type { SentryNuxtModuleOptions } from '../../src/common/types'; + +describe('Sentry Nuxt build-time options type', () => { + it('includes all options based on type BuildTimeOptionsBase', () => { + const completeOptions: SentryNuxtModuleOptions = { + // --- BuildTimeOptionsBase options --- + org: 'test-org', + project: 'test-project', + authToken: 'test-auth-token', + sentryUrl: 'https://sentry.io', + headers: { Authorization: ' Bearer test-auth-token' }, + telemetry: true, + silent: false, + // eslint-disable-next-line no-console + errorHandler: (err: Error) => console.warn(err), + debug: false, + sourcemaps: { + disable: false, + assets: ['./dist/**/*'], + ignore: ['./dist/*.map'], + filesToDeleteAfterUpload: ['./dist/*.map'], + }, + release: { + name: 'test-release-1.0.0', + create: true, + finalize: true, + dist: 'test-dist', + vcsRemote: 'origin', + setCommits: { + auto: false, + repo: 'test/repo', + commit: 'abc123', + previousCommit: 'def456', + ignoreMissing: false, + ignoreEmpty: false, + }, + deploy: { + env: 'production', + started: 1234567890, + finished: 1234567900, + time: 10, + name: 'deployment-name', + url: 'https://example.com', + }, + }, + bundleSizeOptimizations: { + excludeDebugStatements: true, + excludeTracing: false, + excludeReplayShadowDom: true, + excludeReplayIframe: true, + excludeReplayWorker: true, + }, + + // --- SentryNuxtModuleOptions specific options --- + enabled: true, + autoInjectServerSentry: 'experimental_dynamic-import', + experimental_entrypointWrappedFunctions: ['default', 'handler', 'server', 'customExport'], + unstable_sentryBundlerPluginOptions: { + // Rollup plugin options + bundleSizeOptimizations: { + excludeDebugStatements: true, + }, + // Vite plugin options + sourcemaps: { + assets: './dist/**/*', + }, + }, + }; + + expectTypeOf(completeOptions).toEqualTypeOf(); + }); + + it('includes all deprecated options', () => { + const completeOptions: SentryNuxtModuleOptions = { + // SentryNuxtModuleOptions specific options + enabled: true, + debug: true, + autoInjectServerSentry: 'experimental_dynamic-import', // No need for 'as const' with type assertion + experimental_entrypointWrappedFunctions: ['default', 'handler', 'server', 'customExport'], + unstable_sentryBundlerPluginOptions: { + // Rollup plugin options + bundleSizeOptimizations: { + excludeDebugStatements: true, + }, + // Vite plugin options + sourcemaps: { + assets: './dist/**/*', + }, + }, + + // Deprecated sourceMapsUploadOptions + sourceMapsUploadOptions: { + silent: false, + // eslint-disable-next-line no-console + errorHandler: (err: Error) => console.warn(err), + release: { + name: 'deprecated-release', + }, + enabled: true, + authToken: 'deprecated-token', + org: 'deprecated-org', + url: 'https://deprecated.sentry.io', + project: 'deprecated-project', + telemetry: false, + sourcemaps: { + assets: './build/**/*', + ignore: ['./build/*.spec.js'], + filesToDeleteAfterUpload: ['./build/*.map'], + }, + }, + }; + + expectTypeOf(completeOptions).toEqualTypeOf(); + }); + + it('allows partial configuration', () => { + const minimalOptions: SentryNuxtModuleOptions = { enabled: true }; + + expectTypeOf(minimalOptions).toEqualTypeOf(); + + const partialOptions: SentryNuxtModuleOptions = { + enabled: true, + debug: false, + }; + + expectTypeOf(partialOptions).toEqualTypeOf(); + }); +}); diff --git a/packages/nuxt/test/vite/sourceMaps.test.ts b/packages/nuxt/test/vite/sourceMaps.test.ts index aaa7d2035655..59eac291fcc7 100644 --- a/packages/nuxt/test/vite/sourceMaps.test.ts +++ b/packages/nuxt/test/vite/sourceMaps.test.ts @@ -18,16 +18,14 @@ describe('getPluginOptions', () => { process.env = {}; }); - it('uses environment variables when no moduleOptions are provided', () => { - const defaultEnv = { + it('uses environment variables as fallback when no moduleOptions are provided', () => { + process.env = { SENTRY_ORG: 'default-org', SENTRY_PROJECT: 'default-project', SENTRY_AUTH_TOKEN: 'default-token', SENTRY_URL: 'https://santry.io', }; - process.env = { ...defaultEnv }; - const options = getPluginOptions({} as SentryNuxtModuleOptions); expect(options).toEqual( @@ -110,46 +108,159 @@ describe('getPluginOptions', () => { ); }); - it('overrides options that were undefined with options from unstable_sentryRollupPluginOptions', () => { - const customOptions: SentryNuxtModuleOptions = { + it('prioritizes new BuildTimeOptionsBase options over deprecated ones', () => { + const options: SentryNuxtModuleOptions = { + // New options + org: 'new-org', + project: 'new-project', + authToken: 'new-token', + sentryUrl: 'https://new.sentry.io', + telemetry: false, + silent: true, + debug: true, + sourcemaps: { + assets: ['new-assets/**/*'], + ignore: ['new-ignore.js'], + filesToDeleteAfterUpload: ['new-delete.js'], + }, + release: { + name: 'test-release', + create: false, + finalize: true, + dist: 'build-123', + vcsRemote: 'upstream', + setCommits: { auto: true }, + deploy: { env: 'production' }, + }, + bundleSizeOptimizations: { excludeTracing: true }, + + // Deprecated options (should be ignored) sourceMapsUploadOptions: { - org: 'custom-org', - project: 'custom-project', + org: 'old-org', + project: 'old-project', + authToken: 'old-token', + url: 'https://old.sentry.io', + telemetry: true, + silent: false, sourcemaps: { - assets: ['custom-assets/**/*'], - filesToDeleteAfterUpload: ['delete-this.js'], + assets: ['old-assets/**/*'], + ignore: ['old-ignore.js'], + filesToDeleteAfterUpload: ['old-delete.js'], }, - url: 'https://santry.io', + release: { name: 'old-release' }, }, + }; + + const result = getPluginOptions(options); + + expect(result).toMatchObject({ + org: 'new-org', + project: 'new-project', + authToken: 'new-token', + url: 'https://new.sentry.io', + telemetry: false, + silent: true, debug: true, - unstable_sentryBundlerPluginOptions: { - org: 'unstable-org', + bundleSizeOptimizations: { excludeTracing: true }, + release: { + name: 'test-release', + create: false, + finalize: true, + dist: 'build-123', + vcsRemote: 'upstream', + setCommits: { auto: true }, + deploy: { env: 'production' }, + }, + sourcemaps: expect.objectContaining({ + assets: ['new-assets/**/*'], + ignore: ['new-ignore.js'], + filesToDeleteAfterUpload: ['new-delete.js'], + }), + }); + }); + + it('falls back to deprecated options when new ones are undefined', () => { + const options: SentryNuxtModuleOptions = { + debug: true, + sourceMapsUploadOptions: { + org: 'deprecated-org', + project: 'deprecated-project', + authToken: 'deprecated-token', + url: 'https://deprecated.sentry.io', + telemetry: false, sourcemaps: { - assets: ['unstable-assets/**/*'], + assets: ['deprecated/**/*'], }, - release: { - name: 'test-release', + release: { name: 'deprecated-release' }, + }, + }; + + const result = getPluginOptions(options); + + expect(result).toMatchObject({ + org: 'deprecated-org', + project: 'deprecated-project', + authToken: 'deprecated-token', + url: 'https://deprecated.sentry.io', + telemetry: false, + debug: true, + release: { name: 'deprecated-release' }, + sourcemaps: expect.objectContaining({ + assets: ['deprecated/**/*'], + }), + }); + }); + + it('supports bundleSizeOptimizations', () => { + const options: SentryNuxtModuleOptions = { + bundleSizeOptimizations: { + excludeDebugStatements: true, + excludeTracing: true, + excludeReplayShadowDom: true, + excludeReplayIframe: true, + excludeReplayWorker: true, + }, + }; + + const result = getPluginOptions(options); + + expect(result.bundleSizeOptimizations).toEqual({ + excludeDebugStatements: true, + excludeTracing: true, + excludeReplayShadowDom: true, + excludeReplayIframe: true, + excludeReplayWorker: true, + }); + }); + + it('merges with unstable_sentryBundlerPluginOptions correctly', () => { + const options: SentryNuxtModuleOptions = { + org: 'base-org', + bundleSizeOptimizations: { + excludeDebugStatements: false, + }, + unstable_sentryBundlerPluginOptions: { + org: 'override-org', + release: { name: 'override-release' }, + sourcemaps: { assets: ['override/**/*'] }, + bundleSizeOptimizations: { + excludeDebugStatements: true, }, - url: 'https://suntry.io', }, }; - const options = getPluginOptions(customOptions); - expect(options).toEqual( - expect.objectContaining({ - debug: true, - org: 'unstable-org', - project: 'custom-project', - sourcemaps: expect.objectContaining({ - assets: ['unstable-assets/**/*'], - filesToDeleteAfterUpload: ['delete-this.js'], - rewriteSources: expect.any(Function), - }), - release: expect.objectContaining({ - name: 'test-release', - }), - url: 'https://suntry.io', + + const result = getPluginOptions(options); + + expect(result).toMatchObject({ + org: 'override-org', + release: { name: 'override-release' }, + sourcemaps: expect.objectContaining({ + assets: ['override/**/*'], }), - ); + bundleSizeOptimizations: { + excludeDebugStatements: true, + }, + }); }); it.each([ @@ -180,17 +291,24 @@ describe('getPluginOptions', () => { expectedFilesToDelete: ['.*/**/server/**/*.map', '.*/**/output/**/*.map', '.*/**/function/**/*.map'], }, { - name: 'no fallback, but custom filesToDeleteAfterUpload is provided', + name: 'no fallback, but custom filesToDeleteAfterUpload is provided (deprecated)', clientFallback: false, serverFallback: false, customOptions: { sourceMapsUploadOptions: { - sourcemaps: { - filesToDeleteAfterUpload: ['custom/path/**/*.map'], - }, + sourcemaps: { filesToDeleteAfterUpload: ['deprecated/path/**/*.map'] }, }, }, - expectedFilesToDelete: ['custom/path/**/*.map'], + expectedFilesToDelete: ['deprecated/path/**/*.map'], + }, + { + name: 'no fallback, but custom filesToDeleteAfterUpload is provided (new)', + clientFallback: false, + serverFallback: false, + customOptions: { + sourcemaps: { filesToDeleteAfterUpload: ['new-custom/path/**/*.map'] }, + }, + expectedFilesToDelete: ['new-custom/path/**/*.map'], }, { name: 'no fallback, both source maps explicitly false and no custom filesToDeleteAfterUpload', diff --git a/packages/nuxt/test/vite/utils.test.ts b/packages/nuxt/test/vite/utils.test.ts index 6380d2d6a0c7..1b256987828b 100644 --- a/packages/nuxt/test/vite/utils.test.ts +++ b/packages/nuxt/test/vite/utils.test.ts @@ -26,7 +26,7 @@ describe('findDefaultSdkInitFile', () => { 'should return the server file path with .%s extension if it exists', ext => { vi.spyOn(fs, 'existsSync').mockImplementation(filePath => { - return !(filePath instanceof URL) && filePath.includes(`sentry.server.config.${ext}`); + return !(filePath instanceof URL) && filePath.toString().includes(`sentry.server.config.${ext}`); }); const result = findDefaultSdkInitFile('server'); @@ -38,7 +38,7 @@ describe('findDefaultSdkInitFile', () => { 'should return the client file path with .%s extension if it exists', ext => { vi.spyOn(fs, 'existsSync').mockImplementation(filePath => { - return !(filePath instanceof URL) && filePath.includes(`sentry.client.config.${ext}`); + return !(filePath instanceof URL) && filePath.toString().includes(`sentry.client.config.${ext}`); }); const result = findDefaultSdkInitFile('client'); @@ -64,7 +64,8 @@ describe('findDefaultSdkInitFile', () => { vi.spyOn(fs, 'existsSync').mockImplementation(filePath => { return ( !(filePath instanceof URL) && - (filePath.includes('sentry.server.config.js') || filePath.includes('instrument.server.js')) + (filePath.toString().includes('sentry.server.config.js') || + filePath.toString().includes('instrument.server.js')) ); }); @@ -74,7 +75,7 @@ describe('findDefaultSdkInitFile', () => { it('should return the latest layer config file path if client config exists', () => { vi.spyOn(fs, 'existsSync').mockImplementation(filePath => { - return !(filePath instanceof URL) && filePath.includes('sentry.client.config.ts'); + return !(filePath instanceof URL) && filePath.toString().includes('sentry.client.config.ts'); }); const nuxtMock = { @@ -98,7 +99,8 @@ describe('findDefaultSdkInitFile', () => { vi.spyOn(fs, 'existsSync').mockImplementation(filePath => { return ( !(filePath instanceof URL) && - (filePath.includes('sentry.server.config.ts') || filePath.includes('instrument.server.ts')) + (filePath.toString().includes('sentry.server.config.ts') || + filePath.toString().includes('instrument.server.ts')) ); }); @@ -121,7 +123,7 @@ describe('findDefaultSdkInitFile', () => { it('should return the latest layer config file path if client config exists in former layer', () => { vi.spyOn(fs, 'existsSync').mockImplementation(filePath => { - return !(filePath instanceof URL) && filePath.includes('nuxt/sentry.client.config.ts'); + return !(filePath instanceof URL) && filePath.toString().includes('nuxt/sentry.client.config.ts'); }); const nuxtMock = { diff --git a/packages/nuxt/tsconfig.test.json b/packages/nuxt/tsconfig.test.json index c41efeacd92f..da5a816712e3 100644 --- a/packages/nuxt/tsconfig.test.json +++ b/packages/nuxt/tsconfig.test.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", - "include": ["test/**/*", "vite.config.ts"], + "include": ["test/**/*"], "compilerOptions": { // should include all types from `./tsconfig.json` plus types for all test frameworks used diff --git a/packages/nuxt/tsconfig.vite.json b/packages/nuxt/tsconfig.vite.json new file mode 100644 index 000000000000..3e2d75a55e61 --- /dev/null +++ b/packages/nuxt/tsconfig.vite.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + + "include": ["vite.config.ts"], + + "compilerOptions": { + "types": ["node"] + } +} diff --git a/packages/nuxt/vite.config.ts b/packages/nuxt/vite.config.ts index 0229ec105e04..75dc3957244a 100644 --- a/packages/nuxt/vite.config.ts +++ b/packages/nuxt/vite.config.ts @@ -5,5 +5,9 @@ export default { test: { environment: 'jsdom', setupFiles: ['./test/vitest.setup.ts'], + typecheck: { + enabled: true, + tsconfig: './tsconfig.test.json', + }, }, };