File tree 4 files changed +42
-17
lines changed
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) {
357
357
}
358
358
}
359
359
async 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`);
362
360
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`);
364
364
// get old size and compare
365
365
const oldSize = await getHeadSize(file.path);
366
366
const delta = oldSize === undefined ? stat.size : stat.size - oldSize;
367
367
core.debug(` ==> ${file.path} modified: old ${oldSize}, new ${stat.size}, delta ${delta}b `);
368
368
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`);
370
373
core.debug(` ==> ${file.path} added: delta ${stat.size}b`);
371
374
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: {
373
383
throw new Error(`Encountered an unexpected file status in git: ${file.flag} ${file.path}`);
384
+ }
374
385
}
375
386
}
376
387
async function diff(filename) {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " flat" ,
3
- "version" : " 2.0.2 " ,
3
+ "version" : " 2.1.0 " ,
4
4
"description" : " The GitHub action which powers data fetching for Flat" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -46,29 +46,42 @@ async function getHeadSize(path: string): Promise<number | undefined> {
46
46
}
47
47
}
48
48
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
+
56
57
// get old size and compare
57
58
const oldSize = await getHeadSize ( file . path )
58
59
const delta = oldSize === undefined ? stat . size : stat . size - oldSize
59
60
core . debug (
60
61
` ==> ${ file . path } modified: old ${ oldSize } , new ${ stat . size } , delta ${ delta } b `
61
62
)
62
63
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
+ )
63
70
64
- case 'A' :
65
71
core . debug ( ` ==> ${ file . path } added: delta ${ stat . size } b` )
66
72
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 : {
69
81
throw new Error (
70
82
`Encountered an unexpected file status in git: ${ file . flag } ${ file . path } `
71
83
)
84
+ }
72
85
}
73
86
}
74
87
@@ -84,3 +97,4 @@ export async function diff(filename: string): Promise<number> {
84
97
}
85
98
return await diffSize ( status )
86
99
}
100
+
You can’t perform that action at this time.
0 commit comments