File tree Expand file tree Collapse file tree 4 files changed +42
-17
lines changed
Expand file tree Collapse file tree 4 files changed +42
-17
lines changed Original file line number Diff line number Diff line change @@ -357,20 +357,31 @@ async function getHeadSize(path) {
357357 }
358358}
359359async function diffSize(file) {
360- const stat = fs_1.statSync(file.path);
361- core.debug(`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`);
362360 switch (file.flag) {
363- case 'M':
361+ case 'M': {
362+ const stat = fs_1.statSync(file.path);
363+ core.debug(`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`);
364364 // get old size and compare
365365 const oldSize = await getHeadSize(file.path);
366366 const delta = oldSize === undefined ? stat.size : stat.size - oldSize;
367367 core.debug(` ==> ${file.path} modified: old ${oldSize}, new ${stat.size}, delta ${delta}b `);
368368 return delta;
369- case 'A':
369+ }
370+ case 'A': {
371+ const stat = fs_1.statSync(file.path);
372+ core.debug(`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`);
370373 core.debug(` ==> ${file.path} added: delta ${stat.size}b`);
371374 return stat.size;
372- default:
375+ }
376+ case 'D': {
377+ const oldSize = await getHeadSize(file.path);
378+ const delta = oldSize === undefined ? 0 : oldSize;
379+ core.debug(` ==> ${file.path} deleted: delta ${delta}b`);
380+ return delta;
381+ }
382+ default: {
373383 throw new Error(`Encountered an unexpected file status in git: ${file.flag} ${file.path}`);
384+ }
374385 }
375386}
376387async function diff(filename) {
Original file line number Diff line number Diff line change 11{
22 "name" : " flat" ,
3- "version" : " 2.0.2 " ,
3+ "version" : " 2.1.0 " ,
44 "description" : " The GitHub action which powers data fetching for Flat" ,
55 "main" : " index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -46,29 +46,42 @@ async function getHeadSize(path: string): Promise<number | undefined> {
4646 }
4747}
4848
49- async function diffSize ( file : GitStatus ) : Promise < number > {
50- const stat = statSync ( file . path )
51- core . debug (
52- `Calculating diff for ${ JSON . stringify ( file ) } , with size ${ stat . size } b`
53- )
54- switch ( file . flag ) {
55- case 'M' :
49+ async function diffSize ( file : GitStatus ) : Promise < number > {
50+ switch ( file . flag ) {
51+ case 'M' : {
52+ const stat = statSync ( file . path )
53+ core . debug (
54+ `Calculating diff for ${ JSON . stringify ( file ) } , with size ${ stat . size } b`
55+ )
56+
5657 // get old size and compare
5758 const oldSize = await getHeadSize ( file . path )
5859 const delta = oldSize === undefined ? stat . size : stat . size - oldSize
5960 core . debug (
6061 ` ==> ${ file . path } modified: old ${ oldSize } , new ${ stat . size } , delta ${ delta } b `
6162 )
6263 return delta
64+ }
65+ case 'A' : {
66+ const stat = statSync ( file . path )
67+ core . debug (
68+ `Calculating diff for ${ JSON . stringify ( file ) } , with size ${ stat . size } b`
69+ )
6370
64- case 'A' :
6571 core . debug ( ` ==> ${ file . path } added: delta ${ stat . size } b` )
6672 return stat . size
67-
68- default :
73+ }
74+ case 'D' : {
75+ const oldSize = await getHeadSize ( file . path )
76+ const delta = oldSize === undefined ? 0 : oldSize
77+ core . debug ( ` ==> ${ file . path } deleted: delta ${ delta } b` )
78+ return delta
79+ }
80+ default : {
6981 throw new Error (
7082 `Encountered an unexpected file status in git: ${ file . flag } ${ file . path } `
7183 )
84+ }
7285 }
7386}
7487
@@ -84,3 +97,4 @@ export async function diff(filename: string): Promise<number> {
8497 }
8598 return await diffSize ( status )
8699}
100+
You can’t perform that action at this time.
0 commit comments