depcheck: Exit code from `depcheck` executable

Using the depcheck executable should exit with an error code if there are unused dependencies. Running it on my project this doesnt appear to be the case.

$ depcheck
Unused devDependencies
* gulp-eslint
* should-http
Missing dependencies
* mongoose-text-search

Results in an exit code:

$ echo $?
0

Versions: Node: v5.7.0 depcheck: 0.6.3.

I’ve had a look around in the code and the issue appears to stem from this block of code: https://github.com/depcheck/depcheck/blob/6cb92533adf3ed2ed3f6054d6cb3c51e56731615/bin/depcheck#L11-L13 If you move the process.exit to outside of the on('finish') callback then it works as expected. Have you seen this issue before? What was the reasoning behind adding that callback?

Edit: This was introduced here: https://github.com/depcheck/depcheck/commit/44124dd908efb5b638b1d417ece5e2aa7a2daa50

Checking out the version before the 0.6.0 release (0.5.11) has fixed the issue.

Edit 2: I’ve added a regression test for this issue in my fork: https://github.com/domharrington/depcheck/commit/99e6ce1816e9e457a7366b969551472f355991b0 Any help would be appreciated!

Edit 3: According to the node docs, process.stdout never emits a finish event: https://nodejs.org/api/process.html#process_process_stdout. Can confirm this is the case as when i put a log statement into that callback, it never gets called.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I made some tests and it seems that there is only an exit code >0 when there are unused dependencies.

$ depcheck --ignores=winston
Missing dependencies
* handlebars
$ echo $?
0
$ depcheck --ignores=handlebars
Unused dependencies
* winston
$ echo $?
255

Any chance we get get a new release published to npm with this fix?

we can remove this callback all together, and just set process.exitCode = 1 in the cli if there is anything unused or in case of error