Skip to content

Commit 2f62198

Browse files
committed
remove fs dependency for web package
1 parent a72ac11 commit 2f62198

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/utils/benchmark.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import fs from 'fs';
2-
import { Profiler } from './constants.js';
1+
import { FileSystem, Profiler } from './constants.js';
32

43
export { getProfiler, getMemoryUsage };
54

65
const round = (x: number) => Math.round(x * 100) / 100;
76

8-
function getProfiler(name: string): Profiler {
7+
function getProfiler(name: string, fs: FileSystem): Profiler {
98
// eslint-disable-next-line @typescript-eslint/no-explicit-any
109
let times: Record<string, any> = {};
1110
let label: string;
@@ -27,7 +26,7 @@ function getProfiler(name: string): Profiler {
2726
times[label].end = performance.now();
2827
return this;
2928
},
30-
store() {
29+
async store() {
3130
let profilingData = `## Times for ${name}\n\n`;
3231
profilingData += `| Name | time passed in s |\n|---|---|`;
3332
let totalTimePassed = 0;
@@ -43,7 +42,7 @@ function getProfiler(name: string): Profiler {
4342
totalTimePassed
4443
)} seconds to run the entire benchmark\n\n\n`;
4544

46-
fs.appendFileSync(`profiler/${name}.md`, profilingData);
45+
await fs.appendFile(`profiler/${name}.md`, profilingData);
4746
},
4847
};
4948
}

src/utils/config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import fs from 'fs/promises';
21
import { PrivateKey, PublicKey } from 'o1js';
3-
import { Base58Key, Config, Key, ZkApp } from './constants.js';
2+
import { Base58Key, Config, FileSystem, Key, ZkApp } from './constants.js';
43

54
export { readConfig, readZkAppConfig, readUserConfig };
65

7-
async function readConfig(path = 'config.json'): Promise<Config> {
6+
async function readConfig(
7+
fs: FileSystem,
8+
path = 'config.json'
9+
): Promise<Config> {
810
return JSON.parse(await fs.readFile(path, 'utf8'));
911
}
1012

1113
async function readZkAppConfig(
14+
fs: FileSystem,
1215
label: string | number,
1316
path = 'config.json'
1417
): Promise<{
@@ -17,7 +20,7 @@ async function readZkAppConfig(
1720
feePayer: Key;
1821
zkApp: ZkApp;
1922
}> {
20-
const configJson = await readConfig(path);
23+
const configJson = await readConfig(fs, path);
2124
let config =
2225
typeof label === 'string'
2326
? configJson.deployAliases[label]
@@ -52,6 +55,7 @@ async function readZkAppConfig(
5255
}
5356

5457
async function readUserConfig(
58+
fs: FileSystem,
5559
label: string | number,
5660
path = 'config.json'
5761
): Promise<{
@@ -60,7 +64,7 @@ async function readUserConfig(
6064
feePayer: Key;
6165
user: Key;
6266
}> {
63-
const configJson = await readConfig(path);
67+
const configJson = await readConfig(fs, path);
6468
let config =
6569
typeof label === 'string'
6670
? configJson.deployAliases[label]

src/utils/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212

1313
export {
1414
MAX_RETRY,
15+
FileSystem,
1516
Profiler,
1617
Logger,
1718
Program,
@@ -27,6 +28,13 @@ export {
2728

2829
const MAX_RETRY = 3;
2930

31+
type FileSystem = {
32+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33+
appendFile(...args: any): Promise<void>;
34+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35+
readFile(...args: any): Promise<any>;
36+
};
37+
3038
type Profiler = {
3139
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3240
times: Record<string, any>;

0 commit comments

Comments
 (0)