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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@11ty/dependency-tree

v3.0.1

Published

Finds all JavaScript CommmonJS require() dependencies from a filename.

Downloads

276,310

Readme

dependency-tree

Returns an unordered array of local paths to dependencies of a CommonJS node JavaScript file (everything it or any of its dependencies requires).

Reduced feature (faster) alternative to the dependency-tree package. This is used by Eleventy to find dependencies of a JavaScript file to watch for changes to re-run Eleventy’s build.

Big Huge Caveat

⚠ A big caveat to this plugin is that it will require the file in order to build a dependency tree. So if your module has side effects and you don’t want it to execute—do not use this!

Installation

npm install --save-dev @11ty/dependency-tree

Features

  • Ignores node_modules
  • Or, use nodeModuleNames to control whether or not node_modules package names are included (added in v2.0.1)
  • Ignores Node’s built-ins (e.g. path)
  • Handles circular dependencies (Node does this too)

Usage

// my-file.js

// if my-local-dependency.js has dependencies, it will include those too
const test = require("./my-local-dependency.js");

// ignored, is a built-in
const path = require("path");
const DependencyTree = require("@11ty/dependency-tree");

DependencyTree("./my-file.js");
// returns ["./my-local-dependency.js"]

allowNotFound

const DependencyTree = require("@11ty/dependency-tree");

DependencyTree("./this-does-not-exist.js"); // throws an error

DependencyTree("./this-does-not-exist.js", { allowNotFound: true });
// returns []

nodeModuleNames

(Added in v2.0.1) Controls whether or not node package names are included in the list of dependencies.

  • nodeModuleNames: "include": included alongside the local JS files.
  • nodeModuleNames: "exclude" (default): node module package names are excluded.
  • nodeModuleNames: "only": only node module package names are returned.
// my-file.js:

require("./my-local-dependency.js");
require("@11ty/eleventy");
const DependencyTree = require("@11ty/dependency-tree");

DependencyTree("./my-file.js");
// returns ["./my-local-dependency.js"]

DependencyTree("./my-file.js", { nodeModuleNames: "exclude" });
// returns ["./my-local-dependency.js"]

DependencyTree("./my-file.js", { nodeModuleNames: "include" });
// returns ["./my-local-dependency.js", "@11ty/eleventy"]

DependencyTree("./my-file.js", { nodeModuleNames: "only" });
// returns ["@11ty/eleventy"]

(Deprecated) nodeModuleNamesOnly

(Added in v2.0.0) Changed to use nodeModuleNames option instead. Backwards compatibility is maintained automatically.

  • nodeModuleNamesOnly: false is mapped to nodeModuleNames: "exclude"
  • nodeModuleNamesOnly: true is mapped to nodeModuleNames: "only"

If both nodeModuleNamesOnly and nodeModuleNames are included in options, nodeModuleNames takes precedence.