@@ -1353,23 +1353,31 @@ 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
- }
1371
- catch ( e ) {
1372
- continue ;
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
+ }
1379
+ } else {
1380
+ stat = dirent ;
1373
1381
}
1374
1382
1375
1383
if ( stat . isFile ( ) ) {
@@ -1379,6 +1387,8 @@ namespace ts {
1379
1387
directories . push ( entry ) ;
1380
1388
}
1381
1389
}
1390
+ files . sort ( ) ;
1391
+ directories . sort ( ) ;
1382
1392
return { files, directories } ;
1383
1393
}
1384
1394
catch ( e ) {
@@ -1413,8 +1423,7 @@ namespace ts {
1413
1423
}
1414
1424
1415
1425
function getDirectories ( path : string ) : string [ ] {
1416
- perfLogger . logEvent ( "ReadDir: " + path ) ;
1417
- return filter < string > ( _fs . readdirSync ( path ) , dir => fileSystemEntryExists ( combinePaths ( path , dir ) , FileSystemEntryKind . Directory ) ) ;
1426
+ return getAccessibleFileSystemEntries ( path ) . directories . slice ( ) ;
1418
1427
}
1419
1428
1420
1429
function realpath ( path : string ) : string {
0 commit comments