Static analysis library that extracts prop metadata from React component files using the TypeScript compiler.
Without @auto-engineer/component-parser, you would have to manually inspect React component source files to determine their prop names, types, default values, and descriptions -- or write your own ts-morph traversal logic to extract that information.
pnpm add @auto-engineer/component-parserimport { createProject, parseComponentFile } from '@auto-engineer/component-parser';
const project = createProject('./tsconfig.json');
const components = parseComponentFile(project, '/absolute/path/to/Button.tsx');
for (const component of components) {
console.log(component.name); // "Button"
console.log(component.description); // JSDoc description, if present
for (const prop of component.props) {
console.log(prop.name, prop.type, prop.required, prop.defaultValue);
}
}When you have a list of relative component paths (e.g., from a project manifest), use parseManifestComponents to parse them all at once with automatic deduplication:
import { createProject, parseManifestComponents } from '@auto-engineer/component-parser';
const project = createProject('./tsconfig.json');
const paths = ['./components/Button.tsx', './components/Card.tsx'];
const components = parseManifestComponents(project, paths, process.cwd());The parser automatically excludes standard HTML props (e.g., className, onClick, children) from results. It does this by resolving all props of React.ComponentProps<"div"> and subtracting them. Only custom props defined by the component author appear in the output.
If you need the raw HTML prop set for other purposes:
import { createProject, buildHtmlPropSet } from '@auto-engineer/component-parser';
const project = createProject('./tsconfig.json');
const htmlProps: Set<string> = buildHtmlPropSet(project);If you already have a ts-morph Type object and a set of HTML props to exclude, use resolveCustomProps:
import { resolveCustomProps } from '@auto-engineer/component-parser';
const props = resolveCustomProps(paramType, htmlProps, defaults);Creates a ts-morph Project from a tsconfig.json path. All other functions require this project instance.
Parses a single .tsx file and returns metadata for every exported React component (identified as functions with a capitalized name and at least one parameter).
parseManifestComponents(project: Project, componentPaths: string[], projectRoot: string): ParsedComponent[]
Parses multiple component files from a list of relative paths, resolving them against projectRoot. Deduplicates paths so each file is only parsed once.
Returns the full set of standard HTML div element prop names (from React.ComponentProps<"div">). Results are cached per project instance.
Walks a ts-morph Type and returns all properties that are not in htmlProps, enriched with default values and JSDoc descriptions.
Extracts default values from destructured parameters in a function declaration. Returns a map of parameter name to default value text.
type ParsedComponent = {
name: string;
filePath: string;
props: PropInfo[];
description?: string;
};
type PropInfo = {
name: string;
type: string;
required: boolean;
defaultValue?: string;
description?: string;
};The package is a pipeline of small, composable functions built on top of ts-morph:
createProject
└─> parseComponentFile (or parseManifestComponents)
├─> buildHtmlPropSet — resolves standard HTML props to exclude
├─> extractDefaults — reads destructured default values from the function signature
└─> resolveCustomProps — walks the props type, subtracts HTML props, attaches defaults and JSDoc
The only runtime dependency is ts-morph. The HTML prop set is cached per Project instance using a WeakMap to avoid repeated type resolution.