-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: pass strings to JSON.stringify in --json mode #7540
Conversation
053033c
to
ef96b6b
Compare
no statistically significant performance changes detected timing results
|
In refactoring this behavior previously plain strings were no longer being passed through JSON.stringify even in json mode. This commit changes that to the previous behavior which fixes the bug in `npm view`. This also required changing the behavior of `npm pkg` which relied on this. Fixes #7537
ef96b6b
to
8b03990
Compare
// Otherwise its an object with all items merged together | ||
return Object.assign({}, ...items) | ||
// Otherwise its an object with all object items merged together | ||
return Object.assign({}, ...items.filter(o => isPlainObject(o))) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
items is an array of objects, so i dont think it can be spread within another object in the same way as arguments to a function
> Object.assign({}, ...[{a:1},{b:2}])
{ a: 1, b: 2 }
> { ...[{a:1},{b:2}] }
{ '0': { a: 1 }, '1': { b: 2 } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh you're totally right
In refactoring this behavior previously plain strings were no longer
being passed through JSON.stringify even in json mode. This commit
changes that to the previous behavior which fixes the bug in
npm view
.This also required changing the behavior of
npm pkg
which relied on this.Fixes #7537