buildrush 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +82 -3
- package/SECURITY.md +54 -0
- package/bin/buildrush.js +6 -0
- package/dist/src/adapters.d.ts +23 -0
- package/dist/src/adapters.js +171 -0
- package/dist/src/adapters.js.map +1 -0
- package/dist/src/affected.d.ts +28 -0
- package/dist/src/affected.js +59 -0
- package/dist/src/affected.js.map +1 -0
- package/dist/src/cache.d.ts +94 -0
- package/dist/src/cache.js +362 -0
- package/dist/src/cache.js.map +1 -0
- package/dist/src/cli.d.ts +31 -0
- package/dist/src/cli.js +646 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config.d.ts +82 -0
- package/dist/src/config.js +384 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/detect.d.ts +12 -0
- package/dist/src/detect.js +68 -0
- package/dist/src/detect.js.map +1 -0
- package/dist/src/doctor.d.ts +6 -0
- package/dist/src/doctor.js +95 -0
- package/dist/src/doctor.js.map +1 -0
- package/dist/src/engine.d.ts +68 -0
- package/dist/src/engine.js +652 -0
- package/dist/src/engine.js.map +1 -0
- package/dist/src/fsindex.d.ts +37 -0
- package/dist/src/fsindex.js +128 -0
- package/dist/src/fsindex.js.map +1 -0
- package/dist/src/fswatch.d.ts +30 -0
- package/dist/src/fswatch.js +141 -0
- package/dist/src/fswatch.js.map +1 -0
- package/dist/src/graph.d.ts +77 -0
- package/dist/src/graph.js +486 -0
- package/dist/src/graph.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/project.d.ts +28 -0
- package/dist/src/project.js +113 -0
- package/dist/src/project.js.map +1 -0
- package/dist/src/runner.d.ts +36 -0
- package/dist/src/runner.js +174 -0
- package/dist/src/runner.js.map +1 -0
- package/dist/src/scheduler.d.ts +30 -0
- package/dist/src/scheduler.js +143 -0
- package/dist/src/scheduler.js.map +1 -0
- package/dist/src/testcache.d.ts +60 -0
- package/dist/src/testcache.js +93 -0
- package/dist/src/testcache.js.map +1 -0
- package/dist/src/util/fsx.d.ts +11 -0
- package/dist/src/util/fsx.js +61 -0
- package/dist/src/util/fsx.js.map +1 -0
- package/dist/src/util/glob.d.ts +19 -0
- package/dist/src/util/glob.js +193 -0
- package/dist/src/util/glob.js.map +1 -0
- package/dist/src/util/hash.d.ts +14 -0
- package/dist/src/util/hash.js +57 -0
- package/dist/src/util/hash.js.map +1 -0
- package/dist/src/util/paths.d.ts +17 -0
- package/dist/src/util/paths.js +67 -0
- package/dist/src/util/paths.js.map +1 -0
- package/dist/src/watch.d.ts +101 -0
- package/dist/src/watch.js +289 -0
- package/dist/src/watch.js.map +1 -0
- package/dist/src/workspaces.d.ts +118 -0
- package/dist/src/workspaces.js +555 -0
- package/dist/src/workspaces.js.map +1 -0
- package/package.json +49 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BuildRush contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# BuildRush
|
|
2
|
+
|
|
3
|
+
**Local-first incremental build & test engine.** Change a small part of a
|
|
4
|
+
project and BuildRush runs only the work that is provably necessary, reuses
|
|
5
|
+
valid previous results, runs independent tasks in parallel, and tells you
|
|
6
|
+
exactly why anything ran.
|
|
7
|
+
|
|
8
|
+
> **Status: early (0.1).** The core engine is real and tested (60 tests,
|
|
9
|
+
> including adversarial cache/path/secret tests). Watch mode (`--watch`) is
|
|
10
|
+
> available; the daemon is **not built yet**; see
|
|
11
|
+
> [ROADMAP.md](ROADMAP.md). No benchmark claims are made until the benchmark
|
|
12
|
+
> suite exists.
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install --save-dev buildrush # once published; today: clone + `npm ci && npm run build`
|
|
18
|
+
npx buildrush init # detects vite/vitest/eslint/tsc and writes buildrush.json
|
|
19
|
+
npx buildrush run # runs the default pipeline with caching
|
|
20
|
+
npx buildrush run # again: everything is [cached]
|
|
21
|
+
npx buildrush test --affected # only tests that (transitively) import what you changed
|
|
22
|
+
npx buildrush test --watch # stay running; re-run only what each file change affects (also run/build/check)
|
|
23
|
+
npx buildrush run --watch --json # one JSON object per cycle (NDJSON) for editors and scripts
|
|
24
|
+
npx buildrush explain src/Button.tsx # tasks, modules and tests this file affects, with import chains
|
|
25
|
+
npx buildrush run build --affected # monorepos: only changed packages and their dependents
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
[ran] typecheck 1.88s why: input changed: src/util/glob.ts
|
|
30
|
+
[cached] build 91ms restored 368.6 KiB
|
|
31
|
+
[ran] test 3.91s why: dependency task "build" has a different fingerprint
|
|
32
|
+
BuildRush succeeded: 2 ran, 1 cached, 0 failed, 0 skipped in 6.0s
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Monorepos
|
|
36
|
+
|
|
37
|
+
npm/yarn/bun (`workspaces`) and pnpm (`pnpm-workspace.yaml`) workspaces are
|
|
38
|
+
detected. Define a task once with `"scope": "packages"` and it runs in every
|
|
39
|
+
package (`@acme/core:build`, ...), ordered by the package dependency graph with
|
|
40
|
+
`"dependsOn": ["^build"]`, each with its own fingerprint and cache entry; a change
|
|
41
|
+
in one package re-runs its dependents and nothing else. `analyze` and `graph
|
|
42
|
+
--packages` show the packages and their edges. See
|
|
43
|
+
[docs/configuration.md](docs/configuration.md#workspaces-monorepos).
|
|
44
|
+
|
|
45
|
+
## Why trust the cache
|
|
46
|
+
|
|
47
|
+
* Keys are SHA-256 over **file contents** (never mtimes), dependency fingerprints, declared env, toolchain and arguments.
|
|
48
|
+
* Failed, cancelled, timed-out runs and runs whose inputs changed *while running* are **never cached**.
|
|
49
|
+
* Restores verify every blob before writing, refuse traversal and symlinks, and drop setuid bits.
|
|
50
|
+
* If BuildRush cannot prove something is unaffected (global config, dynamic imports, no git) it runs more, and says why.
|
|
51
|
+
|
|
52
|
+
Details: [docs/cache-correctness.md](docs/cache-correctness.md) · [docs/security.md](docs/security.md).
|
|
53
|
+
|
|
54
|
+
## Measured results (and where BuildRush does *not* win)
|
|
55
|
+
|
|
56
|
+
Generated TypeScript apps, Vite 6 + Vitest 3 + tsc 5.9, 4-core shared sandbox, 5 runs each, median. Reproduce with `node bench/run.mjs` ([method](bench/README.md)). "Native parallel" is `tsc && vite build` running alongside `vitest run`; compare against that, not the sequential chain.
|
|
57
|
+
|
|
58
|
+
| Scenario (medium: 400 modules, 60 tests) | Native parallel | BuildRush |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| Cold full run | 10.5 s | 11.3 s (~8% slower) |
|
|
61
|
+
| **No change** | 10.9 s | **0.11 s (~100x faster)** |
|
|
62
|
+
| One-file edit, full pipeline | 10.5 s | 10.6 s (equal) |
|
|
63
|
+
| **Restore deleted `dist/`** | 0.95 s (rebuild) | **0.12 s** |
|
|
64
|
+
| Tests only after a narrow edit | `vitest related` 2.08 s | `test --affected` 2.87 s (**slower**), vs 9.45 s for all tests |
|
|
65
|
+
| Tests only after a wide edit | `vitest related` 9.62 s | 10.3 s (**slower**; all tests selected) |
|
|
66
|
+
|
|
67
|
+
The small workload (60 modules) shows the same shape: no-change 86 ms vs 2.0 s, cold 2.09 s vs 1.93 s.
|
|
68
|
+
|
|
69
|
+
What this says honestly: the cache pays off when nothing relevant changed (the common case between edits, branch switches and CI reruns). When real work must happen, BuildRush costs roughly 0-8% more than a well-written parallel script, and `--affected` currently carries ~0.8 s of overhead versus Vitest's own `related`. Reducing that overhead is the next optimisation target. Memory/CPU, Windows and real monorepos are **not measured**; there are no comparisons with Nx/Turborepo/Bazel.
|
|
70
|
+
|
|
71
|
+
## Docs
|
|
72
|
+
|
|
73
|
+
[Configuration & commands](docs/configuration.md) · [Adapters](docs/adapters.md) · [Benchmarks](bench/README.md) · [Architecture & prior art](docs/architecture.md) · [Security model](docs/security.md) · [Cache correctness](docs/cache-correctness.md) · [Roadmap](ROADMAP.md) · [Contributing](CONTRIBUTING.md) · [Governance](GOVERNANCE.md) · [Security policy](SECURITY.md)
|
|
74
|
+
|
|
75
|
+
## Requirements
|
|
76
|
+
|
|
77
|
+
Node.js ≥ 22 on Linux, macOS and Windows (CI runs all three). On Windows, npm `.cmd` shims are unwrapped and their Node target is run directly; arguments are never passed through `cmd.exe`. Zero runtime dependencies.
|
|
78
|
+
**Do not run BuildRush on repositories you do not trust**: the config runs commands as you.
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT. See [LICENSE](LICENSE).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
BuildRush executes commands defined by a project's configuration and manages a
|
|
4
|
+
cache that is later written back into the working tree. Both are security
|
|
5
|
+
sensitive, so we treat reports seriously. See [docs/security.md](docs/security.md)
|
|
6
|
+
for the trust model, the controls we implement, and the known limits.
|
|
7
|
+
|
|
8
|
+
## Reporting a vulnerability
|
|
9
|
+
|
|
10
|
+
**Do not open a public issue for a security problem.**
|
|
11
|
+
|
|
12
|
+
Use GitHub's private vulnerability reporting:
|
|
13
|
+
<https://github.com/DhruvHarani1/BuildRush/security/advisories/new>
|
|
14
|
+
|
|
15
|
+
Please include the BuildRush version (`buildrush --version`), Node version and
|
|
16
|
+
OS, a minimal reproduction (ideally a fixture project), and the impact you
|
|
17
|
+
believe it has.
|
|
18
|
+
|
|
19
|
+
Targets (best effort, maintained by volunteers):
|
|
20
|
+
|
|
21
|
+
| Step | Target |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| Acknowledge the report | 3 business days |
|
|
24
|
+
| Initial assessment and severity | 7 days |
|
|
25
|
+
| Fix or mitigation for High/Critical | 30 days |
|
|
26
|
+
| Public advisory + CVE (where applicable) | on release of the fix |
|
|
27
|
+
|
|
28
|
+
We credit reporters in the advisory unless you ask us not to. We will not
|
|
29
|
+
pursue good-faith research that follows this policy.
|
|
30
|
+
|
|
31
|
+
## Supported versions
|
|
32
|
+
|
|
33
|
+
Only the latest minor release receives security fixes while the project is
|
|
34
|
+
pre-1.0. After 1.0 the latest two minor lines will be supported.
|
|
35
|
+
|
|
36
|
+
## In scope
|
|
37
|
+
|
|
38
|
+
* Cache poisoning / false cache hits that reuse a result for different inputs
|
|
39
|
+
* Path traversal, symlink or archive-style escapes when restoring cached outputs
|
|
40
|
+
* Secret disclosure through logs, cache metadata or child-process environments
|
|
41
|
+
* Command or argument injection in BuildRush's own subprocess calls
|
|
42
|
+
* Anything that makes BuildRush execute code the project config did not request
|
|
43
|
+
* Supply-chain weaknesses in our release pipeline or published artifacts
|
|
44
|
+
|
|
45
|
+
## Out of scope
|
|
46
|
+
|
|
47
|
+
* "A malicious `buildrush.json` runs commands." That is the product: the config
|
|
48
|
+
is code, like a Makefile or `package.json` scripts. Do not run BuildRush on
|
|
49
|
+
repositories you do not trust, outside a sandbox. BuildRush is **not** a
|
|
50
|
+
sandbox for hostile code.
|
|
51
|
+
* Attacks that require write access to the victim's cache directory or home
|
|
52
|
+
directory as the same OS user (see the trust model for why, and for the
|
|
53
|
+
planned signed-entry design that will cover shared caches).
|
|
54
|
+
* Findings in third-party tools BuildRush merely invokes (tsc, vite, vitest ...).
|
package/bin/buildrush.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TaskConfig } from './config.js';
|
|
2
|
+
export type AdapterName = 'vite' | 'vitest' | 'tsc' | 'eslint';
|
|
3
|
+
export declare const ADAPTER_NAMES: readonly AdapterName[];
|
|
4
|
+
export declare const ADAPTER_KIND: Record<AdapterName, 'build' | 'test' | 'check'>;
|
|
5
|
+
/** What an adapter contributes to a task. Explicit user config always wins over these defaults. */
|
|
6
|
+
export interface Resolved {
|
|
7
|
+
command: string[];
|
|
8
|
+
/** null = hash the whole project (used when the tool config makes the real inputs unknowable). */
|
|
9
|
+
inputs: string[] | null;
|
|
10
|
+
outputs: string[];
|
|
11
|
+
env: string[];
|
|
12
|
+
/** Every process env var whose NAME starts with one of these is passed AND fingerprinted. */
|
|
13
|
+
envPrefixes: string[];
|
|
14
|
+
/** false = adapter cannot make this task safely cacheable. */
|
|
15
|
+
cache: boolean;
|
|
16
|
+
notes: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function resolveAdapter(name: AdapterName, cwd: string, t: TaskConfig): Promise<Resolved>;
|
|
19
|
+
/** Installed version of an npm tool, looked up from `cwd` upward; null when not installed. */
|
|
20
|
+
export declare function toolVersion(root: string, cwd: string, pkg: string): Promise<string | null>;
|
|
21
|
+
export declare const ADAPTER_PACKAGE: Record<AdapterName, string>;
|
|
22
|
+
/** Pull concise failure information out of tool output (display only; never affects caching). */
|
|
23
|
+
export declare function diagnostics(name: AdapterName | null, log: string): string[];
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { parseJsonc } from './graph.js';
|
|
4
|
+
import { readJson } from './util/fsx.js';
|
|
5
|
+
export const ADAPTER_NAMES = ['vite', 'vitest', 'tsc', 'eslint'];
|
|
6
|
+
export const ADAPTER_KIND = { vite: 'build', vitest: 'test', tsc: 'check', eslint: 'check' };
|
|
7
|
+
const PM_FILES = ['package.json', 'package-lock.json', 'npm-shrinkwrap.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lock', 'bun.lockb', '.npmrc', '.nvmrc', '.node-version'];
|
|
8
|
+
const SRC_EXT = '{ts,tsx,mts,cts,js,jsx,mjs,cjs,json}';
|
|
9
|
+
async function firstExisting(dir, names) {
|
|
10
|
+
for (const n of names) {
|
|
11
|
+
try {
|
|
12
|
+
return { file: n, text: await fs.readFile(path.join(dir, n), 'utf8') };
|
|
13
|
+
}
|
|
14
|
+
catch { /* next */ }
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const exts = (base) => ['ts', 'js', 'mjs', 'mts', 'cjs', 'cts'].map((e) => `${base}.${e}`);
|
|
19
|
+
/** Config keys that can pull inputs from places we cannot enumerate statically. */
|
|
20
|
+
const RISKY_CONFIG = /\b(root|envDir|publicDir|cacheDir|include|setupFiles|globalSetup|dir)\s*:|['"`]\.\.\//;
|
|
21
|
+
function flagValue(argv, flag) {
|
|
22
|
+
for (let i = 0; i < argv.length; i++) {
|
|
23
|
+
const a = argv[i];
|
|
24
|
+
if (a === flag)
|
|
25
|
+
return argv[i + 1] ?? null;
|
|
26
|
+
if (a.startsWith(flag + '='))
|
|
27
|
+
return a.slice(flag.length + 1);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function safeOutDir(dir) {
|
|
32
|
+
const n = path.posix.normalize(dir.replace(/^\.\//, ''));
|
|
33
|
+
if (!n || n === '.' || n.startsWith('..') || path.posix.isAbsolute(n))
|
|
34
|
+
return null;
|
|
35
|
+
return n.replace(/\/$/, '');
|
|
36
|
+
}
|
|
37
|
+
export async function resolveAdapter(name, cwd, t) {
|
|
38
|
+
const notes = [];
|
|
39
|
+
const base = { env: ['NODE_ENV'], envPrefixes: [], cache: true, notes };
|
|
40
|
+
const argv = t.command;
|
|
41
|
+
const sub = (i) => argv[i];
|
|
42
|
+
if (name === 'vite') {
|
|
43
|
+
const command = argv.length ? [...argv] : ['vite', 'build'];
|
|
44
|
+
if (command.length === 1)
|
|
45
|
+
command.push('build');
|
|
46
|
+
if (command[0] === 'vite' && !['build', undefined].includes(command[1]) && !command[1].startsWith('-')) {
|
|
47
|
+
throw new Error(`vite adapter only supports "vite build" (got "vite ${command[1]}"): dev/preview servers are long-running and cannot be cached`);
|
|
48
|
+
}
|
|
49
|
+
const cfg = await firstExisting(cwd, exts('vite.config'));
|
|
50
|
+
const text = cfg?.text ?? '';
|
|
51
|
+
let inputs = [
|
|
52
|
+
'src/**', 'public/**', '*.html', ...exts('vite.config'), 'tsconfig*.json', '.env', '.env.*', ...PM_FILES,
|
|
53
|
+
];
|
|
54
|
+
if (RISKY_CONFIG.test(text) || flagValue(command, '--config') || flagValue(command, '-c')) {
|
|
55
|
+
inputs = null;
|
|
56
|
+
notes.push('vite config sets root/envDir/publicDir/include or reaches outside the project (or a custom --config is used): hashing the whole project to stay correct. List inputs explicitly to narrow.');
|
|
57
|
+
}
|
|
58
|
+
const cliOut = flagValue(command, '--outDir');
|
|
59
|
+
const lit = /outDir\s*:\s*(['"`])([^'"`$\n]+)\1/.exec(text);
|
|
60
|
+
const dir = cliOut ?? lit?.[2] ?? (/outDir\s*:/.test(text) ? null : 'dist');
|
|
61
|
+
const out = dir === null ? null : safeOutDir(dir);
|
|
62
|
+
let cache = true;
|
|
63
|
+
let outputs = [];
|
|
64
|
+
if (out === null) {
|
|
65
|
+
cache = false;
|
|
66
|
+
notes.push('vite build.outDir is not a plain project-relative literal: outputs cannot be determined, caching disabled for this task. Set "outputs" explicitly to enable it.');
|
|
67
|
+
}
|
|
68
|
+
else
|
|
69
|
+
outputs = [`${out}/**`];
|
|
70
|
+
base.env.push('MODE');
|
|
71
|
+
notes.push('Vite exposes VITE_* env vars to the bundle: every VITE_* variable present is passed and fingerprinted; .env* files are inputs.');
|
|
72
|
+
return { command, inputs, outputs, ...base, envPrefixes: ['VITE_'], cache, notes };
|
|
73
|
+
}
|
|
74
|
+
if (name === 'vitest') {
|
|
75
|
+
const command = argv.length ? [...argv] : ['vitest', 'run'];
|
|
76
|
+
if (command.length === 1 || (command[0] === 'vitest' && command[1].startsWith('-') && !command.includes('run')))
|
|
77
|
+
command.splice(1, 0, 'run');
|
|
78
|
+
if (['watch', 'dev', 'bench', 'ui'].includes(command[1] ?? '') || command.some((a) => a === '--watch' || a === '-w' || a === '--ui')) {
|
|
79
|
+
throw new Error('vitest adapter requires a single-shot run ("vitest run"); watch/ui modes cannot be cached');
|
|
80
|
+
}
|
|
81
|
+
const cfg = await firstExisting(cwd, [...exts('vitest.config'), ...exts('vitest.workspace'), ...exts('vite.config')]);
|
|
82
|
+
let inputs = [
|
|
83
|
+
'src/**', 'test/**', 'tests/**', '**/__tests__/**', `**/*.{test,spec}.${SRC_EXT}`, ...exts('vitest.config'), ...exts('vitest.workspace'),
|
|
84
|
+
...exts('vite.config'), 'tsconfig*.json', '.env', '.env.*', ...PM_FILES,
|
|
85
|
+
];
|
|
86
|
+
if (cfg && RISKY_CONFIG.test(cfg.text)) {
|
|
87
|
+
inputs = null;
|
|
88
|
+
notes.push(`${cfg.file} customises include/root/setupFiles/dir or reaches outside the project: hashing the whole project to stay correct. List inputs explicitly to narrow.`);
|
|
89
|
+
}
|
|
90
|
+
const outputs = command.some((a) => a === '--coverage' || a.startsWith('--coverage.')) ? ['coverage/**'] : [];
|
|
91
|
+
if (outputs.length)
|
|
92
|
+
notes.push('coverage enabled: coverage/** is captured as an output.');
|
|
93
|
+
notes.push('Test results are only reusable if tests are deterministic. Tests that use network, time or randomness must set "cache": false.');
|
|
94
|
+
return { command, inputs, outputs, ...base, envPrefixes: ['VITE_', 'VITEST_'], notes };
|
|
95
|
+
}
|
|
96
|
+
if (name === 'tsc') {
|
|
97
|
+
const command = argv.length ? [...argv] : ['tsc', '--noEmit'];
|
|
98
|
+
const project = flagValue(command, '-p') ?? flagValue(command, '--project') ?? 'tsconfig.json';
|
|
99
|
+
let noEmit = command.includes('--noEmit');
|
|
100
|
+
let outDir = flagValue(command, '--outDir');
|
|
101
|
+
const ts = (await readJson(path.join(cwd, project)).catch(() => null)) ?? (await fs.readFile(path.join(cwd, project), 'utf8').then(parseJsonc, () => null));
|
|
102
|
+
const co = ts?.compilerOptions;
|
|
103
|
+
if (co?.noEmit)
|
|
104
|
+
noEmit = true;
|
|
105
|
+
outDir ??= co?.outDir ?? null;
|
|
106
|
+
let cache = true;
|
|
107
|
+
let outputs = [];
|
|
108
|
+
if (!noEmit) {
|
|
109
|
+
const o = outDir ? safeOutDir(outDir) : null;
|
|
110
|
+
if (!o) {
|
|
111
|
+
cache = false;
|
|
112
|
+
notes.push('tsc emits but no project-relative outDir was found: it would write next to sources, so caching is disabled. Add "outDir" or use --noEmit.');
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
outputs = [`${o}/**`];
|
|
116
|
+
if (co?.incremental || co?.composite)
|
|
117
|
+
notes.push('incremental/composite builds write .tsbuildinfo, which is not captured; consider "noEmit" for checks.');
|
|
118
|
+
}
|
|
119
|
+
void sub;
|
|
120
|
+
return { command, inputs: [`**/*.${SRC_EXT}`, ...PM_FILES], outputs, ...base, env: [], cache, notes };
|
|
121
|
+
}
|
|
122
|
+
// eslint
|
|
123
|
+
const command = argv.length ? [...argv] : ['eslint', '.'];
|
|
124
|
+
notes.push('eslint plugins/configs outside the project are only tracked through the lockfile.');
|
|
125
|
+
return {
|
|
126
|
+
command,
|
|
127
|
+
inputs: [`**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,json,vue,svelte,astro}`, '.eslintrc*', 'eslint.config.*', '.eslintignore', ...PM_FILES],
|
|
128
|
+
outputs: [], ...base, env: [], cache: true, notes,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Installed version of an npm tool, looked up from `cwd` upward; null when not installed. */
|
|
132
|
+
export async function toolVersion(root, cwd, pkg) {
|
|
133
|
+
let dir = cwd;
|
|
134
|
+
for (;;) {
|
|
135
|
+
const j = await readJson(path.join(dir, 'node_modules', pkg, 'package.json'));
|
|
136
|
+
if (j?.version)
|
|
137
|
+
return j.version;
|
|
138
|
+
if (dir === root || path.dirname(dir) === dir)
|
|
139
|
+
return null;
|
|
140
|
+
dir = path.dirname(dir);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export const ADAPTER_PACKAGE = { vite: 'vite', vitest: 'vitest', tsc: 'typescript', eslint: 'eslint' };
|
|
144
|
+
/** Pull concise failure information out of tool output (display only; never affects caching). */
|
|
145
|
+
export function diagnostics(name, log) {
|
|
146
|
+
const out = new Set();
|
|
147
|
+
if (name === 'vitest') {
|
|
148
|
+
for (const m of log.matchAll(/^\s*(?:FAIL|❯|×)\s+(\S+\.(?:test|spec)\.[cm]?[jt]sx?)/gm))
|
|
149
|
+
out.add(`failed test file: ${m[1]}`);
|
|
150
|
+
}
|
|
151
|
+
else if (name === 'tsc') {
|
|
152
|
+
for (const m of log.matchAll(/^(\S+?)\((\d+),(\d+)\): error (TS\d+): (.+)$/gm))
|
|
153
|
+
out.add(`${m[1]}:${m[2]}:${m[3]} ${m[4]} ${m[5]}`);
|
|
154
|
+
}
|
|
155
|
+
else if (name === 'eslint') {
|
|
156
|
+
let file = '';
|
|
157
|
+
for (const line of log.split('\n')) {
|
|
158
|
+
if (/^\/|^[A-Za-z]:\\|^\S+\.[cm]?[jt]sx?$/.test(line.trim()) && !line.startsWith(' '))
|
|
159
|
+
file = line.trim();
|
|
160
|
+
const m = /^\s+(\d+):(\d+)\s+error\s+(.+?)\s{2,}(\S+)$/.exec(line);
|
|
161
|
+
if (m)
|
|
162
|
+
out.add(`${file}:${m[1]}:${m[2]} ${m[4]} ${m[3]}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (name === 'vite') {
|
|
166
|
+
for (const m of log.matchAll(/^error during build:\n?(.+)$/gm))
|
|
167
|
+
out.add(m[1]);
|
|
168
|
+
}
|
|
169
|
+
return [...out].slice(0, 50);
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,YAAY,GAAoD,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAE9I,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;AAC3K,MAAM,OAAO,GAAG,sCAAsC,CAAC;AA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GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,gCAAgC,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DepGraph } from './graph.js';
|
|
2
|
+
export interface Selection {
|
|
3
|
+
mode: 'affected' | 'all';
|
|
4
|
+
/** Why every test was selected (mode "all"). */
|
|
5
|
+
reason: string | null;
|
|
6
|
+
changed: string[];
|
|
7
|
+
selected: string[];
|
|
8
|
+
skipped: {
|
|
9
|
+
test: string;
|
|
10
|
+
reason: string;
|
|
11
|
+
}[];
|
|
12
|
+
/** selected test -> import chain from the test down to the changed file. */
|
|
13
|
+
chains: Record<string, string[]>;
|
|
14
|
+
}
|
|
15
|
+
export interface ChangedFiles {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
files: string[];
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Files changed relative to `since` (default HEAD), including untracked files. Never uses a shell. */
|
|
21
|
+
export declare function changedFilesFromGit(root: string, since?: string): Promise<ChangedFiles>;
|
|
22
|
+
/**
|
|
23
|
+
* Select the tests that could be affected by `changed`. Correctness rules:
|
|
24
|
+
* - any unbounded change (global config, lockfile, uncertain imports) selects ALL tests;
|
|
25
|
+
* - tests whose own imports cannot be resolved are always selected;
|
|
26
|
+
* - deleted files are expanded using the previous graph's reverse edges.
|
|
27
|
+
*/
|
|
28
|
+
export declare function selectTests(graph: DepGraph, prev: DepGraph | null, changed: string[]): Selection;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
const pexec = promisify(execFile);
|
|
4
|
+
/** Files changed relative to `since` (default HEAD), including untracked files. Never uses a shell. */
|
|
5
|
+
export async function changedFilesFromGit(root, since = 'HEAD') {
|
|
6
|
+
if (since.startsWith('-'))
|
|
7
|
+
return { ok: false, files: [], error: `invalid git ref ${JSON.stringify(since)}` };
|
|
8
|
+
try {
|
|
9
|
+
const opts = { cwd: root, maxBuffer: 64 * 1024 * 1024 };
|
|
10
|
+
// Two independent git processes: run them concurrently (process start-up dominates, esp. on Windows).
|
|
11
|
+
const [tracked, untracked] = await Promise.all([
|
|
12
|
+
pexec('git', ['diff', '--name-only', '-z', '--no-renames', '--relative', since, '--'], opts),
|
|
13
|
+
pexec('git', ['ls-files', '--others', '--exclude-standard', '-z'], opts),
|
|
14
|
+
]);
|
|
15
|
+
const files = new Set();
|
|
16
|
+
for (const out of [tracked.stdout, untracked.stdout])
|
|
17
|
+
for (const f of out.split('\0'))
|
|
18
|
+
if (f)
|
|
19
|
+
files.add(f);
|
|
20
|
+
return { ok: true, files: [...files].sort() };
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
return { ok: false, files: [], error: `git failed: ${e.message.split('\n')[0]}` };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Select the tests that could be affected by `changed`. Correctness rules:
|
|
28
|
+
* - any unbounded change (global config, lockfile, uncertain imports) selects ALL tests;
|
|
29
|
+
* - tests whose own imports cannot be resolved are always selected;
|
|
30
|
+
* - deleted files are expanded using the previous graph's reverse edges.
|
|
31
|
+
*/
|
|
32
|
+
export function selectTests(graph, prev, changed) {
|
|
33
|
+
const all = graph.testFiles();
|
|
34
|
+
const base = { changed, chains: {} };
|
|
35
|
+
if (changed.length === 0) {
|
|
36
|
+
return { mode: 'affected', reason: null, ...base, selected: [], skipped: all.map((test) => ({ test, reason: 'no files changed' })) };
|
|
37
|
+
}
|
|
38
|
+
const { reached, conservative } = graph.impact(changed, prev);
|
|
39
|
+
if (conservative) {
|
|
40
|
+
return { mode: 'all', reason: conservative, ...base, selected: all, skipped: [] };
|
|
41
|
+
}
|
|
42
|
+
const selected = [];
|
|
43
|
+
const skipped = [];
|
|
44
|
+
for (const t of all) {
|
|
45
|
+
const mod = graph.modules.get(t);
|
|
46
|
+
if (reached.has(t)) {
|
|
47
|
+
selected.push(t);
|
|
48
|
+
base.chains[t] = graph.chain(reached, t);
|
|
49
|
+
}
|
|
50
|
+
else if (mod.uncertain.length) {
|
|
51
|
+
selected.push(t);
|
|
52
|
+
base.chains[t] = [t, `(always runs: ${mod.uncertain[0]})`];
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
skipped.push({ test: t, reason: 'no import path to any changed file' });
|
|
56
|
+
}
|
|
57
|
+
return { mode: 'affected', reason: null, ...base, selected, skipped };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=affected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affected.js","sourceRoot":"","sources":["../../src/affected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAmBlC,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAY,EAAE,KAAK,GAAG,MAAM;IACpE,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,mBAAmB,IAAI,CAAC,SAAS,CAAC,KAAK,C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AAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC7D,CAAC;;YAAM,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,oCAAoC,EAAE,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export interface ManifestEntry {
|
|
2
|
+
path: string;
|
|
3
|
+
digest: string;
|
|
4
|
+
size: number;
|
|
5
|
+
/** Permission bits only (0o777 mask); setuid/setgid/sticky are never stored or restored. */
|
|
6
|
+
mode: number;
|
|
7
|
+
}
|
|
8
|
+
/** Non-secret, digest-only description of every fingerprint input (used for miss explanations). */
|
|
9
|
+
export interface Components {
|
|
10
|
+
schema: 1;
|
|
11
|
+
task: string;
|
|
12
|
+
command: string[];
|
|
13
|
+
cwd: string;
|
|
14
|
+
env: Record<string, string | null>;
|
|
15
|
+
toolchain: Record<string, string | null>;
|
|
16
|
+
inputs: Record<string, string>;
|
|
17
|
+
deps: Record<string, string>;
|
|
18
|
+
outputs: string[];
|
|
19
|
+
args: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface ActionRecord {
|
|
22
|
+
v: 1;
|
|
23
|
+
key: string;
|
|
24
|
+
task: string;
|
|
25
|
+
createdAt: number;
|
|
26
|
+
durationMs: number;
|
|
27
|
+
outputs: ManifestEntry[];
|
|
28
|
+
logDigest: string | null;
|
|
29
|
+
components: Components;
|
|
30
|
+
}
|
|
31
|
+
export interface CacheStats {
|
|
32
|
+
dir: string;
|
|
33
|
+
entries: number;
|
|
34
|
+
blobs: number;
|
|
35
|
+
bytes: number;
|
|
36
|
+
}
|
|
37
|
+
export interface VerifyReport {
|
|
38
|
+
entries: number;
|
|
39
|
+
blobs: number;
|
|
40
|
+
corruptBlobs: string[];
|
|
41
|
+
badEntries: string[];
|
|
42
|
+
missingBlobs: {
|
|
43
|
+
entry: string;
|
|
44
|
+
digest: string;
|
|
45
|
+
}[];
|
|
46
|
+
repaired: number;
|
|
47
|
+
}
|
|
48
|
+
export declare class Cache {
|
|
49
|
+
readonly dir: string;
|
|
50
|
+
constructor(dir: string);
|
|
51
|
+
private get blobs();
|
|
52
|
+
private get actions();
|
|
53
|
+
private get tmp();
|
|
54
|
+
blobPath(digest: string): string;
|
|
55
|
+
init(): Promise<void>;
|
|
56
|
+
/** Per-cache random key used for keyed digests of secret-like env values. */
|
|
57
|
+
secretKey(): Promise<Buffer>;
|
|
58
|
+
putBlobFromFile(abs: string, digest: string): Promise<boolean>;
|
|
59
|
+
putBlobData(data: Uint8Array): Promise<string>;
|
|
60
|
+
readBlob(digest: string): Promise<Buffer | null>;
|
|
61
|
+
/** Returns null for missing OR structurally invalid entries (never throws on corruption). */
|
|
62
|
+
lookup(key: string): Promise<ActionRecord | null>;
|
|
63
|
+
store(rec: ActionRecord, root: string): Promise<{
|
|
64
|
+
bytes: number;
|
|
65
|
+
}>;
|
|
66
|
+
touch(key: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Restore outputs into `root`. All blobs are verified BEFORE the first file
|
|
69
|
+
* is written, so a corrupt entry never produces a half-restored tree.
|
|
70
|
+
* Each file is written to a temp name and renamed into place.
|
|
71
|
+
*/
|
|
72
|
+
restore(rec: ActionRecord, root: string): Promise<{
|
|
73
|
+
bytes: number;
|
|
74
|
+
files: number;
|
|
75
|
+
}>;
|
|
76
|
+
deleteEntry(key: string): Promise<void>;
|
|
77
|
+
private listActions;
|
|
78
|
+
private listBlobs;
|
|
79
|
+
stats(): Promise<CacheStats>;
|
|
80
|
+
/** Re-hash every blob and check every entry's references. With `repair`, remove what is broken. */
|
|
81
|
+
verify(opts?: {
|
|
82
|
+
repair?: boolean;
|
|
83
|
+
}): Promise<VerifyReport>;
|
|
84
|
+
/** Evict least-recently-used entries until blobs fit in maxBytes, then drop unreferenced blobs. */
|
|
85
|
+
gc(maxBytes: number): Promise<{
|
|
86
|
+
evictedEntries: number;
|
|
87
|
+
removedBlobs: number;
|
|
88
|
+
freedBytes: number;
|
|
89
|
+
}>;
|
|
90
|
+
clean(): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
export declare class CacheCorruptError extends Error {
|
|
93
|
+
constructor(message: string);
|
|
94
|
+
}
|