8000 fix(sveltekit): Detect sentry release before creating the Vite plugin… · jchatard/sentry-javascript@3040a6b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3040a6b

Browse files
authored
fix(sveltekit): Detect sentry release before creating the Vite plugins (getsentry#7902)
1 parent 2e64ef7 commit 3040a6b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/sveltekit/src/vite/sourceMaps.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { getSentryRelease } from '@sentry/node';
2+
import { uuid4 } from '@sentry/utils';
13
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
24
import { sentryVitePlugin } from '@sentry/vite-plugin';
5+
import * as child_process from 'child_process';
36
import * as fs from 'fs';
47
import * as path from 'path';
58
// @ts-ignore -sorcery has no types :(
@@ -22,6 +25,10 @@ type SentryVitePluginOptionsOptionalInclude = Omit<SentryVitePluginOptions, 'inc
2225
include?: SentryVitePluginOptions['include'];
2326
};
2427

28+
// storing this in the module scope because `makeCustomSentryVitePlugin` is called multiple times
29+
// and we only want to generate a uuid once in case we have to fall back to it.
30+
const release = detectSentryRelease();
31+
2532< 8000 /code>
/**
2633
* Creates a new Vite plugin that uses the unplugin-based Sentry Vite plugin to create
2734
* releases and upload source maps to Sentry.
@@ -51,6 +58,7 @@ export async function makeCustomSentryVitePlugin(options?: SentryVitePluginOptio
5158
{ paths: [`${outputDir}/server`], ignore: ['chunks/**'] },
5259
],
5360
configFile: hasSentryProperties ? 'sentry.properties' : undefined,
61+
release,
5462
};
5563

5664
const mergedOptions = {
@@ -174,3 +182,19 @@ function getFiles(dir: string): string[] {
174182

175183
return Array.prototype.concat(...files);
176184
}
185+
186+
function detectSentryRelease(): string {
187+
let releaseFallback: string;
188+
try {
189+
releaseFallback = child_process.execSync('git rev-parse HEAD', { stdio: 'ignore' }).toString().trim();
190+
} catch (_) {
191+
// the command can throw for various reasons. Most importantly:
192+
// - git is not installed
193+
// - there is no git repo or no commit yet
194+
// regardless of the case we just fall back to assigning a random uuid.
195+
releaseFallback = uuid4();
196+
}
197+
const release = getSentryRelease() || releaseFallback;
198+
199+
return release;
200+
}

0 commit comments

Comments
 (0)
0