-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat(cli): warning on relative paths provided by --cwd param #7372
Open
mollyIV
wants to merge
2
commits into
yarnpkg:master
Choose a base branch
from
mollyIV:add-command-relative-path-warning
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
mollyIV
commented
Jul 4, 2019
@@ -135,6 +135,9 @@ const messages = { | |||
yarnOutdatedInstaller: 'To upgrade, download the latest installer at $0.', | |||
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.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened to better message suggestions 🙌
|
mollyIV
commented
Jul 6, 2019
@@ -454,6 +454,12 @@ export default class Config { | |||
this.registries = map(); | |||
this.cache = map(); | |||
|
|||
if (opts.cwd !== undefined) { | |||
if (!path.isAbsolute(String(opts.cwd))) { | |||
this.reporter.warn(this.reporter.lang('yarnAddRelativePathDetected')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the add
command should display this warning only in a verbose
mode? 🤔
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-name
command 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.js
tests - checking the warning whileconfig
initialisation for a relative path.closes #5206