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

@baphy/npm

v1.2.0

Published

Detect whether a GitHub repository is a monorepo by analyzing its git tree

Readme

@baphy/npm

Detect whether a repository is a monorepo by analyzing its git tree

npm version npm downloads bundle size CI license TypeScript


Overview

@baphy/npm receives a flat list of file paths from any git tree source and tells you:

  • isMonoRepo — whether the repository is a monorepo
  • packages — the list of detected packages, each with the path to its package.json
  • truncated — whether the source truncated the tree (passed through from your input)

Platform-agnostic — works with GitHub, GitLab, Bitbucket, or any other source. Map your data to a string[] of paths before calling.

Zero dependencies · Synchronous · O(n) · < 7ms on a 100k-entry tree

Installation

npm install @baphy/npm

Usage

import { detectMonoRepo } from '@baphy/npm'

// Map your source data to a string[] of paths, then call detectMonoRepo.
// The second argument mirrors any truncation flag from your source (optional, defaults to false).

// GitHub example:
// GET /repos/{owner}/{repo}/git/trees/{sha}?recursive=1
const gitTree = await fetch(url, { headers }).then(r => r.json())
const result = detectMonoRepo(
  gitTree.tree.map((item: { path: string }) => item.path),
  gitTree.truncated,
)

console.log(result)
// {
//   isMonoRepo: true,
//   packages: [
//     { path: 'packages/turbo',        packageJsonPath: 'packages/turbo/package.json' },
//     { path: 'packages/create-turbo', packageJsonPath: 'packages/create-turbo/package.json' },
//     ...
//   ],
//   truncated: false
// }

Fetching package names (GitHub example)

The packageJsonPath field lets you retrieve each package's metadata with a second API call:

const { packages } = detectMonoRepo(
  gitTree.tree.map((item: { path: string }) => item.path),
  gitTree.truncated,
)

const details = await Promise.all(
  packages.map(async (pkg) => {
    const res = await fetch(
      `https://api.github.com/repos/{owner}/{repo}/contents/${pkg.packageJsonPath}`,
      { headers: { Authorization: `Bearer ${token}` } }
    )
    const { content } = await res.json()
    const { name, version, private: isPrivate } = JSON.parse(
      Buffer.from(content, 'base64').toString()
    )
    return { ...pkg, name, version, isPrivate }
  })
)

API

detectMonoRepo(paths, truncated?)

function detectMonoRepo(paths: string[], truncated?: boolean): MonoRepoResult

Parameters

| Parameter | Type | Default | Description | | --- | --- | --- | --- | | paths | string[] | — | Flat list of file paths from any git tree source | | truncated | boolean | false | Pass through the truncation flag from your source |

Returns

interface MonoRepoResult {
  isMonoRepo: boolean
  packages: MonoRepoPackage[]
  /** true when the source truncated the tree — results may be incomplete */
  truncated: boolean
}

interface MonoRepoPackage {
  /** Directory path, e.g. "." or "packages/npm" */
  path: string
  /** Path to the package.json for this package */
  packageJsonPath: string
}

When isMonoRepo is false, packages still includes the root package if a root package.json exists:

detectMonoRepo(['package.json', 'src/index.ts'])
// {
//   isMonoRepo: false,
//   packages: [{ path: '.', packageJsonPath: 'package.json' }],
//   truncated: false
// }

When truncated is true, the tree was cut short before all files were returned. A false isMonoRepo may not be reliable. Always check truncated before acting on the result.

Types

import type { MonoRepoPackage, MonoRepoResult } from '@baphy/npm'

Detection Strategy

| Tool | Indicator file(s) | Signal | |---|---|---| | pnpm workspaces | pnpm-workspace.yaml · pnpm-workspace.yml | Definitive | | Lerna | lerna.json | Definitive | | Nx | nx.json | Definitive | | Rush | rush.json | Definitive | | Moon | .moon/workspace.yml | Definitive | | npm / yarn workspaces | (inferred — content not readable from tree) | Structural | | Turborepo | turbo.json | Soft |

Definitive — file presence alone confirms a monorepo, even if no packages are discovered.

Soft — turbo.json can exist in single-package repos; treated as definitive only when workspace packages are also found.

Structural — when none of the config files above are present but more than one package.json is found exactly one level deep inside packages/, apps/, libs/, services/, tools/, or plugins/, a monorepo is inferred (the workspaces field in the root package.json cannot be read from the git tree).

Performance

Benchmarked with vitest bench on a 100,000-entry tree (GitHub's maximum non-truncated response):

| Tree size | Mean time | |---|---| | 100 items | ~0.005 ms | | 1,000 items | ~0.056 ms | | 10,000 items | ~0.61 ms | | 100,000 items | ~6.7 ms |

The single-pass O(n) algorithm scales linearly with tree size. Reproduce locally:

npm run bench

License

MIT © pilmee