npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@omnihash/rollup-plugin-remove-files

v1.0.0

Published

A safe Rollup plugin to remove files and directories using glob patterns and regex with built-in security features

Downloads

5

Readme

@omnihash/rollup-plugin-remove-files

A secure Rollup plugin that safely removes files and directories using regex patterns and explicit file paths. Built with security-first design to prevent accidental deletion of source files.

Features

  • 🛡️ Security First: Only allows deletion from build/dist directories by default
  • 🎯 Regex Support: Use powerful regex patterns to match files
  • 🚫 Path Traversal Protection: Prevents ../ attacks and escaping to parent directories
  • 🧪 Test Mode: Preview what files would be deleted without actually removing them
  • 📝 Detailed Logging: See exactly what's being removed and why operations are blocked
  • Perfect Timing: Runs after build completion when files actually exist
  • 🔧 Flexible Configuration: Customize allowed directories and safety settings

Installation

npm install @omnihash/rollup-plugin-remove-files --save-dev

Quick Start

import { defineConfig } from "rollup";
import remove from "@omnihash/rollup-plugin-remove-files";

export default defineConfig({
  input: "src/index.js",
  output: {
    file: "dist/bundle.js",
    format: "es",
  },
  plugins: [
    remove({
      patterns: [/\.map$/, /\.temp$/],
      logging: true,
    }),
  ],
});

API Reference

Options

| Option | Type | Default | Description | | ------------- | ------------------------------------------ | ------------------------------------------ | ----------------------------------------- | | filePaths | string \| string[] | [] | Explicit file paths to remove | | patterns | RegExp \| RegExp[] \| string \| string[] | [] | Regex patterns to match files | | allowedDirs | string[] | ['dist', 'build', 'out', '.next/static'] | Directories where deletion is allowed | | baseDir | string | process.cwd() | Base directory for relative paths | | strictMode | boolean | true | Only allow deletion in allowedDirs | | testRun | boolean | false | Preview mode - show what would be deleted | | logging | boolean | false | Enable detailed logging |

Usage Examples

Remove Source Maps

remove({
  patterns: [/\.map$/],
  logging: true,
});

Clean Up Temp Files

remove({
  patterns: [/\.temp$/, /cache.*\.json$/],
  filePaths: ["dist/debug.log"],
  logging: true,
});

Test Mode (Safe Preview)

remove({
  patterns: [/\.test\./],
  testRun: true,
  logging: true,
});
// Output: [remove-files] Would remove: dist/app.test.js

Custom Allowed Directories

remove({
  patterns: [/\.log$/],
  allowedDirs: ["dist", "logs", "temp"],
  logging: true,
});

Development vs Production

const isProduction = process.env.NODE_ENV === "production";

remove({
  patterns: isProduction ? [/\.map$/, /\.test\./] : [],
  logging: !isProduction,
});

Security Features

Automatic Safety

  • Build Directory Detection: Automatically allows deletion from Rollup's output directory
  • Path Traversal Protection: Blocks ../ and absolute paths that could escape allowed directories
  • Whitelist Approach: Only specified directories are allowed for deletion

Safety Examples

// ✅ SAFE - Within allowed directory
remove({
  filePaths: ["dist/temp.js"],
});

// ❌ BLOCKED - Outside allowed directory
remove({
  filePaths: ["../secret-file.txt"], // Path traversal blocked
});

// ❌ BLOCKED - Absolute path
remove({
  filePaths: ["/etc/passwd"], // Absolute path blocked
});

Advanced Configuration

Disable Strict Mode (Use with Caution)

remove({
  filePaths: ["src/temp.js"], // Normally blocked
  strictMode: false, // Allows deletion outside allowedDirs
  logging: true, // Will show warnings
});

Multiple Pattern Types

remove({
  patterns: [
    /\.map$/, // RegExp
    ".*\\.temp", // String (converted to RegExp)
    /node_modules.*\\.log$/, // Complex pattern
  ],
});

Integration Examples

With TypeScript

import { defineConfig } from "rollup";
import typescript from "@rollup/plugin-typescript";
import remove from "@omnihash/rollup-plugin-remove-files";

export default defineConfig({
  input: "src/index.ts",
  output: { dir: "dist", format: "es" },
  plugins: [
    typescript(),
    remove({
      patterns: [/\.tsbuildinfo$/, /\.d\.ts\.map$/],
      logging: true,
    }),
  ],
});

With Vite (Rollup-based)

import { defineConfig } from "vite";
import remove from "@omnihash/rollup-plugin-remove-files";

export default defineConfig({
  build: {
    rollupOptions: {
      plugins: [
        remove({
          patterns: [/\.map$/],
          testRun: process.env.NODE_ENV !== "production",
        }),
      ],
    },
  },
});

Error Handling

The plugin gracefully handles errors and provides clear feedback:

removeFiles({
  filePaths: ["nonexistent.js"],
  logging: true,
});
// Output: [remove-files] File not found: /path/to/nonexistent.js

Contributing

  1. Fork the repository
  2. Create your feature branch: git checkout -b feat/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feat/amazing-feature
  5. Open a Pull Request

License

MIT © [Your Name]

Changelog

1.0.0

  • Initial release
  • Regex pattern support
  • Security-first design
  • Test mode
  • Comprehensive logging