Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function saveTopDependents (name, metric, n) {
la(check.unemptyString(name), 'invalid package name', name)
la(check.unemptyString(metric), 'invalid metric', metric)
la(check.positiveNumber(n), 'invalid top number', n)
var fetchTop = _.partial(npm.downloads, metric)
return npm.topDependents(name, n)
.then(fetchTop)
.then(npm.sortedByDownloads)
.then(function (dependents) {
la(check.array(dependents), 'cannot select top n, not a list', dependents)
console.log('limiting top downloads to first', n, 'from the list of', dependents.length)
return _.take(dependents, n)
})
.then(function saveToFile (topDependents) {
la(check.arrayOfStrings(topDependents), 'expected list of top strings', topDependents)
// TODO use template library instead of manual concat
var str = '// top ' + n + ' most dependent modules by ' + metric + ' for ' + name + '\n'
str += '// data from NPM registry on ' + (new Date()).toDateString() + '\n'
str += JSON.stringify(topDependents, null, 2) + '\n'
currentModuleInstallMethod = expandCommandVars(currentModuleInstallMethod)
return runInFolder(dependentFolder, `${currentModuleInstallMethod}`, {
success: `installed ${pkgName}`,
failure: `installing ${pkgName} failed`
})
}
}
var depName = pkg.name + '-v' + pkg.version + '-against-' + moduleName
var safeName = _.kebabCase(_.deburr(depName))
debug('original name "%s", safe "%s"', depName, safeName)
var toFolder = join(osTmpdir(), safeName)
console.log('testing folder %s', quote(toFolder))
var timeoutSeconds = options.timeout || INSTALL_TIMEOUT_SECONDS
la(check.positiveNumber(timeoutSeconds), 'wrong timeout', timeoutSeconds, options)
var installOptions = {
name: moduleName,
prefix: toFolder,
cmd: expandCommandVars(dependentInstall)
}
var postInstallModuleInFolder = _.partialRight(postInstallInFolder, modulePostinstallCommand)
var res = install(installOptions)
.timeout(timeoutSeconds * 1000, 'install timed out for ' + moduleName)
.then(formFullFolderName)
.then(function checkInstalledFolder (folder) {
la(check.unemptyString(folder), 'expected folder', folder)
la(exists(folder), 'expected folder to exist', folder)
return folder
function getReposPage(ghuser, k, allRepos) {
la(check.positiveNumber(k), 'invalid repos page index', k);
allRepos = allRepos || [];
la(check.array(allRepos), 'expected all repos to be an array', allRepos);
var defer = q.defer();
console.log('fetching repos page', k);
var perPage = 100;
ghuser.repos(k, perPage, function (err, repos) {
if (err) {
console.error(err);
defer.resolve(allRepos);
return;
}
if (!check.array(repos) || repos.length === 0) {
function getTopDependents(name, n) {
la(check.unemptyString(name), 'missing package name');
la(check.positiveNumber(n), 'invalid top dependents to check', n);
console.log('fetching top', n, 'dependent projects for', name);
return Q.ninvoke(npm.packages, 'depended', name).then(function (dependents) {
la(check.array(dependents),
'expected modules dependent on', name, 'to be array', dependents);
console.log('module', name, 'has', dependents.length, 'dependents');
var names = _.pluck(dependents, 'name');
return names;
});
}