Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(view): error on missing version #5035

Merged
merged 15 commits into from Jun 22, 2022
Merged
9 changes: 9 additions & 0 deletions lib/commands/view.js
Expand Up @@ -236,6 +236,15 @@ class View extends BaseCommand {
}
})

// No data has been pushed because no data is matching the specified version
if (data.length === 0 && version !== 'latest') {
fritzy marked this conversation as resolved.
Show resolved Hide resolved
const er = new Error(`No match found for version ${version}`)
er.statusCode = 404
er.code = 'E404'
er.pkgid = `${pckmnt._id}@${version}`
throw er
}

if (
!this.npm.config.get('json') &&
args.length === 1 &&
Expand Down
9 changes: 9 additions & 0 deletions test/lib/commands/view.js
Expand Up @@ -33,6 +33,7 @@ const packument = (nv, opts) => {
},
},
blue: {
_id: 'blue',
name: 'blue',
'dist-tags': {
latest: '1.0.0',
Expand Down Expand Up @@ -464,6 +465,14 @@ t.test('throws when unpublished', async t => {
)
})

t.test('throws when version not matched', async t => {
const { npm } = await loadMockNpm(t)
await t.rejects(
npm.exec('view', ['blue@2.0.0']),
{ code: 'E404', pkgid: 'blue@2.0.0', message: 'No match found for version 2.0.0' }
)
})

t.test('workspaces', async t => {
const prefixDir = {
'package.json': JSON.stringify({
Expand Down