Skip to content

Commit

Permalink
Default latest version in case it is not sent by the npm registry (#6454
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mad-mike authored and arcanis committed Oct 2, 2018
1 parent b07a19b commit c62854c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit c62854c

Please sign in to comment.