Closed jamestalmage closed 8 years ago
As I see it there are two options for when require.extensions['.foo'] === undefined
.
We pass through to the .js
extension:
function defaultHook(module, filename) {
return require.extensions[`.js`](module, filename);
}
This would run through the list of extensions for .js
, followed by whatever future hooks were installed for .foo
.
Pro:
.js
and let Node automatically apply it for .es6
, etc.Con:
.js
and .es6
both get executed), etc.We implement the standard default behavior ourself:
function defaultHook(module, filename) {
var content = fs.readFileSync(filename, 'utf8');
module._compile(stripBom(content), filename);
}
Con:
.es6
in addition to .js
, etc). .js
and expect .es6
files to follow along - this would break that.Pro:
I'm leaning towards 2
. My only concern is the Babel example I listed as a con for 2
, but I think that would be a bad choice on Babel's part anyways (I'm not actually picking on Babel here - I don't know how they do it - this is all hypothetical).
:+1: on 2
. This stuff is hard enough as it is, keeping it explicit seems preferable.
I went with 2
, deployed as 0.4.0
cc: @gotwarlost
Right now, if you do:
And no one ever registers a handler for
.foo
, we throw an error if a.foo
file is ever required.Without
append-tranform
what actually happens is that Node just tries to load it as a.js
file.This should be fixed.
Related: #5
// @gotwarlost