Add WASM fallbacks for tree-sitter and SQLite, fix installer
Replace native tree-sitter with web-tree-sitter + tree-sitter-wasms for universal cross-platform support. Add node-sqlite3-wasm as a fallback when better-sqlite3 native bindings aren't available. Move better-sqlite3 and sqlite-vss to optionalDependencies so installs never fail. Fix installer to use npx fallback when global npm install fails, so MCP config, hooks, and quick-start instructions all work without the bare codegraph command in PATH. Fix tests: update schema version expectation, fix db test paths and method names, extract MAX_OUTPUT_LENGTH as module constant, normalize Windows path separators in import resolver.
This commit is contained in:
+24
-5
@@ -8,8 +8,7 @@
|
||||
import { execSync } from 'child_process';
|
||||
import { showBanner, showNextSteps, success, error, info, chalk } from './banner';
|
||||
import { promptInstallLocation, promptAutoAllow, InstallLocation } from './prompts';
|
||||
import { writeMcpConfig, writePermissions, writeClaudeMd, writeHooks, hasMcpConfig, hasPermissions, hasHooks } from './config-writer';
|
||||
import CodeGraph from '../index';
|
||||
import { writeMcpConfig, writePermissions, writeClaudeMd, writeHooks, hasMcpConfig, hasPermissions, hasHooks, setUseNpxFallback } from './config-writer';
|
||||
|
||||
/**
|
||||
* Format a number with commas
|
||||
@@ -29,7 +28,8 @@ export async function runInstaller(): Promise<void> {
|
||||
// Step 1: Check if codegraph is available (skip install if already there)
|
||||
let codegraphAvailable = false;
|
||||
try {
|
||||
execSync('which codegraph', { stdio: 'pipe' });
|
||||
const checkCmd = process.platform === 'win32' ? 'where codegraph' : 'command -v codegraph';
|
||||
execSync(checkCmd, { stdio: 'pipe' });
|
||||
codegraphAvailable = true;
|
||||
} catch {
|
||||
// Not installed globally yet
|
||||
@@ -40,13 +40,20 @@ export async function runInstaller(): Promise<void> {
|
||||
try {
|
||||
execSync('npm install -g @colbymchenry/codegraph', { stdio: 'pipe' });
|
||||
success('Installed codegraph command globally');
|
||||
codegraphAvailable = true;
|
||||
} catch {
|
||||
// May fail if no permissions, but that's ok - npx still works
|
||||
info('Could not install globally (try with sudo if needed)');
|
||||
info('Could not install globally — will use npx instead');
|
||||
info('(MCP server and hooks will use npx @colbymchenry/codegraph)');
|
||||
}
|
||||
console.log();
|
||||
}
|
||||
|
||||
// If codegraph binary isn't in PATH, tell config-writer to use npx for everything
|
||||
if (!codegraphAvailable) {
|
||||
setUseNpxFallback(true);
|
||||
}
|
||||
|
||||
// Step 2: Ask for installation location
|
||||
const location = await promptInstallLocation();
|
||||
console.log();
|
||||
@@ -104,7 +111,7 @@ export async function runInstaller(): Promise<void> {
|
||||
}
|
||||
|
||||
// Show next steps
|
||||
showNextSteps(location);
|
||||
showNextSteps(location, !codegraphAvailable);
|
||||
} catch (err) {
|
||||
console.log();
|
||||
if (err instanceof Error && err.message.includes('readline was closed')) {
|
||||
@@ -123,6 +130,18 @@ export async function runInstaller(): Promise<void> {
|
||||
async function initializeLocalProject(): Promise<void> {
|
||||
const projectPath = process.cwd();
|
||||
|
||||
// Lazy-load CodeGraph (requires native modules)
|
||||
let CodeGraph: typeof import('../index').default;
|
||||
try {
|
||||
CodeGraph = (await import('../index')).default;
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
error(`Could not load native modules: ${msg}`);
|
||||
info('Skipping project initialization. You can run "codegraph init -i" later.');
|
||||
info('If this persists, try a Node.js LTS version (20 or 22).');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if already initialized
|
||||
if (CodeGraph.isInitialized(projectPath)) {
|
||||
info('CodeGraph already initialized in this project');
|
||||
|
||||
Reference in New Issue
Block a user