Skip to content

Commit a2d0d88

Browse files
committed
fix: fix file path when running in ESM
1 parent 67a4f23 commit a2d0d88

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/tinybench-plugin/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { findUpSync, Options } from "find-up";
33
import path, { dirname } from "path";
44
import { get as getStackTrace } from "stack-trace";
55
import { Bench } from "tinybench";
6+
import { fileURLToPath } from "url";
67

78
declare const __VERSION__: string;
89

@@ -37,11 +38,14 @@ export function withCodSpeed(bench: Bench): Bench {
3738

3839
function getCallingFile(): string {
3940
const stack = getStackTrace();
40-
const callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]
41+
let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]
4142
const gitDir = getGitDir(callingFile);
4243
if (gitDir === undefined) {
4344
throw new Error("Could not find a git repository");
4445
}
46+
if (callingFile.startsWith("file://")) {
47+
callingFile = fileURLToPath(callingFile);
48+
}
4549
return path.relative(gitDir, callingFile);
4650
}
4751

0 commit comments

Comments
 (0)