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