File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,20 +24,26 @@ const formatFile = async ({
2424 cache,
2525} : FormatFileTask ) : Promise < FmtWorkerResult > => {
2626 let source : string | undefined ;
27+ let sourceBuffer : Buffer | undefined ;
2728 let contentHash : string | undefined ;
2829
2930 const readSource = ( shouldHash = ! shouldWrite ) : string => {
31+ if ( sourceBuffer !== undefined ) {
32+ return sourceBuffer . toString ( 'utf8' ) ;
33+ }
34+
3035 if ( ! cache || ! shouldHash ) {
3136 return readFileSync ( file . path , 'utf8' ) ;
3237 }
3338
34- const content = readFileSync ( file . path ) ;
35- contentHash = hashContent ( content ) ;
36- return content . toString ( 'utf8' ) ;
39+ sourceBuffer = readFileSync ( file . path ) ;
40+ contentHash = hashContent ( sourceBuffer ) ;
41+ return sourceBuffer . toString ( 'utf8' ) ;
3742 } ;
3843
3944 if ( cache ?. entry && cache . entry [ 1 ] === cache . optionsHash ) {
40- source = readSource ( true ) ;
45+ sourceBuffer = readFileSync ( file . path ) ;
46+ contentHash = hashContent ( sourceBuffer ) ;
4147 const { entry } = cache ;
4248 if ( entry [ 0 ] === contentHash && ( ! shouldWrite || entry [ 2 ] === 'clean' ) ) {
4349 return { status : entry [ 2 ] === 'clean' ? 'unchanged' : 'changed' } ;
You can’t perform that action at this time.
0 commit comments