Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/bundler-plugins/src/core/debug-id-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ export function defaultRewriteSourcesHook(source: string): string {
if (source.match(PROTOCOL_REGEX)) {
return source.replace(PROTOCOL_REGEX, '');
} else {
return path.relative(process.cwd(), path.normalize(source));
// Source map `sources` are URLs, so Windows separators must not leak into the uploaded map.
return path.relative(process.cwd(), path.normalize(source)).split(path.sep).join('/');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type * as Path from 'path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

vi.mock('path', async () => {
const actual = await vi.importActual<typeof Path>('path');
return { ...actual.win32, default: actual.win32 };
});

import { defaultRewriteSourcesHook } from '../../src/core/debug-id-upload';

describe('defaultRewriteSourcesHook on Windows', () => {
beforeEach(() => {
vi.spyOn(process, 'cwd').mockReturnValue('C:\\project\\dist\\assets');
});

afterEach(() => {
vi.restoreAllMocks();
});

it('returns forward-slash sources for relative inputs', () => {
expect(defaultRewriteSourcesHook('../../node_modules/nanoid/index.browser.js')).toBe(
'../../node_modules/nanoid/index.browser.js',
);
expect(defaultRewriteSourcesHook('../../src/main.js')).toBe('../../src/main.js');
});

it('returns forward-slash sources for absolute inputs', () => {
expect(defaultRewriteSourcesHook('C:\\project\\src\\main.js')).toBe('../../src/main.js');
});

it('strips the protocol from URL sources', () => {
expect(defaultRewriteSourcesHook('webpack://my-app/src/main.js')).toBe('my-app/src/main.js');
});
});
Loading