Skip to content

Commit 84d1921

Browse files
authored
fix: properly show npm view ./directory (#4576)
1 parent 2361a68 commit 84d1921

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/commands/view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class View extends BaseCommand {
103103
// put the version back if it existed
104104
pkg = `${manifest.name}${pkg.slice(1)}`
105105
}
106+
106107
let wholePackument = false
107108
if (!args.length) {
108109
args = ['']
@@ -196,7 +197,7 @@ class View extends BaseCommand {
196197
// get the data about this package
197198
let version = this.npm.config.get('tag')
198199
// rawSpec is the git url if this is from git
199-
if (spec.type !== 'git' && spec.rawSpec) {
200+
if (spec.type !== 'git' && spec.type !== 'directory' && spec.rawSpec) {
200201
version = spec.rawSpec
201202
}
202203

@@ -205,7 +206,6 @@ class View extends BaseCommand {
205206
if (pckmnt['dist-tags'] && pckmnt['dist-tags'][version]) {
206207
version = pckmnt['dist-tags'][version]
207208
}
208-
209209
if (pckmnt.time && pckmnt.time.unpublished) {
210210
const u = pckmnt.time.unpublished
211211
const er = new Error(`Unpublished on ${u.time}`)

tap-snapshots/test/lib/commands/view.js.test.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ [email protected] 'claudia'
6868
6969
`
7070

71+
exports[`test/lib/commands/view.js TAP should log info of package in current working dir directory > must match snapshot 1`] = `
72+
73+
74+
blue@1.0.0 | Proprietary | deps: none | versions: 2
75+
76+
dist
77+
.tarball:http://hm.blue.com/1.0.0.tgz
78+
.shasum:123
79+
.integrity:---
80+
.unpackedSize:1 B
81+
82+
dist-tags:
83+
latest: 1.0.0
84+
85+
published {TIME} ago
86+
`
87+
7188
exports[`test/lib/commands/view.js TAP should log info of package in current working dir non-specific version > must match snapshot 1`] = `
7289
7390

test/lib/commands/view.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ const packument = (nv, opts) => {
265265
if (nv.type === 'git') {
266266
return mocks[nv.hosted.project]
267267
}
268+
if (nv.raw === './blue') {
269+
return mocks.blue
270+
}
268271
return mocks[nv.name]
269272
}
270273

@@ -390,6 +393,11 @@ t.test('should log info of package in current working dir', async t => {
390393
await view.exec(['.'])
391394
t.matchSnapshot(logs)
392395
})
396+
397+
t.test('directory', async t => {
398+
await view.exec(['./blue'])
399+
t.matchSnapshot(logs)
400+
})
393401
})
394402

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

0 commit comments

Comments
 (0)