@ -59,8 +59,6 @@ function requireNative (id) {
return loadNative ( id ) . exports ;
}
// Event
var eventsFn = process . compile ( "(function (exports) {" + natives . events + "\n})" ,
@ -93,6 +91,8 @@ if (process.env["NODE_PATH"]) {
modulePaths = process . env [ "NODE_PATH" ] . split ( ":" ) . concat ( modulePaths ) ;
}
var moduleNativeExtensions = [ 'js' , 'node' ] ;
/* Sync unless callback given */
function findModulePath ( id , dirs , callback ) {
process . assert ( dirs . constructor == Array ) ;
@ -106,10 +106,6 @@ function findModulePath (id, dirs, callback) {
return ;
}
if ( /\.(js|node)$/ . exec ( id ) ) {
throw new Error ( "No longer accepting filename extension in module names" ) ;
}
if ( dirs . length == 0 ) {
if ( callback ) {
callback ( ) ;
@ -126,22 +122,17 @@ function findModulePath (id, dirs, callback) {
rest = [ ] ;
}
var locations = [
path . join ( dir , id + ".js" ) ,
path . join ( dir , id + ".node" ) ,
path . join ( dir , id , "index.js" ) ,
path . join ( dir , id , "index.node" ) ,
path . join ( dir , id )
] ;
var ext , locDirect = [ ] , locIndex = [ ] ;
var extensions = moduleNativeExtensions . concat ( Object . keys ( extensionCache ) ) ;
var ext ;
var extensions = Object . keys ( extensionCache ) ;
for ( var i = 0 , l = extensions . length ; i < l ; i ++ ) {
var ext = extensions [ i ] ;
locations . push ( path . join ( dir , id + ext ) ) ;
locations . push ( path . join ( dir , id , 'index' + ext ) ) ;
ext = extensions [ i ] ;
locDirect . push ( path . join ( dir , id + '.' + ext ) ) ;
locIndex . push ( path . join ( dir , id , 'index.' + ext ) ) ;
}
var locations = [ path . join ( dir , id ) ] . concat ( locDirect ) . concat ( locIndex ) ;
var fs = requireNative ( 'fs' ) ;
function searchLocations ( ) {
@ -192,12 +183,7 @@ function resolveModulePath(request, parent) {
if ( request . charAt ( 0 ) == "." && ( request . charAt ( 1 ) == "/" || request . charAt ( 1 ) == "." ) ) {
// Relative request
var exts = [ 'js' , 'node' ] , ext ;
var extensions = Object . keys ( extensionCache ) ;
for ( var i = 0 , l = extensions . length ; i < l ; i ++ ) {
var ext = extensions [ i ] ;
exts . push ( ext . slice ( 1 ) ) ;
}
var exts = moduleNativeExtensions . concat ( Object . keys ( extensionCache ) ) ;
var parentIdPath = path . dirname ( parent . id +
( path . basename ( parent . filename ) . match ( new RegExp ( '^index\\.(' + exts . join ( '|' ) + ')$' ) ) ? "/." : "" ) ) ;
@ -293,7 +279,7 @@ function registerExtension(ext, compiler) {
throw new Error ( 'require.registerExtension: Second argument not a valid compiler function.' ) ;
}
extensionCache [ ext ] = compiler ;
extensionCache [ ext . slice ( 1 ) ] = compiler ;
}
@ -364,7 +350,7 @@ Module.prototype._compile = function (content, filename) {
content = content . replace ( /^\#\!.*/ , '' ) ;
// Compile content if needed
var ext = path . extname ( filename ) ;
var ext = path . extname ( filename ) . slice ( 1 ) ;
if ( extensionCache [ ext ] ) {
content = extensionCache [ ext ] ( content ) ;
}