@@ -1217,8 +1217,8 @@ namespace ts {
1217
1217
} ,
1218
1218
getFileSize ( path ) {
1219
1219
try {
1220
- const stat = _fs . statSync ( path ) ;
1221
- if ( stat . isFile ( ) ) {
1220
+ const stat = statSync ( path ) ;
1221
+ if ( stat ? .isFile ( ) ) {
1222
1222
return stat . size ;
1223
1223
}
1224
1224
}
@@ -1265,6 +1265,16 @@ namespace ts {
1265
1265
} ;
1266
1266
return nodeSystem ;
1267
1267
1268
+ /**
1269
+ * `throwIfNoEntry` was added so recently that it's not in the node types.
1270
+ * This helper encapsulates the mitigating usage of `any`.
1271
+ * See https://github.com./nodejs/node/pull/33716
1272
+ */
1273
+ function statSync ( path : string ) : import ( "fs" ) . Stats | undefined {
1274
+ // throwIfNoEntry will be ignored by older versions of node
1275
+ return ( _fs as any ) . statSync ( path , { throwIfNoEntry : false } ) ;
1276
+ }
1277
+
1268
1278
/**
1269
1279
* Uses the builtin inspector APIs to capture a CPU profile
1270
1280
* See https://nodejs.org/api/inspector.html#inspector_example_usage for details
@@ -1323,7 +1333,7 @@ namespace ts {
1323
1333
activeSession . post ( "Profiler.stop" , ( err , { profile } ) => {
1324
1334
if ( ! err ) {
1325
1335
try {
1326
- if ( _fs . statSync ( profilePath ) . isDirectory ( ) ) {
1336
+ if ( statSync ( profilePath ) ? .isDirectory ( ) ) {
1327
1337
profilePath = _path . join ( profilePath , `${ ( new Date ( ) ) . toISOString ( ) . replace ( / : / g, "-" ) } +P${ process . pid } .cpuprofile` ) ;
1328
1338
}
1329
1339
}
@@ -1613,7 +1623,10 @@ namespace ts {
1613
1623
const name = combinePaths ( path , entry ) ;
1614
1624
1615
1625
try {
1616
- stat = _fs . statSync ( name ) ;
1626
+ stat = statSync ( name ) ;
1627
+ if ( ! stat ) {
1628
+ continue ;
1629
+ }
1617
1630
}
1618
1631
catch ( e ) {
1619
1632
continue ;
@@ -1645,7 +1658,10 @@ namespace ts {
1645
1658
1646
1659
function fileSystemEntryExists ( path : string , entryKind : FileSystemEntryKind ) : boolean {
1647
1660
try {
1648
- const stat = _fs . statSync ( path ) ;
1661
+ const stat = statSync ( path ) ;
1662
+ if ( ! stat ) {
1663
+ return false ;
1664
+ }
1649
1665
switch ( entryKind ) {
1650
1666
case FileSystemEntryKind . File : return stat . isFile ( ) ;
1651
1667
case FileSystemEntryKind . Directory : return stat . isDirectory ( ) ;
@@ -1680,7 +1696,7 @@ namespace ts {
1680
1696
1681
1697
function getModifiedTime ( path : string ) {
1682
1698
try {
1683
- return _fs . statSync ( path ) . mtime ;
1699
+ return statSync ( path ) ? .mtime ;
1684
1700
}
1685
1701
catch ( e ) {
1686
1702
return undefined ;
0 commit comments