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

dependencies-tree

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dependencies-tree

Collect dependencies from package.json

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
69
decreased by-2.82%
Maintainers
0
Weekly downloads
 
Created
Source

dependencies-tree

Collect dependencies from package.json

Install

npm i dependencies-tree

Usage

import getDependencies from 'dependencies-tree'

const { tree, flat } = await getDependencies()

API (Define)

export interface DependenciesOptions {
  /** @default process.cwd() */
  root?: string
  /** `dependencies` in package.json under the default root path */
  dependencies?: string[]
}

Example

Assume there is a dependency electron-squirrel-startup in package.json.

{
  "dependencies": {
    "electron-squirrel-startup": "^1.0.0"
  }
}

We get the dependency tree based on the path where package.json is located.

import getDependencies from 'dependencies-tree'

const root = process.cwd()
const { tree } = await getDependencies({ root })

console.log(tree)

// ↓↓↓↓

[
  {
    name: 'electron-squirrel-startup',
    path: {
      src: path.join(fixtureRoot, 'node_modules', 'electron-squirrel-startup'),
      dest: path.join('node_modules', 'electron-squirrel-startup'),
      name: 'electron-squirrel-startup',
    },
    dependencies: [
      {
        name: 'debug',
        path: {
          src: path.join(fixtureRoot, 'node_modules', 'debug'),
          dest: path.join('node_modules', 'debug'),
          name: 'debug',
        },
        dependencies: [
          {
            name: 'ms',
            path: {
              src: path.join(fixtureRoot, 'node_modules', 'ms'),
              dest: path.join('node_modules', 'ms'),
              name: 'ms',
            },
            dependencies: [],
          },
        ],
      },
    ],
  },
]

Get the flat dependency tree

import getDependencies from 'dependencies-tree'

const root = process.cwd()
const { flat } = await getDependencies({ root })

console.log(falg)

// ↓↓↓↓

[
  {
    src: path.join(fixtureRoot, 'node_modules', 'electron-squirrel-startup'),
    dest: path.join('node_modules', 'electron-squirrel-startup'),
    name: 'electron-squirrel-startup',
  },
  {
    src: path.join(fixtureRoot, 'node_modules', 'debug'),
    dest: path.join('node_modules', 'debug'),
    name: 'debug',
  },
  {
    src: path.join(fixtureRoot, 'node_modules', 'ms'),
    dest: path.join('node_modules', 'ms'),
    name: 'ms',
  },
]

FAQs

Package last updated on 25 Sep 2024

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