-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Bug: resolveBin
function doesn't work correctly on Windows
#2064
Comments
You are just hitting all the Windows bugs 🙂 Related: JoshuaKGoldberg/bingo#300 |
…mpatibility (#2069) <!-- 👋 Hi, thanks for sending a PR to create-typescript-app! 🎁 Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #2064 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview <!-- Description of what is changed and how the code change does that. --> ### 🧐 The Problem On Windows, file paths typically begin with a drive letter (e.g., `C:`). However, to conform to the `file://` URI scheme in Node.js, they must be prefixed with a slash (e.g., `/C:`), resulting in a correct file URL like `file:///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 be `C:/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](https://nodejs.org/api/url.html#urlfileurltopathurl-options) from the `node: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 💖
@all-contributors please add @astrochemx for bug.
|
🎉 This is included in version v2.18.6 🎉 The release is available on: Cheers! 📦🚀 |
Bug Report Checklist
main
branch of the repository.Expected
To create a new app without any errors.
Actual
On Windows, an error occurs in the
resolveBin
function due to incorrect path handling, which results in a duplicate drive letter, such asC:\C:\GHub\create-typescript-app\node_modules\.pnpm\[email protected]\node_modules\cspell-populate-words\bin\index.mjs
.Example of an error:
Additional Info
🧐 Cause of the Issue
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. In this case, it results in an erroneous path with duplicated drive letters (like
C:/C:/GHub/file.js
), as seen in the error output.💡 Proposed Solution
To resolve this issue, we should use the
fileURLToPath
function from thenode:url
module instead of manually handling paths via regular expressions.🖥️ Proposed Code
Original code:
Updated code:
This approach ensures that paths are correctly converted and eliminates the risk of incorrect path handling on Windows.
✔️ Testing
I have tested such change on Windows and WSL (Ubuntu 24.04.2 LTS), and it works as expected.
💖
The text was updated successfully, but these errors were encountered: