From 282522eafc86bceebdcd742b040a66a4c1b17174 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:27:03 +0000 Subject: [PATCH 1/3] chore: drop require in benchmark In latest node, tsx/node seem to load this benchmark file as ESM which results in an error when trying to use `require.resolve`. We can achieve the same with regular path resolution, using `import.meta` to get hold of the current path. --- benchmark/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/benchmark/index.ts b/benchmark/index.ts index 6e23c845..7f142222 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -1,12 +1,15 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair -- ignore /* eslint-disable no-console -- ignore */ -import * as Benchmark from "benchmark"; +import Benchmark from "benchmark"; import fs from "fs"; import { parseForESLint } from "../src/index.js"; import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser/lib/index.js"; +import { fileURLToPath } from "node:url"; +import path from "node:path"; +const dirname = fileURLToPath(new URL(".", import.meta.url)); const contents = `${fs.readFileSync( - require.resolve("../explorer-v2/src/lib/RulesSettings.svelte"), + path.resolve(dirname, "../explorer-v2/src/lib/RulesSettings.svelte"), "utf-8", )}// comments`; From ce1795da0740e94ab7b79d7ee87a68a3c53146b2 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:59:27 +0000 Subject: [PATCH 2/3] chore: use `import.meta.resolve` --- benchmark/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmark/index.ts b/benchmark/index.ts index 7f142222..dbb7d8c0 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -5,11 +5,11 @@ import fs from "fs"; import { parseForESLint } from "../src/index.js"; import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser/lib/index.js"; import { fileURLToPath } from "node:url"; -import path from "node:path"; -const dirname = fileURLToPath(new URL(".", import.meta.url)); const contents = `${fs.readFileSync( - path.resolve(dirname, "../explorer-v2/src/lib/RulesSettings.svelte"), + fileURLToPath( + import.meta.resolve("../explorer-v2/src/lib/RulesSettings.svelte"), + ), "utf-8", )}// comments`; From 3b092d001a31a5b976e16a98aa543bbf1bc3a502 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sat, 29 Mar 2025 16:53:48 +0000 Subject: [PATCH 3/3] chore: sort imports --- benchmark/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmark/index.ts b/benchmark/index.ts index dbb7d8c0..38ff0001 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -1,10 +1,10 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair -- ignore /* eslint-disable no-console -- ignore */ import Benchmark from "benchmark"; -import fs from "fs"; -import { parseForESLint } from "../src/index.js"; -import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser/lib/index.js"; +import fs from "node:fs"; import { fileURLToPath } from "node:url"; +import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser/lib/index.js"; +import { parseForESLint } from "../src/index.js"; const contents = `${fs.readFileSync( fileURLToPath(