or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-del-cli

Cross-platform command-line tool for deleting files and directories using glob patterns with safety features.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/del-cli@6.0.x

To install, run

npx @tessl/cli install tessl/npm-del-cli@6.0.0

index.mddocs/

del-cli

del-cli is a cross-platform command-line tool for safely deleting files and directories using glob patterns. It provides a safer alternative to rm -rf and rimraf with built-in protection against deleting parent directories, dry-run capabilities, and comprehensive glob pattern support including Windows compatibility.

Package Information

  • Package Name: del-cli
  • Package Type: npm
  • Language: JavaScript (ES Modules)
  • Installation: npm install --global del-cli
  • Node.js Requirements: >=18
  • Module Type: ES Modules ("type": "module")
  • Side Effects: None

Core Imports

This is a CLI tool that provides binary commands rather than importable modules. The tool is built on the del npm package for programmatic deletion functionality:

// For programmatic usage, use the underlying del package directly:
const { deleteAsync } = require('del');
// or
import { deleteAsync } from 'del';

Binary Commands

The tool provides two binary commands:

del-cli <path|glob> ...
del <path|glob> ...    # Alias (conflicts with Windows built-in del command)

Basic Usage

# Delete specific files
del-cli file.txt another-file.js

# Delete using glob patterns
del-cli "*.log" "temp/**/*.tmp"

# Preview deletions without actually deleting
del-cli --dry-run "*.cache"

# Delete with verbose output
del-cli --verbose --force "build/**"

# Exclude specific patterns
del-cli "*.png" "!important.png"

Architecture

del-cli is built around several key components:

  • CLI Interface: Built with meow package for argument parsing and help text
  • Deletion Engine: Uses the del package for actual file system operations
  • Progress Monitoring: Hooks into del's onProgress callback for verbose output
  • Safety Layer: Built-in protections against deleting parent directories
  • Cross-platform Support: Consistent glob pattern handling across all platforms

Capabilities

Command-Line Interface

Provides a complete CLI for deleting files and directories with glob pattern support.

// CLI Command Structure
interface DelCliCommand {
  command: 'del-cli' | 'del';
  arguments: string[];  // Array of path/glob patterns
  flags: {
    force?: boolean;    // -f, --force
    dryRun?: boolean;   // -d, --dry-run
    verbose?: boolean;  // -v, --verbose
  };
}

// Exit Codes
interface ExitCodes {
  SUCCESS: 0;           // Successful operation
  INPUT_ERROR: 1;       // No paths specified
  SYSTEM_ERROR: number; // File system errors
}

// Output Formats
interface OutputBehavior {
  verbose: {            // When --verbose flag is used
    existingFile: string;    // Prints absolute file path
    nonExistingFile: '';     // No output
  };
  dryRun: string[];          // Array of files that would be deleted
  normal: void;              // Silent operation
}

File and Directory Deletion

Deletes files and directories using glob patterns with cross-platform compatibility and safety features.

// Primary deletion function (CLI interface)
function delCli(
  patterns: string[],           // Array of glob patterns/file paths (minimum 1 required)
  options: {
    force?: boolean;            // Allow deleting CWD and outside directories
    dryRun?: boolean;           // Preview mode - list files without deleting
    verbose?: boolean;          // Show real-time deletion progress
  }
): Promise<string[]>;           // Returns array of deleted file paths

// Usage examples:
// del-cli "*.png" "!important.png" --dry-run
// del-cli --force --verbose "build/**"

Arguments:

  • patterns (string[], required): One or more file paths or glob patterns to delete

Glob Pattern Support:

  • Standard wildcards: *, **, ?
  • Exclusion patterns: !pattern
  • Cross-platform compatibility including Windows
  • Examples:
    • *.png - All PNG files in current directory
    • **/*.log - All log files recursively
    • "*.tmp" "!important.tmp" - All tmp files except important.tmp

Force Mode

Allows deletion of the current working directory and files outside the current directory.

interface ForceMode {
  flag: '--force' | '-f';
  behavior: {
    allowCurrentDirectory: boolean;    // Can delete current working directory
    allowOutsideDirectory: boolean;    // Can delete files outside CWD
    bypassSafetyChecks: boolean;      // Disables built-in protections
  };
}

// Usage: del-cli --force <path|glob> ...
// Usage: del-cli -f <path|glob> ...

Safety Note: Use with caution as this bypasses built-in safety protections.

Dry Run Mode

Lists what would be deleted without actually performing the deletion.

interface DryRunMode {
  flag: '--dry-run' | '-d';
  behavior: {
    deletesFiles: false;                  // No actual deletion performed
    outputFormat: 'newline-separated';    // One file path per line
    returnValue: string[];                // Array of file paths that would be deleted
  };
}

// Usage: del-cli --dry-run <path|glob> ...
// Usage: del-cli -d <path|glob> ...

Output: Prints the full paths of files that would be deleted, one per line to stdout.

Verbose Mode

Displays the absolute path of files and directories as they are deleted.

interface VerboseMode {
  flag: '--verbose' | '-v';
  behavior: {
    showProgress: boolean;           // Real-time deletion feedback
    outputTarget: 'stdout';          // Outputs to standard output
    pathFormat: 'absolute';          // Full absolute file paths
    timing: 'real-time';            // Shows paths as files are processed  
  };
  
  outputBehavior: {
    existingFile: (path: string) => void;     // Prints absolute path
    nonExistingFile: () => void;              // No output
  };
}

// Usage: del-cli --verbose <path|glob> ...
// Usage: del-cli -v <path|glob> ...

Output: Shows real-time feedback of deletion operations with absolute file paths to stdout.

Safety Features

Built-in Protections

  • Parent Directory Protection: Prevents deletion of parent directories by default
  • Current Directory Protection: Requires --force flag to delete current working directory
  • Outside Directory Protection: Requires --force flag to delete files outside current directory

Preview and Verification

  • Dry Run Mode: Test glob patterns before actual deletion with --dry-run
  • Verbose Output: Monitor exactly which files are being processed with --verbose
  • Glob Pattern Validation: Invalid patterns are handled gracefully

Error Handling

Input Validation

interface InputValidation {
  requiredArguments: {
    minimum: 1;                    // At least one path/glob pattern required
    errorMessage: 'Specify at least one path';
    exitCode: 1;
  };
  
  patternValidation: {
    handler: 'del-package';        // Handled by underlying del package
    globEngine: boolean;           // Uses glob pattern matching
    crossPlatform: boolean;        // Works on Windows, macOS, Linux
  };
  
  permissionHandling: {
    fileSystemErrors: 'standard';  // Standard Node.js file system errors
    displayToUser: boolean;        // Error messages shown to user
  };
}

Exit Codes

interface ExitCodes {
  SUCCESS: 0;                    // Deletion completed successfully or dry-run finished
  INPUT_ERROR: 1;                // No path arguments provided
  SYSTEM_ERROR: number;          // File system operation errors (from del package)
}

// Error conditions that trigger exit code 1:
// - Command executed with no path/glob arguments
// - Displays "Specify at least one path" to stderr

Platform Compatibility

Windows Considerations

  • Command Conflict: Windows has a built-in del command, use del-cli instead
  • Glob Support: Full glob pattern support despite Windows limitations
  • Path Handling: Automatic path separator normalization

Cross-Platform Features

  • Consistent Behavior: Identical functionality across Linux, macOS, and Windows
  • Unicode Support: Handles international file names correctly
  • Path Separators: Automatic handling of different path separator conventions

Common Usage Patterns

Build Script Cleanup

# Clean build artifacts
del-cli "dist/**" "*.tsbuildinfo" "coverage/**"

# Clean with safety check
del-cli --dry-run "node_modules/**/.cache/**"

Development Workflow

# Remove temporary files
del-cli "**/*.tmp" "**/*.log" "**/.DS_Store"

# Clean specific file types
del-cli "**/*.{tmp,log,cache}" "!important.log"

Advanced Operations

# Force delete with verbose output
del-cli --force --verbose "**/.git/**" 

# Preview complex patterns
del-cli --dry-run "src/**/*.{js,ts}" "!src/**/*.test.{js,ts}"

Comparison with Alternatives

vs rimraf CLI

  • ✅ Cross-platform glob support (including Windows)
  • ✅ Built-in parent directory protection
  • ✅ Dry-run mode for testing patterns
  • ✅ Verbose output for monitoring

vs rm -rf

  • ✅ Cross-platform compatibility
  • ✅ Glob pattern support without shell expansion issues
  • ✅ Built-in safety protections
  • ✅ Dry-run testing capability