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

fix(cli): fail when yarn adding Github package with no version (#5292) #5318

Merged
merged 2 commits into from
Feb 6, 2018
Merged

fix(cli): fail when yarn adding Github package with no version (#5292) #5318

merged 2 commits into from
Feb 6, 2018

Conversation

mhchen
Copy link
Contributor

@mhchen mhchen commented Feb 5, 2018

Summary

Running yarn add to install from a Github repo that has a package.json with no version succeeds, but then all further yarn operations fail due to failing checks for versions in dependencies. As well, per npm, the install method should not succeed at all. This PR causes yarn add to fail if version is not properly formatted as a semver.

Fixes #5292

Test plan

Running:

$ yarn add github:Studio-42/elFinder

Produces the following output:

yarn add v1.4.1
warning ../../package.json: No license field
[1/5] Validating package.json...
[2/5] Resolving packages...
error Can't add "elFinder": invalid package version undefined.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

@mhchen
Copy link
Contributor Author

mhchen commented Feb 5, 2018

@bestander please review at your convenience. It looks like most of the testing for these helper libraries is done through issuing actual cli commands, so hopefully this test coverage is sufficient. Thanks for all your help!

@@ -473,7 +473,7 @@ export default class Git implements GitRefResolvingInterface {
});
if (!resolvedResult) {
throw new MessageError(
this.reporter.lang('couldntFindMatch', version, Object.keys(refs).join(','), this.gitUrl.repository),
this.reporter.lang('couldntFindMatch', version, Array.from(refs.keys()).join(','), this.gitUrl.repository),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

refs is a Map which always returns an empty array with Object.keys()

} catch (err) {
message = err.message;
}
expect(message).toEqual(expect.stringContaining('invalid package version'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be preferable to use .rejects and assert on the error message using toThrow or the like, but it looks like this is still problematic: jestjs/jest#3601

@JoshuaCWebDeveloper
Copy link

Thank you @mhchen !

@bestander bestander merged commit 1b4b318 into yarnpkg:master Feb 6, 2018
@bestander
Copy link
Member

@mhchen great work! Thank you for following it through and doing tests.

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.

3 participants