ngast
raw JSON → 0.6.2 verified Fri May 01 auth: no javascript
ngast is a library providing a user-friendly API for parsing Angular projects by abstracting over the Angular compiler. The current stable version is 0.6.2, built on top of Ivy (ngtsc) and requiring TypeScript ~4.0.0. Key differentiators: it offers a high-level interface to analyze Angular workspaces, methods like getAllComponents() and getAllModules(), and integrates with tools like ngrev and codelyzer. The analysis is slow (>10 sec for small projects). Release cadence is low; previous version 0.4.0 used the older ViewEngine.
Common errors
error Error: Can't resolve '@angular/compiler' ↓
cause Missing @angular/compiler as a dependency.
fix
npm install @angular/compiler --save
error TypeError: ngast_1.WorkspaceSymbols is not a constructor ↓
cause Using require instead of import for the ES module.
fix
Use 'import { WorkspaceSymbols } from 'ngast' instead of require.
error Error: getAllComponents is not a function ↓
cause Calling getUserComponents() or similar wrong method name.
fix
Use workspace.getAllComponents().
Warnings
breaking Version 0.5+ is built on Ivy (ngtsc) and is incompatible with ViewEngine (ngc). Previous version 0.4.0 used ViewEngine. ↓
fix Upgrade your Angular project to use Ivy and run ngcc before using ngast 0.5+.
gotcha First analysis is very slow: >10 seconds for small projects, >2 minutes for large projects. Subsequent calls are cached but still slow. ↓
fix Be patient; consider using a progress indicator. Avoid calling getAll* multiple times unnecessarily.
gotcha Requires TypeScript ~4.0.0 and tslib ^2.0.0 as peer dependencies. Using a different TypeScript version may cause errors. ↓
fix Ensure your project uses TypeScript 4.0.x and tslib 2.x.
deprecated ngast 0.4.0 (ViewEngine) is deprecated and no longer maintained. Users on Angular versions prior to Ivy should stay on that version. ↓
fix Update to ngast 0.6.2 and upgrade Angular to version 9+ with Ivy enabled.
Install
npm install ngast yarn add ngast pnpm add ngast Imports
- WorkspaceSymbols wrong
const WorkspaceSymbols = require('ngast');correctimport { WorkspaceSymbols } from 'ngast'
Quickstart
import { join } from 'path';
import { WorkspaceSymbols } from 'ngast';
const tsconfigPath = join(process.cwd(), 'tsconfig.json');
const workspace = new WorkspaceSymbols(tsconfigPath);
// Wait for first analysis (could take minutes)
const modules = workspace.getAllModules();
console.log('Modules found:', modules.length);
const components = workspace.getAllComponents();
console.log('Components found:', components.length);
const directives = workspace.getAllDirectives();
console.log('Directives found:', directives.length);
const injectables = workspace.getAllInjectable();
console.log('Injectable found:', injectables.length);
const pipes = workspace.getAllPipes();
console.log('Pipes found:', pipes.length);