Skip to content

Commit 02c837e

Browse files
isaacszkat
authored andcommitted
dist-tag: make 'ls' the default action (#106)
I keep typing `npm dist-tags` expecting it to print out a list of dist-tags and instead it yells at me and that feels very un-npm-y. PR-URL: #106 Credit: @isaacs Reviewed-By: @zkat
1 parent 890a744 commit 02c837e

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

doc/cli/npm-dist-tag.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Add, remove, and enumerate distribution tags on a package:
2626
Show all of the dist-tags for a package, defaulting to the package in
2727
the current prefix.
2828

29+
This is the default action if none is specified.
30+
2931
A tag can be used when installing packages as a reference to a version instead
3032
of using a specific version number:
3133

lib/dist-tag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function distTag (args, cb) {
4040
case 'ls': case 'l': case 'sl': case 'list':
4141
return list(args[0], cb)
4242
default:
43-
return cb('Usage:\n' + distTag.usage)
43+
return list(cmd, cb)
4444
}
4545
}
4646

test/tap/dist-tag.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ function mocks (server) {
2020
server.get('/-/package/@scoped%2fpkg/dist-tags')
2121
.reply(200, { latest: '1.0.0', a: '0.0.1', b: '0.5.0' })
2222

23+
server.get('/-/package/@scoped%2fpkg/dist-tags')
24+
.reply(200, { latest: '1.0.0', a: '0.0.1', b: '0.5.0' })
25+
2326
// ls named package
2427
server.get('/-/package/@scoped%2fanother/dist-tags')
2528
.reply(200, { latest: '2.0.0', a: '0.0.2', b: '0.6.0' })
2629

30+
server.get('/-/package/@scoped%2fanother/dist-tags')
31+
.reply(200, { latest: '2.0.0', a: '0.0.2', b: '0.6.0' })
32+
2733
// add c
2834
server.get('/-/package/@scoped%2fanother/dist-tags')
2935
.reply(200, { latest: '2.0.0', a: '0.0.2', b: '0.6.0' })
@@ -83,6 +89,25 @@ test('npm dist-tags ls in current package', function (t) {
8389
)
8490
})
8591

92+
test('npm dist-tags ls default in current package', function (t) {
93+
common.npm(
94+
[
95+
'dist-tags',
96+
'--registry', common.registry,
97+
'--loglevel', 'silent'
98+
],
99+
{ cwd: pkg },
100+
function (er, code, stdout, stderr) {
101+
t.ifError(er, 'npm access')
102+
t.notOk(code, 'exited OK')
103+
t.notOk(stderr, 'no error output')
104+
t.equal(stdout, 'a: 0.0.1\nb: 0.5.0\nlatest: 1.0.0\n')
105+
106+
t.end()
107+
}
108+
)
109+
})
110+
86111
test('npm dist-tags ls on named package', function (t) {
87112
common.npm(
88113
[
@@ -103,6 +128,26 @@ test('npm dist-tags ls on named package', function (t) {
103128
)
104129
})
105130

131+
test('npm dist-tags ls default, named package', function (t) {
132+
common.npm(
133+
[
134+
'dist-tags',
135+
'@scoped/another',
136+
'--registry', common.registry,
137+
'--loglevel', 'silent'
138+
],
139+
{ cwd: pkg },
140+
function (er, code, stdout, stderr) {
141+
t.ifError(er, 'npm access')
142+
t.notOk(code, 'exited OK')
143+
t.notOk(stderr, 'no error output')
144+
t.equal(stdout, 'a: 0.0.2\nb: 0.6.0\nlatest: 2.0.0\n')
145+
146+
t.end()
147+
}
148+
)
149+
})
150+
106151
test('npm dist-tags add @scoped/another@7.7.7 c', function (t) {
107152
common.npm(
108153
[

0 commit comments

Comments
 (0)