Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 0 additions & 161 deletions packages/nuxt/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,156 +22,6 @@ export type SentryNuxtServerOptions = Parameters<typeof initNode>[0] & {
enableNitroErrorHandler?: boolean;
};

type SourceMapsOptions = {
/**
* Suppresses all logs.
*
* @default false
* @deprecated Use option `silent` instead of `sourceMapsUploadOptions.silent`
*/
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);
* }
* ```
*
* @deprecated Use option `errorHandler` instead of `sourceMapsUploadOptions.errorHandler`
*/
errorHandler?: (err: Error) => void;

/**
* 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?: {
/**
* 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.
*
* @deprecated Use `release.name` instead of `sourceMapsUploadOptions.release.name`
*/
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.
*
* @default true
* @deprecated Use option `sourcemaps.disable` instead of `sourceMapsUploadOptions.enabled`
*/
enabled?: boolean;

/**
* The auth token to use when uploading source maps to Sentry.
*
* Instead of specifying this option, you can also set the `SENTRY_AUTH_TOKEN` environment variable.
*
* 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;

/**
* 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;

/**
* If this flag is `true`, the Sentry plugin will collect some telemetry data and send it to Sentry.
* 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?: {
/**
* A glob or an array of globs that specify the build artifacts and source maps that will be uploaded to Sentry.
*
* If this option is not specified, sensible defaults based on your adapter and nuxt.config.js
* setup will be used. Use this option to override these defaults, for instance if you have a
* customized build setup that diverges from Nuxt's defaults.
*
* 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<string>;

/**
* A glob or an array of globs that specifies which build artifacts should not be uploaded to Sentry.
*
* @default [] - By default no files are ignored. Thus, all files matching the `assets` glob
* 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<string>;

/**
* A glob or an array of globs that specifies the build artifacts that should be deleted after the artifact
* upload to Sentry has been completed.
*
* @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<string>;
};
};

/**
* Build options for the Sentry module. These options are used during build-time by the Sentry SDK.
*/
Expand Down Expand Up @@ -200,17 +50,6 @@ export type SentryNuxtModuleOptions = BuildTimeOptionsBase & {
useDiagnosticsChannelInjection?: boolean;
};

/**
* Options for the Sentry Vite plugin to customize the source maps upload process.
*
* 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;

/**
*
* Enables (partial) server tracing by automatically injecting Sentry for environments where modifying the node option `--import` is not possible.
Expand Down
123 changes: 50 additions & 73 deletions packages/nuxt/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,9 @@ export function setupSourceMaps(
nuxt: Nuxt,
addVitePlugin: (plugin: Plugin[], options?: { dev?: boolean; build?: boolean }) => void,
): void {
// TODO(v11): remove deprecated options (also from SentryNuxtModuleOptions type)

const isDebug = moduleOptions.debug;

// eslint-disable-next-line typescript/no-deprecated
const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {};

const sourceMapsEnabled =
moduleOptions.sourcemaps?.disable === true
? false
: moduleOptions.sourcemaps?.disable === false
? true
: // eslint-disable-next-line typescript/no-deprecated
(sourceMapsUploadOptions.enabled ?? true);
const sourceMapsEnabled = moduleOptions.sourcemaps?.disable !== true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed hahaha


// In case we overwrite the source map settings, we default to deleting the files
const shouldDeleteFilesFallback = { client: true, server: true };
Expand All @@ -62,11 +51,7 @@ export function setupSourceMaps(
? 'server-side'
: 'client-side';

if (
!moduleOptions.sourcemaps?.filesToDeleteAfterUpload &&
// eslint-disable-next-line typescript/no-deprecated
!sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload
) {
if (!moduleOptions.sourcemaps?.filesToDeleteAfterUpload) {
// eslint-disable-next-line no-console
console.log(
`[Sentry] We enabled \`'hidden'\` source maps for your ${enabledDeleteFallbacks} build. Source map files will be automatically deleted after uploading them to Sentry.`,
Expand Down Expand Up @@ -131,65 +116,27 @@ 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 typescript/no-deprecated
const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {};

const shouldDeleteFilesAfterUpload = shouldDeleteFilesFallback?.client || shouldDeleteFilesFallback?.server;
const fallbackFilesToDelete = [
...(shouldDeleteFilesFallback?.client ? ['.*/**/public/**/*.map'] : []),
...(shouldDeleteFilesFallback?.server
? ['.*/**/server/**/*.map', '.*/**/output/**/*.map', '.*/**/function/**/*.map']
: []),
];

// Check for filesToDeleteAfterUpload in new location first, then deprecated location
const sourcemapsOptions = moduleOptions.sourcemaps || {};
// eslint-disable-next-line typescript/no-deprecated
const deprecatedSourcemapsOptions = sourceMapsUploadOptions.sourcemaps || {};

const filesToDeleteAfterUpload =
sourcemapsOptions.filesToDeleteAfterUpload ??
// eslint-disable-next-line typescript/no-deprecated
deprecatedSourcemapsOptions.filesToDeleteAfterUpload;

if (typeof filesToDeleteAfterUpload === 'undefined' && shouldDeleteFilesAfterUpload && moduleOptions.debug) {
// eslint-disable-next-line no-console
console.log(
`[Sentry] Setting \`sentry.sourceMapsUploadOptions.sourcemaps.filesToDeleteAfterUpload: [${fallbackFilesToDelete
// Logging it as strings in the array
.map(path => `"${path}"`)
.join(', ')}]\` to delete generated source maps after they were uploaded to Sentry.`,
);
}
const filesToDeleteAfterUpload = resolveFilesToDeleteAfterUpload(moduleOptions, shouldDeleteFilesFallback);

return {
applicationKey: moduleOptions.applicationKey,
// eslint-disable-next-line typescript/no-deprecated
org: moduleOptions.org ?? sourceMapsUploadOptions.org ?? process.env.SENTRY_ORG,
// eslint-disable-next-line typescript/no-deprecated
project: moduleOptions.project ?? sourceMapsUploadOptions.project ?? process.env.SENTRY_PROJECT,
// eslint-disable-next-line typescript/no-deprecated
authToken: moduleOptions.authToken ?? sourceMapsUploadOptions.authToken ?? process.env.SENTRY_AUTH_TOKEN,
// eslint-disable-next-line typescript/no-deprecated
telemetry: moduleOptions.telemetry ?? sourceMapsUploadOptions.telemetry ?? true,
// eslint-disable-next-line typescript/no-deprecated
url: moduleOptions.sentryUrl ?? sourceMapsUploadOptions.url ?? process.env.SENTRY_URL,
org: moduleOptions.org ?? process.env.SENTRY_ORG,
project: moduleOptions.project ?? process.env.SENTRY_PROJECT,
authToken: moduleOptions.authToken ?? process.env.SENTRY_AUTH_TOKEN,
telemetry: moduleOptions.telemetry ?? true,
url: moduleOptions.sentryUrl ?? process.env.SENTRY_URL,
headers: moduleOptions.headers,
debug: moduleOptions.debug ?? false,
// eslint-disable-next-line typescript/no-deprecated
silent: moduleOptions.silent ?? sourceMapsUploadOptions.silent ?? false,
// eslint-disable-next-line typescript/no-deprecated
errorHandler: moduleOptions.errorHandler ?? sourceMapsUploadOptions.errorHandler,
silent: moduleOptions.silent ?? false,
errorHandler: moduleOptions.errorHandler,
bundleSizeOptimizations: moduleOptions.bundleSizeOptimizations, // todo: test if this can be overridden by the user
release: {
// eslint-disable-next-line typescript/no-deprecated
name: moduleOptions.release?.name ?? sourceMapsUploadOptions.release?.name,
name: moduleOptions.release?.name,
// Support all release options from BuildTimeOptionsBase
...moduleOptions.release,
...moduleOptions?.unstable_sentryBundlerPluginOptions?.release,
Expand All @@ -206,21 +153,51 @@ export function getPluginOptions(
// 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/**/*'],
// eslint-disable-next-line typescript/no-deprecated
assets: sourcemapsOptions.assets ?? deprecatedSourcemapsOptions.assets ?? undefined,
// eslint-disable-next-line typescript/no-deprecated
ignore: sourcemapsOptions.ignore ?? deprecatedSourcemapsOptions.ignore ?? undefined,
filesToDeleteAfterUpload: filesToDeleteAfterUpload
? filesToDeleteAfterUpload
: shouldDeleteFilesFallback?.server || shouldDeleteFilesFallback?.client
? fallbackFilesToDelete
: undefined,
assets: sourcemapsOptions.assets ?? undefined,
ignore: sourcemapsOptions.ignore ?? undefined,
filesToDeleteAfterUpload,
rewriteSources: sourcemapsOptions.rewriteSources ?? normalizePath,
...moduleOptions?.unstable_sentryBundlerPluginOptions?.sourcemaps,
},
};
}

/**
* Users can set `filesToDeleteAfterUpload` themselves. If they don't, we fall back to deleting the
* client/server source maps — but only the ones Sentry generated itself (i.e. when the user didn't
* configure source maps at all). If the user explicitly set source maps, we leave their files alone.
*/
Comment on lines +165 to +169

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nuxt has no undefined default values for source maps so this "deleting by default" cannot happen in the default case. Only if users would set them to undefined.

Maybe that's worth pointing out here. Also a link to the docs: https://nuxt.com/docs/4.x/api/nuxt-config#sourcemap

function resolveFilesToDeleteAfterUpload(
moduleOptions: SentryNuxtModuleOptions,
shouldDeleteFilesFallback?: { client: boolean; server: boolean },
): string | Array<string> | undefined {
const shouldDeleteFilesAfterUpload = shouldDeleteFilesFallback?.client || shouldDeleteFilesFallback?.server;
const fallbackFilesToDelete = [
...(shouldDeleteFilesFallback?.client ? ['.*/**/public/**/*.map'] : []),
...(shouldDeleteFilesFallback?.server
? ['.*/**/server/**/*.map', '.*/**/output/**/*.map', '.*/**/function/**/*.map']
: []),
];

const filesToDeleteAfterUpload = moduleOptions.sourcemaps?.filesToDeleteAfterUpload;

if (typeof filesToDeleteAfterUpload === 'undefined' && shouldDeleteFilesAfterUpload && moduleOptions.debug) {
// eslint-disable-next-line no-console
console.log(
`[Sentry] Setting \`sentry.sourcemaps.filesToDeleteAfterUpload: [${fallbackFilesToDelete
// Logging it as strings in the array
.map(path => `"${path}"`)
.join(', ')}]\` to delete generated source maps after they were uploaded to Sentry.`,
);
}

return filesToDeleteAfterUpload
? filesToDeleteAfterUpload
: shouldDeleteFilesAfterUpload
? fallbackFilesToDelete
: undefined;
}

/* There are multiple ways to set up source maps (https://github.com/getsentry/sentry-javascript/issues/13993 and https://github.com/getsentry/sentry-javascript/pull/15859)
1. User explicitly disabled source maps
- keep this setting (emit a warning that errors won't be unminified in Sentry)
Expand Down
43 changes: 0 additions & 43 deletions packages/nuxt/test/vite/buildOptions.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,49 +75,6 @@ describe('Sentry Nuxt build-time options type', () => {
expectTypeOf(completeOptions).toEqualTypeOf<SentryNuxtModuleOptions>();
});

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<SentryNuxtModuleOptions>();
});

it('allows partial configuration', () => {
const minimalOptions: SentryNuxtModuleOptions = { enabled: true };

Expand Down
Loading
Loading