From 91ce25910abdd6de36ec921d2455832489e3280e Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Fri, 23 Jun 2023 19:49:50 +0200 Subject: [PATCH] fix: fix ESM path with benchmark.js --- packages/benchmark.js-plugin/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/benchmark.js-plugin/src/index.ts b/packages/benchmark.js-plugin/src/index.ts index 8d7a8a5..0fdfbed 100644 --- a/packages/benchmark.js-plugin/src/index.ts +++ b/packages/benchmark.js-plugin/src/index.ts @@ -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; @@ -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); }