tsconfck icon indicating copy to clipboard operation
tsconfck copied to clipboard

[Feature Request] Add a few API for `eslint-import-resolver-typescript` and `eslint-plugin-import-x` to migrate to `tsconfck`

Open SukkaW opened this issue 1 year ago • 3 comments

Describe the feature

I recently became the co-maintainer of the eslint-import-resolver-typescript and the eslint-plugin-import-x projects, and I am working on replacing get-tsconfig w/ tsconfck. I have faced a few difficulties in implementing that because of the lack of the following features:

  • Synchronous API
  • Paths matcher / resolver

A Usecase

ESLint rules are synchronous, so we need a synchronous API to get the tsconfig file.

We also need a resolver that implements a module resolver interface that implements the TypeScript resolving algorithm (https://github.com/microsoft/TypeScript/blob/3ccbe804f850f40d228d3c875be952d94d39aa1d/src/compiler/moduleNameResolver.ts#L2465):

  • https://github.com/dividab/tsconfig-paths/blob/b4eb77bd1a49096f0fa1076e65a8182819b1dc2c/src/match-path-sync.ts#L27
  • https://github.com/privatenumber/get-tsconfig/blob/9e78ec52d450d58743439358dd88e2066109743f/src/paths-matcher/index.ts#L41

Alternatives

I could use libraries like synckit to force convert async API to sync, but it is less ideal.

As for the matcher/resolver, I could copy codes from vite-tsconfig-paths, which IMHO is also not ideal.

Additional context

SukkaW avatar Jul 27 '24 18:07 SukkaW

from your requirements it reads like get-tsconfig is a pretty good fit. What makes you consider tsconfck as a replacement?

see https://github.com/dominikg/tsconfck/issues/31 and https://github.com/dominikg/tsconfck/discussions/18 for previous discussions around sync apis.

dominikg avatar Jul 27 '24 19:07 dominikg

from your requirements it reads like get-tsconfig is a pretty good fit. What makes you consider tsconfck as a replacement?

Mostly the sheer difficulties of contributing to get-tsconfig. I've tried to add ${configDir} support for get-tsconfig, but I can't even get its existing test cases to pass after upgrading to TypeScript 5.5. On the other hand, tsconfck already has full ${configDir} support.

SukkaW avatar Jul 28 '24 06:07 SukkaW

it might still be easier to add support for that in get-tsconfig (a little surprised it isn't supported yet) than bringing sync support to tsconfck.

There is an old branch linked in the Discussion above but from what i remember it wasn't easy to have a single codebase that supports sync and async. And it probably got worse since then because of the changes around the cache.

Happy to look into contributions that add sync support, but afraid that would require a major refactor to ensure keeping it lean and without duplicated logic.

For the features around implementing a resolver or paths matcher, it is more difficult to justify adding them to tsconfck. I think they would better live in separate packages and shared between get-tsconfig, vite-tsconfig-paths etc.

tsconfck focus is

A utility to find and parse tsconfig files without depending on typescript

what to do with the output is out of it's scope.

dominikg avatar Jul 28 '24 11:07 dominikg

closing this as out of scope, get-tsconfig gives you sync access until eslint allows you to work async and anything that is related to interpreting the outcome of tsconfig needs to be in a separate package.

dominikg avatar Oct 08 '24 07:10 dominikg

Still thanks for your awesome library!

SukkaW avatar Oct 08 '24 07:10 SukkaW