-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Greetings,
I have a setup of ESLint + Node + TS and VS Code for a server-side project. In order to get my path aliases working in ESLint plugin of VS Code, I decided to use this package. I spent 4 hours today and finally got it to work after debugging this code!
The problem was that my project was in a subfolder of the WorkingDirectory, so the process.cwd()
in https://github.com/johvin/eslint-import-resolver-alias/blob/master/index.js#L70-L71 was returning /
and couldn't resolve the path to the referred module. I found that I needed to use changeProcessDirectory
in the ESLint settings of VS Code in settings.json
for my subfolder WorkingDirectroy. (As shown in microsoft/vscode-eslint#196 (comment))
With this history, the biggest problem I have right now is every time I want to define a new module path-mapping (alias), I need to change 3 different places individually! that is:
tsconfig.json
,.eslintrc.js
(for thisalias
resolver),- and finally a manual
module-alias
becausetsc
doesn't resolve the mapping when it emits the JS codes. (Filed at Offer option to resolve module path maps in emitted code microsoft/TypeScript#26722 (comment))
Suggestion
In order to reduce the number of places I need to change upon adding a new mapping, I was thinking that maybe this resolver can take a parameter to read the mapping from tsconfig.json
.
To start, it can take a pathToTSConfig
and pathPrefix
(e.g. @
or ~
to make it easier to identify the custom paths) and extract the mapping from there. That way, the source of truth will live in one less place.
I don't know if you guys think it's a good addition to this NPM package. If so, I can start working on a PR. Otherwise, I think the best I should do is to fork this resolver and create a new one, simply to support reading from tsconfig.json
.
Please advise.
Thanks!