Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 910dc6f

Browse files
authored
remove readline to stop hangup (#19)
1 parent eed085e commit 910dc6f

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

src/commands/login/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Command} from '@oclif/core'
2+
import chalk from 'chalk'
23
import * as fs from 'node:fs'
34
import * as http from 'node:http'
4-
import {createInterface} from 'node:readline'
55
import {URL} from 'node:url'
66
import open from 'open'
77

@@ -73,7 +73,7 @@ export default class LoginIndex extends Command {
7373
public async openLoginPage() {
7474
// Open the Hypermode sign-in page in the default browser
7575
const loginUrl = 'https://hypermode.com/app/callback?port=5051&type=cli'
76-
await open(loginUrl)
76+
await open(loginUrl, {wait: false})
7777
}
7878

7979
public async run(): Promise<void> {
@@ -90,23 +90,16 @@ export default class LoginIndex extends Command {
9090
res.writeHead(200, {'Content-Type': 'text/html'})
9191
res.end(loginHTML)
9292

93-
// Close the server once JWT and email are captured
93+
// Close the server once JWT and eamail are captured
9494
server.close()
9595

96-
const rl = createInterface({
97-
input: process.stdin,
98-
output: process.stdout,
99-
})
100-
10196
const orgs = await sendGraphQLRequest(jwt)
102-
const selectedOrg = await promptOrgSelection(rl, orgs)
97+
const selectedOrg = await promptOrgSelection(orgs)
10398
// Store JWT and email securely
10499
this.writeToEnvFile(jwt, email, selectedOrg.id)
105100

106101
// Confirm successful login in the CLI
107-
this.log('Successfully logged in as ' + email + '! 🎉')
108-
109-
rl.close()
102+
this.log('Successfully logged in as ' + chalk.dim(email) + '! 🎉')
110103
} else {
111104
// Respond with an error if JWT or email is missing
112105
res.writeHead(400, {'Content-Type': 'text/plain'})

src/commands/org/switch.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Command} from '@oclif/core'
22
import chalk from 'chalk'
33
import * as fs from 'node:fs'
4-
import {createInterface} from 'node:readline'
54

65
import {
76
fileExists, getEnvFilePath, promptOrgSelection, readSettingsJson, sendGraphQLRequest,
@@ -30,13 +29,8 @@ export default class OrgSwitch extends Command {
3029
return
3130
}
3231

33-
const rl = createInterface({
34-
input: process.stdin,
35-
output: process.stdout,
36-
})
37-
3832
const orgs = await sendGraphQLRequest(res.jwt)
39-
const selectedOrg = await promptOrgSelection(rl, orgs)
33+
const selectedOrg = await promptOrgSelection(orgs)
4034

4135
const updatedContent = {
4236
HYP_EMAIL: res.email,
@@ -45,7 +39,5 @@ export default class OrgSwitch extends Command {
4539
}
4640

4741
fs.writeFileSync(envFilePath, JSON.stringify(updatedContent, null, 2), {flag: 'w'})
48-
49-
rl.close()
5042
}
5143
}

src/util/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as inquirer from '@inquirer/prompts'
33
import chalk from 'chalk'
44
import * as fs from 'node:fs'
55
import * as path from 'node:path'
6-
import {Interface, createInterface} from 'node:readline'
6+
import {Interface} from 'node:readline'
77
import fetch from 'node-fetch'
88

99
type Org = {
@@ -19,7 +19,7 @@ export function ask(question: string, rl: Interface, placeholder?: string): Prom
1919
})
2020
}
2121

22-
export async function promptOrgSelection(rl: ReturnType<typeof createInterface>, orgs: Org[]): Promise<Org> {
22+
export async function promptOrgSelection(orgs: Org[]): Promise<Org> {
2323
const choices = orgs.map(org => ({
2424
name: org.slug,
2525
value: org,

0 commit comments

Comments
 (0)