@williamthorsen/nmr 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.readyup/kits/default.js +92 -19
- package/.readyup/manifest.json +11 -8
- package/README.md +83 -17
- package/agents/guidance/rulebooks/nmr.md +1 -1
- package/dist/esm/UserError.d.ts +6 -0
- package/dist/esm/check-cache.d.ts +145 -0
- package/dist/esm/commands/build-output.d.ts +64 -0
- package/dist/esm/commands/build.d.ts +29 -1
- package/dist/esm/commands/build.js +25 -5
- package/dist/esm/commands/clean.d.ts +15 -0
- package/dist/esm/commands/ensure-prepublish-hooks.d.ts +11 -0
- package/dist/esm/commands/fmt.d.ts +32 -0
- package/dist/esm/commands/report-catalog.d.ts +10 -0
- package/dist/esm/commands/report-overrides.d.ts +6 -0
- package/dist/esm/commands/taze.d.ts +18 -0
- package/dist/esm/config.d.ts +25 -0
- package/dist/esm/context.d.ts +11 -0
- package/dist/esm/default-scripts.d.ts +15 -0
- package/dist/esm/defineConfig.d.ts +9 -0
- package/dist/esm/help.d.ts +13 -0
- package/dist/esm/helpers/clampToBytes.d.ts +12 -0
- package/dist/esm/helpers/createBoundedBuffer.d.ts +7 -0
- package/dist/esm/helpers/deriveExcerpt.d.ts +10 -0
- package/dist/esm/helpers/duration.d.ts +15 -0
- package/dist/esm/helpers/hook-name.d.ts +8 -0
- package/dist/esm/helpers/package-json.d.ts +25 -0
- package/dist/esm/helpers/readStringValues.d.ts +7 -0
- package/dist/esm/helpers/reportClosing.d.ts +15 -0
- package/dist/esm/helpers/transcript.d.ts +25 -0
- package/dist/esm/helpers/type-guards.d.ts +1 -0
- package/dist/esm/helpers/workspace-patterns.d.ts +7 -0
- package/dist/esm/prettier.d.ts +8 -0
- package/dist/esm/recording.d.ts +39 -1
- package/dist/esm/replay-assembly.d.ts +18 -2
- package/dist/esm/report-format.d.ts +33 -0
- package/dist/esm/reportCliFailure.d.ts +8 -0
- package/dist/esm/resolve-scripts.d.ts +10 -1
- package/dist/esm/resolver.d.ts +67 -2
- package/dist/esm/resolver.js +1 -1
- package/dist/esm/runCli.d.ts +17 -0
- package/dist/esm/runCli.js +1 -1
- package/dist/esm/runner.d.ts +52 -0
- package/dist/esm/scripts.d.ts +1 -0
- package/dist/esm/steps.d.ts +71 -0
- package/dist/esm/taze.d.ts +16 -0
- package/dist/esm/tests.d.ts +40 -0
- package/dist/esm/tests.js +25 -0
- package/dist/esm/tiers.d.ts +56 -1
- package/dist/esm/tiers.js +22 -9
- package/dist/esm/types.d.ts +27 -0
- package/dist/esm/verbosity.d.ts +37 -0
- package/dist/esm/verdict.d.ts +45 -0
- package/dist/esm/vitest.d.ts +72 -2
- package/dist/esm/vitest.js +17 -9
- package/dist/esm/workspace.d.ts +18 -0
- package/package.json +18 -10
package/dist/esm/help.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
1
|
import type { NmrConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the help text for the `nmr` CLI. Renders only nmr commands —
|
|
4
|
+
* names from the workspace and root registries, excluding hooks (`*:pre`,
|
|
5
|
+
* `*:post`).
|
|
6
|
+
*
|
|
7
|
+
* When `packageDir` is provided, tier-3 entries from that package's
|
|
8
|
+
* `package.json:scripts` that match a registry name in the active section
|
|
9
|
+
* are inlined as overrides: the registry value is replaced with the
|
|
10
|
+
* override value and the row's command name is suffixed with `*`. The
|
|
11
|
+
* active section is the root section when `useRoot` is true (root cwd
|
|
12
|
+
* or `-w`), otherwise the workspace section. A footnote is appended once
|
|
13
|
+
* if any override marker was rendered.
|
|
14
|
+
*/
|
|
2
15
|
export declare function generateHelp(config: NmrConfig, packageDir: string | undefined, useRoot: boolean): string;
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
/** Marks a value that was cut, so a reader can tell a truncated one from a complete one. */
|
|
1
2
|
export declare const TRUNCATION_MARK = "\u2026";
|
|
3
|
+
/**
|
|
4
|
+
* Cuts a string that would overrun a byte budget, marking the cut. What comes back is at most `budgetBytes`
|
|
5
|
+
* long, the mark included.
|
|
6
|
+
*
|
|
7
|
+
* Cuts between code points rather than between bytes, so a multi-byte character is never left in halves.
|
|
8
|
+
* Graphemes are left unconsidered, which can separate an emoji from a modifier following it -- a cost paid
|
|
9
|
+
* only at a budget no caller here comes near.
|
|
10
|
+
*
|
|
11
|
+
* A budget too small to hold the mark yields nothing at all, rather than a return that overruns what the
|
|
12
|
+
* caller asked for.
|
|
13
|
+
*/
|
|
2
14
|
export declare function clampToBytes(value: string, budgetBytes: number): string;
|
|
@@ -3,7 +3,14 @@ export interface BoundedBufferOptions {
|
|
|
3
3
|
tailLimitBytes?: number;
|
|
4
4
|
}
|
|
5
5
|
export interface BoundedBuffer {
|
|
6
|
+
/** Retains a chunk, dropping bytes from the middle once both ends are full. */
|
|
6
7
|
append: (chunk: Buffer) => void;
|
|
8
|
+
/** Renders the retained bytes, with a marker naming the dropped count standing in for what was dropped. */
|
|
7
9
|
toBuffer: () => Buffer;
|
|
8
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates an accumulator that retains the first and last bytes it is fed and drops the middle.
|
|
13
|
+
* Both ends are kept because a failing command's first error and its trailing summary each carry signal
|
|
14
|
+
* that the other end does not.
|
|
15
|
+
*/
|
|
9
16
|
export declare function createBoundedBuffer(options?: BoundedBufferOptions): BoundedBuffer;
|
|
@@ -1 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reduces a transcript to the one line a verdict's detail slot carries, or `undefined` when it held nothing.
|
|
3
|
+
*
|
|
4
|
+
* The excerpt is the last blank-line-delimited block: a tool that prints progress separates its closing
|
|
5
|
+
* statement with a blank line, so the blank line is the tool naming where its summary starts. A fixed count of
|
|
6
|
+
* trailing lines fits vitest's four-line summary and v8's six-line coverage summary only by coincidence.
|
|
7
|
+
*
|
|
8
|
+
* The line carries a byte bound of its own, so what a caller persists is bounded. The 512-byte ceiling a
|
|
9
|
+
* verdict line is held to is not applied here, which leaves that line's grammar with the module that owns it.
|
|
10
|
+
*/
|
|
1
11
|
export declare function deriveExcerpt(transcript: string): string | undefined;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders a duration at the two coarsest units that say something, for a line a reader skims.
|
|
3
|
+
*
|
|
4
|
+
* Truncates at every unit rather than rounding, so a value never reads as more time than elapsed: 90 seconds is
|
|
5
|
+
* `1m 30s`, where rounding would claim `2m`. Below a minute the tenth is kept, since that is the scale at which
|
|
6
|
+
* one check's runtime differs from another's; a whole number sheds the `.0` rather than reading `12.0s`.
|
|
7
|
+
*/
|
|
1
8
|
export declare function formatDuration(milliseconds: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Renders the clause a skip spends on the time it saved, or `undefined` when there is no saving worth naming.
|
|
11
|
+
* A skip that can say what it saved earns the clause; one that cannot says nothing, and the caller drops it
|
|
12
|
+
* rather than printing a saving of `~0s`.
|
|
13
|
+
*
|
|
14
|
+
* Guards its own input rather than trusting the caller's, because the clause is shared: a non-finite duration
|
|
15
|
+
* compares false against the threshold, and would reach a reader as `saved ~NaNs`.
|
|
16
|
+
*/
|
|
2
17
|
export declare function formatSaving(milliseconds: number): string | undefined;
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true when `key` is a hook script name — that is, ends with the
|
|
3
|
+
* `:pre` or `:post` suffix preceded by at least one character.
|
|
4
|
+
*
|
|
5
|
+
* Bare `:pre` and `:post` (no parent name) return false. The predicate is
|
|
6
|
+
* purely about suffix shape; it does not consult the registry or care
|
|
7
|
+
* whether the parent command exists.
|
|
8
|
+
*/
|
|
1
9
|
export declare function isHookName(key: string): boolean;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `package.json` fields that carry a dependency's version specifier.
|
|
3
|
+
*
|
|
4
|
+
* pnpm accepts the `catalog:` protocol in all four, so a reader looking for catalogued dependencies has to
|
|
5
|
+
* sweep the whole set rather than the two that carry most of them.
|
|
6
|
+
*/
|
|
1
7
|
export declare const DEPENDENCY_FIELDS: readonly ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
2
8
|
export type DependencyField = (typeof DEPENDENCY_FIELDS)[number];
|
|
3
9
|
export type PackageJson = {
|
|
@@ -12,8 +18,27 @@ export type PackageJson = {
|
|
|
12
18
|
} & {
|
|
13
19
|
[K in DependencyField]?: Record<string, string>;
|
|
14
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Reads and parses the package.json at the given directory, keeping only the fields nmr reads.
|
|
23
|
+
*/
|
|
15
24
|
export declare function readPackageJson(dir: string): PackageJson;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the `pnpm.overrides` block a package.json declares, every key it holds and each value as written.
|
|
27
|
+
*/
|
|
16
28
|
export declare function getPnpmOverrides(pkg: PackageJson): Record<string, unknown> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Parses a `package.json`'s text, rejecting what does not parse.
|
|
31
|
+
*
|
|
32
|
+
* A file the user wrote by hand is theirs to fix, so the failure names it rather than reporting the parser's
|
|
33
|
+
* own stack.
|
|
34
|
+
*/
|
|
17
35
|
export declare function parsePackageJson(raw: string, file: string): unknown;
|
|
36
|
+
/**
|
|
37
|
+
* Narrows a `scripts` record to strings, rejecting any value that is not one.
|
|
38
|
+
*
|
|
39
|
+
* npm and pnpm read a script as a string too, so a value of any other type is malformed however it got there.
|
|
40
|
+
* Dropping one silently would let a caller run something else in its place and report nothing.
|
|
41
|
+
*/
|
|
18
42
|
export declare function readScriptRecord(dir: string, scripts: Record<string, unknown>): Record<string, string>;
|
|
43
|
+
/** Resolves the `package.json` path for a directory: the file tier-3 scripts are read from. */
|
|
19
44
|
export declare function resolvePackageJsonPath(dir: string): string;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps the entries whose value is a string, dropping the rest.
|
|
3
|
+
*
|
|
4
|
+
* A manifest reader that rejected the whole record over one bad value would report nothing about the entries
|
|
5
|
+
* beside it, which for a reporter is silence where there is something to say. YAML's implicit typing makes
|
|
6
|
+
* that easy to reach without malformed intent: an unquoted `18` parses as a number.
|
|
7
|
+
*/
|
|
1
8
|
export declare function readStringValues(record: Record<string, unknown>): Record<string, string>;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports the line that closes a bin's output, separated from the items above it by a blank line.
|
|
3
|
+
*
|
|
4
|
+
* A bin that prints one line per item leaves a reader who reaches the end holding whichever item happened to
|
|
5
|
+
* be last. The convention this writes: the header says what the list is, and the closing statement says what
|
|
6
|
+
* the run came to, so the count and the remedy live here rather than in the header. The blank line is what
|
|
7
|
+
* makes the statement findable once the lines are flattened.
|
|
8
|
+
*
|
|
9
|
+
* The blank line rides in the same call as the statement, so the closer is one write and cannot be
|
|
10
|
+
* interleaved. `log` is what puts the closer on the stream its items went to: a bin reporting to stderr
|
|
11
|
+
* passes `console.warn`.
|
|
12
|
+
*
|
|
13
|
+
* A bin whose whole output is one or two statements about one subject has no items to be separated from, and
|
|
14
|
+
* closes by printing plainly rather than through here.
|
|
15
|
+
*/
|
|
1
16
|
export declare function reportClosing(message: string, log?: (line: string) => void): void;
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import type { RetainedOutput } from '../runner.js';
|
|
2
|
+
/**
|
|
3
|
+
* The bound on what one recorded pass persists, and so on what `nmr --log` can print back.
|
|
4
|
+
*
|
|
5
|
+
* A quantity of its own, distinct from the two that bound the same bytes elsewhere: the in-memory copy a
|
|
6
|
+
* command's capture keeps is bounded per stream, for a failure this run may still have to report, and a
|
|
7
|
+
* verdict line is bounded at what a pipe carries atomically. This one bounds what a cache directory
|
|
8
|
+
* accumulates over every scope and command a repo records.
|
|
9
|
+
*/
|
|
2
10
|
export declare const TRANSCRIPT_LIMIT_BYTES = 262144;
|
|
11
|
+
/**
|
|
12
|
+
* Reduces a command's raw output to the form nmr persists: escape sequences dropped, and a line the command
|
|
13
|
+
* redrew reduced to what a reader was left looking at.
|
|
14
|
+
*
|
|
15
|
+
* Applied where the bytes are stored rather than where they are captured. The copy a quiet run writes to
|
|
16
|
+
* stderr on failure is the command's own output going to a stream that may be a terminal, and stripping its
|
|
17
|
+
* color there would be a loss.
|
|
18
|
+
*/
|
|
3
19
|
export declare function cleanTranscript(raw: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Composes what a pass persists from what its command wrote, or `undefined` where it wrote nothing worth
|
|
22
|
+
* keeping.
|
|
23
|
+
*
|
|
24
|
+
* The streams follow one another rather than interleaving, in the order a quiet run already dumps them on
|
|
25
|
+
* failure: nmr reads each through a pipe of its own, so their true interleaving is not among the facts it
|
|
26
|
+
* holds. A stream carrying nothing contributes neither content nor marker.
|
|
27
|
+
*/
|
|
4
28
|
export declare function composeTranscript(retained: RetainedOutput): string | undefined;
|
|
29
|
+
/** Renders the line that stands in for dropped bytes, in nmr's voice so it is not mistaken for the tool's. */
|
|
5
30
|
export declare function formatElisionMarker(byteCount: number): string;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves pnpm workspace patterns to absolute package directories.
|
|
3
|
+
*
|
|
4
|
+
* Applies pnpm's algorithm: every pattern is rewritten to match a manifest, `!`-prefixed patterns become
|
|
5
|
+
* exclusions, and the matcher decides the rest. Exclusions filter the entire positive match set
|
|
6
|
+
* irrespective of declaration order.
|
|
7
|
+
*/
|
|
1
8
|
export declare function resolvePackageDirs(monorepoRoot: string, patterns: string[]): string[];
|
package/dist/esm/prettier.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import type { Config } from 'prettier';
|
|
2
2
|
export interface PrettierConfigOptions extends Omit<Config, 'overrides' | 'plugins'> {
|
|
3
|
+
/** Appended to the plugins this config registers. */
|
|
3
4
|
additionalPlugins?: NonNullable<Config['plugins']>;
|
|
5
|
+
/** Appended to the overrides this config declares, so a later entry wins over nmr's own. */
|
|
4
6
|
additionalOverrides?: NonNullable<Config['overrides']>;
|
|
7
|
+
/** Replacing the override list is inexpressible; append through `additionalOverrides`. */
|
|
5
8
|
overrides?: never;
|
|
9
|
+
/** Replacing the plugin list is inexpressible; append through `additionalPlugins`. */
|
|
6
10
|
plugins?: never;
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds the shared Prettier config, registering shell and Dockerfile support alongside the house options.
|
|
14
|
+
* Every option other than `plugins` and `overrides` spreads over the defaults.
|
|
15
|
+
*/
|
|
8
16
|
export declare function definePrettierConfig(options?: PrettierConfigOptions): Config;
|
package/dist/esm/recording.d.ts
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CheckCacheEntry } from './check-cache.js';
|
|
2
|
+
/**
|
|
3
|
+
* What this invocation would be recorded under, insofar as an entry records the same facts. A mismatch is read
|
|
4
|
+
* against these, so a refusal names the ingredient that moved rather than blaming the tree for all of them.
|
|
5
|
+
*/
|
|
2
6
|
export interface RunIdentity {
|
|
3
7
|
commandString: string;
|
|
4
8
|
nmrVersion: string;
|
|
5
9
|
nodeVersion: string;
|
|
10
|
+
/** Absent where no snapshot was taken, which leaves the tree unattributable rather than assumed equal. */
|
|
6
11
|
treeHash: string | undefined;
|
|
7
12
|
}
|
|
13
|
+
/** A recorded pass and what it left a reader: its command's own transcript, or the assembly a composite holds. */
|
|
8
14
|
export interface Recording {
|
|
9
15
|
entry: CheckCacheEntry;
|
|
16
|
+
/** What the command wrote, absent on a composite, which retains nothing of its own. */
|
|
10
17
|
transcript?: string;
|
|
11
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Which of the pass key's ingredients a recorded pass and this invocation disagree on, insofar as an entry
|
|
21
|
+
* records enough to tell: the residual covers what it does not, which is the install, the platform, and the
|
|
22
|
+
* environment variables the key folds in.
|
|
23
|
+
*/
|
|
12
24
|
export type KeyDifference = {
|
|
13
25
|
ingredient: 'tree';
|
|
14
26
|
} | {
|
|
@@ -24,6 +36,7 @@ export type KeyDifference = {
|
|
|
24
36
|
} | {
|
|
25
37
|
ingredient: 'other';
|
|
26
38
|
};
|
|
39
|
+
/** What `--log` found for one command at one scope. */
|
|
27
40
|
export type RecordingLookup = {
|
|
28
41
|
ok: true;
|
|
29
42
|
recording: Recording;
|
|
@@ -31,6 +44,11 @@ export type RecordingLookup = {
|
|
|
31
44
|
ok: false;
|
|
32
45
|
refusal: RecordingRefusal;
|
|
33
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Why there is nothing to print. Each is a separate answer to a reader asking for the last run's output, and
|
|
49
|
+
* each names a different next move: run the command, run it on this tree, run it through a pipe, or stop
|
|
50
|
+
* asking for a command no run records.
|
|
51
|
+
*/
|
|
34
52
|
export type RecordingRefusal = {
|
|
35
53
|
kind: 'uncacheable';
|
|
36
54
|
} | {
|
|
@@ -45,16 +63,36 @@ export type RecordingRefusal = {
|
|
|
45
63
|
kind: 'no-output';
|
|
46
64
|
ageMs: number;
|
|
47
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Renders a recording as the reader sees it: a header dating what follows, the command string that produced
|
|
68
|
+
* it, and then the run's own bytes.
|
|
69
|
+
*
|
|
70
|
+
* The header is what presents the body as a recording rather than as this invocation's output, which is what
|
|
71
|
+
* lets a reader at a terminal be shown what a piped run wrote. The command string is the whole chain, hooks
|
|
72
|
+
* included, so the header names what earned the pass and not merely what was typed.
|
|
73
|
+
*/
|
|
48
74
|
export declare function renderRecording(options: {
|
|
49
75
|
command: string;
|
|
50
76
|
recording: Recording;
|
|
51
77
|
scope: string;
|
|
52
78
|
}): string;
|
|
79
|
+
/**
|
|
80
|
+
* Renders a refusal on the one line a fan-out can attribute, in the grammar a verdict uses: the scope, the
|
|
81
|
+
* command, and what is missing.
|
|
82
|
+
*/
|
|
53
83
|
export declare function renderRefusal(options: {
|
|
54
84
|
command: string;
|
|
55
85
|
refusal: RecordingRefusal;
|
|
56
86
|
scope: string;
|
|
57
87
|
}): string;
|
|
88
|
+
/**
|
|
89
|
+
* Resolves what one scope has to show for one command.
|
|
90
|
+
*
|
|
91
|
+
* Admitted on the pass key alone, so `--log` prints exactly what a skip would have recalled and never a
|
|
92
|
+
* recording of some other tree. The retention key is deliberately not consulted: it certifies that a recording
|
|
93
|
+
* describes this presentation environment, which is what a replayed excerpt needs and what a dated recording
|
|
94
|
+
* does not.
|
|
95
|
+
*/
|
|
58
96
|
export declare function resolveRecording(options: {
|
|
59
97
|
anchorDir: string;
|
|
60
98
|
command: string;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import { type ReplayLine } from './check-cache.js';
|
|
2
|
+
import { type Step } from './steps.js';
|
|
3
|
+
/**
|
|
4
|
+
* Assembles what a composite's skip replays: the excerpts its constituents recorded, in the order its own
|
|
5
|
+
* steps name them.
|
|
6
|
+
*
|
|
7
|
+
* A constituent that is itself a composite holds a flat, attributed list of its own, so splicing one in keeps
|
|
8
|
+
* the assembly flat and a skipped `ci` replays a package's `test` rather than one opaque `check:strict`
|
|
9
|
+
* line. Nothing is computed and nothing is inferred: a constituent with no admissible entry is absent from
|
|
10
|
+
* the assembly.
|
|
11
|
+
*
|
|
12
|
+
* A constituent is looked up at the scope its own process anchors at: the composite's anchor, or the monorepo
|
|
13
|
+
* root for an element carrying `-w`, which is how a package-scoped composite reaches a root command.
|
|
14
|
+
*
|
|
15
|
+
* An entry is admissible where the run that certified it is this one and the tree it describes is this one.
|
|
16
|
+
* The witness is what a run stamps on an excerpt it records and on one it recalls and replays; the tree hash
|
|
17
|
+
* is what bounds an identity a process carried out of the run that issued it.
|
|
18
|
+
*/
|
|
3
19
|
export declare function assembleReplay(options: {
|
|
4
20
|
anchorDir: string;
|
|
5
21
|
monorepoRoot: string;
|
|
@@ -1,9 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders the rejection of a value off the format ladder, naming where it was written. Every source that
|
|
3
|
+
* accepts a format renders through this, so no two of them can come to name different ladders.
|
|
4
|
+
*/
|
|
1
5
|
export declare function formatReportFormatRejection(source: string, value: string): string;
|
|
6
|
+
/** Narrows a raw value to a point on the format ladder. */
|
|
2
7
|
export declare function isReportFormat(value: string): value is ReportFormat;
|
|
8
|
+
/**
|
|
9
|
+
* Reads the format the environment names. An unrecognized value resolves to nothing at all, since falling back
|
|
10
|
+
* would pick a rendering nobody chose and hide a misspelling for the life of the shell.
|
|
11
|
+
*
|
|
12
|
+
* An unset or empty variable names no format rather than resolving to `text`, which keeps the read symmetric
|
|
13
|
+
* with the one the loudness ladder performs and leaves room for a level below the environment.
|
|
14
|
+
*/
|
|
3
15
|
export declare function readReportFormatEnv(env: NodeJS.ProcessEnv): ReportFormatRead;
|
|
16
|
+
/**
|
|
17
|
+
* Carries the resolved format down the spawned chain, so `--json` reaches every process rather than the first.
|
|
18
|
+
* Deliberately not a keyed variable: it changes how a run reports and never what a command concludes, so
|
|
19
|
+
* folding it into the cache key would stop a machine-readable run from hitting a pass a prose one recorded.
|
|
20
|
+
*/
|
|
4
21
|
export declare const REPORT_FORMAT_ENV_VAR = "NMR_REPORT_FORMAT";
|
|
22
|
+
/**
|
|
23
|
+
* The points on the format ladder. Both are spelled out rather than leaving `text` implicit in the variable's
|
|
24
|
+
* absence, so a format exported for a shell is overridable on one invocation in either direction.
|
|
25
|
+
*/
|
|
5
26
|
export declare const REPORT_FORMATS: readonly ["text", "json"];
|
|
27
|
+
/** How nmr renders its own verdicts, which is never the output of the commands it runs. */
|
|
6
28
|
export type ReportFormat = (typeof REPORT_FORMATS)[number];
|
|
29
|
+
/** The format the environment names, if any, or the message naming why its value could not be read. */
|
|
7
30
|
export type ReportFormatRead = {
|
|
8
31
|
ok: true;
|
|
9
32
|
format?: ReportFormat;
|
|
@@ -11,6 +34,16 @@ export type ReportFormatRead = {
|
|
|
11
34
|
ok: false;
|
|
12
35
|
error: string;
|
|
13
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the format this process reports in: the flag, then the environment, then `text`.
|
|
39
|
+
*
|
|
40
|
+
* Two levels where the loudness ladder has four. A repo wanting JSON for everyone working in it is not a case
|
|
41
|
+
* anyone has, and detecting a harness would hand every agent JSON in place of the prose the shipped guidance
|
|
42
|
+
* teaches; either is additive later.
|
|
43
|
+
*
|
|
44
|
+
* Total by construction. The environment was validated as it was read, so no rejection is left for this to
|
|
45
|
+
* report and the whole ladder reads in one place.
|
|
46
|
+
*/
|
|
14
47
|
export declare function resolveReportFormat(options: ResolveReportFormatOptions): ReportFormat;
|
|
15
48
|
export interface ResolveReportFormatOptions {
|
|
16
49
|
envFormat: ReportFormat | undefined;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import type { Writable } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* Writes a failure to the CLI's error stream: as its message alone when the user's own declaration caused it,
|
|
4
|
+
* and with its stack otherwise.
|
|
5
|
+
*
|
|
6
|
+
* A stack records where nmr noticed a problem, which says nothing about the file a user has to edit; for nmr's
|
|
7
|
+
* own fault it is where a report has to start. `describeError` covers an `Error` carrying no stack and a thrown
|
|
8
|
+
* non-`Error` alike.
|
|
9
|
+
*/
|
|
2
10
|
export declare function reportCliFailure(error: unknown, stderr: Writable): void;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ScriptRegistry } from './default-scripts.js';
|
|
2
2
|
export type { ScriptRegistry, ScriptValue, StepSpec } from './default-scripts.js';
|
|
3
|
+
/**
|
|
4
|
+
* Return the default workspace scripts.
|
|
5
|
+
*
|
|
6
|
+
* A function rather than the exported table itself: callers merge overrides into the result, and `generateHelp`
|
|
7
|
+
* rewrites entries in place, so each caller needs a copy the module does not share.
|
|
8
|
+
*/
|
|
3
9
|
export declare function getDefaultWorkspaceScripts(): ScriptRegistry;
|
|
10
|
+
/**
|
|
11
|
+
* Return the default root scripts.
|
|
12
|
+
*/
|
|
4
13
|
export declare function getDefaultRootScripts(): ScriptRegistry;
|
package/dist/esm/resolver.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import { type ScriptRegistry, type ScriptValue } from './resolve-scripts.js';
|
|
2
|
+
import { type Step } from './steps.js';
|
|
3
3
|
import type { NmrConfig } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Replace the first token of a command with a `devBin` substitute.
|
|
6
|
+
* Relative paths in the replacement are resolved from `monorepoRoot`.
|
|
7
|
+
*/
|
|
4
8
|
export declare function applyDevBin(command: string, devBin: Record<string, string> | undefined, monorepoRoot: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Applies a `devBin` substitution to each opaque step, leaving nmr's own compositions alone.
|
|
11
|
+
*
|
|
12
|
+
* A structural step names a command nmr resolves for itself, so substituting its first token would replace the
|
|
13
|
+
* `nmr` that carries the composite rather than the leaf tool `devBin` documents replacing.
|
|
14
|
+
*/
|
|
5
15
|
export declare function applyDevBinToSteps(steps: readonly Step[], devBin: Record<string, string> | undefined, monorepoRoot: string): readonly Step[];
|
|
16
|
+
/**
|
|
17
|
+
* Where a resolved script was read from.
|
|
18
|
+
*
|
|
19
|
+
* `registry` covers the built-in defaults and the repo-wide config together, which resolution cannot tell
|
|
20
|
+
* apart: it receives the two already merged. A caller holding the config refines the two.
|
|
21
|
+
*/
|
|
6
22
|
export type ScriptOrigin = {
|
|
7
23
|
tier: 'registry';
|
|
8
24
|
key: string;
|
|
@@ -15,11 +31,60 @@ export interface ResolvedScript {
|
|
|
15
31
|
origin: ScriptOrigin;
|
|
16
32
|
steps: readonly Step[];
|
|
17
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Expands a script value into the ordered steps it runs as: a string is one opaque step, and an array is one
|
|
36
|
+
* structural step per element.
|
|
37
|
+
*
|
|
38
|
+
* A bare string element and the `{ run }` spec compose the same step. The spec's only addition is the
|
|
39
|
+
* declaration of what the step does with the invocation's trailing arguments, which position cannot carry.
|
|
40
|
+
*/
|
|
18
41
|
export declare function expandScript(script: ScriptValue, workspaceRoot: boolean): readonly Step[];
|
|
42
|
+
/**
|
|
43
|
+
* Returns a description of a script for help output.
|
|
44
|
+
*/
|
|
19
45
|
export declare function describeScript(script: ScriptValue): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reads a package.json's `scripts`, rejecting any value that is not a string.
|
|
48
|
+
*
|
|
49
|
+
* npm and pnpm read a script as a string too, so a value of any other type is malformed however it got there.
|
|
50
|
+
* Dropping one silently would run the registry's entry in its place, which is what an array written here after
|
|
51
|
+
* being told a step list resolves a shelled-nmr crossing would otherwise do.
|
|
52
|
+
*/
|
|
20
53
|
export declare function readPackageJsonScripts(packageDir: string): Record<string, string> | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Builds the merged workspace script registry:
|
|
56
|
+
* tier 1 (defaults) + tier 2 (config overrides)
|
|
57
|
+
*/
|
|
21
58
|
export declare function buildWorkspaceRegistry(config: NmrConfig): ScriptRegistry;
|
|
59
|
+
/**
|
|
60
|
+
* Builds the merged root script registry:
|
|
61
|
+
* tier 1 (defaults) + tier 2 (config overrides)
|
|
62
|
+
*/
|
|
22
63
|
export declare function buildRootRegistry(config: NmrConfig): ScriptRegistry;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a `package.json` entry that re-invokes the command it is declared under alongside other steps, or
|
|
66
|
+
* `undefined` where the entry declares no such thing.
|
|
67
|
+
*
|
|
68
|
+
* Resolution discards a self-referential entry however it reads, so an entry that chains loses the steps it
|
|
69
|
+
* chained. This is what an invocation rejects on, read where the command runs rather than raised from
|
|
70
|
+
* resolution: the same scripts are resolved speculatively, for packages nobody named.
|
|
71
|
+
*/
|
|
23
72
|
export declare function findChainedSelfReference(packageDir: string | undefined, commandName: string): string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Reports whether a `package.json` entry re-invokes the command it is declared under, wherever the
|
|
75
|
+
* re-invocation stands in it, e.g. `"build": "nmr build"` or `"build": "rdy compile && nmr build"`.
|
|
76
|
+
*
|
|
77
|
+
* Honouring one spawns a shell that runs the same command in the same directory, reaching the same entry
|
|
78
|
+
* again without bound, so resolution discards it.
|
|
79
|
+
*/
|
|
24
80
|
export declare function isSelfReferential(script: string, commandName: string, packageDir: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Resolves a script command using the three-tier override system:
|
|
83
|
+
* 1. Package defaults (built-in registry)
|
|
84
|
+
* 2. Repo-wide config (.config/nmr.config.ts)
|
|
85
|
+
* 3. Per-package overrides (package.json scripts)
|
|
86
|
+
*
|
|
87
|
+
* Returns undefined if the command is not found in the registry. A package.json override of `""` (indicating
|
|
88
|
+
* skip) resolves to a single opaque step carrying it, which renders back to the empty string.
|
|
89
|
+
*/
|
|
25
90
|
export declare function resolveScript(commandName: string, registry: ScriptRegistry, packageDir: string | undefined, workspaceRoot: boolean): ResolvedScript | undefined;
|
package/dist/esm/resolver.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { hasErrnoCode } from '@williamthorsen/nmr-core';
|
|
4
4
|
import { parsePackageJson, readScriptRecord, resolvePackageJsonPath } from "./helpers/package-json.js";
|
|
5
5
|
import { isObject } from "./helpers/type-guards.js";
|
|
6
|
-
import { getDefaultRootScripts, getDefaultWorkspaceScripts } from "./resolve-scripts.js";
|
|
6
|
+
import { getDefaultRootScripts, getDefaultWorkspaceScripts, } from "./resolve-scripts.js";
|
|
7
7
|
import { composeNmrStep, readSelfReference } from "./steps.js";
|
|
8
8
|
import { isMonorepoRoot } from "./workspace.js";
|
|
9
9
|
export function applyDevBin(command, devBin, monorepoRoot) {
|
package/dist/esm/runCli.d.ts
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import type { Writable } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a run made on a delegating caller's behalf, where a command the registry does not define exits 0
|
|
4
|
+
* rather than failing.
|
|
5
|
+
*/
|
|
2
6
|
export declare const RUN_IF_PRESENT_ENV_VAR = "NMR_RUN_IF_PRESENT";
|
|
7
|
+
/** @internal */
|
|
3
8
|
export interface RunCliOptions {
|
|
9
|
+
/** Post-slice CLI arguments (equivalent to `process.argv.slice(2)`). */
|
|
4
10
|
args: string[];
|
|
11
|
+
/** Working directory used to resolve the nmr execution context. */
|
|
5
12
|
cwd: string;
|
|
13
|
+
/** Environment for `runCli` (used for `NMR_RUN_IF_PRESENT` reads and `-R` writes). */
|
|
6
14
|
env: NodeJS.ProcessEnv;
|
|
15
|
+
/** Stream for normal output (help text, override messages). */
|
|
7
16
|
stdout: Writable;
|
|
17
|
+
/** Stream for error output (unknown command, parse errors). */
|
|
8
18
|
stderr: Writable;
|
|
9
19
|
}
|
|
20
|
+
/** @internal */
|
|
10
21
|
export interface RunCliResult {
|
|
11
22
|
exitCode: number;
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Executes the nmr CLI flow in-process and returns the resulting exit code.
|
|
26
|
+
* Holds no global state, reads no `process.*` globals, never calls `process.exit`.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
13
30
|
export declare function runCli(options: RunCliOptions): Promise<RunCliResult>;
|
package/dist/esm/runCli.js
CHANGED
|
@@ -16,7 +16,7 @@ import { applyDevBinToSteps, buildRootRegistry, buildWorkspaceRegistry, expandSc
|
|
|
16
16
|
import { resolveChannel, runSteps } from "./runner.js";
|
|
17
17
|
import { composeNmrStep, findNmrCrossing, renderChain } from "./steps.js";
|
|
18
18
|
import { UserError } from "./UserError.js";
|
|
19
|
-
import { COMMAND_VERBOSITY_ENV_VAR, readVerbosityEnv, resolveVerbosity } from "./verbosity.js";
|
|
19
|
+
import { COMMAND_VERBOSITY_ENV_VAR, readVerbosityEnv, resolveVerbosity, } from "./verbosity.js";
|
|
20
20
|
import { writeVerdict } from "./verdict.js";
|
|
21
21
|
const VERSION = readPackageVersion(import.meta.url);
|
|
22
22
|
const CROSSING_CONSEQUENCE = "so nmr handles the nested run's output as a tool's.";
|
package/dist/esm/runner.d.ts
CHANGED
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import type { Writable } from 'node:stream';
|
|
2
2
|
import type { Step } from './steps.js';
|
|
3
|
+
/** Where one of a child's output streams goes: a descriptor the child writes to, or a pipe nmr reads. */
|
|
3
4
|
export type OutputChannel = number | 'pipe';
|
|
5
|
+
/** The channel each of a child's output streams runs on. */
|
|
4
6
|
export interface OutputChannels {
|
|
5
7
|
stderr: OutputChannel;
|
|
6
8
|
stdout: OutputChannel;
|
|
7
9
|
}
|
|
8
10
|
export interface RunCommandOptions {
|
|
11
|
+
/** The channel each of the child's output streams runs on. */
|
|
9
12
|
channels: OutputChannels;
|
|
13
|
+
/** When true, suppress output on success and write captured output to stderr on failure. */
|
|
10
14
|
quiet?: boolean;
|
|
15
|
+
/** Stream that subprocess stdout flows to in non-quiet mode. Defaults to `process.stdout`. */
|
|
11
16
|
stdout?: Writable;
|
|
17
|
+
/** Stream that subprocess stderr flows to (and that quiet-mode failure output is written to). Defaults to `process.stderr`. */
|
|
12
18
|
stderr?: Writable;
|
|
19
|
+
/** Environment for the subprocess. Defaults to `process.env`. */
|
|
13
20
|
env?: NodeJS.ProcessEnv;
|
|
14
21
|
}
|
|
22
|
+
/** What a step list needs to run. Each step's channels follow its kind, so the caller chooses none of them. */
|
|
15
23
|
export type RunStepsOptions = Omit<RunCommandOptions, 'channels'>;
|
|
24
|
+
/** A bounded copy of what a step list's own commands wrote, each stream kept apart from the other. */
|
|
16
25
|
export interface RetainedOutput {
|
|
17
26
|
stderr: Buffer;
|
|
18
27
|
stdout: Buffer;
|
|
19
28
|
}
|
|
20
29
|
export interface RunStepsResult {
|
|
21
30
|
exitCode: number;
|
|
31
|
+
/**
|
|
32
|
+
* What the list's opaque steps produced, absent unless every one of them was captured whole and there was
|
|
33
|
+
* at least one to capture.
|
|
34
|
+
*/
|
|
22
35
|
retained?: RetainedOutput;
|
|
23
36
|
}
|
|
37
|
+
/** How a command ended, and the exit code that carries that ending to nmr's own caller. */
|
|
24
38
|
type CommandCompletion = {
|
|
25
39
|
outcome: 'exited';
|
|
26
40
|
exitCode: number;
|
|
@@ -34,11 +48,49 @@ type CommandCompletion = {
|
|
|
34
48
|
error: Error;
|
|
35
49
|
};
|
|
36
50
|
export type RunCommandResult = CommandCompletion & {
|
|
51
|
+
/**
|
|
52
|
+
* Output retained while the command ran, elided in the middle when it overran the bound.
|
|
53
|
+
* `undefined` where the stream was handed to the child directly, or where capture stopped early
|
|
54
|
+
* and the retained copy would understate what the command produced.
|
|
55
|
+
*/
|
|
37
56
|
stdout: Buffer | undefined;
|
|
38
57
|
stderr: Buffer | undefined;
|
|
39
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Returns the channel a stream runs on: the stream's own descriptor when it is a terminal and output is not
|
|
61
|
+
* being withheld, so the child's terminal detection matches nmr's, and a pipe everywhere else.
|
|
62
|
+
*/
|
|
40
63
|
export declare function resolveChannel(stream: Writable, quiet: boolean): OutputChannel;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the channel a step running an nmr process below this one runs on: nmr's own descriptor whenever it
|
|
66
|
+
* has one, so the child writes where nmr writes and no ancestor stands between them relaying bytes. A stream
|
|
67
|
+
* carrying no descriptor, which is the one a test injects, falls back to a pipe.
|
|
68
|
+
*/
|
|
41
69
|
export declare function resolveInheritedChannel(stream: Writable): OutputChannel;
|
|
70
|
+
/**
|
|
71
|
+
* Runs a step list in order and resolves once one fails or all have run, carrying the `&&` semantics nmr
|
|
72
|
+
* promises: the first non-zero exit ends the sequence and is the code returned.
|
|
73
|
+
*
|
|
74
|
+
* Sequencing here rather than in a spawned shell is what lets each step run on the channels its kind calls
|
|
75
|
+
* for, and what makes a signal to nmr end the run: the steps after it are never reached, where a shell would
|
|
76
|
+
* have gone on running them unsupervised.
|
|
77
|
+
*
|
|
78
|
+
* Carries back a bounded copy of what the list's own commands wrote, so a caller can retain it. Only opaque
|
|
79
|
+
* steps contribute: a structural step is another nmr process reporting for the subtree beneath it, and its
|
|
80
|
+
* output is that subtree's to account for.
|
|
81
|
+
*/
|
|
42
82
|
export declare function runSteps(steps: readonly Step[], cwd: string | undefined, options: RunStepsOptions): Promise<RunStepsResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Runs a command through a shell and resolves once it has ended.
|
|
85
|
+
*
|
|
86
|
+
* The caller chooses each stream's channel. A descriptor is handed to the child and nmr sees none of what
|
|
87
|
+
* flows through it; a pipe is forwarded to the matching option stream as it arrives, with that destination's
|
|
88
|
+
* back-pressure throttling the child, and a bounded copy is retained. Quiet mode withholds the forwarding,
|
|
89
|
+
* discarding the retained copy on success and writing it to `options.stderr` on failure, so it has nothing to
|
|
90
|
+
* report unless the caller chose a pipe on both streams.
|
|
91
|
+
*
|
|
92
|
+
* Piped stdout and stderr are ordered by arrival rather than by a shared descriptor, so their interleaving
|
|
93
|
+
* is approximate.
|
|
94
|
+
*/
|
|
43
95
|
export declare function runCommand(command: string, cwd: string | undefined, options: RunCommandOptions): Promise<RunCommandResult>;
|
|
44
96
|
export {};
|
package/dist/esm/scripts.d.ts
CHANGED