@@ -158,7 +158,7 @@ Module.builtinModules = builtinModules;
158
158
Module . _cache = Object . create ( null ) ;
159
159
Module . _pathCache = Object . create ( null ) ;
160
160
Module . _extensions = Object . create ( null ) ;
161
- var modulePaths = [ ] ;
161
+ let modulePaths = [ ] ;
162
162
Module . globalPaths = [ ] ;
163
163
164
164
let patched = false ;
@@ -347,7 +347,7 @@ function toRealPath(requestPath) {
347
347
348
348
// Given a path, check if the file exists with any of the set extensions
349
349
function tryExtensions ( p , exts , isMain ) {
350
- for ( var i = 0 ; i < exts . length ; i ++ ) {
350
+ for ( let i = 0 ; i < exts . length ; i ++ ) {
351
351
const filename = tryFile ( p + exts [ i ] , isMain ) ;
352
352
353
353
if ( filename ) {
@@ -625,22 +625,22 @@ Module._findPath = function(request, paths, isMain) {
625
625
if ( entry )
626
626
return entry ;
627
627
628
- var exts ;
629
- var trailingSlash = request . length > 0 &&
628
+ let exts ;
629
+ let trailingSlash = request . length > 0 &&
630
630
request . charCodeAt ( request . length - 1 ) === CHAR_FORWARD_SLASH ;
631
631
if ( ! trailingSlash ) {
632
632
trailingSlash = / (?: ^ | \/ ) \. ? \. $ / . test ( request ) ;
633
633
}
634
634
635
635
// For each path
636
- for ( var i = 0 ; i < paths . length ; i ++ ) {
636
+ for ( let i = 0 ; i < paths . length ; i ++ ) {
637
637
// Don't search further if path doesn't exist
638
638
const curPath = paths [ i ] ;
639
639
if ( curPath && stat ( curPath ) < 1 ) continue ;
640
- var basePath = resolveExports ( curPath , request , absoluteRequest ) ;
641
- var filename ;
640
+ const basePath = resolveExports ( curPath , request , absoluteRequest ) ;
641
+ let filename ;
642
642
643
- var rc = stat ( basePath ) ;
643
+ const rc = stat ( basePath ) ;
644
644
if ( ! trailingSlash ) {
645
645
if ( rc === 0 ) { // File.
646
646
if ( ! isMain ) {
@@ -714,9 +714,7 @@ if (isWindows) {
714
714
return [ from + 'node_modules' ] ;
715
715
716
716
const paths = [ ] ;
717
- var p = 0 ;
718
- var last = from . length ;
719
- for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
717
+ for ( let i = from . length - 1 , p = 0 , last = from . length ; i >= 0 ; -- i ) {
720
718
const code = from . charCodeAt ( i ) ;
721
719
// The path segment separator check ('\' and '/') was used to get
722
720
// node_modules path for every path segment.
@@ -755,9 +753,7 @@ if (isWindows) {
755
753
// to be absolute. Doing a fully-edge-case-correct path.split
756
754
// that works on both Windows and Posix is non-trivial.
757
755
const paths = [ ] ;
758
- var p = 0 ;
759
- var last = from . length ;
760
- for ( var i = from . length - 1 ; i >= 0 ; -- i ) {
756
+ for ( let i = from . length - 1 , p = 0 , last = from . length ; i >= 0 ; -- i ) {
761
757
const code = from . charCodeAt ( i ) ;
762
758
if ( code === CHAR_FORWARD_SLASH ) {
763
759
if ( p !== nmLen )
@@ -956,7 +952,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
956
952
return request ;
957
953
}
958
954
959
- var paths ;
955
+ let paths ;
960
956
961
957
if ( typeof options === 'object' && options !== null ) {
962
958
if ( Array . isArray ( options . paths ) ) {
@@ -972,12 +968,12 @@ Module._resolveFilename = function(request, parent, isMain, options) {
972
968
973
969
paths = [ ] ;
974
970
975
- for ( var i = 0 ; i < options . paths . length ; i ++ ) {
971
+ for ( let i = 0 ; i < options . paths . length ; i ++ ) {
976
972
const path = options . paths [ i ] ;
977
973
fakeParent . paths = Module . _nodeModulePaths ( path ) ;
978
974
const lookupPaths = Module . _resolveLookupPaths ( request , fakeParent ) ;
979
975
980
- for ( var j = 0 ; j < lookupPaths . length ; j ++ ) {
976
+ for ( let j = 0 ; j < lookupPaths . length ; j ++ ) {
981
977
if ( ! paths . includes ( lookupPaths [ j ] ) )
982
978
paths . push ( lookupPaths [ j ] ) ;
983
979
}
@@ -996,7 +992,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
996
992
const filename = Module . _findPath ( request , paths , isMain ) ;
997
993
if ( ! filename ) {
998
994
const requireStack = [ ] ;
999
- for ( var cursor = parent ;
995
+ for ( let cursor = parent ;
1000
996
cursor ;
1001
997
cursor = cursor . parent ) {
1002
998
requireStack . push ( cursor . filename || cursor . id ) ;
@@ -1006,7 +1002,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
1006
1002
message = message + '\nRequire stack:\n- ' + requireStack . join ( '\n- ' ) ;
1007
1003
}
1008
1004
// eslint-disable-next-line no-restricted-syntax
1009
- var err = new Error ( message ) ;
1005
+ const err = new Error ( message ) ;
1010
1006
err . code = 'MODULE_NOT_FOUND' ;
1011
1007
err . requireStack = requireStack ;
1012
1008
throw err ;
@@ -1077,7 +1073,7 @@ Module.prototype.require = function(id) {
1077
1073
1078
1074
// Resolved path to process.argv[1] will be lazily placed here
1079
1075
// (needed for setting breakpoint when called with --inspect-brk)
1080
- var resolvedArgv ;
1076
+ let resolvedArgv ;
1081
1077
let hasPausedEntry = false ;
1082
1078
1083
1079
function wrapSafe ( filename , content , cjsModuleInstance ) {
@@ -1145,7 +1141,7 @@ Module.prototype._compile = function(content, filename) {
1145
1141
maybeCacheSourceMap ( filename , content , this ) ;
1146
1142
const compiledWrapper = wrapSafe ( filename , content , this ) ;
1147
1143
1148
- var inspectorWrapper = null ;
1144
+ let inspectorWrapper = null ;
1149
1145
if ( getOptionValue ( '--inspect-brk' ) && process . _eval == null ) {
1150
1146
if ( ! resolvedArgv ) {
1151
1147
// We enter the repl if we're not given a filename argument.
@@ -1164,7 +1160,7 @@ Module.prototype._compile = function(content, filename) {
1164
1160
}
1165
1161
const dirname = path . dirname ( filename ) ;
1166
1162
const require = makeRequireFunction ( this , redirects ) ;
1167
- var result ;
1163
+ let result ;
1168
1164
const exports = this . exports ;
1169
1165
const thisValue = exports ;
1170
1166
const module = this ;
@@ -1303,26 +1299,16 @@ function createRequire(filename) {
1303
1299
Module . createRequire = createRequire ;
1304
1300
1305
1301
Module . _initPaths = function ( ) {
1306
- var homeDir ;
1307
- var nodePath ;
1308
- if ( isWindows ) {
1309
- homeDir = process . env . USERPROFILE ;
1310
- nodePath = process . env . NODE_PATH ;
1311
- } else {
1312
- homeDir = safeGetenv ( 'HOME' ) ;
1313
- nodePath = safeGetenv ( 'NODE_PATH' ) ;
1314
- }
1302
+ const homeDir = isWindows ? process . env . USERPROFILE : safeGetenv ( 'HOME' ) ;
1303
+ const nodePath = isWindows ? process . env . NODE_PATH : safeGetenv ( 'NODE_PATH' ) ;
1315
1304
1316
- // $PREFIX/lib/node, where $PREFIX is the root of the Node.js installation.
1317
- var prefixDir ;
1318
1305
// process.execPath is $PREFIX/bin/node except on Windows where it is
1319
- // $PREFIX\node.exe.
1320
- if ( isWindows ) {
1321
- prefixDir = path . resolve ( process . execPath , '..' ) ;
1322
- } else {
1323
- prefixDir = path . resolve ( process . execPath , '..' , '..' ) ;
1324
- }
1325
- var paths = [ path . resolve ( prefixDir , 'lib' , 'node' ) ] ;
1306
+ // $PREFIX\node.exe where $PREFIX is the root of the Node.js installation.
1307
+ const prefixDir = isWindows ?
1308
+ path . resolve ( process . execPath , '..' ) :
1309
+ path . resolve ( process . execPath , '..' , '..' ) ;
1310
+
1311
+ let paths = [ path . resolve ( prefixDir , 'lib' , 'node' ) ] ;
1326
1312
1327
1313
if ( homeDir ) {
1328
1314
paths . unshift ( path . resolve ( homeDir , '.node_libraries' ) ) ;
@@ -1356,7 +1342,7 @@ Module._preloadModules = function(requests) {
1356
1342
throw e ;
1357
1343
}
1358
1344
}
1359
- for ( var n = 0 ; n < requests . length ; n ++ )
1345
+ for ( let n = 0 ; n < requests . length ; n ++ )
1360
1346
parent . require ( requests [ n ] ) ;
1361
1347
} ;
1362
1348
0 commit comments