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', () => {
3737 . then ( ( ) => end ( ) )
3838 . catch ( ( ) => { } ) ;
3939
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' ) ;
4241 } ) ;
4342 } ) ;
4443} ) ;
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' ;
41import { AppConfigError } from '@app-config/core' ;
52import { logger } from '@app-config/logging' ;
3+ import type { PromptObject } from 'prompts' ;
4+ import prompts from 'prompts' ;
65
76export async function promptUser < T > ( options : Omit < PromptObject , 'name' > ) : Promise < T > {
87 const { named } = await prompts ( { ...options , name : 'named' } ) ;
@@ -31,14 +30,9 @@ export async function promptUserWithRetry<T>(
3130
3231export async function consumeStdin ( ) : Promise < string > {
3332 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' ) ) ) ;
4337 } ) ;
4438}
You can’t perform that action at this time.
0 commit comments