Registry
Ccodemod avatar

codemod/mine-react-components

Read-only React component inventory for Insights dashboards across JavaScript and TypeScript codebases

codemod2 executions

  • react
  • component-inventory
  • insights
  • metrics
  • analysis
Connect a repo
npx codemod @codemod/mine-react-components

@codemod/mine-react-components

Read-only React component inventory for Insights dashboards.

Installation

bash
# Install from registry
codemod run @codemod/mine-react-components

# Or run locally
codemod run -w workflow.yaml

Usage

This package scans .js, .jsx, .ts, and .tsx source files and emits metrics for React component definitions. It does not rewrite source files.

Default workflow step: detect-react-components

Included files:

  • **/*.{js,jsx,ts,tsx}

Default exclusions:

  • **/node_modules/**
  • **/dist/**
  • **/build/**
  • **/coverage/**
  • **/.next/**
  • **/out/**
  • **/storybook-static/**
  • **/__generated__/**
  • **/generated/**
  • **/*.generated.*

Detection heuristics:

  • PascalCase function declarations that return JSX
  • PascalCase arrow functions assigned to identifiers that return JSX
  • PascalCase function expressions assigned to identifiers that return JSX
  • Class components extending React.Component, Component, React.PureComponent, or PureComponent with a render() method that returns JSX
  • Wrapped component declarations such as memo(...), forwardRef(...), React.memo(...), React.forwardRef(...), and other wrapper calls when the wrapped value resolves to a JSX-returning component

Preserve and no-op cases:

  • Lowercase helpers without a wrapped component shape are ignored
  • Hooks such as useThing are ignored unless they are defined through a wrapped component declaration like memo(...)
  • Utilities and classes without React inheritance are ignored

Metrics

Workflow step name: detect-react-components

Metric: react-component-definition

Cardinality keys:

  • componentName: Component identifier, or anonymous when no safe name is available
  • componentKind: function, arrow-function, function-expression, class, memo, forwardRef, or wrapped
  • exported: true or false
  • defaultExport: true or false
  • fileExtension: js, jsx, ts, or tsx

Insights Queries

Example package-source query:

json
{
  "packageId": "@codemod/mine-react-components",
  "packageVersionId": "<package-version-id>",
  "stepName": "detect-react-components",
  "select": {
    "type": "metric",
    "metricName": "react-component-definition"
  }
}

Example widgets:

  1. Total React components
json
{
  "packageId": "@codemod/mine-react-components",
  "packageVersionId": "<package-version-id>",
  "stepName": "detect-react-components",
  "select": {
    "type": "metric",
    "metricName": "react-component-definition"
  }
}
  1. Components by kind
json
{
  "packageId": "@codemod/mine-react-components",
  "packageVersionId": "<package-version-id>",
  "stepName": "detect-react-components",
  "select": {
    "type": "metric",
    "metricName": "react-component-definition"
  },
  "groupBy": [{ "name": "cardinality", "key": "componentKind" }]
}
  1. Components by repository
json
{
  "packageId": "@codemod/mine-react-components",
  "packageVersionId": "<package-version-id>",
  "stepName": "detect-react-components",
  "select": {
    "type": "metric",
    "metricName": "react-component-definition"
  },
  "groupBy": [{ "name": "repository" }]
}
  1. Components by directory depth 2
json
{
  "packageId": "@codemod/mine-react-components",
  "packageVersionId": "<package-version-id>",
  "stepName": "detect-react-components",
  "select": {
    "type": "metric",
    "metricName": "react-component-definition"
  },
  "groupBy": [{ "name": "directory", "depth": 2 }]
}
  1. Exported vs non-exported components
json
{
  "packageId": "@codemod/mine-react-components",
  "packageVersionId": "<package-version-id>",
  "stepName": "detect-react-components",
  "select": {
    "type": "metric",
    "metricName": "react-component-definition"
  },
  "groupBy": [{ "name": "cardinality", "key": "exported" }]
}
  1. Components by file extension
json
{
  "packageId": "@codemod/mine-react-components",
  "packageVersionId": "<package-version-id>",
  "stepName": "detect-react-components",
  "select": {
    "type": "metric",
    "metricName": "react-component-definition"
  },
  "groupBy": [{ "name": "cardinality", "key": "fileExtension" }]
}

Development

bash
# Run fixtures and metrics snapshots
pnpm test

# Update fixture snapshots
pnpm test:update

# Validate the package
codemod workflow validate -w workflow.yaml
codemod package validate

# Publish to registry
codemod login
codemod publish

License

MIT

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.