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:
@@ -113,15 +113,16 @@ export function warn(message: string): void {
|
||||
/**
|
||||
* Show the "next steps" section after installation
|
||||
*/
|
||||
export function showNextSteps(location: 'global' | 'local'): void {
|
||||
export function showNextSteps(location: 'global' | 'local', useNpx?: boolean): void {
|
||||
console.log();
|
||||
console.log(chalk.bold(' Done!') + ' Restart Claude Code to use CodeGraph.');
|
||||
console.log();
|
||||
|
||||
if (location === 'global') {
|
||||
const cmd = useNpx ? 'npx @colbymchenry/codegraph' : 'codegraph';
|
||||
console.log(chalk.dim(' Quick start:'));
|
||||
console.log(chalk.dim(' cd your-project'));
|
||||
console.log(chalk.cyan(' codegraph init -i'));
|
||||
console.log(chalk.cyan(` ${cmd} init -i`));
|
||||
} else {
|
||||
console.log(chalk.dim(' CodeGraph is ready to use in this project!'));
|
||||
}
|
||||
|
||||
@@ -97,19 +97,29 @@ function writeJsonFile(filePath: string, data: Record<string, any>): void {
|
||||
atomicWriteFileSync(filePath, JSON.stringify(data, null, 2) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* When true, all configs use `npx @colbymchenry/codegraph` instead of the
|
||||
* bare `codegraph` command. Set by the installer when global install fails.
|
||||
*/
|
||||
let useNpxFallback = false;
|
||||
|
||||
export function setUseNpxFallback(value: boolean): void {
|
||||
useNpxFallback = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MCP server configuration for the given location
|
||||
*/
|
||||
function getMcpServerConfig(location: InstallLocation): Record<string, any> {
|
||||
if (location === 'global') {
|
||||
// Global: use 'codegraph' command directly (assumes globally installed)
|
||||
if (location === 'global' && !useNpxFallback) {
|
||||
// Global: use 'codegraph' command directly (globally installed and in PATH)
|
||||
return {
|
||||
type: 'stdio',
|
||||
command: 'codegraph',
|
||||
args: ['serve', '--mcp'],
|
||||
};
|
||||
}
|
||||
// Local: use npx to run the package
|
||||
// Local or npx fallback: use npx to run the package
|
||||
return {
|
||||
type: 'stdio',
|
||||
command: 'npx',
|
||||
@@ -212,7 +222,7 @@ export function hasPermissions(location: InstallLocation): boolean {
|
||||
* Stop → sync-if-dirty (sync, ensures fresh index before next user turn)
|
||||
*/
|
||||
function getHooksConfig(location: InstallLocation): Record<string, any> {
|
||||
const command = location === 'global' ? 'codegraph' : 'npx @colbymchenry/codegraph';
|
||||
const command = (location === 'global' && !useNpxFallback) ? 'codegraph' : 'npx @colbymchenry/codegraph';
|
||||
|
||||
return {
|
||||
PostToolUse: [
|
||||
@@ -229,6 +239,7 @@ function getHooksConfig(location: InstallLocation): Record<string, any> {
|
||||
],
|
||||
Stop: [
|
||||
{
|
||||
matcher: '.*',
|
||||
hooks: [
|
||||
{
|
||||
type: 'command',
|
||||
|
||||
+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