Skip to content

Commit 498455a

Browse files
committed
fix: potential fix to absolute windows paths failing in benchmarks
1 parent d4ce2dd commit 498455a

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

benches/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ console.log('dirname', dirname);
1212

1313
async function main(): Promise<void> {
1414
console.log('mkdir', path.join(dirname, 'results'));
15-
await fs.promises.mkdir(path.join(dirname, 'results'), { recursive: true });
15+
await fs.promises.mkdir(url.pathToFileURL(path.join(dirname, 'results')), {
16+
recursive: true,
17+
});
1618
// Running all suites
1719
for await (const suitePath of fsWalk(suitesPath)) {
1820
// Skip over non-ts and non-js files
@@ -29,28 +31,30 @@ async function main(): Promise<void> {
2931
}
3032
// Concatenating metrics
3133
const metricsPath = path.join(resultsPath, 'metrics.txt');
32-
await fs.promises.rm(metricsPath, { force: true });
34+
await fs.promises.rm(url.pathToFileURL(metricsPath), { force: true });
3335
let concatenating = false;
3436
for await (const metricPath of fsWalk(resultsPath)) {
3537
// Skip over non-metrics files
3638
if (!metricPath.endsWith('_metrics.txt')) {
3739
continue;
3840
}
39-
const metricData = await fs.promises.readFile(metricPath);
41+
const metricData = await fs.promises.readFile(
42+
url.pathToFileURL(metricPath),
43+
);
4044
if (concatenating) {
41-
await fs.promises.appendFile(metricsPath, '\n');
45+
await fs.promises.appendFile(url.pathToFileURL(metricsPath), '\n');
4246
}
43-
await fs.promises.appendFile(metricsPath, metricData);
47+
await fs.promises.appendFile(url.pathToFileURL(metricsPath), metricData);
4448
concatenating = true;
4549
}
4650
const systemData = await si.get({
4751
cpu: '*',
4852
osInfo: 'platform, distro, release, kernel, arch',
4953
system: 'model, manufacturer',
5054
});
51-
console.log('write file', path.join(dirname, 'results', 'system.json'))
55+
console.log('write file', path.join(dirname, 'results', 'system.json'));
5256
await fs.promises.writeFile(
53-
path.join(dirname, 'results', 'system.json'),
57+
url.pathToFileURL(path.join(dirname, 'results', 'system.json')),
5458
JSON.stringify(systemData, null, 2),
5559
);
5660
}

benches/utils.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const suiteCommon = [
2727
// To `results/path/to/suite`
2828
const resultPath = path.join(resultsPath, relativePath);
2929
// This creates directory `results/path/to`
30-
fs.mkdirSync(path.dirname(resultPath), { recursive: true });
30+
fs.mkdirSync(url.pathToFileURL(path.dirname(resultPath)), {
31+
recursive: true,
32+
});
3133
return relativePath;
3234
},
3335
folder: resultsPath,
@@ -41,7 +43,9 @@ const suiteCommon = [
4143
// To `results/path/to/suite`
4244
const resultPath = path.join(resultsPath, relativePath);
4345
// This creates directory `results/path/to`
44-
fs.mkdirSync(path.dirname(resultPath), { recursive: true });
46+
fs.mkdirSync(url.pathToFileURL(path.dirname(resultPath)), {
47+
recursive: true,
48+
});
4549
return relativePath;
4650
},
4751
folder: resultsPath,
@@ -54,9 +58,11 @@ const suiteCommon = [
5458
// To `results/path/to/suite_metrics.txt`
5559
const resultPath = path.join(resultsPath, relativePath) + '_metrics.txt';
5660
// This creates directory `results/path/to`
57-
fs.mkdirSync(path.dirname(resultPath), { recursive: true });
61+
fs.mkdirSync(url.pathToFileURL(path.dirname(resultPath)), {
62+
recursive: true,
63+
});
5864
fs.writeFileSync(
59-
resultPath,
65+
url.pathToFileURL(resultPath),
6066
codeBlock`
6167
# TYPE ${summary.name}_ops gauge
6268
${summary.results
@@ -89,7 +95,9 @@ const suiteCommon = [
8995
];
9096

9197
async function* fsWalk(dir: string): AsyncGenerator<string> {
92-
const dirents = await fs.promises.readdir(dir, { withFileTypes: true });
98+
const dirents = await fs.promises.readdir(url.pathToFileURL(dir), {
99+
withFileTypes: true,
100+
});
93101
for (const dirent of dirents) {
94102
const res = path.resolve(dir, dirent.name);
95103
if (dirent.isDirectory()) {

0 commit comments

Comments
 (0)