Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dependency-tree

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dependency-tree

Utilities for interacting with the dependency tree of a module

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1M
increased by3.1%
Maintainers
1
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

FAQs

Package last updated on 24 Nov 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc