When passing an absolute path as input to dependency-cruiser it exits with an error, because resolving the file fails.
For example.
$ dependency-cruise --validate .dependency-cruiser.js /Users/felix/Development/dashboard/src
ERROR: ENOENT: no such file or directory, stat '/Users/felix/Development/dashboard/Users/felix/Development/dashboard/src'
dependency-cruiser should correctly determine that a provided input path is absolute and does not require prefixing it with a base path.
dependency-cruiser prefixes every input path with a base path, preventing it from finding inputs specified with an absolute path.
It appears that src/extract/gatherInitialSources.js is responsible for the concatenation. Ideally it would check every pThis before concatenating or use something like path.resolve instead.
The ideal solution would involve exposing a basePath option that allows customizing the behavior further.
dependency-cruiser with an absolute path to the input file. It won't be resolved.
We are trying to integrate this very useful tool into our project to prevent teams from importing other teams' code. Part of achieving this is running dependency-cruiser via lint-staged in a pre-commit hook. lint-staged passes absolute file paths to tools and dependency-cruiser seems to simply concat the input file paths with process.cwd(). Obviously this breaks.
Thanks for making such a great tool! I'd be happy to open a PR, but I'll need some more help getting the dev environment set up. I couldn't find a working build task in package.json. The build command exits without doing anything:
$ make dev-build
make: Nothing to be done for `dev-build'.
Hi @felixjung - thanks for raising this issue, and providing clear description & context - I understand what's going wrong and why you'll need it.
For testing purposes dependency-cruiser's api has an (undocumented) basePath as a part of the options you can pass it. Until now I haven't exposed it to the cli or the dependency-cruiser config format because (1) it'd probably need quite some additional testing (2) I didn't see the use case. However, this issue seems like a good excuse to start exposing it:-)
I'll see what I can whip up - probably I've some time this weekend to work on it.
Thanks a lot! Please let me know, if you need help or more details.
I'll need a helping hand with validating - I'll give a shout in this thread.
B.t.w. on the build task: there's very little to build - there's a handlebar templates or two that need translating to javascript. make takes care of that, but only if it's strictly necessary (which is the reason I'm using make for this in the first place).
So if make reports nothing to be done - you're all set :-)
@felixjung as you can see I've created a fix. It turned out there was no need to expose the basePath - absolute paths now work out of the box.
I've published it on npm as [email protected]. Can you give it a spin and let me know if it solves the issue for you?
Oh sweet! Thanks a lot. Will take it for a spin with my feature branch.
I just confirmed that it works as expected for our use case. Thanks! Looking forward to the release.
@felixjung Thanks for the validation! I hope to release somewhere this evening - I'll give a holler in this thread.
4.12.1 with the fix for this issue is on npm since a few seconds
Thanks! Awesome job. 鉂わ笍