New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

depon

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depon

This library explores and visualizes project dependencies, offering both CLI-based text output and an interactive visualizer for intuitive understanding of file relationships.

latest
Source
npmnpm
Version
0.3.3
Version published
Weekly downloads
254
-28.85%
Maintainers
0
Weekly downloads
 
Created
Source

DePon!!

"DePon!!" is a tool for visualizing the dependencies of JS/TS-based projects. It provides both a CLI and functions.

In the future, it will also offer the feature to visualize dependencies as a graph.

Installation

"DePon!!" can be installed via npm.

# install
npm install depon

or CLI tools are also provided.

# cli
npx depon --help

CLI

The CLI provides the following commands:

  • tree
    • Displays file dependencies in a tree format.
  • list
    • Displays file dependencies in a list format.

Examples targeting ./examples are shown below.

Tree Command

Displays the dependencies of the target file in a tree format.

# input
npx depon tree --target-dir ./examples ./examples/src/index.ts
# output
🌲 Dependency Tree 🌲

✔ Analysis Complete !!

👶 Children Tree 👶
└── examples/src/index.ts
    ├── examples/src/elements/A (depth:1)/index.tsx
    │   ├── examples/src/elements/A (depth:1)/C (depth:2)/index.ts
    │   │   ├── examples/src/elements/A (depth:1)/C (depth:2)/F (depth:3)/index.tsx
    │   │   │   └── examples/src/elements/A (depth:1)/C (depth:2)/F (depth:3)/H (depth: 4)/index.tsx
    │   │   │       └── examples/src/elements/A (depth:1)/C (depth:2)/F (depth:3)/H (depth: 4)/I (depth: 5)/index.tsx
    │   │   └── examples/src/elements/A (depth:1)/C (depth:2)/G (depth:3)/index.tsx
    │   └── examples/src/elements/A (depth:1)/D (depth:2)/index.tsx
    └── examples/src/elements/B (depth:1)/index.tsx
        └── examples/src/elements/B (depth:1)/E (depth:2)/index.tsx

🎅 Parents Tree 🎅
└── examples/src/index.ts
OptionTypeDescriptionDefault Value
target-dir*stringSpecify the target directoryNone
--no-childrenbooleanDo not display child dependenciesfalse
--no-parentsbooleanDo not display parent dependenciesfalse
--absolutestringDisplay as absolute pathsfalse
--depth stringSpecify the depth to search (root is 0)None
--ignore-patterns stringSpecify patterns of files/directories to exclude from analysisNone
--alias-resolver recordIf { "@" : ".", "~" : ".." }, then it would be ~/@/path will be replaced as .././pathNone

List Command

Displays the dependencies of the target file in a list format.

# input
npx depon list --target-dir ./examples ./examples/src/index.ts
# output
📋 Dependency List 📋

✔ Analysis Complete !!

👶 Children List 👶
examples/src/elements/A (depth:1)/index.tsx
examples/src/elements/A (depth:1)/C (depth:2)/index.ts
examples/src/elements/A (depth:1)/C (depth:2)/F (depth:3)/index.tsx
examples/src/elements/A (depth:1)/C (depth:2)/F (depth:3)/H (depth: 4)/index.tsx
examples/src/elements/A (depth:1)/C (depth:2)/F (depth:3)/H (depth: 4)/I (depth: 5)/index.tsx
examples/src/elements/A (depth:1)/C (depth:2)/G (depth:3)/index.tsx
examples/src/elements/A (depth:1)/D (depth:2)/index.tsx
examples/src/elements/B (depth:1)/index.tsx
examples/src/elements/B (depth:1)/E (depth:2)/index.tsx

🎅 Parents List 🎅

OptionTypeDescriptionDefault Value
target-dir*stringSpecify the target directoryNone
--no-childrenbooleanDo not display child dependenciesfalse
--no-parentsbooleanDo not display parent dependenciesfalse
--absolutestringDisplay as absolute pathsfalse
--depth stringSpecify the depth to search (root is 0)None
--ignore-patterns stringSpecify patterns of files/directories to exclude from analysisNone
--alias-resolver recordIf { "@" : ".", "~" : ".." }, then it would be ~/@/path will be replaced as .././pathNone

API

The API provides the following functions under generator and analyzer.

Below is a concrete example.

import {
  genFileRelation,
  getChildrenList,
  getParentsList,
  getChildrenTree,
  getParentsTree,
} from "depon";

const targetDir = "./examples/src";

const fileRelation = genFileRelation({ targetDir });

// Get a list of files that depend on main.tsx
const childrenList = getChildrenList(fileRelation, "main.tsx");
const parentsList = getParentsList(fileRelation, "main.tsx");

// Get a tree of files that depend on main.tsx
const childrenTree = getChildrenTree(fileRelation, "main.tsx");
const parentsTree = getParentsTree(fileRelation, "main.tsx");

genFileRelation

Arguments for genFileRelation

ArgumentTypeDescription
targetDirstringSpecify the target directory
ignorePatternsstring[] (optional)Specify patterns of files/directories to exclude
aliasResolverRecord<string, string> (optional)If { "@" : ".", "~" : ".." }, then it would be ~/@/path will be replaced as .././path.

Return value of genFileRelation

export type ImportType = "import" | "require" | "dynamicImport" | "export";

export type RelationNode = {
  parent: string;
  child: string;
};

export type FileRelationNode = RelationNode & {
  context: {
    importType: ImportType;
    targetType: "file" | "external";
  };
};
TypeDescription
FileRelationNode[]Contains paths of parent and child dependencies

getChildrenList, getParentsList

Arguments for getChildrenList, getParentsList

ArgumentTypeDescription
relationListFileRelationNode[]Specify the return value of genFileRelation
targetKeystringSpecify the target file
depthnumber?Specify the depth to search (root is 0)

Return value of getChildrenList, getParentsList

TypeDescription
{ key:string }[]Array containing paths of related files under key

getChildrenTree, getParentsTree

Arguments for getChildrenTree, getParentsTree

ArgumentTypeDescription
relationListFileRelationNode[]Specify the return value of genFileRelation
targetKeystringSpecify the target file
depthnumber?Specify the depth to search (root is 0)
stopCondition(key, depth) => boolean ?Once the function is true, no further searching is done.

Return value of getChildrenTree, getParentsTree

// Return value of getChildrenTree
type ChildrenTree<T extends RelationNode> = {
  key: string;
  children: ChildrenTree<T>[];
};

// Return value of getParentsTree
type ParentsTree<T extends RelationNode> = {
  key: string;
  parents: ParentsTree<T>[];
};
TypeDescription
ChildrenTree | ParentsTreeHave a recursive structure of related file paths in tree form

Keywords

Depon

FAQs

Package last updated on 20 Dec 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