Skip to content

Commit

Permalink
fix: properly show npm view ./directory (#4576)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored Mar 17, 2022
1 parent 2361a68 commit 84d1921
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class View extends BaseCommand {
// put the version back if it existed
pkg = `${manifest.name}${pkg.slice(1)}`
}

let wholePackument = false
if (!args.length) {
args = ['']
Expand Down Expand Up @@ -196,7 +197,7 @@ class View extends BaseCommand {
// get the data about this package
let version = this.npm.config.get('tag')
// rawSpec is the git url if this is from git
if (spec.type !== 'git' && spec.rawSpec) {
if (spec.type !== 'git' && spec.type !== 'directory' && spec.rawSpec) {
version = spec.rawSpec
}

Expand All @@ -205,7 +206,6 @@ class View extends BaseCommand {
if (pckmnt['dist-tags'] && pckmnt['dist-tags'][version]) {
version = pckmnt['dist-tags'][version]
}

if (pckmnt.time && pckmnt.time.unpublished) {
const u = pckmnt.time.unpublished
const er = new Error(`Unpublished on ${u.time}`)
Expand Down
17 changes: 17 additions & 0 deletions tap-snapshots/test/lib/commands/view.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ [email protected] 'claudia'
[email protected] 'claudia'
`

exports[`test/lib/commands/view.js TAP should log info of package in current working dir directory > must match snapshot 1`] = `
blue@1.0.0 | Proprietary | deps: none | versions: 2
dist
.tarball:http://hm.blue.com/1.0.0.tgz
.shasum:123
.integrity:---
.unpackedSize:1 B
dist-tags:
latest: 1.0.0
published {TIME} ago
`

exports[`test/lib/commands/view.js TAP should log info of package in current working dir non-specific version > must match snapshot 1`] = `
Expand Down
8 changes: 8 additions & 0 deletions test/lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ const packument = (nv, opts) => {
if (nv.type === 'git') {
return mocks[nv.hosted.project]
}
if (nv.raw === './blue') {
return mocks.blue
}
return mocks[nv.name]
}

Expand Down Expand Up @@ -390,6 +393,11 @@ t.test('should log info of package in current working dir', async t => {
await view.exec(['.'])
t.matchSnapshot(logs)
})

t.test('directory', async t => {
await view.exec(['./blue'])
t.matchSnapshot(logs)
})
})

t.test('should log info by field name', async t => {
Expand Down

0 comments on commit 84d1921

Please sign in to comment.