Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, function (err, data) {
if (err) throw err
// check missing dependencies
var result = depCheck.missing(data.package, data.used)
if (result.length) {
console.error(['Dependencies not listed in package.json:'].concat(result).join('\n\t') + '\n')
}
process.exit(result.length)
})
})
}, function (error, data) {
if (error) {
console.error(error.stack || error);
return process.exit(1);
}
var pkg = data.package;
var dependencies = data.used;
var unusedDependencies = checkDependencies.extra(pkg, dependencies, {excludeDev: true});
var missingDependencies = checkDependencies.missing(pkg, dependencies);
if (unusedDependencies.length === 0 && missingDependencies.length === 0) {
printMessage([
"Checking dependencies successfully done",
"---",
"Unused dependencies - " + "Not Found",
"Missing dependencies - " + "Not Found"
], {
borderColor: 'green',
marginTop: 0,
marginBottom: 0
});
process.exit(0);
}
}, function (error, data) {
if (error) {
console.error(error.stack || error);
return process.exit(1);
}
var pkg = data.package;
var dependencies = data.used;
var unusedDependencies = checkDependencies.extra(pkg, dependencies, {excludeDev: true});
var missingDependencies = checkDependencies.missing(pkg, dependencies);
if (unusedDependencies.length === 0 && missingDependencies.length === 0) {
printMessage([
"Checking dependencies successfully done",
"---",
"Unused dependencies - " + "Not Found",
"Missing dependencies - " + "Not Found"
], {
borderColor: 'green',
marginTop: 0,
marginBottom: 0
});
process.exit(0);
}
function missing (err, installed) {
if (err) {
log.error(err)
return cb(err)
}
var pending = 2
install(dependencyCheck.missing(installed.package, installed.used), done)
uninstall(dependencyCheck.extra(installed.package, installed.used, { excludeDev: true }), done)
function done (err) {
if (err) {
return cb(err)
} else {
pending--
if (!pending) cb(err)
}
}
}
return grunt.fail.fatal(err);
}
var pkg = data.package;
var deps = data.used;
var results;
if (options.unused) {
results = check.extra(pkg, deps, { excludeDev: options.excludeMissingDev });
if (results.length !== 0) {
grunt.log.error('Modules in package.json not used in code: ' + grunt.log.wordlist(results, { color: 'red' }));
}
}
if (options.missing) {
results = check.missing(pkg, deps);
if (results.length !== 0) {
grunt.fail.fatal('Dependencies not listed in package.json: ' + grunt.log.wordlist(results, { color: 'red' }));
}
}
done();
});
});
function missing (err, installed) {
if (err) {
log.error(err)
return cb(err)
}
var pending = 2
install(dependencyCheck.missing(installed.package, installed.used), done)
uninstall(dependencyCheck.extra(installed.package, installed.used, { excludeDev: true }), done)
function done (err) {
if (err) {
return cb(err)
} else {
pending--
if (!pending) cb(err)
}
}
}
check({ path: options.package, entries: this.filesSrc }, function(err, data) {
if (err) {
return grunt.fail.fatal(err);
}
var pkg = data.package;
var deps = data.used;
var results;
if (options.unused) {
results = check.extra(pkg, deps, { excludeDev: options.excludeMissingDev });
if (results.length !== 0) {
grunt.log.error('Modules in package.json not used in code: ' + grunt.log.wordlist(results, { color: 'red' }));
}
}
if (options.missing) {
results = check.missing(pkg, deps);
if (results.length !== 0) {
grunt.fail.fatal('Dependencies not listed in package.json: ' + grunt.log.wordlist(results, { color: 'red' }));
}
}
done();
});
});