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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { Cache } from './cache.js';
|
|
4
|
+
import { findProjectRoot, loadConfig } from './config.js';
|
|
5
|
+
import { resolveAdapter } from './adapters.js';
|
|
6
|
+
import { FileIndex } from './fsindex.js';
|
|
7
|
+
import { DepGraph } from './graph.js';
|
|
8
|
+
import { readJson, writeFileAtomic } from './util/fsx.js';
|
|
9
|
+
import { compileGlobs } from './util/glob.js';
|
|
10
|
+
import { discoverWorkspaces, expandWorkspaceTasks, finalizePackageTasks } from './workspaces.js';
|
|
11
|
+
export class Project {
|
|
12
|
+
root;
|
|
13
|
+
config;
|
|
14
|
+
index;
|
|
15
|
+
cache;
|
|
16
|
+
workspace;
|
|
17
|
+
taskGroups;
|
|
18
|
+
stateDir;
|
|
19
|
+
graphCache = null;
|
|
20
|
+
constructor(root, config, index, cache,
|
|
21
|
+
/** Detected workspace (monorepo), or null. */
|
|
22
|
+
workspace = null,
|
|
23
|
+
/** Package-task template name -> its per-package instance ids. */
|
|
24
|
+
taskGroups = {}) {
|
|
25
|
+
this.root = root;
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.index = index;
|
|
28
|
+
this.cache = cache;
|
|
29
|
+
this.workspace = workspace;
|
|
30
|
+
this.taskGroups = taskGroups;
|
|
31
|
+
this.stateDir = path.join(root, '.buildrush', 'state');
|
|
32
|
+
}
|
|
33
|
+
static async open(start, opts = {}) {
|
|
34
|
+
const found = await findProjectRoot(start);
|
|
35
|
+
if (!found)
|
|
36
|
+
throw new Error(`no buildrush.json found in ${start} or any parent directory (run \`buildrush init\`)`);
|
|
37
|
+
const root = await fs.realpath(found);
|
|
38
|
+
const config = await loadConfig(root);
|
|
39
|
+
const workspace = await discoverWorkspaces(root, config.workspaces);
|
|
40
|
+
const taskGroups = expandWorkspaceTasks(config, workspace);
|
|
41
|
+
for (const t of Object.values(config.tasks)) {
|
|
42
|
+
if (!t.adapter)
|
|
43
|
+
continue;
|
|
44
|
+
const cwd = t.cwd === '.' ? root : path.join(root, t.cwd);
|
|
45
|
+
let r;
|
|
46
|
+
try {
|
|
47
|
+
r = await resolveAdapter(t.adapter, cwd, t);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
throw new Error(`tasks.${t.name} (adapter ${t.adapter}): ${e.message}`);
|
|
51
|
+
}
|
|
52
|
+
t.command = r.command;
|
|
53
|
+
t.inputs ??= r.inputs;
|
|
54
|
+
const userOutputs = t.outputs.length > 0;
|
|
55
|
+
if (!userOutputs)
|
|
56
|
+
t.outputs = r.outputs;
|
|
57
|
+
t.env = [...new Set([...t.env, ...r.env])];
|
|
58
|
+
t.envPrefixes = r.envPrefixes;
|
|
59
|
+
if (!r.cache && !userOutputs)
|
|
60
|
+
t.cache = false;
|
|
61
|
+
t.notes = r.notes;
|
|
62
|
+
if (t.testCache && t.adapter === 'vitest') {
|
|
63
|
+
const customised = r.inputs === null || t.command.some((a) => /^(--config|-c|--root|-r|--dir|--workspace|--project)(=|$)/.test(a));
|
|
64
|
+
if (customised) {
|
|
65
|
+
t.testCache = false;
|
|
66
|
+
t.notes.push('testCache disabled: the vitest config/command customises root/include/setupFiles/dir, so per-file inputs cannot be bounded safely.');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
finalizePackageTasks(config);
|
|
71
|
+
const stateDir = path.join(root, '.buildrush', 'state');
|
|
72
|
+
const cacheDir = process.env.BUILDRUSH_CACHE_DIR
|
|
73
|
+
? path.resolve(process.env.BUILDRUSH_CACHE_DIR)
|
|
74
|
+
: config.cache.dir
|
|
75
|
+
? path.resolve(root, config.cache.dir)
|
|
76
|
+
: path.join(root, '.buildrush', 'cache');
|
|
77
|
+
const index = new FileIndex(root, config.ignore, path.join(stateDir, 'index.json'));
|
|
78
|
+
const cache = new Cache(cacheDir);
|
|
79
|
+
await cache.init();
|
|
80
|
+
await fs.mkdir(stateDir, { recursive: true, mode: 0o700 });
|
|
81
|
+
const p = new Project(root, config, index, cache, workspace, taskGroups);
|
|
82
|
+
if (opts.scan !== false) {
|
|
83
|
+
await index.load();
|
|
84
|
+
await index.scan();
|
|
85
|
+
}
|
|
86
|
+
return p;
|
|
87
|
+
}
|
|
88
|
+
/** Union of every task's output globs: files BuildRush itself produces. */
|
|
89
|
+
outputMatcher() {
|
|
90
|
+
return compileGlobs(Object.values(this.config.tasks).flatMap((t) => t.outputs));
|
|
91
|
+
}
|
|
92
|
+
async graph(opts = {}) {
|
|
93
|
+
if (this.graphCache && !opts.fresh)
|
|
94
|
+
return this.graphCache;
|
|
95
|
+
const isOutput = this.outputMatcher();
|
|
96
|
+
// Generated outputs are not source: keep them out of the module graph.
|
|
97
|
+
const files = new Map([...this.index.files].filter(([f]) => !isOutput(f)));
|
|
98
|
+
this.graphCache = await DepGraph.build(this.root, files, {
|
|
99
|
+
testPatterns: this.config.tests.patterns,
|
|
100
|
+
cachePath: path.join(this.stateDir, 'scan-cache.json'),
|
|
101
|
+
workspace: this.workspace,
|
|
102
|
+
});
|
|
103
|
+
return this.graphCache;
|
|
104
|
+
}
|
|
105
|
+
async loadPreviousGraph() {
|
|
106
|
+
const s = await readJson(path.join(this.stateDir, 'graph.json'));
|
|
107
|
+
return s && s.version === 1 ? DepGraph.deserialize(s) : null;
|
|
108
|
+
}
|
|
109
|
+
async saveGraph(g) {
|
|
110
|
+
await writeFileAtomic(path.join(this.stateDir, 'graph.json'), JSON.stringify(g.serialize()));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAU,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAmB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,oBAAoB,EAAa,MAAM,iBAAiB,CAAC;AAE5G,MAAM,OAAO,OAAO;IAKP,IAAI;IACJ,MAAM;IACN,KAAK;IACL,KAAK;IAEL,SAAS;IAET,UAAU;IAXZ,QAAQ,CAAS;IAClB,UAAU,GAAoB,IAAI,CAAC;IAE3C,YACW,IAAY,EACZ,MAAc,EACd,KAAgB,EAChB,KAAY;IACrB,8CAA8C;IACrC,SAAS,GAAqB,IAAI;IAC3C,kE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C,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC/F,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface RunResult {
|
|
2
|
+
exitCode: number | null;
|
|
3
|
+
signal: NodeJS.Signals | null;
|
|
4
|
+
durationMs: number;
|
|
5
|
+
log: string;
|
|
6
|
+
timedOut: boolean;
|
|
7
|
+
cancelled: boolean;
|
|
8
|
+
spawnError: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function isSecretName(name: string): boolean;
|
|
11
|
+
/** Replace the values of secret-looking env vars wherever they appear in `text`. */
|
|
12
|
+
export declare function makeRedactor(env: Record<string, string | undefined>): (text: string) => string;
|
|
13
|
+
/** Find an executable without a shell: explicit path, project node_modules/.bin, then PATH. */
|
|
14
|
+
export declare function resolveExecutable(cmd: string, cwd: string, root: string, pathEnv: string): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Extract the JS entry point from an npm/pnpm/yarn `.cmd` shim (e.g. `"%dp0%\..\vite\bin\vite.js"`).
|
|
17
|
+
* Windows cannot spawn `.cmd` files without a shell, and routing arguments through cmd.exe is an
|
|
18
|
+
* injection risk, so we run the shim's real target directly with node instead. Returns null when
|
|
19
|
+
* the shim is not a recognisable node launcher.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseCmdShim(shimText: string, shimPath: string): string | null;
|
|
22
|
+
/** Turn a resolved executable into a shell-free (file, args) pair; unwraps Windows .cmd shims. */
|
|
23
|
+
export declare function toSpawnArgs(file: string, args: string[]): {
|
|
24
|
+
file: string;
|
|
25
|
+
args: string[];
|
|
26
|
+
error?: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function runCommand(opts: {
|
|
29
|
+
file: string;
|
|
30
|
+
args: string[];
|
|
31
|
+
cwd: string;
|
|
32
|
+
env: Record<string, string>;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
timeoutMs?: number | null;
|
|
35
|
+
redact: (s: string) => string;
|
|
36
|
+
}): Promise<RunResult>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
const SECRET_NAME = /(TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|API_?KEY|PRIVATE_?KEY|AUTH|COOKIE|SESSION)/i;
|
|
5
|
+
const MAX_LOG_BYTES = 8 * 1024 * 1024;
|
|
6
|
+
const KILL_GRACE_MS = 5000;
|
|
7
|
+
export function isSecretName(name) {
|
|
8
|
+
return SECRET_NAME.test(name);
|
|
9
|
+
}
|
|
10
|
+
/** Replace the values of secret-looking env vars wherever they appear in `text`. */
|
|
11
|
+
export function makeRedactor(env) {
|
|
12
|
+
const secrets = Object.entries(env)
|
|
13
|
+
.filter(([k, v]) => isSecretName(k) && typeof v === 'string' && v.length >= 6)
|
|
14
|
+
.map(([, v]) => v)
|
|
15
|
+
.sort((a, b) => b.length - a.length);
|
|
16
|
+
if (secrets.length === 0)
|
|
17
|
+
return (t) => t;
|
|
18
|
+
return (t) => {
|
|
19
|
+
let out = t;
|
|
20
|
+
for (const s of secrets)
|
|
21
|
+
out = out.split(s).join('***');
|
|
22
|
+
return out;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Find an executable without a shell: explicit path, project node_modules/.bin, then PATH. */
|
|
26
|
+
export function resolveExecutable(cmd, cwd, root, pathEnv) {
|
|
27
|
+
const isExec = (p) => {
|
|
28
|
+
try {
|
|
29
|
+
fs.accessSync(p, fs.constants.X_OK);
|
|
30
|
+
return fs.statSync(p).isFile();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
if (cmd.includes('/') || cmd.includes(path.sep)) {
|
|
37
|
+
const abs = path.resolve(cwd, cmd);
|
|
38
|
+
return isExec(abs) ? abs : null;
|
|
39
|
+
}
|
|
40
|
+
const dirs = [path.join(cwd, 'node_modules', '.bin'), path.join(root, 'node_modules', '.bin'), ...pathEnv.split(path.delimiter)];
|
|
41
|
+
const exts = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
42
|
+
for (const d of dirs) {
|
|
43
|
+
if (!d)
|
|
44
|
+
continue;
|
|
45
|
+
for (const e of exts) {
|
|
46
|
+
const p = path.join(d, cmd + e);
|
|
47
|
+
if (isExec(p))
|
|
48
|
+
return p;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extract the JS entry point from an npm/pnpm/yarn `.cmd` shim (e.g. `"%dp0%\..\vite\bin\vite.js"`).
|
|
55
|
+
* Windows cannot spawn `.cmd` files without a shell, and routing arguments through cmd.exe is an
|
|
56
|
+
* injection risk, so we run the shim's real target directly with node instead. Returns null when
|
|
57
|
+
* the shim is not a recognisable node launcher.
|
|
58
|
+
*/
|
|
59
|
+
export function parseCmdShim(shimText, shimPath) {
|
|
60
|
+
// Shims mention "%dp0%\node.exe" (the optional bundled node) before the real script: take the
|
|
61
|
+
// first quoted %dp0%-relative path that is an existing file other than node.exe.
|
|
62
|
+
for (const m of shimText.matchAll(/"%(?:~dp0|dp0%)\\?([^"%]+)"/gi)) {
|
|
63
|
+
const rel = m[1].replace(/\\/g, path.sep);
|
|
64
|
+
if (/(^|[\\/])node(\.exe)?$/i.test(rel))
|
|
65
|
+
continue;
|
|
66
|
+
const target = path.resolve(path.dirname(shimPath), rel);
|
|
67
|
+
try {
|
|
68
|
+
if (fs.statSync(target).isFile())
|
|
69
|
+
return target;
|
|
70
|
+
}
|
|
71
|
+
catch { /* try the next candidate */ }
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
/** Turn a resolved executable into a shell-free (file, args) pair; unwraps Windows .cmd shims. */
|
|
76
|
+
export function toSpawnArgs(file, args) {
|
|
77
|
+
if (process.platform === 'win32' && /\.(cmd|bat)$/i.test(file)) {
|
|
78
|
+
let text = '';
|
|
79
|
+
try {
|
|
80
|
+
text = fs.readFileSync(file, 'utf8');
|
|
81
|
+
}
|
|
82
|
+
catch { /* handled below */ }
|
|
83
|
+
const target = parseCmdShim(text, file);
|
|
84
|
+
if (!target)
|
|
85
|
+
return { file, args, error: `cannot run ${file} without a shell: not a recognised Node.js launcher shim (BuildRush never passes arguments through cmd.exe)` };
|
|
86
|
+
return { file: process.execPath, args: [target, ...args] };
|
|
87
|
+
}
|
|
88
|
+
return { file, args };
|
|
89
|
+
}
|
|
90
|
+
export function runCommand(opts) {
|
|
91
|
+
const start = Date.now();
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
let child;
|
|
94
|
+
try {
|
|
95
|
+
const sp = toSpawnArgs(opts.file, opts.args);
|
|
96
|
+
if (sp.error)
|
|
97
|
+
throw new Error(sp.error);
|
|
98
|
+
child = spawn(sp.file, sp.args, {
|
|
99
|
+
cwd: opts.cwd,
|
|
100
|
+
env: opts.env,
|
|
101
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
102
|
+
shell: false,
|
|
103
|
+
detached: process.platform !== 'win32',
|
|
104
|
+
windowsHide: true,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
resolve({ exitCode: null, signal: null, durationMs: 0, log: '', timedOut: false, cancelled: false, spawnError: e.message });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const chunks = [];
|
|
112
|
+
let size = 0;
|
|
113
|
+
let truncated = false;
|
|
114
|
+
const onData = (d) => {
|
|
115
|
+
if (size >= MAX_LOG_BYTES) {
|
|
116
|
+
truncated = true;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
chunks.push(d);
|
|
120
|
+
size += d.length;
|
|
121
|
+
};
|
|
122
|
+
child.stdout.on('data', onData);
|
|
123
|
+
child.stderr.on('data', onData);
|
|
124
|
+
let timedOut = false;
|
|
125
|
+
let cancelled = false;
|
|
126
|
+
let spawnError = null;
|
|
127
|
+
let killTimer;
|
|
128
|
+
const kill = (sig) => {
|
|
129
|
+
try {
|
|
130
|
+
if (process.platform !== 'win32' && child.pid)
|
|
131
|
+
process.kill(-child.pid, sig);
|
|
132
|
+
else
|
|
133
|
+
child.kill(sig);
|
|
134
|
+
}
|
|
135
|
+
catch { /* already gone */ }
|
|
136
|
+
};
|
|
137
|
+
const terminate = () => {
|
|
138
|
+
kill('SIGTERM');
|
|
139
|
+
killTimer = setTimeout(() => kill('SIGKILL'), KILL_GRACE_MS);
|
|
140
|
+
killTimer.unref();
|
|
141
|
+
};
|
|
142
|
+
const onAbort = () => {
|
|
143
|
+
cancelled = true;
|
|
144
|
+
terminate();
|
|
145
|
+
};
|
|
146
|
+
if (opts.signal) {
|
|
147
|
+
if (opts.signal.aborted)
|
|
148
|
+
onAbort();
|
|
149
|
+
else
|
|
150
|
+
opts.signal.addEventListener('abort', onAbort, { once: true });
|
|
151
|
+
}
|
|
152
|
+
const timer = opts.timeoutMs
|
|
153
|
+
? setTimeout(() => {
|
|
154
|
+
timedOut = true;
|
|
155
|
+
terminate();
|
|
156
|
+
}, opts.timeoutMs)
|
|
157
|
+
: undefined;
|
|
158
|
+
child.on('error', (e) => {
|
|
159
|
+
spawnError = e.message;
|
|
160
|
+
});
|
|
161
|
+
child.on('close', (code, signal) => {
|
|
162
|
+
if (timer)
|
|
163
|
+
clearTimeout(timer);
|
|
164
|
+
if (killTimer)
|
|
165
|
+
clearTimeout(killTimer);
|
|
166
|
+
opts.signal?.removeEventListener('abort', onAbort);
|
|
167
|
+
let log = opts.redact(Buffer.concat(chunks).toString('utf8'));
|
|
168
|
+
if (truncated)
|
|
169
|
+
log += '\n[buildrush: output truncated at 8 MiB]\n';
|
|
170
|
+
resolve({ exitCode: code, signal, durationMs: Date.now() - start, log, timedOut, cancelled, spawnError });
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
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AC;YAC9D,IAAI,SAAS;gBAAE,GAAG,IAAI,4CAA4C,CAAC;YACnE,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;QAC5G,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type TaskState = 'pending' | 'ready' | 'running' | 'cached' | 'succeeded' | 'failed' | 'cancelled' | 'skipped';
|
|
2
|
+
export type ExecResult = 'succeeded' | 'cached' | 'failed' | 'skipped';
|
|
3
|
+
export interface SchedNode {
|
|
4
|
+
id: string;
|
|
5
|
+
deps: string[];
|
|
6
|
+
/** Resource units this task occupies (clamped to capacity). */
|
|
7
|
+
weight: number;
|
|
8
|
+
/** Historical duration estimate, used for critical-path priority. */
|
|
9
|
+
estimateMs: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ScheduleOptions {
|
|
12
|
+
capacity: number;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
/** Abort everything still running as soon as one task fails. */
|
|
15
|
+
bail?: boolean;
|
|
16
|
+
onState?: (id: string, state: TaskState) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Bounded DAG scheduler. Ready tasks are started highest critical-path first
|
|
20
|
+
* while total running weight stays within `capacity`. A failed task blocks its
|
|
21
|
+
* dependents (state "skipped"); independent branches continue unless `bail`.
|
|
22
|
+
* `exec` may return "skipped" to mean "intentionally nothing to do": that
|
|
23
|
+
* satisfies dependents, unlike a skip caused by an upstream failure.
|
|
24
|
+
*/
|
|
25
|
+
export declare function schedule(nodes: SchedNode[], exec: (id: string, signal: AbortSignal) => Promise<ExecResult>, opts: ScheduleOptions): Promise<Map<string, TaskState>>;
|
|
26
|
+
/** Returns the first dependency cycle found, as a path, or null. */
|
|
27
|
+
export declare function detectCycle(nodes: {
|
|
28
|
+
id: string;
|
|
29
|
+
deps: string[];
|
|
30
|
+
}[]): string[] | null;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded DAG scheduler. Ready tasks are started highest critical-path first
|
|
3
|
+
* while total running weight stays within `capacity`. A failed task blocks its
|
|
4
|
+
* dependents (state "skipped"); independent branches continue unless `bail`.
|
|
5
|
+
* `exec` may return "skipped" to mean "intentionally nothing to do": that
|
|
6
|
+
* satisfies dependents, unlike a skip caused by an upstream failure.
|
|
7
|
+
*/
|
|
8
|
+
export async function schedule(nodes, exec, opts) {
|
|
9
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
10
|
+
for (const n of nodes)
|
|
11
|
+
for (const d of n.deps)
|
|
12
|
+
if (!byId.has(d))
|
|
13
|
+
throw new Error(`task ${n.id} depends on unknown task ${d}`);
|
|
14
|
+
const state = new Map(nodes.map((n) => [n.id, 'pending']));
|
|
15
|
+
const blocked = new Set();
|
|
16
|
+
const set = (id, s) => {
|
|
17
|
+
state.set(id, s);
|
|
18
|
+
opts.onState?.(id, s);
|
|
19
|
+
};
|
|
20
|
+
const dependents = new Map(nodes.map((n) => [n.id, []]));
|
|
21
|
+
for (const n of nodes)
|
|
22
|
+
for (const d of n.deps)
|
|
23
|
+
dependents.get(d).push(n.id);
|
|
24
|
+
const prio = new Map();
|
|
25
|
+
const critical = (id) => {
|
|
26
|
+
const hit = prio.get(id);
|
|
27
|
+
if (hit !== undefined)
|
|
28
|
+
return hit;
|
|
29
|
+
const p = byId.get(id).estimateMs + Math.max(0, ...dependents.get(id).map(critical));
|
|
30
|
+
prio.set(id, p);
|
|
31
|
+
return p;
|
|
32
|
+
};
|
|
33
|
+
const ctl = new AbortController();
|
|
34
|
+
const onExternalAbort = () => ctl.abort();
|
|
35
|
+
if (opts.signal) {
|
|
36
|
+
if (opts.signal.aborted)
|
|
37
|
+
ctl.abort();
|
|
38
|
+
else
|
|
39
|
+
opts.signal.addEventListener('abort', onExternalAbort, { once: true });
|
|
40
|
+
}
|
|
41
|
+
const capacity = Math.max(1, opts.capacity);
|
|
42
|
+
let used = 0;
|
|
43
|
+
const running = new Map();
|
|
44
|
+
const satisfied = (id) => {
|
|
45
|
+
const s = state.get(id);
|
|
46
|
+
return s === 'succeeded' || s === 'cached' || (s === 'skipped' && !blocked.has(id));
|
|
47
|
+
};
|
|
48
|
+
const start = (id) => {
|
|
49
|
+
const w = Math.min(capacity, byId.get(id).weight);
|
|
50
|
+
used += w;
|
|
51
|
+
set(id, 'running');
|
|
52
|
+
const p = (async () => {
|
|
53
|
+
let r;
|
|
54
|
+
try {
|
|
55
|
+
r = await exec(id, ctl.signal);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
r = 'failed';
|
|
59
|
+
}
|
|
60
|
+
used -= w;
|
|
61
|
+
running.delete(id);
|
|
62
|
+
if (ctl.signal.aborted && r === 'failed')
|
|
63
|
+
set(id, 'cancelled');
|
|
64
|
+
else
|
|
65
|
+
set(id, r);
|
|
66
|
+
if (r === 'failed' && opts.bail)
|
|
67
|
+
ctl.abort();
|
|
68
|
+
})();
|
|
69
|
+
running.set(id, p);
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
for (;;) {
|
|
73
|
+
// Propagate failures to dependents and cancel everything when aborted.
|
|
74
|
+
let changed = true;
|
|
75
|
+
while (changed) {
|
|
76
|
+
changed = false;
|
|
77
|
+
for (const n of nodes) {
|
|
78
|
+
const s = state.get(n.id);
|
|
79
|
+
if (s !== 'pending' && s !== 'ready')
|
|
80
|
+
continue;
|
|
81
|
+
if (ctl.signal.aborted) {
|
|
82
|
+
set(n.id, 'cancelled');
|
|
83
|
+
changed = true;
|
|
84
|
+
}
|
|
85
|
+
else if (n.deps.some((d) => ['failed', 'cancelled'].includes(state.get(d)) || blocked.has(d))) {
|
|
86
|
+
blocked.add(n.id);
|
|
87
|
+
set(n.id, 'skipped');
|
|
88
|
+
changed = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const ready = nodes
|
|
93
|
+
.filter((n) => state.get(n.id) === 'pending' || state.get(n.id) === 'ready')
|
|
94
|
+
.filter((n) => n.deps.every(satisfied))
|
|
95
|
+
.sort((a, b) => critical(b.id) - critical(a.id) || (a.id < b.id ? -1 : 1));
|
|
96
|
+
for (const n of ready)
|
|
97
|
+
if (state.get(n.id) === 'pending')
|
|
98
|
+
set(n.id, 'ready');
|
|
99
|
+
for (const n of ready) {
|
|
100
|
+
const w = Math.min(capacity, n.weight);
|
|
101
|
+
if (used > 0 && used + w > capacity)
|
|
102
|
+
continue;
|
|
103
|
+
start(n.id);
|
|
104
|
+
}
|
|
105
|
+
if (running.size === 0)
|
|
106
|
+
break;
|
|
107
|
+
await Promise.race(running.values());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
opts.signal?.removeEventListener('abort', onExternalAbort);
|
|
112
|
+
}
|
|
113
|
+
return state;
|
|
114
|
+
}
|
|
115
|
+
/** Returns the first dependency cycle found, as a path, or null. */
|
|
116
|
+
export function detectCycle(nodes) {
|
|
117
|
+
const deps = new Map(nodes.map((n) => [n.id, n.deps]));
|
|
118
|
+
const mark = new Map();
|
|
119
|
+
const stack = [];
|
|
120
|
+
const visit = (id) => {
|
|
121
|
+
if (mark.get(id) === 2)
|
|
122
|
+
return null;
|
|
123
|
+
if (mark.get(id) === 1)
|
|
124
|
+
return [...stack.slice(stack.indexOf(id)), id];
|
|
125
|
+
mark.set(id, 1);
|
|
126
|
+
stack.push(id);
|
|
127
|
+
for (const d of deps.get(id) ?? []) {
|
|
128
|
+
const c = visit(d);
|
|
129
|
+
if (c)
|
|
130
|
+
return c;
|
|
131
|
+
}
|
|
132
|
+
stack.pop();
|
|
133
|
+
mark.set(id, 2);
|
|
134
|
+
return null;
|
|
135
|
+
};
|
|
136
|
+
for (const n of nodes) {
|
|
137
|
+
const c = visit(n.id);
|
|
138
|
+
if (c)
|
|
139
|
+
return c;
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/scheduler.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,KAAkB,EAClB,IAA8D,EAC9D,IAAqB;IAErB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,4BAA4B,CAAC,EAAE,CAAC,CAAC;IAE9H,MAAM,KAAK,GAAG,IAAI,GAAG,CAAoB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAC9E,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,CAAY,EAAE,EAAE;QACvC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACjB,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACxB,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAmB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAA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AE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAiB,CAAC;IACtC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAmB,EAAE;QAC5C,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACpC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;YAAE,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YACnC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC;gBAAE,OAAO,CAAC,CAAC;QAClB,CAAC;QACD,KAAK,CAAC,GAAG,EAAE,CAAC;QACZ,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACtB,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { DepGraph } from './graph.js';
|
|
2
|
+
/**
|
|
3
|
+
* Per-test-file result caching ("testCache"). A test file may be skipped only when a prior PASSING run
|
|
4
|
+
* recorded exactly the same key. The key covers:
|
|
5
|
+
* - the test file's own content digest and the digests of its whole transitive import closure;
|
|
6
|
+
* - every global configuration file (package.json, lockfiles, tsconfig, vitest/vite config, .env, ...);
|
|
7
|
+
* - the task command, cwd, declared env (secret values are HMAC'd by the engine, never stored) and toolchain.
|
|
8
|
+
* A test whose closure contains ANY uncertain import (non-literal dynamic loading, unresolved import,
|
|
9
|
+
* import.meta.glob, ...) has no key and always runs: it may depend on files the graph cannot see.
|
|
10
|
+
*/
|
|
11
|
+
export interface TestKey {
|
|
12
|
+
/** null = never cacheable (see reason). */
|
|
13
|
+
key: string | null;
|
|
14
|
+
reason: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface TestCacheReport {
|
|
17
|
+
/** Test files not executed because an identical earlier run passed. */
|
|
18
|
+
skipped: {
|
|
19
|
+
test: string;
|
|
20
|
+
reason: string;
|
|
21
|
+
}[];
|
|
22
|
+
/** Test files executed, with why. */
|
|
23
|
+
ran: {
|
|
24
|
+
test: string;
|
|
25
|
+
reason: string;
|
|
26
|
+
}[];
|
|
27
|
+
/** Number of passing results recorded after this run. */
|
|
28
|
+
recorded: number;
|
|
29
|
+
}
|
|
30
|
+
export interface KeyBase {
|
|
31
|
+
task: string;
|
|
32
|
+
command: string[];
|
|
33
|
+
cwd: string;
|
|
34
|
+
env: Record<string, string | null>;
|
|
35
|
+
toolchain: Record<string, string | null>;
|
|
36
|
+
}
|
|
37
|
+
/** Digest of every global configuration file in the index plus the task-level key components. */
|
|
38
|
+
export declare function baseDigest(base: KeyBase, files: ReadonlyMap<string, {
|
|
39
|
+
digest: string;
|
|
40
|
+
}>): string;
|
|
41
|
+
export declare function computeKeys(graph: DepGraph, files: ReadonlyMap<string, {
|
|
42
|
+
digest: string;
|
|
43
|
+
}>, tests: string[], baseHash: string): Map<string, TestKey>;
|
|
44
|
+
interface Rec {
|
|
45
|
+
test: string;
|
|
46
|
+
at: number;
|
|
47
|
+
durationMs: number;
|
|
48
|
+
}
|
|
49
|
+
export declare class TestResultStore {
|
|
50
|
+
private readonly file;
|
|
51
|
+
private data;
|
|
52
|
+
constructor(file: string);
|
|
53
|
+
load(): Promise<void>;
|
|
54
|
+
has(key: string): Rec | null;
|
|
55
|
+
knowsTest(test: string): boolean;
|
|
56
|
+
add(key: string, rec: Rec): void;
|
|
57
|
+
save(): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export declare function storePath(stateDir: string, task: string): string;
|
|
60
|
+
export {};
|