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

@itrocks/dependency

v0.0.6

Published

Builds a dependency-sorted list of Nodes.js modules

Downloads

43

Readme

npm version npm downloads GitHub issues discord

dependency

Builds a dependency-sorted list of Nodes.js modules.

This documentation was written by an artificial intelligence and may contain errors or approximations. It has not yet been fully reviewed by a human. If anything seems unclear or incomplete, please feel free to contact the author of this package.

Installation

npm i @itrocks/dependency

This package is meant to be used in a Node.js environment. It scans the installed modules starting from a given directory and returns their names ordered so that every package appears after all its dependencies.

Usage

@itrocks/dependency exposes a single async helper: dependencies.

It inspects the installed packages (those visible from the given directory) and builds a list of package names sorted in dependency order. If a cyclic dependency is detected, the function rejects with an error describing the cycle.

By default, it starts from the application directory detected by @itrocks/app-dir, so in many cases you can simply call it without arguments.

Minimal example

import { dependencies } from '@itrocks/dependency'

async function main ()
{
	const ordered = await dependencies()

	console.log('Packages in dependency order:')
	for (const name of ordered) {
		console.log(' -', name)
	}
}

main().catch((error) => {
	console.error('Unable to compute dependencies:', error)
	process.exitCode = 1
})

Complete example – running tasks in dependency order

The typical use‑case is to perform some work (build, migration, initialisation, checks, …) module by module, while ensuring that each module is processed after all the modules it depends on.

import { dependencies } from '@itrocks/dependency'
import { spawn }        from 'node:child_process'
import { promisify }    from 'node:util'

const spawnAsync = promisify(spawn)

async function runBuildsInOrder ()
{
	// Compute the list of installed packages in dependency order
	const ordered = await dependencies() // starts from your app directory

	for (const pkg of ordered) {
		// Here we arbitrarily decide to run an npm script on each package.
		// You could instead require a file, run database migrations, etc.
		console.log('Building', pkg)
		await spawnAsync('npm', ['run', 'build', '--workspace', pkg], {
			stdio: 'inherit',
		})
	}
}

runBuildsInOrder().catch((error) => {
	console.error('Build aborted because of dependency issue:', error)
	process.exitCode = 1
})

In the example above, @itrocks/dependency is responsible only for the ordering. What you actually do with each package (npm run build, custom scripts, migrations, checks, …) is entirely up to your application.

API

dependencies(path?: string): Promise<string[]>

Builds and returns a list of installed packages ordered so that each package appears after all of its dependencies.

The function looks at the packages that are installed under the provided path (or the application directory if omitted) and analyses their dependencies declared in package.json.

Parameters

  • path (optional) – base directory from which installed packages are discovered. It should normally be the root of your application or workspace (where node_modules can be resolved). If not provided, the default application directory from @itrocks/app-dir is used.

Return value

Returns a Promise that resolves to an array of package names (string[]).

The order guarantees that, whenever package A depends on package B, B appears before A in the resulting array.

Errors

The Promise is rejected in particular when:

  • a cyclic dependency is detected between some of the installed packages. The error message lists the packages involved in the cycle;
  • an underlying error occurs while listing installed packages (filesystem access problems, invalid package.json, etc.).

You should treat any rejection as a signal that the dependency graph of the current installation is not valid for ordered processing.

Typical use cases

  • Running build scripts for a set of internal packages in a dependency‑safe order.
  • Applying database migrations or initialisation scripts for feature modules whose code is distributed across several packages.
  • Generating documentation or reports that need to aggregate information from each package only after its dependencies have been analysed.
  • Checking for dependency graph issues in a project (for example as part of a CI step that fails when cycles are introduced).
  • Implementing custom orchestration tools for monorepos or modular backends without writing your own dependency‑resolution logic.