antoine-coulon/skott

Relative paths in tsconfig `extends` not supported

Opened this issue · 4 comments

Summary

Relative paths in the tsconfig extends field don't appear to work. If I adjust the path to be relative to the cwd, things work as expected.

Happy to open a PR if that'd be helpful. Thanks!

Reproduction steps

Adjust the extends field in a tsconfig file to use a relative path. Run Skott, and observe exceptions when reading tsconfig.

Expected result:

Actual result:

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
skott installed version? 0.35.3
Operating system? Mac
Would you consider contributing a PR? Yes
Node.js version (node -v)? v20.11.1

Hello @rmunch,

Thanks for reporting the issue!

Could you please provide me a concrete example of a not working config (the one you opened the issue for) vs the working config? Just to make sure that there is no quiproquo regarding the issue to fix (most of the time relative paths are misleading).

Thanks

@rmunch,

I'm not sure I understood the problem, I might be missing details, here is a working example with skott working extends from tsconfig.json using a relative path to tsconfig.alias.json

For me to be able to solve the issue I would need the configuration you're using that is all the tsconfig and what you're trying to achieve.

Capture d’écran 2024-10-22 à 22 19 52

Hi @antoine-coulon - with your screenshot above, if you move the tsconfig.json into a subdirectory and adjust the extends value to something like ../tsconfig.alias.json, that'll trigger the issue. So essentially, Skott assumes the path is relative to the current working directory rather than to the tsconfig file (in your example, both happen to be the same).

I see, in that case the outcome will probably depend on the directory where skott is run.

It should probably be documented somewhere, but currently skott is not really supporting the run from a directory where files are relying on path aliases references or definitions located in parent directories. What you describe to me seems like you're running skott from a sub-package and this sub-package references a tsconfig in a parent directory (which seems to be the root of the repository, usually where a tsconfig.base.json lives).

In the case you're describing, running skott from the root directory where path alias references live and then target the sub directory using --cwd=<dir> (to narrow the analysis to files located in <dir>) should work. In other words running skott from ../ that is in the same directory as tsconfig.alias.json should work, as there are only references starting with the cwd as a base reference (nothing goes outside): cd ../ && skott --cwd=<package>

While as I user I would expect both ways to work out of the box, having all resolution cases working with path aliases support indeed comes with a lot of edge cases and challenges. Also, some design decisions don't allow me an easy fix, but rather needing more or less a wide re-design, you can read a bit more there if you're interested.