Skip to content

Commit

Permalink
Add paths for missing dependencies
Browse files Browse the repository at this point in the history
Closes #428

Co-authored-by: Bernie @twk-b
  • Loading branch information
rumpl committed Oct 29, 2019
1 parent f7240a1 commit 718fb1b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/cli.js
Expand Up @@ -47,15 +47,20 @@ function prettify(caption, deps) {
return list.length ? [caption].concat(list) : [];
}

function print(result, log, json) {
function mapMissing(missing, rootDir) {
return lodash.map(missing, (foundInFiles, key) =>
`${key}: ${lodash.replace(lodash.first(foundInFiles), rootDir, '.')}`);
}

function print(result, log, json, rootDir) {
if (json) {
log(JSON.stringify(result, (key, value) => (lodash.isError(value) ? value.stack : value)));
} else if (noIssue(result)) {
log('No depcheck issue');
} else {
const deps = prettify('Unused dependencies', result.dependencies);
const devDeps = prettify('Unused devDependencies', result.devDependencies);
const missing = prettify('Missing dependencies', Object.keys(result.missing));
const missing = prettify('Missing dependencies', mapMissing(result.missing, rootDir));
const content = deps.concat(devDeps, missing).join('\n');
log(content);
}
Expand Down Expand Up @@ -119,7 +124,7 @@ export default function cli(args, log, error, exit) {
specials: getSpecials(opt.argv.specials),
skipMissing: opt.argv.skipMissing,
}))
.then((result) => print(result, log, opt.argv.json))
.then((result) => print(result, log, opt.argv.json, rootDir))
.then((result) => exit((opt.argv.json || noIssue(result)) ? 0 : -1))
.catch((errorMessage) => {
error(errorMessage);
Expand Down

0 comments on commit 718fb1b

Please sign in to comment.