feat(cli): warning on relative paths provided by --cwd param#7372
Open
mollyIV wants to merge 2 commits intoyarnpkg:masterfrom
Open
feat(cli): warning on relative paths provided by --cwd param#7372mollyIV wants to merge 2 commits intoyarnpkg:masterfrom
mollyIV wants to merge 2 commits intoyarnpkg:masterfrom
Conversation
mollyIV
commented
Jul 4, 2019
| yarnOutdatedCommand: 'To upgrade, run the following command:', | ||
|
|
||
| yarnAddRelativePathDetected: | ||
| 'Detected a relative path. --cwd only supports an absolute path. A current working directory will be used instead.', |
Author
There was a problem hiding this comment.
Opened to better message suggestions 🙌
|
mollyIV
commented
Jul 6, 2019
|
|
||
| if (opts.cwd !== undefined) { | ||
| if (!path.isAbsolute(String(opts.cwd))) { | ||
| this.reporter.warn(this.reporter.lang('yarnAddRelativePathDetected')); |
Author
There was a problem hiding this comment.
Maybe the add command should display this warning only in a verbose mode? 🤔
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When a user executes
yarn add --cwd relative-path-to-the-dir dependency-namecommand and passes a relative path to the directory, the path is resolved and a current working directory is used instead.yarn/src/config.js
Line 458 in 49332fa
A user might be surprised by described behaviour, so adding a warning can be really helpful. You can find more details about it in this issue.
Test plan
I did perform manual testing for a relative path:
The new warning is added ☝️🎊
Also tested the potential regression, if we passed an absolute path to the command:
Worked as expected 👍
I wish I could add unit tests to check the warning. Any suggestion on that would be appreciated 🙏 Was thinking about adding it to
config.jstests - checking the warning whileconfiginitialisation for a relative path.closes #5206