From a756b7b599cb92ac720c559bee8451f63b1643a1 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 5 Oct 2022 19:19:23 +0900 Subject: [PATCH] fix: swap back windows path in sourcemap --- src/transform/index.ts | 10 ++++++++-- tests/specs/source-maps.ts | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/transform/index.ts b/src/transform/index.ts index ca6392f..4fd2b52 100644 --- a/src/transform/index.ts +++ b/src/transform/index.ts @@ -51,7 +51,10 @@ export function transformSync( // eslint-disable-next-line @typescript-eslint/no-shadow const transformed = esbuildTransformSync(code, esbuildOptions); if (esbuildOptions.sourcefile !== filePath) { - transformed.map = transformed.map.replace(`"${esbuildOptions.sourcefile}"`, `"${filePath}"`); + transformed.map = transformed.map.replace( + JSON.stringify(esbuildOptions.sourcefile), + JSON.stringify(filePath), + ); } return transformed; }, @@ -97,7 +100,10 @@ export async function transform( // eslint-disable-next-line @typescript-eslint/no-shadow const transformed = await esbuildTransform(code, esbuildOptions); if (esbuildOptions.sourcefile !== filePath) { - transformed.map = transformed.map.replace(`"${esbuildOptions.sourcefile}"`, `"${filePath}"`); + transformed.map = transformed.map.replace( + JSON.stringify(esbuildOptions.sourcefile), + JSON.stringify(filePath), + ); } return transformed; }, diff --git a/tests/specs/source-maps.ts b/tests/specs/source-maps.ts index 3e0b985..5757e77 100644 --- a/tests/specs/source-maps.ts +++ b/tests/specs/source-maps.ts @@ -37,5 +37,12 @@ export default testSuite(({ describe }) => { const errorPosition = expected.stderr.toString().match(new RegExp(`${rawFile}(:\\d+:\\d+)`)); expect(stderrReceived).toMatch(transformedFile + errorPosition![1]); }); + + test('path is same for windows', async () => { + const filePath = 'D:\\windows\\path\\index.mts'; + const transformed = transformSync('1', filePath); + + expect(transformed.map.sources[0]).toBe(filePath); + }); }); });