Skip to content

Commit

Permalink
fix decimal number & fix script total gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch-txs committed Apr 21, 2024
1 parent 54f4781 commit cfd4ebe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
12 changes: 7 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30459,12 +30459,14 @@ async function exec_vite_size({ branch } = {}) {
const filtered_output = JSON.parse(stdout_output[stdout_output.length - 1]);
const size_values = [['Name', 'Size (kb)', 'Gzip (kb)']];
for (let i = 0; i < filtered_output.length; i++) {
total_size[1] += Number(filtered_output[i].size);
total_size[2] += Number(filtered_output[i].gzip);
const _size = Number(parseFloat(filtered_output[i].size).toFixed(3));
const _gzip = Number(parseFloat(filtered_output[i].gzip).toFixed(3));
total_size[1] += _size;
total_size[2] += _gzip;
size_values.push([
filtered_output[i].name.toString(),
Number(filtered_output[i].size),
Number(filtered_output[i].gzip)
_size,
_gzip
]);
}
size_values.push(total_size);
Expand All @@ -30481,7 +30483,7 @@ function calcDiff({ current, base }) {
const current_size = Number(current[current.length - 1]?.[1]);
const current_gzip = Number(current[current.length - 1]?.[2]);
const base_size = Number(base[base.length - 1]?.[1]);
const base_gzip = Number(current[current.length - 1]?.[2]);
const base_gzip = Number(base[base.length - 1]?.[2]);
let size = Math.abs(current_size - base_size);
let gzip = Math.abs(current_gzip - base_gzip);
if (current_size > base_size) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-size-action",
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"main": "index.js",
"type": "module",
Expand Down
13 changes: 8 additions & 5 deletions utils/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ export async function exec_vite_size({ branch }: { branch?: string } = {}){
const size_values: SizeValue = [['Name', 'Size (kb)', 'Gzip (kb)']]

for(let i = 0; i < filtered_output.length; i++){
(total_size[1] as number) += Number(filtered_output[i].size);
(total_size[2] as number) += Number(filtered_output[i].gzip);
const _size = Number(parseFloat(filtered_output[i].size).toFixed(3));
const _gzip = Number(parseFloat(filtered_output[i].gzip).toFixed(3));

(total_size[1] as number) += _size;
(total_size[2] as number) += _gzip;

size_values.push([
filtered_output[i].name.toString(),
Number(filtered_output[i].size),
Number(filtered_output[i].gzip)
_size,
_gzip
])
}
size_values.push(total_size)
Expand All @@ -63,7 +66,7 @@ export function calcDiff({ current, base }: { current?: SizeValue, base?: SizeVa
const current_size = Number(current[current.length - 1]?.[1])
const current_gzip = Number(current[current.length - 1]?.[2])
const base_size = Number(base[base.length - 1]?.[1])
const base_gzip = Number(current[current.length - 1]?.[2])
const base_gzip = Number(base[base.length - 1]?.[2])

let size: string | number = Math.abs(current_size - base_size)
let gzip: string | number = Math.abs(current_gzip - base_gzip)
Expand Down

0 comments on commit cfd4ebe

Please sign in to comment.