@williamthorsen/nmr 0.33.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 +121 -25
- package/.readyup/manifest.json +11 -8
- package/README.md +155 -18
- 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/commands/taze.js +17 -1
- 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-git-isolation.d.ts +1 -0
- package/dist/esm/vitest-git-isolation.js +4 -0
- package/dist/esm/vitest.d.ts +74 -2
- package/dist/esm/vitest.js +33 -2
- package/dist/esm/workspace.d.ts +18 -0
- package/package.json +21 -11
|
@@ -1,19 +1,83 @@
|
|
|
1
1
|
export interface BuildOptions {
|
|
2
2
|
entryGlobs?: string[];
|
|
3
|
+
/** Adds to the effective ignore set, whether that set is the default or an `ignorePatterns` override. */
|
|
3
4
|
extraIgnorePatterns?: string[];
|
|
5
|
+
/** Replaces the default ignore set. */
|
|
4
6
|
ignorePatterns?: string[];
|
|
5
7
|
outdir?: string;
|
|
6
8
|
}
|
|
9
|
+
/** The pair of directories a build publishes through, both siblings of the emit directory. */
|
|
7
10
|
export interface ScratchDirs {
|
|
8
11
|
previous: string;
|
|
9
12
|
staging: string;
|
|
10
13
|
}
|
|
11
14
|
export declare const DEFAULT_ENTRY_GLOBS: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Directories holding test scaffolding rather than shipped code, excluded from entry-point selection so a
|
|
17
|
+
* package does not publish its own helpers. Deliberately not the vitest factory's `COVERAGE_EXCLUDE`: helpers
|
|
18
|
+
* live in `test-utils/` precisely so they stay inside the coverage include set, so the two lists overlap
|
|
19
|
+
* without converging and neither can be derived from the other.
|
|
20
|
+
*
|
|
21
|
+
* Ignoring a file removes it as an entry point, not from the emit. The compiler still emits whatever the
|
|
22
|
+
* surviving entry points import, which is what keeps a production module that uses a helper from emitting a
|
|
23
|
+
* dangling specifier. Widening this list can therefore only drop files nothing in production reaches.
|
|
24
|
+
*/
|
|
12
25
|
export declare const DEFAULT_IGNORE_PATTERNS: string[];
|
|
13
26
|
export declare const DEFAULT_OUTDIR = "dist/esm/";
|
|
27
|
+
/**
|
|
28
|
+
* Reports whether the output a build of `packageDir` would produce is currently on disk. Applies the rule the
|
|
29
|
+
* build applies, on the same options the build was given, so a caller probing for output and the build deciding
|
|
30
|
+
* whether to rebuild cannot disagree: a package whose entry points emit nothing expects no output, and reports
|
|
31
|
+
* present. Passing options the build was not given is what would make the two disagree.
|
|
32
|
+
*/
|
|
14
33
|
export declare function hasBuildOutput(packageDir: string, options?: BuildOptions): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Reports whether the output a previous build would have produced is still on disk. Entry points that
|
|
36
|
+
* emit nothing expect no output, so their absent outdir is not deleted output: a `src` tree holding only
|
|
37
|
+
* declaration files, or none at all, would otherwise be reported as missing output and recompiled forever.
|
|
38
|
+
* The emit is what makes an outdir, so what counts is whether any entry point emits, not how many there are.
|
|
39
|
+
*/
|
|
15
40
|
export declare function hasExpectedBuildOutput(packageDir: string, outdir: string, entryPoints: string[]): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the digest of the inputs the output currently on disk was built from, or `undefined` when the package
|
|
43
|
+
* has never been built. Two packages holding the same sources report the same digest, and a package whose output
|
|
44
|
+
* came from a different tree reports a different one, which is what tells a stale `dist` from a current one.
|
|
45
|
+
*/
|
|
16
46
|
export declare function readBuildDigest(packageDir: string): Promise<string | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the absolute path of a package's build-cache file, one entry in the shared store. The package
|
|
49
|
+
* directory is the entry's scope, so the store keys the file to it and packages sharing a hoisted
|
|
50
|
+
* `node_modules` never collide.
|
|
51
|
+
*
|
|
52
|
+
* Three things hold the path where every previously written entry already sits: the `.hash` extension, the
|
|
53
|
+
* package's own directory name as the slug, and the absence of `discriminators`, which would otherwise fold
|
|
54
|
+
* into the digest. Changing any of them strands every entry on disk.
|
|
55
|
+
*/
|
|
17
56
|
export declare function resolveBuildCachePath(packageDir: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Resolves the two scratch directories a build publishes through: `staging`, which the emit is written to, and
|
|
59
|
+
* `previous`, which the outgoing output is renamed aside to. Both are siblings of the emit directory, so a
|
|
60
|
+
* rename between them never crosses a filesystem, and both are dot-prefixed so a leftover stays out of the
|
|
61
|
+
* globs that select sources.
|
|
62
|
+
*
|
|
63
|
+
* The names are fixed rather than unique because the build removes both before use. That removal is what a
|
|
64
|
+
* unique name would need a sweep to accomplish, and a sweep cannot tell a directory orphaned by a killed run
|
|
65
|
+
* from one a concurrent build is still writing. A directory left behind by a failed build is cleared the same
|
|
66
|
+
* way, so the failure path needs no cleanup of its own.
|
|
67
|
+
*/
|
|
18
68
|
export declare function resolveScratchDirs(emitDir: string): ScratchDirs;
|
|
69
|
+
/**
|
|
70
|
+
* Resolves the fingerprint of the nmr compiling `packageDir`, which joins the build digest beside the compiler
|
|
71
|
+
* version: the same sources emit differently across nmr versions as they do across TypeScript versions. It is
|
|
72
|
+
* nmr's own build digest where one is on disk, which is what moves on a dev-loop edit the version does not
|
|
73
|
+
* follow, and nmr's package version otherwise -- the case in a consuming repo, whose installed copy was built
|
|
74
|
+
* elsewhere.
|
|
75
|
+
*
|
|
76
|
+
* A build of nmr itself takes the version too. Its digest is the entry that build is about to overwrite, so
|
|
77
|
+
* folding it would make the key a function of its own previous value, which never settles: nmr would rebuild on
|
|
78
|
+
* every invocation and move the fingerprint every other package reads.
|
|
79
|
+
*
|
|
80
|
+
* What the fingerprint names is the nmr that produced the output, not the sources sitting in `src`, so a package
|
|
81
|
+
* the pre-rebuild binary compiled keeps the old fingerprint and rebuilds on the run after.
|
|
82
|
+
*/
|
|
19
83
|
export declare function resolveToolchainFingerprint(packageDir: string, selfDir?: string): Promise<string>;
|
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BuildOptions } from './build-output.js';
|
|
2
|
+
/**
|
|
3
|
+
* The toolchain a build's emit comes from: the resolved compiler and the nmr running it. Both join the build
|
|
4
|
+
* hash, because the same sources can emit differently across either.
|
|
5
|
+
*/
|
|
2
6
|
export interface BuildToolchain {
|
|
3
7
|
compilerVersion: string;
|
|
4
8
|
fingerprint: string;
|
|
5
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Compiles a package's `src` tree to `dist/esm` with the TypeScript compiler API, emitting `.js` and
|
|
12
|
+
* `.d.ts` from two programs and rewriting relative `.ts` specifiers and tsconfig `paths` aliases to
|
|
13
|
+
* runnable relative `.js` specifiers in both outputs. Skips the build only when no input has changed
|
|
14
|
+
* and the previous output is still on disk.
|
|
15
|
+
*
|
|
16
|
+
* The build owns its output directory: every emit replaces it wholesale, so `dist` is a function of the
|
|
17
|
+
* current inputs rather than an accumulation of every build that ever ran. Assets belong outside it, or in a
|
|
18
|
+
* `build:post` hook, which runs after the output is published.
|
|
19
|
+
*/
|
|
6
20
|
export declare function buildPackage(packageDir: string, options?: BuildOptions): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Produces a digest of the given files (paths and contents), the emit config, and the toolchain.
|
|
23
|
+
* The file list is sorted so the digest is order-invariant, and each path is folded in so renames are detected.
|
|
24
|
+
* The toolchain joins it because the same sources emit differently across TypeScript versions, and across the
|
|
25
|
+
* nmr versions whose emit logic drives them.
|
|
26
|
+
*/
|
|
7
27
|
export declare function computeBuildHash(packageDir: string, files: string[], emitConfig: object, toolchain: BuildToolchain): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Resolves a package's full tsconfig `extends` chain, returning every config file in it (the leaf `tsconfig.json` and
|
|
30
|
+
* each base it transitively extends, up to the repo root) as paths relative to `packageDir`.
|
|
31
|
+
* Emit is driven by the fully-resolved compiler options, so the base configs (where `target`, `module`, `paths`,
|
|
32
|
+
* `lib`, and `strict` are actually defined) must be in the cache's hashed input set; otherwise a change to a base
|
|
33
|
+
* config would not bust the cache and stale output could ship. Paths are returned relative to `packageDir`, so
|
|
34
|
+
* `computeBuildHash` reads them and folds a stable, location-independent path string into the digest.
|
|
35
|
+
*/
|
|
8
36
|
export declare function resolveTsconfigChain(packageDir: string, configFileName?: string): string[];
|
|
@@ -85,14 +85,15 @@ async function emitPackage(packageDir, entryPoints, outdir) {
|
|
|
85
85
|
const emitDir = resolveEmitDir(packageDir, outdir);
|
|
86
86
|
const scratchDirs = resolveScratchDirs(emitDir);
|
|
87
87
|
await removeScratchDirs(scratchDirs);
|
|
88
|
-
const program = ts.createProgram(rootNames, compilerOptions);
|
|
89
88
|
const emitted = new Map();
|
|
90
|
-
|
|
89
|
+
function collect(fileName, text, writeByteOrderMark) {
|
|
91
90
|
emitted.set(fileName, { text, writeByteOrderMark });
|
|
92
|
-
});
|
|
93
|
-
if (emitResult.emitSkipped) {
|
|
94
|
-
throw new Error(`nmr-compile: emit failed.\n${formatDiagnostics(emitResult.diagnostics)}`);
|
|
95
91
|
}
|
|
92
|
+
const host = createCachingCompilerHost(compilerOptions);
|
|
93
|
+
const scriptProgram = ts.createProgram(rootNames, { ...compilerOptions, declaration: false }, host);
|
|
94
|
+
assertEmitSucceeded(scriptProgram.emit(undefined, collect));
|
|
95
|
+
const declarationProgram = ts.createProgram(rootNames, { ...compilerOptions, emitDeclarationOnly: true, removeComments: false }, host, scriptProgram);
|
|
96
|
+
assertEmitSucceeded(declarationProgram.emit(undefined, collect));
|
|
96
97
|
const staged = new Map();
|
|
97
98
|
for (const [fileName, file] of emitted) {
|
|
98
99
|
staged.set(fileName, { ...file, text: rewriteSpecifiers(fileName, file.text, compilerOptions, sourceRoot) });
|
|
@@ -105,6 +106,25 @@ async function emitPackage(packageDir, entryPoints, outdir) {
|
|
|
105
106
|
await swapIntoPlace(emitDir, scratchDirs);
|
|
106
107
|
return staged.size;
|
|
107
108
|
}
|
|
109
|
+
function assertEmitSucceeded(result) {
|
|
110
|
+
if (result.emitSkipped) {
|
|
111
|
+
throw new Error(`nmr-compile: emit failed.\n${formatDiagnostics(result.diagnostics)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function createCachingCompilerHost(compilerOptions) {
|
|
115
|
+
const host = ts.createCompilerHost(compilerOptions);
|
|
116
|
+
const parsed = new Map();
|
|
117
|
+
const readSourceFile = host.getSourceFile.bind(host);
|
|
118
|
+
host.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
|
|
119
|
+
if (parsed.has(fileName)) {
|
|
120
|
+
return parsed.get(fileName);
|
|
121
|
+
}
|
|
122
|
+
const sourceFile = readSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
|
|
123
|
+
parsed.set(fileName, sourceFile);
|
|
124
|
+
return sourceFile;
|
|
125
|
+
};
|
|
126
|
+
return host;
|
|
127
|
+
}
|
|
108
128
|
async function discardScratchDirs(scratchDirs) {
|
|
109
129
|
try {
|
|
110
130
|
await removeScratchDirs(scratchDirs);
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes a package's build output and the build-cache entry that describes it, so no state survives to
|
|
3
|
+
* make the next build skip. Removal is idempotent: an already-clean package is a silent no-op.
|
|
4
|
+
*/
|
|
1
5
|
export declare function cleanPackage(packageDir: string): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Cleans the package containing `cwd`, or every workspace package when run from the monorepo root.
|
|
8
|
+
*
|
|
9
|
+
* From within a package this is the built-in clean itself: `nmr` has already resolved `clean` to this bin
|
|
10
|
+
* before invoking it, so resolving again would apply the package's own override twice.
|
|
11
|
+
*
|
|
12
|
+
* This is the default `clean` script, shipped as a bin rather than delegating to `rimraf`. Under pnpm's
|
|
13
|
+
* isolated layout, `pnpm exec` resolves only bins of the consuming project's own direct dependencies, so
|
|
14
|
+
* a `rimraf` in nmr's dependency tree would be unreachable — while nmr's own bins are linked into the
|
|
15
|
+
* consumer's `node_modules/.bin`, nmr being a direct dependency.
|
|
16
|
+
*/
|
|
2
17
|
export declare function runClean(cwd?: string): Promise<void>;
|
|
@@ -10,9 +10,20 @@ export interface EnsurePrepublishHooksResult {
|
|
|
10
10
|
hasFailures: boolean;
|
|
11
11
|
}
|
|
12
12
|
export declare const DEFAULT_HOOK = "npm run build";
|
|
13
|
+
/**
|
|
14
|
+
* Check (and optionally fix) whether all publishable workspace packages
|
|
15
|
+
* have a `prepublishOnly` script.
|
|
16
|
+
*/
|
|
13
17
|
export declare function ensurePrepublishHooks(monorepoRoot: string, options: {
|
|
14
18
|
fix: boolean;
|
|
15
19
|
dryRun: boolean;
|
|
16
20
|
command?: string;
|
|
17
21
|
}): EnsurePrepublishHooksResult;
|
|
22
|
+
/**
|
|
23
|
+
* Reports one line per publishable package and closes with what the run came to. Private packages appear in
|
|
24
|
+
* neither: they publish nothing, so a `prepublishOnly` is not theirs to carry.
|
|
25
|
+
*
|
|
26
|
+
* Every line goes to stdout, the `✗` included, and the exit code is what carries a failure. A report split
|
|
27
|
+
* across two streams leaves no reader holding the whole list.
|
|
28
|
+
*/
|
|
18
29
|
export declare function reportPrepublishHooks(result: EnsurePrepublishHooksResult, hookCommand: string): void;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type FormatMode = 'check' | 'write';
|
|
2
2
|
export interface FormatTargets {
|
|
3
|
+
/** Paths relative to the working directory, as `git ls-files` emits them. */
|
|
3
4
|
files: string[];
|
|
5
|
+
/** Absolute paths to every `.prettierignore` governing the repository, root-most first. */
|
|
4
6
|
ignorePaths: string[];
|
|
5
7
|
}
|
|
6
8
|
export type ResolveTargetsResult = {
|
|
@@ -10,14 +12,44 @@ export type ResolveTargetsResult = {
|
|
|
10
12
|
ok: false;
|
|
11
13
|
error: string;
|
|
12
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Formats or checks the files git reports for `cwd`, and returns the exit code to report.
|
|
17
|
+
*
|
|
18
|
+
* Trailing arguments are git pathspecs, not Prettier flags; an unrecognized option is rejected rather
|
|
19
|
+
* than passed along, since git would read it as a pathspec matching nothing and the run would report
|
|
20
|
+
* success over an empty selection.
|
|
21
|
+
*/
|
|
13
22
|
export declare function runFmt(argv: string[], cwd?: string): number;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves what Prettier should format and which ignore files govern it, using git rather than Prettier's
|
|
25
|
+
* own discovery. Prettier reads `.gitignore` and `.prettierignore` from the working directory only, so a
|
|
26
|
+
* pattern in `packages/<pkg>/.gitignore` is invisible to a root-level run; git knows the whole hierarchy,
|
|
27
|
+
* along with `.git/info/exclude` and `core.excludesFile`, which Prettier cannot read under any flag.
|
|
28
|
+
*
|
|
29
|
+
* File selection is anchored at `cwd` and ignore discovery at the repository root. That split is the point:
|
|
30
|
+
* scoping still follows where the caller stands, while the rules applied to a given file no longer do.
|
|
31
|
+
*
|
|
32
|
+
* `pathspecs` narrow the selection and are passed to git verbatim, so they carry git pathspec semantics
|
|
33
|
+
* rather than shell glob semantics.
|
|
34
|
+
*/
|
|
14
35
|
export declare function resolveFormatTargets(cwd: string, pathspecs?: string[]): ResolveTargetsResult;
|
|
36
|
+
/** @internal */
|
|
15
37
|
export interface RunPrettierOptions {
|
|
16
38
|
cliPath: string;
|
|
17
39
|
mode: FormatMode;
|
|
18
40
|
files: string[];
|
|
19
41
|
ignorePaths: string[];
|
|
20
42
|
cwd: string;
|
|
43
|
+
/** Overridable so the multi-batch path is reachable without a fixture that hits the real ceiling. */
|
|
21
44
|
budgetBytes?: number;
|
|
22
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Runs Prettier over the selection, returning the first non-zero exit code. Every batch runs even after
|
|
48
|
+
* one fails, so a check reports every offending file rather than only those in the first batch.
|
|
49
|
+
*
|
|
50
|
+
* The CLI runs under this process's own Node rather than through its shebang, so it does not depend on
|
|
51
|
+
* the file's execute bit or on PATH holding a `node`.
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
23
55
|
export declare function runPrettier(options: RunPrettierOptions): number;
|
|
@@ -1 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports the catalogued dependencies a package-scoped upgrade pass cannot see.
|
|
3
|
+
*
|
|
4
|
+
* The upgrade tool reads `pnpm-workspace.yaml` only when it sits at the working directory, so a pass run
|
|
5
|
+
* inside a package drops every dependency a catalog declares -- and a package whose dependencies are all
|
|
6
|
+
* catalogued reports itself up to date. Naming them, and the root a covering pass runs from, is what keeps
|
|
7
|
+
* that from reading as a clean bill of health.
|
|
8
|
+
*
|
|
9
|
+
* Runs ahead of the report produced by the workspace `upgrade` script.
|
|
10
|
+
*/
|
|
1
11
|
export declare function reportCatalog(cwd: string): void;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports the pnpm dependency overrides declared in the monorepo root's `pnpm-workspace.yaml`, and rejects a
|
|
3
|
+
* `pnpm.overrides` block left behind in the root `package.json`.
|
|
4
|
+
*
|
|
5
|
+
* Runs ahead of the report produced by the root `upgrade` script.
|
|
6
|
+
*/
|
|
1
7
|
export declare function reportOverrides(monorepoRoot: string): void;
|
|
@@ -4,9 +4,27 @@ export interface SpawnOutcome {
|
|
|
4
4
|
error?: Error | undefined;
|
|
5
5
|
}
|
|
6
6
|
export interface RunTazeOptions {
|
|
7
|
+
/** Resolves the absolute path of taze's CLI entry. Injected by tests. */
|
|
7
8
|
resolveCliPath?: () => string;
|
|
9
|
+
/** Runs the CLI and reports how it exited. Injected by tests. */
|
|
8
10
|
spawn?: (nodePath: string, argv: string[]) => SpawnOutcome;
|
|
11
|
+
/** Stream that error output is written to. Defaults to `process.stderr`. */
|
|
9
12
|
stderr?: Writable;
|
|
10
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Runs taze from nmr's own dependency tree, forwarding `args`, and returns its exit code.
|
|
16
|
+
*
|
|
17
|
+
* Consumers depend on nmr, not on taze, so taze is transitive and its bin is absent from the consumer's
|
|
18
|
+
* root `node_modules/.bin`. This launcher is what bridges that gap: pnpm links nmr's own bins into the
|
|
19
|
+
* consumer root, and nmr resolves taze from the tree it does control.
|
|
20
|
+
*
|
|
21
|
+
* A request timeout is the one argument added, and only where `args` carries none. Neither other site can hold
|
|
22
|
+
* it: an invocation's trailing arguments are appended to the resolved command string, so the same flag in the
|
|
23
|
+
* `upgrade` script would be doubled by `nmr upgrade --request-timeout ...`, and taze's parser collects the pair
|
|
24
|
+
* into an array it reads as a near-zero deadline; a `taze.config.ts` setting lands in the object taze's own CLI
|
|
25
|
+
* defaults overwrite. Every other argument is forwarded untouched, so invocation policy (`--recursive`) stays in
|
|
26
|
+
* the script registry, visible in `nmr` help output and overridable per repo, and upgrade policy in `taze.ts`.
|
|
27
|
+
*/
|
|
11
28
|
export declare function runTaze(args: string[], options?: RunTazeOptions): number;
|
|
29
|
+
/** Resolves the absolute path of taze's CLI entry from nmr's own dependency tree. */
|
|
12
30
|
export declare function resolveTazeCliPath(): string;
|
|
@@ -4,6 +4,10 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
import { reportError } from '@williamthorsen/nmr-core';
|
|
5
5
|
import { describeError } from '@williamthorsen/toolbelt.errors';
|
|
6
6
|
const TAZE_CLI_SPECIFIER = 'taze/cli';
|
|
7
|
+
const REQUEST_TIMEOUT_FLAG = '--request-timeout';
|
|
8
|
+
const REQUEST_TIMEOUT_FLAGS = [REQUEST_TIMEOUT_FLAG, '--requestTimeout'];
|
|
9
|
+
const REQUEST_TIMEOUT_MS = 30_000;
|
|
10
|
+
const ARGUMENT_TERMINATOR = '--';
|
|
7
11
|
export function runTaze(args, options = {}) {
|
|
8
12
|
const stderr = options.stderr ?? process.stderr;
|
|
9
13
|
const resolveCliPath = options.resolveCliPath ?? resolveTazeCliPath;
|
|
@@ -17,7 +21,7 @@ export function runTaze(args, options = {}) {
|
|
|
17
21
|
reportError(`Could not resolve '${TAZE_CLI_SPECIFIER}' from nmr's dependencies. Reinstall the workspace to restore it. (${detail})`, stderr);
|
|
18
22
|
return 1;
|
|
19
23
|
}
|
|
20
|
-
const outcome = spawn(process.execPath, [cliPath, ...args]);
|
|
24
|
+
const outcome = spawn(process.execPath, [cliPath, ...composeRequestTimeoutArgs(args), ...args]);
|
|
21
25
|
if (outcome.error) {
|
|
22
26
|
reportError(`Failed to run taze: ${outcome.error.message}`, stderr);
|
|
23
27
|
return 1;
|
|
@@ -27,6 +31,18 @@ export function runTaze(args, options = {}) {
|
|
|
27
31
|
export function resolveTazeCliPath() {
|
|
28
32
|
return fileURLToPath(import.meta.resolve(TAZE_CLI_SPECIFIER));
|
|
29
33
|
}
|
|
34
|
+
function carriesRequestTimeout(args) {
|
|
35
|
+
for (const arg of args) {
|
|
36
|
+
if (arg === ARGUMENT_TERMINATOR)
|
|
37
|
+
return false;
|
|
38
|
+
if (REQUEST_TIMEOUT_FLAGS.some((flag) => arg === flag || arg.startsWith(`${flag}=`)))
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function composeRequestTimeoutArgs(args) {
|
|
44
|
+
return carriesRequestTimeout(args) ? [] : [REQUEST_TIMEOUT_FLAG, String(REQUEST_TIMEOUT_MS)];
|
|
45
|
+
}
|
|
30
46
|
function spawnNode(nodePath, argv) {
|
|
31
47
|
const result = spawnSync(nodePath, argv, { stdio: 'inherit' });
|
|
32
48
|
return { status: result.status, error: result.error };
|
package/dist/esm/config.d.ts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import type { NmrConfig } from './types.js';
|
|
2
|
+
/** The config's path relative to the directory holding it, for a message composed without one in hand. */
|
|
2
3
|
export declare const CONFIG_RELATIVE_PATH: string;
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the config-file path for a directory, whether that is the monorepo root or a package.
|
|
6
|
+
* Callers that only need to know whether a config exists -- the build, which folds it into its cache digest -- go
|
|
7
|
+
* through this rather than spelling the path again, so that the two cannot drift into hashing a file nothing reads.
|
|
8
|
+
*/
|
|
3
9
|
export declare function resolveConfigPath(baseDir: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Loads the nmr configuration from `.config/nmr.config.ts` under `baseDir`, which is the monorepo root for
|
|
12
|
+
* the repo-wide config and a package directory for the workspace tier. Returns an empty config if the file
|
|
13
|
+
* doesn't exist.
|
|
14
|
+
*/
|
|
4
15
|
export declare function loadConfig(baseDir: string): Promise<NmrConfig>;
|
|
16
|
+
/**
|
|
17
|
+
* Loads the monorepo-root `.config/nmr.config.ts`, the tier that feeds script resolution and `devBin`.
|
|
18
|
+
* Returns an empty config if the file doesn't exist.
|
|
19
|
+
*
|
|
20
|
+
* Throws on a recognized key this tier does not honor. `build` governs one package's compile, which reads the
|
|
21
|
+
* package's own config alone, so a `build` accepted here would apply its patterns nowhere.
|
|
22
|
+
*/
|
|
5
23
|
export declare function loadRootConfig(monorepoRoot: string): Promise<NmrConfig>;
|
|
24
|
+
/**
|
|
25
|
+
* Loads a single package's `.config/nmr.config.ts`, the tier `nmr-compile` reads from its working directory.
|
|
26
|
+
* Returns an empty config if the file doesn't exist.
|
|
27
|
+
*
|
|
28
|
+
* Throws on a recognized key this tier does not honor. Dropping one would leave a package building on
|
|
29
|
+
* settings its own config file appears to change, which nothing in the build's output would reveal.
|
|
30
|
+
*/
|
|
6
31
|
export declare function loadWorkspaceConfig(packageDir: string): Promise<NmrConfig>;
|
package/dist/esm/context.d.ts
CHANGED
|
@@ -5,5 +5,16 @@ export interface ResolvedContext {
|
|
|
5
5
|
packageDir?: string;
|
|
6
6
|
config: NmrConfig;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Determines whether a directory is inside a workspace package.
|
|
10
|
+
* Returns the package directory if so, or `undefined` if in root context.
|
|
11
|
+
*
|
|
12
|
+
* A workspace may nest one package inside another, so the deepest containing directory wins — matching
|
|
13
|
+
* pnpm, which resolves a cwd to the package that encloses it most nearly.
|
|
14
|
+
*/
|
|
8
15
|
export declare function findContainingPackageDir(dir: string, workspacePackageDirs: string[]): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the full execution context: monorepo root, whether we're in a
|
|
18
|
+
* workspace package or root context, and the loaded configuration.
|
|
19
|
+
*/
|
|
9
20
|
export declare function resolveContext(cwd?: string): Promise<ResolvedContext>;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One element of a composite, paired with what it does with the invocation's trailing arguments. The bare
|
|
3
|
+
* string form of an element is this spec with `declinesArgs` left at its default.
|
|
4
|
+
*/
|
|
1
5
|
export interface StepSpec {
|
|
6
|
+
/** A command name, optionally preceded by nmr's own flags, as it would be typed after `nmr`. */
|
|
2
7
|
run: string;
|
|
8
|
+
/**
|
|
9
|
+
* Set where the trailing arguments cannot narrow this step's work: it is a prerequisite the narrowed steps
|
|
10
|
+
* run against, or the tool it reaches would be misled by them. A declining step runs unnarrowed.
|
|
11
|
+
*/
|
|
3
12
|
declinesArgs?: boolean;
|
|
4
13
|
}
|
|
5
14
|
export type ScriptValue = string | ReadonlyArray<string | StepSpec>;
|
|
6
15
|
export type ScriptRegistry = Record<string, ScriptValue>;
|
|
16
|
+
/**
|
|
17
|
+
* Workspace scripts, identical for every package.
|
|
18
|
+
* Four Vitest projects are recognized: `tool`, `localhost`, `remote`, and `unit`. The latter is also a catch-all.
|
|
19
|
+
* Name a test file with the matching infix to associate it with a project.
|
|
20
|
+
* Example: `nmr test:tool` runs every file carrying the `tool` infix, such as `my-file.tool.test.ts`.
|
|
21
|
+
*/
|
|
7
22
|
export declare const workspaceScripts: ScriptRegistry;
|
|
8
23
|
export declare const rootScripts: ScriptRegistry;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import type { NmrConfig } from './types.js';
|
|
2
2
|
export type { BuildConfig, CheckCacheConfig, CommandVerbosity, NmrConfig, OutputConfig, ScriptValue, StepSpec, } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Type-safe identity function for configuration files.
|
|
5
|
+
*
|
|
6
|
+
* Usage in `.config/nmr.config.ts`:
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { defineConfig } from '@williamthorsen/nmr/config';
|
|
9
|
+
* export default defineConfig({ ... });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
3
12
|
export declare function defineConfig(config: NmrConfig): NmrConfig;
|
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;
|