Skip to content

Commit

Permalink
Correct expected prompt, deal with non-matching prompt
Browse files Browse the repository at this point in the history
and add other suggestions from offline chat
  • Loading branch information
krassowski committed Aug 13, 2021
1 parent 98158fa commit 77075df
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions buildutils/src/local-repository.ts
Expand Up @@ -134,13 +134,13 @@ packages:
console.log('Logging in');
const loginPs = child_process.spawn(
'npm',
`login -e ${email} -r ${local_registry}`.split(' ')
`login -r ${local_registry}`.split(' ')
);

const loggedIn = new Promise<void>((accept, reject) => {
loginPs.stdout.on('data', (chunk: string) => {
const data = Buffer.from(chunk, 'utf-8').toString().trim();
console.log('debug:', data);
console.log('stdout:', data);
switch (data) {
case 'Username:':
console.log('Passing username...');
Expand All @@ -150,16 +150,21 @@ packages:
console.log('Passing password...');
loginPs.stdin.write(pass + '\n');
break;
case 'Email':
case 'Email: (this IS public)':
console.log('Passing email...');
loginPs.stdin.write(email + '\n');
break;
default:
reject(`Unexpected prompt: "${data}"`);
}
if (data.indexOf('Logged in as') !== -1) {
console.log('debug: matched');
loginPs.stdin.end();
accept();
// do not accept here yet, the token may not have been written
}
loginPs.stderr.on('data', (chunk: string) => {
const data = Buffer.from(chunk, 'utf-8').toString().trim();
console.log('stderr:', data);
});
});
loginPs.on('error', error => reject(error));
loginPs.on('close', () => accept());
Expand Down

0 comments on commit 77075df

Please sign in to comment.