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

Improve cwd option #803

Merged
merged 1 commit into from
Feb 8, 2024
Merged

Improve cwd option #803

merged 1 commit into from
Feb 8, 2024

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Feb 8, 2024

Fixes #798.
Fixes #799.


let cwdStat;
try {
cwdStat = statSync(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.

This function is used both by execa() and execaSync().
In principle, we could use two separate methods, one async and one sync. This would require having two versions of makeError(), one async and one sync.
However, this function happens only when both:

  • the child process failed
  • the cwd option was set with a different value than process.cwd()

So I thought it might be ok to keep it simple for the time being.

Copy link
Owner

Choose a reason for hiding this comment

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

So I thought it might be ok to keep it simple for the time being.

👍


export const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;

export const fixCwdError = (originalMessage, 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.

We cannot perform this cwd validation check before process spawning because it involves making a stat I/O call. Right now, execa() spawns processes right away, and introducing a sync I/O call before spawning for every execa() call is not worth it, just to improve the cwd validation error message.

That being said, since process.cwd() is synchronous, when the cwd option default value is used, it is validated before process spawning.

@sindresorhus
Copy link
Owner

Conflict

@ehmicky
Copy link
Collaborator Author

ehmicky commented Feb 8, 2024

Fixed. 👍

@sindresorhus sindresorhus merged commit 2fd9351 into main Feb 8, 2024
14 checks passed
@sindresorhus sindresorhus deleted the improve-cwd branch February 8, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error message when cwd is invalid error.cwd is set but not result.cwd
2 participants