or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Node Modules Cleanup CLI

Build a command-line tool that cleans up redundant packages from node_modules directories in pnpm-managed projects.

Requirements

Your CLI should accept the following command-line arguments:

  • <project-path> - Path to the project directory (required, positional argument)
  • --dry-run - Simulate the operation without making actual changes (optional flag)

Functionality

The tool should:

  1. Accept a project directory path as the first argument
  2. Read the project's lockfile state (both wanted and current lockfiles)
  3. Execute a pruning operation to identify and remove redundant packages
  4. Display the number of packages processed for removal
  5. When --dry-run is specified, only simulate the operation without making changes

Expected Behavior

  • Exit with code 0 on successful completion
  • Exit with non-zero code if the project directory is invalid or errors occur
  • Print clear output indicating the number of packages affected

Test Cases

  • When executed with a valid project path, it successfully prunes redundant packages and outputs the count @test
  • When executed with the --dry-run flag, it simulates the operation without modifying files @test
  • When given an invalid project directory, it exits with an error code @test

Implementation

@generates

API

/**
 * Main CLI entry point
 * Parses command-line arguments and executes the cleanup operation
 */
function main(): Promise<void>;

/**
 * Executes the pruning operation for a given project directory
 * @param projectPath - Path to the project directory
 * @param dryRun - If true, simulate without making changes
 * @returns The number of packages processed
 */
function cleanupProject(projectPath: string, dryRun: boolean): Promise<number>;

Dependencies { .dependencies }

@pnpm/modules-cleaner { .dependency }

Provides the core pruning functionality to remove redundant packages from node_modules.

@pnpm/lockfile.fs { .dependency }

Handles reading and parsing of pnpm lockfiles.

@pnpm/store-controller-types { .dependency }

Provides type definitions for store controller operations.