Skip to content

Commit bf33fe5

Browse files
committed
build: adding NPM_TOKEN secret
1 parent 4b08d63 commit bf33fe5

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

benches/db_1KiB.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ async function main() {
4646
});
4747
return summary;
4848
}
49-
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
50-
void main();
49+
50+
if (import.meta.url.startsWith('file:')) {
51+
const modulePath = url.fileURLToPath(import.meta.url);
52+
if (process.argv[1] === modulePath) {
53+
void main();
54+
}
5155
}
5256

5357
export default main;

benches/db_1MiB.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ async function main() {
4747
return summary;
4848
}
4949

50-
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
51-
void main();
50+
if (import.meta.url.startsWith('file:')) {
51+
const modulePath = url.fileURLToPath(import.meta.url);
52+
if (process.argv[1] === modulePath) {
53+
void main();
54+
}
5255
}
5356

5457
export default main;

benches/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
#!/usr/bin/env ts-node
22

3-
import fs from 'fs';
4-
import path from 'path';
3+
import fs from 'node:fs';
4+
import path from 'node:path';
55
import url from 'node:url';
66
import si from 'systeminformation';
7+
import { benchesPath } from './utils/utils.js';
78
import DB1KiB from './db_1KiB.js';
89
import DB1MiB from './db_1MiB.js';
910

10-
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
11-
1211
async function main(): Promise<void> {
13-
await fs.promises.mkdir(path.join(dirname, 'results'), { recursive: true });
12+
await fs.promises.mkdir(path.join(benchesPath, 'results'), {
13+
recursive: true,
14+
});
1415
await DB1KiB();
1516
await DB1MiB();
1617
const resultFilenames = await fs.promises.readdir(
17-
path.join(dirname, 'results'),
18+
path.join(benchesPath, 'results'),
1819
);
1920
const metricsFile = await fs.promises.open(
20-
path.join(dirname, 'results', 'metrics.txt'),
21+
path.join(benchesPath, 'results', 'metrics.txt'),
2122
'w',
2223
);
2324
let concatenating = false;
2425
for (const resultFilename of resultFilenames) {
2526
if (/.+_metrics\.txt$/.test(resultFilename)) {
2627
const metricsData = await fs.promises.readFile(
27-
path.join(dirname, 'results', resultFilename),
28+
path.join(benchesPath, 'results', resultFilename),
2829
);
2930
if (concatenating) {
3031
await metricsFile.write('\n');
@@ -40,9 +41,16 @@ async function main(): Promise<void> {
4041
system: 'model, manufacturer',
4142
});
4243
await fs.promises.writeFile(
43-
path.join(dirname, 'results', 'system.json'),
44+
path.join(benchesPath, 'results', 'system.json'),
4445
JSON.stringify(systemData, null, 2),
4546
);
4647
}
4748

48-
void main();
49+
if (import.meta.url.startsWith('file:')) {
50+
const modulePath = url.fileURLToPath(import.meta.url);
51+
if (process.argv[1] === modulePath) {
52+
void main();
53+
}
54+
}
55+
56+
export default main;

benches/utils/utils.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
33
import url from 'node:url';
44
import b from 'benny';
55
import { codeBlock } from 'common-tags';
6-
import packageJson from '../../package.json';
6+
import packageJson from '../../package.json' assert { type: 'json' };
77

8-
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
8+
const benchesPath = path.dirname(
9+
path.dirname(url.fileURLToPath(import.meta.url)),
10+
);
911

1012
const suiteCommon = [
1113
b.cycle(),
1214
b.complete(),
1315
b.save({
1416
file: (summary) => summary.name,
15-
folder: path.join(dirname, '../results'),
17+
folder: path.join(benchesPath, 'results'),
1618
version: packageJson.version,
1719
details: true,
1820
}),
1921
b.save({
2022
file: (summary) => summary.name,
21-
folder: path.join(dirname, '../results'),
23+
folder: path.join(benchesPath, 'results'),
2224
version: packageJson.version,
2325
format: 'chart.html',
2426
}),
2527
b.complete((summary) => {
2628
const filePath = path.join(
27-
dirname,
28-
'../results',
29+
benchesPath,
30+
'results',
2931
summary.name + '_metrics.txt',
3032
);
3133
fs.writeFileSync(
@@ -61,4 +63,4 @@ const suiteCommon = [
6163
}),
6264
];
6365

64-
export { suiteCommon };
66+
export { benchesPath, suiteCommon };

0 commit comments

Comments
 (0)