dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

fix: use typescript library to resolve tsconfig files #246

Closed effervescentia closed 1 year ago

effervescentia commented 1 year ago

hey @jonaskello I'm running into this problem when trying to use a library that depends on yours (dependency-cruiser)

My company has a fairly complex typescript configuration setup which we have extracted to a config that is extended from multiple levels deep, as a result the paths configuration that is inherited is unfortunately ignored by your library. This change updates the tsconfig resolution to use what is provided out-of-the-box by typescript itself to avoid needing to concern yourself with the details of how config extension actually works

https://typestrong.org/ts-node/api/interfaces/TSCommon.html#readConfigFile https://typestrong.org/ts-node/api/interfaces/TSCommon.html#parseJsonConfigFileContent

ironically I originally saw this while exploring the codebase of dependency-cruiser trying to get to the bottom of this issue https://github.com/sverweij/dependency-cruiser/blob/master/src/config-utl/extract-ts-config.js#L52

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -1.62 :warning:

Comparison is base (910a138) 68.16% compared to head (9a46e67) 66.54%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #246 +/- ## ========================================== - Coverage 68.16% 66.54% -1.62% ========================================== Files 9 9 Lines 311 284 -27 Branches 96 86 -10 ========================================== - Hits 212 189 -23 + Misses 93 88 -5 - Partials 6 7 +1 ``` | [Impacted Files](https://codecov.io/gh/dividab/tsconfig-paths/pull/246?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dividab) | Coverage Δ | | |---|---|---| | [src/tsconfig-loader.ts](https://codecov.io/gh/dividab/tsconfig-paths/pull/246?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dividab#diff-c3JjL3RzY29uZmlnLWxvYWRlci50cw==) | `83.78% <100.00%> (-0.60%)` | :arrow_down: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dividab). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dividab)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

jonaskello commented 1 year ago

This seems interesting :-) Is there some docs that state that parseJsonConfigFileContent is a public api in the typescript package?

effervescentia commented 1 year ago

This seems interesting :-) Is there some docs that state that parseJsonConfigFileContent is a public api in the typescript package?

That's a good question... I haven't seen anywhere that states that it is explicitly available for use or what the expected longterm support for it is. The docs from ts-node that I referenced indicate that it's a common method shared across multiple versions of typescript.

The other (or one of the other) options is to use a library that is purpose-built for resolving a typescript config file such as this one, get-tsconfig. It has no dependency on typescript to provide the config file resolution, but does claim to test against it for correctness (I haven't confirmed this for myself).

effervescentia commented 1 year ago

@jonaskello I collected a list of notable repositories using this approach in their own source code, not sure if that helps to sell my change 😅

https://github.com/quasarframework/quasar https://github.com/bokeh/bokeh https://github.com/AssemblyScript/assemblyscript https://github.com/GoogleChromeLabs/squoosh https://github.com/vuejs/vetur

effervescentia commented 1 year ago

hey @jonaskello any update from your end? are you looking for a different kind of solution?