Skip to content

Commit 40de41d

Browse files
authored
feat: support for tracking Rspack binary size (#104)
1 parent fd3b164 commit 40de41d

File tree

6 files changed

+66
-22
lines changed

6 files changed

+66
-22
lines changed

.github/workflows/manual.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
type: choice
99
required: true
1010
options:
11+
- RSPACK
1112
- RSBUILD
1213
- RSPRESS
1314
- RSLIB
@@ -17,6 +18,7 @@ on:
1718
type: choice
1819
required: true
1920
options:
21+
- rspack-binary-size
2022
- rsbuild-react
2123
- rsbuild-vue3
2224
- rsbuild-lit
@@ -76,7 +78,7 @@ jobs:
7678
- name: Setup Node.js
7779
uses: actions/setup-node@v4
7880
with:
79-
node-version: 18
81+
node-version: 22
8082
cache-dependency-path: pnpm-lock.yaml
8183

8284
- name: Activate corepack

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ temp/**/*
4949
rspress
5050
rsbuild
5151
rslib
52+
rspack
5253
!/cases/rspress/
5354
!/scripts/**/*/rspress
5455
!/cases/rsbuild/

scripts/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
},
1111
"exports": {
1212
"./plugins/modernjs-framework": "./dist/plugins/modernjs-framework/index.js",
13-
"./plugins/modernjs-module": "./dist/plugins/modernjs-module/index.js",
1413
"./plugins/rspress": "./dist/plugins/rspress/index.js",
1514
"./plugins/rsbuild": "./dist/plugins/rsbuild/index.js",
1615
"./plugins/rspack": "./dist/plugins/rspack/index.js"
@@ -20,9 +19,6 @@
2019
"plugins/modernjs-framework": [
2120
"./dist/plugins/modernjs-framework/index.d.ts"
2221
],
23-
"plugins/modernjs-module": [
24-
"./dist/plugins/modernjs-module/index.d.ts"
25-
],
2622
"plugins/rspress": [
2723
"./dist/plugins/rspress/index.d.ts"
2824
],

scripts/src/main.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { build } from './runners/build';
44
import { cloneRepo, getDataPath, mergeMetrics } from './shared';
55
import { remove } from 'fs-extra';
66
import { yarnInstall } from './runners/yarn-install';
7+
import { getBinarySize } from './runners/binary-size';
78

89
const productName = process.argv[2];
910
const caseName = process.argv[3];
@@ -17,28 +18,36 @@ async function main() {
1718
logger.error(`product not found: ${productName}`);
1819
}
1920

20-
if (caseName) {
21-
process.env.PRODUCT_NAME = productName;
22-
process.env.CASE_NAME = caseName;
23-
await remove(dataPath);
21+
process.env.PRODUCT_NAME = productName;
22+
process.env.CASE_NAME = caseName;
2423

25-
if (process.env.ONLY_INSTALL_SIZE !== 'true') {
26-
if (productName !== 'RSLIB') {
27-
await dev(productName, caseName);
28-
}
29-
await build(productName, caseName);
30-
}
24+
await remove(dataPath);
3125

32-
try {
33-
await yarnInstall(productName, caseName);
34-
} catch (err) {
35-
console.log('failed to collect install size metrics:', err);
36-
}
26+
if (!caseName) {
27+
throw new Error('Missing case name!');
28+
}
3729

30+
// Rspack only need to get binary size
31+
if (productName === 'RSPACK') {
32+
await getBinarySize();
3833
await mergeMetrics(productName, caseName);
39-
} else {
40-
logger.error(`Case not found: ${productName} ${caseName}`);
34+
return;
4135
}
36+
37+
if (process.env.ONLY_INSTALL_SIZE !== 'true') {
38+
if (productName !== 'RSLIB') {
39+
await dev(productName, caseName);
40+
}
41+
await build(productName, caseName);
42+
}
43+
44+
try {
45+
await yarnInstall(productName, caseName);
46+
} catch (err) {
47+
console.log('failed to collect install size metrics:', err);
48+
}
49+
50+
await mergeMetrics(productName, caseName);
4251
}
4352

4453
main();

scripts/src/runners/binary-size.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { join, parse } from 'path';
2+
import { getRepoName, getRepoPath, runCommand, saveMetrics } from '../shared';
3+
import glob from 'fast-glob';
4+
import { statSync } from 'fs';
5+
6+
export const getBinarySize = async () => {
7+
const repoPath = getRepoPath(getRepoName('RSPACK'));
8+
9+
await runCommand(repoPath, 'pnpm run build:binding:release-prod');
10+
11+
const binaryPath = glob.sync(
12+
join(repoPath, 'crates/node_binding/rspack.*.node'),
13+
{
14+
absolute: true,
15+
},
16+
);
17+
18+
if (!binaryPath.length) {
19+
throw new Error('Binary file not found!');
20+
}
21+
22+
const data: Record<string, number> = {};
23+
24+
for (const path of binaryPath) {
25+
const size = statSync(path).size;
26+
data[parse(path).name] = size;
27+
}
28+
29+
return saveMetrics(data);
30+
};

scripts/src/shared/git.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ export async function cloneRepo(productName: string, caseName: string) {
6868
return;
6969
}
7070

71+
if (productName === 'RSPACK') {
72+
await runCommand(localRepoPath, 'corepack enable && pnpm -v');
73+
await runCommand(localRepoPath, 'pnpm i');
74+
return;
75+
}
76+
7177
await copy(
7278
join(getCaseSrcPath(productName), caseName),
7379
join(getCaseDistPath(productName), caseName),

0 commit comments

Comments
 (0)