Skip to content

Add stripExtensions option to determine which extensions get removed.#247

Merged
fatfisz merged 2 commits into
tleunen:masterfrom
amosyuen:master
Dec 22, 2017
Merged

Add stripExtensions option to determine which extensions get removed.#247
fatfisz merged 2 commits into
tleunen:masterfrom
amosyuen:master

Conversation

@amosyuen
Copy link
Copy Markdown
Contributor

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

@codecov
Copy link
Copy Markdown

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

Comment thread DOCS.md Outdated
[
"module-resolver",
{
"extensions": [".js", ".jsx", ".es", ".es6", ".mjs"]
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread src/utils.js Outdated
}

export function isRelativePath(nodePath) {
return nodePath.match(/\.?\.\//);
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/utils.js
return name;
export function stripExtension(modulePath, stripExtensions) {
let name = path.basename(modulePath);
stripExtensions.some((extension) => {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@amosyuen
Copy link
Copy Markdown
Contributor Author

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

@fatfisz
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@fatfisz Poke?

@fatfisz
Copy link
Copy Markdown
Contributor

fatfisz commented Dec 22, 2017

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

@fatfisz
Copy link
Copy Markdown
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