mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-19 09:36:59 +03:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user