|
1 | | -import { optArg, optArgSync } from './opt-arg.js' |
| 1 | +import { glob, globSync } from 'glob' |
| 2 | +import { |
| 3 | + optArg, |
| 4 | + optArgSync, |
| 5 | + RimrafAsyncOptions, |
| 6 | + RimrafSyncOptions, |
| 7 | +} from './opt-arg.js' |
2 | 8 | import pathArg from './path-arg.js' |
3 | | - |
4 | | -import { glob, GlobOptions, globSync } from 'glob' |
5 | | - |
6 | | -export interface RimrafAsyncOptions { |
7 | | - preserveRoot?: boolean |
8 | | - tmp?: string |
9 | | - maxRetries?: number |
10 | | - retryDelay?: number |
11 | | - backoff?: number |
12 | | - maxBackoff?: number |
13 | | - signal?: AbortSignal |
14 | | - glob?: boolean | GlobOptions |
15 | | - filter?: |
16 | | - | ((path: string, ent: Dirent | Stats) => boolean) |
17 | | - | ((path: string, ent: Dirent | Stats) => Promise<boolean>) |
18 | | -} |
19 | | - |
20 | | -export interface RimrafSyncOptions extends RimrafAsyncOptions { |
21 | | - filter?: (path: string, ent: Dirent | Stats) => boolean |
22 | | -} |
23 | | - |
24 | | -export type RimrafOptions = RimrafSyncOptions | RimrafAsyncOptions |
25 | | - |
26 | | -const typeOrUndef = (val: any, t: string) => |
27 | | - typeof val === 'undefined' || typeof val === t |
28 | | - |
29 | | -export const isRimrafOptions = (o: any): o is RimrafOptions => |
30 | | - !!o && |
31 | | - typeof o === 'object' && |
32 | | - typeOrUndef(o.preserveRoot, 'boolean') && |
33 | | - typeOrUndef(o.tmp, 'string') && |
34 | | - typeOrUndef(o.maxRetries, 'number') && |
35 | | - typeOrUndef(o.retryDelay, 'number') && |
36 | | - typeOrUndef(o.backoff, 'number') && |
37 | | - typeOrUndef(o.maxBackoff, 'number') && |
38 | | - (typeOrUndef(o.glob, 'boolean') || (o.glob && typeof o.glob === 'object')) && |
39 | | - typeOrUndef(o.filter, 'function') |
40 | | - |
41 | | -export const assertRimrafOptions: (o: any) => void = ( |
42 | | - o: any |
43 | | -): asserts o is RimrafOptions => { |
44 | | - if (!isRimrafOptions(o)) { |
45 | | - throw new Error('invalid rimraf options') |
46 | | - } |
47 | | -} |
48 | | - |
49 | | -import { Dirent, Stats } from 'fs' |
50 | 9 | import { rimrafManual, rimrafManualSync } from './rimraf-manual.js' |
51 | 10 | import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js' |
52 | 11 | import { rimrafNative, rimrafNativeSync } from './rimraf-native.js' |
53 | 12 | import { rimrafPosix, rimrafPosixSync } from './rimraf-posix.js' |
54 | 13 | import { rimrafWindows, rimrafWindowsSync } from './rimraf-windows.js' |
55 | 14 | import { useNative, useNativeSync } from './use-native.js' |
56 | 15 |
|
| 16 | +export { |
| 17 | + assertRimrafOptions, |
| 18 | + isRimrafOptions, |
| 19 | + RimrafAsyncOptions, |
| 20 | + RimrafOptions, |
| 21 | + RimrafSyncOptions, |
| 22 | +} from './opt-arg.js' |
| 23 | + |
57 | 24 | const wrap = |
58 | 25 | (fn: (p: string, o: RimrafAsyncOptions) => Promise<boolean>) => |
59 | 26 | async ( |
|
0 commit comments