@@ -1484,6 +1484,8 @@ export let sys: System = (() => {
1484
1484
const isMacOs = process . platform === "darwin" ;
1485
1485
const isLinuxOrMacOs = process . platform === "linux" || isMacOs ;
1486
1486
1487
+ const statSyncOptions = { throwIfNoEntry : false } as const ;
1488
+
1487
1489
const platform : string = _os . platform ( ) ;
1488
1490
const useCaseSensitiveFileNames = isFileSystemCaseSensitive ( ) ;
1489
1491
const fsRealpath = ! ! _fs . realpathSync . native ? process . platform === "win32" ? fsRealPathHandlingLongPath : _fs . realpathSync . native : _fs . realpathSync ;
@@ -1576,13 +1578,10 @@ export let sys: System = (() => {
1576
1578
return process . memoryUsage ( ) . heapUsed ;
1577
1579
} ,
1578
1580
getFileSize ( path ) {
1579
- try {
1580
- const stat = statSync ( path ) ;
1581
- if ( stat ?. isFile ( ) ) {
1582
- return stat . size ;
1583
- }
1581
+ const stat = statSync ( path ) ;
1582
+ if ( stat ?. isFile ( ) ) {
1583
+ return stat . size ;
1584
1584
}
1585
- catch { /*ignore*/ }
1586
1585
return 0 ;
1587
1586
} ,
1588
1587
exit ( exitCode ?: number ) : void {
@@ -1626,14 +1625,17 @@ export let sys: System = (() => {
1626
1625
} ;
1627
1626
return nodeSystem ;
1628
1627
1629
- /**
1630
- * `throwIfNoEntry` was added so recently that it's not in the node types.
1631
- * This helper encapsulates the mitigating usage of `any`.
1632
- * See https://github.com/nodejs/node/pull/33716
1633
- */
1628
+ /** Calls fs.statSync, returning undefined if any errors are thrown */
1634
1629
function statSync ( path : string ) : import ( "fs" ) . Stats | undefined {
1635
- // throwIfNoEntry will be ignored by older versions of node
1636
- return ( _fs as any ) . statSync ( path , { throwIfNoEntry : false } ) ;
1630
+ // throwIfNoEntry is available in Node 14.17 and above, which matches our supported range.
1631
+ try {
1632
+ return _fs . statSync ( path , statSyncOptions ) ;
1633
+ }
1634
+ catch {
1635
+ // This should never happen as we are passing throwIfNoEntry: false,
1636
+ // but guard against this just in case (e.g. a polyfill doesn't check this flag).
1637
+ return undefined ;
1638
+ }
1637
1639
}
1638
1640
1639
1641
/**
@@ -1693,13 +1695,8 @@ export let sys: System = (() => {
1693
1695
const s = activeSession ;
1694
1696
activeSession . post ( "Profiler.stop" , ( err , { profile } ) => {
1695
1697
if ( ! err ) {
1696
- try {
1697
- if ( statSync ( profilePath ) ?. isDirectory ( ) ) {
1698
- profilePath = _path . join ( profilePath , `${ ( new Date ( ) ) . toISOString ( ) . replace ( / : / g, "-" ) } +P${ process . pid } .cpuprofile` ) ;
1699
- }
1700
- }
1701
- catch {
1702
- // do nothing and ignore fallible fs operation
1698
+ if ( statSync ( profilePath ) ?. isDirectory ( ) ) {
1699
+ profilePath = _path . join ( profilePath , `${ ( new Date ( ) ) . toISOString ( ) . replace ( / : / g, "-" ) } +P${ process . pid } .cpuprofile` ) ;
1703
1700
}
1704
1701
try {
1705
1702
_fs . mkdirSync ( _path . dirname ( profilePath ) , { recursive : true } ) ;
@@ -1857,13 +1854,8 @@ export let sys: System = (() => {
1857
1854
if ( typeof dirent === "string" || dirent . isSymbolicLink ( ) ) {
1858
1855
const name = combinePaths ( path , entry ) ;
1859
1856
1860
- try {
1861
- stat = statSync ( name ) ;
1862
- if ( ! stat ) {
1863
- continue ;
1864
- }
1865
- }
1866
- catch {
1857
+ stat = statSync ( name ) ;
1858
+ if ( ! stat ) {
1867
1859
continue ;
1868
1860
}
1869
1861
}
@@ -1892,30 +1884,17 @@ export let sys: System = (() => {
1892
1884
}
1893
1885
1894
1886
function fileSystemEntryExists ( path : string , entryKind : FileSystemEntryKind ) : boolean {
1895
- // Since the error thrown by fs.statSync isn't used, we can avoid collecting a stack trace to improve
1896
- // the CPU time performance.
1897
- const originalStackTraceLimit = Error . stackTraceLimit ;
1898
- Error . stackTraceLimit = 0 ;
1899
-
1900
- try {
1901
- const stat = statSync ( path ) ;
1902
- if ( ! stat ) {
1903
- return false ;
1904
- }
1905
- switch ( entryKind ) {
1906
- case FileSystemEntryKind . File :
1907
- return stat . isFile ( ) ;
1908
- case FileSystemEntryKind . Directory :
1909
- return stat . isDirectory ( ) ;
1910
- default :
1911
- return false ;
1912
- }
1913
- }
1914
- catch {
1887
+ const stat = statSync ( path ) ;
1888
+ if ( ! stat ) {
1915
1889
return false ;
1916
1890
}
1917
- finally {
1918
- Error . stackTraceLimit = originalStackTraceLimit ;
1891
+ switch ( entryKind ) {
1892
+ case FileSystemEntryKind . File :
1893
+ return stat . isFile ( ) ;
1894
+ case FileSystemEntryKind . Directory :
1895
+ return stat . isDirectory ( ) ;
1896
+ default :
1897
+ return false ;
1919
1898
}
1920
1899
}
1921
1900
@@ -1945,19 +1924,7 @@ export let sys: System = (() => {
1945
1924
}
1946
1925
1947
1926
function getModifiedTime ( path : string ) {
1948
- // Since the error thrown by fs.statSync isn't used, we can avoid collecting a stack trace to improve
1949
- // the CPU time performance.
1950
- const originalStackTraceLimit = Error . stackTraceLimit ;
1951
- Error . stackTraceLimit = 0 ;
1952
- try {
1953
- return statSync ( path ) ?. mtime ;
1954
- }
1955
- catch {
1956
- return undefined ;
1957
- }
1958
- finally {
1959
- Error . stackTraceLimit = originalStackTraceLimit ;
1960
- }
1927
+ return statSync ( path ) ?. mtime ;
1961
1928
}
1962
1929
1963
1930
function setModifiedTime ( path : string , time : Date ) {
0 commit comments