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

xsh-rm

v1.0.4

Published

跨平台安全删除目录工具:先改名、再隐藏、最后逐文件慢删,避免误删与系统卡顿。

Readme

xsh-rm

跨平台、零第三方依赖的命令行安全删除工具。

它会先把目标目录改名成 32 位随机名,再按平台隐藏,最后逐文件慢删(每删一个文件 sleep 约 1ms),从而避免误删难以挽回、也避免一次性删除把电脑搞卡。

安装

npm install -g xsh-rm

或本地使用:

git clone <repo>
cd xsh-rm
node bin/xsh-rm.js <目录名> [选项]

要求 Node.js >= 14。

用法

xsh-rm <目录名> [选项]

| 选项 | 说明 | | --- | --- | | -y, --yes | 跳过删除前确认(慎用) | | -d, --delay <ms> | 每个文件删除后的睡眠时间(毫秒),默认 1 | | -n, --dry-run | 只打印将要执行的操作,不实际改名/隐藏/删除 | | -h, --help | 显示帮助并退出 | | -v, --version | 显示版本号并退出 |

工作流程

  1. 瞬时转移:把目标目录 rename 到「目标所在盘的根目录下的固定容器 xsh-rm-temp」 内的一个 32 位十六进制随机名子目录:
    • 容器路径 = path.join(path.parse(目标).root, 'xsh-rm-temp')(例:D:\projects\xsh-rm\mydirD:\xsh-rm-temp\<随机名>)。
    • 容器位于目标所在盘的根目录,天然与源同卷,rename 是 O(1) 的元数据操作,瞬间完成、 不跨卷退化成复制;当前目录不留下任何隐藏目录,保持干净。
    • 隐藏:Windows 由后台 worker 调用 attrib +h;Unix/macOS 在随机名前加 . 前缀。
  2. 后台慢删:父进程立即返回,并 spawn 一个 detached 子进程接管逐文件慢删 (每删完一个文件 await 睡眠约 1ms),全过程中无提示、无日志
  3. 删完清场:后台子进程删空随机子目录后,再移除 xsh-rm-temp 容器本身 (当容器内还有其他并发删除的随机目录时会因非空而跳过,属正常),做到删完无残留。

暂存容器的权限降级

优先把容器建在「目标所在盘的根目录」下(如 C:\xsh-rm-temp)。但 Windows 的盘符根目录 (尤其 C:\)通常需要管理员权限才能创建目录,会抛 EACCES/EPERM。此时 xsh-rm 静默降级os.tmpdir() 下的同名容器(如 C:\Users\<用户>\AppData\Local\Temp\xsh-rm-temp):

  • 降级过程不打印任何日志,行为对调用方透明;
  • 降级后容器仍不在当前目录,删除逻辑完全相同(仅当跨盘时 rename 会退化成复制,功能正确);
  • 删完后该降级容器同样会被移除,不留残留。

因此无论是否发生降级,删除完成后盘根(或临时目录)下的 xsh-rm-temp 容器都会被清理掉。

安全护栏

  • 目标必须是已存在的目录,否则报错退出(非零退出码)。
  • 拒绝删除危险路径:绝对路径长度过短,或命中以下任一会被拒绝并退出:
    • 根目录(/
    • 盘符根(如 C:\D:\
    • 用户家目录(os.homedir()
    • 当前工作目录(process.cwd()
    • ... 及其解析结果
  • 删除前确认:除非传 -y/--yes,否则用 readline 展示目标绝对路径并要求输入 y 确认,否则中止。

示例

# 先看看会做什么(不会真正删除)
xsh-rm ./old-project --dry-run

# 真正删除,并跳过确认、把每文件延迟调大到 5ms
xsh-rm ./old-project -y -d 5

本地验证

# 运行单元测试
npm test

# 冒烟测试
node bin/xsh-rm.js /path/to/some/temp/dir --dry-run   # 应只打印,不删文件
node bin/xsh-rm.js /path/to/some/temp/dir -y          # 真正改名隐藏后删除

License

MIT