-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(solidstart): Respect user-provided source map setting #14979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,53 +1,48 @@ | ||||||
import { consoleSandbox } from '@sentry/core'; | ||||||
import { sentryVitePlugin } from '@sentry/vite-plugin'; | ||||||
import type { Plugin } from 'vite'; | ||||||
import type { Plugin, UserConfig } from 'vite'; | ||||||
import type { SentrySolidStartPluginOptions } from './types'; | ||||||
|
||||||
/** | ||||||
* A Sentry plugin for SolidStart to enable source maps and use | ||||||
* @sentry/vite-plugin to automatically upload source maps to Sentry. | ||||||
* @param {SourceMapsOptions} options | ||||||
* A Sentry plugin for adding the @sentry/vite-plugin to automatically upload source maps to Sentry. | ||||||
*/ | ||||||
export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions): Plugin[] { | ||||||
export function makeAddSentryVitePlugin(options: SentrySolidStartPluginOptions, viteConfig: UserConfig): Plugin[] { | ||||||
const { authToken, debug, org, project, sourceMapsUploadOptions } = options; | ||||||
return [ | ||||||
{ | ||||||
name: 'sentry-solidstart-source-maps', | ||||||
apply: 'build', | ||||||
enforce: 'post', | ||||||
config(config) { | ||||||
// TODO(v9): Remove this warning | ||||||
if (config.build?.sourcemap === false) { | ||||||
// eslint-disable-next-line no-console | ||||||
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: { | ||||||
...config.build, | ||||||
sourcemap: true, | ||||||
}, | ||||||
}; | ||||||
}, | ||||||
}, | ||||||
let updatedFilesToDeleteAfterUpload: string[] | undefined = undefined; | ||||||
|
||||||
if ( | ||||||
typeof sourceMapsUploadOptions?.filesToDeleteAfterUpload === 'undefined' && | ||||||
typeof sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps?.filesToDeleteAfterUpload === | ||||||
'undefined' && | ||||||
// Only if source maps were previously not set, we update the "filesToDeleteAfterUpload" (as we override the setting with "hidden") | ||||||
typeof viteConfig.build?.sourcemap === 'undefined' | ||||||
) { | ||||||
// This also works for adapters, as the source maps are also copied to e.g. the .vercel folder | ||||||
updatedFilesToDeleteAfterUpload = ['.*/**/*.map']; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Unless this is intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional. It should match |
||||||
|
||||||
consoleSandbox(() => { | ||||||
// eslint-disable-next-line no-console | ||||||
console.log( | ||||||
`[Sentry] Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( | ||||||
updatedFilesToDeleteAfterUpload, | ||||||
)}\` to delete generated source maps after they were uploaded to Sentry.`, | ||||||
); | ||||||
}); | ||||||
} | ||||||
|
||||||
return [ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: If we only return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was done to make it easier to add more plugins if we ever need, but I guess we can cross that bridge then :) |
||||||
...sentryVitePlugin({ | ||||||
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN, | ||||||
bundleSizeOptimizations: options.bundleSizeOptimizations, | ||||||
debug: debug ?? false, | ||||||
org: org ?? process.env.SENTRY_ORG, | ||||||
project: project ?? process.env.SENTRY_PROJECT, | ||||||
sourcemaps: { | ||||||
filesToDeleteAfterUpload: sourceMapsUploadOptions?.filesToDeleteAfterUpload ?? undefined, | ||||||
filesToDeleteAfterUpload: | ||||||
(sourceMapsUploadOptions?.filesToDeleteAfterUpload || | ||||||
sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps?.filesToDeleteAfterUpload) ?? | ||||||
updatedFilesToDeleteAfterUpload, | ||||||
...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps, | ||||||
}, | ||||||
telemetry: sourceMapsUploadOptions?.telemetry ?? true, | ||||||
|
@@ -60,3 +55,85 @@ export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions) | |||||
}), | ||||||
]; | ||||||
} | ||||||
|
||||||
/** | ||||||
* A Sentry plugin for SolidStart to enable "hidden" source maps if they are unset. | ||||||
*/ | ||||||
export function makeEnableSourceMapsVitePlugin(options: SentrySolidStartPluginOptions): Plugin[] { | ||||||
return [ | ||||||
{ | ||||||
name: 'sentry-solidstart-update-source-map-setting', | ||||||
apply: 'build', | ||||||
enforce: 'post', | ||||||
config(viteConfig) { | ||||||
return { | ||||||
...viteConfig, | ||||||
build: { | ||||||
...viteConfig.build, | ||||||
sourcemap: getUpdatedSourceMapSettings(viteConfig, options), | ||||||
}, | ||||||
}; | ||||||
}, | ||||||
}, | ||||||
]; | ||||||
} | ||||||
|
||||||
/** There are 3 ways to set up source map generation (https://github.com/getsentry/sentry-j avascript/issues/13993) | ||||||
* | ||||||
* 1. User explicitly disabled source maps | ||||||
* - keep this setting (emit a warning that errors won't be unminified in Sentry) | ||||||
* - We won't upload anything | ||||||
* | ||||||
* 2. Users enabled source map generation (true, 'hidden', 'inline'). | ||||||
* - keep this setting (don't do anything - like deletion - besides uploading) | ||||||
* | ||||||
* 3. Users didn't set source maps generation | ||||||
* - we enable 'hidden' source maps generation | ||||||
* - configure `filesToDeleteAfterUpload` to delete all .map files (we emit a log about this) | ||||||
* | ||||||
* --> only exported for testing | ||||||
*/ | ||||||
export function getUpdatedSourceMapSettings( | ||||||
viteConfig: UserConfig, | ||||||
sentryPluginOptions?: SentrySolidStartPluginOptions, | ||||||
): boolean | 'inline' | 'hidden' { | ||||||
viteConfig.build = viteConfig.build || {}; | ||||||
|
||||||
const viteSourceMap = viteConfig?.build?.sourcemap; | ||||||
let updatedSourceMapSetting = viteSourceMap; | ||||||
|
||||||
const settingKey = 'vite.build.sourcemap'; | ||||||
|
||||||
if (viteSourceMap === false) { | ||||||
updatedSourceMapSetting = viteSourceMap; | ||||||
|
||||||
consoleSandbox(() => { | ||||||
// eslint-disable-next-line no-console | ||||||
console.warn( | ||||||
`[Sentry] Source map generation is currently disabled in your SolidStart configuration (\`${settingKey}: false \`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${settingKey}\` (e.g. by setting them to \`hidden\`).`, | ||||||
); | ||||||
}); | ||||||
} else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) { | ||||||
updatedSourceMapSetting = viteSourceMap; | ||||||
|
||||||
if (sentryPluginOptions?.debug) { | ||||||
consoleSandbox(() => { | ||||||
// eslint-disable-next-line no-console | ||||||
console.log( | ||||||
`[Sentry] We discovered \`${settingKey}\` is set to \`${viteSourceMap.toString()}\`. Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.`, | ||||||
); | ||||||
}); | ||||||
} | ||||||
} else { | ||||||
updatedSourceMapSetting = 'hidden'; | ||||||
|
||||||
consoleSandbox(() => { | ||||||
// eslint-disable-next-line no-console | ||||||
console.log( | ||||||
`[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`. The source maps will be deleted after they were uploaded to Sentry.`, | ||||||
); | ||||||
}); | ||||||
} | ||||||
|
||||||
return updatedSourceMapSetting; | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: any chance this comment is from astro (not sure if solid start has adapters)? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes, good catch