Skip to content

Commit 52c164e

Browse files
committed
feat(nuxt): Don't run source maps related code on Nuxt "prepare"
1 parent b2b92a2 commit 52c164e

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
@@ -136,6 +136,10 @@ export default defineNuxtModule<ModuleOptions>({
136136
}
137137

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

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
});
@@ -107,7 +119,7 @@ export function setupSourceMaps(moduleOptions: SentryNuxtModuleOptions, nuxt: Nu
107119
});
108120

109121
nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => {
110-
if (sourceMapsEnabled && !nitroConfig.dev) {
122+
if (sourceMapsEnabled && !nitroConfig.dev && !nuxt.options?._prepare) {
111123
if (!nitroConfig.rollupConfig) {
112124
nitroConfig.rollupConfig = {};
113125
}

0 commit comments

Comments
 (0)