Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
component-usage-analyzer
Advanced tools
這是一個用於分析 React/TypeScript 專案中元件依賴關係和使用情況的工具。它可以幫助你:
npm install component-usage-analyzer
// ESM
import { createAnalyzer } from 'component-usage-analyzer';
// CommonJS
const { createAnalyzer } = require('component-usage-analyzer');
// 使用預設配置建立分析器
const analyzer = createAnalyzer();
// 執行分析
analyzer.run();
// 生成 Markdown 報告
analyzer.generateMarkDown();
// 生成依賴樹圖
analyzer.generateDependencyTree();
你可以透過傳入配置物件來自定義分析器的行為:
interface ComponentPathConfig {
path: string; // 元件目錄路徑
importPrefix: string; // import 語句的前綴
}
const analyzer = createAnalyzer({
name: 'Component', // 分析報告的標題名稱
targetPath: 'src/components', // 要分析的元件目錄
pagesPath: 'src/pages', // 頁面檔案目錄
fileExtensions: ['.tsx'], // 要分析的檔案副檔名
componentPaths: [ // 元件搜尋路徑配置
{
path: 'src/components',
importPrefix: '@/components'
},
{
path: 'src/elements',
importPrefix: '@/elements'
}
],
outputDir: 'tools/usageAnalyzer', // 輸出目錄
exportNamePattern: /^[A-Z]/, // 元件名稱匹配模式(預設匹配大寫開頭)
});
工具內建以下預設配置:
const defaultConfig = {
name: 'Component',
targetPath: 'src/components',
pagesPath: 'src/pages',
fileExtensions: ['.tsx'],
componentPaths: [
{
path: 'src/components',
importPrefix: '@/components'
},
{
path: 'src/elements',
importPrefix: '@/elements'
}
],
outputDir: 'tools/usageAnalyzer',
exportNamePattern: /^[A-Z]/,
};
# Component Dependencies and Usage
- Button (src/components/Button.tsx)
Dependencies:
- @/elements/Icon (src/elements/Icon.tsx)
Imports: Icon
Used in pages:
- src/pages/home.tsx
- src/pages/about.tsx
- Card (src/components/Card.tsx)
Dependencies:
- @/components/Button (src/components/Button.tsx)
Imports: Button
Used in pages:
- src/pages/products.tsx
工具會生成一個使用 Mermaid 語法的依賴樹圖,可以直接在支援 Mermaid 的 Markdown 檢視器中顯示(如 GitHub)。
flowchart TD
Button["Button"]
Card["Card"]
Icon["Icon"]
Button --> Icon
Card --> Button
Button --> page_home["home"]
Button --> page_about["about"]
Card --> page_products["products"]
.tsx
檔案的分析,可透過配置擴展支援其他檔案類型MIT
FAQs
分析 React 元件使用情況的工具
We found that component-usage-analyzer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.