Content-Length: 331662 | pFad | http://github.com/npm/cli/commit/45835c80745b9b293ac75b7faea747d2c516d925

B5 fix(pkg): return json result when multiple arguments where provided b… · npm/cli@45835c8 · GitHub
Skip to content

Commit 45835c8

Browse files
committed
fix(pkg): return json result when multiple arguments where provided but not all exist in package.json
1 parent ecd2d23 commit 45835c8

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/commands/pkg.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ class Pkg extends BaseCommand {
6363

6464
if (args.length) {
6565
result = new Queryable(result).query(args)
66-
// in case there's only a single result from the query
67-
// just prints that one element to stdout
66+
// in case there's only a single argument and a single result from the query
67+
// just prints that one element to stdout.
6868
// TODO(BREAKING_CHANGE): much like other places where we unwrap single
6969
// item arrays this should go away. it makes the behavior unknown for users
7070
// who don't already know the shape of the data.
71-
if (Object.keys(result).length === 1) {
71+
if (Object.keys(result).length === 1 && args.length === 1) {
7272
result = result[args]
7373
}
7474
}

test/lib/commands/pkg.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ t.test('get multiple arg', async t => {
108108
)
109109
})
110110

111+
t.test('get multiple arg with only one arg existing', async t => {
112+
const { pkg, OUTPUT } = await mockNpm(t, {
113+
prefixDir: {
114+
'package.json': JSON.stringify({
115+
name: 'foo',
116+
}),
117+
},
118+
})
119+
120+
await pkg('get', 'name', 'version', 'dependencies')
121+
122+
t.strictSame(
123+
JSON.parse(OUTPUT()),
124+
{
125+
name: 'foo',
126+
},
127+
'should print retrieved package.json field'
128+
)
129+
})
130+
111131
t.test('get multiple arg with empty value', async t => {
112132
const { pkg, OUTPUT } = await mockNpm(t, {
113133
prefixDir: {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/npm/cli/commit/45835c80745b9b293ac75b7faea747d2c516d925

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy