/** * What the repository imports and exports, read from the source index. * * [`use.ts`](https://github.com/Variance-Authority/variance-authority/blob/main/packages/package/src/use.ts) can answer this by itself: walk every * directory, parse every module, collect every specifier. On this repository * that is 1336 files and about half a second, and the half second is paid again * on the next question about the same unchanged checkout. A repository ten times * the size — which is an ordinary repository — pays ten times that, every time, * to re-learn a tree where almost nothing moved. * * Nothing about the reading justifies the cost, because the reading is already * done. [`sense`](https://github.com/Variance-Authority/variance-authority/tree/main/packages/sense) keeps a durable, content-keyed index of exactly * these bytes: git names each file's content without opening it, the digest * names what parsing that content produced, and an update of an unchanged tree * reads no file. So a read here brings the index up to date over what Git says * moved, and reads the value off the written index in the addon, as `variance * index` does: one producer, and no parse row handed to JavaScript. * * ## Two readings, one index * * The scan's own question is which files reach which files. This question is * which *names* one package takes from another and which names each file hands * out, and the specifiers it needs are the same specifiers the scan resolved. * Sharing the index means the answer gets faster every time anything else in the * toolchain scans — and it means a repository that has never run a selection * still pays the full walk exactly once. * * Both halves of a file's parse are read, not just the requests. The exports are * what makes a name findable when no manifest publishes it, which is most of the * code in any checkout, and they cost nothing extra: the same cached parse that * already said what the file imports also says what it exports. */ import { type FileRecord, type Tree } from '@variance-authority/mcp/tools'; import { type Progress } from '@variance-authority/sense'; import { type Taint } from '@variance-authority/sense/taint'; import { type Help, type HelpOptions } from '@variance-authority/package/help'; export interface ReadingOptions extends HelpOptions, IndexedUsageOptions { } /** * How a question opens a generation: the published one as it stands, or, with * `changed` or `taints` named, one written from those files first. */ export interface AnsweringOptions extends ReadingOptions { /** Read the published generation regardless of age and perform no refresh. */ readonly justAnswer?: boolean; /** Refresh a published generation older than this. Defaults to one hour. */ readonly refreshAfterMs?: number; } /** * A read whose source index could not be saved. A tool reads lines out of the * index on disk and names out of the value it was given, so a value of this * read would answer with the last read's lines: it is thrown away, and the * generation before it stays whole, its value, index and times together. */ export declare class UnsavedRead extends Error { /** The reader's to fix, as {@link operatorError} says of any other refusal. */ readonly varianceOperatorError = true; constructor(refused: string); } /** * Answer from the published value while it is young enough, or refresh it when * the caller permits. `justAnswer` is the hard no-I/O-beyond-the-artifact path. */ export declare function readWorkspaceForAnswer(root: string, options?: AnsweringOptions): Promise; export interface IndexedUsageOptions { /** Where the index is kept. The checkout's own cache layer when absent. */ readonly index?: string; /** Read each file's bytes from Git's object store, as `variance index --no-git` turns off. On when absent. */ readonly packs?: boolean; /** * Changed file paths, relative to the scan root: present, the reading is * refreshed now whatever its age, and an empty list republishes it as it * stands. The index finds what moved from git, so the list names no file. */ readonly changed?: readonly string[]; /** * Additional declarative module loads to join onto the graph used by path * questions. * * These do not manufacture symbol bindings: usage counts remain facts from * ordinary imports inside the files the additional edge makes reachable. * Subtractive taints are refused because a mock is relative to one file's * run and cannot be flattened into the workspace-wide source tree. */ readonly taints?: readonly Taint[]; /** * Handed the arrows the scan drew, for a caller that needs the graph as well * as the names. * * The index holds the whole checkout's records; the published value keeps * only the names each file takes and hands out. A caller that has to answer * *which files does this path reach* takes the records here rather than * reading the index a second time. * * So it is a door rather than a return value: the reading that wants it is * not the reading this function performs, and a caller that does not want it * should not be handed a graph it has to ignore. */ readonly records?: (records: readonly FileRecord[], graphRoot: string) => void; /** Handed the queryable graph when a caller asks a path-shaped question: the tree this reading publishes. */ readonly tree?: (tree: Tree) => void; /** Told each step as it starts and ends: the manifests, the source, the names, the publish. */ readonly progress?: Progress; } /** * A workspace, read with the index doing the expensive third of the work. * * The same value [`readHelp`](https://github.com/Variance-Authority/variance-authority/blob/main/packages/package/src/help.ts) returns and the same * reading behind it — the manifests say which doors exist, the source behind * them says what is on the other side, and the repository says what it reaches * for. Only the third one changes: it comes from the source index rather than * from a walk, so asking a second question about an unchanged checkout costs the * manifests and nothing else. * * The update brings the index up to date and writes it, and the value is read * off the written index and published beside it, so a read whose index could * not be written throws {@link UnsavedRead}. Asynchronous because the index is a file: a * caller with no cache directory to write to, or one reading a tree it does not * own, wants `readHelp` and should keep having it. */ export declare function readWorkspace(root: string, options?: ReadingOptions): Promise; /** * Read the workspace again over a value published before it. * * Every read publishes the whole value off the saved index, so `documented` * says only when its read began. A refresh of `changed` files keeps that time as * `readStartedAt`: it is never later than the update's own start, so a file * saved since either read is compared again. */ export declare function refreshWorkspace(root: string, documented: Help, options?: ReadingOptions): Promise; //# sourceMappingURL=read.d.ts.map