or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdconfiguration.mdindex.mdlist-generation.mdtree-analysis.md
tile.json

cli.mddocs/

Command Line Interface

The dependency-tree CLI provides a command-line interface for analyzing dependency trees from the terminal. It supports both object tree and list output formats with integration for various build tool configurations.

Installation

Install globally to use the CLI:

npm install -g dependency-tree

Or use with npx:

npx dependency-tree [options] <filename>

Command Syntax

dependency-tree [options] <filename>

Arguments

  • filename (required): Path to the entry point file to analyze

Options

-d, --directory <path>        Location of files of supported filetypes
-c, --require-config <path>   Path to a RequireJS config file  
-w, --webpack-config <path>   Path to a Webpack config file
-t, --ts-config <path>        Path to a TypeScript config file
--list-form                   Output the list form (one element per line)
-h, --help                    Display help information
-V, --version                 Output version number

Usage Examples

Basic Tree Analysis

dependency-tree -d ./src ./src/app.js

Output (JSON format):

{
  "/absolute/path/to/src/app.js": {
    "/absolute/path/to/src/utils.js": {},
    "/absolute/path/to/src/config.js": {
      "/absolute/path/to/src/constants.js": {}
    }
  }
}

List Format Output

dependency-tree --list-form -d ./src ./src/app.js

Output (one file per line):

/absolute/path/to/src/utils.js
/absolute/path/to/src/constants.js
/absolute/path/to/src/config.js
/absolute/path/to/src/app.js

TypeScript Project

dependency-tree -d ./src -t ./tsconfig.json ./src/main.ts

RequireJS Project

dependency-tree -d ./js -c ./require.config.js ./js/app.js

Webpack Project

dependency-tree -d ./src -w ./webpack.config.js ./src/index.js

Output Formats

JSON Tree Format (Default)

The default output is a JSON representation of the dependency tree:

{
  "/path/to/entry.js": {
    "/path/to/dependency1.js": {
      "/path/to/subdependency.js": {}
    },
    "/path/to/dependency2.js": {}
  }
}

List Format

With --list-form, outputs one file path per line in dependency order:

/path/to/subdependency.js
/path/to/dependency1.js
/path/to/dependency2.js
/path/to/entry.js

Integration Examples

Build Scripts

Add to package.json scripts:

{
  "scripts": {
    "deps": "dependency-tree -d ./src ./src/index.js",
    "deps-list": "dependency-tree --list-form -d ./src ./src/index.js",
    "deps-ts": "dependency-tree -d ./src -t ./tsconfig.json ./src/main.ts"
  }
}

Shell Scripting

#!/bin/bash

# Get dependency list for bundling
DEPS=$(dependency-tree --list-form -d ./src ./src/app.js)

# Process each dependency
while IFS= read -r file; do
    echo "Processing: $file"
    # Add your processing logic here
done <<< "$DEPS"

Makefile Integration

ENTRY_FILE = ./src/index.js
SRC_DIR = ./src

.PHONY: deps
deps:
	dependency-tree -d $(SRC_DIR) $(ENTRY_FILE)

.PHONY: bundle
bundle:
	dependency-tree --list-form -d $(SRC_DIR) $(ENTRY_FILE) | \
	xargs cat > dist/bundle.js

Advanced Usage

Complex Project Structure

# Analyze with multiple configuration files
dependency-tree \
  -d ./src \
  -w ./webpack.config.js \
  -t ./tsconfig.json \
  ./src/main.ts

Output Redirection

# Save tree to file
dependency-tree -d ./src ./src/app.js > dependency-tree.json

# Save list to file  
dependency-tree --list-form -d ./src ./src/app.js > build-order.txt

Combining with Other Tools

# Count total dependencies
dependency-tree --list-form -d ./src ./src/app.js | wc -l

# Find specific file types in dependencies
dependency-tree --list-form -d ./src ./src/app.js | grep '\.tsx\?$'

# Check for specific patterns
dependency-tree --list-form -d ./src ./src/app.js | grep node_modules

Error Handling

The CLI provides helpful error messages for common issues:

Missing Required Arguments

$ dependency-tree
error: missing required argument 'filename'

Invalid Directory

$ dependency-tree -d ./nonexistent ./src/app.js
# Outputs empty result for non-existent files

Configuration File Issues

$ dependency-tree -w ./invalid-webpack.config.js ./src/app.js
# Uses default resolution when config files are invalid

Exit Codes

  • 0: Success
  • 1: General error (missing arguments, invalid options)
  • 2: File system error (permissions, missing files)

Environment Variables

The CLI respects Node.js debugging environment variables:

# Enable debug output
DEBUG=tree dependency-tree -d ./src ./src/app.js

# Or use Node.js built-in debugging
NODE_DEBUG=tree dependency-tree -d ./src ./src/app.js

Performance Tips

  1. Use specific directories: Narrow down the -d option to the smallest relevant directory
  2. Leverage caching: Multiple runs on the same codebase benefit from file system caching
  3. Filter early: Use build tool configs to exclude unnecessary files
  4. List format: Use --list-form when you don't need the tree structure

Troubleshooting

Common Issues

Empty output: Check that the filename and directory paths are correct and accessible

Missing dependencies: Ensure all configuration files (webpack, tsconfig, etc.) are valid

Slow performance: Consider using more specific directory paths or adding filters via config files