Skip to content
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

Allow cwd and localDir options to be URLs #492

Merged
merged 6 commits into from Feb 12, 2022
Merged

Allow cwd and localDir options to be URLs #492

merged 6 commits into from Feb 12, 2022

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Feb 10, 2022

Fixes #491

This allows the cwd and localDir options to be URLs with the file: scheme.

This is not available in Node.js 12. We could potentially use fileURLToPath() to convert it in Node.js 12. However, Node.js 12 support is ending in a little more than 2 months. Also, it would require detecting the Node.js version, which might add semver as a production dependency. Overall, it does not seem to be worth it, but please let me know if you think otherwise.

@ehmicky ehmicky marked this pull request as draft February 10, 2022 21:07
@ehmicky ehmicky marked this pull request as ready for review February 10, 2022 21:22
test('can use `options.cwd` as a string', async t => {
const cwd = '/';
const {stdout} = await execa('node', ['-p', 'process.cwd()'], {cwd});
t.is(path.toNamespacedPath(stdout), path.toNamespacedPath(cwd));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.cwd() returns the drive letter on Windows, but path.normalize() does not, so we have to use path.toNamespacedPath().

Default: `process.cwd()`

Preferred path to find locally installed binaries in (use with `preferLocal`).

Using a `URL` is only supported in Node.js `14.18.0`, `16.14.0` or above.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing from the TS docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! 👍

@sindresorhus sindresorhus merged commit 93ab929 into main Feb 12, 2022
@sindresorhus sindresorhus deleted the feat/cwd-url branch February 12, 2022 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cwd as a file: URL does not work
2 participants