-
Notifications
You must be signed in to change notification settings - Fork 38
Conversation
I'm not in love with adding custom extension support here. All I see is maintenance burden. Would something like the following suffice? function tryResolve(file) {
try {
// implicitly uses require.extensions to resolve known file types
// json would be a noop since JSON files don't fulfill the required
// exported function API
file = file.replace(path.extname(file), '');
require.resolve(file);
return true;
} catch (err) {
return false;
}
}
// ... snip ...
} else if (stats.isFile() && tryResolve(file)) {
// ... snip ... |
Yup, that's a good suggestion. I've done that an pushed. |
The sample code isn't very robust and should be improved before merging. For example, if Thanks for being so responsive @aexmachina. |
Maybe I don't understand, but I'm not aware of any issue with using require |
@totherik's comment was pointed toward the code behavior. In his example, Think about all the weird stuff that "clever" developers will come up with. 😆 |
Okay, gotcha. Good point, have pushed a more robust version. |
I was thinking some more along the lines of: file.replace(new RegExp(path.extname(file) + '$'), ''); |
Yes, I considered that but then you'd need to escape the I also tested some assumptions about how |
Yeah, I don't want to be in the business of maintaining naive extension parsing regexes when I can rely on extname. It may not be a bad idea to have an explicit test case for this feature at this point. Consider this: 'use strict';
var path = require('path'),
assert = require('assert');
function a(file) {
var ext = path.extname(file);
if (ext) {
return file.replace(new RegExp('\\' + ext + '$'), '');
}
return file;
}
function b(file) {
return file.replace(/\.[a-z]+$/i, '');
}
['', '.js', '.coffee', '.', '.pk12'].forEach(function (ext) {
var expected, original;
expected = path.join(__dirname, 'foo');
original = expected + ext;
assert.equal(a(original), expected, 'implementation a failed to parse ' + original);
assert.equal(b(original), expected, 'implementation b failed to parse ' + original);
}); Function |
Yes I couldn't agree more. My latest commit (when I posted my last comment) didn't actually push, so you couldn't see it after my previous commit. Basically I have used |
This looks good to me. One last question: you actually tested this with coffeescript, right? 😄 I don't have it configured to actually try out so I want to make sure at least one person has tested ensure this code change resolve this particular issue. Thanks, again, for your work on this @aexmachina |
Just one last request from me. @aexmachina, would you mind contributing a simple example along the vein of what's in the krakenjs.com examples section? I'd be happy to link to it |
Tested in CoffeeScript - yes, I've been using it with CoffeeScript. Not sure what the example would be - it's exactly the same as JavaScript. I've updated |
Either way, 👍 from me. |
Kraken now supports CoffeeScript 👍 |
Go team! |
There's several ways that we could do this, but I'm not sure what your preference is so I've implemented how I think it should be supported: if
.coffee
is included inrequire.extensions
then enrouten will load CoffeeScript files.Other options include opt-in using a configuration option, or the ability to specify the set of extensions to be loaded in the config.