Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

dependency-tree

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dependency-tree

Get the dependency tree of a module

latest
Source
npmnpm
Version
11.2.0
Version published
Weekly downloads
2M
0.69%
Maintainers
3
Weekly downloads
 
Created

What is dependency-tree?

The dependency-tree npm package is used to generate a dependency tree for a given file or module. It helps in understanding the structure and dependencies of a project by analyzing the import/require statements.

What are dependency-tree's main functionalities?

Generate Dependency Tree

This feature allows you to generate a dependency tree for a specific file within a project. The `filename` parameter specifies the file for which the dependency tree is to be generated, and the `directory` parameter specifies the root directory of the project.

const dependencyTree = require('dependency-tree');
const tree = dependencyTree({
  filename: 'path/to/your/file.js',
  directory: 'path/to/your/project'
});
console.log(tree);

Circular Dependency Detection

This feature helps in detecting circular dependencies within a project. By converting the dependency tree to a list and checking for duplicates, you can identify if there are any circular dependencies.

const dependencyTree = require('dependency-tree');
const hasCircularDeps = dependencyTree.toList({
  filename: 'path/to/your/file.js',
  directory: 'path/to/your/project',
  filter: (path) => path.indexOf('node_modules') === -1
}).some((file, index, allFiles) => allFiles.indexOf(file) !== index);
console.log(hasCircularDeps ? 'Circular dependencies detected' : 'No circular dependencies');

Custom Dependency Filters

This feature allows you to apply custom filters to the dependency tree generation process. For example, you can exclude dependencies from `node_modules` by providing a filter function.

const dependencyTree = require('dependency-tree');
const tree = dependencyTree({
  filename: 'path/to/your/file.js',
  directory: 'path/to/your/project',
  filter: (path) => path.indexOf('node_modules') === -1
});
console.log(tree);

Other packages similar to dependency-tree

Keywords

dependency

FAQs

Package last updated on 19 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts