-
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 support for resolving extensions in relative paths #259
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
|
@fatfisz What do you think? |
I'm more worried about surprises in resolving, but we could always release this as a RC to verify the assumptions. Otherwise I think this is a good change; I wouldn't worry about the potential increase in time. |
So how should we move forward with this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like the feature, I think it makes sense. Resolving is not only about custom paths, it's also about specific extensions.
Although the use case seems limited since people usually write the extension when it's not one of the "default" supported extensions.
And it wouldn't work well for the .android.js
or .ios.js
since the plugin doesn't know which one to use in that case. It shouldn't actually put the extension in this very specific case.
]; | ||
|
||
export default function resolvePath(sourcePath, currentFile, opts) { | ||
if (isRelativePath(sourcePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to remove this condition?
I mean.. Resolving a relative path is only about potentially adding the custom extension, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to make sure the relative path is checked first we can change the order of the resolvers to have the relativeResolver first. Which is logically equivalent to having an if statement that explicitly runs the relative resolver.
I'm not opposed to that, but I think this is more a question of where we want the if checks of whether to run the resolver. For example, rather than have the array of resolvers, we could just have multiple if statements that decide whether to run each resolver. But I do think we should be consistent. My leaning is towards having the if checks in the resolvers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Sorry, it's been a while since I worked in this area of the code and I didn't read it properly. resolvePath
is called for every "resolvers" so indeed we have to remove it.
But then, should we actually run resolvePathFromAliasConfig
and resolvePathFromRootConfig
on relative paths? I don't think so, right? (cc @fatfisz)
Should relative paths only run resolvePathFromRelativeConfig
to potentially resolve the custom extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly somebody might want a relative path alias "e.g. ./lib -> some/other/path/lib". So there might be a small case for running aliases for relative paths. resolving from root, probably not.
Depending on the order we put the resolvers, the others won't run. e.g. with the way I have it now, if the path is relative, it will always run resolvePathFromRelativeConfig first, and so will never reach the other two resolvers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with @amosyuen . it might slow down resolution but perhaps we should add an exclude/include option so we can exclude/include specific directories/regexes, ....
for the android, ios case you probably have different babel configs, one that looks for ios.js & .js and another one that does for android.js and .js
I have something like this in config
where BUILD_PLATFORM can be web, android or ios. this PR does the trick for me already published to our private NPM |
I finally got a use case where I wanted to resolve a relative path as well, but with a specific alias config though. The usecase was to map all So I wonder if instead of the custom |
Nvm, it's not safe to run on all paths as is. Let's say I have an alias |
Currently relative paths are always ignored, so extensions can't be resolved for relative paths. This change adds support for resolving relative paths.