Skip to content

fix(view): error on missing version #5035

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

Merged
merged 15 commits into from
Jun 22, 2022
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