Content-Length: 321096 | pFad | http://github.com/npm/cli/pull/7855/commits/45835c80745b9b293ac75b7faea747d2c516d925

76 fix(pkg): display if any of multiple attributes exist by Sanderovich · Pull Request #7855 · npm/cli · GitHub
Skip to content

fix(pkg): display if any of multiple attributes exist #7855

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

Merged
merged 1 commit into from
Oct 18, 2024
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
fix(pkg): return json result when multiple arguments where provided b…
…ut not all exist in package.json
  • Loading branch information
Sanderovich committed Oct 18, 2024
commit 45835c80745b9b293ac75b7faea747d2c516d925
6 changes: 3 additions & 3 deletions lib/commands/pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ class Pkg extends BaseCommand {

if (args.length) {
result = new Queryable(result).query(args)
// in case there's only a single result from the query
// just prints that one element to stdout
// in case there's only a single argument and a single result from the query
// just prints that one element to stdout.
// TODO(BREAKING_CHANGE): much like other places where we unwrap single
// item arrays this should go away. it makes the behavior unknown for users
// who don't already know the shape of the data.
if (Object.keys(result).length === 1) {
if (Object.keys(result).length === 1 && args.length === 1) {
result = result[args]
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/lib/commands/pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ t.test('get multiple arg', async t => {
)
})

t.test('get multiple arg with only one arg existing', async t => {
const { pkg, OUTPUT } = await mockNpm(t, {
prefixDir: {
'package.json': JSON.stringify({
name: 'foo',
}),
},
})

await pkg('get', 'name', 'version', 'dependencies')

t.strictSame(
JSON.parse(OUTPUT()),
{
name: 'foo',
},
'should print retrieved package.json field'
)
})

t.test('get multiple arg with empty value', async t => {
const { pkg, OUTPUT } = await mockNpm(t, {
prefixDir: {
Expand Down
Loading








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/pull/7855/commits/45835c80745b9b293ac75b7faea747d2c516d925

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy