@@ -1271,8 +1271,8 @@ namespace ts {
1271
1271
} ,
1272
1272
getFileSize ( path ) {
1273
1273
try {
1274
- const stat = _fs . statSync ( path ) ;
1275
- if ( stat . isFile ( ) ) {
1274
+ const stat = statSync ( path ) ;
1275
+ if ( stat ? .isFile ( ) ) {
1276
1276
return stat . size ;
1277
1277
}
1278
1278
}
@@ -1319,6 +1319,16 @@ namespace ts {
1319
1319
} ;
1320
1320
return nodeSystem ;
1321
1321
1322
+ /**
1323
+ * `throwIfNoEntry` was added so recently that it's not in the node types.
1324
+ * This helper encapsulates the mitigating usage of `any`.
1325
+ * See https://github.com/nodejs/node/pull/33716
1326
+ */
1327
+ function statSync ( path : string ) : import ( "fs" ) . Stats | undefined {
1328
+ // throwIfNoEntry will be ignored by older versions of node
1329
+ return ( _fs as any ) . statSync ( path , { throwIfNoEntry : false } ) ;
1330
+ }
1331
+
1322
1332
/**
1323
1333
* Uses the builtin inspector APIs to capture a CPU profile
1324
1334
* See https://nodejs.org/api/inspector.html#inspector_example_usage for details
@@ -1377,7 +1387,7 @@ namespace ts {
1377
1387
activeSession . post ( "Profiler.stop" , ( err , { profile } ) => {
1378
1388
if ( ! err ) {
1379
1389
try {
1380
- if ( _fs . statSync ( profilePath ) . isDirectory ( ) ) {
1390
+ if ( statSync ( profilePath ) ? .isDirectory ( ) ) {
1381
1391
profilePath = _path . join ( profilePath , `${ ( new Date ( ) ) . toISOString ( ) . replace ( / : / g, "-" ) } +P${ process . pid } .cpuprofile` ) ;
1382
1392
}
1383
1393
}
@@ -1667,7 +1677,10 @@ namespace ts {
1667
1677
const name = combinePaths ( path , entry ) ;
1668
1678
1669
1679
try {
1670
- stat = _fs . statSync ( name ) ;
1680
+ stat = statSync ( name ) ;
1681
+ if ( ! stat ) {
1682
+ continue ;
1683
+ }
1671
1684
}
1672
1685
catch ( e ) {
1673
1686
continue ;
@@ -1704,7 +1717,10 @@ namespace ts {
1704
1717
Error . stackTraceLimit = 0 ;
1705
1718
1706
1719
try {
1707
- const stat = _fs . statSync ( path ) ;
1720
+ const stat = statSync ( path ) ;
1721
+ if ( ! stat ) {
1722
+ return false ;
1723
+ }
1708
1724
switch ( entryKind ) {
1709
1725
case FileSystemEntryKind . File : return stat . isFile ( ) ;
1710
1726
case FileSystemEntryKind . Directory : return stat . isDirectory ( ) ;
@@ -1742,7 +1758,7 @@ namespace ts {
1742
1758
1743
1759
function getModifiedTime ( path : string ) {
1744
1760
try {
1745
- return _fs . statSync ( path ) . mtime ;
1761
+ return statSync ( path ) ? .mtime ;
1746
1762
}
1747
1763
catch ( e ) {
1748
1764
return undefined ;
0 commit comments