fix: Always run npm install -g, skip command -v check

command -v codegraph is unreliable inside npx because npx puts a
temporary binary in PATH. The check always passes, so the global
install is always skipped — which is the root cause of #37 and #38.

Fix: remove the check entirely, always run npm install -g.
This commit is contained in:
Colby McHenry
2026-02-19 15:51:03 -06:00
parent 67f60b9b2f
commit a46d6b7487
+9 -22
View File
@@ -25,31 +25,18 @@ export async function runInstaller(): Promise<void> {
showBanner();
try {
// Step 1: Ensure codegraph is installed globally
// Step 1: Install codegraph globally.
// Always run npm install -g — we can't use `command -v codegraph` to check
// because npx puts a temporary binary in PATH that vanishes when npx exits.
console.log(chalk.dim(' Installing codegraph globally...'));
try {
const checkCmd = process.platform === 'win32' ? 'where codegraph' : 'command -v codegraph';
execSync(checkCmd, { stdio: 'pipe' });
execSync('npm install -g @colbymchenry/codegraph', { stdio: 'pipe' });
success('Installed codegraph command globally');
} catch {
// Not installed globally yet — try to install
console.log(chalk.dim(' Installing codegraph globally...'));
try {
execSync('npm install -g @colbymchenry/codegraph', { stdio: 'pipe' });
// Verify it actually worked (PATH may not include npm global bin)
try {
execSync(process.platform === 'win32' ? 'where codegraph' : 'command -v codegraph', { stdio: 'pipe' });
success('Installed codegraph command globally');
} catch {
// Install "succeeded" but command not in PATH — common with nvm/fnm
info('Global install succeeded but codegraph is not in your PATH');
info('You may need to add npm\'s global bin directory to your PATH');
info('Then restart your terminal and run: codegraph init -i');
}
} catch {
info('Could not install globally (permission denied)');
info('Try: sudo npm install -g @colbymchenry/codegraph');
}
console.log();
info('Could not install globally (permission denied)');
info('Try: sudo npm install -g @colbymchenry/codegraph');
}
console.log();
// Step 2: Ask for installation location
const location = await promptInstallLocation();