Skip to content

Commit

Permalink
Default latest version in case it is not sent by the npm registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Müller committed Sep 30, 2018
1 parent ed2c8a5 commit d279a81
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
28 changes: 28 additions & 0 deletions __tests__/registries/npm-registry.js
Expand Up @@ -866,4 +866,32 @@ describe('checkOutdated functional test', () => {

expect(message).toEqual(expect.stringContaining('No valid versions'));
});

test('latest version fallback to wanted package manifest', async () => {
const testCwd = '.';
const {mockRequestManager, mockRegistries, mockReporter} = createMocks();
const npmRegistry = new NpmRegistry(testCwd, mockRegistries, mockRequestManager, mockReporter, true, []);

mockRequestManager.request = () => {
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',
});
});
});
8 changes: 7 additions & 1 deletion src/registries/npm-registry.js
Expand Up @@ -206,10 +206,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 d279a81

Please sign in to comment.