Skip to content

Commit ad88f83

Browse files
committed
feat(nuxt): Don't run source maps related code on Nuxt "prepare"
1 parent 80b4705 commit ad88f83

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

packages/nuxt/src/module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ export default defineNuxtModule<ModuleOptions>({
135135
}
136136

137137
nuxt.hooks.hook('nitro:init', nitro => {
138+
if (nuxt.options?._prepare) {
139+
return;
140+
}
141+
138142
if (serverConfigFile) {
139143
addMiddlewareInstrumentation(nitro);
140144
}

packages/nuxt/src/vite/sourceMaps.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
3535
let shouldDeleteFilesFallback = { client: true, server: true };
3636

3737
nuxt.hook('modules:done', () => {
38-
if (sourceMapsEnabled && !nuxt.options.dev) {
38+
if (sourceMapsEnabled && !nuxt.options.dev && !nuxt.options?._prepare) {
3939
// Changing this setting will propagate:
4040
// - for client to viteConfig.build.sourceMap
4141
// - for server to viteConfig.build.sourceMap and nitro.sourceMap
@@ -49,17 +49,29 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
4949
server: previousSourceMapSettings.server === 'unset',
5050
};
5151

52-
if (
53-
isDebug &&
54-
!moduleOptions.sourcemaps?.filesToDeleteAfterUpload &&
55-
// eslint-disable-next-line deprecation/deprecation
56-
!sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload &&
57-
(shouldDeleteFilesFallback.client || shouldDeleteFilesFallback.server)
58-
) {
59-
// eslint-disable-next-line no-console
60-
console.log(
61-
"[Sentry] As Sentry enabled `'hidden'` source maps, source maps will be automatically deleted after uploading them to Sentry.",
62-
);
52+
if (isDebug && (shouldDeleteFilesFallback.client || shouldDeleteFilesFallback.server)) {
53+
const enabledDeleteFallbacks =
54+
shouldDeleteFilesFallback.client && shouldDeleteFilesFallback.server
55+
? 'client-side and server-side'
56+
: shouldDeleteFilesFallback.server
57+
? 'server-side'
58+
: 'client-side';
59+
60+
if (
61+
!moduleOptions.sourcemaps?.filesToDeleteAfterUpload &&
62+
// eslint-disable-next-line deprecation/deprecation
63+
!sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload
64+
) {
65+
// eslint-disable-next-line no-console
66+
console.log(
67+
`[Sentry] We enabled \`'hidden'\` source maps for your ${enabledDeleteFallbacks} build. Source map files will be automatically deleted after uploading them to Sentry.`,
68+
);
69+
} else {
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 deleted according to your \`sourcemaps.filesToDeleteAfterUpload\` configuration. To use automatic deletion instead, leave \`filesToDeleteAfterUpload\` empty.`,
73+
);
74+
}
6375
}
6476
}
6577
});
@@ -99,7 +111,7 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
99111
});
100112

101113
nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => {
102-
if (sourceMapsEnabled && !nitroConfig.dev) {
114+
if (sourceMapsEnabled && !nitroConfig.dev && !nuxt.options?._prepare) {
103115
if (!nitroConfig.rollupConfig) {
104116
nitroConfig.rollupConfig = {};
105117
}

0 commit comments

Comments
 (0)