Skip to content

Commit

Permalink
fix: unpublish with scoped registry
Browse files Browse the repository at this point in the history
Unpublish now works if you have a scoped registry config
  • Loading branch information
wraithgar authored and fritzy committed Feb 1, 2023
1 parent 328c3d8 commit 1525a5e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Unpublish extends BaseCommand {

async getKeysOfVersions (name, opts) {
const pkgUri = npa(name).escapedName
const json = await npmFetch.json(`${pkgUri}?write=true`, opts)
const json = await npmFetch.json(`${pkgUri}?write=true`, {
...opts,
spec: name,
})
return Object.keys(json.versions)
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mock-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const setupMockNpm = async (t, {
acc.env[`process.env."npm_config_${key}"`] = value
} else {
const values = [].concat(value)
acc.argv.push(...values.flatMap(v => [`--${key}`, v.toString()]))
acc.argv.push(...values.flatMap(v => `--${key}=${v.toString()}`))
}
acc.config[key] = value
return acc
Expand Down
40 changes: 35 additions & 5 deletions test/lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ t.test('no args --force success', async t => {
})
const manifest = registry.manifest({ name: pkg })
await registry.package({ manifest, query: { write: true } })
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
registry.unpublish({ manifest })
await npm.exec('unpublish', [])
t.equal(joinedOutput(), '- [email protected]')
})
Expand Down Expand Up @@ -148,7 +148,7 @@ t.test('no version found in package.json', async t => {
})
const manifest = registry.manifest({ name: pkg })
await registry.package({ manifest, query: { write: true } })
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
registry.unpublish({ manifest })

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

await npm.exec('unpublish', ['test-package'])
t.equal(joinedOutput(), '- test-package')
Expand Down Expand Up @@ -361,7 +361,7 @@ t.test('publishConfig no spec', async t => {
})
const manifest = registry.manifest({ name: pkg })
await registry.package({ manifest, query: { write: true } })
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
registry.unpublish({ manifest })
await npm.exec('unpublish', [])
t.equal(joinedOutput(), '- [email protected]')
})
Expand Down Expand Up @@ -391,11 +391,41 @@ t.test('publishConfig with spec', async t => {
})
const manifest = registry.manifest({ name: pkg })
await registry.package({ manifest, query: { write: true }, times: 2 })
registry.nock.delete(`/${pkg}/-rev/${manifest._rev}`).reply(201)
registry.unpublish({ manifest })
await npm.exec('unpublish', ['test-package'])
t.equal(joinedOutput(), '- test-package')
})

t.test('scoped registry config', async t => {
const scopedPkg = `@npm/test-package`
const alternateRegistry = 'https://other.registry.npmjs.org'
const { npm } = await loadMockNpm(t, {
config: {
force: true,
'@npm:registry': alternateRegistry,
'//other.registry.npmjs.org/:_authToken': 'test-other-token',
},
prefixDir: {
'package.json': JSON.stringify({
name: pkg,
version: '1.0.0',
publishConfig: {
registry: alternateRegistry,
},
}, null, 2),
},
})
const registry = new MockRegistry({
tap: t,
registry: alternateRegistry,
authorization: 'test-other-token',
})
const manifest = registry.manifest({ name: scopedPkg })
await registry.package({ manifest, query: { write: true } })
registry.unpublish({ manifest })
await npm.exec('unpublish', [scopedPkg])
})

t.test('completion', async t => {
const { npm } = await loadMockNpm(t, {
config: {
Expand Down

0 comments on commit 1525a5e

Please sign in to comment.