CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-loopback--build

A comprehensive set of build tools and configurations for LoopBack 4 and TypeScript projects providing CLI commands for compilation, linting, testing, and coverage

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

file-cleanup.mddocs/

File Cleanup

Utility for safely removing build artifacts and temporary files with glob pattern support and security safeguards.

Capabilities

lb-clean Command

Safely removes files and directories using glob patterns with built-in security checks.

/**
 * File cleanup function with glob pattern support and safety checks
 * @param argv - Command line arguments including file patterns to remove
 * @param options - Execution options for dry run and process control
 * @returns String description of removed files
 */
function clean(argv: string[], options?: RunOptions): string;

CLI Usage:

# Remove build directories
lb-clean dist lib

# Remove with glob patterns
lb-clean "dist/**" "*.tmp"

# Remove multiple patterns
lb-clean dist coverage temp "*.log"

# Common cleanup patterns
lb-clean dist lib coverage *.tsbuildinfo

Programmatic Usage:

import { clean } from "@loopback/build";

// Remove build artifacts
const result = clean(["dist", "lib"]);
console.log(result); // "rm -rf dist lib"

// Dry run to see what would be removed
const dryResult = clean(["dist", "coverage"], { dryRun: true });
console.log(dryResult); // "rm -rf dist coverage"

// Remove files in custom directory
const cleanResult = clean(["build"], { cwd: "/path/to/project" });

Security Safeguards

Built-in protection against accidentally removing files outside the project directory.

// Prevents removal of files outside project root using path traversal (../)
// Skips patterns that resolve outside current working directory
// Logs warning messages for skipped patterns

Security Features:

  • Checks all patterns for path traversal attempts (../)
  • Only removes files within the current working directory
  • Warns when patterns are skipped for security reasons
  • Never follows symbolic links outside the project

Security Examples:

# Safe - removes dist directory in current project
lb-clean dist

# Skipped - would access parent directory
lb-clean ../dist

# Safe - removes nested directories
lb-clean src/temp lib/cache

# Skipped - path traversal attempt
lb-clean "../../system-files"

Glob Pattern Support

Comprehensive glob pattern support for flexible file matching.

interface GlobPatterns {
  "**": "Recursive directory match";
  "*": "Single directory/file wildcard";
  "?": "Single character wildcard";
  "[abc]": "Character set matching";
  "{a,b,c}": "Alternative matching";
  "!pattern": "Negation (not supported in lb-clean)";
}

Pattern Examples:

# Remove all JavaScript files
lb-clean "**/*.js"

# Remove all build artifacts
lb-clean "dist/**" "lib/**" "coverage/**"

# Remove temporary files
lb-clean "*.tmp" "*.log" ".cache"

# Remove TypeScript build info
lb-clean "*.tsbuildinfo" "**/*.tsbuildinfo"

# Remove test artifacts
lb-clean "**/*.test.js.map" "**/coverage-*"

Usage Examples

Basic Cleanup:

import { clean } from "@loopback/build";

// Remove common build directories
const result = clean(["dist", "lib", "coverage"]);

// Remove with glob patterns
const globResult = clean(["dist/**", "*.tsbuildinfo"]);

// Check what would be removed
const dryRun = clean(["temp", "cache"], { dryRun: true });
console.log(`Would execute: ${dryRun}`);

Package.json Integration:

{
  "scripts": {
    "clean": "lb-clean dist lib coverage *.tsbuildinfo",
    "clean:all": "lb-clean dist lib coverage temp cache *.log *.tmp",
    "clean:build": "lb-clean dist lib",
    "clean:coverage": "lb-clean coverage .nyc_output",
    "clean:cache": "lb-clean .cache node_modules/.cache",
    "prebuild": "npm run clean",
    "pretest": "npm run clean && npm run build"
  }
}

Common Cleanup Patterns:

# TypeScript project cleanup
lb-clean dist lib *.tsbuildinfo

# Node.js project cleanup  
lb-clean dist coverage .nyc_output *.log

# Full cleanup (preserve node_modules)
lb-clean dist lib coverage temp .cache *.tmp *.log *.tsbuildinfo

# Cache cleanup
lb-clean .cache .nyc_output coverage

# Development cleanup
lb-clean "**/*.js.map" "**/*.d.ts" "!node_modules/**"

Error Handling and Logging

Comprehensive error handling with informative logging.

// Logs each pattern being processed
// Warns about skipped patterns with reasons
// Reports successful removals
// Handles permission errors gracefully

Error Scenarios:

  • Path traversal: Logs warning and skips pattern
  • Permission denied: Reports error but continues with other patterns
  • File not found: Silent (not an error)
  • Invalid glob pattern: Reports error and skips pattern

Logging Examples:

$ lb-clean dist ../config temp
# Output:
# Skipping ../config as it is not inside the project root directory.
# rm -rf dist temp

Integration with Build Tools

Seamlessly integrates with build processes and development workflows.

Build Process Integration:

{
  "scripts": {
    "prebuild": "lb-clean dist",
    "build": "lb-tsc",
    "postbuild": "lb-clean **/*.tsbuildinfo",
    
    "pretest": "npm run build",
    "test": "lb-mocha dist/__tests__",
    "posttest": "lb-clean .nyc_output",
    
    "prepublishOnly": "npm run clean && npm run build && npm test"
  }
}

Watch Mode Compatibility:

# Safe for watch mode - only removes build outputs
lb-clean dist

# Avoid cleaning source files in watch mode
# Good: lb-clean dist lib
# Bad: lb-clean src (would remove source files)

Performance Considerations

Optimized for performance with large file sets and complex glob patterns.

// Uses rimraf for efficient file removal
// Processes patterns in parallel where safe
// Handles large directory trees efficiently
// Minimizes file system operations

Performance Tips:

  • Use specific patterns instead of broad globs when possible
  • Clean directories rather than individual files when appropriate
  • Combine related patterns in single command
  • Avoid deeply nested recursive patterns when unnecessary

Advanced Usage

Advanced patterns and use cases for complex project structures.

Monorepo Cleanup:

# Clean all package build outputs
lb-clean "packages/*/dist" "packages/*/lib"

# Clean all test artifacts
lb-clean "packages/*/coverage" "**/.nyc_output"

# Clean TypeScript artifacts
lb-clean "**/*.tsbuildinfo" "packages/*/tsconfig.tsbuildinfo"

Conditional Cleanup:

{
  "scripts": {
    "clean:dev": "lb-clean dist coverage .cache",
    "clean:prod": "lb-clean dist lib coverage .nyc_output *.log",
    "clean": "npm run clean:dev"
  }
}

Custom Cleanup Functions:

import { clean } from "@loopback/build";

// Create cleanup utility
function cleanBuildArtifacts() {
  return clean(["dist", "lib", "*.tsbuildinfo"], { dryRun: false });
}

function cleanTestArtifacts() {  
  return clean(["coverage", ".nyc_output"], { dryRun: false });
}

// Use in build scripts
cleanBuildArtifacts();
cleanTestArtifacts();

docs

code-coverage.md

code-formatting.md

code-linting.md

file-cleanup.md

index.md

process-management.md

test-execution.md

typescript-compilation.md

tile.json