@ -326,14 +326,14 @@ if (process.platform === 'win32') {
// 'index.' character codes
// 'index.' character codes
var indexChars = [ 105 , 110 , 100 , 101 , 120 , 46 ] ;
var indexChars = [ 105 , 110 , 100 , 101 , 120 , 46 ] ;
var indexLen = indexChars . length ;
var indexLen = indexChars . length ;
Module . _ resolveLookupPaths = function ( request , parent ) {
Module . _ resolveLookupPaths = function ( request , parent , newReturn ) {
if ( NativeModule . nonInternalExists ( request ) ) {
if ( NativeModule . nonInternalExists ( request ) ) {
return [ request , [ ] ] ;
debug ( 'looking for %j in []' , request ) ;
return ( newReturn ? null : [ request , [ ] ] ) ;
}
}
var reqLen = request . length ;
// Check for relative path
// Check for relative path
if ( reqLen < 2 ||
if ( request . length < 2 ||
request . charCodeAt ( 0 ) !== 46 /*.*/ ||
request . charCodeAt ( 0 ) !== 46 /*.*/ ||
( request . charCodeAt ( 1 ) !== 46 /*.*/ &&
( request . charCodeAt ( 1 ) !== 46 /*.*/ &&
request . charCodeAt ( 1 ) !== 47 /*/*/ ) ) {
request . charCodeAt ( 1 ) !== 47 /*/*/ ) ) {
@ -355,7 +355,8 @@ Module._resolveLookupPaths = function(request, parent) {
}
}
}
}
return [ request , paths ] ;
debug ( 'looking for %j in %j' , request , paths ) ;
return ( newReturn ? ( paths . length > 0 ? paths : null ) : [ request , paths ] ) ;
}
}
// with --eval, parent.id is not set and parent.filename is null
// with --eval, parent.id is not set and parent.filename is null
@ -363,7 +364,9 @@ Module._resolveLookupPaths = function(request, parent) {
// make require('./path/to/foo') work - normally the path is taken
// make require('./path/to/foo') work - normally the path is taken
// from realpath(__filename) but with eval there is no filename
// from realpath(__filename) but with eval there is no filename
var mainPaths = [ '.' ] . concat ( Module . _ nodeModulePaths ( '.' ) , modulePaths ) ;
var mainPaths = [ '.' ] . concat ( Module . _ nodeModulePaths ( '.' ) , modulePaths ) ;
return [ request , mainPaths ] ;
debug ( 'looking for %j in %j' , request , mainPaths ) ;
return ( newReturn ? mainPaths : [ request , mainPaths ] ) ;
}
}
// Is the parent an index module?
// Is the parent an index module?
@ -413,7 +416,9 @@ Module._resolveLookupPaths = function(request, parent) {
debug ( 'RELATIVE: requested: %s set ID to: %s from %s' , request , id ,
debug ( 'RELATIVE: requested: %s set ID to: %s from %s' , request , id ,
parent . id ) ;
parent . id ) ;
return [ id , [ path . dirname ( parent . filename ) ] ] ;
var parentDir = [ path . dirname ( parent . filename ) ] ;
debug ( 'looking for %j in %j' , id , parentDir ) ;
return ( newReturn ? parentDir : [ id , parentDir ] ) ;
} ;
} ;
@ -472,16 +477,12 @@ Module._resolveFilename = function(request, parent, isMain) {
return request ;
return request ;
}
}
var resolvedModule = Module . _ resolveLookupPaths ( request , parent ) ;
var paths = Module . _ resolveLookupPaths ( request , parent , true ) ;
var id = resolvedModule [ 0 ] ;
var paths = resolvedModule [ 1 ] ;
// look up the filename first, since that's the cache key.
// look up the filename first, since that's the cache key.
debug ( 'looking for %j in %j' , id , paths ) ;
var filename = Module . _ findPath ( request , paths , isMain ) ;
var filename = Module . _ findPath ( request , paths , isMain ) ;
if ( ! filename ) {
if ( ! filename ) {
var err = new Error ( "Cannot find module '" + request + "'" ) ;
var err = new Error ( ` Cannot find module ' ${ request } ' ` ) ;
err . code = 'MODULE_NOT_FOUND' ;
err . code = 'MODULE_NOT_FOUND' ;
throw err ;
throw err ;
}
}
@ -564,7 +565,7 @@ Module.prototype._compile = function(content, filename) {
if ( ! resolvedArgv ) {
if ( ! resolvedArgv ) {
// we enter the repl if we're not given a filename argument.
// we enter the repl if we're not given a filename argument.
if ( process . argv [ 1 ] ) {
if ( process . argv [ 1 ] ) {
resolvedArgv = Module . _ resolveFilename ( process . argv [ 1 ] , null ) ;
resolvedArgv = Module . _ resolveFilename ( process . argv [ 1 ] , null , false ) ;
} else {
} else {
resolvedArgv = 'repl' ;
resolvedArgv = 'repl' ;
}
}