@ac-bench/reporter-json 0.1.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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # @ac-bench/reporter-json
2
+
3
+ Writes a benchmark run to a single JSON document, one section per measure, when
4
+ the run ends. The section's shape is whatever the measure's own plugin produces:
5
+ this reporter adds no schema of its own.
6
+
7
+ ```ts
8
+ import { defineConfig } from "@ac-bench/cli";
9
+ import jsonReporter from "@ac-bench/reporter-json";
10
+
11
+ export default defineConfig({
12
+ plugins: [jsonReporter({ output: "artifacts/bench.json" })],
13
+ reporters: ["json"],
14
+ });
15
+ ```
16
+
17
+ `output` defaults to the run's output base name plus `.json`. The default export
18
+ is a factory because there is something to configure; call it with no arguments
19
+ for the defaults.
20
+
21
+ `@ac-bench/cli` already depends on this package and selects it by id, so listing
22
+ it in `plugins` is only necessary to pass options.
@@ -0,0 +1,8 @@
1
+ import type { ReporterPlugin } from "@ac-bench/core/plugin";
2
+ export type JsonReporterOptions = {
3
+ /** Where to write. Default: the run's output base name plus `.json`. */
4
+ readonly output?: string;
5
+ };
6
+ /** The whole run as one JSON document, written when the run ends. */
7
+ export default function jsonReporter(options?: JsonReporterOptions): ReporterPlugin;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,cAAc,EACd,MAAM,uBAAuB,CAAC;AAS/B,MAAM,MAAM,mBAAmB,GAAG;IACjC,wEAAwE;IACxE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,OAAO,GAAE,mBAAwB,GAC/B,cAAc,CAShB"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { buildConditionInput, defineReporterPlugin, groupCaseResultsByMeasure, } from "@ac-bench/core/plugin";
2
+ import { AggregateSink } from "@ac-kit/app-report";
3
+ /** The whole run as one JSON document, written when the run ends. */
4
+ export default function jsonReporter(options = {}) {
5
+ return defineReporterPlugin({
6
+ id: "json",
7
+ createSink: (context) => new AggregateSink(context.openOutput(options.output ?? `${context.defaultOutput}.json`), { formatter: formatJson_(context) }),
8
+ });
9
+ }
10
+ /** Serialises every measure present in `run` into one JSON document. */
11
+ function formatJson_(context) {
12
+ return (run) => {
13
+ const merged = {};
14
+ for (const [measureId, caseResults] of groupCaseResultsByMeasure(run.data)) {
15
+ if (caseResults.length === 0) {
16
+ continue;
17
+ }
18
+ const plugin = context.registry.resolve(measureId);
19
+ const section = plugin.toJsonCondition(buildConditionInput(measureId, caseResults));
20
+ Object.assign(merged, section);
21
+ }
22
+ return `${JSON.stringify(merged, null, 2)}\n`;
23
+ };
24
+ }
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOnD,qEAAqE;AACrE,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,OAAO,GAAwB,EAAE;IAEjC,OAAO,oBAAoB,CAAC;QAC3B,EAAE,EAAE,MAAM;QACV,UAAU,EAAE,CAAC,OAAO,EAAE,EAAE,CACvB,IAAI,aAAa,CAChB,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,OAAO,CAAC,EACrE,EAAE,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CACnC;KACF,CAAC,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,SAAS,WAAW,CACnB,OAAwB;IAExB,OAAO,CAAC,GAAG,EAAE,EAAE;QACd,MAAM,MAAM,GAA4B,EAAE,CAAC;QAE3C,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,yBAAyB,CAC/D,GAAG,CAAC,IAAI,CACR,EAAE,CAAC;YACH,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC9B,SAAS;YACV,CAAC;YACD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACnD,MAAM,OAAO,GAAG,MAAM,CAAC,eAAe,CACrC,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC,CAC3C,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAkC,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IAC/C,CAAC,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@ac-bench/reporter-json",
3
+ "version": "0.1.0",
4
+ "description": "JSON reporter for @ac-bench: writes a run to a single document, one section per measure.",
5
+ "keywords": [
6
+ "benchmark",
7
+ "json",
8
+ "reporter"
9
+ ],
10
+ "homepage": "https://github.com/anthochamp/node-essentials/tree/main/bench/reporter-json#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/anthochamp/node-essentials/issues"
13
+ },
14
+ "license": "BSD-3-Clause",
15
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
19
+ "directory": "bench/reporter-json"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "main": "./dist/index.js",
27
+ "exports": {
28
+ ".": "./dist/index.js"
29
+ },
30
+ "publishConfig": {
31
+ "main": "./dist/index.js",
32
+ "exports": {
33
+ ".": "./dist/index.js"
34
+ },
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "compile": "tsc -p ./tsconfig.build.json --outDir dist",
39
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
40
+ "clean": "rimraf dist",
41
+ "build": "yarn clean && yarn compile",
42
+ "test": "yarn run -T vitest run",
43
+ "prepack": "yarn build"
44
+ },
45
+ "dependencies": {
46
+ "@ac-bench/core": "^0.1.0",
47
+ "@ac-kit/app-report": "^0.1.0",
48
+ "@types/web": "^0.0.354"
49
+ },
50
+ "devDependencies": {
51
+ "@ac-kit/model-dataset": "^0.1.0",
52
+ "@ac-kit/tsconfig": "0.1.0",
53
+ "@ac-kit/typedoc-config": "0.1.0",
54
+ "@ac-kit/vitest-config": "0.1.0",
55
+ "@typescript/native": "typescript@7.0.2",
56
+ "rimraf": "6.1.3",
57
+ "typedoc": "0.28.20",
58
+ "typescript": "@typescript/typescript6@6.0.2",
59
+ "vite": "8.3.0",
60
+ "vitest": "5.0.0"
61
+ },
62
+ "engines": {
63
+ "node": ">=24"
64
+ }
65
+ }