@@ -1617,23 +1617,32 @@ namespace ts {
1617
1617
function getAccessibleFileSystemEntries ( path : string ) : FileSystemEntries {
1618
1618
perfLogger . logEvent ( "ReadDir: " + ( path || "." ) ) ;
1619
1619
try {
1620
- const entries = _fs . readdirSync ( path || "." ) . sort ( ) ;
1620
+ const entries = _fs . readdirSync ( path || "." , { withFileTypes : true } ) ;
1621
1621
const files : string [ ] = [ ] ;
1622
1622
const directories : string [ ] = [ ] ;
1623
- for ( const entry of entries ) {
1623
+ for ( const dirent of entries ) {
1624
+ // withFileTypes is not supported before Node 10.10.
1625
+ const entry = typeof dirent === "string" ? dirent : dirent . name ;
1626
+
1624
1627
// This is necessary because on some file system node fails to exclude
1625
1628
// "." and "..". See https://github.com/nodejs/node/issues/4002
1626
1629
if ( entry === "." || entry === ".." ) {
1627
1630
continue ;
1628
1631
}
1629
- const name = combinePaths ( path , entry ) ;
1630
1632
1631
1633
let stat : any ;
1632
- try {
1633
- stat = _fs . statSync ( name ) ;
1634
+ if ( typeof dirent === "string" || dirent . isSymbolicLink ( ) ) {
1635
+ const name = combinePaths ( path , entry ) ;
1636
+
1637
+ try {
1638
+ stat = _fs . statSync ( name ) ;
1639
+ }
1640
+ catch ( e ) {
1641
+ continue ;
1642
+ }
1634
1643
}
1635
- catch ( e ) {
1636
- continue ;
1644
+ else {
1645
+ stat = dirent ;
1637
1646
}
1638
1647
1639
1648
if ( stat . isFile ( ) ) {
@@ -1643,6 +1652,8 @@ namespace ts {
1643
1652
directories . push ( entry ) ;
1644
1653
}
1645
1654
}
1655
+ files . sort ( ) ;
1656
+ directories . sort ( ) ;
1646
1657
return { files, directories } ;
1647
1658
}
1648
1659
catch ( e ) {
@@ -1677,8 +1688,7 @@ namespace ts {
1677
1688
}
1678
1689
1679
1690
function getDirectories ( path : string ) : string [ ] {
1680
- perfLogger . logEvent ( "ReadDir: " + path ) ;
1681
- return filter < string > ( _fs . readdirSync ( path ) , dir => fileSystemEntryExists ( combinePaths ( path , dir ) , FileSystemEntryKind . Directory ) ) ;
1691
+ return getAccessibleFileSystemEntries ( path ) . directories . slice ( ) ;
1682
1692
}
1683
1693
1684
1694
function realpath ( path : string ) : string {
0 commit comments