@@ -46,6 +46,7 @@ import { parse, relative, resolve } from 'path'
4646const cwd = process . cwd ( )
4747
4848import { createInterface , Interface } from 'readline'
49+ import { Dirent , Stats } from 'fs'
4950
5051const prompt = async ( rl : Interface , q : string ) =>
5152 new Promise < string > ( res => rl . question ( q , res ) )
@@ -70,11 +71,11 @@ const interactiveRimraf = async (
7071 processing = false
7172 }
7273 const oneAtATime =
73- ( fn : ( s : string ) = > Promise < boolean > ) =>
74- async ( s : string ) : Promise < boolean > => {
74+ ( fn : ( s : string , e : Dirent | Stats ) = > Promise < boolean > ) =>
75+ async ( s : string , e : Dirent | Stats ) : Promise < boolean > => {
7576 const p = new Promise < boolean > ( res => {
7677 queue . push ( async ( ) => {
77- const result = await fn ( s )
78+ const result = await fn ( s , e )
7879 res ( result )
7980 return result
8081 } )
@@ -86,30 +87,32 @@ const interactiveRimraf = async (
8687 input : process . stdin ,
8788 output : process . stdout ,
8889 } )
89- opt . filter = oneAtATime ( async ( path : string ) : Promise < boolean > => {
90- if ( noneRemaining ) {
91- return false
92- }
93- while ( ! allRemaining ) {
94- const a = (
95- await prompt ( rl , `rm? ${ relative ( cwd , path ) } \n[(Yes)/No/All/Quit] > ` )
96- ) . trim ( )
97- if ( / ^ n / i. test ( a ) ) {
98- return false
99- } else if ( / ^ a / i. test ( a ) ) {
100- allRemaining = true
101- break
102- } else if ( / ^ q / i. test ( a ) ) {
103- noneRemaining = true
90+ opt . filter = oneAtATime (
91+ async ( path : string , ent : Dirent | Stats ) : Promise < boolean > => {
92+ if ( noneRemaining ) {
10493 return false
105- } else if ( a === '' || / ^ y / i. test ( a ) ) {
106- break
107- } else {
108- continue
10994 }
95+ while ( ! allRemaining ) {
96+ const a = (
97+ await prompt ( rl , `rm? ${ relative ( cwd , path ) } \n[(Yes)/No/All/Quit] > ` )
98+ ) . trim ( )
99+ if ( / ^ n / i. test ( a ) ) {
100+ return false
101+ } else if ( / ^ a / i. test ( a ) ) {
102+ allRemaining = true
103+ break
104+ } else if ( / ^ q / i. test ( a ) ) {
105+ noneRemaining = true
106+ return false
107+ } else if ( a === '' || / ^ y / i. test ( a ) ) {
108+ break
109+ } else {
110+ continue
111+ }
112+ }
113+ return existingFilter ( path , ent )
110114 }
111- return existingFilter ( path )
112- } )
115+ )
113116 await impl ( paths , opt )
114117 rl . close ( )
115118}
0 commit comments