bivium 0.5.1 → 0.6.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/README.md +65 -560
- package/cli.js +38 -34
- package/docs/api.md +69 -0
- package/docs/ci.md +112 -0
- package/docs/cli.md +133 -0
- package/docs/config.md +59 -0
- package/docs/how-it-works.md +106 -0
- package/docs/recipes.md +67 -0
- package/docs/tuning.md +91 -0
- package/index.d.ts +52 -0
- package/index.js +2 -0
- package/package.json +2 -2
- package/shared.js +47 -15
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# How it works
|
|
2
|
+
|
|
3
|
+
bivium builds a static, file-level dependency graph
|
|
4
|
+
and walks it backwards from the files a change touches to the tests that
|
|
5
|
+
reach them; what it can't read counts as depending on everything.
|
|
6
|
+
|
|
7
|
+
## What it reads
|
|
8
|
+
|
|
9
|
+
A one-pass lexer reads JavaScript and TypeScript
|
|
10
|
+
(`.js`, `.ts`, `.jsx`, `.tsx`, and their `m`/`c` variants),
|
|
11
|
+
the scripts and markup expressions of `.svelte`, the scripts of `.vue`,
|
|
12
|
+
`.astro` and `.html`, and the `script[src]`,
|
|
13
|
+
`link[href]` and `iframe[src]` of `.html`.
|
|
14
|
+
Only code counts: an import spelled in a string
|
|
15
|
+
or a comment adds no edge.
|
|
16
|
+
|
|
17
|
+
| It follows | As |
|
|
18
|
+
|:---|:---|
|
|
19
|
+
| Static, side-effect and dynamic imports, `export … from`, `require()` | Edges to every file the specifier can load: each extension that exists, each `exports` condition. A missing `x.js` (`.jsx`, `.mjs`, `.cjs`) is its TypeScript source, as TypeScript reads it: `x.ts`, `x.tsx` or `x.d.ts`, through any path, alias or `exports` target. A value import that finds only `x.d.ts` is unknown: what runs isn't in the graph |
|
|
20
|
+
| `vi.mock()`, `vi.importActual()` and the rest of the family | Edges |
|
|
21
|
+
| `import.meta.glob()` | Every matching file, now and later |
|
|
22
|
+
| JSDoc `@type {import("x")}` and `@import` | Edges (TypeScript reads them) |
|
|
23
|
+
| `%sveltekit.assets%/x` in a SvelteKit `app.html` | An edge to `static/x` in the project, the nearest directory with a `svelte.config.*` or a `package.json`. `%sveltekit.head%`, `%sveltekit.body%` and the rest aren't references |
|
|
24
|
+
| `page.goto("/x.html")` in a suite with `urls` | An edge to the page |
|
|
25
|
+
| `compilerOptions.paths` and `baseUrl` of the nearest `tsconfig.json`, with its relative `extends` | Edges to every target that exists, tried after `alias` and before `package.json` `exports`. A `tsconfig.json` that doesn't parse maps nothing, and `check` lists it |
|
|
26
|
+
| `#name` subpath imports, through the `imports` of the importing file's own `package.json` | Edges to every condition's target that exists; an unmatched `#name` is unknown |
|
|
27
|
+
| Named imports from a module made only of re-exports | An edge to the one file that exports each name, when the package declares `sideEffects` |
|
|
28
|
+
| A file's own package and its ancestors' `package.json` dependencies, and builtins | `pkg:` nodes |
|
|
29
|
+
| Anything else | Unknown: the file depends on every change |
|
|
30
|
+
|
|
31
|
+
A root `bun.lock`, `package-lock.json` or `pnpm-lock.yaml` isn't a
|
|
32
|
+
source file: a change to one seeds the packages it changed
|
|
33
|
+
(see [Lockfiles](#lockfiles)).
|
|
34
|
+
|
|
35
|
+
Nor is a `tsconfig.json` (or a file one `extends`)
|
|
36
|
+
or a `package.json` under `roots`: their options, `paths`,
|
|
37
|
+
`type` or `exports` change how the files under them resolve or run,
|
|
38
|
+
which no import says.
|
|
39
|
+
A change to one seeds the files it governs,
|
|
40
|
+
those it's the nearest of its kind to.
|
|
41
|
+
A change the parsed file doesn't show, such as formatting or comments,
|
|
42
|
+
seeds nothing; so does one to a `package.json`'s metadata alone
|
|
43
|
+
(`version`, `description`, `repository` and the like),
|
|
44
|
+
and a dependency change is the lockfile's.
|
|
45
|
+
|
|
46
|
+
A file it can't lex cleanly is read by a regex extractor instead,
|
|
47
|
+
which over-approximates.
|
|
48
|
+
CSS isn't scanned: generated stylesheets reach their inputs through
|
|
49
|
+
`edges`, and a [narrower](api.md#narrowers) can do better.
|
|
50
|
+
|
|
51
|
+
## Lockfiles
|
|
52
|
+
|
|
53
|
+
A dependency bump changes a lockfile, which no file imports.
|
|
54
|
+
When a root `bun.lock`, `package-lock.json` (v2 or v3),
|
|
55
|
+
or `pnpm-lock.yaml` v6 or v9 changes,
|
|
56
|
+
bivium diffs it against the merge base and seeds the walk with the
|
|
57
|
+
`pkg:` nodes of the packages whose entries changed,
|
|
58
|
+
and of every package that depends on one,
|
|
59
|
+
so a `svelte` bump selects what imports `svelte`,
|
|
60
|
+
or a package built on it.
|
|
61
|
+
A `package.json` whose only change is to dependencies the lockfile
|
|
62
|
+
records the same way counts as those packages changing.
|
|
63
|
+
|
|
64
|
+
A changed package can also be used in ways the graph can't see:
|
|
65
|
+
a CLI a test spawns, a runner, a type package.
|
|
66
|
+
So when a change reaches a package that a `package.json` declares,
|
|
67
|
+
or that some file imports, and that no test imports, everything runs,
|
|
68
|
+
with the reason
|
|
69
|
+
(`bun.lock: playwright 1.63.0 → 1.64.0, and no test imports it`),
|
|
70
|
+
unless the package is `inert`.
|
|
71
|
+
bivium itself always is: a bump changes which tests later plans pick,
|
|
72
|
+
not what a test does.
|
|
73
|
+
With `loadedByName` set, only a package with a `bin` in the lockfile,
|
|
74
|
+
or one it lists, counts as used that way:
|
|
75
|
+
a bump that reaches a library only a CMS config imports selects nothing.
|
|
76
|
+
Everything also runs for a lockfile bivium can't parse,
|
|
77
|
+
one whose settings other than its packages changed
|
|
78
|
+
(`overrides`, patches, pnpm's `settings`, `catalogs`, or the version of
|
|
79
|
+
pnpm itself), and a `package.json` change the lockfile doesn't record.
|
|
80
|
+
Other lockfiles (`yarn.lock`, `bun.lockb`) are files like any other:
|
|
81
|
+
outside the roots, a change to one runs everything.
|
|
82
|
+
|
|
83
|
+
```console
|
|
84
|
+
$ bunx bivium plan
|
|
85
|
+
bun.lock: @biomejs/biome 2.5.14 → 2.6.3, inert
|
|
86
|
+
bun.lock: svelte 5.57.1 → 5.57.2
|
|
87
|
+
unit tests: 4 of 12 files
|
|
88
|
+
…
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Compared with
|
|
92
|
+
|
|
93
|
+
Where bivium sits among the tools that select or skip tests:
|
|
94
|
+
|
|
95
|
+
| | Selects | Misses |
|
|
96
|
+
|:---|:---|:---|
|
|
97
|
+
| `vitest --changed`, `jest --changedSince` | Tests whose module graph reaches a changed file, from the runner's own resolver | Disk reads, fixtures, pages a test visits, config and setup wiring |
|
|
98
|
+
| Playwright `--only-changed` | Test files whose imports changed | The pages a test opens and what they load |
|
|
99
|
+
| Nx, Turborepo | Whole projects whose inputs changed | Nothing within a project's declared inputs, at project granularity |
|
|
100
|
+
| Bazel | Targets whose declared inputs changed | Nothing, if every input is declared |
|
|
101
|
+
| bivium | Test files, across runners and file types, from one graph | Nothing it can see; what it can't, it runs |
|
|
102
|
+
|
|
103
|
+
## Related
|
|
104
|
+
|
|
105
|
+
- [Tuning a plan](tuning.md): the orphan rule and `check`
|
|
106
|
+
- [Config](config.md): telling it what it can't see
|
package/docs/recipes.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Recipes
|
|
2
|
+
|
|
3
|
+
Settings for common test runners and repository shapes,
|
|
4
|
+
each a starting point to adjust.
|
|
5
|
+
|
|
6
|
+
**Vitest or Jest.**
|
|
7
|
+
Name the setup files the runner loads,
|
|
8
|
+
mirror `resolve.alias` (a Vite key like `"@/"` works as written),
|
|
9
|
+
give snapshots to their tests, and, for a suite that runs code,
|
|
10
|
+
skip type-only edges:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
suites: {
|
|
14
|
+
unit: {
|
|
15
|
+
tests: "src/**/*.test.{ts,tsx}",
|
|
16
|
+
run: "vitest run {files}",
|
|
17
|
+
root: "src",
|
|
18
|
+
setup: ["src/setupTests.ts"], // vitest.config.ts `setupFiles`
|
|
19
|
+
wiring: ["vitest.config.ts"],
|
|
20
|
+
types: false,
|
|
21
|
+
nonInputs: ["src/**/types.ts"], // types only: nothing loads them at runtime
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
alias: { "@/": "src/" },
|
|
25
|
+
reads: { "src/**/*.test.{ts,tsx}": "src/$1__snapshots__/$2.test.$3.snap" },
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
tsconfig `paths` (what `vite-tsconfig-paths` reads) are read without an
|
|
29
|
+
`alias`.
|
|
30
|
+
An extensionless `vi.mock("@/x")` resolves as an import does.
|
|
31
|
+
A test environment the runner loads by name (`jsdom`, `happy-dom`) goes
|
|
32
|
+
in `loadedByName` if you set it.
|
|
33
|
+
|
|
34
|
+
**pnpm workspaces.**
|
|
35
|
+
Workspace packages resolve through their `package.json` `exports`,
|
|
36
|
+
and a `.js` specifier into one (`@acme/ui/Button.js`) reaches its `.ts`
|
|
37
|
+
source.
|
|
38
|
+
A `pnpm-lock.yaml` change selects through the packages it changed.
|
|
39
|
+
Set `roots` to the packages and apps whose changes the suites need to
|
|
40
|
+
see, and a suite per test runner.
|
|
41
|
+
|
|
42
|
+
**Playwright.**
|
|
43
|
+
Map `page.goto()` URLs to the pages they open with `urls`,
|
|
44
|
+
list pages only a `goto()` opens in `pages`,
|
|
45
|
+
and name `playwright.config.ts` in `wiring`:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
e2e: {
|
|
49
|
+
tests: "e2e/**/*.spec.ts",
|
|
50
|
+
root: "e2e",
|
|
51
|
+
urls: { "/*": "e2e/fixtures/*.html" },
|
|
52
|
+
wiring: ["playwright.config.ts"],
|
|
53
|
+
},
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Generated code.**
|
|
57
|
+
A content or type generator that writes into a gitignored directory
|
|
58
|
+
(`.velite`, `.contentlayer/generated`) is an `edges` entry from what it
|
|
59
|
+
writes to what it reads:
|
|
60
|
+
`{ ".velite/*": ["content/**", "velite.config.ts"] }`.
|
|
61
|
+
An import of `#velite` or `../.velite` then reaches the content,
|
|
62
|
+
and not every change.
|
|
63
|
+
|
|
64
|
+
## Related
|
|
65
|
+
|
|
66
|
+
- [Config](config.md): every key
|
|
67
|
+
- [Tuning a plan](tuning.md): when a plan still runs too much
|
package/docs/tuning.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Tuning a plan
|
|
2
|
+
|
|
3
|
+
A plan that runs more than a change needs has a cause bivium can name;
|
|
4
|
+
`bivium check` lists each one with its fix.
|
|
5
|
+
|
|
6
|
+
## A change no test reaches
|
|
7
|
+
|
|
8
|
+
A changed file under a suite's `root` that no test of the suite reaches
|
|
9
|
+
is wired some other way (a runner config, a setup file),
|
|
10
|
+
so the whole suite runs: the orphan rule.
|
|
11
|
+
With the default `root`, the whole repository,
|
|
12
|
+
any file bivium can't trace to a test runs the suite,
|
|
13
|
+
which is sound and coarse.
|
|
14
|
+
Set `root` on every suite to the directories its tests
|
|
15
|
+
and sources live in, and say what the rest is:
|
|
16
|
+
|
|
17
|
+
| You changed… | and want… | Use |
|
|
18
|
+
|:---|:---|:---|
|
|
19
|
+
| a file no test can observe: docs, stories, a changelog | nothing to run, unless some test imports it | `ignore` |
|
|
20
|
+
| a file under the suite's `root` only another tool reads: type-check inputs | nothing to run for this suite | the suite's `nonInputs` |
|
|
21
|
+
| a runner config or a second harness | the whole suite | the suite's `wiring` |
|
|
22
|
+
| a setup file the runner loads before every test, or what it imports | every test of the suite | the suite's `setup` |
|
|
23
|
+
| the selector's config, or its own code | everything | `self` (the config file always is) |
|
|
24
|
+
| a declaration file, in a suite that runs code | nothing | the suite's `types: false` |
|
|
25
|
+
| a types-only module only `import type` reaches, in a suite that runs code | nothing | the suite's `types: false`, and the module in its `nonInputs` |
|
|
26
|
+
| a file a test lists but doesn't read (a route, a story) | the test, when one is added or deleted | `// @lists <glob>` in the test |
|
|
27
|
+
| a file a build turns into what tests load | the tests that load the output | `edges` from the output to its inputs |
|
|
28
|
+
|
|
29
|
+
A file outside `roots` that isn't ignored runs everything:
|
|
30
|
+
it's the backstop for wiring the graph can't see, such as a CI workflow.
|
|
31
|
+
|
|
32
|
+
`bivium check` lists every file under a suite's `root` that no test
|
|
33
|
+
reaches and the config doesn't exempt,
|
|
34
|
+
with a fix for each by what it looks like: a test's snapshot,
|
|
35
|
+
a runner's config, or anything else.
|
|
36
|
+
It's the list to work through when adopting bivium,
|
|
37
|
+
and a new entry is a gap someone added.
|
|
38
|
+
|
|
39
|
+
A file's own disk reads make it unknown,
|
|
40
|
+
but a test that hands a path to the code under test
|
|
41
|
+
(`typecheck({ workspace: "tests/fixtures" })`),
|
|
42
|
+
or a `hermetic` one that reads it, reads nothing the graph can see.
|
|
43
|
+
So `check` also reads the string literals in each test,
|
|
44
|
+
and in what the tests reach under a suite's `root`,
|
|
45
|
+
for repository paths: relative to the root when they have a slash,
|
|
46
|
+
as `join(root, "tests/fixtures")` spells one, and relative to the file,
|
|
47
|
+
as `new URL("fixtures", import.meta.url)` does.
|
|
48
|
+
It fails on one a change to which wouldn't select the tests that reach
|
|
49
|
+
the file, with the `reads`, `edges` or annotation that declares it.
|
|
50
|
+
A path whose change runs the suite anyway, as `wiring`,
|
|
51
|
+
`self` or by the orphan rule, doesn't fail,
|
|
52
|
+
and an unreached file's fix names where it's spelled.
|
|
53
|
+
Strings inside brackets are skipped as data
|
|
54
|
+
(`["src/a.ts", …]`, `map["key"]`), as are the directories a file is in
|
|
55
|
+
and paths outside the graph.
|
|
56
|
+
A path a test only names, such as an expected output,
|
|
57
|
+
takes `// @lists <path>`.
|
|
58
|
+
|
|
59
|
+
## Dead globs
|
|
60
|
+
|
|
61
|
+
A typo'd `@depends-on`, or one pointing only at files the planner skips,
|
|
62
|
+
looks fine and never selects its file.
|
|
63
|
+
`check` evaluates every `@depends-on`, `@reads`,
|
|
64
|
+
`@lists` and `import.meta.glob` pattern,
|
|
65
|
+
every `edges` and `reads` value, and every suite's `setup`,
|
|
66
|
+
against every file git lists
|
|
67
|
+
(tracked and untracked, inside the roots or not) and reports one that:
|
|
68
|
+
|
|
69
|
+
| Problem | Means |
|
|
70
|
+
|:---|:---|
|
|
71
|
+
| matches nothing | No file matches: a typo or a stale path |
|
|
72
|
+
| matches only ignored files, partly ignored | Some matches are ignored and not in the graph, so a change to one selects nothing |
|
|
73
|
+
|
|
74
|
+
A config value with captures is dead only when it matches nothing for
|
|
75
|
+
every file its key matches, and a key that matches no file the graph
|
|
76
|
+
reads is reported too, under the config's file.
|
|
77
|
+
An ignored file the graph reads still seeds a walk,
|
|
78
|
+
and a change outside the roots runs everything, so neither is dead.
|
|
79
|
+
A glob that's dead on purpose goes in `deadGlobs` with a reason:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
deadGlobs: [
|
|
83
|
+
{ file: "tests/css/tokens.test.ts", glob: "docs/src/**", reason: "docs-only changes skip CI" },
|
|
84
|
+
],
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Related
|
|
88
|
+
|
|
89
|
+
- [Config](config.md): every key named here
|
|
90
|
+
- [CLI](cli.md): `check`, `why` and `graph`
|
|
91
|
+
- [Recipes](recipes.md): settings for common runners
|
package/index.d.ts
CHANGED
|
@@ -278,3 +278,55 @@ export interface FullRunCause<Suite extends string = string> {
|
|
|
278
278
|
}
|
|
279
279
|
/** Types a config. Returns it unchanged. */
|
|
280
280
|
export declare function defineConfig<Suite extends string>(config: Config<Suite>): Config<Suite>;
|
|
281
|
+
/** An error bivium names: its `code` says which failure, its `kind` what to do. */
|
|
282
|
+
export declare class BiviumError extends Error {
|
|
283
|
+
readonly code: BiviumErrorCode;
|
|
284
|
+
readonly kind: BiviumErrorKind;
|
|
285
|
+
constructor(code: BiviumErrorCode, message: string, options?: ErrorOptions);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Which failure it is, stable across releases: a code is never reused for
|
|
289
|
+
* another meaning, and `--json` prints it as `error.code`.
|
|
290
|
+
*/
|
|
291
|
+
export type BiviumErrorCode =
|
|
292
|
+
/** No command, or `why` without a test. */
|
|
293
|
+
"BV_MISSING_ARGUMENT"
|
|
294
|
+
/** A command bivium doesn't have. */
|
|
295
|
+
| "BV_UNKNOWN_COMMAND"
|
|
296
|
+
/** An option the command doesn't take. */
|
|
297
|
+
| "BV_UNKNOWN_OPTION"
|
|
298
|
+
/** An option's value is missing or of the wrong form. */
|
|
299
|
+
| "BV_BAD_OPTION_VALUE"
|
|
300
|
+
/** More arguments than the command takes. */
|
|
301
|
+
| "BV_UNEXPECTED_ARGUMENT"
|
|
302
|
+
/** A suite the config doesn't define. */
|
|
303
|
+
| "BV_UNKNOWN_SUITE"
|
|
304
|
+
/** A path that is no suite's test. */
|
|
305
|
+
| "BV_UNKNOWN_TEST"
|
|
306
|
+
/** A path that names no file of the graph. */
|
|
307
|
+
| "BV_UNKNOWN_FILE"
|
|
308
|
+
/** `run` for a suite with no `run` command. */
|
|
309
|
+
| "BV_NO_RUN_COMMAND"
|
|
310
|
+
/** `plan --github` outside a GitHub Actions step. */
|
|
311
|
+
| "BV_NO_GITHUB_OUTPUT"
|
|
312
|
+
/** No config file where bivium looked. */
|
|
313
|
+
| "BV_CONFIG_NOT_FOUND"
|
|
314
|
+
/** The config file failed to load: a syntax error, or one it throws. */
|
|
315
|
+
| "BV_CONFIG_UNREADABLE"
|
|
316
|
+
/** The config loaded, but a key is unknown or a value is invalid. */
|
|
317
|
+
| "BV_CONFIG_INVALID"
|
|
318
|
+
/** The base to diff against isn't here, or there's no default branch. */
|
|
319
|
+
| "BV_GIT_NO_BASE"
|
|
320
|
+
/** The base and HEAD share no commit here. */
|
|
321
|
+
| "BV_GIT_NO_MERGE_BASE"
|
|
322
|
+
/** A git command failed; the message carries git's own words. */
|
|
323
|
+
| "BV_GIT_FAILED"
|
|
324
|
+
/** A failure bivium didn't anticipate: a bug, or the environment. */
|
|
325
|
+
| "BV_INTERNAL";
|
|
326
|
+
/**
|
|
327
|
+
* What a caller does about an error: `usage`, bivium was called wrong;
|
|
328
|
+
* `config`, the config can't be found, read, or is invalid; `git`, git
|
|
329
|
+
* refused or the history is missing; `other`, a failure bivium didn't
|
|
330
|
+
* name. Every kind exits 2.
|
|
331
|
+
*/
|
|
332
|
+
export type BiviumErrorKind = "usage" | "config" | "git" | "other";
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bivium",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Run only the tests
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "Run only the tests your change can reach.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eric Liu (https://github.com/metonym)",
|
|
7
7
|
"repository": {
|
package/shared.js
CHANGED
|
@@ -8,7 +8,7 @@ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
|
8
8
|
import { isAbsolute, join } from "node:path";
|
|
9
9
|
|
|
10
10
|
// package.json
|
|
11
|
-
var version = "0.
|
|
11
|
+
var version = "0.6.1";
|
|
12
12
|
|
|
13
13
|
// src/env.ts
|
|
14
14
|
function githubOutputPath() {
|
|
@@ -247,11 +247,33 @@ import { isAbsolute as isAbsolute2, join as join2, relative, resolve } from "nod
|
|
|
247
247
|
import { pathToFileURL } from "node:url";
|
|
248
248
|
|
|
249
249
|
// src/errors.ts
|
|
250
|
-
|
|
250
|
+
var KINDS = {
|
|
251
|
+
BV_MISSING_ARGUMENT: "usage",
|
|
252
|
+
BV_UNKNOWN_COMMAND: "usage",
|
|
253
|
+
BV_UNKNOWN_OPTION: "usage",
|
|
254
|
+
BV_BAD_OPTION_VALUE: "usage",
|
|
255
|
+
BV_UNEXPECTED_ARGUMENT: "usage",
|
|
256
|
+
BV_UNKNOWN_SUITE: "usage",
|
|
257
|
+
BV_UNKNOWN_TEST: "usage",
|
|
258
|
+
BV_UNKNOWN_FILE: "usage",
|
|
259
|
+
BV_NO_RUN_COMMAND: "usage",
|
|
260
|
+
BV_NO_GITHUB_OUTPUT: "usage",
|
|
261
|
+
BV_CONFIG_NOT_FOUND: "config",
|
|
262
|
+
BV_CONFIG_UNREADABLE: "config",
|
|
263
|
+
BV_CONFIG_INVALID: "config",
|
|
264
|
+
BV_GIT_NO_BASE: "git",
|
|
265
|
+
BV_GIT_NO_MERGE_BASE: "git",
|
|
266
|
+
BV_GIT_FAILED: "git",
|
|
267
|
+
BV_INTERNAL: "other"
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
class BiviumError2 extends Error {
|
|
271
|
+
code;
|
|
251
272
|
kind;
|
|
252
|
-
constructor(
|
|
273
|
+
constructor(code, message, options) {
|
|
253
274
|
super(message, options);
|
|
254
|
-
this.
|
|
275
|
+
this.code = code;
|
|
276
|
+
this.kind = KINDS[code];
|
|
255
277
|
}
|
|
256
278
|
}
|
|
257
279
|
function distance(a, b) {
|
|
@@ -758,16 +780,25 @@ var CONFIG_PREFIX = /^bivium config: /;
|
|
|
758
780
|
async function loadConfig(root, path) {
|
|
759
781
|
const file = path === undefined ? CONFIG_FILES.map((name) => join2(root, name)).find((f) => existsSync2(f)) : resolve(process.cwd(), path);
|
|
760
782
|
if (!file || !existsSync2(file)) {
|
|
761
|
-
throw new
|
|
783
|
+
throw new BiviumError2("BV_CONFIG_NOT_FOUND", path ? `bivium: no config found at ${path}` : `bivium: no config found in ${root}: looked for ${CONFIG_FILES.join(", ")} (--config names another file, --cwd another repository)`);
|
|
762
784
|
}
|
|
763
785
|
const inside = relative(root, file);
|
|
764
786
|
const shown = inside.startsWith("..") || isAbsolute2(inside) ? file : inside;
|
|
787
|
+
const named = (code, error) => {
|
|
788
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
789
|
+
return new BiviumError2(code, `bivium config: ${shown}: ${message.replace(CONFIG_PREFIX, "")}`, { cause: error });
|
|
790
|
+
};
|
|
791
|
+
let raw;
|
|
792
|
+
try {
|
|
793
|
+
raw = await readConfig(file);
|
|
794
|
+
} catch (error) {
|
|
795
|
+
throw named("BV_CONFIG_UNREADABLE", error);
|
|
796
|
+
}
|
|
765
797
|
let config;
|
|
766
798
|
try {
|
|
767
|
-
config = resolveConfig(checkConfig(
|
|
799
|
+
config = resolveConfig(checkConfig(raw));
|
|
768
800
|
} catch (error) {
|
|
769
|
-
|
|
770
|
-
throw new BiviumError("config", `bivium config: ${shown}: ${message.replace(CONFIG_PREFIX, "")}`, { cause: error });
|
|
801
|
+
throw named("BV_CONFIG_INVALID", error);
|
|
771
802
|
}
|
|
772
803
|
return { config, file: shown };
|
|
773
804
|
}
|
|
@@ -810,7 +841,7 @@ async function gitOrThrow(cwd, ...args) {
|
|
|
810
841
|
if (result.status !== 0) {
|
|
811
842
|
const said = result.stderr.trim().split(`
|
|
812
843
|
`)[0];
|
|
813
|
-
throw new
|
|
844
|
+
throw new BiviumError2("BV_GIT_FAILED", `bivium: git ${args.join(" ")} failed${said ? `: ${said}` : ""}`);
|
|
814
845
|
}
|
|
815
846
|
return result.stdout;
|
|
816
847
|
}
|
|
@@ -828,10 +859,10 @@ async function missingHistory(cwd, base) {
|
|
|
828
859
|
]);
|
|
829
860
|
const fix = shallow.stdout.trim() === "true" ? " The clone is shallow: fetch the history (actions/checkout: `fetch-depth: 0`)." : "";
|
|
830
861
|
if (known.status !== 0) {
|
|
831
|
-
return new
|
|
862
|
+
return new BiviumError2("BV_GIT_NO_BASE", `bivium: no commit ${base} here to diff against: fetch it.${fix}`);
|
|
832
863
|
}
|
|
833
864
|
if (forked.status !== 0) {
|
|
834
|
-
return new
|
|
865
|
+
return new BiviumError2("BV_GIT_NO_MERGE_BASE", `bivium: ${base} and HEAD share no commit here, so there's no merge base to diff against.${fix}`);
|
|
835
866
|
}
|
|
836
867
|
return;
|
|
837
868
|
}
|
|
@@ -959,7 +990,7 @@ async function defaultBase(cwd) {
|
|
|
959
990
|
const branch = refs[found.findIndex((result) => result.status === 0)];
|
|
960
991
|
if (branch)
|
|
961
992
|
return branch;
|
|
962
|
-
throw new
|
|
993
|
+
throw new BiviumError2("BV_GIT_NO_BASE", `bivium: no base given and no default branch found (tried origin/HEAD, ${refs.join(", ")}): pass one, as in \`bivium plan origin/main\`, or set base in the config`);
|
|
963
994
|
}
|
|
964
995
|
|
|
965
996
|
// src/barrel.ts
|
|
@@ -4610,8 +4641,9 @@ function graphView(graph, config) {
|
|
|
4610
4641
|
dependents: (from) => affectedBy(graph, from, { includeUnknown: false }),
|
|
4611
4642
|
tests: (name) => {
|
|
4612
4643
|
const suite = config.suites.find((candidate) => candidate.name === name);
|
|
4613
|
-
if (!suite)
|
|
4614
|
-
throw new
|
|
4644
|
+
if (!suite) {
|
|
4645
|
+
throw new BiviumError2("BV_UNKNOWN_SUITE", `bivium: no suite "${name}"`);
|
|
4646
|
+
}
|
|
4615
4647
|
return nodes.filter(suite.isTest);
|
|
4616
4648
|
}
|
|
4617
4649
|
};
|
|
@@ -4784,4 +4816,4 @@ async function plan2(options = {}) {
|
|
|
4784
4816
|
};
|
|
4785
4817
|
}
|
|
4786
4818
|
|
|
4787
|
-
export { version, githubOutputPath,
|
|
4819
|
+
export { version, githubOutputPath, BiviumError2, didYouMean, globToRegExp, defineConfig2, inRoot, sorted, QUERY, UNDECLARED_READS, RELATIVE, aliasPath, createResolver, SCANNED, formatOf, extract, stringsOf, finish, gotoPage, walksByTypes, importersOf, affectedBy, formatSelection, orphanOf, plural, computePlan, prepare, plan2 };
|