From 3fdab049623555bf89c72a3d3d8f9efacf208a07 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 29 Nov 2024 18:44:49 +0100 Subject: [PATCH] feat: Warn about source-map generation (#14533) --- packages/astro/src/integration/index.ts | 9 ++++++++ packages/nextjs/src/config/types.ts | 2 +- packages/nextjs/src/config/webpack.ts | 24 ++++++++++++++++++++-- packages/solidstart/src/vite/sourceMaps.ts | 24 +++++++++++++--------- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index eb976e24213d..49e33ff0231d 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -35,6 +35,15 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { // We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env if (shouldUploadSourcemaps && command !== 'dev') { + // TODO(v9): Remove this warning + if (config?.vite?.build?.sourcemap === false) { + logger.warn( + "You disabled sourcemaps with the `vite.build.sourcemap` option. Currently, the Sentry SDK will override this option to generate sourcemaps. In future versions, the Sentry SDK will not override the `vite.build.sourcemap` option if you explicitly disable it. If you want to generate and upload sourcemaps please set the `vite.build.sourcemap` option to 'hidden' or undefined.", + ); + } + + // TODO: Add deleteSourcemapsAfterUpload option and warn if it isn't set. + updateConfig({ vite: { build: { diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index 75b1c29281fa..75ce7258fae5 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -470,7 +470,7 @@ export type IgnoreWarningsOption = ( // The two possible formats for providing custom webpack config in `next.config.js` export type WebpackConfigFunction = (config: WebpackConfigObject, options: BuildContext) => WebpackConfigObject; export type WebpackConfigObject = { - devtool?: string; + devtool?: string | boolean; plugins?: Array; entry: WebpackEntryProperty; output: { filename: string; path: string }; diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 445ef32ab1e3..20f1a00ce3c0 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -336,13 +336,33 @@ export function constructWebpackConfigFunction( if (sentryWebpackPlugin) { if (!userSentryOptions.sourcemaps?.disable) { + // TODO(v9): Remove this warning + if (newConfig.devtool === false) { + const runtimePrefix = !isServer ? 'Client' : runtime === 'edge' ? 'Edge' : 'Node.js'; + // eslint-disable-next-line no-console + console.warn( + `[@sentry/nextjs - ${runtimePrefix}] You disabled sourcemaps with the Webpack \`devtool\` option. Currently, the Sentry SDK will override this option to generate sourcemaps. In future versions, the Sentry SDK will not override the \`devtool\` option if you explicitly disable it. If you want to generate and upload sourcemaps please set the \`devtool\` option to 'hidden-source-map' or undefined.`, + ); + } + + // TODO(v9): Remove this warning and print warning in case source map deletion is auto configured + if (!isServer && !userSentryOptions.sourcemaps?.deleteSourcemapsAfterUpload) { + // eslint-disable-next-line no-console + console.warn( + "[@sentry/nextjs] The Sentry SDK has enabled source map generation for your Next.js app. If you don't want to serve Source Maps to your users, either set the `deleteSourceMapsAfterUpload` option to true, or manually delete the source maps after the build. In future Sentry SDK versions `deleteSourceMapsAfterUpload` will default to `true`.", + ); + } + // `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL` // comment at the bottom. For folks who aren't publicly hosting their sourcemaps, this is helpful because then // the browser won't look for them and throw errors into the console when it can't find them. Because this is a // front-end-only problem, and because `sentry-cli` handles sourcemaps more reliably with the comment than // without, the option to use `hidden-source-map` only applies to the client-side build. - newConfig.devtool = - isServer || userNextConfig.productionBrowserSourceMaps ? 'source-map' : 'hidden-source-map'; + if (isServer || userNextConfig.productionBrowserSourceMaps) { + newConfig.devtool = 'source-map'; + } else { + newConfig.devtool = 'hidden-source-map'; + } } newConfig.plugins = newConfig.plugins || []; diff --git a/packages/solidstart/src/vite/sourceMaps.ts b/packages/solidstart/src/vite/sourceMaps.ts index 548038515e79..0f8178356d88 100644 --- a/packages/solidstart/src/vite/sourceMaps.ts +++ b/packages/solidstart/src/vite/sourceMaps.ts @@ -15,18 +15,22 @@ export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions) apply: 'build', enforce: 'post', config(config) { - const sourceMapsPreviouslyNotEnabled = !config.build?.sourcemap; - if (debug && sourceMapsPreviouslyNotEnabled) { + // TODO(v9): Remove this warning + if (config.build?.sourcemap === false) { // eslint-disable-next-line no-console - console.log('[Sentry SolidStart Plugin] Enabling source map generation'); - if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) { - // eslint-disable-next-line no-console - console.warn( - `[Sentry SolidStart PLugin] We recommend setting the \`sourceMapsUploadOptions.filesToDeleteAfterUpload\` option to clean up source maps after uploading. -[Sentry SolidStart Plugin] Otherwise, source maps might be deployed to production, depending on your configuration`, - ); - } + console.warn( + "[Sentry SolidStart Plugin] You disabled sourcemaps with the `build.sourcemap` option. Currently, the Sentry SDK will override this option to generate sourcemaps. In future versions, the Sentry SDK will not override the `build.sourcemap` option if you explicitly disable it. If you want to generate and upload sourcemaps please set the `build.sourcemap` option to 'hidden' or undefined.", + ); } + + // TODO(v9): Remove this warning and print warning in case source map deletion is auto configured + if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) { + // eslint-disable-next-line no-console + console.warn( + "[Sentry SolidStart Plugin] The Sentry SDK has enabled source map generation for your SolidStart app. If you don't want to serve Source Maps to your users, either configure the `filesToDeleteAfterUpload` option with a glob to remove source maps after uploading them, or manually delete the source maps after the build. In future Sentry SDK versions source maps will be deleted automatically after uploading them.", + ); + } + return { ...config, build: {