react-scanner is a static analysis tool designed to extract React component and prop usage from source code, supporting both JavaScript and TypeScript. It operates by crawling a specified directory, identifying relevant files, and then parsing them to build a detailed JSON report of component instances and their associated prop values. The current stable version is 1.2.0, with a history of regular updates indicating active maintenance and feature development. Key differentiators include its static analysis approach, eliminating the need for runtime instrumentation, robust TypeScript support, and a flexible architecture that allows for custom processors to transform the raw JSON output into actionable insights, such as component usage counts or prop value distributions. It is primarily used for understanding the adoption and utilization patterns of design system components within a codebase.
npm install react-scannerVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic use of `react-scanner` to scan a temporary React project and print the raw JSON report. It shows how to configure the scanner with basic options like `rootDir`, `getComponentName`, and `getPropValue` to analyze component and prop usage.
Update your `react-scanner` configuration to include `getComponentName: ({ local }) => local` if you need to replicate the component name extraction logic from versions prior to 0.5.0.Ensure your scanning process handles a non-zero exit code if it's acceptable for no files to be found. Adjust CI/CD scripts to either validate file existence before running the scanner or to explicitly allow a non-zero exit code in this scenario.
Add nullish coalescing or optional chaining (`?.`) when accessing properties within your custom configuration functions, e.g., `value && value.type` or `value?.type`.
Ensure your configuration object explicitly includes a `rootDir` property pointing to the base directory for scanning, e.g., `{ rootDir: './src' }`.No dependency data recorded yet.