-
Notifications
You must be signed in to change notification settings - Fork 205
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
Add regular expression support #132
Conversation
Codecov Report
Continue to review full report at Codecov.
|
Nice work again @fatfisz. I'm a little bit busy but I'll try to take a look at the code tomorrow |
I like the fact that the root config has the highest priority. Forcing the regex to start with Nothing else to say, I'll merge it during the weekend unless you want to add something? |
Hi, after all I think that RegExps should have the lowest priority, because they are this sort of catch-all mechanism and can handle more cases than aliases. For example:
Even though an alias for Also I first wanted to confirm if the feature is ok and then add the docs - so I'll add them while I'm at that. |
You have a good point here @fatfisz :) Shouldn't this be done automatically when the system finds it's a regex? I guess it's not that important too since people shouldn't really use a backslash in their path/filename |
We are dealing with a string here (not the regexp), and that's where the problems are coming from; let's look at an example: If we had a string With that out of the way, let's look at this example: Hence the quadruple backslash - first escaping because of the need to discern between I hope this is clear, but as usually it might be too long and clear only to me, so thanks for the patience :) Side note: |
Btw. by "clear only to me" I meant my explanation and not the thing that I was trying to explain 😄 Basically explaining is not easy for me, as you can see by the length of the previous comment 😜 |
@tleunen Hi, is there anything I can do to help with this PR? I understand that life is not only GitHub, no pressure here :) |
Hey @fatfisz, I'm very sorry, I've been very busy these past few weeks with personal things so I can't give the time I'd like to the OSS projects I have to maintain. Having said that, I really appreciate your contributions, everything looks fine in this PR again. I'll merge it and grant you a collaborator access to this repo. Before releasing a new version, I'd like to test the latest changes in one of my project (and alongside the eslint-import-resolver-babel-module project to make sure everything's fine. |
Thanks for merging! Also I hope all is well for you; personal matters are more important than OSS. |
This PR adds a support for the regular expressions. The feature was alread requested a few times (e.g. #88 and #127).
This is a proposed implementation and it may and should be a subject to changes if there is a better solution to the problem.
RegExps are defined in the
alias
part of the plugin options. For an alias to be treated as a RegExp it has to either start with'^'
or end with'$'
.RegExp resolving has a higher priority than alias resolving but a lower priority than the root resolving.
Once a path is matched, it is changed to the value passed in the
alias
options with those changes:'\\\\'
is changed to'\\'
'\\n'
wheren
is a non-negative integer is changed to the n-th matched groupn
in'\\n'
is greater than the number of the matched groups then it is changed to''
(an empty string), and not'undefined'