CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-gulp-rimraf

rimraf plugin for gulp that provides a transform stream for deleting files and directories within gulp build pipelines

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

Gulp Rimraf

Gulp Rimraf is a gulp plugin that wraps the rimraf library to enable file and directory deletion within gulp build pipelines. It creates a transform stream that processes vinyl files and safely removes corresponding files and folders from the filesystem, with built-in safety features to prevent deletion of files outside the current working directory unless explicitly forced.

Package Information

  • Package Name: gulp-rimraf
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install gulp-rimraf

Core Imports

const rimraf = require('gulp-rimraf');

ES modules:

import rimraf from 'gulp-rimraf';

Basic Usage

const gulp = require('gulp');
const rimraf = require('gulp-rimraf');

// Basic usage - delete files with default settings
gulp.task('clean', function() {
  return gulp.src('./build/**/*', { read: false })
    .pipe(rimraf());
});

// With options - enable verbose logging
gulp.task('clean-verbose', function() {
  return gulp.src('./temp/**/*', { read: false })
    .pipe(rimraf({ verbose: true }));
});

// Force deletion outside current working directory
gulp.task('clean-external', function() {
  return gulp.src('../temp/*.tmp', { read: false })
    .pipe(rimraf({ force: true }));
});

Capabilities

Rimraf Stream Creation

Creates a gulp-compatible transform stream for file and directory deletion.

/**
 * Creates a transform stream that deletes files and directories from the filesystem
 * based on vinyl file paths from gulp.src()
 * @param {RimrafOptions} [options] - Configuration options for the deletion operation
 * @returns {through2.Transform} A through2 object stream compatible with gulp pipelines
 */
function rimraf(options);

Configuration Options

Options object for controlling rimraf behavior.

interface RimrafOptions {
  /**
   * Allow deletion of files outside current working directory
   * @default false
   */
  force?: boolean;
  
  /**
   * Enable verbose logging to console for each deleted file/directory
   * @default false
   */
  verbose?: boolean;
}

Types

// Return type from through2 package
interface through2.Transform extends stream.Transform {
  // Transform stream for processing vinyl file objects
  // Inherits all standard Node.js Transform stream methods
}

Safety Features

Path Protection

  • Current Working Directory Protection: Cannot delete the current working directory
  • Path Traversal Protection: By default, cannot delete files outside current working directory without force: true option
  • Path Resolution: Always resolves paths to prevent relative path confusion

Error Handling

The stream emits error events in the following cases:

  1. Attempting to delete current working directory: Emits error with message "Cannot delete the current working directory: {path}"
  2. Attempting to delete files outside CWD without force: Emits error with message "Cannot delete files or folders outside the current working directory: {path}"
  3. Filesystem errors: Passes through any errors from the underlying rimraf library

Stream Behavior

  • Input: Vinyl file objects from gulp.src()
  • Output: Same vinyl file objects (pass-through stream)
  • Side Effect: Deletes files/directories from filesystem based on vinyl file paths
  • Read Optimization: Works best when gulp.src() uses { read: false } option for performance

Usage Patterns

Selective File Deletion

const gulp = require('gulp');
const ignore = require('gulp-ignore');
const rimraf = require('gulp-rimraf');

gulp.task('clean-js', function() {
  return gulp.src('./**/*.js', { read: false })
    .pipe(ignore('node_modules/**'))
    .pipe(rimraf());
});

Force Deletion Outside Working Directory

gulp.task('clean-temp', function() {
  return gulp.src('../temp/*.tmp', { read: false })
    .pipe(rimraf({ force: true }));
});

Verbose Logging

gulp.task('clean-with-log', function() {
  return gulp.src('./dist/**/*', { read: false })
    .pipe(rimraf({ verbose: true }));
});

Deprecation Notice

This package is deprecated in favor of using rimraf directly for simple folder deletion:

const rimraf = require('rimraf');

gulp.task('clean-simple', function(cb) {
  rimraf('./folder', cb);
});

However, gulp-rimraf remains useful for selective file deletion within gulp streams using glob patterns and pipe operations.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/gulp-rimraf@1.0.x
Publish Source
CLI
Badge
tessl/npm-gulp-rimraf badge