Skip to content

Commit e0b4c68

Browse files
committed
logout: stop using npm-registry-client
1 parent d2af077 commit e0b4c68

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

lib/logout.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1-
module.exports = logout
1+
'use strict'
22

3-
var dezalgo = require('dezalgo')
4-
var log = require('npmlog')
3+
const BB = require('bluebird')
54

6-
var npm = require('./npm.js')
7-
var mapToRegistry = require('./utils/map-to-registry.js')
5+
const eu = encodeURIComponent
6+
const getAuth = require('npm-registry-fetch/auth.js')
7+
const log = require('npmlog')
8+
const npm = require('./npm.js')
9+
const npmConfig = require('./config/figgy-config.js')
10+
const npmFetch = require('libnpm/fetch')
811

912
logout.usage = 'npm logout [--registry=<url>] [--scope=<@scope>]'
1013

11-
function afterLogout (normalized, cb) {
14+
function afterLogout (normalized) {
1215
var scope = npm.config.get('scope')
1316

1417
if (scope) npm.config.del(scope + ':registry')
1518

1619
npm.config.clearCredentialsByURI(normalized)
17-
npm.config.save('user', cb)
20+
return BB.fromNode(cb => npm.config.save('user', cb))
1821
}
1922

23+
module.exports = logout
2024
function logout (args, cb) {
21-
cb = dezalgo(cb)
22-
23-
mapToRegistry('/', npm.config, function (err, uri, auth, normalized) {
24-
if (err) return cb(err)
25-
25+
const opts = npmConfig()
26+
BB.try(() => {
27+
const reg = npmFetch.pickRegistry('foo', opts)
28+
const auth = getAuth(reg, opts)
2629
if (auth.token) {
27-
log.verbose('logout', 'clearing session token for', normalized)
28-
npm.registry.logout(normalized, { auth: auth }, function (err) {
29-
if (err) return cb(err)
30-
31-
afterLogout(normalized, cb)
32-
})
30+
log.verbose('logout', 'clearing session token for', reg)
31+
return npmFetch(`/-/user/token/${eu(auth.token)}`, opts.concat({
32+
method: 'DELETE',
33+
ignoreBody: true
34+
})).then(() => afterLogout(reg))
3335
} else if (auth.username || auth.password) {
34-
log.verbose('logout', 'clearing user credentials for', normalized)
35-
36-
afterLogout(normalized, cb)
36+
log.verbose('logout', 'clearing user credentials for', reg)
37+
return afterLogout(reg)
3738
} else {
38-
cb(new Error(
39-
'Not logged in to', normalized + ',', "so can't log out."
40-
))
39+
throw new Error(
40+
'Not logged in to', reg + ',', "so can't log out."
41+
)
4142
}
42-
})
43+
}).nodeify(cb)
4344
}

0 commit comments

Comments
 (0)