Skip to content

Commit 9916e02

Browse files
committed
fix: fix ESM path with benchmark.js
1 parent 3fd6a83 commit 9916e02

File tree

1 file changed

+5
-1
lines changed
  • packages/benchmark.js-plugin/src

1 file changed

+5
-1
lines changed

packages/benchmark.js-plugin/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Benchmark from "benchmark";
88
import { findUpSync, Options as FindupOptions } from "find-up";
99
import path, { dirname } from "path";
1010
import { get as getStackTrace } from "stack-trace";
11+
import { fileURLToPath } from "url";
1112

1213
declare const __VERSION__: string;
1314

@@ -201,11 +202,14 @@ async function runBenchmarks({
201202

202203
function getCallingFile(): string {
203204
const stack = getStackTrace();
204-
const callingFile = stack[3].getFileName(); // [here, withCodSpeed, withCodSpeedX, actual caller]
205+
let callingFile = stack[3].getFileName(); // [here, withCodSpeed, withCodSpeedX, actual caller]
205206
const gitDir = getGitDir(callingFile);
206207
if (gitDir === undefined) {
207208
throw new Error("Could not find a git repository");
208209
}
210+
if (callingFile.startsWith("file://")) {
211+
callingFile = fileURLToPath(callingFile);
212+
}
209213
return path.relative(gitDir, callingFile);
210214
}
211215

0 commit comments

Comments
 (0)