Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(), '- test-package@1.0.0')
})
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(), '- test-package@1.0.0')
})
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