npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@makotot/component-env-graph

v0.1.11

Published

A library to statically analyze component dependencies in a React Server Components (RSC) project and determine their execution environment.

Readme

Component Env Graph

npm version License: MIT

A library to statically analyze component dependencies in a React Server Components (RSC) project and determine their execution environment (client, server, or universal).

It 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.

Features

  • Environment Classification: Classifies components into client, server, or universal.
  • Fast Incremental Updates: Rebuilds the graph quickly when files change, avoiding full scans.
  • TypeScript First: Heavily relies on ts-morph for robust static analysis of TypeScript code.
  • Customizable: Allows custom tsconfig.json paths and file exclusion patterns.

Installation

npm install @makotot/component-env-graph

Or with pnpm:

pnpm add @makotot/component-env-graph

Basic Usage

This library is often used with a file watcher like chokidar to keep the dependency graph up-to-date as you code.

import { ComponentEnvGraph } from '@makotot/component-env-graph';
import chokidar from 'chokidar';

// 1. Initialize the graph with your project's root directory
const graph = new ComponentEnvGraph('/path/to/your/nextjs-project');

// 2. Perform the initial full-scan build
console.log('Building initial dependency graph...');
graph.build();
console.log('Initial build complete!');

// 3. Access the analysis results from the `.nodes` property
const fileInfo = graph.nodes.get('/path/to/your/nextjs-project/src/app/page.tsx');
if (fileInfo) {
    console.log(`page.tsx is a ${fileInfo.type} component.`);
}

// 4. (Optional) Subscribe to update events
graph.onDidUpdate(() => {
    console.log('Graph has been updated!');
    // You can re-render your UI or perform other actions here
    // e.g., redrawUI(graph.nodes);
});

// 5. Watch for file changes and perform incremental updates
const watcher = chokidar.watch('/path/to/your/nextjs-project/src', {
    ignored: /node_modules/,
    persistent: true,
});

const handleFileChange = (filePath: string) => {
    console.log(`File changed: ${filePath}. Rebuilding graph...`);
    // Pass an array of changed files to `build()` for a fast incremental update
    graph.build([filePath]);
};

watcher
    .on('add', handleFileChange)
    .on('change', handleFileChange)
    .on('unlink', handleFileChange);

API Reference

new ComponentEnvGraph(rootDir, options?)

Creates a new graph instance.

  • rootDir (string, required): The absolute path to the root of the project to be analyzed.
  • options (object, optional):
    • tsConfigFilePath (string): Absolute path to a custom tsconfig.json. Defaults to {rootDir}/tsconfig.json.
    • exclude (string[]): An array of glob patterns to exclude from the analysis, in addition to the defaults.

.build(changedFiles?)

Builds or updates the dependency graph.

  • 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.

.nodes

A Map<string, FileNode> containing the analysis result for each file in the graph. The key is the absolute file path.

The FileNode object has the following structure:

interface FileNode {
    filePath: string;      // Absolute path to the file
    isClient: boolean;     // True if the file contains a "use client" directive
    imports: string[];     // Array of absolute paths to other files this file imports
    type?: 'client' | 'server' | 'universal'; // The classified execution environment
}

.onDidUpdate(listener)

Registers a callback function to be invoked whenever the graph is updated by the .build() method.

  • listener (() => void): The function to call on updates.

License

MIT