@@ -9,29 +9,27 @@ const path = require("path");
99class RequestShortener {
1010 constructor ( directory ) {
1111 directory = directory . replace ( / \\ / g, "/" ) ;
12- let parentDirectory = path . dirname ( directory ) ;
1312 if ( / [ \/ \\ ] $ / . test ( directory ) ) directory = directory . substr ( 0 , directory . length - 1 ) ;
1413
1514 if ( directory ) {
16- let currentDirectoryRegExp = directory . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
17- currentDirectoryRegExp = new RegExp ( "^" + currentDirectoryRegExp + "|(!)" + currentDirectoryRegExp , "g" ) ;
18- this . currentDirectoryRegExp = currentDirectoryRegExp ;
15+ const currentDirectoryRegExpString = directory . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
16+ this . currentDirectoryRegExp = new RegExp ( "^" + currentDirectoryRegExpString + "|(!)" + currentDirectoryRegExpString , "g" ) ;
1917 }
2018
21- if ( / [ \/ \\ ] $ / . test ( parentDirectory ) ) parentDirectory = parentDirectory . substr ( 0 , parentDirectory . length - 1 ) ;
19+ const dirname = path . dirname ( directory ) ;
20+ const endsWithSeperator = / [ \/ \\ ] $ / . test ( dirname ) ;
21+ const parentDirectory = endsWithSeperator ? dirname . substr ( 0 , dirname . length - 1 ) : dirname ;
2222 if ( parentDirectory && parentDirectory !== directory ) {
23- let parentDirectoryRegExp = parentDirectory . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
24- parentDirectoryRegExp = new RegExp ( "^" + parentDirectoryRegExp + "|(!)" + parentDirectoryRegExp , "g" ) ;
25- this . parentDirectoryRegExp = parentDirectoryRegExp ;
23+ const parentDirectoryRegExpString = parentDirectory . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
24+ this . parentDirectoryRegExp = new RegExp ( "^" + parentDirectoryRegExpString + "|(!)" + parentDirectoryRegExpString , "g" ) ;
2625 }
2726
2827 if ( __dirname . length >= 2 ) {
29- let buildins = path . join ( __dirname , ".." ) . replace ( / \\ / g, "/" ) ;
30- let buildinsAsModule = this . currentDirectoryRegExp && this . currentDirectoryRegExp . test ( buildins ) ;
31- let buildinsRegExp = buildins . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
32- buildinsRegExp = new RegExp ( "^" + buildinsRegExp + "|(!)" + buildinsRegExp , "g" ) ;
28+ const buildins = path . join ( __dirname , ".." ) . replace ( / \\ / g, "/" ) ;
29+ const buildinsAsModule = this . currentDirectoryRegExp && this . currentDirectoryRegExp . test ( buildins ) ;
3330 this . buildinsAsModule = buildinsAsModule ;
34- this . buildinsRegExp = buildinsRegExp ;
31+ const buildinsRegExpString = buildins . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
32+ this . buildinsRegExp = new RegExp ( "^" + buildinsRegExpString + "|(!)" + buildinsRegExpString , "g" ) ;
3533 }
3634
3735 this . nodeModulesRegExp = / \/ n o d e _ m o d u l e s \/ / g;
0 commit comments