johvin / eslint-import-resolver-alias

a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias
MIT License
180 stars 10 forks source link

Question about subfolders #7

Closed parvezalisha closed 5 years ago

parvezalisha commented 5 years ago

Hi, I have a folder structure like:

src/helpers/
src/abcd/helpers/

If i have an alias "helpers" for src/helpers then the resolver tries to resolve src/abcs/helpers to that alias too and then eslint throws import/no-unresolved.

Wanted to know if i am doing something wrong or if this is not supported.

Thanks

johvin commented 5 years ago

@parvezalisha You are right. The resolver will find all the "helpers" words in package path and replace it with its alias. If you just want to make alias for "src/helpers", use ['^helpers$', 'src/helpers'] instead.

parvezalisha commented 5 years ago

My issue is resolved by changing the order of the paths. If i resolve src/abcd/helpers/ first then src/helpers/ doesn't throw errors. Thanks

parvezalisha commented 5 years ago

Can this be mentioned in the usage documentation?

johvin commented 5 years ago

@parvezalisha Actually, I still don't know quite well what your configuration of alias resolver is, can you post it here so that I can be sure that description of the thrid note item in the usage section doesn't cover this situation. thanks.

parvezalisha commented 5 years ago

@johvin I have a folder structure like:

src/helpers/
src/abcd/helpers/

and if i try to map it as below:

 map: [
          ['helpers', path.resolve(__dirname, './src/helpers')],
          ['abcd', path.resolve(__dirname, './src/abcd/helpers')], 
      ],

eslint throws unresolved path errors because the plugin tries to resolve src/abcd/helpers to the first helpers path. But if i change the order to:

 map: [
          ['abcd', path.resolve(__dirname, './src/abcd/helpers')], 
          ['helpers', path.resolve(__dirname, './src/helpers')],
      ],

everything works fine because now src/abcd/helpers gets resolved first and does not conflict with the other 'helpers' mapping.

johvin commented 5 years ago

@parvezalisha Actually, description of the fourth note item in the usage section just explains the importance of the config rules' order, but maybe not clear enough for your situation. I will improve the notes with this issue soon. Many thanks.

johvin commented 5 years ago

@parvezalisha After much thought, I think your problem is caused by a bug of this plugin, not the order of configuration. The bug, actually, is specially designed as a feature to resolve path/to/file to path/from/file with the configuration of ['to', 'from'], but it now seems problematic. I have fixed it in version 1.1.2 and welcome to upgrade to that. Sorry for the trouble to you and thanks.

parvezalisha commented 5 years ago

@johvin it works fine now. Thanks.