bivium 0.3.3 → 0.5.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.
@@ -1,49 +1,21 @@
1
- /** One glob, or several. */
2
- export type Globs = string | readonly string[];
3
- /** A test suite: its files, how to run them, and how they're wired. */
4
- export interface SuiteConfig {
5
- /** The suite's test files. */
6
- tests: Globs;
7
- /** The command `bivium run` runs. `{files}` is replaced by the selected files, or nothing for all of them; without it, they're appended. */
8
- run?: string;
9
- /**
10
- * Where the orphan rule applies: a changed file under one of these paths
11
- * that no test of the suite reaches is wired some other way (a setup
12
- * file, a runner config), so the whole suite runs. Also where `goto()`
13
- * calls are read. Paths, not globs. Default: the whole repository.
14
- */
15
- root?: string | readonly string[];
16
- /**
17
- * URL pattern → the page a `page.goto()` of it opens: `{ "/*":
18
- * "e2e/fixtures/*" }`. A list names the page first, then what else it
19
- * loads that no import says, such as a router's layouts; the page must
20
- * exist, and the rest are edges where they do.
21
- */
22
- urls?: Readonly<Record<string, string | readonly string[]>>;
23
- /** Pages only a `goto()` opens. A changed file that only such pages load, and that no test opens, is wired to no test. */
24
- pages?: Globs;
25
- /** Files whose change runs the whole suite: a second harness, a runner config. */
26
- wiring?: Globs;
27
- /**
28
- * Files the runner loads before every test (Vitest and Jest `setupFiles`,
29
- * Mocha `--require`, Playwright `globalSetup`): every test of the suite
30
- * depends on them, and on what they import.
31
- */
32
- setup?: Globs;
33
- /** Files under `root` the runner never reads, such as type-check inputs: exempt from the orphan rule. */
34
- nonInputs?: Globs;
35
- /**
36
- * Whether the suite's tests can observe types. `false` for a suite that
37
- * runs code (Vitest, Jest, Playwright, `bun test`): a change that reaches
38
- * its tests only through type-only edges (`import type`, `export type …
39
- * from`, JSDoc types, declaration files) selects none of them. For the
40
- * orphan rule only a declaration file counts as reached that way: list a
41
- * types-only module under `root` in `nonInputs`. Default:
42
- * `true`, for a type-checking suite (`tsc`, `vitest --typecheck`).
43
- */
44
- types?: boolean;
45
- /** The step output `bivium plan --github` writes the selection to. Default: `<name>-tests`. */
46
- output?: string;
1
+ /**
2
+ * Picks the tests of each suite that the working tree's changes against
3
+ * `base` can affect.
4
+ */
5
+ export declare function plan<Suite extends string>(options: PlanOptions<Suite> & {
6
+ config: Config<Suite>;
7
+ }): Promise<PlanResult<Suite>>;
8
+ export declare function plan(options?: PlanOptions): Promise<PlanResult>;
9
+ /** Options for {@link plan}. */
10
+ export interface PlanOptions<Suite extends string = string> {
11
+ /** The repository. Default: the current directory. */
12
+ cwd?: string;
13
+ /** The ref to compare the working tree with. Default: the config's `base`, else the upstream default branch. */
14
+ base?: string;
15
+ /** The config. Default: the `bivium.config.*` file in `cwd`. */
16
+ config?: Config<Suite>;
17
+ /** Overrides the config's `cache`: a directory, or `false` for none. */
18
+ cache?: boolean | string;
47
19
  }
48
20
  /** A `bivium.config.ts`. `Suite` is the union of the suite names. */
49
21
  export interface Config<Suite extends string = string> {
@@ -140,71 +112,86 @@ export interface Config<Suite extends string = string> {
140
112
  /** The extraction cache's directory, or `false` for none. Default: `node_modules/.cache/bivium`, or `.bivium/cache` without `node_modules`. */
141
113
  cache?: boolean | string;
142
114
  }
143
- /** A suite's selected tests. */
144
- export type Selection = {
145
- mode: "all";
146
- } | {
147
- mode: "none";
148
- } | {
149
- mode: "some";
150
- files: string[];
151
- };
152
- /** Why some suites run in full, for a program to act on. */
153
- export interface FullRunCause<Suite extends string = string> {
115
+ /** A test suite: its files, how to run them, and how they're wired. */
116
+ export interface SuiteConfig {
117
+ /** The suite's test files. */
118
+ tests: Globs;
119
+ /** The command `bivium run` runs. `{files}` is replaced by the selected files, or nothing for all of them; without it, they're appended. */
120
+ run?: string;
154
121
  /**
155
- * `self`: the selector's own file changed. `wiring`: a suite's `wiring`
156
- * file. `outside`: a file outside the roots. `lockfile`: a lockfile
157
- * added, deleted, unreadable, or with changed settings. `package`: a
158
- * changed package no test imports.
159
- * `orphan`: a file under a suite's `root` no test of it reaches.
160
- * `narrower`: a narrower that couldn't decide.
122
+ * Where the orphan rule applies: a changed file under one of these paths
123
+ * that no test of the suite reaches is wired some other way (a setup
124
+ * file, a runner config), so the whole suite runs. Also where `goto()`
125
+ * calls are read. Paths, not globs. Default: the whole repository.
161
126
  */
162
- kind: "self" | "wiring" | "outside" | "lockfile" | "package" | "orphan" | "narrower";
163
- /** The suites it runs in full. */
164
- suites: Suite[];
165
- /** The changed file, when one is the cause. */
166
- file?: string;
167
- /** For `package`: the package no test imports. */
168
- package?: string;
169
- /** For `narrower`: its name. */
170
- narrower?: string;
171
- /** The sentence `reasons` has for it. */
172
- message: string;
127
+ root?: string | readonly string[];
128
+ /**
129
+ * URL pattern → the page a `page.goto()` of it opens: `{ "/*":
130
+ * "e2e/fixtures/*" }`. A list names the page first, then what else it
131
+ * loads that no import says, such as a router's layouts; the page must
132
+ * exist, and the rest are edges where they do.
133
+ */
134
+ urls?: Readonly<Record<string, string | readonly string[]>>;
135
+ /** Pages only a `goto()` opens. A changed file that only such pages load, and that no test opens, is wired to no test. */
136
+ pages?: Globs;
137
+ /** Files whose change runs the whole suite: a second harness, a runner config. */
138
+ wiring?: Globs;
139
+ /**
140
+ * Files the runner loads before every test (Vitest and Jest `setupFiles`,
141
+ * Mocha `--require`, Playwright `globalSetup`): every test of the suite
142
+ * depends on them, and on what they import.
143
+ */
144
+ setup?: Globs;
145
+ /** Files under `root` the runner never reads, such as type-check inputs: exempt from the orphan rule. */
146
+ nonInputs?: Globs;
147
+ /**
148
+ * Whether the suite's tests can observe types. `false` for a suite that
149
+ * runs code (Vitest, Jest, Playwright, `bun test`): a change that reaches
150
+ * its tests only through type-only edges (`import type`, `export type …
151
+ * from`, JSDoc types, declaration files) selects none of them. For the
152
+ * orphan rule only a declaration file counts as reached that way: list a
153
+ * types-only module under `root` in `nonInputs`. Default:
154
+ * `true`, for a type-checking suite (`tsc`, `vitest --typecheck`).
155
+ */
156
+ types?: boolean;
157
+ /** The step output `bivium plan --github` writes the selection to. Default: `<name>-tests`. */
158
+ output?: string;
173
159
  }
174
- /** Options for {@link plan}. */
175
- export interface PlanOptions<Suite extends string = string> {
176
- /** The repository. Default: the current directory. */
177
- cwd?: string;
178
- /** The ref to compare the working tree with. Default: the config's `base`, else the upstream default branch. */
179
- base?: string;
180
- /** The config. Default: the `bivium.config.*` file in `cwd`. */
181
- config?: Config<Suite>;
182
- /** Overrides the config's `cache`: a directory, or `false` for none. */
183
- cache?: boolean | string;
160
+ /** One glob, or several. */
161
+ export type Globs = string | readonly string[];
162
+ /**
163
+ * Replaces the coarse seeds of some changed files with finer ones from a
164
+ * semantic diff: a stylesheet change seeded with the sources that render a
165
+ * changed rule, instead of every page that loads the stylesheet.
166
+ *
167
+ * The matched files still seed the walk, but it stops at the `opaque`
168
+ * nodes they reach the tests through; the narrower's seeds stand in for
169
+ * those. A narrower can only narrow: its selection is cut to what the
170
+ * coarse walk selects. One that can't decide returns `{ all: reason }`, and
171
+ * one that throws counts as that.
172
+ */
173
+ export interface Narrower<Suite extends string = string> {
174
+ /** Names it in reasons: `css/: …`. */
175
+ name: string;
176
+ /** The changed files it narrows. */
177
+ match: Globs;
178
+ /** The generated nodes its seeds stand in for, such as `dist/*.css`. */
179
+ opaque: Globs;
180
+ /** The suites it narrows. Default: every suite. */
181
+ suites?: readonly Suite[];
182
+ narrow(context: NarrowContext<Suite>): NarrowResult | Promise<NarrowResult>;
184
183
  }
185
- /** What {@link plan} selected. */
186
- export interface PlanResult<Suite extends string = string> {
187
- /** Each suite's tests: `all`, `none`, or the files that can be affected. */
188
- suites: Record<Suite, Selection>;
189
- /** Why a suite runs in full. */
190
- reasons: string[];
191
- /** The same, as data: one per reason, in order. */
192
- causes: FullRunCause<Suite>[];
193
- /** How many test files each suite has. */
194
- totals: Record<Suite, number>;
195
- /** A line per package a lockfile or `package.json` change changed, and that selects through its importers or nothing: `bun.lock: svelte 5.1.0 → 5.2.0`. */
196
- packages: string[];
197
- /** The base ref. */
198
- base: string;
199
- /** The merge base of `base` and `HEAD`, which the working tree is compared with. */
200
- mergeBase: string;
201
- /** The files changed since the merge base, untracked ones included. */
202
- changed: string[];
203
- /** What each narrower that ran returned. */
204
- narrowed: {
205
- name: string;
206
- result: NarrowResult;
207
- }[];
184
+ /** What a narrower is given. */
185
+ export interface NarrowContext<Suite extends string = string> {
186
+ /** The repository's root directory. */
187
+ root: string;
188
+ /** The merge base, which the working tree is compared with. */
189
+ base: Tree;
190
+ /** The working tree. */
191
+ head: Tree;
192
+ /** The changed files the narrower matches. */
193
+ changed: readonly string[];
194
+ graph: GraphView<Suite>;
208
195
  }
209
196
  /** A tree a narrower reads files from. */
210
197
  export interface Tree {
@@ -224,18 +211,6 @@ export interface GraphView<Suite extends string = string> {
224
211
  /** A suite's test files. */
225
212
  tests(suite: Suite): readonly string[];
226
213
  }
227
- /** What a narrower is given. */
228
- export interface NarrowContext<Suite extends string = string> {
229
- /** The repository's root directory. */
230
- root: string;
231
- /** The merge base, which the working tree is compared with. */
232
- base: Tree;
233
- /** The working tree. */
234
- head: Tree;
235
- /** The changed files the narrower matches. */
236
- changed: readonly string[];
237
- graph: GraphView<Suite>;
238
- }
239
214
  /**
240
215
  * Finer seeds for the matched files, with an optional line for the CLI to
241
216
  * print, or why the narrower can't tell: its suites then run in full.
@@ -246,38 +221,60 @@ export type NarrowResult = {
246
221
  } | {
247
222
  all: string;
248
223
  };
249
- /**
250
- * Replaces the coarse seeds of some changed files with finer ones from a
251
- * semantic diff: a stylesheet change seeded with the sources that render a
252
- * changed rule, instead of every page that loads the stylesheet.
253
- *
254
- * The matched files still seed the walk, but it stops at the `opaque`
255
- * nodes they reach the tests through; the narrower's seeds stand in for
256
- * those. A narrower can only narrow: its selection is cut to what the
257
- * coarse walk selects. One that can't decide returns `{ all: reason }`, and
258
- * one that throws counts as that.
259
- */
260
- export interface Narrower<Suite extends string = string> {
261
- /** Names it in reasons: `css/: …`. */
262
- name: string;
263
- /** The changed files it narrows. */
264
- match: Globs;
265
- /** The generated nodes its seeds stand in for, such as `dist/*.css`. */
266
- opaque: Globs;
267
- /** The suites it narrows. Default: every suite. */
268
- suites?: readonly Suite[];
269
- narrow(context: NarrowContext<Suite>): NarrowResult | Promise<NarrowResult>;
224
+ /** What {@link plan} selected. */
225
+ export interface PlanResult<Suite extends string = string> {
226
+ /** Each suite's tests: `all`, `none`, or the files that can be affected. */
227
+ suites: Record<Suite, Selection>;
228
+ /** Why a suite runs in full. */
229
+ reasons: string[];
230
+ /** The same, as data: one per reason, in order. */
231
+ causes: FullRunCause<Suite>[];
232
+ /** How many test files each suite has. */
233
+ totals: Record<Suite, number>;
234
+ /** A line per package a lockfile or `package.json` change changed, and that selects through its importers or nothing: `bun.lock: svelte 5.1.0 → 5.2.0`. */
235
+ packages: string[];
236
+ /** The base ref. */
237
+ base: string;
238
+ /** The merge base of `base` and `HEAD`, which the working tree is compared with. */
239
+ mergeBase: string;
240
+ /** The files changed since the merge base, untracked ones included. */
241
+ changed: string[];
242
+ /** What each narrower that ran returned. */
243
+ narrowed: {
244
+ name: string;
245
+ result: NarrowResult;
246
+ }[];
247
+ }
248
+ /** A suite's selected tests. */
249
+ export type Selection = {
250
+ mode: "all";
251
+ } | {
252
+ mode: "none";
253
+ } | {
254
+ mode: "some";
255
+ files: string[];
256
+ };
257
+ /** Why some suites run in full, for a program to act on. */
258
+ export interface FullRunCause<Suite extends string = string> {
259
+ /**
260
+ * `self`: the selector's own file changed. `wiring`: a suite's `wiring`
261
+ * file. `outside`: a file outside the roots. `lockfile`: a lockfile
262
+ * added, deleted, unreadable, or with changed settings. `package`: a
263
+ * changed package no test imports.
264
+ * `orphan`: a file under a suite's `root` no test of it reaches.
265
+ * `narrower`: a narrower that couldn't decide.
266
+ */
267
+ kind: "self" | "wiring" | "outside" | "lockfile" | "package" | "orphan" | "narrower";
268
+ /** The suites it runs in full. */
269
+ suites: Suite[];
270
+ /** The changed file, when one is the cause. */
271
+ file?: string;
272
+ /** For `package`: the package no test imports. */
273
+ package?: string;
274
+ /** For `narrower`: its name. */
275
+ narrower?: string;
276
+ /** The sentence `reasons` has for it. */
277
+ message: string;
270
278
  }
271
-
272
- /**
273
- * Picks the tests of each suite that the working tree's changes against
274
- * `base` can affect.
275
- */
276
- export declare function plan<Suite extends string>(options: PlanOptions<Suite> & {
277
- config: Config<Suite>;
278
- }): Promise<PlanResult<Suite>>;
279
-
280
- export declare function plan(options?: PlanOptions): Promise<PlanResult>;
281
-
282
279
  /** Types a config. Returns it unchanged. */
283
280
  export declare function defineConfig<Suite extends string>(config: Config<Suite>): Config<Suite>;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ defineConfig2,
3
+ plan2
4
+ } from "./shared.js";
5
+ export {
6
+ defineConfig2 as defineConfig,
7
+ plan2 as plan
8
+ };