npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aiderdesk/tree-sitter-utils

v0.1.0

Published

Tree-sitter utilities for code analysis, symbol extraction, and repository mapping

Downloads

49

Readme

@aiderdesk/tree-sitter-utils

A comprehensive tree-sitter library for code analysis, symbol extraction, and repository mapping.

Features

  • 🌳 Tree-Sitter Based: Uses tree-sitter for accurate AST parsing
  • 📦 On-Demand WASM Loading: Automatically downloads language WASM files when needed
  • 🔍 Symbol Extraction: Extract functions, classes, variables, and other symbols from code
  • 🗺️ Repository Mapping: Generate comprehensive repository maps with PageRank-based symbol ranking
  • 💾 Smart Caching: SQLite-based caching for fast repeated analysis
  • 🌐 Multi-Language Support: Supports 18+ programming languages out of the box

Installation

npm install @aiderdesk/tree-sitter-utils

Quick Start

Extract Symbols from Files

import { extractSymbols } from '@aiderdesk/tree-sitter-utils';

const symbols = await extractSymbols([
  '/path/to/file.ts',
  '/path/to/another-file.py'
]);

console.log(symbols);
// [
//   { name: 'MyClass', kind: 'def', line: 10, rel_fname: 'file.ts', ... },
//   { name: 'myFunction', kind: 'def', line: 25, rel_fname: 'file.ts', ... }
// ]

Generate Repository Map

import { getRepoMap } from '@aiderdesk/tree-sitter-utils';

const map = await getRepoMap('/path/to/project', {
  maxLines: 1000,
  excludePatterns: ['node_modules/**', 'dist/**']
});

console.log(map);
// src/index.ts:
// ├── class MyClass
// ├── function myFunction
// ...

Advanced Usage with TreeSitterAnalyzer

import { TreeSitterAnalyzer } from '@aiderdesk/tree-sitter-utils';

const analyzer = new TreeSitterAnalyzer();

// Initialize (optional - lazy initialization supported)
await analyzer.initialize();

// Get repository map
const repoMap = await analyzer.getRepoMap('/path/to/project', {
  maxLines: 500,
  mentionedFiles: new Set(['src/important.ts']),
  mentionedIdents: new Set(['ImportantClass'])
});

// Extract symbols
const symbols = await analyzer.extractSymbols(['/path/to/file.ts'], {
  useCache: true
});

// Parse single file
const parseResult = await analyzer.parseFile('/path/to/file.ts');

Supported Languages

  • Python
  • JavaScript / JSX
  • TypeScript / TSX
  • Java
  • Go
  • Rust
  • C / C++
  • C#
  • Ruby
  • PHP
  • Scala
  • Dart
  • OCaml / OCaml Interface
  • Haskell
  • Julia

Configuration Options

RepoMapOptions

interface RepoMapOptions {
  root: string;                    // Root directory of the project
  files?: string[];                // Specific files to analyze (optional)
  excludePatterns?: string[];      // Glob patterns to exclude
  mentionedFiles?: Set<string>;    // Files to prioritize in ranking
  mentionedIdents?: Set<string>;   // Identifiers to prioritize
  chatFiles?: Set<string>;         // Files to exclude from output
  maxLines?: number;               // Maximum lines in output
}

SymbolOptions

interface SymbolOptions {
  useCache?: boolean;              // Use SQLite cache (default: true)
  rootDir?: string;                // Root directory for relative paths
}

How It Works

  1. On-Demand WASM Loading: When a language is first encountered, the library automatically downloads its WASM file from unpkg and caches it in ~/.cache/aiderdesk/tree-sitter/wasm/

  2. Tree-Sitter Parsing: Uses tree-sitter queries (.scm files) to extract definitions and references from source code

  3. PageRank Algorithm: Builds a dependency graph and applies PageRank to rank symbols by importance

  4. Smart Caching: SQLite-based caching tracks file modification times to avoid re-parsing unchanged files

API Reference

Convenience Functions

  • extractSymbols(filePaths: string[], options?: SymbolOptions): Promise<Symbol[]>
  • getRepoMap(root: string, options?: RepoMapOptions): Promise<string>

TreeSitterAnalyzer Class

  • initialize(): Promise<void> - Initialize the analyzer
  • getRepoMap(options: RepoMapOptions): Promise<string> - Generate repository map
  • extractSymbols(filePaths: string[], options?: SymbolOptions): Promise<Symbol[]> - Extract symbols
  • parseFile(filePath: string): Promise<ParseResult> - Parse single file

License

MIT