Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TypeScript resolver #20

Open
JounQin opened this issue Jun 25, 2022 · 6 comments
Open

feat: TypeScript resolver #20

JounQin opened this issue Jun 25, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@JounQin
Copy link
Contributor

JounQin commented Jun 25, 2022

Reproduction detail #19

@privatenumber
Copy link
Owner

privatenumber commented Jun 25, 2022

This is currently expected behavior because it's a "paths matcher", not a TypeScript resolver.

In tsx (+ cjs-loader, esm-loader), we resolve using this util.

Are you trying to use this in another project?
Perhaps we can turn this into a feature request to add a TypeScript resolver.

@JounQin
Copy link
Contributor Author

JounQin commented Jun 25, 2022

@JounQin
Copy link
Contributor Author

JounQin commented Jun 25, 2022

@privatenumber privatenumber added the enhancement New feature or request label Jun 25, 2022
@privatenumber privatenumber changed the title baseUrl + .js extension with .ts source feat: TypeScript resolver Jun 25, 2022
@privatenumber
Copy link
Owner

privatenumber commented Jun 26, 2022

I investigated this, and it might be a little more complicated than it appears.

I'd like to keep get-tsconfig file-system agnostic, but it seems to definitely require a file-system to check whether a path is a directory, has a package.json and read from the main property.

Here's a tsc resolver log:

======== Resolving module './a' from '/get-tsconfig/test/index.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module as file / folder, candidate module location '/get-tsconfig/test/a', target file type 'TypeScript'.
File '/get-tsconfig/test/a.ts' does not exist.
File '/get-tsconfig/test/a.tsx' does not exist.
File '/get-tsconfig/test/a.d.ts' does not exist.
File '/get-tsconfig/test/a/package.json' does not exist.
File '/get-tsconfig/test/a/index.ts' does not exist.
File '/get-tsconfig/test/a/index.tsx' does not exist.
File '/get-tsconfig/test/a/index.d.ts' does not exist.
Loading module as file / folder, candidate module location '/get-tsconfig/test/a', target file type 'JavaScript'.
File '/get-tsconfig/test/a.js' does not exist.
File '/get-tsconfig/test/a.jsx' does not exist.
File '/get-tsconfig/test/a/package.json' does not exist according to earlier cached lookups.
File '/get-tsconfig/test/a/index.js' does not exist.
File '/get-tsconfig/test/a/index.jsx' does not exist.
======== Module name './a' was not resolved. ========

That said, it won't be as simple as adding paths with .ts, .tsx, etc appended.

@JounQin
Copy link
Contributor Author

JounQin commented Jun 26, 2022

See https://github.com/alexgorbatchev/eslint-import-resolver-typescript/blob/master/tests/withJsExtension/test.js#L27-L131 for more test cases.

Yeah, there are a lot of test cases. 😅

@privatenumber
Copy link
Owner

For reference, here's another edge-case to cover:
privatenumber/tsx#59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants