Skip to content

Commit a279131

Browse files
chargomeclaude
andcommitted
fix(bundler-plugins): Use forward slashes in rewritten source map sources
The default rewriteSources hook built sources with path.relative, which returns backslash paths on Windows. Since sentry CLI 0.50.0 skips the injection step that used to convert them back, uploaded maps carried Windows-style sources. Fixes #26788 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 84df128 commit a279131

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎packages/bundler-plugins/src/core/debug-id-upload.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export function defaultRewriteSourcesHook(source: string): string {
404404
if (source.match(PROTOCOL_REGEX)) {
405405
return source.replace(PROTOCOL_REGEX, '');
406406
} else {
407-
return path.relative(process.cwd(), path.normalize(source));
407+
// Source map `sources` are URLs, so Windows separators must not leak into the uploaded map.
408+
return path.relative(process.cwd(), path.normalize(source)).split(path.sep).join('/');
408409
}
409410
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type * as Path from 'path';
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
4+
vi.mock('path', async () => {
5+
const actual = await vi.importActual<typeof Path>('path');
6+
return { ...actual.win32, default: actual.win32 };
7+
});
8+
9+
import { defaultRewriteSourcesHook } from '../../src/core/debug-id-upload';
10+
11+
describe('defaultRewriteSourcesHook on Windows', () => {
12+
beforeEach(() => {
13+
vi.spyOn(process, 'cwd').mockReturnValue('C:\\project\\dist\\assets');
14+
});
15+
16+
afterEach(() => {
17+
vi.restoreAllMocks();
18+
});
19+
20+
it('returns forward-slash sources for relative inputs', () => {
21+
expect(defaultRewriteSourcesHook('../../node_modules/nanoid/index.browser.js')).toBe(
22+
'../../node_modules/nanoid/index.browser.js',
23+
);
24+
expect(defaultRewriteSourcesHook('../../src/main.js')).toBe('../../src/main.js');
25+
});
26+
27+
it('returns forward-slash sources for absolute inputs', () => {
28+
expect(defaultRewriteSourcesHook('C:\\project\\src\\main.js')).toBe('../../src/main.js');
29+
});
30+
31+
it('strips the protocol from URL sources', () => {
32+
expect(defaultRewriteSourcesHook('webpack://my-app/src/main.js')).toBe('my-app/src/main.js');
33+
});
34+
});

0 commit comments

Comments
 (0)