-
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 stripExtensions option to determine which extensions get removed. #247
Conversation
Codecov Report
|
785db33
to
d85c119
Compare
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.
@fatfisz I'd like your eyes on this PR as well when you have some time :)
DOCS.md
Outdated
[ | ||
"module-resolver", | ||
{ | ||
"extensions": [".js", ".jsx", ".es", ".es6", ".mjs"] |
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.
shouldn't this be stripExtensions
? ;)
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.
Yep, copy and paste error
src/utils.js
Outdated
@@ -15,27 +15,32 @@ export function toPosixPath(modulePath) { | |||
return modulePath.replace(/\\/g, '/'); | |||
} | |||
|
|||
export function isRelativePath(nodePath) { | |||
return nodePath.match(/\.?\.\//); |
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.
Should we start the regex with ^
to make sure we match only the beginning?
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.
Ah, good catch.
return name; | ||
export function stripExtension(modulePath, stripExtensions) { | ||
let name = path.basename(modulePath); | ||
stripExtensions.some((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.
nit: I'd prefer a reduce
function in this case, but it seems ok :)
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.
Not sure why a reduce
is preferred unless you want to strip multiple extensions, but I feel like that could easily behave differently than people expect. Simpler to strip the first matched 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.
Oh you're right. You only need to do the operation once. My bad.
Hmm it seems like this branch is doing a bunch of other stuff other than adding the option (e.g. removing the I'm especially worried about "with the plugin applied twice" test being removed - does this mean the changes broke the test? If so, then it would be better to at least document the new behavior instead of removing the test, and also at this point we're dealing with a breaking change (if this is the case). I suggest splitting the branch into smaller ones, because I'm afraid that too much is happening here at once. |
9bc08ac
to
72f7667
Compare
I moved the relative path check fix to another branch. That also lets us keep the broken test. |
Sorry for the silence, I'll take look at the branch in at most two days. Thanks for your patience! |
@fatfisz Poke? |
@amosyuen Really sorry for the delay, I'm reading the code right now. |
@amosyuen Ok, everything's much clearer now! LGTM |
Add stripExtensions option to determine which extensions get removed.
Also process relative paths so that extensions get resolved.