-
Notifications
You must be signed in to change notification settings - Fork 6
changed method of loading npm packages #4
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,75 @@ | ||
// if your GitHub location field matches this then we'll guess you're Aussie | ||
const GITHUB_REPO_REGEX = /github.com[:\/]([\.\-\w]+)\/([^$\/\.]+)/ | ||
|
||
const npm = require('npm') | ||
, NPM_ALL_PACKAGES_URL = 'https://skimdb.npmjs.com/registry/_all_docs' | ||
, NPM_SINGLE_PACKAGE_URL = 'https://registry.npmjs.org/{packageId}/latest' | ||
, request = require('request').defaults({json:true}) | ||
, async = require('async'); | ||
|
||
function matchGitHubRepo (npmPackage, repo) { | ||
var match = repo | ||
&& typeof repo.url == 'string' | ||
&& repo.url.match(GITHUB_REPO_REGEX) | ||
&& repo.url.match(GITHUB_REPO_REGEX); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no semicolon |
||
|
||
return match && { | ||
githubUser : match[1] | ||
, githubRepo : match[2] | ||
, npmPackage : npmPackage | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no semi |
||
} | ||
|
||
// load the list of all npm libs with 'repo' pointing to GitHub | ||
function loadNpmData (callback) { | ||
var repositories = [] | ||
, allPackages = [] | ||
function getPackageData(repositories, allPackages, packageData, callback){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces both sides of the args parnens |
||
request(NPM_SINGLE_PACKAGE_URL.replace('{packageId}', packageData.id), function (err, response, data) { | ||
if (err) { | ||
// log and continue usually just a timeout, possibly needs retry logic | ||
console.log('error getting data for package: ' + packageData.id, err.message); | ||
return callback(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. semicolons previous 2 lines |
||
} | ||
|
||
// Bad maintainers property there are MANY just skip for much speed increase | ||
if(!data.maintainers || !Array.isArray(data.maintainers)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces, after |
||
return callback(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. semi |
||
} | ||
|
||
var repo = matchGitHubRepo(data.name, data.repository); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. semi |
||
|
||
if (repo){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space beore |
||
repositories.push(repo); | ||
} | ||
|
||
npm.load(function (err) { | ||
if (err) return callback(err) | ||
allPackages.push({ | ||
name : data.name | ||
, maintainers : (data.maintainers || []).map(function (m) { return m && m.name }) | ||
, githubUser : repo ? repo.githubUser : null | ||
, githubRepo : repo ? repo.githubRepo : null | ||
, description : data.description | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. semis on the next few lines |
||
|
||
callback(); | ||
}); | ||
} | ||
|
||
function getAllPackages(callback){ | ||
var repositories = [] | ||
, allPackages = []; | ||
|
||
npm.registry.get('/-/all', function (err, data) { | ||
if (err) return callback(err) | ||
// https://github.com/npm/npm-registry-couchapp/issues/162 | ||
request(NPM_ALL_PACKAGES_URL, function(err, response, body){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
Object.keys(data).forEach(function (k) { | ||
var repo = matchGitHubRepo(data[k].name, data[k].repository) | ||
if (repo) | ||
repositories.push(repo) | ||
if(!body || !body.rows){ | ||
body = { rows: [] }; | ||
} | ||
|
||
allPackages.push({ | ||
name : data[k].name | ||
, maintainers : (data[k].maintainers || []).map(function (m) { return m.name }) | ||
, githubUser : repo ? repo.githubUser : null | ||
, githubRepo : repo ? repo.githubRepo : null | ||
, description : data[k].description | ||
}) | ||
}) | ||
async.mapLimit(body.rows, 10, getPackageData.bind(null, repositories, allPackages), function(err){ | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
callback(null, { repositories: repositories, allPackages: allPackages }) | ||
}) | ||
}) | ||
}); | ||
} | ||
|
||
module.exports = loadNpmData | ||
module.exports = getAllPackages |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,9 @@ | |
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"npm": "~1.2.18", | ||
"async": "~0.2.7", | ||
"request": "~2.20.0", | ||
"function-rate-limit": "0.0.1" | ||
"async": "^1.5.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"function-rate-limit": "0.0.1", | ||
"request": "^2.67.0" | ||
}, | ||
"private": true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct? I don't think this is needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to as is used on line 87