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: properly show npm view ./directory #4576

Merged
merged 1 commit into from
Mar 17, 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
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 by ' + u.name + ' 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 @@ yellow@1.0.1 'claudia'
yellow@1.0.2 '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 @@ -262,6 +262,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 @@ -387,6 +390,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