abcoder-ts-parser
v0.0.30
Published
TypeScript AST parser for UNIAST specification
Readme
TypeScript Parser for ABCoder
A TypeScript AST parser that extracts method calls, variable references, and dependencies with advanced monorepo support and intelligent parsing strategies.
Features
- 🚀 Monorepo Support: Intelligent detection and parsing of monorepo projects
- ⚡ Smart Parsing Strategy: Automatic selection between single-process and cluster-based parsing
- 📦 Multiple Monorepo Formats: Support for Edex, pnpm workspaces, Lerna
- 🎯 Flexible Output Modes: Combined or separate repo output for monorepo packages
Usage
Build: npm run build
Run: node dist/index.js parse [options] <directory>
Parse a TypeScript repository and generate UNIAST JSON
Arguments: directory Directory to parse
Examples
Basic Usage
Parse a single TypeScript project :
node dist/index.js parse ./my-projectParse with pretty output :
node dist/index.js parse ./my-project --prettyParse monorepo with separate package outputs :
node dist/index.js parse ./my-monorepo --monorepo-mode separateParse monorepo (combined output):
node dist/index.js parse ./my-monorepoParse monorepo (separate output for each package):
node dist/index.js parse ./my-monorepo --monorepo-mode separateCustom output path :
node dist/index.js parse ./my-project -o ./output/result.json
Options
| Option | Description | | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | | -o, --output | Output file path (default: "output.json") | | -t, --tsconfig | Path to tsconfig.json file, if you provide a relative path, it will be relative to the directory of the input file (default: "tsconfig.json") | | --no-dist | Ignore dist folder and its contents | | --pretty | Pretty print JSON output | | --src | Directory paths to include (comma-separated) | | --monorepo-mode | Monorepo output mode: "combined" (entire repository) or "separate" (each package) (default: "combined") | | -h, --help | display help for command |
See ./index.ts for more information.
Monorepo Support
The parser automatically detects and supports various monorepo configurations:
- Eden Monorepo: Supports both
packagesformat andworkspacesformat - pnpm Workspaces: Reads
pnpm-workspace.yamlconfiguration - Lerna: Detects
lerna.jsonconfiguration
Parsing Strategies
The parser intelligently selects the optimal parsing strategy based on project size:
- Single Process Mode: For small to medium projects
- Cluster Mode: For large projects with parallel processing across multiple CPU cores
Notes
MUST correctly specify the location of the current project's
tsconfig.json.If you provide a relative path to argument
--tsconfig, it will be relative to the directory of the input file.Before usage, please configure the dependencies for your TypeScript project, such as running npm install and setting up cross-package dependencies in monorepo.
For large monorepo projects, the parser will automatically use cluster-based processing to improve performance.
If the repository you're analyzing is too large, you may need to adjust Node.js's maximum memory allocation.
Terminology
Package vs Module: In JavaScript/TypeScript terminology, a "Package" typically refers to an npm package (defined by package.json). However, in our UniAST output, what JavaScript/TypeScript calls a "Package" corresponds to a "Module" in the UniAST structure. This means:
- TypeScript/JavaScript Package (npm package with
package.json) → UniAST Module - TypeScript/JavaScript Module (individual
.ts/.jsfiles) → UniAST Package
This terminology mapping is used consistently throughout the parser to align with the UniAST specification, but it may initially seem counterintuitive to developers familiar with JavaScript/TypeScript conventions.
Some known issues
- When there is a circular dependency, the parser will choose one of the dependencies as the main dependency.
- The parser does not handle dynamic imports.
- The parser does not handle TypeScript decorators.
- For external symbol which has no
.d.tsdeclaration file, the parser will not be able to resolve the symbol.
