fix: use fileURLToPath for Windows path resolution (#95)

On Windows, `new URL(import.meta.url).pathname` returns `/C:/...`
(with a leading slash). Passing that to `path.resolve()` or
`path.join()` causes Node to prepend the drive letter again, producing
doubled paths like `C:\C:\Users\...\detect-antipatterns-browser.js`.

Replace both occurrences (puppeteer scan at ~L2690 and live detect at
~L3506) with `fileURLToPath(import.meta.url)` from `node:url`, which
correctly strips the leading slash on Windows while remaining a no-op
on POSIX.

Add regression tests verifying the source no longer uses the raw
`.pathname` accessor for local path construction and that
`fileURLToPath` handles both Windows and POSIX file URLs correctly.

Closes #95
This commit is contained in:
voidborne-d
2026-04-27 14:44:25 -07:00
committed by Paul Bakaus
parent 17fe31baa9
commit 94b315ef63
2 changed files with 76 additions and 2 deletions
+3 -2
View File
@@ -26,10 +26,11 @@ const IS_BROWSER = typeof window !== 'undefined';
const IS_NODE = !IS_BROWSER;
// @browser-strip-start
let fs, path;
let fs, path, fileURLToPath;
if (!IS_BROWSER) {
fs = (await import('node:fs')).default;
path = (await import('node:path')).default;
fileURLToPath = (await import('node:url')).fileURLToPath;
}
// @browser-strip-end
@@ -2697,7 +2698,7 @@ async function detectUrl(url) {
// Read the browser detection script — reuse it instead of reimplementing
const browserScriptPath = path.resolve(
path.dirname(new URL(import.meta.url).pathname),
path.dirname(fileURLToPath(import.meta.url)),
'detect-antipatterns-browser.js'
);
let browserScript;