Does not find inputs provided with absolute paths
See original GitHub issueWhen 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'
Expected Behavior
dependency-cruiser should correctly determine that a provided input path is absolute and does not require prefixing it with a base path.
Current Behavior
dependency-cruiser prefixes every input path with a base path, preventing it from finding inputs specified with an absolute path.
Possible Solution
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.
Steps to Reproduce (for bugs)
- Call
dependency-cruiser
with an absolute path to the input file. It won’t be resolved.
Context
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'.
Your Environment
- Version used: 4.12.0
- Node version: 8.9.4
- Operating System and version: macOS Mojave
- Link to your project: closed-source
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
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 usingmake
for this in the first place).So if
make
reportsnothing to be done
- you’re all set 😃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.