import fs from 'fs' ; export class StatsCache { private readonly cachedStats : Record < string , number > = { } ; public add ( files ) { const { cachedStats } = this ; for ( const filename of files ) { if ( fs . existsSync ( filename ) ) { const stat = fs . statSync ( filename ) ; if ( stat . isFile ( ) && ! cachedStats [ filename ] ) { cachedStats [ filename ] = this . sign ( stat ) ; } } } } public refresh ( filename ) { const { cachedStats } = this ; if ( fs . existsSync ( filename ) ) { const stat = fs . statSync ( filename ) ; if ( stat . isFile ( ) ) { cachedStats [ filename ] = this . sign ( stat ) ; } } } public del ( filename ) { if ( this . cachedStats [ filename ] ) { delete this . cachedStats [ filename ] ; } } public isDiff ( filename ) { const { cachedStats } = this ; const stat = fs . statSync ( filename ) ; const cachedStat = cachedStats [ filename ] ; if ( this . sign ( stat ) !== cachedStat ) { return true ; } return false ; } public has ( filename ) { return Boolean ( this . cachedStats [ filename ] ) ; } private sign ( stat ) { return stat . size ; } }