Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
fix: swap back windows path in sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Oct 5, 2022
1 parent 94595f1 commit a756b7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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;
},
Expand Down
7 changes: 7 additions & 0 deletions tests/specs/source-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit a756b7b

Please sign in to comment.