@esposter/shared-node 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache.d.ts +4 -4
- package/dist/cache.js +3 -34
- package/dist/child-process.d.ts +6 -7
- package/dist/child-process.js +5 -15
- package/dist/reporter.js +2 -119
- package/dist/services/buildBenchmarkFileReport.js +31 -0
- package/dist/services/cache/constants.d.ts +2 -0
- package/dist/services/cache/constants.js +7 -0
- package/dist/services/cache/readContentAddressedObject.d.ts +1 -0
- package/dist/services/cache/readContentAddressedObject.js +21 -0
- package/dist/services/cache/writePartialThenMove.d.ts +1 -0
- package/dist/services/cache/writePartialThenMove.js +17 -0
- package/dist/services/childProcess/execFile.d.ts +4 -0
- package/dist/services/childProcess/execFile.js +10 -0
- package/dist/services/childProcess/execFileSync.d.ts +3 -0
- package/dist/services/childProcess/execFileSync.js +5 -0
- package/dist/services/childProcess/execSync.d.ts +3 -0
- package/dist/services/childProcess/execSync.js +5 -0
- package/dist/services/childProcess/spawn.d.ts +3 -0
- package/dist/services/childProcess/spawn.js +5 -0
- package/dist/services/childProcess/spawnSync.d.ts +3 -0
- package/dist/services/childProcess/spawnSync.js +5 -0
- package/dist/{execSync-DCcbOCo8.js → services/childProcess/withHiddenWindow.js} +1 -4
- package/dist/services/formatBenchmarkMarkdown.js +60 -0
- package/dist/services/readBenchmarkEnvironment.js +19 -0
- package/dist/services/writeBenchmarkReport.js +18 -0
- package/package.json +4 -4
package/dist/cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
import { CACHE_ROOT, CONTENT_CACHE_DIRECTORY } from "./services/cache/constants.js";
|
|
2
|
+
import { readContentAddressedObject } from "./services/cache/readContentAddressedObject.js";
|
|
3
|
+
import { writePartialThenMove } from "./services/cache/writePartialThenMove.js";
|
|
4
|
+
export { CACHE_ROOT, CONTENT_CACHE_DIRECTORY, readContentAddressedObject, writePartialThenMove };
|
package/dist/cache.js
CHANGED
|
@@ -1,35 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { existsSync, rmSync } from "node:fs";
|
|
5
|
-
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
7
|
-
// src/services/cache/constants.ts
|
|
8
|
-
const CACHE_ROOT = join(homedir(), SITE_NAME, "cache");
|
|
9
|
-
const CONTENT_CACHE_DIRECTORY = join(CACHE_ROOT, "content");
|
|
10
|
-
// src/services/cache/writePartialThenMove.ts
|
|
11
|
-
const writePartialThenMove = async (path, write) => {
|
|
12
|
-
await mkdir(dirname(path), { recursive: true });
|
|
13
|
-
const partialPath = `${path}.${crypto.randomUUID()}.part`;
|
|
14
|
-
(await getResultAsync(async () => {
|
|
15
|
-
await write(partialPath);
|
|
16
|
-
await rename(partialPath, path);
|
|
17
|
-
})).match(noop, (error) => {
|
|
18
|
-
rmSync(partialPath, { force: true });
|
|
19
|
-
throw error;
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
// src/services/cache/readContentAddressedObject.ts
|
|
23
|
-
const SHA_256_HEX_REGEX = /^[0-9a-f]{64}$/u;
|
|
24
|
-
const readContentAddressedObject = async (hash, download, directory = CONTENT_CACHE_DIRECTORY) => {
|
|
25
|
-
if (!SHA_256_HEX_REGEX.test(hash)) throw new InvalidOperationError(Operation.Read, hash, "is not a SHA-256 hex digest");
|
|
26
|
-
const path = join(directory, hash);
|
|
27
|
-
if (existsSync(path)) return readFile(path);
|
|
28
|
-
const bytes = Buffer.from(await download());
|
|
29
|
-
if (createHash("sha256").update(bytes).digest("hex") !== hash) throw new InvalidOperationError(Operation.Read, hash, "does not hash to its name");
|
|
30
|
-
await getResultAsync(() => writePartialThenMove(path, (partialPath) => writeFile(partialPath, bytes))).match(noop, (error) => {
|
|
31
|
-
if (!existsSync(path)) throw error;
|
|
32
|
-
});
|
|
33
|
-
return bytes;
|
|
34
|
-
};
|
|
1
|
+
import { CACHE_ROOT, CONTENT_CACHE_DIRECTORY } from "./services/cache/constants.js";
|
|
2
|
+
import { readContentAddressedObject } from "./services/cache/readContentAddressedObject.js";
|
|
3
|
+
import { writePartialThenMove } from "./services/cache/writePartialThenMove.js";
|
|
35
4
|
export { CACHE_ROOT, CONTENT_CACHE_DIRECTORY, readContentAddressedObject, writePartialThenMove };
|
package/dist/child-process.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { execFile
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export declare const spawnSync: typeof spawnSync$1;
|
|
1
|
+
import { execFile, execFileAsync } from "./services/childProcess/execFile.js";
|
|
2
|
+
import { execFileSync } from "./services/childProcess/execFileSync.js";
|
|
3
|
+
import { execSync } from "./services/childProcess/execSync.js";
|
|
4
|
+
import { spawn } from "./services/childProcess/spawn.js";
|
|
5
|
+
import { spawnSync } from "./services/childProcess/spawnSync.js";
|
|
6
|
+
export { execFile, execFileAsync, execFileSync, execSync, spawn, spawnSync };
|
package/dist/child-process.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(execFile, promisify.custom, { value: (file, ...parameters) => {
|
|
7
|
-
return promisify(execFile$1)(file, ...withHiddenWindow(parameters));
|
|
8
|
-
} });
|
|
9
|
-
const execFileAsync = promisify(execFile);
|
|
10
|
-
// src/services/childProcess/execFileSync.ts
|
|
11
|
-
const execFileSync = ((file, ...parameters) => execFileSync$1(file, ...withHiddenWindow(parameters)));
|
|
12
|
-
// src/services/childProcess/spawn.ts
|
|
13
|
-
const spawn = ((file, ...parameters) => spawn$1(file, ...withHiddenWindow(parameters)));
|
|
14
|
-
// src/services/childProcess/spawnSync.ts
|
|
15
|
-
const spawnSync = ((file, ...parameters) => spawnSync$1(file, ...withHiddenWindow(parameters)));
|
|
1
|
+
import { execFile, execFileAsync } from "./services/childProcess/execFile.js";
|
|
2
|
+
import { execFileSync } from "./services/childProcess/execFileSync.js";
|
|
3
|
+
import { execSync } from "./services/childProcess/execSync.js";
|
|
4
|
+
import { spawn } from "./services/childProcess/spawn.js";
|
|
5
|
+
import { spawnSync } from "./services/childProcess/spawnSync.js";
|
|
16
6
|
export { execFile, execFileAsync, execFileSync, execSync, spawn, spawnSync };
|
package/dist/reporter.js
CHANGED
|
@@ -1,122 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
3
|
-
import { GIBIBYTE, InvalidOperationError, Operation, getResult, getResultAsync, noop, normalizeString, takeOne } from "@esposter/shared";
|
|
4
|
-
import { arch, cpus, platform, release, totalmem } from "node:os";
|
|
5
|
-
import { writeFile } from "node:fs/promises";
|
|
6
|
-
// src/services/readBenchmarkEnvironment.ts
|
|
7
|
-
const readCommit = () => getResult(() => execSync("git rev-parse --short HEAD", {
|
|
8
|
-
encoding: "utf8",
|
|
9
|
-
stdio: "pipe"
|
|
10
|
-
})).match((stdout) => normalizeString(stdout), () => "unknown");
|
|
11
|
-
const readBenchmarkEnvironment = () => {
|
|
12
|
-
const cpu = cpus();
|
|
13
|
-
return [
|
|
14
|
-
`- Commit: ${readCommit()}`,
|
|
15
|
-
`- Node: ${process.version}`,
|
|
16
|
-
`- OS: ${platform()} ${release()} (${arch()})`,
|
|
17
|
-
`- CPU: ${normalizeString(cpu[0]?.model) || "unknown"} × ${cpu.length}`,
|
|
18
|
-
`- RAM: ${(totalmem() / GIBIBYTE).toFixed(1)} GiB`
|
|
19
|
-
].join("\n");
|
|
20
|
-
};
|
|
21
|
-
// src/services/buildBenchmarkFileReport.ts
|
|
22
|
-
const getGroupName = (testCase, benchmarkName, benchmarkCount) => benchmarkCount > 1 ? `${testCase.fullName} > ${benchmarkName}` : testCase.fullName;
|
|
23
|
-
const buildBenchmarkFileReport = (filepath, testCases) => {
|
|
24
|
-
const groups = [];
|
|
25
|
-
for (const testCase of testCases) {
|
|
26
|
-
const testCaseBenchmarks = testCase.benchmarks();
|
|
27
|
-
for (const { name, tasks } of testCaseBenchmarks) {
|
|
28
|
-
const benchmarks = [];
|
|
29
|
-
for (const task of tasks.toSorted((firstTask, secondTask) => firstTask.rank - secondTask.rank)) {
|
|
30
|
-
if (!Number.isFinite(task.latency.mean)) throw new InvalidOperationError(Operation.Read, testCase.fullName, `benchmark "${task.name}" produced no samples — it likely threw on every iteration`);
|
|
31
|
-
benchmarks.push({
|
|
32
|
-
mean: task.latency.mean,
|
|
33
|
-
name: task.name,
|
|
34
|
-
p99: task.latency.p99,
|
|
35
|
-
rme: task.latency.rme,
|
|
36
|
-
sampleCount: task.latency.samplesCount
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (benchmarks.length > 0) groups.push({
|
|
40
|
-
benchmarks,
|
|
41
|
-
fullName: getGroupName(testCase, name, testCaseBenchmarks.length)
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return { files: [{
|
|
46
|
-
filepath,
|
|
47
|
-
groups
|
|
48
|
-
}] };
|
|
49
|
-
};
|
|
50
|
-
// src/services/formatBenchmarkMarkdown.ts
|
|
51
|
-
const getBaseline = (benchmarks) => benchmarks.find(({ name }) => name === "native") ?? benchmarks[0];
|
|
52
|
-
const formatRelative = (baselineMean, mean) => {
|
|
53
|
-
const ratio = baselineMean / mean;
|
|
54
|
-
return `${ratio >= 1 ? ratio.toFixed(2) : Number(ratio.toPrecision(2))}×`;
|
|
55
|
-
};
|
|
56
|
-
const HEADER = [
|
|
57
|
-
"task",
|
|
58
|
-
"vs base",
|
|
59
|
-
"mean (ms)",
|
|
60
|
-
"±rme",
|
|
61
|
-
"p99 (ms)",
|
|
62
|
-
"samples"
|
|
63
|
-
];
|
|
64
|
-
const formatTable = (rows) => {
|
|
65
|
-
const widths = rows.reduce((accumulator, row) => accumulator.map((width, index) => Math.max(width, takeOne(row, index).length)), HEADER.map((header) => header.length));
|
|
66
|
-
const formatRow = (cells) => `| ${cells.map((cell, index) => cell.padEnd(takeOne(widths, index))).join(" | ")} |`;
|
|
67
|
-
return [
|
|
68
|
-
formatRow(HEADER),
|
|
69
|
-
`| ${widths.map((width) => "-".repeat(width)).join(" | ")} |`,
|
|
70
|
-
...rows.map((row) => formatRow(row))
|
|
71
|
-
];
|
|
72
|
-
};
|
|
73
|
-
const formatBenchmarkMarkdown = (report, environment) => {
|
|
74
|
-
return [
|
|
75
|
-
"# Benchmark results",
|
|
76
|
-
"",
|
|
77
|
-
"Auto-generated by the BenchmarkMarkdownReporter on `pnpm bench`, colocated beside the bench file (a",
|
|
78
|
-
"`.bench.json` sits next to it). Diff over time to catch regressions. Tasks are listed fastest first.",
|
|
79
|
-
"`vs base` is a throughput multiplier against each group's baseline (the `native` task, else the",
|
|
80
|
-
"fastest): `1.00×` is the baseline, higher is faster, lower is slower — a fast task drifting back",
|
|
81
|
-
"toward `1.00×` is a regression. `±rme` is the relative margin of error.",
|
|
82
|
-
"Numbers are machine- and commit-dependent (see Environment); only compare runs from the same host.",
|
|
83
|
-
"",
|
|
84
|
-
"## Environment",
|
|
85
|
-
"",
|
|
86
|
-
environment,
|
|
87
|
-
"",
|
|
88
|
-
...report.files.flatMap((file) => file.groups.map((group) => {
|
|
89
|
-
const baselineMean = getBaseline(group.benchmarks)?.mean ?? NaN;
|
|
90
|
-
const rows = group.benchmarks.map(({ mean, name, p99, rme, sampleCount }) => [
|
|
91
|
-
name.replaceAll("|", String.raw`\|`),
|
|
92
|
-
formatRelative(baselineMean, mean),
|
|
93
|
-
mean.toFixed(4),
|
|
94
|
-
`±${rme.toFixed(2)}%`,
|
|
95
|
-
p99.toFixed(4),
|
|
96
|
-
`${sampleCount}`
|
|
97
|
-
]);
|
|
98
|
-
return [
|
|
99
|
-
`## ${group.fullName}`,
|
|
100
|
-
"",
|
|
101
|
-
...formatTable(rows),
|
|
102
|
-
""
|
|
103
|
-
].join("\n");
|
|
104
|
-
}))
|
|
105
|
-
].join("\n");
|
|
106
|
-
};
|
|
107
|
-
// src/services/writeBenchmarkReport.ts
|
|
108
|
-
const TS_EXTENSION_REGEX = /\.ts$/u;
|
|
109
|
-
const writeFileOrThrow = (path, contents) => getResultAsync(() => writeFile(path, contents)).match(noop, (error) => {
|
|
110
|
-
throw new InvalidOperationError(Operation.Create, path, error.message);
|
|
111
|
-
});
|
|
112
|
-
const writeBenchmarkReport = async (moduleId, relativeModuleId, testCases, environment) => {
|
|
113
|
-
const report = buildBenchmarkFileReport(relativeModuleId, testCases);
|
|
114
|
-
const [benchmarkFile] = report.files;
|
|
115
|
-
if (benchmarkFile === void 0 || benchmarkFile.groups.length === 0) return;
|
|
116
|
-
const basePath = moduleId.replace(TS_EXTENSION_REGEX, "");
|
|
117
|
-
const reportPath = basePath.endsWith(".platform.bench") ? `${basePath}.${process.platform}` : basePath;
|
|
118
|
-
await Promise.all([writeFileOrThrow(`${reportPath}.json`, `${JSON.stringify(report, null, 2)}\n`), writeFileOrThrow(`${reportPath}.md`, formatBenchmarkMarkdown(report, environment))]);
|
|
119
|
-
};
|
|
1
|
+
import { readBenchmarkEnvironment } from "./services/readBenchmarkEnvironment.js";
|
|
2
|
+
import { writeBenchmarkReport } from "./services/writeBenchmarkReport.js";
|
|
120
3
|
// src/services/BenchmarkMarkdownReporter.ts
|
|
121
4
|
var BenchmarkMarkdownReporter = class {
|
|
122
5
|
async onTestRunEnd(testModules) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { InvalidOperationError, Operation } from "@esposter/shared";
|
|
2
|
+
// src/services/buildBenchmarkFileReport.ts
|
|
3
|
+
const getGroupName = (testCase, benchmarkName, benchmarkCount) => benchmarkCount > 1 ? `${testCase.fullName} > ${benchmarkName}` : testCase.fullName;
|
|
4
|
+
const buildBenchmarkFileReport = (filepath, testCases) => {
|
|
5
|
+
const groups = [];
|
|
6
|
+
for (const testCase of testCases) {
|
|
7
|
+
const testCaseBenchmarks = testCase.benchmarks();
|
|
8
|
+
for (const { name, tasks } of testCaseBenchmarks) {
|
|
9
|
+
const benchmarks = [];
|
|
10
|
+
for (const task of tasks.toSorted((firstTask, secondTask) => firstTask.rank - secondTask.rank)) {
|
|
11
|
+
if (!Number.isFinite(task.latency.mean)) throw new InvalidOperationError(Operation.Read, testCase.fullName, `benchmark "${task.name}" produced no samples — it likely threw on every iteration`);
|
|
12
|
+
benchmarks.push({
|
|
13
|
+
mean: task.latency.mean,
|
|
14
|
+
name: task.name,
|
|
15
|
+
p99: task.latency.p99,
|
|
16
|
+
rme: task.latency.rme,
|
|
17
|
+
sampleCount: task.latency.samplesCount
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (benchmarks.length > 0) groups.push({
|
|
21
|
+
benchmarks,
|
|
22
|
+
fullName: getGroupName(testCase, name, testCaseBenchmarks.length)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { files: [{
|
|
27
|
+
filepath,
|
|
28
|
+
groups
|
|
29
|
+
}] };
|
|
30
|
+
};
|
|
31
|
+
export { buildBenchmarkFileReport };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SITE_NAME } from "@esposter/shared";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// src/services/cache/constants.ts
|
|
5
|
+
const CACHE_ROOT = join(homedir(), SITE_NAME, "cache");
|
|
6
|
+
const CONTENT_CACHE_DIRECTORY = join(CACHE_ROOT, "content");
|
|
7
|
+
export { CACHE_ROOT, CONTENT_CACHE_DIRECTORY };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const readContentAddressedObject: (hash: string, download: () => Promise<Uint8Array>, directory?: string) => Promise<Buffer>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CONTENT_CACHE_DIRECTORY } from "./constants.js";
|
|
2
|
+
import { writePartialThenMove } from "./writePartialThenMove.js";
|
|
3
|
+
import { InvalidOperationError, Operation, getResultAsync, noop } from "@esposter/shared";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
// src/services/cache/readContentAddressedObject.ts
|
|
9
|
+
const SHA_256_HEX_REGEX = /^[0-9a-f]{64}$/u;
|
|
10
|
+
const readContentAddressedObject = async (hash, download, directory = CONTENT_CACHE_DIRECTORY) => {
|
|
11
|
+
if (!SHA_256_HEX_REGEX.test(hash)) throw new InvalidOperationError(Operation.Read, hash, "is not a SHA-256 hex digest");
|
|
12
|
+
const path = join(directory, hash);
|
|
13
|
+
if (existsSync(path)) return readFile(path);
|
|
14
|
+
const bytes = Buffer.from(await download());
|
|
15
|
+
if (createHash("sha256").update(bytes).digest("hex") !== hash) throw new InvalidOperationError(Operation.Read, hash, "does not hash to its name");
|
|
16
|
+
await getResultAsync(() => writePartialThenMove(path, (partialPath) => writeFile(partialPath, bytes))).match(noop, (error) => {
|
|
17
|
+
if (!existsSync(path)) throw error;
|
|
18
|
+
});
|
|
19
|
+
return bytes;
|
|
20
|
+
};
|
|
21
|
+
export { readContentAddressedObject };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const writePartialThenMove: (path: string, write: (partialPath: string) => Promise<void>) => Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getResultAsync, noop } from "@esposter/shared";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { rmSync } from "node:fs";
|
|
4
|
+
import { mkdir, rename } from "node:fs/promises";
|
|
5
|
+
// src/services/cache/writePartialThenMove.ts
|
|
6
|
+
const writePartialThenMove = async (path, write) => {
|
|
7
|
+
await mkdir(dirname(path), { recursive: true });
|
|
8
|
+
const partialPath = `${path}.${crypto.randomUUID()}.part`;
|
|
9
|
+
(await getResultAsync(async () => {
|
|
10
|
+
await write(partialPath);
|
|
11
|
+
await rename(partialPath, path);
|
|
12
|
+
})).match(noop, (error) => {
|
|
13
|
+
rmSync(partialPath, { force: true });
|
|
14
|
+
throw error;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export { writePartialThenMove };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { withHiddenWindow } from "./withHiddenWindow.js";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
// src/services/childProcess/execFile.ts
|
|
5
|
+
const execFile$1 = ((file, ...parameters) => execFile(file, ...withHiddenWindow(parameters)));
|
|
6
|
+
Object.defineProperty(execFile$1, promisify.custom, { value: (file, ...parameters) => {
|
|
7
|
+
return promisify(execFile)(file, ...withHiddenWindow(parameters));
|
|
8
|
+
} });
|
|
9
|
+
const execFileAsync = promisify(execFile$1);
|
|
10
|
+
export { execFile$1 as execFile, execFileAsync };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { withHiddenWindow } from "./withHiddenWindow.js";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
// src/services/childProcess/execFileSync.ts
|
|
4
|
+
const execFileSync$1 = ((file, ...parameters) => execFileSync(file, ...withHiddenWindow(parameters)));
|
|
5
|
+
export { execFileSync$1 as execFileSync };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { withHiddenWindow } from "./withHiddenWindow.js";
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
// src/services/childProcess/execSync.ts
|
|
4
|
+
const execSync$1 = ((command, ...parameters) => execSync(command, ...withHiddenWindow(parameters)));
|
|
5
|
+
export { execSync$1 as execSync };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { withHiddenWindow } from "./withHiddenWindow.js";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
// src/services/childProcess/spawnSync.ts
|
|
4
|
+
const spawnSync$1 = ((file, ...parameters) => spawnSync(file, ...withHiddenWindow(parameters)));
|
|
5
|
+
export { spawnSync$1 as spawnSync };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { execSync } from "node:child_process";
|
|
2
1
|
// src/services/childProcess/withHiddenWindow.ts
|
|
3
2
|
const withHiddenWindow = (parameters) => {
|
|
4
3
|
const optionsIndex = Array.isArray(parameters[0]) || parameters[0] === void 0 && parameters.length > 1 ? 1 : 0;
|
|
@@ -10,6 +9,4 @@ const withHiddenWindow = (parameters) => {
|
|
|
10
9
|
const isPlaceholder = options === void 0 && optionsIndex < parameters.length;
|
|
11
10
|
return parameters.toSpliced(optionsIndex, Number(isPlaceholder), { windowsHide: true });
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
const execSync$1 = ((command, ...parameters) => execSync(command, ...withHiddenWindow(parameters)));
|
|
15
|
-
export { withHiddenWindow as n, execSync$1 as t };
|
|
12
|
+
export { withHiddenWindow };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import "../bench.js";
|
|
2
|
+
import { takeOne } from "@esposter/shared";
|
|
3
|
+
// src/services/formatBenchmarkMarkdown.ts
|
|
4
|
+
const getBaseline = (benchmarks) => benchmarks.find(({ name }) => name === "native") ?? benchmarks[0];
|
|
5
|
+
const formatRelative = (baselineMean, mean) => {
|
|
6
|
+
const ratio = baselineMean / mean;
|
|
7
|
+
return `${ratio >= 1 ? ratio.toFixed(2) : Number(ratio.toPrecision(2))}×`;
|
|
8
|
+
};
|
|
9
|
+
const HEADER = [
|
|
10
|
+
"task",
|
|
11
|
+
"vs base",
|
|
12
|
+
"mean (ms)",
|
|
13
|
+
"±rme",
|
|
14
|
+
"p99 (ms)",
|
|
15
|
+
"samples"
|
|
16
|
+
];
|
|
17
|
+
const formatTable = (rows) => {
|
|
18
|
+
const widths = rows.reduce((accumulator, row) => accumulator.map((width, index) => Math.max(width, takeOne(row, index).length)), HEADER.map((header) => header.length));
|
|
19
|
+
const formatRow = (cells) => `| ${cells.map((cell, index) => cell.padEnd(takeOne(widths, index))).join(" | ")} |`;
|
|
20
|
+
return [
|
|
21
|
+
formatRow(HEADER),
|
|
22
|
+
`| ${widths.map((width) => "-".repeat(width)).join(" | ")} |`,
|
|
23
|
+
...rows.map((row) => formatRow(row))
|
|
24
|
+
];
|
|
25
|
+
};
|
|
26
|
+
const formatBenchmarkMarkdown = (report, environment) => {
|
|
27
|
+
return [
|
|
28
|
+
"# Benchmark results",
|
|
29
|
+
"",
|
|
30
|
+
"Auto-generated by the BenchmarkMarkdownReporter on `pnpm bench`, colocated beside the bench file (a",
|
|
31
|
+
"`.bench.json` sits next to it). Diff over time to catch regressions. Tasks are listed fastest first.",
|
|
32
|
+
"`vs base` is a throughput multiplier against each group's baseline (the `native` task, else the",
|
|
33
|
+
"fastest): `1.00×` is the baseline, higher is faster, lower is slower — a fast task drifting back",
|
|
34
|
+
"toward `1.00×` is a regression. `±rme` is the relative margin of error.",
|
|
35
|
+
"Numbers are machine- and commit-dependent (see Environment); only compare runs from the same host.",
|
|
36
|
+
"",
|
|
37
|
+
"## Environment",
|
|
38
|
+
"",
|
|
39
|
+
environment,
|
|
40
|
+
"",
|
|
41
|
+
...report.files.flatMap((file) => file.groups.map((group) => {
|
|
42
|
+
const baselineMean = getBaseline(group.benchmarks)?.mean ?? NaN;
|
|
43
|
+
const rows = group.benchmarks.map(({ mean, name, p99, rme, sampleCount }) => [
|
|
44
|
+
name.replaceAll("|", String.raw`\|`),
|
|
45
|
+
formatRelative(baselineMean, mean),
|
|
46
|
+
mean.toFixed(4),
|
|
47
|
+
`±${rme.toFixed(2)}%`,
|
|
48
|
+
p99.toFixed(4),
|
|
49
|
+
`${sampleCount}`
|
|
50
|
+
]);
|
|
51
|
+
return [
|
|
52
|
+
`## ${group.fullName}`,
|
|
53
|
+
"",
|
|
54
|
+
...formatTable(rows),
|
|
55
|
+
""
|
|
56
|
+
].join("\n");
|
|
57
|
+
}))
|
|
58
|
+
].join("\n");
|
|
59
|
+
};
|
|
60
|
+
export { formatBenchmarkMarkdown };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { execSync } from "./childProcess/execSync.js";
|
|
2
|
+
import { GIBIBYTE, getResult, normalizeString } from "@esposter/shared";
|
|
3
|
+
import { arch, cpus, platform, release, totalmem } from "node:os";
|
|
4
|
+
// src/services/readBenchmarkEnvironment.ts
|
|
5
|
+
const readCommit = () => getResult(() => execSync("git rev-parse --short HEAD", {
|
|
6
|
+
encoding: "utf8",
|
|
7
|
+
stdio: "pipe"
|
|
8
|
+
})).match((stdout) => normalizeString(stdout), () => "unknown");
|
|
9
|
+
const readBenchmarkEnvironment = () => {
|
|
10
|
+
const cpu = cpus();
|
|
11
|
+
return [
|
|
12
|
+
`- Commit: ${readCommit()}`,
|
|
13
|
+
`- Node: ${process.version}`,
|
|
14
|
+
`- OS: ${platform()} ${release()} (${arch()})`,
|
|
15
|
+
`- CPU: ${normalizeString(cpu[0]?.model) || "unknown"} × ${cpu.length}`,
|
|
16
|
+
`- RAM: ${(totalmem() / GIBIBYTE).toFixed(1)} GiB`
|
|
17
|
+
].join("\n");
|
|
18
|
+
};
|
|
19
|
+
export { readBenchmarkEnvironment };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { buildBenchmarkFileReport } from "./buildBenchmarkFileReport.js";
|
|
2
|
+
import { formatBenchmarkMarkdown } from "./formatBenchmarkMarkdown.js";
|
|
3
|
+
import { InvalidOperationError, Operation, getResultAsync, noop } from "@esposter/shared";
|
|
4
|
+
import { writeFile } from "node:fs/promises";
|
|
5
|
+
// src/services/writeBenchmarkReport.ts
|
|
6
|
+
const TS_EXTENSION_REGEX = /\.ts$/u;
|
|
7
|
+
const writeFileOrThrow = (path, contents) => getResultAsync(() => writeFile(path, contents)).match(noop, (error) => {
|
|
8
|
+
throw new InvalidOperationError(Operation.Create, path, error.message);
|
|
9
|
+
});
|
|
10
|
+
const writeBenchmarkReport = async (moduleId, relativeModuleId, testCases, environment) => {
|
|
11
|
+
const report = buildBenchmarkFileReport(relativeModuleId, testCases);
|
|
12
|
+
const [benchmarkFile] = report.files;
|
|
13
|
+
if (benchmarkFile === void 0 || benchmarkFile.groups.length === 0) return;
|
|
14
|
+
const basePath = moduleId.replace(TS_EXTENSION_REGEX, "");
|
|
15
|
+
const reportPath = basePath.endsWith(".platform.bench") ? `${basePath}.${process.platform}` : basePath;
|
|
16
|
+
await Promise.all([writeFileOrThrow(`${reportPath}.json`, `${JSON.stringify(report, null, 2)}\n`), writeFileOrThrow(`${reportPath}.md`, formatBenchmarkMarkdown(report, environment))]);
|
|
17
|
+
};
|
|
18
|
+
export { writeBenchmarkReport };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esposter/shared-node",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "Node-only shared tooling: the machine-wide download cache, hidden-window child processes, and benchmark reporting reused across packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"benchmark",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"typecheck": "tsrs --fast"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@esposter/shared": "4.
|
|
53
|
+
"@esposter/shared": "4.8.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@esposter/configuration": "4.
|
|
56
|
+
"@esposter/configuration": "4.8.0",
|
|
57
57
|
"@types/node": "^26.6.6",
|
|
58
58
|
"tsdown": "^0.23.7"
|
|
59
59
|
},
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"optional": true
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "a76179895911c8c93401873a6bd5895658977592"
|
|
69
69
|
}
|