@@ -722,18 +722,8 @@ Module._findPath = function(request, paths, isMain, conditions = getCjsCondition
722722 )
723723 ) ) ;
724724
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- ) ;
735725 let insidePath = true ;
736- if ( isRelative ) {
726+ if ( isRelative ( request ) ) {
737727 const normalizedRequest = path . normalize ( request ) ;
738728 if ( StringPrototypeStartsWith ( normalizedRequest , '..' ) ) {
739729 insidePath = false ;
@@ -1328,12 +1318,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
13281318
13291319 if ( typeof options === 'object' && options !== null ) {
13301320 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 ) ) {
13371322 paths = options . paths ;
13381323 } else {
13391324 const fakeParent = new Module ( '' , null ) ;
@@ -1978,6 +1963,19 @@ function createRequire(filename) {
19781963 return createRequireFromPath ( filepath ) ;
19791964}
19801965
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+ return path === '.' || path === '..' ||
1973+ StringPrototypeStartsWith ( path , './' ) ||
1974+ StringPrototypeStartsWith ( path , '../' ) ||
1975+ ( ( isWindows && StringPrototypeStartsWith ( path , '.\\' ) ) ||
1976+ StringPrototypeStartsWith ( path , '..\\' ) ) ;
1977+ }
1978+
19811979Module . createRequire = createRequire ;
19821980
19831981/**
0 commit comments