Skip to content

Commit 008ebec

Browse files
committed
fix(sveltekit): Keep source maps of the hooks files under a base path
1 parent 07a7527 commit 008ebec

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎packages/sveltekit/src/vite/tunnelBasePath.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { escapeStringForRegex } from '@sentry/core';
2+
import MagicString from 'magic-string';
23
import type { Plugin } from 'vite';
34
import { TUNNEL_BASE_PATH_GLOBAL } from '../common/tunnel';
45
import type { ResolvedKitConfig } from './kitConfig';
@@ -40,7 +41,10 @@ export function makeTunnelBasePathPlugin(getKitConfig: () => Promise<ResolvedKit
4041
return null;
4142
}
4243

43-
return { code: `import ${JSON.stringify(VIRTUAL_BASE_PATH_FILE)};\n${code}`, map: null };
44+
const ms = new MagicString(code);
45+
ms.prepend(`import ${JSON.stringify(VIRTUAL_BASE_PATH_FILE)};\n`);
46+
47+
return { code: ms.toString(), map: ms.generateMap({ hires: true }) };
4448
},
4549
};
4650
}

‎packages/sveltekit/test/vite/tunnelBasePath.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('makeTunnelBasePathPlugin', () => {
2020
for (const id of ['/p/src/hooks.server.ts', '/p/src/hooks.client.js', '/p/src/instrumentation.server.ts']) {
2121
expect(transform('const a = 1;', id)).toEqual({
2222
code: `import ${JSON.stringify('\0sentry-sveltekit-tunnel-base-path')};\nconst a = 1;`,
23-
map: null,
23+
map: expect.objectContaining({ mappings: expect.any(String) }),
2424
});
2525
}
2626
expect(transform('const a = 1;', '/p/src/routes/+page.svelte')).toBeNull();

0 commit comments

Comments
 (0)