@browsercore/dev 0.1.2 → 0.2.1
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 +21 -0
- package/README.md +63 -53
- package/bin/coverage-md.mjs +17 -58
- package/dist/coverage-md.d.ts +188 -17
- package/dist/coverage-md.d.ts.map +1 -1
- package/dist/coverage-md.js +151 -25
- package/dist/coverage-md.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/oxlint.d.ts +15 -5
- package/dist/oxlint.d.ts.map +1 -1
- package/dist/oxlint.js +15 -5
- package/dist/oxlint.js.map +1 -1
- package/dist/vitest.d.ts +35 -3
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +19 -2
- package/dist/vitest.js.map +1 -1
- package/package.json +74 -65
- package/CODING_STANDARDS.md +0 -205
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jens Verneuer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
CHANGED
|
@@ -1,76 +1,86 @@
|
|
|
1
1
|
# @browsercore/dev
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
non-extendable GitHub files arrive via a sync script.
|
|
3
|
+
[](https://www.npmjs.com/package/@browsercore/dev)
|
|
4
|
+
[](https://github.com/jverneuer/browsercore-dev/blob/main/COVERAGE.md)
|
|
5
|
+
[](LICENSE)
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Shared build, lint, test, and coverage tooling for every `@browsercore/*` package. One published package is the single source of truth; consumers extend it live via npm.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
| --- | --- |
|
|
12
|
-
| `tsconfig` strict flags | `tsconfig.json` `"extends": "@browsercore/dev/tsconfig.base.json"` |
|
|
13
|
-
| `vitest` config | factory import: `definePackageConfig({ name })` from `@browsercore/dev/vitest` |
|
|
14
|
-
| `.oxlintrc.json` → `oxlint.config.ts` | import the base object from `@browsercore/dev/oxlint` |
|
|
15
|
-
| `coverage-md` (coverage report generator) | npm `bin` |
|
|
16
|
-
| `CODING_STANDARDS.md`, `.github/{ci.yml,ruleset.json,bootstrap-ruleset.sh}` | `scripts/sync.mjs` (GitHub reads only each repo's own `.github/`) |
|
|
17
|
-
|
|
18
|
-
Why a TS import for oxlint rather than `.oxlintrc.json` `extends`: oxlint's JSON
|
|
19
|
-
`extends` resolves only relative file paths, not `node_modules`
|
|
20
|
-
(see oxc-project/oxc#15538). The `oxlint.config.ts` form imports the config object
|
|
21
|
-
directly, which resolves through `node_modules`.
|
|
22
|
-
|
|
23
|
-
## Consumer adoption (per repo)
|
|
9
|
+
## Install
|
|
24
10
|
|
|
25
11
|
```sh
|
|
26
|
-
# 1. depend on it (use the npm version once published; locally: file:../dev)
|
|
27
12
|
npm install -D @browsercore/dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
28
16
|
|
|
29
|
-
|
|
30
|
-
# { "extends": "@browsercore/dev/tsconfig.base.json",
|
|
31
|
-
# "compilerOptions": { "rootDir": "src", "outDir": "dist" },
|
|
32
|
-
# "include": ["src/**/*.ts"], "exclude": ["node_modules","dist","tests","scripts"] }
|
|
17
|
+
### tsconfig
|
|
33
18
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"extends": "@browsercore/dev/tsconfig.base.json",
|
|
22
|
+
"compilerOptions": { "rootDir": "src", "outDir": "dist" },
|
|
23
|
+
"include": ["src/**/*.ts"],
|
|
24
|
+
"exclude": ["node_modules", "dist", "tests"]
|
|
25
|
+
}
|
|
26
|
+
```
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
# import { defineConfig } from "oxlint";
|
|
40
|
-
# import base from "@browsercore/dev/oxlint";
|
|
41
|
-
# export default defineConfig({ extends: [base] });
|
|
28
|
+
For builds that emit declarations, extend `@browsercore/dev/tsconfig.build.base.json` instead (layers `declaration`, `declarationMap`, `sourceMap` on top of the base).
|
|
42
29
|
|
|
43
|
-
|
|
30
|
+
### vitest
|
|
44
31
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
```ts
|
|
33
|
+
import { definePackageConfig } from "@browsercore/dev/vitest";
|
|
34
|
+
|
|
35
|
+
export default definePackageConfig({ name: "<pkg>" });
|
|
48
36
|
```
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
`definePackageConfig` wires in the shared reporters (`text`, `html`, `json-summary`), v8 coverage over `src/**/*.ts`, and 30s test/hook timeouts. The `html` + `json-summary` artifacts are what the coverage report reads. Pass `{ include, coverage }` to override test globs or append coverage excludes.
|
|
39
|
+
|
|
40
|
+
### oxlint
|
|
41
|
+
|
|
42
|
+
oxlint's JSON `extends` only resolves relative file paths (not `node_modules`), so the base is consumed via a TS import:
|
|
52
43
|
|
|
53
|
-
|
|
44
|
+
```ts
|
|
45
|
+
import { defineConfig } from "oxlint";
|
|
46
|
+
import base from "@browsercore/dev/oxlint";
|
|
54
47
|
|
|
48
|
+
export default defineConfig({ extends: [base] });
|
|
55
49
|
```
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
|
|
51
|
+
Type-aware linting (`--type-aware`) requires `oxlint-tsgolint` in the consumer's devDependencies.
|
|
52
|
+
|
|
53
|
+
### coverage-md
|
|
54
|
+
|
|
55
|
+
After running vitest with coverage, generate a `COVERAGE.md` report + shields.io badge:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
npx vitest run --coverage
|
|
59
|
+
npx coverage-md
|
|
65
60
|
```
|
|
66
61
|
|
|
67
|
-
|
|
62
|
+
The bin reads `coverage/coverage-summary.json` (written by the `json-summary` reporter) and writes `COVERAGE.md` and `coverage/badge.json` to the package root.
|
|
63
|
+
|
|
64
|
+
## Scripts
|
|
65
|
+
|
|
66
|
+
| Command | Runs |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| `npm run typecheck` | `tsc -p tsconfig.json --noEmit` |
|
|
69
|
+
| `npm run lint` | `oxlint --type-aware src/` |
|
|
70
|
+
| `npm test` | `vitest run` |
|
|
71
|
+
| `npm run build` | `tsc -p tsconfig.build.json` |
|
|
72
|
+
|
|
73
|
+
## Coverage report
|
|
74
|
+
|
|
75
|
+
To produce a coverage report:
|
|
68
76
|
|
|
69
77
|
```sh
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
npm run build
|
|
73
|
-
npm run lint -- --deny-warnings
|
|
78
|
+
npx vitest run --coverage
|
|
79
|
+
node scripts/coverage-md.mjs # writes COVERAGE.md + coverage/badge.json
|
|
74
80
|
```
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
Provider is `@vitest/coverage-v8`. The report is generated from `coverage/coverage-summary.json`.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT
|
package/bin/coverage-md.mjs
CHANGED
|
@@ -9,20 +9,27 @@
|
|
|
9
9
|
* Distributed as the `coverage-md` bin of @browsercore/dev, replacing the
|
|
10
10
|
* per-repo scripts/coverage-md.mjs copies.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* The bin is a thin I/O wrapper: all rendering logic and the boundary
|
|
13
|
+
* validation schema live in the compiled output (`dist/coverage-md.js`);
|
|
14
|
+
* this file reads JSON, validates it, renders, and writes results.
|
|
13
15
|
*/
|
|
14
16
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
15
17
|
import { join, relative } from "node:path";
|
|
18
|
+
import {
|
|
19
|
+
renderCoverageMarkdown,
|
|
20
|
+
renderBadge,
|
|
21
|
+
CoverageSummarySchema,
|
|
22
|
+
} from "../dist/coverage-md.js";
|
|
16
23
|
|
|
17
24
|
const pkgRoot = process.cwd();
|
|
18
25
|
const summaryPath = join(pkgRoot, "coverage", "coverage-summary.json");
|
|
19
26
|
const outPath = join(pkgRoot, "COVERAGE.md");
|
|
20
|
-
const badgePath = join(pkgRoot, "
|
|
27
|
+
const badgePath = join(pkgRoot, ".github", "coverage-badge.json");
|
|
21
28
|
|
|
22
|
-
/** @type {
|
|
23
|
-
let
|
|
29
|
+
/** @type {unknown} */
|
|
30
|
+
let raw;
|
|
24
31
|
try {
|
|
25
|
-
|
|
32
|
+
raw = readFileSync(summaryPath, "utf-8");
|
|
26
33
|
} catch {
|
|
27
34
|
console.error(
|
|
28
35
|
`[coverage-md] Could not read ${summaryPath}. ` +
|
|
@@ -31,23 +38,9 @@ try {
|
|
|
31
38
|
process.exit(1);
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
const
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {Object} Metric
|
|
37
|
-
* @property {string} label
|
|
38
|
-
* @property {keyof typeof total} key
|
|
39
|
-
*/
|
|
40
|
-
/** @type {Metric[]} */
|
|
41
|
-
const metrics = [
|
|
42
|
-
{ label: "Statements", key: "statements" },
|
|
43
|
-
{ label: "Branches", key: "branches" },
|
|
44
|
-
{ label: "Functions", key: "functions" },
|
|
45
|
-
{ label: "Lines", key: "lines" },
|
|
46
|
-
];
|
|
47
|
-
/** @param {{pct:number,covered:number,total:number}} m */
|
|
48
|
-
const render = (m) => `${m.pct}% (${m.covered}/${m.total})`;
|
|
41
|
+
const parsed = CoverageSummarySchema.parse(JSON.parse(raw));
|
|
49
42
|
|
|
50
|
-
const fileEntries = Object.entries(
|
|
43
|
+
const fileEntries = Object.entries(parsed)
|
|
51
44
|
.filter(([key]) => key !== "total")
|
|
52
45
|
.map(([file, m]) => {
|
|
53
46
|
// coverage-summary.json keys are absolute paths; show repo-relative.
|
|
@@ -56,44 +49,10 @@ const fileEntries = Object.entries(data)
|
|
|
56
49
|
})
|
|
57
50
|
.sort((a, b) => a.file.localeCompare(b.file));
|
|
58
51
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
lines.push("");
|
|
62
|
-
lines.push(`Generated from \`coverage-summary.json\` by \`coverage-md\` (@browsercore/dev).`);
|
|
63
|
-
lines.push("");
|
|
64
|
-
lines.push(`## Total`);
|
|
65
|
-
lines.push("");
|
|
66
|
-
lines.push(`| Metric | Coverage |`);
|
|
67
|
-
lines.push(`| --- | --- |`);
|
|
68
|
-
for (const { label, key } of metrics) {
|
|
69
|
-
lines.push(`| ${label} | ${render(total[key])} |`);
|
|
70
|
-
}
|
|
71
|
-
lines.push("");
|
|
72
|
-
lines.push(`## Per-file`);
|
|
73
|
-
lines.push("");
|
|
74
|
-
const header = `| File | ${metrics.map((m) => m.label).join(" | ")} |`;
|
|
75
|
-
const sep = `| --- | ${metrics.map(() => "---").join(" | ")} |`;
|
|
76
|
-
lines.push(header);
|
|
77
|
-
lines.push(sep);
|
|
78
|
-
for (const { file, m } of fileEntries) {
|
|
79
|
-
lines.push(`| \`${file}\` | ${metrics.map((met) => render(m[met.key])).join(" | ")} |`);
|
|
80
|
-
}
|
|
81
|
-
lines.push("");
|
|
82
|
-
|
|
83
|
-
writeFileSync(outPath, lines.join("\n"));
|
|
52
|
+
const md = renderCoverageMarkdown(parsed, fileEntries);
|
|
53
|
+
writeFileSync(outPath, md);
|
|
84
54
|
console.log(`[coverage-md] wrote ${relative(process.cwd(), outPath)}`);
|
|
85
55
|
|
|
86
|
-
|
|
87
|
-
// README badge. Color tiers mirror shields.io conventions.
|
|
88
|
-
const pct = total.statements.pct;
|
|
89
|
-
const badgeColor =
|
|
90
|
-
pct >= 90 ? "brightgreen" : pct >= 75 ? "green" : pct >= 50 ? "yellow" : "red";
|
|
91
|
-
const badge = {
|
|
92
|
-
schemaVersion: 1,
|
|
93
|
-
label: "coverage",
|
|
94
|
-
message: `${pct}%`,
|
|
95
|
-
color: badgeColor,
|
|
96
|
-
namedLogo: "vitest",
|
|
97
|
-
};
|
|
56
|
+
const badge = renderBadge(parsed.total.statements.pct);
|
|
98
57
|
writeFileSync(badgePath, JSON.stringify(badge));
|
|
99
58
|
console.log(`[coverage-md] wrote ${relative(process.cwd(), badgePath)}`);
|
package/dist/coverage-md.d.ts
CHANGED
|
@@ -1,32 +1,202 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pure rendering logic for the coverage-md bin
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
* Pure rendering logic for the coverage-md bin.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `bin/coverage-md.mjs` so it can be unit-tested without
|
|
5
|
+
* touching the filesystem. The bin imports these helpers and handles I/O;
|
|
6
|
+
* everything here is deterministic given a coverage summary.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
/**
|
|
13
|
+
* Schema for a single metric's totals (statements, branches, functions, lines).
|
|
14
|
+
*
|
|
15
|
+
* @since 0.3.0
|
|
16
|
+
*/
|
|
17
|
+
declare const metricTotalsSchema: z.ZodObject<{
|
|
18
|
+
total: z.ZodNumber;
|
|
19
|
+
covered: z.ZodNumber;
|
|
20
|
+
pct: z.ZodNumber;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/**
|
|
23
|
+
* Totals for a single metric (statements, branches, functions, lines).
|
|
24
|
+
*
|
|
25
|
+
* Derived from {@link metricTotalsSchema} so the type and its validator stay
|
|
26
|
+
* in sync.
|
|
27
|
+
*
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export type MetricTotals = z.infer<typeof metricTotalsSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* The shape of v8's `coverage-summary.json` file.
|
|
33
|
+
*
|
|
34
|
+
* `total` holds the aggregate; every other key is an absolute file path with
|
|
35
|
+
* the same per-metric shape. The `.catchall` validates every entry (total and
|
|
36
|
+
* per-file) against {@link fileCoverageSchema} without stripping the arbitrary
|
|
37
|
+
* file-path keys the bin iterates over.
|
|
38
|
+
*
|
|
39
|
+
* This is the single source of truth for the coverage shape: the
|
|
40
|
+
* {@link CoverageSummary} type is derived from it via `z.infer`, so the
|
|
41
|
+
* validated runtime shape and the static type can never drift.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.3.0
|
|
44
|
+
*/
|
|
45
|
+
export declare const CoverageSummarySchema: z.ZodObject<{
|
|
46
|
+
total: z.ZodObject<{
|
|
47
|
+
statements: z.ZodObject<{
|
|
48
|
+
total: z.ZodNumber;
|
|
49
|
+
covered: z.ZodNumber;
|
|
50
|
+
pct: z.ZodNumber;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
branches: z.ZodObject<{
|
|
53
|
+
total: z.ZodNumber;
|
|
54
|
+
covered: z.ZodNumber;
|
|
55
|
+
pct: z.ZodNumber;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
functions: z.ZodObject<{
|
|
58
|
+
total: z.ZodNumber;
|
|
59
|
+
covered: z.ZodNumber;
|
|
60
|
+
pct: z.ZodNumber;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
lines: z.ZodObject<{
|
|
63
|
+
total: z.ZodNumber;
|
|
64
|
+
covered: z.ZodNumber;
|
|
65
|
+
pct: z.ZodNumber;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
}, z.core.$catchall<z.ZodObject<{
|
|
69
|
+
statements: z.ZodObject<{
|
|
70
|
+
total: z.ZodNumber;
|
|
71
|
+
covered: z.ZodNumber;
|
|
72
|
+
pct: z.ZodNumber;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
branches: z.ZodObject<{
|
|
75
|
+
total: z.ZodNumber;
|
|
76
|
+
covered: z.ZodNumber;
|
|
77
|
+
pct: z.ZodNumber;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
functions: z.ZodObject<{
|
|
80
|
+
total: z.ZodNumber;
|
|
81
|
+
covered: z.ZodNumber;
|
|
82
|
+
pct: z.ZodNumber;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
lines: z.ZodObject<{
|
|
85
|
+
total: z.ZodNumber;
|
|
86
|
+
covered: z.ZodNumber;
|
|
87
|
+
pct: z.ZodNumber;
|
|
88
|
+
}, z.core.$strip>;
|
|
89
|
+
}, z.core.$strip>>>;
|
|
90
|
+
/**
|
|
91
|
+
* The shape of v8's `coverage-summary.json` file.
|
|
92
|
+
*
|
|
93
|
+
* `total` holds the aggregate; every other key is an absolute file path with
|
|
94
|
+
* the same per-metric shape.
|
|
95
|
+
*
|
|
96
|
+
* Derived from {@link CoverageSummarySchema} so the type and its validator stay
|
|
97
|
+
* in sync.
|
|
98
|
+
*
|
|
99
|
+
* @since 0.1.0
|
|
100
|
+
*/
|
|
101
|
+
export type CoverageSummary = z.infer<typeof CoverageSummarySchema>;
|
|
102
|
+
/**
|
|
103
|
+
* A single coverage metric with a human-readable label and its key in
|
|
104
|
+
* {@link CoverageSummary}.
|
|
105
|
+
*
|
|
106
|
+
* @since 0.1.0
|
|
107
|
+
*/
|
|
19
108
|
export interface Metric {
|
|
109
|
+
/** Human-readable label (e.g. `"Statements"`). */
|
|
20
110
|
label: string;
|
|
111
|
+
/** Key into {@link CoverageSummary.total} (e.g. `"statements"`). */
|
|
21
112
|
key: keyof CoverageSummary["total"];
|
|
22
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* The canonical ordered list of coverage metrics.
|
|
116
|
+
*
|
|
117
|
+
* Used by both the markdown renderer and the badge renderer so they stay in sync.
|
|
118
|
+
*
|
|
119
|
+
* @since 0.1.0
|
|
120
|
+
*/
|
|
23
121
|
export declare const METRICS: Metric[];
|
|
122
|
+
/**
|
|
123
|
+
* Render a single metric as a human-readable string.
|
|
124
|
+
*
|
|
125
|
+
* @param m The metric totals to render.
|
|
126
|
+
* @returns A string like `"85% (17/20)"`.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* renderMetric({ total: 20, covered: 17, pct: 85 });
|
|
131
|
+
* // => "85% (17/20)"
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @since 0.1.0
|
|
135
|
+
*/
|
|
24
136
|
export declare const renderMetric: (m: MetricTotals) => string;
|
|
137
|
+
/**
|
|
138
|
+
* Map a coverage percentage to a badge color.
|
|
139
|
+
*
|
|
140
|
+
* Follows the Shields.io color scheme:
|
|
141
|
+
* - `≥ 90%` → `brightgreen`
|
|
142
|
+
* - `≥ 75%` → `green`
|
|
143
|
+
* - `≥ 50%` → `yellow`
|
|
144
|
+
* - `< 50%` → `red`
|
|
145
|
+
*
|
|
146
|
+
* @param pct Coverage percentage (0–100).
|
|
147
|
+
* @returns The Shields.io color name.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* badgeColor(95); // => "brightgreen"
|
|
152
|
+
* badgeColor(60); // => "yellow"
|
|
153
|
+
* badgeColor(30); // => "red"
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @since 0.1.0
|
|
157
|
+
*/
|
|
25
158
|
export declare const badgeColor: (pct: number) => string;
|
|
159
|
+
/**
|
|
160
|
+
* Render a full coverage report as a Markdown string.
|
|
161
|
+
*
|
|
162
|
+
* Produces a document with a total section and a per-file section, each as
|
|
163
|
+
* a table with columns for statements, branches, functions, and lines.
|
|
164
|
+
*
|
|
165
|
+
* @param data The aggregate coverage summary.
|
|
166
|
+
* @param fileEntries Per-file breakdown (file path + metric totals).
|
|
167
|
+
* @returns A complete Markdown document.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const md = renderCoverageMarkdown(summary, [
|
|
172
|
+
* { file: "src/index.ts", m: { statements: { total: 10, covered: 8, pct: 80 }, ... } }
|
|
173
|
+
* ]);
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @since 0.1.0
|
|
177
|
+
*/
|
|
26
178
|
export declare const renderCoverageMarkdown: (data: CoverageSummary, fileEntries: Array<{
|
|
27
179
|
file: string;
|
|
28
180
|
m: CoverageSummary["total"];
|
|
29
181
|
}>) => string;
|
|
182
|
+
/**
|
|
183
|
+
* Render a Shields.io-compatible coverage badge JSON object.
|
|
184
|
+
*
|
|
185
|
+
* The returned object can be written to a JSON file and served as a badge
|
|
186
|
+
* endpoint, or consumed directly by Shields.io's endpoint badge format.
|
|
187
|
+
*
|
|
188
|
+
* @param statementsPct The statements coverage percentage (0–100).
|
|
189
|
+
* @returns A badge object with `schemaVersion`, `label`, `message`, `color`, and `namedLogo`.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* renderBadge(87);
|
|
194
|
+
* // => { schemaVersion: 1, label: "coverage", message: "87%", color: "green", namedLogo: "vitest" }
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* @see {@link https://shields.io/badges Shields.io badge format}
|
|
198
|
+
* @since 0.1.0
|
|
199
|
+
*/
|
|
30
200
|
export declare const renderBadge: (statementsPct: number) => {
|
|
31
201
|
schemaVersion: number;
|
|
32
202
|
label: string;
|
|
@@ -34,4 +204,5 @@ export declare const renderBadge: (statementsPct: number) => {
|
|
|
34
204
|
color: string;
|
|
35
205
|
namedLogo: string;
|
|
36
206
|
};
|
|
207
|
+
export {};
|
|
37
208
|
//# sourceMappingURL=coverage-md.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage-md.d.ts","sourceRoot":"","sources":["../src/coverage-md.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"coverage-md.d.ts","sourceRoot":"","sources":["../src/coverage-md.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,QAAA,MAAM,kBAAkB;;;;iBAOtB,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAc9D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAID,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACnB,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,GAAG,EAAE,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,EAK3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,MAAO,YAAY,KAAG,MAA+C,CAAC;AAE/F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,MACyC,CAAC;AAEnF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,sBAAsB,SACzB,eAAe,eACR,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,KAClE,MA4BF,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,WAAW,kBACL,MAAM,KACtB;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAM1F,CAAC"}
|
package/dist/coverage-md.js
CHANGED
|
@@ -1,7 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pure rendering logic for the coverage-md bin
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Pure rendering logic for the coverage-md bin.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `bin/coverage-md.mjs` so it can be unit-tested without
|
|
5
|
+
* touching the filesystem. The bin imports these helpers and handles I/O;
|
|
6
|
+
* everything here is deterministic given a coverage summary.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
/**
|
|
13
|
+
* Schema for a single metric's totals (statements, branches, functions, lines).
|
|
14
|
+
*
|
|
15
|
+
* @since 0.3.0
|
|
16
|
+
*/
|
|
17
|
+
const metricTotalsSchema = z.object({
|
|
18
|
+
/** Total number of trackable items. */
|
|
19
|
+
total: z.number(),
|
|
20
|
+
/** Number of items that were covered. */
|
|
21
|
+
covered: z.number(),
|
|
22
|
+
/** Coverage percentage (0–100). */
|
|
23
|
+
pct: z.number(),
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Schema for one file's coverage entry (or the aggregate `total` entry).
|
|
27
|
+
*
|
|
28
|
+
* @since 0.3.0
|
|
29
|
+
*/
|
|
30
|
+
const fileCoverageSchema = z.object({
|
|
31
|
+
statements: metricTotalsSchema,
|
|
32
|
+
branches: metricTotalsSchema,
|
|
33
|
+
functions: metricTotalsSchema,
|
|
34
|
+
lines: metricTotalsSchema,
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* The shape of v8's `coverage-summary.json` file.
|
|
38
|
+
*
|
|
39
|
+
* `total` holds the aggregate; every other key is an absolute file path with
|
|
40
|
+
* the same per-metric shape. The `.catchall` validates every entry (total and
|
|
41
|
+
* per-file) against {@link fileCoverageSchema} without stripping the arbitrary
|
|
42
|
+
* file-path keys the bin iterates over.
|
|
43
|
+
*
|
|
44
|
+
* This is the single source of truth for the coverage shape: the
|
|
45
|
+
* {@link CoverageSummary} type is derived from it via `z.infer`, so the
|
|
46
|
+
* validated runtime shape and the static type can never drift.
|
|
47
|
+
*
|
|
48
|
+
* @since 0.3.0
|
|
49
|
+
*/
|
|
50
|
+
export const CoverageSummarySchema = z
|
|
51
|
+
.object({
|
|
52
|
+
total: fileCoverageSchema,
|
|
53
|
+
})
|
|
54
|
+
.catchall(fileCoverageSchema);
|
|
55
|
+
/**
|
|
56
|
+
* The canonical ordered list of coverage metrics.
|
|
57
|
+
*
|
|
58
|
+
* Used by both the markdown renderer and the badge renderer so they stay in sync.
|
|
59
|
+
*
|
|
60
|
+
* @since 0.1.0
|
|
5
61
|
*/
|
|
6
62
|
export const METRICS = [
|
|
7
63
|
{ label: "Statements", key: "statements" },
|
|
@@ -9,35 +65,105 @@ export const METRICS = [
|
|
|
9
65
|
{ label: "Functions", key: "functions" },
|
|
10
66
|
{ label: "Lines", key: "lines" },
|
|
11
67
|
];
|
|
68
|
+
/**
|
|
69
|
+
* Render a single metric as a human-readable string.
|
|
70
|
+
*
|
|
71
|
+
* @param m The metric totals to render.
|
|
72
|
+
* @returns A string like `"85% (17/20)"`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* renderMetric({ total: 20, covered: 17, pct: 85 });
|
|
77
|
+
* // => "85% (17/20)"
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @since 0.1.0
|
|
81
|
+
*/
|
|
12
82
|
export const renderMetric = (m) => `${m.pct}% (${m.covered}/${m.total})`;
|
|
83
|
+
/**
|
|
84
|
+
* Map a coverage percentage to a badge color.
|
|
85
|
+
*
|
|
86
|
+
* Follows the Shields.io color scheme:
|
|
87
|
+
* - `≥ 90%` → `brightgreen`
|
|
88
|
+
* - `≥ 75%` → `green`
|
|
89
|
+
* - `≥ 50%` → `yellow`
|
|
90
|
+
* - `< 50%` → `red`
|
|
91
|
+
*
|
|
92
|
+
* @param pct Coverage percentage (0–100).
|
|
93
|
+
* @returns The Shields.io color name.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* badgeColor(95); // => "brightgreen"
|
|
98
|
+
* badgeColor(60); // => "yellow"
|
|
99
|
+
* badgeColor(30); // => "red"
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @since 0.1.0
|
|
103
|
+
*/
|
|
13
104
|
export const badgeColor = (pct) => pct >= 90 ? "brightgreen" : pct >= 75 ? "green" : pct >= 50 ? "yellow" : "red";
|
|
105
|
+
/**
|
|
106
|
+
* Render a full coverage report as a Markdown string.
|
|
107
|
+
*
|
|
108
|
+
* Produces a document with a total section and a per-file section, each as
|
|
109
|
+
* a table with columns for statements, branches, functions, and lines.
|
|
110
|
+
*
|
|
111
|
+
* @param data The aggregate coverage summary.
|
|
112
|
+
* @param fileEntries Per-file breakdown (file path + metric totals).
|
|
113
|
+
* @returns A complete Markdown document.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const md = renderCoverageMarkdown(summary, [
|
|
118
|
+
* { file: "src/index.ts", m: { statements: { total: 10, covered: 8, pct: 80 }, ... } }
|
|
119
|
+
* ]);
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @since 0.1.0
|
|
123
|
+
*/
|
|
14
124
|
export const renderCoverageMarkdown = (data, fileEntries) => {
|
|
15
125
|
const total = data.total;
|
|
16
|
-
const
|
|
17
|
-
lines.push("# Coverage report");
|
|
18
|
-
lines.push("");
|
|
19
|
-
lines.push("Generated from `coverage-summary.json` by `coverage-md` (@browsercore/dev).");
|
|
20
|
-
lines.push("");
|
|
21
|
-
lines.push("## Total");
|
|
22
|
-
lines.push("");
|
|
23
|
-
lines.push("| Metric | Coverage |");
|
|
24
|
-
lines.push("| --- | --- |");
|
|
25
|
-
for (const { label, key } of METRICS) {
|
|
26
|
-
lines.push(`| ${label} | ${renderMetric(total[key])} |`);
|
|
27
|
-
}
|
|
28
|
-
lines.push("");
|
|
29
|
-
lines.push("## Per-file");
|
|
30
|
-
lines.push("");
|
|
126
|
+
const totalRows = METRICS.map(({ label, key }) => `| ${label} | ${renderMetric(total[key])} |`);
|
|
31
127
|
const header = `| File | ${METRICS.map((m) => m.label).join(" | ")} |`;
|
|
32
128
|
const sep = `| --- | ${METRICS.map(() => "---").join(" | ")} |`;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
129
|
+
const fileRows = fileEntries.map(({ file, m }) => `| \`${file}\` | ${METRICS.map((met) => renderMetric(m[met.key])).join(" | ")} |`);
|
|
130
|
+
return [
|
|
131
|
+
"# Coverage report",
|
|
132
|
+
"",
|
|
133
|
+
"Generated from `coverage-summary.json` by `coverage-md` (@browsercore/dev).",
|
|
134
|
+
"",
|
|
135
|
+
"## Total",
|
|
136
|
+
"",
|
|
137
|
+
"| Metric | Coverage |",
|
|
138
|
+
"| --- | --- |",
|
|
139
|
+
...totalRows,
|
|
140
|
+
"",
|
|
141
|
+
"## Per-file",
|
|
142
|
+
"",
|
|
143
|
+
header,
|
|
144
|
+
sep,
|
|
145
|
+
...fileRows,
|
|
146
|
+
"",
|
|
147
|
+
].join("\n");
|
|
40
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Render a Shields.io-compatible coverage badge JSON object.
|
|
151
|
+
*
|
|
152
|
+
* The returned object can be written to a JSON file and served as a badge
|
|
153
|
+
* endpoint, or consumed directly by Shields.io's endpoint badge format.
|
|
154
|
+
*
|
|
155
|
+
* @param statementsPct The statements coverage percentage (0–100).
|
|
156
|
+
* @returns A badge object with `schemaVersion`, `label`, `message`, `color`, and `namedLogo`.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* renderBadge(87);
|
|
161
|
+
* // => { schemaVersion: 1, label: "coverage", message: "87%", color: "green", namedLogo: "vitest" }
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @see {@link https://shields.io/badges Shields.io badge format}
|
|
165
|
+
* @since 0.1.0
|
|
166
|
+
*/
|
|
41
167
|
export const renderBadge = (statementsPct) => ({
|
|
42
168
|
schemaVersion: 1,
|
|
43
169
|
label: "coverage",
|
package/dist/coverage-md.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage-md.js","sourceRoot":"","sources":["../src/coverage-md.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"coverage-md.js","sourceRoot":"","sources":["../src/coverage-md.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public entrypoint for @browsercore/dev.
|
|
3
3
|
*
|
|
4
|
-
* Re-exports the convenience helpers
|
|
4
|
+
* Re-exports the convenience helpers. Consumers normally import the subpath
|
|
5
5
|
* directly (`@browsercore/dev/vitest`, `@browsercore/dev/oxlint`), but the root
|
|
6
6
|
* export is here for `import { definePackageConfig, oxlintBase } from "@browsercore/dev"`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
* @since 0.1.0
|
|
7
10
|
*/
|
|
8
11
|
export { definePackageConfig } from "./vitest.js";
|
|
9
12
|
export { default as oxlintBase } from "./oxlint.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public entrypoint for @browsercore/dev.
|
|
3
3
|
*
|
|
4
|
-
* Re-exports the convenience helpers
|
|
4
|
+
* Re-exports the convenience helpers. Consumers normally import the subpath
|
|
5
5
|
* directly (`@browsercore/dev/vitest`, `@browsercore/dev/oxlint`), but the root
|
|
6
6
|
* export is here for `import { definePackageConfig, oxlintBase } from "@browsercore/dev"`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
* @since 0.1.0
|
|
7
10
|
*/
|
|
8
11
|
export { definePackageConfig } from "./vitest.js";
|
|
9
12
|
export { default as oxlintBase } from "./oxlint.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/oxlint.d.ts
CHANGED
|
@@ -2,18 +2,28 @@ import type { OxlintConfig } from "oxlint";
|
|
|
2
2
|
/**
|
|
3
3
|
* Base oxlint config shared by every @browsercore/* package.
|
|
4
4
|
*
|
|
5
|
-
* Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`)
|
|
5
|
+
* Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`).
|
|
6
6
|
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Why a TS import rather than `.oxlintrc.json` `extends`: oxlint's JSON
|
|
9
|
+
* `extends` resolves only relative file paths, not `node_modules` (see
|
|
10
|
+
* oxc-project/oxc#15538). The `oxlint.config.ts` form imports the config object
|
|
11
|
+
* directly, which does resolve through `node_modules`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
7
14
|
* ```ts
|
|
15
|
+
* // oxlint.config.ts in a @browsercore/* package
|
|
8
16
|
* import { defineConfig } from "oxlint";
|
|
9
17
|
* import base from "@browsercore/dev/oxlint";
|
|
10
18
|
* export default defineConfig({ extends: [base] });
|
|
11
19
|
* ```
|
|
12
20
|
*
|
|
13
|
-
*
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
16
|
-
*
|
|
21
|
+
* @defaultValue
|
|
22
|
+
* Enables `typescript`, `unicorn`, `import`, `promise`, and `node` plugins with
|
|
23
|
+
* `correctness`, `suspicious`, and `pedantic` set to `"error"`.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://oxc.rs/docs/guide/linting/ oxlint documentation}
|
|
26
|
+
* @since 0.1.0
|
|
17
27
|
*/
|
|
18
28
|
declare const base: OxlintConfig;
|
|
19
29
|
export default base;
|
package/dist/oxlint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C
|
|
1
|
+
{"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,QAAA,MAAM,IAAI,EAAE,YAwDX,CAAC;eAEa,IAAI"}
|
package/dist/oxlint.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base oxlint config shared by every @browsercore/* package.
|
|
3
3
|
*
|
|
4
|
-
* Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`)
|
|
4
|
+
* Consumers extend it in an `oxlint.config.ts` (which replaces `.oxlintrc.json`).
|
|
5
5
|
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Why a TS import rather than `.oxlintrc.json` `extends`: oxlint's JSON
|
|
8
|
+
* `extends` resolves only relative file paths, not `node_modules` (see
|
|
9
|
+
* oxc-project/oxc#15538). The `oxlint.config.ts` form imports the config object
|
|
10
|
+
* directly, which does resolve through `node_modules`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
6
13
|
* ```ts
|
|
14
|
+
* // oxlint.config.ts in a @browsercore/* package
|
|
7
15
|
* import { defineConfig } from "oxlint";
|
|
8
16
|
* import base from "@browsercore/dev/oxlint";
|
|
9
17
|
* export default defineConfig({ extends: [base] });
|
|
10
18
|
* ```
|
|
11
19
|
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
14
|
-
*
|
|
15
|
-
*
|
|
20
|
+
* @defaultValue
|
|
21
|
+
* Enables `typescript`, `unicorn`, `import`, `promise`, and `node` plugins with
|
|
22
|
+
* `correctness`, `suspicious`, and `pedantic` set to `"error"`.
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://oxc.rs/docs/guide/linting/ oxlint documentation}
|
|
25
|
+
* @since 0.1.0
|
|
16
26
|
*/
|
|
17
27
|
const base = {
|
|
18
28
|
plugins: ["typescript", "unicorn", "import", "promise", "node"],
|
package/dist/oxlint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.js","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"oxlint.js","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,IAAI,GAAiB;IACvB,OAAO,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;IAC/D,GAAG,EAAE;QACD,IAAI,EAAE,IAAI;KACb;IACD,UAAU,EAAE;QACR,WAAW,EAAE,OAAO;QACpB,UAAU,EAAE,OAAO;QACnB,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,KAAK;KACf;IACD,KAAK,EAAE;QACH,YAAY,EAAE,MAAM;QACpB,aAAa,EAAE,OAAO;QACtB,MAAM,EAAE,OAAO;QACf,QAAQ,EAAE,OAAO;QACjB,cAAc,EAAE,OAAO;QACvB,kBAAkB,EAAE,OAAO;QAC3B,KAAK,EAAE,OAAO;QACd,sBAAsB,EAAE,OAAO;QAC/B,wBAAwB,EAAE,OAAO;QACjC,gBAAgB,EAAE,OAAO;QACzB,uBAAuB,EAAE,OAAO;QAChC,iBAAiB,EAAE,OAAO;QAC1B,6BAA6B,EAAE,OAAO;QACtC,qBAAqB,EAAE,OAAO;QAC9B,4BAA4B,EAAE,OAAO;QACrC,kCAAkC,EAAE,OAAO;QAC3C,yBAAyB,EAAE,OAAO;QAClC,oCAAoC,EAAE,OAAO;QAC7C,2BAA2B,EAAE,OAAO;QACpC,8BAA8B,EAAE,OAAO;QACvC,2BAA2B,EAAE,OAAO;QACpC,2BAA2B,EAAE,OAAO;QACpC,iCAAiC,EAAE,OAAO;QAC1C,yBAAyB,EAAE,KAAK;QAChC,yBAAyB,EAAE,OAAO;QAClC,uBAAuB,EAAE,KAAK;QAC9B,0EAA0E;QAC1E,oEAAoE;QACpE,6BAA6B,EAAE,KAAK;QACpC,oBAAoB,EAAE,KAAK;QAC3B,WAAW,EAAE,KAAK;QAClB,wBAAwB,EAAE,KAAK;QAC/B,iBAAiB,EAAE,OAAO;QAC1B,sBAAsB,EAAE,OAAO;QAC/B,uBAAuB,EAAE,OAAO;QAChC,wBAAwB,EAAE,OAAO;QACjC,oBAAoB,EAAE,MAAM;QAC5B,qCAAqC,EAAE,KAAK;QAC5C,0CAA0C,EAAE,KAAK;QACjD,sBAAsB,EAAE,KAAK;QAC7B,iCAAiC,EAAE,KAAK;KAC3C;IACD,cAAc,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,CAAC;CACtE,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/dist/vitest.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring a package's vitest setup.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
1
6
|
type PackageOptions = {
|
|
7
|
+
/** Display name for the test run (shown in reporters). */
|
|
2
8
|
name: string;
|
|
3
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Test files to run.
|
|
11
|
+
*
|
|
12
|
+
* @defaultValue <code>["tests/**/*.test.ts"]</code>
|
|
13
|
+
*/
|
|
4
14
|
include?: string[];
|
|
5
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Overrides merged into the <code>coverage</code> block.
|
|
17
|
+
*
|
|
18
|
+
* Use this to add extra <code>exclude</code> patterns — they are appended to the
|
|
19
|
+
* default excludes (<code>**/index.ts</code>, <code>tests/**</code>, <code>node_modules/**</code>).
|
|
20
|
+
*/
|
|
6
21
|
coverage?: {
|
|
7
22
|
exclude?: string[];
|
|
8
23
|
[key: string]: unknown;
|
|
@@ -16,12 +31,29 @@ type PackageOptions = {
|
|
|
16
31
|
* `json-summary` — the last is what the coverage gate reads), the same v8
|
|
17
32
|
* coverage over `src/` (all `.ts` files), the same 30s timeouts, and `globals: false`.
|
|
18
33
|
*
|
|
19
|
-
*
|
|
34
|
+
* @param options Configuration options for the package.
|
|
35
|
+
* @param options.name Display name for the test run.
|
|
36
|
+
* @param options.include Glob patterns for test files.
|
|
37
|
+
* @param options.coverage Optional coverage overrides.
|
|
38
|
+
* @returns A fully-formed vitest config object.
|
|
20
39
|
*
|
|
40
|
+
* @example
|
|
21
41
|
* ```ts
|
|
42
|
+
* // vitest.config.ts in a @browsercore/* package
|
|
22
43
|
* import { definePackageConfig } from "@browsercore/dev/vitest";
|
|
23
44
|
* export default definePackageConfig({ name: "crypto" });
|
|
24
45
|
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // With custom coverage excludes
|
|
50
|
+
* export default definePackageConfig({
|
|
51
|
+
* name: "tls",
|
|
52
|
+
* coverage: { exclude: ["**/handshake-driver.ts"] }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @since 0.1.0
|
|
25
57
|
*/
|
|
26
58
|
export declare function definePackageConfig(options: PackageOptions): import("vite").UserConfig;
|
|
27
59
|
export {};
|
package/dist/vitest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb
|
|
1
|
+
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,KAAK,cAAc,GAAG;IAClB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAC1B,CAAC;CACL,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,6BA8B1D"}
|
package/dist/vitest.js
CHANGED
|
@@ -7,12 +7,29 @@ import { defineConfig } from "vitest/config";
|
|
|
7
7
|
* `json-summary` — the last is what the coverage gate reads), the same v8
|
|
8
8
|
* coverage over `src/` (all `.ts` files), the same 30s timeouts, and `globals: false`.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* @param options Configuration options for the package.
|
|
11
|
+
* @param options.name Display name for the test run.
|
|
12
|
+
* @param options.include Glob patterns for test files.
|
|
13
|
+
* @param options.coverage Optional coverage overrides.
|
|
14
|
+
* @returns A fully-formed vitest config object.
|
|
11
15
|
*
|
|
16
|
+
* @example
|
|
12
17
|
* ```ts
|
|
18
|
+
* // vitest.config.ts in a @browsercore/* package
|
|
13
19
|
* import { definePackageConfig } from "@browsercore/dev/vitest";
|
|
14
20
|
* export default definePackageConfig({ name: "crypto" });
|
|
15
21
|
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // With custom coverage excludes
|
|
26
|
+
* export default definePackageConfig({
|
|
27
|
+
* name: "tls",
|
|
28
|
+
* coverage: { exclude: ["**/handshake-driver.ts"] }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @since 0.1.0
|
|
16
33
|
*/
|
|
17
34
|
export function definePackageConfig(options) {
|
|
18
35
|
return defineConfig({
|
|
@@ -29,7 +46,7 @@ export function definePackageConfig(options) {
|
|
|
29
46
|
include: ["src/**/*.ts"],
|
|
30
47
|
reporter: ["text", "html", "json-summary"],
|
|
31
48
|
// Pure-reexport entrypoints can't be observed by V8's coverage
|
|
32
|
-
// instrumentation:
|
|
49
|
+
// instrumentation: 'export { … } from' compiles to no executable
|
|
33
50
|
// lines, so a file that only re-exports reports 0% even when every
|
|
34
51
|
// re-exported symbol is exercised by tests. The symbols remain
|
|
35
52
|
// fully covered at their origin modules. Append (don't replace)
|
package/dist/vitest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA4B7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAuB;IACvD,OAAO,YAAY,CAAC;QAChB,IAAI,EAAE;YACF,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,GAAG;YACT,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,oBAAoB,CAAC;YAClD,WAAW,EAAE,MAAM;YACnB,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,MAAM;YACnB,WAAW,EAAE,MAAM;YACnB,QAAQ,EAAE;gBACN,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,CAAC,aAAa,CAAC;gBACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC;gBAC1C,+DAA+D;gBAC/D,iEAAiE;gBACjE,mEAAmE;gBACnE,+DAA+D;gBAC/D,gEAAgE;gBAChE,4DAA4D;gBAC5D,GAAG,OAAO,CAAC,QAAQ;gBACnB,OAAO,EAAE;oBACL,aAAa;oBACb,UAAU;oBACV,iBAAiB;oBACjB,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,CAAC;iBACvC;aACJ;SACJ;KACJ,CAAC,CAAC;AACP,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,70 +1,79 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://github.com/jverneuer/browsercore-dev#readme",
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/jverneuer/browsercore-dev/issues"
|
|
13
|
-
},
|
|
14
|
-
"type": "module",
|
|
15
|
-
"main": "./dist/index.js",
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"sideEffects": false,
|
|
18
|
-
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/index.js"
|
|
2
|
+
"name": "@browsercore/dev",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Shared build, lint, test, and coverage tooling for the @browsercore/* packages.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/jverneuer/browsercore-dev.git"
|
|
22
9
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
"homepage": "https://github.com/jverneuer/browsercore-dev#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/jverneuer/browsercore-dev/issues"
|
|
26
13
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./vitest": {
|
|
24
|
+
"types": "./dist/vitest.d.ts",
|
|
25
|
+
"import": "./dist/vitest.js"
|
|
26
|
+
},
|
|
27
|
+
"./oxlint": {
|
|
28
|
+
"types": "./dist/oxlint.d.ts",
|
|
29
|
+
"import": "./dist/oxlint.js"
|
|
30
|
+
},
|
|
31
|
+
"./tsconfig.base.json": "./tsconfig.base.json",
|
|
32
|
+
"./tsconfig.build.base.json": "./tsconfig.build.base.json",
|
|
33
|
+
"./CODING_STANDARDS.md": "./CODING_STANDARDS.md"
|
|
30
34
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
35
|
+
"bin": {
|
|
36
|
+
"coverage-md": "./bin/coverage-md.mjs"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"bin",
|
|
41
|
+
"tsconfig.base.json",
|
|
42
|
+
"tsconfig.build.base.json",
|
|
43
|
+
"CODING_STANDARDS.md",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=26.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.build.json",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"lint": "oxlint --type-aware src/",
|
|
54
|
+
"clean": "rm -rf dist coverage",
|
|
55
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
56
|
+
"graph": "npx tsx scripts/resolve-graph.ts",
|
|
57
|
+
"memory:brief": "npx tsx scripts/memory-session.ts brief",
|
|
58
|
+
"memory:search": "npx tsx scripts/memory-query.ts search",
|
|
59
|
+
"memory:questions": "npx tsx scripts/memory-query.ts questions",
|
|
60
|
+
"memory:facts": "npx tsx scripts/memory-query.ts facts"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@tursodatabase/database": "^0.2.0",
|
|
64
|
+
"@xenova/transformers": "^2.17.2",
|
|
65
|
+
"zod": "^4.4.3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"oxlint": "^1.76.0",
|
|
69
|
+
"vitest": "^4.1.10"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/node": "^26.1.2",
|
|
73
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
74
|
+
"oxlint": "^1.76.0",
|
|
75
|
+
"oxlint-tsgolint": "7.0.2001",
|
|
76
|
+
"typescript": "^7.0.0",
|
|
77
|
+
"vitest": "^4.1.10"
|
|
78
|
+
}
|
|
70
79
|
}
|
package/CODING_STANDARDS.md
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
# TypeScript Coding Standards
|
|
2
|
-
|
|
3
|
-
These rules are the standard for this codebase and **every** sub-package. Every PR,
|
|
4
|
-
every AI-generated snippet, and every hand-written file follows them. They exist so
|
|
5
|
-
the intended behavior lives in the types — never in tribal knowledge or hidden assumptions.
|
|
6
|
-
|
|
7
|
-
> Design for AI modification: before committing, ask *"Could another developer or an
|
|
8
|
-
> LLM understand the intended behavior without asking me?"* If not — add types, split
|
|
9
|
-
> functions, clarify states, rename.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## 1. Strict compiler — never relax it
|
|
14
|
-
|
|
15
|
-
Every `tsconfig.json` inherits `tsconfig.base.json`, which carries:
|
|
16
|
-
|
|
17
|
-
```json
|
|
18
|
-
{
|
|
19
|
-
"strict": true,
|
|
20
|
-
"noUncheckedIndexedAccess": true,
|
|
21
|
-
"exactOptionalPropertyTypes": true
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
- `noUncheckedIndexedAccess` → `arr[i]` is `T | undefined`.
|
|
26
|
-
- `exactOptionalPropertyTypes` → `?` means absent-or-present, not present-and-undefined.
|
|
27
|
-
|
|
28
|
-
Ambiguity creates bugs and forces LLMs to guess. **Never** override these to `false`
|
|
29
|
-
in a sub-package to dodge an error. Fix the error instead.
|
|
30
|
-
|
|
31
|
-
## 2. Every important data structure has a type
|
|
32
|
-
|
|
33
|
-
If data crosses a module boundary, it has an explicit type. No anonymous object
|
|
34
|
-
literals escaping a function.
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
// Bad
|
|
38
|
-
const frame = { type: 0x1, streamId: 3, data: buf };
|
|
39
|
-
|
|
40
|
-
// Good
|
|
41
|
-
interface HeadersFrame {
|
|
42
|
-
readonly type: FrameType.HEADERS;
|
|
43
|
-
readonly streamId: StreamId;
|
|
44
|
-
readonly data: Uint8Array;
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## 3. Never `any`
|
|
49
|
-
|
|
50
|
-
Unknown external data is `unknown`, then validated. `any` is a build failure.
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
function parseFrame(raw: Uint8Array): Frame {
|
|
54
|
-
const unknown = decodeUnknown(raw); // unknown
|
|
55
|
-
return FrameSchema.parse(unknown); // validated → typed
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## 4. Interfaces for domain objects, type aliases for states/constraints
|
|
60
|
-
|
|
61
|
-
- Interfaces for real entities (`TlsConnection`, `Http2Stream`, `Cookie`).
|
|
62
|
-
- Type aliases for states/constraints (`RunStatus`, `CipherSuite`).
|
|
63
|
-
- If values come from a known set, encode the set — never bare `string`.
|
|
64
|
-
|
|
65
|
-
## 5. Model states explicitly — make invalid states unrepresentable
|
|
66
|
-
|
|
67
|
-
No "state via nullable-field combos." Use discriminated unions.
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
// Bad — allows { state: "open", error: "failed" }
|
|
71
|
-
interface Connection {
|
|
72
|
-
state: string;
|
|
73
|
-
stream?: Stream;
|
|
74
|
-
error?: string;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Good
|
|
78
|
-
type ConnectionState =
|
|
79
|
-
| { readonly state: "connecting" }
|
|
80
|
-
| { readonly state: "open"; readonly stream: Stream }
|
|
81
|
-
| { readonly state: "closed"; readonly reason: CloseReason };
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## 6. Discriminated unions for every workflow/state
|
|
85
|
-
|
|
86
|
-
The compiler + LLM reason about every case.
|
|
87
|
-
|
|
88
|
-
## 7. Functions declare input AND output types
|
|
89
|
-
|
|
90
|
-
Public functions always define both sides — no inference-only signatures on exported APIs.
|
|
91
|
-
|
|
92
|
-
## 8. One function = one decision
|
|
93
|
-
|
|
94
|
-
No `processHandshake()` that validates + persists + schedules + notifies. Split:
|
|
95
|
-
`validate…`, `decodeStep`, `actuate`, `recordStep`.
|
|
96
|
-
|
|
97
|
-
## 9. No hidden behavior
|
|
98
|
-
|
|
99
|
-
A function named `updateSettings` does not also flush a log. Every side effect is its
|
|
100
|
-
own named call.
|
|
101
|
-
|
|
102
|
-
## 10. Name things explicitly
|
|
103
|
-
|
|
104
|
-
`cipherSuite`, `observedRank`, `clientHello` — never `data`, `result`, `obj`.
|
|
105
|
-
The name is the documentation.
|
|
106
|
-
|
|
107
|
-
## 11. Prefer immutable data + `readonly`
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
const next = { ...prev, cipherSuite } as const;
|
|
111
|
-
interface Connection { readonly id: ConnectionId; }
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
No in-place mutation of shared state. `const` over `let`.
|
|
115
|
-
|
|
116
|
-
## 12. Validate external data immediately
|
|
117
|
-
|
|
118
|
-
Everything from outside the boundary is `unknown`: sockets, files, captures, configs.
|
|
119
|
-
Use **Zod** at every boundary:
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
const frame = FrameSchema.parse(raw); // never `raw as Frame`
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## 13. Types are contracts, not documentation
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
// Bad // user id
|
|
129
|
-
// id: string;
|
|
130
|
-
// Good
|
|
131
|
-
type UserId = string & { __brand: "UserId" };
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## 14. Branded/opaque ID types — load-bearing
|
|
135
|
-
|
|
136
|
-
Don't use bare `number`/`string` for IDs. This kills the "pass an X where a Y belongs"
|
|
137
|
-
class of bug. The project uses these brands (defined per-package, see `types.ts`):
|
|
138
|
-
|
|
139
|
-
```ts
|
|
140
|
-
type ConnectionId = string & { __brand: "ConnectionId" };
|
|
141
|
-
type StreamId = number & { __brand: "StreamId" };
|
|
142
|
-
type SessionId = string & { __brand: "SessionId" };
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## 15. Exhaustive switches
|
|
146
|
-
|
|
147
|
-
Every `switch` over a union hits `default: assertNever(x)`. Adding a state forces every
|
|
148
|
-
handler to compile-error until handled.
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
function assertNever(x: never): never {
|
|
152
|
-
throw new Error(`Unexpected value: ${JSON.stringify(x)}`);
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## 16. Explicit, typed errors
|
|
157
|
-
|
|
158
|
-
```ts
|
|
159
|
-
// Bad
|
|
160
|
-
throw new Error("handshake failed");
|
|
161
|
-
// Good
|
|
162
|
-
throw new TlsHandshakeError("server_hello_parse", cause);
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
Errors are part of the API. Define them in each package's `errors.ts`.
|
|
166
|
-
|
|
167
|
-
## 17. No magic strings
|
|
168
|
-
|
|
169
|
-
`if (event === Event.COLD_START)` or a string-literal union — never bare `"cold_start"`.
|
|
170
|
-
|
|
171
|
-
## 18. Clear dependency boundaries
|
|
172
|
-
|
|
173
|
-
Domain (pure protocol logic) knows nothing of AWS / HTTP / DDB / sockets. Infrastructure
|
|
174
|
-
adapts. The protocol state machines stay I/O-free so they're unit-testable.
|
|
175
|
-
|
|
176
|
-
**Within this repo**, the dependency graph flows upward only — never sideways or downward:
|
|
177
|
-
|
|
178
|
-
```
|
|
179
|
-
@browsercore/fetch
|
|
180
|
-
└─ @browsercore/http2 @browsercore/http1 @browsercore/cookies @browsercore/profiles
|
|
181
|
-
└─ @browsercore/tls
|
|
182
|
-
└─ @browsercore/crypto @browsercore/transport
|
|
183
|
-
└─ node:net / node:crypto
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
A package may only import from packages *below* it in this graph.
|
|
187
|
-
|
|
188
|
-
## 19. Documentation: why, not what
|
|
189
|
-
|
|
190
|
-
Comments explain *why* ("crawl past our position so the competitor snapshot covers the
|
|
191
|
-
neighborhood"), never *what* the code obviously does. Priority: Types > Names > Structure >
|
|
192
|
-
Comments.
|
|
193
|
-
|
|
194
|
-
## 20. API contracts in one place
|
|
195
|
-
|
|
196
|
-
Domain types live in each package's `types.ts`; wire schemas in `schemas.ts`. One source
|
|
197
|
-
of truth, never duplicated shapes.
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## The Golden Rule
|
|
202
|
-
|
|
203
|
-
Every piece of important information exists as one of: **a type, a function signature,
|
|
204
|
-
an explicit state model, a schema validation, or clear naming.** Never rely on tribal
|
|
205
|
-
knowledge or hidden assumptions.
|