Skip to content

Commit

Permalink
Add spec to dist-tag remove function
Browse files Browse the repository at this point in the history
PR-URL: #235
Credit: @theberbie
Close: #235
Reviewed-by: @isaacs

EDIT(isaacs): Added test
  • Loading branch information
theberbie authored and isaacs committed Aug 15, 2019
1 parent a2cd07f commit 54b095d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ function remove (spec, tag, opts) {
delete tags[tag]
const url = `/-/package/${spec.escapedName}/dist-tags/${encodeURIComponent(tag)}`
const reqOpts = opts.concat({
method: 'DELETE'
method: 'DELETE',
spec
})
return otplease(reqOpts, reqOpts => regFetch(url, reqOpts)).then(() => {
output(`-${tag}: ${spec.name}@${version}`)
Expand Down
31 changes: 31 additions & 0 deletions test/tap/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ function mocks (server) {
server.delete('/-/package/@scoped%2fanother/dist-tags/c')
.reply(200, { c: '7.7.7' })

// using a scoped registry
server.get('/-/package/@scoped%2ffoo/dist-tags')
.reply(200, { latest: '2.0.0', a: '0.0.2', b: '0.6.0' })
server.delete('/-/package/@scoped%2ffoo/dist-tags/b')
.reply(200, { b: '0.6.0' })

// rm
server.get('/-/package/@scoped%2fanother/dist-tags')
.reply(200, { latest: '4.0.0' })
Expand Down Expand Up @@ -232,6 +238,31 @@ test('npm dist-tags rm @scoped/another nonexistent', function (t) {
)
})

test('npm dist-tags rm with registry assigned to scope', function (t) {
fs.writeFileSync(path.resolve(pkg, '.npmrc'), `
@scoped:registry=${common.registry}
${common.registry.replace(/^https?:/, '')}:_authToken=taken
`)

common.npm(
[
'dist-tags',
'rm', '@scoped/foo', 'b',
'--loglevel', 'silent',
'--userconfig', path.resolve(pkg, '.npmrc')
],
{ cwd: pkg },
function (er, code, stdout, stderr) {
t.ifError(er, 'npm access')
t.notOk(code, 'exited OK')
t.notOk(stderr, 'no error output')
t.equal(stdout, '-b: @scoped/foo@0.6.0\n')

t.end()
}
)
})

test('cleanup', function (t) {
t.pass('cleaned up')
rimraf.sync(pkg)
Expand Down

0 comments on commit 54b095d

Please # to comment.