@@ -1353,23 +1353,32 @@ namespace ts {
1353
1353
function getAccessibleFileSystemEntries ( path : string ) : FileSystemEntries {
1354
1354
perfLogger . logEvent ( "ReadDir: " + ( path || "." ) ) ;
1355
1355
try {
1356
- const entries = _fs . readdirSync ( path || "." ) . sort ( ) ;
1356
+ const entries = _fs . readdirSync ( path || "." , { withFileTypes : true } ) ;
1357
1357
const files : string [ ] = [ ] ;
1358
1358
const directories : string [ ] = [ ] ;
1359
- for ( const entry of entries ) {
1359
+ for ( const dirent of entries ) {
1360
+ // withFileTypes is not supported before Node 10.10.
1361
+ const entry = typeof dirent === "string" ? dirent : dirent . name ;
1362
+
1360
1363
// This is necessary because on some file system node fails to exclude
1361
1364
// "." and "..". See https://github.com/nodejs/node/issues/4002
1362
1365
if ( entry === "." || entry === ".." ) {
1363
1366
continue ;
1364
1367
}
1365
- const name = combinePaths ( path , entry ) ;
1366
1368
1367
1369
let stat : any ;
1368
- try {
1369
- stat = _fs . statSync ( name ) ;
1370
+ if ( typeof dirent === "string" || dirent . isSymbolicLink ( ) ) {
1371
+ const name = combinePaths ( path , entry ) ;
1372
+
1373
+ try {
1374
+ stat = _fs . statSync ( name ) ;
1375
+ }
1376
+ catch ( e ) {
1377
+ continue ;
1378
+ }
1370
1379
}
1371
- catch ( e ) {
1372
- continue ;
1380
+ else {
1381
+ stat = dirent ;
1373
1382
}
1374
1383
1375
1384
if ( stat . isFile ( ) ) {
@@ -1379,6 +1388,8 @@ namespace ts {
1379
1388
directories . push ( entry ) ;
1380
1389
}
1381
1390
}
1391
+ files . sort ( ) ;
1392
+ directories . sort ( ) ;
1382
1393
return { files, directories } ;
1383
1394
}
1384
1395
catch ( e ) {
@@ -1413,8 +1424,7 @@ namespace ts {
1413
1424
}
1414
1425
1415
1426
function getDirectories ( path : string ) : string [ ] {
1416
- perfLogger . logEvent ( "ReadDir: " + path ) ;
1417
- return filter < string > ( _fs . readdirSync ( path ) , dir => fileSystemEntryExists ( combinePaths ( path , dir ) , FileSystemEntryKind . Directory ) ) ;
1427
+ return getAccessibleFileSystemEntries ( path ) . directories . slice ( ) ;
1418
1428
}
1419
1429
1420
1430
function realpath ( path : string ) : string {
0 commit comments