Dependency-cruiser: Does not find inputs provided with absolute paths

Created on 24 Jan 2019  路  9Comments  路  Source: sverweij/dependency-cruiser

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'

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)


  1. 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
bug

All 9 comments

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. 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings