Rimraf Alternatives: Del-cli, Shx, and Other Cross-Platform File Removal Tools

For new clean scripts, del-cli is usually safer bett than old Rimraf habits. Rimraf is not dead; it still gets tens of millions of weekly downloads on npm [source: npm]. Yet many teams can get clearer scripts, lower risk, and fewer Windows surprises by picking a removal tool that fits the job.

TLDR: Use del-cli when you want safe glob-based deletion in npm scripts. Use shx rm -rf when your scripts already read like Unix shell commands and need to run on Windows too. In a 20-package monorepo, replacing four custom clean commands with one del-cli "packages/*/dist" command can cut maintenence time and avoid repeated script edits. Keep native fs.rm() for Node scripts where you control the code path.

Start with the job, not the brand

Rimraf became popular because rm -rf was awkward on Windows. That problem was real. It still bites teams that run npm scripts across macOS, Linux, Windows runners, and developer laptops.

The catch is that many projects now use Rimraf as a reflex. A clean script gets copied from an old repo, then copied again, then nobody asks if it is still the best fit. That is how build tooling gets clunky.

A file removal tool should answer a few plain questions:

  • Does it handle Windows paths without shenanigans?
  • Does it support globs in a predictable way?
  • Can it show what it will delete before it acts?
  • Is it meant for scripts, code, or human-run cleanup?
  • Will future maintainers understand it in five seconds?

del-cli: the clean choice for build artifacts

del-cli is a strong pick for deleting generated files: dist, coverage, .cache, Storybook output, and compiled assets. Its syntax is simple:

"scripts": {
  "clean": "del-cli dist coverage .cache"
}

It also works well with globs:

"clean": "del-cli \"packages/*/dist\" \"apps/*/.next\""

The best part is readability. Nobody has to decode a strange Node one-liner. Nobody has to remember which shell is running. That matters in CI logs at 6:40 p.m. when a release build fails for a silly reason.

Its dry-run option is also useful before touching folders that match broad patterns. Honestly, it feels like every deletion tool should make dry runs obvious, because one bad glob can waste an afternoon.

shx: Unix-style scripts without the Windows pain

shx wraps ShellJS commands for npm scripts. If your team likes commands such as rm, cp, mkdir, and cat, shx keeps scripts familiar while still working across platforms.

"scripts": {
  "clean": "shx rm -rf dist coverage"
}

This is handy for frontend teams with mixed scripts. One line may remove a folder. Another may copy static assets. Another may create a temp directory. With shx, the whole script block can keep the same style.

It can feel a bit quirky, though. shx rm -rf looks like real Unix rm, but it is still a JavaScript package sitting in the middle. If someone expects every shell edge case to behave the same way, expect grumbling.

Native Node fs.rm(): best inside scripts

Modern Node includes fs.rm(), with options such as recursive and force. That makes it a neat choice for custom build scripts, code generators, and internal tooling.

import { rm } from "node:fs/promises";

await rm("dist", { recursive: true, force: true });

This is not always the nicest npm script option. It belongs in JavaScript or TypeScript files where you can add checks, logging, and project-specific rules. For example, a video editing SaaS might delete per-customer render temp folders only after checking that a job status is marked finished. That kind of guard does not belong in a tiny shell command.

Trash-based tools: safer for human cleanup

Tools such as trash-cli send files to the system trash instead of wiping them right away. That is a better fit for manual cleanup, demos, and local scripts that touch user-created files.

Do not use trash behavior for most CI jobs. CI runners should remove build output fast and leave no mystery state behind. But for a local design asset folder or an editor export directory, trash-based deletion can save someone from a stupid mishap.

When Rimraf still makes sense

Rimraf is still fine for many projects. If repo already uses it and the script is boring, there may be no reason to touch it. The newer versions are maintained, widely tested, and familiar to many Node developers.

The reason to switch is not fashion. Switch when the script is hard to read, when globs need safer handling, or when you are trimming old dependencies. Also check install size and package age. A tiny cleanup command should not drag in a shabby hodgepodge of packages if a simpler option works.

A practical choice list

  • Pick del-cli for npm clean scripts, globs, and generated folders.
  • Pick shx if your package scripts already use a Unix-like style.
  • Pick native fs.rm() for custom Node scripts with checks and logs.
  • Pick trash-cli for local human-run cleanup where recovery matters.
  • Keep Rimraf if it is already stable and nobody is fighting it.

The best deletion tool is the one that makes the risky action plain. File removal should look boring. If a new teammate can read the script once and know exactly what disappears, you have made the right call.