Skip to content

Commit 2fdd36d

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

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default {
22
singleQuote: true,
33
trailingComma: 'all',
44
importOrder: [
5+
'^:node',
56
'<BUILTIN_MODULES>',
67
'',
78
'<THIRD_PARTY_MODULES>',

scripts/ci/measure-size.cjs

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

3-
import { setFailed, setOutput } from '@actions/core';
4-
import { getExecOutput } from '@actions/exec';
5-
import { markdownTable } from 'markdown-table';
6-
import bytes from 'bytes';
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+
}
739

840
async function run() {
941
/**
@@ -57,36 +89,8 @@ async function run() {
5789
}
5890
}
5991

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();
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+
});

0 commit comments

Comments
 (0)