Remove the leading slash in windows file path when instrumenting js files for ccov

This commit is contained in:
calixteman 2026-02-21 22:48:36 +01:00 committed by Calixte Denizet
parent 62054ae0a2
commit a8b1c8bd70
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F

View File

@ -306,7 +306,15 @@ class WebServer {
// Transform with Babel and istanbul plugin
const result = babel.transformSync(content, {
filename: fileURL.pathname,
// On Windows, the file URL starts with a slash (e.g.
// /C:/path/to/file.js).
// This leading slash makes the file path invalid and causes the
// instrumentation to fail, so we need to remove it before passing the
// path.
filename:
process.platform === "win32"
? fileURL.pathname.substring(1)
: fileURL.pathname,
plugins: ["babel-plugin-istanbul"],
sourceMaps: false,
});