{"id":48435225,"url":"https://github.com/makotot/component-env-graph","last_synced_at":"2026-04-06T12:30:31.755Z","repository":{"id":312328132,"uuid":"1047165182","full_name":"makotot/component-env-graph","owner":"makotot","description":"A library to statically analyze component dependencies in a React Server Components (RSC) project and determine their execution environment.","archived":false,"fork":false,"pushed_at":"2026-04-05T13:00:39.000Z","size":137,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-05T15:04:48.063Z","etag":null,"topics":["react","react-server-components","ts-morph","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@makotot/component-env-graph","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/makotot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-08-29T21:10:21.000Z","updated_at":"2026-02-19T14:39:10.000Z","dependencies_parsed_at":"2026-04-05T15:01:33.250Z","dependency_job_id":null,"html_url":"https://github.com/makotot/component-env-graph","commit_stats":null,"previous_names":["makotot/component-env-graph"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/makotot/component-env-graph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makotot%2Fcomponent-env-graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makotot%2Fcomponent-env-graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makotot%2Fcomponent-env-graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makotot%2Fcomponent-env-graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makotot","download_url":"https://codeload.github.com/makotot/component-env-graph/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makotot%2Fcomponent-env-graph/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31473271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T08:36:52.050Z","status":"ssl_error","status_checked_at":"2026-04-06T08:36:51.267Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","react-server-components","ts-morph","typescript"],"created_at":"2026-04-06T12:30:31.670Z","updated_at":"2026-04-06T12:30:31.743Z","avatar_url":"https://github.com/makotot.png","language":"TypeScript","readme":"# Component Env Graph\n\n[![npm version](https://badge.fury.io/js/%40makotot%2Fcomponent-env-graph.svg)](https://badge.fury.io/js/%40makotot%2Fcomponent-env-graph)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA library to statically analyze component dependencies in a React Server Components (RSC) project and determine their execution environment (`client`, `server`, or `universal`).\n\nIt parses your TypeScript/JavaScript project, builds a dependency graph, and classifies each component based on whether it's part of a `\"use client\"` module tree.\n\n## Features\n\n-   **Environment Classification**: Classifies components into `client`, `server`, or `universal`.\n-   **Fast Incremental Updates**: Rebuilds the graph quickly when files change, avoiding full scans.\n-   **TypeScript First**: Heavily relies on [ts-morph](https://ts-morph.com/) for robust static analysis of TypeScript code.\n-   **Customizable**: Allows custom `tsconfig.json` paths and file exclusion patterns.\n\n## Installation\n\n```bash\nnpm install @makotot/component-env-graph\n```\n\nOr with pnpm:\n\n```bash\npnpm add @makotot/component-env-graph\n```\n\n## Basic Usage\n\nThis library is often used with a file watcher like `chokidar` to keep the dependency graph up-to-date as you code.\n\n```typescript\nimport { ComponentEnvGraph } from '@makotot/component-env-graph';\nimport chokidar from 'chokidar';\n\n// 1. Initialize the graph with your project's root directory\nconst graph = new ComponentEnvGraph('/path/to/your/nextjs-project');\n\n// 2. Perform the initial full-scan build\nconsole.log('Building initial dependency graph...');\ngraph.build();\nconsole.log('Initial build complete!');\n\n// 3. Access the analysis results from the `.nodes` property\nconst fileInfo = graph.nodes.get('/path/to/your/nextjs-project/src/app/page.tsx');\nif (fileInfo) {\n    console.log(`page.tsx is a ${fileInfo.type} component.`);\n}\n\n// 4. (Optional) Subscribe to update events\ngraph.onDidUpdate(() =\u003e {\n    console.log('Graph has been updated!');\n    // You can re-render your UI or perform other actions here\n    // e.g., redrawUI(graph.nodes);\n});\n\n// 5. Watch for file changes and perform incremental updates\nconst watcher = chokidar.watch('/path/to/your/nextjs-project/src', {\n    ignored: /node_modules/,\n    persistent: true,\n});\n\nconst handleFileChange = (filePath: string) =\u003e {\n    console.log(`File changed: ${filePath}. Rebuilding graph...`);\n    // Pass an array of changed files to `build()` for a fast incremental update\n    graph.build([filePath]);\n};\n\nwatcher\n    .on('add', handleFileChange)\n    .on('change', handleFileChange)\n    .on('unlink', handleFileChange);\n```\n\n## API Reference\n\n### `new ComponentEnvGraph(rootDir, options?)`\n\nCreates a new graph instance.\n\n-   `rootDir` (string, required): The absolute path to the root of the project to be analyzed.\n-   `options` (object, optional):\n    -   `tsConfigFilePath` (string): Absolute path to a custom `tsconfig.json`. Defaults to `{rootDir}/tsconfig.json`.\n    -   `exclude` (string[]): An array of glob patterns to exclude from the analysis, in addition to the defaults.\n\n### `.build(changedFiles?)`\n\nBuilds or updates the dependency graph.\n\n-   `changedFiles` (string[], optional): An array of absolute paths to files that have been added, changed, or deleted. If provided, performs a fast incremental update. If omitted, performs a full scan of the entire project.\n\n### `.nodes`\n\nA `Map\u003cstring, FileNode\u003e` containing the analysis result for each file in the graph. The key is the absolute file path.\n\nThe `FileNode` object has the following structure:\n\n```typescript\ninterface FileNode {\n    filePath: string;      // Absolute path to the file\n    isClient: boolean;     // True if the file contains a \"use client\" directive\n    imports: string[];     // Array of absolute paths to other files this file imports\n    type?: 'client' | 'server' | 'universal'; // The classified execution environment\n}\n```\n\n### `.onDidUpdate(listener)`\n\nRegisters a callback function to be invoked whenever the graph is updated by the `.build()` method.\n\n-   `listener` (() =\u003e void): The function to call on updates.\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakotot%2Fcomponent-env-graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakotot%2Fcomponent-env-graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakotot%2Fcomponent-env-graph/lists"}