Skip to content

Commit b178343

Browse files
authored
fix: only use browser login when available (#44)
1 parent 03097ae commit b178343

File tree

3 files changed

+63
-58
lines changed

3 files changed

+63
-58
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@heroku-cli/color": "^1.1.5",
99
"@oclif/errors": "^1.1.2",
10-
"cli-ux": "^4.6.1",
10+
"cli-ux": "^4.7.1",
1111
"debug": "^3.1.0",
1212
"fs-extra": "^6.0.1",
1313
"heroku-client": "^3.0.6",
@@ -19,28 +19,28 @@
1919
"@heroku-cli/schema": "^1.0.5",
2020
"@heroku-cli/tslint": "^1.1.4",
2121
"@oclif/command": "^1.4.33",
22-
"@oclif/config": "^1.6.27",
22+
"@oclif/config": "^1.6.30",
2323
"@oclif/tslint": "^1.1.2",
2424
"@types/ansi-styles": "^3.2.0",
25-
"@types/chai": "^4.1.3",
25+
"@types/chai": "^4.1.4",
2626
"@types/fs-extra": "^5.0.3",
27-
"@types/mocha": "^5.2.1",
27+
"@types/mocha": "^5.2.2",
2828
"@types/nock": "^9.1.3",
29-
"@types/node": "^10.3.2",
29+
"@types/node": "^10.3.3",
3030
"@types/opn": "^5.1.0",
3131
"@types/proxyquire": "^1.3.28",
3232
"@types/sinon": "^5.0.1",
3333
"@types/supports-color": "^5.3.0",
3434
"chai": "^4.1.2",
35-
"fancy-test": "^1.1.4",
35+
"fancy-test": "^1.2.0",
3636
"mocha": "^5.2.0",
37-
"nock": "^9.3.2",
37+
"nock": "^9.3.3",
3838
"proxyquire": "^2.0.1",
39-
"sinon": "^5.1.1",
39+
"sinon": "^6.0.0",
4040
"testdouble": "^3.8.1",
41-
"ts-node": "^6.1.0",
41+
"ts-node": "^6.1.1",
4242
"tslint": "^5.10.0",
43-
"typescript": "^2.9.1"
43+
"typescript": "^2.9.2"
4444
},
4545
"engines": {
4646
"node": ">=6.0.0"

src/login.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export class Login {
5757
// can't use browser with --expires-in
5858
input = 'interactive'
5959
} else if (this.enableBrowserLogin()) {
60-
input = await ux.prompt(`heroku: Login with [${color.green('b')}]rowser, [${color.green('i')}]nteractive, or [${color.green('s')}]so (enterprise-only)`, {default: defaultMethod})
60+
await ux.anykey(`heroku: Press any key to open up the browser to login or ${color.yellow('q')} to exit`)
61+
input = 'browser'
6162
} else {
6263
input = defaultMethod || 'interactive'
6364
}
@@ -72,7 +73,7 @@ export class Login {
7273
switch (input) {
7374
case 'b':
7475
case 'browser':
75-
auth = await this.browser()
76+
auth = await this.browser(opts.browser)
7677
break
7778
case 'i':
7879
case 'interactive':
@@ -138,19 +139,26 @@ export class Login {
138139
await Promise.all(requests)
139140
}
140141

141-
private async browser(): Promise<NetrcEntry> {
142+
private async browser(browser?: string): Promise<NetrcEntry> {
142143
const {body: urls} = await HTTP.post<{browser_url: string, cli_url: string, token: string}>(`${this.loginHost}/auth`)
143144
// TODO: handle browser
144145
const url = `${this.loginHost}${urls.browser_url}`
145146
debug(`opening browser to ${url}`)
146-
const cp = await opn(url, {wait: false})
147-
cp.on('error', ux.error)
148-
const showUrl = () => ux.warn(`Cannot open browser. Go to ${color.greenBright(url)} to finish login or run ${color.cmd('heroku login --interactive')}\n`)
147+
let urlDisplayed = false
148+
const showUrl = () => {
149+
if (!urlDisplayed) ux.warn(`Cannot open browser. Go to ${color.greenBright(url)} to finish login or run ${color.cmd('heroku login --interactive')}\n`)
150+
urlDisplayed = true
151+
}
152+
const cp = await opn(url, {app: browser, wait: false})
153+
cp.on('error', err => {
154+
ux.warn(err)
155+
showUrl()
156+
})
149157
if (process.env.HEROKU_TESTING_HEADLESS_LOGIN === '1') showUrl()
150158
cp.on('close', code => {
151159
if (code !== 0) showUrl()
152160
})
153-
ux.action.start('Waiting for login')
161+
ux.action.start('heroku: Waiting for login')
154162
const {body: auth} = await HTTP.get<{error?: string, access_token: string}>(`${this.loginHost}${urls.cli_url}`, {
155163
headers: {
156164
authorization: `Bearer ${urls.token}`,

yarn.lock

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
debug "^3.1.0"
4848
semver "^5.5.0"
4949

50-
"@oclif/config@^1.6.27":
51-
version "1.6.27"
52-
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.6.27.tgz#d3de1cff71301784c8e4ee3903d3f7db21a18c3f"
50+
"@oclif/config@^1.6.30":
51+
version "1.6.30"
52+
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.6.30.tgz#ec5d60c86a5f5e4c04a02c73c43459d56140fafd"
5353
dependencies:
5454
debug "^3.1.0"
5555
tslib "^1.9.2"
@@ -97,9 +97,9 @@
9797
dependencies:
9898
"@types/color-name" "*"
9999

100-
"@types/chai@^4.1.3":
101-
version "4.1.3"
102-
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.3.tgz#b8a74352977a23b604c01aa784f5b793443fb7dc"
100+
"@types/chai@^4.1.4":
101+
version "4.1.4"
102+
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.4.tgz#5ca073b330d90b4066d6ce18f60d57f2084ce8ca"
103103

104104
"@types/color-name@*":
105105
version "1.1.0"
@@ -115,13 +115,9 @@
115115
version "4.14.109"
116116
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.109.tgz#b1c4442239730bf35cabaf493c772b18c045886d"
117117

118-
"@types/mocha@^5.2.0":
119-
version "5.2.0"
120-
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.0.tgz#b3c8e69f038835db1a7fdc0b3d879fc50506e29e"
121-
122-
"@types/mocha@^5.2.1":
123-
version "5.2.1"
124-
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.1.tgz#465450aaf5cec6f7d35523748c6cc89a5e222dc5"
118+
"@types/mocha@^5.2.2":
119+
version "5.2.2"
120+
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.2.tgz#202d2b8fe1364c5b617b439b26a54f0e75eac0a7"
125121

126122
"@types/nock@^9.1.3":
127123
version "9.1.3"
@@ -133,13 +129,9 @@
133129
version "10.0.4"
134130
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.0.4.tgz#130598ee56e9a1210a53f557d64935571f05390d"
135131

136-
"@types/node@^10.3.0":
137-
version "10.3.0"
138-
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.3.0.tgz#078516315a84d56216b5d4fed8f75d59d3b16cac"
139-
140-
"@types/node@^10.3.2":
141-
version "10.3.2"
142-
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.3.2.tgz#3840ec6c12556fdda6e0e6d036df853101d732a4"
132+
"@types/node@^10.3.3":
133+
version "10.3.3"
134+
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.3.3.tgz#8798d9e39af2fa604f715ee6a6b19796528e46c3"
143135

144136
"@types/opn@^5.1.0":
145137
version "5.1.0"
@@ -274,9 +266,9 @@ clean-stack@^1.3.0:
274266
version "1.3.0"
275267
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-1.3.0.tgz#9e821501ae979986c46b1d66d2d432db2fd4ae31"
276268

277-
cli-ux@^4.6.1:
278-
version "4.6.1"
279-
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-4.6.1.tgz#2cc7feb4d48932a95bffe712426eaa36ec861004"
269+
cli-ux@^4.7.1:
270+
version "4.7.1"
271+
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-4.7.1.tgz#b954aa806620cc818cbdd0a75e587c54bf0a0bbe"
280272
dependencies:
281273
"@oclif/linewrap" "^1.0.0"
282274
"@oclif/screen" "^1.0.2"
@@ -444,17 +436,18 @@ extract-stack@^1.0.0:
444436
version "1.0.0"
445437
resolved "https://registry.yarnpkg.com/extract-stack/-/extract-stack-1.0.0.tgz#b97acaf9441eea2332529624b732fc5a1c8165fa"
446438

447-
fancy-test@^1.1.4:
448-
version "1.1.4"
449-
resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-1.1.4.tgz#1bcc7b7a526218a85ed1ff0d2e95afc4b69fab23"
439+
fancy-test@^1.2.0:
440+
version "1.2.0"
441+
resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-1.2.0.tgz#c5f6f81725ea42b9caec9bb18731449cfab526f3"
450442
dependencies:
451-
"@types/chai" "^4.1.3"
443+
"@types/chai" "^4.1.4"
452444
"@types/lodash" "^4.14.109"
453-
"@types/mocha" "^5.2.0"
445+
"@types/mocha" "^5.2.2"
454446
"@types/nock" "^9.1.3"
455-
"@types/node" "^10.3.0"
447+
"@types/node" "^10.3.3"
456448
"@types/sinon" "^5.0.1"
457449
lodash "^4.17.10"
450+
mock-stdin "^0.3.1"
458451
stdout-stderr "^0.1.9"
459452

460453
fill-keys@^1.0.2:
@@ -686,6 +679,10 @@ mocha@^5.2.0:
686679
mkdirp "0.5.1"
687680
supports-color "5.4.0"
688681

682+
mock-stdin@^0.3.1:
683+
version "0.3.1"
684+
resolved "https://registry.yarnpkg.com/mock-stdin/-/mock-stdin-0.3.1.tgz#c657d9642d90786435c64ca5e99bbd4d09bd7dd3"
685+
689686
module-not-found-error@^1.0.0:
690687
version "1.0.1"
691688
resolved "https://registry.yarnpkg.com/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0"
@@ -719,9 +716,9 @@ nise@^1.3.3:
719716
path-to-regexp "^1.7.0"
720717
text-encoding "^0.6.4"
721718

722-
nock@^9.3.2:
723-
version "9.3.2"
724-
resolved "https://registry.yarnpkg.com/nock/-/nock-9.3.2.tgz#f2f52a784a8a33d7496f4ab5b28c3b879091e6d6"
719+
nock@^9.3.3:
720+
version "9.3.3"
721+
resolved "https://registry.yarnpkg.com/nock/-/nock-9.3.3.tgz#d9f4cd3c011afeadaf5ccf1b243f6e353781cda0"
725722
dependencies:
726723
chai "^4.1.2"
727724
debug "^3.1.0"
@@ -855,9 +852,9 @@ signal-exit@^3.0.0:
855852
version "3.0.2"
856853
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
857854

858-
sinon@^5.1.1:
859-
version "5.1.1"
860-
resolved "https://registry.yarnpkg.com/sinon/-/sinon-5.1.1.tgz#19c59810ffb733ea6e76a28b94a71fc4c2f523b8"
855+
sinon@^6.0.0:
856+
version "6.0.0"
857+
resolved "https://registry.yarnpkg.com/sinon/-/sinon-6.0.0.tgz#f26627e4830dc34279661474da2c9e784f166215"
861858
dependencies:
862859
"@sinonjs/formatio" "^2.0.0"
863860
diff "^3.5.0"
@@ -954,9 +951,9 @@ theredoc@^1.0.0:
954951
version "1.0.0"
955952
resolved "https://registry.yarnpkg.com/theredoc/-/theredoc-1.0.0.tgz#bcace376af6feb1873efbdd0f91ed026570ff062"
956953

957-
ts-node@^6.1.0:
958-
version "6.1.0"
959-
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-6.1.0.tgz#a2c37a11fdb58e60eca887a1269b025cf4d2f8b8"
954+
ts-node@^6.1.1:
955+
version "6.1.1"
956+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-6.1.1.tgz#19607140acb06150441fcdb61be11f73f7b6657e"
960957
dependencies:
961958
arrify "^1.0.0"
962959
diff "^3.1.0"
@@ -1047,9 +1044,9 @@ type-detect@^4.0.0, type-detect@^4.0.8:
10471044
version "4.0.8"
10481045
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
10491046

1050-
typescript@^2.9.1:
1051-
version "2.9.1"
1052-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.1.tgz#fdb19d2c67a15d11995fd15640e373e09ab09961"
1047+
typescript@^2.9.2:
1048+
version "2.9.2"
1049+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
10531050

10541051
universalify@^0.1.0:
10551052
version "0.1.1"

0 commit comments

Comments
 (0)