fix: update resolveBin
to use fileURLToPath
for cross-platform compatibility
#2069
+3
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
resolveBin
function doesn't work correctly on Windows #2064status: accepting prs
Overview
🧐 The Problem
On Windows, file paths typically begin with a drive letter (e.g.,
C:
). However, to conform to thefile://
URI scheme in Node.js, they must be prefixed with a slash (e.g.,/C:
), resulting in a correct file URL likefile:///C:/GHub/file.js
.Currently, the
resolveBin
function does not properly handle this conversion and mistakenly outputs an absolute path with a leading slash, such as/C:/GHub/file.js
. This format is invalid on Windows, where the correct absolute path should beC:/GHub/file.js
.Mishandling paths that start with a leading slash on Windows can cause them to be interpreted as relative to the current drive, leading to incorrect resolutions. This can result in an erroneous path with duplicated drive letters (like
C:/C:/GHub/file.js
).💡 The Solution
To resolve this issue, we should use the
fileURLToPath
function from thenode:url
module instead of manually handling paths via regular expressions. This approach ensures that paths are correctly converted and eliminates the risk of incorrect path handling on Windows.✔️ Testing
I have tested this change on Windows and WSL (Ubuntu 24.04.2 LTS), and it works as expected.
Additional Info
💖