|
1 | 1 | import { RimrafAsyncOptions, RimrafOptions } from './index.js'
|
2 | 2 |
|
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)) |
7 | 7 | const hasNative = major > 14 || (major === 14 && minor >= 14)
|
8 | 8 |
|
9 | 9 | // we do NOT use native by default on Windows, because Node's native
|
10 | 10 | // 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