-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Added Multi extension support. #26
Conversation
This PR is intended to fix #24. |
@phated Any idea why the test suite is failing for |
3380e69
to
ed6cabb
Compare
It was actually my fault. The supportsExtension check should iterate over 1 - |
|
||
var supportsExtension = Object.keys(require.extensions).indexOf(exts[0]) !== -1; | ||
|
||
if (supportsExtension) { | ||
return true; |
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.
You can't return here. Some extensions require further setup which is performed later.
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'm not sure I get your point. I believe this return was here before. This is basically the same check as used to be in the master branch.
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.
Since you are asking for multiple match groups, you are also implying that there is an upper limit to the number of possible extensions any one file can have. I presume that with at most three extensions the system should work fine, e.g.
yields
|
Just grab everything from the first dot, split on dot, and do this: ['.one', '.two', '.three'].map(function (item, idx, arr) {
return arr.slice(idx).join('');
}); ...that will give you |
Yeah, agreed. I believe this is the simplest solution. I will work on that. On Fri, Jun 5, 2015 at 11:47 AM, Tyler Kellen notifications@github.com
Alan Souza |
ed6cabb
to
74ff352
Compare
return; | ||
} | ||
return extension[1]; | ||
return possibleExtensions.map(function (item, idx, arr) { | ||
return arr.slice(idx).join(''); |
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.
Thanks for the insight @tkellen!
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.
great solution btw!
@alansouzati Is this ready for review? |
Sorry, let me just fix the typo in |
Also, can you add to the test a path that includes a directory with a dot in it? |
74ff352
to
f5cc3dd
Compare
Sure @phated ! |
if (Object.keys(require.extensions).indexOf(ext) !== -1) { | ||
var exts = extension(filepath); | ||
|
||
var supportsExtension = Object.keys(require.extensions).indexOf(exts[0]) !== -1; |
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 think we need to filter here and then check length, no?
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.
Well, if you look at the validation I'm using only the first option exts[0]
(e.g .babel.js
). If we don't do this check we would treat .babel.js
as .js
files. You can check that by removing it and running the tests.
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.
but shouldn't we check every extension to see if we support it? e.g. what if a user names something .babel.coffee for some reason
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.
Yeah, that's a good point, but I'm not sure how to solve this unless we check semantics on the file, 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.
I was thinking
var registered = exts.filter(function(ext){ return Object.keys(require.extensions).indexOf(ext) !== -1; });
if(exts.length === registered.length){
return true
}
@tkellen am I thinking about this correctly?
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.
actually, i don't think require.extensions will ever have something like .babel.js
because node's loader doesn't work with that. hmmm, this is a tricky check
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.
In the context of Liftoff, it was wrong of rechoir to throw on an unknown extension. An unknown extension could very well be standard JS (as is the case for @alansouzati). I've fixed this here: 62fb2a6
We still need to use some portion of this PR to support things like tmp.babel.js
, though.
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.
Cool. feel free to pick and choose whatever you need from this code. Then after that we can easily close the PR.
Fixed supportsExtension check. Fixed extensions for multi period. Fixing typo on the extension. Added tests for folders with dots.
f5cc3dd
to
3d0412c
Compare
@alansouzati any chance you can tackle the remaining issue? I'd like to close some of the issues open related to this. |
I'm uncertain how to tackle the remaining issue.. any suggestions? |
@alansouzati maybe that check can go away and we can check if the module that matches the extension is already in the |
@tkellen any chance of fixing this? I'm looking into using this module for karma config loading where I have files like |
This is currently blocked by gulpjs/rechoir#26 to work. When finished this will fix #2180,#1597,#1727
Superseded by #37 |
Hi, as agreed, I'm creating the PR again to add multi extension support!