-
-
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
Multi extension support #37
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
const path = require('path'); | ||
|
||
const EXTRE = /^[.]?[^.]+([.].*)$/; | ||
const EXTRE = /\.[^.]+/g; | ||
const LONGEXTRE = /^[.]?[^.]+([.].+)$/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sttk yeah, I think your regexp is better than mine. Let me come up with some tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sttk actually, it seems the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made the above changes that I suggested and added a test. Let me know what you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sttk your above RegExp is pretty good but it completely rejects ANY path that has double dots. I think that is incorrect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure. We should change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @phated Which should we adopt for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sttk I think 2 is correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sttk I just pushed changes that use your suggestion (2) and included tests. Let me know if you think that solves the issue. |
||
|
||
module.exports = function (input) { | ||
var extension = EXTRE.exec(path.basename(input)); | ||
if (!extension) { | ||
var basename = path.basename(input); | ||
var longExtension = LONGEXTRE.exec(basename); | ||
if (!longExtension) { | ||
return; | ||
} | ||
return extension[1]; | ||
var possibleExtensions = longExtension[1].match(EXTRE); | ||
if (!possibleExtensions) { | ||
return; | ||
} | ||
return possibleExtensions.map(function (_, idx, exts) { | ||
return exts.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.
Boolean(require.extensions[ext])
is faster.Or is it possible that a value of an existing key is falsy?
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.
Sorry, it is possible that
usedExtension
is undefined andrequire.extensions[usedExtension]
becomesrequire.extensions['undefined']
.Cancel the above comment, or move this line after checking
config
is not nullish if you will modify.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 it's fine to keep like this.