Skip to content

Commit c580cd2

Browse files
committed
fix(astro): Configure sourcemap assets directory for Vercel adapter
1 parent 97e04a0 commit c580cd2

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)