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:
+9
-22
@@ -25,31 +25,18 @@ export async function runInstaller(): Promise<void> {
|
|||||||
showBanner();
|
showBanner();
|
||||||
|
|
||||||
try {
|
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 {
|
try {
|
||||||
const checkCmd = process.platform === 'win32' ? 'where codegraph' : 'command -v codegraph';
|
execSync('npm install -g @colbymchenry/codegraph', { stdio: 'pipe' });
|
||||||
execSync(checkCmd, { stdio: 'pipe' });
|
success('Installed codegraph command globally');
|
||||||
} catch {
|
} catch {
|
||||||
// Not installed globally yet — try to install
|
info('Could not install globally (permission denied)');
|
||||||
console.log(chalk.dim(' Installing codegraph globally...'));
|
info('Try: sudo npm install -g @colbymchenry/codegraph');
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
console.log();
|
||||||
|
|
||||||
// Step 2: Ask for installation location
|
// Step 2: Ask for installation location
|
||||||
const location = await promptInstallLocation();
|
const location = await promptInstallLocation();
|
||||||
|
|||||||
Reference in New Issue
Block a user