Skip to content

Commit 42bb9c5

Browse files
committed
fix: current key error
1 parent 78cc122 commit 42bb9c5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"start": "npm run build && node ./dist/main.js",
66
"start:pr": "npm run build && node ./dist/pr-bench.js",
7-
"compare": "npm run build && node ./dist/compare.js",
7+
"compare": "node ./dist/compare.js",
88
"dev": "tsc --watch",
99
"build": "rm -rf ./dist && tsc"
1010
},

scripts/src/compare.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { readJson } from 'fs-extra';
33
import {
44
DefaultBenchCase,
55
ValidMetricsForCase,
6+
getCommitId,
67
getCommitLink,
78
getMetricsPath,
9+
getRepoName,
10+
getRepoPath,
811
} from './shared';
912

1013
const productName = process.argv[2] || 'MODERNJS_FRAMEWORK';
@@ -102,8 +105,18 @@ export async function compare(productName: string) {
102105

103106
arr.sort((a, b) => a.value.time - b.value.time);
104107

105-
const currentKey = arr[arr.length - 1].key;
106-
const baseKey = arr[arr.length - 2].key;
108+
let currentKey = arr[arr.length - 1].key;
109+
let baseKey = arr[arr.length - 2]?.key || currentKey;
110+
111+
if (process.env.MONITOR !== '1') {
112+
const repoPath = getRepoPath(getRepoName(productName));
113+
const id = await getCommitId(repoPath);
114+
if (id !== currentKey) {
115+
baseKey = currentKey;
116+
currentKey = id;
117+
}
118+
}
119+
107120
const current = allMetrics[currentKey as any];
108121
const base = allMetrics[baseKey as any];
109122
const baseCommitLink = getCommitLink(productName, baseKey);

0 commit comments

Comments
 (0)