Skip to content

Commit b0833aa

Browse files
committed
use new tap methods for testing
1 parent 0d6e652 commit b0833aa

File tree

5 files changed

+100
-133
lines changed

5 files changed

+100
-133
lines changed

src/bin.mts

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env node
22
import type { RimrafAsyncOptions } from './index.js'
33
import { rimraf } from './index.js'
4-
54
import { loadPackageJson } from 'package-json-from-dist'
65

76
const { version } = loadPackageJson(import.meta.url, '../package.json')
@@ -253,18 +252,11 @@ const main = async (...args: string[]) => {
253252

254253
return 0
255254
}
256-
main.help = help
257-
main.version = version
258-
259-
export default main
260255

261-
if (process.env.__TESTING_RIMRAF_BIN__ !== '1') {
262-
const args = process.argv.slice(2)
263-
main(...args).then(
264-
code => process.exit(code),
265-
er => {
266-
console.error(er)
267-
process.exit(1)
268-
},
269-
)
270-
}
256+
main(...process.argv.slice(2)).then(
257+
code => process.exit(code),
258+
er => {
259+
console.error(er)
260+
process.exit(1)
261+
},
262+
)

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ export const moveRemove = Object.assign(wrap(rimrafMoveRemove), {
7474
})
7575

7676
export const rimrafSync = wrapSync((path, opt) =>
77-
useNativeSync(opt) ?
77+
useNativeSync?.(opt) ?
7878
rimrafNativeSync(path, opt)
7979
: rimrafManualSync(path, opt),
8080
)
8181
export const sync = rimrafSync
8282

8383
const rimraf_ = wrap((path, opt) =>
84-
useNative(opt) ? rimrafNative(path, opt) : rimrafManual(path, opt),
84+
useNative?.(opt) ? rimrafNative(path, opt) : rimrafManual(path, opt),
8585
)
8686
export const rimraf = Object.assign(rimraf_, {
8787
rimraf: rimraf_,

src/use-native.ts

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { RimrafAsyncOptions, RimrafOptions } from './index.js'
22

3-
const versArr = process.version.replace(/^v/, '').split('.')
4-
5-
/* c8 ignore next */
6-
const [major = 0, minor = 0] = versArr.map(v => parseInt(v, 10))
3+
const [major = 0, minor = 0] = process.version
4+
.replace(/^v/, '')
5+
.split('.')
6+
.map(v => parseInt(v, 10))
77
const hasNative = major > 14 || (major === 14 && minor >= 14)
88

99
// we do NOT use native by default on Windows, because Node's native
1010
// rm implementation is less advanced. Change this code if that changes.
11-
export const useNative: (opt?: RimrafAsyncOptions) => boolean =
12-
!hasNative || process.platform === 'win32' ?
13-
() => false
14-
: opt => !opt?.signal && !opt?.filter
15-
export const useNativeSync: (opt?: RimrafOptions) => boolean =
16-
!hasNative || process.platform === 'win32' ?
17-
() => false
18-
: opt => !opt?.signal && !opt?.filter
11+
const doNotUseNative =
12+
!hasNative || process.platform === 'win32' ? () => false : null
13+
14+
// signal and filter options are not available on native methods
15+
const hasNativeOptions = (opt?: RimrafAsyncOptions | RimrafOptions) =>
16+
!opt?.signal && !opt?.filter
17+
18+
export const useNative =
19+
doNotUseNative ?? ((o?: RimrafAsyncOptions) => hasNativeOptions(o))
20+
export const useNativeSync =
21+
doNotUseNative ?? ((o?: RimrafOptions) => hasNativeOptions(o))

0 commit comments

Comments
 (0)