Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: isaacs/rimraf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.1.1
Choose a base ref
...
head repository: isaacs/rimraf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.1.2
Choose a head ref
  • 4 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 19, 2023

  1. Copy the full SHA
    89b38cf View commit details

Commits on Jan 24, 2023

  1. 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
    isaacs committed Jan 24, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    dc2fd42 View commit details
  2. Copy the full SHA
    385f86f View commit details
  3. 4.1.2

    isaacs committed Jan 24, 2023
    Copy the full SHA
    df3d085 View commit details
Showing with 108 additions and 9 deletions.
  1. +3 −0 CHANGELOG.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +3 −0 src/bin.ts
  5. +1 −5 src/index.ts
  6. +23 −1 test/bin.js
  7. +75 −0 test/opt-arg.js
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rimraf",
"version": "4.1.1",
"version": "4.1.2",
"main": "./dist/cjs/src/index-cjs.js",
"module": "./dist/mjs/index.js",
"bin": "./dist/cjs/src/bin.js",
3 changes: 3 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -10,30 +10,26 @@ export interface RimrafOptions {
maxBackoff?: number
}

/* c8 ignore start */
const typeOrUndef = (val: any, t: string) =>
typeof val === 'undefined' || typeof val === t
/* c8 ignore stop */

export const isRimrafOptions = (o: any): o is RimrafOptions =>
!!o &&
typeof o === 'object' &&
typeOrUndef(o.preserveRoot, 'boolean') &&
typeOrUndef(o.preserveRoot, 'number') &&
typeOrUndef(o.tmp, 'string') &&
typeOrUndef(o.maxRetries, 'number') &&
typeOrUndef(o.retryDelay, 'number') &&
typeOrUndef(o.backoff, 'number') &&
typeOrUndef(o.maxBackoff, 'number')

/* c8 ignore start */
export const assertRimrafOptions: (o: any) => void = (
o: any
): asserts o is RimrafOptions => {
if (!isRimrafOptions(o)) {
throw new Error('invalid rimraf options')
}
}
/* c8 ignore stop */

import { rimrafManual, rimrafManualSync } from './rimraf-manual.js'
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js'
24 changes: 23 additions & 1 deletion test/bin.js
Original file line number Diff line number Diff line change
@@ -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)
75 changes: 75 additions & 0 deletions test/opt-arg.js
Original file line number Diff line number Diff line change
@@ -3,3 +3,78 @@ const optArg = require('../dist/cjs/src/opt-arg.js').default
const opt = { a: 1 }
t.equal(optArg(opt), opt, 'returns object if provided')
t.same(optArg(), {}, 'returns new object otherwise')

t.throws(() => optArg(true))
t.throws(() => optArg(null))
t.throws(() => optArg('hello'))
t.throws(() => optArg({ maxRetries: 'banana' }))

t.test('every kind of invalid option value', t => {
// skip them when it's undefined, and skip the case
// where they're all undefined, otherwise try every
// possible combination of the values here.
const badBool = [undefined, 1, null, 'x', {}]
const badNum = [undefined, true, false, null, 'x', '1', {}]
const badStr = [undefined, { toString: () => 'hi' }, /hi/, Symbol.for('hi')]
for (const preserveRoot of badBool) {
for (const tmp of badStr) {
for (const maxRetries of badNum) {
for (const retryDelay of badNum) {
for (const backoff of badNum) {
for (const maxBackoff of badNum) {
if (
preserveRoot === undefined &&
maxRetries === undefined &&
retryDelay === undefined &&
backoff === undefined &&
maxBackoff === undefined
) {
continue
}
t.throws(() =>
optArg({
preserveRoot,
maxRetries,
retryDelay,
backoff,
maxBackoff,
})
)
}
}
}
}
}
}
t.end()
})

t.test('test every allowed combination', t => {
const goodBool = [undefined, true, false]
// note that a few of these actually aren't *valid*,
// but it's verifying what the initial opt checker does.
const goodNum = [undefined, 1, Math.pow(2, 32), -1]
const goodStr = [undefined, 'hi']
for (const preserveRoot of goodBool) {
for (const tmp of goodStr) {
for (const maxRetries of goodNum) {
for (const retryDelay of goodNum) {
for (const backoff of goodNum) {
for (const maxBackoff of goodNum) {
t.ok(
optArg({
preserveRoot,
maxRetries,
retryDelay,
backoff,
maxBackoff,
})
)
}
}
}
}
}
}
t.end()
})