diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index 5f5629697e3e..e844e383aaec 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -100,6 +100,16 @@ function findDefaultSdkInitFile(type: 'server' | 'client'): string | undefined { } function getSourcemapsAssetsGlob(config: AstroConfig): string { + // The vercel adapter puts the output into its .vercel directory + // However, the way this adapter is written, the config.outDir value is update too late for + // us to reliably detect it. Also, server files are first temporarily written to /dist and then + // only copied over to /.vercel. This seems to happen too late though. + // So we glob on both of these directories. + // Another case of "it ain't pretty but it works":( + if (config.adapter && config.adapter.name?.startsWith('@astrojs/vercel')) { + return '{.vercel,dist}/**/*'; + } + // paths are stored as "file://" URLs const outDirPathname = config.outDir && path.resolve(config.outDir.pathname); const rootDirName = path.resolve((config.root && config.root.pathname) || process.cwd()); diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index 51132971321d..fcf606c40e0b 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -83,6 +83,33 @@ describe('sentryAstro integration', () => { }); }); + it('sets the correct assets glob for vercel if the Vercel adapter is used', async () => { + const integration = sentryAstro({ + sourceMapsUploadOptions: { enabled: true, org: 'my-org', project: 'my-project', telemetry: false }, + }); + // @ts-expect-error - the hook exists and we only need to pass what we actually use + await integration.hooks['astro:config:setup']({ + updateConfig, + injectScript, + config: { + // @ts-expect-error - we only need to pass what we actually use + adapter: { name: '@astrojs/vercel/serverless' }, + }, + }); + + expect(sentryVitePluginSpy).toHaveBeenCalledTimes(1); + expect(sentryVitePluginSpy).toHaveBeenCalledWith({ + authToken: 'my-token', + org: 'my-org', + project: 'my-project', + telemetry: false, + debug: false, + sourcemaps: { + assets: ['{.vercel,dist}/**/*'], + }, + }); + }); + it("doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`", async () => { const integration = sentryAstro({ sourceMapsUploadOptions: { enabled: false },