@@ -80,6 +80,8 @@ const {
80
80
CHAR_9 ,
81
81
} = require ( 'internal/constants' ) ;
82
82
83
+ const isWindows = process . platform === 'win32' ;
84
+
83
85
function stat ( filename ) {
84
86
filename = path . toNamespacedPath ( filename ) ;
85
87
const cache = stat . cache ;
@@ -310,7 +312,7 @@ Module._findPath = function(request, paths, isMain) {
310
312
// 'node_modules' character codes reversed
311
313
var nmChars = [ 115 , 101 , 108 , 117 , 100 , 111 , 109 , 95 , 101 , 100 , 111 , 110 ] ;
312
314
var nmLen = nmChars . length ;
313
- if ( process . platform === 'win32' ) {
315
+ if ( isWindows ) {
314
316
// 'from' is the __dirname of the module.
315
317
Module . _nodeModulePaths = function ( from ) {
316
318
// guarantee that 'from' is absolute.
@@ -403,11 +405,12 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
403
405
return ( newReturn ? null : [ request , [ ] ] ) ;
404
406
}
405
407
406
- // Check for relative path
408
+ // Check for non- relative path
407
409
if ( request . length < 2 ||
408
410
request . charCodeAt ( 0 ) !== CHAR_DOT ||
409
411
( request . charCodeAt ( 1 ) !== CHAR_DOT &&
410
- request . charCodeAt ( 1 ) !== CHAR_FORWARD_SLASH ) ) {
412
+ request . charCodeAt ( 1 ) !== CHAR_FORWARD_SLASH &&
413
+ ( ! isWindows || request . charCodeAt ( 1 ) !== CHAR_BACKWARD_SLASH ) ) ) {
411
414
var paths = modulePaths ;
412
415
if ( parent ) {
413
416
if ( ! parent . paths )
@@ -480,7 +483,9 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
480
483
481
484
// make sure require('./path') and require('path') get distinct ids, even
482
485
// when called from the toplevel js file
483
- if ( parentIdPath === '.' && id . indexOf ( '/' ) === - 1 ) {
486
+ if ( parentIdPath === '.' &&
487
+ id . indexOf ( '/' ) === - 1 &&
488
+ ( ! isWindows || id . indexOf ( '\\' ) === - 1 ) ) {
484
489
id = './' + id ;
485
490
}
486
491
@@ -746,8 +751,6 @@ Module.runMain = function() {
746
751
} ;
747
752
748
753
Module . _initPaths = function ( ) {
749
- const isWindows = process . platform === 'win32' ;
750
-
751
754
var homeDir ;
752
755
var nodePath ;
753
756
if ( isWindows ) {
0 commit comments