Skip to content

Commit 85a494a

Browse files
authored
fix(astro): Configure sourcemap assets directory for Vercel adapter (#9665)
This PR adds support for uploading sourcemaps when using the `@astrojs/vercel/*` adapters. It seems that the adapter updates the config.outdir value too late for our previous detection logic to correctly detect the .vercel output directory. Furthermore, the adapter for some reason first saves server files to <root>/dist only to copy it later to <root>/.vercel/functions. This copy command seems to happen too late for when our sourcemaps plugin runs. For these two reasons, we try to detect the used adapter (love that this is much simpler in Astro than Sveltekit) and adjust the assets glob to search for files in both, `dist` and `.vercel`.
1 parent 7249cf9 commit 85a494a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

packages/astro/src/integration/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ function findDefaultSdkInitFile(type: 'server' | 'client'): string | undefined {
100100
}
101101

102102
function getSourcemapsAssetsGlob(config: AstroConfig): string {
103+
// The vercel adapter puts the output into its .vercel directory
104+
// However, the way this adapter is written, the config.outDir value is update too late for
105+
// us to reliably detect it. Also, server files are first temporarily written to <root>/dist and then
106+
// only copied over to <root>/.vercel. This seems to happen too late though.
107+
// So we glob on both of these directories.
108+
// Another case of "it ain't pretty but it works":(
109+
if (config.adapter && config.adapter.name?.startsWith('@astrojs/vercel')) {
110+
return '{.vercel,dist}/**/*';
111+
}
112+
103113
// paths are stored as "file://" URLs
104114
const outDirPathname = config.outDir && path.resolve(config.outDir.pathname);
105115
const rootDirName = path.resolve((config.root && config.root.pathname) || process.cwd());

packages/astro/test/integration/index.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,33 @@ describe('sentryAstro integration', () => {
8383
});
8484
});
8585

86+
it('sets the correct assets glob for vercel if the Vercel adapter is used', async () => {
87+
const integration = sentryAstro({
88+
sourceMapsUploadOptions: { enabled: true, org: 'my-org', project: 'my-project', telemetry: false },
89+
});
90+
// @ts-expect-error - the hook exists and we only need to pass what we actually use
91+
await integration.hooks['astro:config:setup']({
92+
updateConfig,
93+
injectScript,
94+
config: {
95+
// @ts-expect-error - we only need to pass what we actually use
96+
adapter: { name: '@astrojs/vercel/serverless' },
97+
},
98+
});
99+
100+
expect(sentryVitePluginSpy).toHaveBeenCalledTimes(1);
101+
expect(sentryVitePluginSpy).toHaveBeenCalledWith({
102+
authToken: 'my-token',
103+
org: 'my-org',
104+
project: 'my-project',
105+
telemetry: false,
106+
debug: false,
107+
sourcemaps: {
108+
assets: ['{.vercel,dist}/**/*'],
109+
},
110+
});
111+
});
112+
86113
it("doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`", async () => {
87114
const integration = sentryAstro({
88115
sourceMapsUploadOptions: { enabled: false },

0 commit comments

Comments
 (0)