UNPKG

1.37 kBJavaScriptView Raw
1'use strict';
2
3const _ = require('lodash');
4const bestGuessHomepage = require('./best-guess-homepage');
5const semver = require('semver');
6const packageJson = require('package-json');
7const cpuCount = require('os').cpus().length;
8const throat = require('throat')(cpuCount);
9
10function getNpmInfo(packageName) {
11 return throat(() => packageJson(packageName, { fullMetadata: true, allVersions: true }))
12 .then(rawData => {
13 const CRAZY_HIGH_SEMVER = '8000.0.0';
14
15 const sortedVersions = _(rawData.versions)
16 .keys()
17 .remove(_.partial(semver.gt, CRAZY_HIGH_SEMVER))
18 .sort(semver.compare)
19 .valueOf();
20
21 const latest = rawData['dist-tags'].latest;
22 const next = rawData['dist-tags'].next;
23 const latestStableRelease = semver.satisfies(latest, '*') ?
24 latest :
25 semver.maxSatisfying(sortedVersions, '*');
26 return {
27 latest: latestStableRelease,
28 next: next,
29 versions: sortedVersions,
30 homepage: bestGuessHomepage(rawData)
31 };
32 }).catch(err => {
33 const errorMessage = `Registry error ${err.message}`;
34 return {
35 error: errorMessage
36 };
37 });
38}
39
40module.exports = getNpmInfo;