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(info): Use version from latest dist-tag instead of the highest one #4797

Merged
merged 4 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions __tests__/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import Config from '../../src/config.js';
import path from 'path';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
// the mocked requests have stripped metadata, don't use it in the following tests
jest.unmock('request');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'info');

Expand Down Expand Up @@ -48,6 +46,11 @@ const expectedKeys = [
// yarn now ships as built, single JS files so it has no dependencies and no scripts
const unexpectedKeys = ['dependencies', 'devDependencies', 'scripts'];

beforeEach(() => {
// the mocked requests have stripped metadata, don't use it in the following tests
jest.unmock('request');
});

test.concurrent('without arguments and in directory containing a valid package file', (): Promise<void> => {
return runInfo([], {}, 'local', (config, output): ?Promise<void> => {
const actualKeys = Object.keys(output);
Expand Down Expand Up @@ -88,6 +91,20 @@ test.concurrent('with two arguments and second argument "readme" shows readme st
});
});

test.concurrent('with two arguments and second argument "version" shows `latest` version', (): Promise<void> => {
// Scenario:
// If a registry contains versions [1.0.0, 1.0.1, 1.0.2] and latest:1.0.1
// If `yarn info` is run, it should choose `1.0.1` because it is "latest", not `1.0.2` even though it is newer.
// In other words, when no range is explicitely given, Yarn should choose "latest".
//
// In this test, `ui-select` has a max version of `0.20.0` but a `latest:0.19.8`
jest.mock('../__mocks__/request.js');

return runInfo(['ui-select', 'version'], {}, '', (config, output): ?Promise<void> => {
expect(output).toEqual('0.19.8');
});
});

test.concurrent('with two arguments and second argument as a simple field', (): Promise<void> => {
return runInfo(['yarn', 'repository'], {}, '', (config, output): ?Promise<void> => {
expect(output).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
const versions = result.versions;
// $FlowFixMe
result.versions = Object.keys(versions).sort(semver.compareLoose);
result.version = version || result.versions[result.versions.length - 1];
result.version = version || result['dist-tags'].latest;
Copy link
Member

Choose a reason for hiding this comment

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

Are we always guaranteed to have dist-tags and ['dist-tags'].latest?

Copy link
Member

Choose a reason for hiding this comment

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

Who knows, it's entirely up to the npm server implementation :/ For now I think we can make this assumption, and revisit if needed.

result = Object.assign(result, versions[result.version]);

const fieldPath = args.shift();
Expand Down