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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/commands/view.js
Original file line number Diff line number Diff line change
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') {
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
Original file line number Diff line number Diff line change
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', ['[email protected]']),
{ code: 'E404', pkgid: '[email protected]', message: 'No match found for version 2.0.0' }
)
})

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