Skip to content

Commit

Permalink
fix: fix ESM path with benchmark.js
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Jun 23, 2023
1 parent 2574459 commit 91ce259
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/benchmark.js-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Benchmark from "benchmark";
import { findUpSync, Options as FindupOptions } from "find-up";
import path, { dirname } from "path";
import { get as getStackTrace } from "stack-trace";
import { fileURLToPath } from "url";

declare const __VERSION__: string;

Expand Down Expand Up @@ -201,11 +202,14 @@ async function runBenchmarks({

function getCallingFile(): string {
const stack = getStackTrace();
const callingFile = stack[3].getFileName(); // [here, withCodSpeed, withCodSpeedX, actual caller]
let callingFile = stack[3].getFileName(); // [here, withCodSpeed, withCodSpeedX, actual caller]
const gitDir = getGitDir(callingFile);
if (gitDir === undefined) {
throw new Error("Could not find a git repository");
}
if (callingFile.startsWith("file://")) {
callingFile = fileURLToPath(callingFile);
}
return path.relative(gitDir, callingFile);
}

Expand Down

0 comments on commit 91ce259

Please sign in to comment.