Files
vibe-kanban/scripts/cargo.js
Solomon dc008b70ca perf: Share Cargo build cache across git worktrees (#60)
Use a common target directory for all worktrees to avoid recompiling the backend in every worktree directory.
2025-07-07 15:27:00 +01:00

32 lines
1.0 KiB
JavaScript

#!/usr/bin/env node
/**
* Drop-in replacement for the `cargo` binary.
* If CARGO_TARGET_DIR is already set we leave it alone.
* Otherwise we compute a path that is the same for every git-worktree:
* <main-clone-root>/target
*
* Usage : node scripts/cargo.js <cargo-subcommand> […]
* NPM : "backend:build": "node scripts/cargo.js build --release …"
*/
const { spawnSync, execSync } = require('node:child_process');
const path = require('node:path');
function sharedTarget() {
try {
// Works in any work-tree folder
const common = execSync('git rev-parse --git-common-dir', { encoding: 'utf8' }).trim();
return path.resolve(common, '..', 'target');
} catch {
return undefined; // not a git repo? -> let Cargo use ./target
}
}
const env = { ...process.env };
if (!env.CARGO_TARGET_DIR) {
const dir = sharedTarget();
if (dir) env.CARGO_TARGET_DIR = dir;
}
const result = spawnSync('cargo', process.argv.slice(2), { stdio: 'inherit', env });
process.exitCode = result.status;