@@ -1235,8 +1235,8 @@ namespace ts {
1235
1235
} ,
1236
1236
getFileSize ( path ) {
1237
1237
try {
1238
- const stat = _fs . statSync ( path ) ;
1239
- if ( stat . isFile ( ) ) {
1238
+ const stat = statSync ( path ) ;
1239
+ if ( stat ? .isFile ( ) ) {
1240
1240
return stat . size ;
1241
1241
}
1242
1242
}
@@ -1283,6 +1283,16 @@ namespace ts {
1283
1283
} ;
1284
1284
return nodeSystem ;
1285
1285
1286
+ /**
1287
+ * `throwIfNoEntry` was added so recently that it's not in the node types.
1288
+ * This helper encapsulates the mitigating usage of `any`.
1289
+ * See https://github.com/nodejs/node/pull/33716
1290
+ */
1291
+ function statSync ( path : string ) : import ( "fs" ) . Stats | undefined {
1292
+ // throwIfNoEntry will be ignored by older versions of node
1293
+ return ( _fs as any ) . statSync ( path , { throwIfNoEntry : false } ) ;
1294
+ }
1295
+
1286
1296
/**
1287
1297
* Uses the builtin inspector APIs to capture a CPU profile
1288
1298
* See https://nodejs.org/api/inspector.html#inspector_example_usage for details
@@ -1341,7 +1351,7 @@ namespace ts {
1341
1351
activeSession . post ( "Profiler.stop" , ( err , { profile } ) => {
1342
1352
if ( ! err ) {
1343
1353
try {
1344
- if ( _fs . statSync ( profilePath ) . isDirectory ( ) ) {
1354
+ if ( statSync ( profilePath ) ? .isDirectory ( ) ) {
1345
1355
profilePath = _path . join ( profilePath , `${ ( new Date ( ) ) . toISOString ( ) . replace ( / : / g, "-" ) } +P${ process . pid } .cpuprofile` ) ;
1346
1356
}
1347
1357
}
@@ -1631,7 +1641,10 @@ namespace ts {
1631
1641
const name = combinePaths ( path , entry ) ;
1632
1642
1633
1643
try {
1634
- stat = _fs . statSync ( name ) ;
1644
+ stat = statSync ( name ) ;
1645
+ if ( ! stat ) {
1646
+ continue ;
1647
+ }
1635
1648
}
1636
1649
catch ( e ) {
1637
1650
continue ;
@@ -1668,7 +1681,10 @@ namespace ts {
1668
1681
Error . stackTraceLimit = 0 ;
1669
1682
1670
1683
try {
1671
- const stat = _fs . statSync ( path ) ;
1684
+ const stat = statSync ( path ) ;
1685
+ if ( ! stat ) {
1686
+ return false ;
1687
+ }
1672
1688
switch ( entryKind ) {
1673
1689
case FileSystemEntryKind . File : return stat . isFile ( ) ;
1674
1690
case FileSystemEntryKind . Directory : return stat . isDirectory ( ) ;
@@ -1706,7 +1722,7 @@ namespace ts {
1706
1722
1707
1723
function getModifiedTime ( path : string ) {
1708
1724
try {
1709
- return _fs . statSync ( path ) . mtime ;
1725
+ return statSync ( path ) ? .mtime ;
1710
1726
}
1711
1727
catch ( e ) {
1712
1728
return undefined ;
0 commit comments