Skip to content

fix(package.json): replace rm -rf with cross-platform Node.js clean script#80

Open
notsoblack wants to merge 2 commits into
midnightntwrk:mainfrom
notsoblack:fix-clean-script-cross-platform
Open

fix(package.json): replace rm -rf with cross-platform Node.js clean script#80
notsoblack wants to merge 2 commits into
midnightntwrk:mainfrom
notsoblack:fix-clean-script-cross-platform

Conversation

@notsoblack

Copy link
Copy Markdown

Bug Report & Fix

Closes #79

Problem

The clean npm script uses rm -rf dist test-app, which is a Unix-only shell command. On Windows (PowerShell / CMD / Windows Terminal), npm run clean fails immediately with:

> create-mn-app@0.4.2 clean
> rm -rf dist test-app

'rm' is not recognized as an internal or external command, operable program or batch file.

This blocks Windows contributors from cleaning build artifacts and breaks CI on Windows runners.

Root Cause

The rm binary is not available on Windows unless the user has installed Git Bash, MSYS2, or WSL. The create-mn-app CLI is meant to work cross-platform (it targets Node.js >=22), but its own build scripts are not cross-platform.

Fix

  1. Added scripts/clean.js — A small Node.js utility that uses fs.rmSync(dir, { recursive: true, force: true }), which is fully cross-platform (Linux, macOS, Windows). It gracefully skips missing directories and exits with code 1 on actual filesystem errors.

  2. Updated package.json — Changed "clean": "rm -rf dist test-app" to "clean": "node scripts/clean.js".

Verification

  • Script runs successfully on Windows (PowerShell 7.x)
  • Script runs successfully on Linux/macOS (same behavior as rm -rf)
  • Missing directories are skipped without error
  • Actual errors (permissions, etc.) exit with non-zero code
  • No new dependencies added — uses Node.js built-in fs

Impact

This fix unblocks the clean workflow for Windows developers and makes the repository's npm scripts truly cross-platform, matching the CLI's own cross-platform promises.

Related

  • engines.node already requires >=22.0.0, so fs.rmSync (stabilized in Node.js 14.14.0) is safe.

- Replaces Unix-only `rm -rf` with Node.js fs.rmSync
- Works on Windows PowerShell/CMD without WSL or Git Bash
- Gracefully handles missing directories (ENOENT)
- Returns non-zero exit code on actual errors
@notsoblack
notsoblack requested a review from Olanetsoft as a code owner June 25, 2026 17:42
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Olanetsoft

Olanetsoft commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, @notsoblack — swapping rm -rf for a Node script is exactly the right call for cross-platform support. I verified it locally: this repo is CommonJS (no top-level "type": "module"), so the require("fs") works, and { recursive: true, force: true } gives it clean rm -rf semantics including the idempotent "directory already gone" case. 👍

One change before this is complete: the generated template has the same bug. templates/hello-world/package.json.template still uses:

"clean": "rm -rf contracts/managed .midnight-state.json .midnight-wallet-state"

That script ships into the scaffolded project and runs on end users' Windows machines, so it's arguably the higher-impact case for the cross-platform goal this PR is about. Could you fold a fix for it into this PR?

Heads-up so it doesn't cost you a round-trip: that template package is ESM ("type": "module"), so it can't reuse the same require()-based scripts/clean.js. The simplest dependency-free option is a small ESM script, e.g. templates/hello-world/scripts/clean.mjs:

import { rmSync } from "node:fs";

for (const target of ["contracts/managed", ".midnight-state.json", ".midnight-wallet-state"]) {
  rmSync(target, { recursive: true, force: true });
}
"clean": "node scripts/clean.mjs"

(A devDependency like rimraf would also work, but an inline script keeps it dep-free and consistent with what you did at the root.)

Two optional nits on scripts/clean.js neither blocks anything, feel free to leave them:

  • The err.code === "ENOENT" branch is effectively unreachable, since { force: true } already suppresses missing-path errors.
  • It logs Removed: <dir> even when the directory wasn't there (rm -rf was silent) an fs.existsSync() guard would make the output truthful.

A couple of process items outside your code:

  • The CLA still shows as unsigned, the sign link is in the CLA-assistant comment above. (It's signable on your account, so it should clear once you sign.)
  • CI hasn't run yet because first-time-contributor workflows need a maintainer to approve them, I'll kick that off so we can see it go green.

Really appreciate the contribution, the direction is spot on, and with the template fix it'll fully deliver the cross-platform promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(package.json): npm run clean fails on Windows because rm -rf is not a valid shell command

3 participants