Skip to content

Commit 1525a5e

Browse files
wraithgarfritzy
authored andcommitted
fix: unpublish with scoped registry
Unpublish now works if you have a scoped registry config
1 parent 328c3d8 commit 1525a5e

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

lib/commands/unpublish.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class Unpublish extends BaseCommand {
2626

2727
async getKeysOfVersions (name, opts) {
2828
const pkgUri = npa(name).escapedName
29-
const json = await npmFetch.json(`${pkgUri}?write=true`, opts)
29+
const json = await npmFetch.json(`${pkgUri}?write=true`, {
30+
...opts,
31+
spec: name,
32+
})
3033
return Object.keys(json.versions)
3134
}
3235

test/fixtures/mock-npm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const setupMockNpm = async (t, {
206206
acc.env[`process.env."npm_config_${key}"`] = value
207207
} else {
208208
const values = [].concat(value)
209-
acc.argv.push(...values.flatMap(v => [`--${key}`, v.toString()]))
209+
acc.argv.push(...values.flatMap(v => `--${key}=${v.toString()}`))
210210
}
211211
acc.config[key] = value
212212
return acc

test/lib/commands/unpublish.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ t.test('no args --force success', async t => {
2727
})
2828
const manifest = registry.manifest({ name: pkg })
2929
await registry.package({ manifest, query: { write: true } })
30-
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
30+
registry.unpublish({ manifest })
3131
await npm.exec('unpublish', [])
3232
t.equal(joinedOutput(), '- [email protected]')
3333
})
@@ -148,7 +148,7 @@ t.test('no version found in package.json', async t => {
148148
})
149149
const manifest = registry.manifest({ name: pkg })
150150
await registry.package({ manifest, query: { write: true } })
151-
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
151+
registry.unpublish({ manifest })
152152

153153
await npm.exec('unpublish', [])
154154
t.equal(joinedOutput(), '- test-package')
@@ -168,7 +168,7 @@ t.test('unpublish <pkg> --force no version set', async t => {
168168
})
169169
const manifest = registry.manifest({ name: pkg })
170170
await registry.package({ manifest, query: { write: true }, times: 2 })
171-
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
171+
registry.unpublish({ manifest })
172172

173173
await npm.exec('unpublish', ['test-package'])
174174
t.equal(joinedOutput(), '- test-package')
@@ -361,7 +361,7 @@ t.test('publishConfig no spec', async t => {
361361
})
362362
const manifest = registry.manifest({ name: pkg })
363363
await registry.package({ manifest, query: { write: true } })
364-
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
364+
registry.unpublish({ manifest })
365365
await npm.exec('unpublish', [])
366366
t.equal(joinedOutput(), '- [email protected]')
367367
})
@@ -391,11 +391,41 @@ t.test('publishConfig with spec', async t => {
391391
})
392392
const manifest = registry.manifest({ name: pkg })
393393
await registry.package({ manifest, query: { write: true }, times: 2 })
394-
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
394+
registry.unpublish({ manifest })
395395
await npm.exec('unpublish', ['test-package'])
396396
t.equal(joinedOutput(), '- test-package')
397397
})
398398

399+
t.test('scoped registry config', async t => {
400+
const scopedPkg = `@npm/test-package`
401+
const alternateRegistry = 'https://other.registry.npmjs.org'
402+
const { npm } = await loadMockNpm(t, {
403+
config: {
404+
force: true,
405+
'@npm:registry': alternateRegistry,
406+
'//other.registry.npmjs.org/:_authToken': 'test-other-token',
407+
},
408+
prefixDir: {
409+
'package.json': JSON.stringify({
410+
name: pkg,
411+
version: '1.0.0',
412+
publishConfig: {
413+
registry: alternateRegistry,
414+
},
415+
}, null, 2),
416+
},
417+
})
418+
const registry = new MockRegistry({
419+
tap: t,
420+
registry: alternateRegistry,
421+
authorization: 'test-other-token',
422+
})
423+
const manifest = registry.manifest({ name: scopedPkg })
424+
await registry.package({ manifest, query: { write: true } })
425+
registry.unpublish({ manifest })
426+
await npm.exec('unpublish', [scopedPkg])
427+
})
428+
399429
t.test('completion', async t => {
400430
const { npm } = await loadMockNpm(t, {
401431
config: {

0 commit comments

Comments
 (0)