# node_runtime: Fix npm v12 output deserialization \(\#60798\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/8c4550cb95d88a1841a1d6cfcf5e092d313745a1)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 8c4550cb95d88a1841a1d6cfcf5e092d313745a1

Requested commit: 8c4550cb95d88a1841a1d6cfcf5e092d313745a1

Commit: 8c4550cb95d88a1841a1d6cfcf5e092d313745a1

Tree: aef22f227a3d75ee71fb16f8869e00c7f9a3831c

Author: Vitaly Slobodin

Committer: GitHub

## Message

```
node_runtime: Fix npm v12 output deserialization (#60798)

# Objective

- Fix npm v12 output deserialization
- Fixes #60705

## Solution

Initially I was thinking about checking the `npm` version and then
parsing its output accordingly but that would
include a call to `npm --version`. Zed's mojo is to be blazingly fast so
just checking the structure of the output should be enough:

1. `npm info --json` in v12 produces an array with 1 object: `[ {
"name": "something" } ]`
2. `npm info --json` in v11 and older produces an object: `{ "name":
"something" }`

So the trick is to check the output: if it's an array, we have npm v12,
otherwise npm v11.

## Testing

- Did you test these changes? If so, how?

   1. Ensure you have `npm` v12 installed.
2. Install a Node.js based language server, for example, `markdownlint`
or `oxfmt`
   3. Open a project and trigger start of a language server

- Are there any parts that need more testing?

   no

- How can other people (reviewers) test your changes? Is there anything
specific they need to know?

   Use steps above

- If relevant, what platforms did you test these changes on, and are
there any important ones you can't test?

   I've tested this on macOS and Linux.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [ ] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Showcase

N/A

---

Release Notes:

- Fixed npm v12 output deserialization
```

## Parents

- [5b7b970d08eb273af8e0e74e6a389be8384b21b1](https://git.cafe/gitcafe/zed/commit/5b7b970d08eb273af8e0e74e6a389be8384b21b1?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/8c4550cb95d88a1841a1d6cfcf5e092d313745a1?format=markdown)
