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

Default latest version in case it is not sent by the npm registry #6454

Merged
merged 2 commits into from Oct 2, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions __tests__/registries/npm-registry.js
Expand Up @@ -867,6 +867,29 @@ describe('checkOutdated functional test', () => {
expect(message).toEqual(expect.stringContaining('No valid versions'));
});

test('latest version fallback to wanted package manifest', async () => {
return {
'dist-tags': {},
versions: {
'2.0.0': {
version: '2.0.0',
repository: {
url: 'http://package.repo.com',
},
},
},
};
};

const result = await npmRegistry.checkOutdated(mockConfig, 'left-pad', '2.0.0');

expect(result).toMatchObject({
latest: '2.0.0',
wanted: '2.0.0',
url: 'http://package.repo.com',
});
});

test('package with an empty response', async () => {
const testCwd = '.';
const {mockRequestManager, mockRegistries, mockReporter} = createMocks();
Expand Down
8 changes: 7 additions & 1 deletion src/registries/npm-registry.js
Expand Up @@ -207,10 +207,16 @@ export default class NpmRegistry extends Registry {
homepage = wantedPkg.homepage;
}

let latest = req['dist-tags'].latest;
// In certain cases, registries do not return a 'latest' tag.
if (!latest) {
latest = wantedPkg.version;
}

const url = homepage || (repository && repository.url) || '';

return {
latest: req['dist-tags'].latest,
latest,
wanted: wantedPkg.version,
url,
};
Expand Down