sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.16k stars 249 forks source link

How to get `exit(1)` when errors occurred by running `depcruise -p src` in pre-commit hook? #881

Closed Lenghak closed 9 months ago

Lenghak commented 9 months ago

Summary

I wanted to find out how to generate exit code 1 from getting an dependencies violation errors in pre-commit hook.

Context

So, the thing is I wanted to check to see if there are any dependencies violations like orphan-files, circular-dependencies, and more in my pre-commit hook. However, even though there is an error regarding to above options, I still got exit code 0 meaning people can still push their code along with errors into their branch.

Environment

Lenghak commented 9 months ago

[Updated on : 7th Dec 2023]

Found the solution:

// ...

pnpm cruise || exit $

// ...

This is about shell knowledge and problems not library specific. Further inspection I will add more on this.