Skip to content

Commit 31c39b2

Browse files
committed
chore: migrate scripts
1 parent 2fdd36d commit 31c39b2

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

scripts/ci/measure-size.cjs renamed to scripts/ci/measure-size.js

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,9 @@
1-
const { readFile } = require('node:fs/promises');
1+
import { readFile } from 'node:fs/promises';
22

3-
const { setFailed, setOutput } = require('@actions/core');
4-
const { getExecOutput } = require('@actions/exec');
5-
const { markdownTable } = require('markdown-table');
6-
const bytes = require('bytes');
7-
8-
/**
9-
* @param size {number}
10-
* @return {string | null}
11-
*/
12-
function formatBytes(size) {
13-
return bytes.format(size, { unitSeparator: ' ' });
14-
}
15-
16-
/**
17-
* @param current {number}
18-
* @param baseline {number}
19-
* @return {string}
20-
*/
21-
function compareSizeWithBaseline(current, baseline) {
22-
if (baseline === 0) {
23-
return '+100% 🔺';
24-
}
25-
26-
const value = ((current - baseline) / baseline) * 100;
27-
const formatted = (Math.sign(value) * Math.ceil(Math.abs(value) * 100)) / 100;
28-
29-
if (value > 0) {
30-
return `+${formatted}% 🔺`;
31-
}
32-
33-
if (value === 0) {
34-
return `${formatted}% 🟰`;
35-
}
36-
37-
return `${formatted}% 🔽👏`;
38-
}
3+
import { setFailed, setOutput } from '@actions/core';
4+
import { getExecOutput } from '@actions/exec';
5+
import bytes from 'bytes';
6+
import { markdownTable } from 'markdown-table';
397

408
async function run() {
419
/**
@@ -89,8 +57,36 @@ async function run() {
8957
}
9058
}
9159

92-
// Replace top-level await with function call that handles the promise
93-
run().catch((error) => {
94-
console.error(error);
95-
setFailed(error.message);
96-
});
60+
/**
61+
* @param size {number}
62+
* @return {string | null}
63+
*/
64+
function formatBytes(size) {
65+
return bytes.format(size, { unitSeparator: ' ' });
66+
}
67+
68+
/**
69+
* @param current {number}
70+
* @param baseline {number}
71+
* @return {string}
72+
*/
73+
function compareSizeWithBaseline(current, baseline) {
74+
if (baseline === 0) {
75+
return '+100% 🔺';
76+
}
77+
78+
const value = ((current - baseline) / baseline) * 100;
79+
const formatted = (Math.sign(value) * Math.ceil(Math.abs(value) * 100)) / 100;
80+
81+
if (value > 0) {
82+
return `+${formatted}% 🔺`;
83+
}
84+
85+
if (value === 0) {
86+
return `${formatted}% 🟰`;
87+
}
88+
89+
return `${formatted}% 🔽👏`;
90+
}
91+
92+
await run();

0 commit comments

Comments
 (0)