Skip to content
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

Merged
merged 2 commits into from
Dec 22, 2017

Conversation

amosyuen
Copy link
Contributor

Add stripExtensions option to determine which extensions get removed.
Also process relative paths so that extensions get resolved.

@codecov
Copy link

codecov bot commented Dec 11, 2017

Codecov Report

Merging #247 into master will not change coverage.
The diff coverage is 100%.

Impacted Files Coverage Δ
src/normalizeOptions.js 100% <100%> (ø) ⬆️
src/resolvePath.js 100% <100%> (ø) ⬆️
src/utils.js 100% <100%> (ø) ⬆️

@amosyuen amosyuen force-pushed the master branch 3 times, most recently from 785db33 to d85c119 Compare December 11, 2017 00:45
Copy link
Owner

@tleunen tleunen left a 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"]
Copy link
Owner

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? ;)

Copy link
Contributor Author

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(/\.?\.\//);
Copy link
Owner

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?

Copy link
Contributor Author

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) => {
Copy link
Owner

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 :)

Copy link
Contributor Author

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.

Copy link
Owner

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.

@fatfisz
Copy link
Contributor

fatfisz commented Dec 12, 2017

Hmm it seems like this branch is doing a bunch of other stuff other than adding the option (e.g. removing the if (sourcePath[0] === '.') check at the beginning of resolvePath).

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.

@amosyuen amosyuen force-pushed the master branch 2 times, most recently from 9bc08ac to 72f7667 Compare December 15, 2017 04:42
@amosyuen
Copy link
Contributor Author

I moved the relative path check fix to another branch. That also lets us keep the broken test.

@amosyuen
Copy link
Contributor Author

@fatfisz @tleunen Have you had a chance to take a look with the new breakdown?

@fatfisz
Copy link
Contributor

fatfisz commented Dec 18, 2017

Sorry for the silence, I'll take look at the branch in at most two days. Thanks for your patience!

@amosyuen
Copy link
Contributor Author

@fatfisz Poke?

@fatfisz
Copy link
Contributor

fatfisz commented Dec 22, 2017

@amosyuen Really sorry for the delay, I'm reading the code right now.

@fatfisz
Copy link
Contributor

fatfisz commented Dec 22, 2017

@amosyuen Ok, everything's much clearer now! LGTM

@fatfisz fatfisz merged commit fdf5da9 into tleunen:master Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants