question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not find inputs provided with absolute paths

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sverweijcommented, Jan 25, 2019

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 😃

1reaction
sverweijcommented, Jan 24, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IOException: Can't read input file. I couldn't find solution using ...
1 Answer 1 ... obviously your absolute paths are incorrect. you are resolving the relative paths based on the directory in which you...
Read more >
Same absolute path works for \input but does not work for ...
If I use the command "\input{filepath}" then the file is perfectly printed in "main.tex". If I only change the command to "\include{filepath}" I ......
Read more >
ffmpeg concat doesn't work with absolute path - Super User
Since non-absolute paths are relative to the location of the concat demuxer input script, ffmpeg prepends the path of the latter to the...
Read more >
Path variables | CLion Documentation - JetBrains
Use path variables to define absolute paths to resources that are not part of a specific project. These external resources may be located...
Read more >
Absolute, relative, UNC, and URL paths—ArcMap
If, however, you use relative paths, ArcGIS will not find the script and the tool will not work. The tool dialog box will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found