@@ -722,18 +722,8 @@ Module._findPath = function(request, paths, isMain, conditions = getCjsCondition
722
722
)
723
723
) ) ;
724
724
725
- const isRelative = StringPrototypeCharCodeAt ( request , 0 ) === CHAR_DOT &&
726
- (
727
- request . length === 1 ||
728
- StringPrototypeCharCodeAt ( request , 1 ) === CHAR_FORWARD_SLASH ||
729
- ( isWindows && StringPrototypeCharCodeAt ( request , 1 ) === CHAR_BACKWARD_SLASH ) ||
730
- ( StringPrototypeCharCodeAt ( request , 1 ) === CHAR_DOT && ( (
731
- request . length === 2 ||
732
- StringPrototypeCharCodeAt ( request , 2 ) === CHAR_FORWARD_SLASH ) ||
733
- ( isWindows && StringPrototypeCharCodeAt ( request , 2 ) === CHAR_BACKWARD_SLASH ) ) )
734
- ) ;
735
725
let insidePath = true ;
736
- if ( isRelative ) {
726
+ if ( isRelative ( request ) ) {
737
727
const normalizedRequest = path . normalize ( request ) ;
738
728
if ( StringPrototypeStartsWith ( normalizedRequest , '..' ) ) {
739
729
insidePath = false ;
@@ -1328,12 +1318,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
1328
1318
1329
1319
if ( typeof options === 'object' && options !== null ) {
1330
1320
if ( ArrayIsArray ( options . paths ) ) {
1331
- const isRelative = StringPrototypeStartsWith ( request , './' ) ||
1332
- StringPrototypeStartsWith ( request , '../' ) ||
1333
- ( ( isWindows && StringPrototypeStartsWith ( request , '.\\' ) ) ||
1334
- StringPrototypeStartsWith ( request , '..\\' ) ) ;
1335
-
1336
- if ( isRelative ) {
1321
+ if ( isRelative ( request ) ) {
1337
1322
paths = options . paths ;
1338
1323
} else {
1339
1324
const fakeParent = new Module ( '' , null ) ;
@@ -1978,6 +1963,21 @@ function createRequire(filename) {
1978
1963
return createRequireFromPath ( filepath ) ;
1979
1964
}
1980
1965
1966
+ /**
1967
+ * Checks if a path is relative
1968
+ * @param {string } path the target path
1969
+ * @returns {boolean } true if the path is relative, false otherwise
1970
+ */
1971
+ function isRelative ( path ) {
1972
+ if ( StringPrototypeCharCodeAt ( path , 0 ) !== CHAR_DOT ) { return false ; }
1973
+
1974
+ return path === '.' || path === '..' ||
1975
+ StringPrototypeStartsWith ( path , './' ) ||
1976
+ StringPrototypeStartsWith ( path , '../' ) ||
1977
+ ( ( isWindows && StringPrototypeStartsWith ( path , '.\\' ) ) ||
1978
+ StringPrototypeStartsWith ( path , '..\\' ) ) ;
1979
+ }
1980
+
1981
1981
Module . createRequire = createRequire ;
1982
1982
1983
1983
/**
0 commit comments