@@ -8,18 +8,15 @@ const path = require("path");
88const NORMALIZE_SLASH_DIRECTION_REGEXP = / \\ / g;
99const PATH_CHARS_REGEXP = / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g;
1010const SEPERATOR_REGEXP = / [ \/ \\ ] $ / ;
11- const FRONT_OR_BACK_BANG_REGEXP = / ^ ! | ! $ / ;
11+ const FRONT_OR_BACK_BANG_REGEXP = / ^ ! | ! $ / g ;
1212
1313const normalizeBackSlashDirection = ( request ) => {
1414 return request . replace ( NORMALIZE_SLASH_DIRECTION_REGEXP , "/" ) ;
1515} ;
1616
17- const shortenPath = ( path ) => {
18- return path . replace ( PATH_CHARS_REGEXP , "\\$&" ) ;
19- } ;
20-
21- const createRegExpForTypeWith = ( regexpTypePartial ) => {
22- return new RegExp ( `^${ regexpTypePartial } |(!)${ regexpTypePartial } ` , "g" ) ;
17+ const createRegExpForPath = ( path ) => {
18+ const regexpTypePartial = path . replace ( PATH_CHARS_REGEXP , "\\$&" ) ;
19+ return new RegExp ( `(^|!)${ regexpTypePartial } ` , "g" ) ;
2320} ;
2421
2522class RequestShortener {
@@ -28,24 +25,21 @@ class RequestShortener {
2825 if ( SEPERATOR_REGEXP . test ( directory ) ) directory = directory . substr ( 0 , directory . length - 1 ) ;
2926
3027 if ( directory ) {
31- const currentDirectoryRegExpString = shortenPath ( directory ) ;
32- this . currentDirectoryRegExp = createRegExpForTypeWith ( currentDirectoryRegExpString ) ;
28+ this . currentDirectoryRegExp = createRegExpForPath ( directory ) ;
3329 }
3430
3531 const dirname = path . dirname ( directory ) ;
3632 const endsWithSeperator = SEPERATOR_REGEXP . test ( dirname ) ;
3733 const parentDirectory = endsWithSeperator ? dirname . substr ( 0 , dirname . length - 1 ) : dirname ;
3834 if ( parentDirectory && parentDirectory !== directory ) {
39- const parentDirectoryRegExpString = shortenPath ( parentDirectory ) ;
40- this . parentDirectoryRegExp = createRegExpForTypeWith ( parentDirectoryRegExpString ) ;
35+ this . parentDirectoryRegExp = createRegExpForPath ( parentDirectory ) ;
4136 }
4237
4338 if ( __dirname . length >= 2 ) {
4439 const buildins = normalizeBackSlashDirection ( path . join ( __dirname , ".." ) ) ;
4540 const buildinsAsModule = this . currentDirectoryRegExp && this . currentDirectoryRegExp . test ( buildins ) ;
4641 this . buildinsAsModule = buildinsAsModule ;
47- const buildinsRegExpString = shortenPath ( buildins ) ;
48- this . buildinsRegExp = createRegExpForTypeWith ( buildinsRegExpString ) ;
42+ this . buildinsRegExp = createRegExpForPath ( buildins ) ;
4943 }
5044
5145 this . indexJsRegExp = / \/ i n d e x .j s ( ! | \? | \( q u e r y \) ) / g;
0 commit comments