From dc2fd42a44532a5cca30e6394d4304129b5a2bf6 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 23 Jan 2023 21:43:33 -0800 Subject: [PATCH] ignore unnecessary -rf or -fr rimraf is always 'rm -rf', that's how it got its name Updated changelog with this overlooked breaking change in v4.0, and added the newly ignored -rf/-fr to the changelog for v4.1. Fix: #253 --- CHANGELOG.md | 3 +++ src/bin.ts | 3 +++ test/bin.js | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe51ce2..5bcd91a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Improved hybrid module with no need to look at the `.default` dangly bit. `.default` preserved as a reference to `rimraf` for compatibility with anyone who came to rely on it in v4.0. +- Accept and ignore `-rf` and `-fr` arguments to the bin. # v4.0 @@ -14,6 +15,8 @@ - Drop support for Node.js below version 14 - rewrite in TypeScript - ship CJS/ESM hybrid module +- Error on ignore unknown arguments to the bin. (Previously they + were silently ignored.) # v3.0 diff --git a/src/bin.ts b/src/bin.ts index 6aaed9b8..3791e369 100755 --- a/src/bin.ts +++ b/src/bin.ts @@ -53,6 +53,9 @@ const main = async (...args: string[]) => { if (arg === '--') { dashdash = true continue + } else if (arg === '-rf' || arg === '-fr') { + // this never did anything, but people put it there I guess + continue } else if (arg === '-h' || arg === '--help') { console.log(help) return 0 diff --git a/test/bin.js b/test/bin.js index 73f37a8e..03d6ff1e 100644 --- a/test/bin.js +++ b/test/bin.js @@ -51,6 +51,21 @@ t.test('basic arg parsing stuff', t => { ]) }) + t.test('unnecessary -rf', async t => { + t.equal(await bin('-rf', 'foo'), 0) + t.equal(await bin('-fr', 'foo'), 0) + t.equal(await bin('foo', '-rf'), 0) + t.equal(await bin('foo', '-fr'), 0) + t.same(LOGS, []) + t.same(ERRS, []) + t.same(CALLS, [ + ['rimraf', ['foo'], {}], + ['rimraf', ['foo'], {}], + ['rimraf', ['foo'], {}], + ['rimraf', ['foo'], {}], + ]) + }) + t.test('dashdash', async t => { t.equal(await bin('--', '-h'), 0) t.same(LOGS, []) @@ -134,7 +149,14 @@ t.test('basic arg parsing stuff', t => { t.same(CALLS, []) }) - const impls = ['rimraf', 'native', 'manual', 'posix', 'windows', 'move-remove'] + const impls = [ + 'rimraf', + 'native', + 'manual', + 'posix', + 'windows', + 'move-remove', + ] for (const impl of impls) { t.test(`--impl=${impl}`, async t => { t.equal(await bin('foo', `--impl=${impl}`), 0)