File tree Expand file tree Collapse file tree 2 files changed +7
-14
lines changed Expand file tree Collapse file tree 2 files changed +7
-14
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,7 @@ describe('consumeStdin', () => {
37
37
. then ( ( ) => end ( ) )
38
38
. catch ( ( ) => { } ) ;
39
39
40
- // we expect newlines to be eaten up, since this function is used for html and base64 data
41
- expect ( await consumeStdin ( ) ) . toBe ( 'foobarbaz' ) ;
40
+ expect ( await consumeStdin ( ) ) . toBe ( 'foo\nbar\nbaz\n' ) ;
42
41
} ) ;
43
42
} ) ;
44
43
} ) ;
Original file line number Diff line number Diff line change 1
- import readline from 'readline' ;
2
- import prompts from 'prompts' ;
3
- import type { PromptObject } from 'prompts' ;
4
1
import { AppConfigError } from '@app-config/core' ;
5
2
import { logger } from '@app-config/logging' ;
3
+ import type { PromptObject } from 'prompts' ;
4
+ import prompts from 'prompts' ;
6
5
7
6
export async function promptUser < T > ( options : Omit < PromptObject , 'name' > ) : Promise < T > {
8
7
const { named } = await prompts ( { ...options , name : 'named' } ) ;
@@ -31,14 +30,9 @@ export async function promptUserWithRetry<T>(
31
30
32
31
export async function consumeStdin ( ) : Promise < string > {
33
32
return new Promise ( ( resolve , reject ) => {
34
- const rl = readline . createInterface ( { input : process . stdin } ) ;
35
-
36
- let buffer = '' ;
37
- rl . on ( 'line' , ( line ) => {
38
- buffer += line ;
39
- } ) ;
40
-
41
- rl . on ( 'error' , reject ) ;
42
- rl . on ( 'close' , ( ) => resolve ( buffer ) ) ;
33
+ const buffers : Buffer [ ] = [ ] ;
34
+ process . stdin . on ( 'data' , ( data ) => buffers . push ( data ) ) ;
35
+ process . stdin . on ( 'error' , reject ) ;
36
+ process . stdin . on ( 'end' , ( ) => resolve ( Buffer . concat ( buffers ) . toString ( 'utf8' ) ) ) ;
43
37
} ) ;
44
38
}
You can’t perform that action at this time.
0 commit comments