ilearnio / module-alias

Register aliases of directories and custom module paths in Node
MIT License
1.74k stars 69 forks source link

Support / documentation for tooling #26

Open josemotanet opened 6 years ago

josemotanet commented 6 years ago

Hello Nick,

I read about module-alias today and I was very interested in using it. However, I intend to use it in a way that won't break the tooling around it such as test suites with either Jest, Mocha, Jasmine, or other tooling such as ESLint, TSLint and all that.

I wonder how it would be possible to have all possible tools around a Node project to leverage module-alias. I don't think there's enough documentation to teach the community about it.

Thank you.

ilearnio commented 6 years ago

Hey,

As far as I know the only tool that may not play nicely with it is an IDE, because things like autocompletion, go-to-definition etc will not not work properly. There is a way to configure VSCode editor to support aliases, but I'm not sure about other editors. I guess it makes sense to add some docs for that.

The other tools that you mentioned should work fine, linters don't care about path names, and test frameworks are just regular Node.js packages that you require/import the usual way, so there are no problems with them.

Will keep this open

josemotanet commented 6 years ago

Thanks for getting back. ESLint does have a rule called import/no-unresolved which effectively attempts to resolve paths, therefore my question.

So you're suggesting I require('module-alias/register'); before each test file, for instance? Having some sort of entry file for the test run to consider and avoid all the duplication would be super convenient. What do you think?

Thanks.

ilearnio commented 6 years ago

I've never seen import/no-unresolved in action since I'm using eslint + standard in all my projects which apparently doesn't include such rule. But if I find how to make it work, I think it worth adding it to the docs/readme.

As per testing, it is a common practice to create a setup file, where all the pre-initialization logic goes. So module-alias can be registered there. I don't think it worth describing how to set up each test framework, plus they change their API quite frequently so I will then need to monitor each of them.

josemotanet commented 6 years ago

Thanks Nick. I understand I'm not an expert in Node by any stretch of the imagination and could really use some help. I'm sure the community will benefit from the contribution.

Re: testing, I agree that setups per tool is not worth the time. However, I'm willing to put an example for Jest for instance and document the common pattern from there.