or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Workspace Dependency Analyzer

Build a command-line tool that analyzes project dependencies in an Nx workspace and provides insights about the dependency structure.

Requirements

Your tool should:

  1. Load and analyze the Nx workspace project graph
  2. Identify all projects that depend on a specified target project
  3. Detect and report any circular dependencies in the workspace
  4. Calculate and display the total number of direct dependencies for a given project
  5. Export the full project graph to a JSON file for external analysis

The tool should accept a project name as a command-line argument and output:

  • A list of all projects that depend on the specified project (reverse dependencies)
  • Whether the specified project is part of any circular dependency chains
  • The count of direct dependencies for the specified project
  • Confirmation that the full graph has been exported to workspace-graph.json

Dependencies { .dependencies }

@nx/devkit { .dependency }

Provides workspace analysis and project graph utilities.

Test Cases

  • Given project "shared-ui" with dependents ["app-admin", "app-portal"], the tool lists both projects as dependents @test
  • Given a workspace with a circular dependency between "lib-a" and "lib-b", the tool detects and reports the circular dependency @test
  • Given project "core-utils" with 3 direct dependencies, the tool reports the count as 3 @test
  • After running the tool, a file named "workspace-graph.json" exists and contains valid project graph data @test

Implementation

@generates

API

/**
 * Analyzes dependencies for a given project in the Nx workspace
 * @param projectName - The name of the project to analyze
 * @returns Analysis results including dependents, circular dependencies, and dependency count
 */
export async function analyzeProject(projectName: string): Promise<{
  dependents: string[];
  hasCircularDependency: boolean;
  directDependencyCount: number;
}>;

/**
 * Exports the full project graph to a JSON file
 * @param outputPath - Path where the graph JSON should be written
 * @returns Promise that resolves when export is complete
 */
export async function exportProjectGraph(outputPath: string): Promise<void>;

/**
 * Main entry point for the CLI tool
 * @param args - Command line arguments
 */
export async function main(args: string[]): Promise<void>;