MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / setupSourceMaps

Function setupSourceMaps

packages/nuxt/src/vite/sourceMaps.ts:20–122  ·  view source on GitHub ↗
(
  moduleOptions: SentryNuxtModuleOptions,
  nuxt: Nuxt,
  addVitePlugin: (plugin: Plugin[], options?: { dev?: boolean; build?: boolean }) => void,
)

Source from the content-addressed store, hash-verified

18 * Setup source maps for Sentry inside the Nuxt module during build time (in Vite for Nuxt and Rollup for Nitro).
19 */
20export function setupSourceMaps(
21 moduleOptions: SentryNuxtModuleOptions,
22 nuxt: Nuxt,
23 addVitePlugin: (plugin: Plugin[], options?: { dev?: boolean; build?: boolean }) => void,
24): void {
25 // TODO(v11): remove deprecated options (also from SentryNuxtModuleOptions type)
26
27 const isDebug = moduleOptions.debug;
28
29 // eslint-disable-next-line typescript/no-deprecated
30 const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {};
31
32 const sourceMapsEnabled =
33 moduleOptions.sourcemaps?.disable === true
34 ? false
35 : moduleOptions.sourcemaps?.disable === false
36 ? true
37 : // eslint-disable-next-line typescript/no-deprecated
38 (sourceMapsUploadOptions.enabled ?? true);
39
40 // In case we overwrite the source map settings, we default to deleting the files
41 const shouldDeleteFilesFallback = { client: true, server: true };
42
43 nuxt.hook('modules:done', () => {
44 if (sourceMapsEnabled && !nuxt.options.dev && !nuxt.options?._prepare) {
45 // Changing this setting will propagate:
46 // - for client to viteConfig.build.sourceMap
47 // - for server to viteConfig.build.sourceMap and nitro.sourceMap
48 // On server, nitro.rollupConfig.output.sourcemap remains unaffected from this change.
49
50 // ONLY THIS nuxt.sourcemap.(server/client) setting is the one Sentry will overwrite with 'hidden', if needed.
51 const previousSourceMapSettings = changeNuxtSourceMapSettings(nuxt, moduleOptions);
52
53 // Mutate in place so the Vite plugin (which captured this object at registration time) sees the updated values
54 shouldDeleteFilesFallback.client = previousSourceMapSettings.client === 'unset';
55 shouldDeleteFilesFallback.server = previousSourceMapSettings.server === 'unset';
56
57 if (isDebug && (shouldDeleteFilesFallback.client || shouldDeleteFilesFallback.server)) {
58 const enabledDeleteFallbacks =
59 shouldDeleteFilesFallback.client && shouldDeleteFilesFallback.server
60 ? 'client-side and server-side'
61 : shouldDeleteFilesFallback.server
62 ? 'server-side'
63 : 'client-side';
64
65 if (
66 !moduleOptions.sourcemaps?.filesToDeleteAfterUpload &&
67 // eslint-disable-next-line typescript/no-deprecated
68 !sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload
69 ) {
70 // eslint-disable-next-line no-console
71 console.log(
72 `[Sentry] We enabled \`'hidden'\` source maps for your ${enabledDeleteFallbacks} build. Source map files will be automatically deleted after uploading them to Sentry.`,
73 );
74 } else {
75 // eslint-disable-next-line no-console
76 console.log(
77 `[Sentry] We enabled \`'hidden'\` source maps for your ${enabledDeleteFallbacks} build. Source map files will be deleted according to your \`sourcemaps.filesToDeleteAfterUpload\` configuration. To use automatic deletion instead, leave \`filesToDeleteAfterUpload\` empty.`,

Callers 2

setupFunction · 0.90

Calls 8

sentryVitePluginFunction · 0.85
sentryRollupPluginFunction · 0.85
pushMethod · 0.80
getPluginOptionsFunction · 0.70
logMethod · 0.65

Tested by

no test coverage detected