@@ -8,6 +8,10 @@ var isCore = require('is-core-module');
88
99var realpathFS = process . platform !== 'win32' && fs . realpath && typeof fs . realpath . native === 'function' ? fs . realpath . native : fs . realpath ;
1010
11+ var relativePathRegex = / ^ (?: \. \. ? (?: \/ | $ ) | \/ | ( [ A - Z a - z ] : ) ? [ / \\ ] ) / ;
12+ var windowsDriveRegex = / ^ \w : [ / \\ ] * $ / ;
13+ var nodeModulesRegex = / [ / \\ ] n o d e _ m o d u l e s [ / \\ ] * $ / ;
14+
1115var homedir = getHomedir ( ) ;
1216var defaultPaths = function ( ) {
1317 return [
@@ -124,10 +128,10 @@ module.exports = function resolve(x, options, callback) {
124128
125129 var res ;
126130 function init ( basedir ) {
127- if ( ( / ^ (?: \. \. ? (?: \/ | $ ) | \/ | ( [ A - Z a - z ] : ) ? [ / \\ ] ) / ) . test ( x ) ) {
131+ if ( relativePathRegex . test ( x ) ) {
128132 res = path . resolve ( basedir , x ) ;
129133 if ( x === '.' || x === '..' || x . slice ( - 1 ) === '/' ) res += '/' ;
130- if ( ( / \/ $ / ) . test ( x ) && res === basedir ) {
134+ if ( x . slice ( - 1 ) === '/' && res === basedir ) {
131135 loadAsDirectory ( res , opts . package , onfile ) ;
132136 } else loadAsFile ( res , opts . package , onfile ) ;
133137 } else if ( includeCoreModules && isCore ( x ) ) {
@@ -215,10 +219,10 @@ module.exports = function resolve(x, options, callback) {
215219
216220 function loadpkg ( dir , cb ) {
217221 if ( dir === '' || dir === '/' ) return cb ( null ) ;
218- if ( process . platform === 'win32' && ( / ^ \w : [ / \\ ] * $ / ) . test ( dir ) ) {
222+ if ( process . platform === 'win32' && windowsDriveRegex . test ( dir ) ) {
219223 return cb ( null ) ;
220224 }
221- if ( ( / [ / \\ ] n o d e _ m o d u l e s [ / \\ ] * $ / ) . test ( dir ) ) return cb ( null ) ;
225+ if ( nodeModulesRegex . test ( dir ) ) return cb ( null ) ;
222226
223227 maybeRealpath ( realpath , dir , opts , function ( unwrapErr , pkgdir ) {
224228 if ( unwrapErr ) return loadpkg ( path . dirname ( dir ) , cb ) ;
0 commit comments