Skip to content

Commit 34d26bc

Browse files
authored
chore: use sync file io to read and write json (#51)
1 parent 2eabc4f commit 34d26bc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

scripts/src/plugins/rsbuild/measure-rspress-build-plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export const measureRspressBuildPlugin = () => ({
2525
api.onAfterBuild(async () => {
2626
const buildTime = performance.now() - beforeBuildTime;
2727
metrics.buildColdBootTime = buildTime;
28-
await saveMetrics(metrics);
28+
if (api.context.target === 'web') {
29+
await saveMetrics(metrics);
30+
}
2931
});
3032

3133
api.onBeforeStartDevServer(() => {

scripts/src/shared/fs.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
outputJson,
88
outputFile,
99
pathExists,
10+
readJsonSync,
11+
outputJsonSync,
1012
} from 'fs-extra';
1113
import logger from 'consola';
1214
import type { Metrics } from './types';
@@ -65,17 +67,17 @@ export async function saveMetrics(metrics: Metrics) {
6567
const { jsonPath, jsonName } = await getMetricsPath(PRODUCT_NAME, CASE_NAME);
6668

6769
if (await pathExists(jsonPath)) {
68-
const content: Metrics[] = await readJson(jsonPath);
70+
const content: Metrics[] = readJsonSync(jsonPath);
6971

7072
if (content[index]) {
7173
Object.assign(content[index], metrics);
7274
} else {
7375
content.push(metrics);
7476
}
7577

76-
await outputJson(jsonPath, content, { spaces: 2 });
78+
outputJsonSync(jsonPath, content, { spaces: 2 });
7779
} else {
78-
await outputJson(jsonPath, [metrics], { spaces: 2 });
80+
outputJsonSync(jsonPath, [metrics], { spaces: 2 });
7981
}
8082

8183
logger.success(`Successfully write metrics to ${jsonName}.`);

0 commit comments

Comments
 (0)