npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] Version 7.x Nerfs JSON Output for Install Command #2773

Open bdkjones opened 3 years ago

bdkjones commented 3 years ago

Summary:

npm 7.x seriously nerfed the usefulness of the --json flag when paired with the install command. (It may have done so with other commands as well; I've only tested install.)

I do realize that --json is marked experimental for all commands other than ls and search, but this is a MASSIVE regression in usefulness. I can understand changing the structure of the returned JSON, etc. while the feature is experimental, but nuking all of the details and returning only the bare minimum summary information must be an inadvertent change, right?

This makes npm exceptionally difficult to integrate with build tools and scripts. I've rolled back from 7.x until this can be addressed. Thanks!

Current Behavior:

Using npm 7.5.3 run this command: npm install jquery --json

The output produced is:

{
  "added": 1,
  "removed": 0,
  "changed": 0,
  "audited": 2,
  "funding": 0,
  "audit": {
    "vulnerabilities": {
      "info": 0,
      "low": 0,
      "moderate": 0,
      "high": 0,
      "critical": 0,
      "total": 0
    },
    "dependencies": {
      "prod": 2,
      "dev": 0,
      "optional": 0,
      "peer": 0,
      "peerOptional": 0,
      "total": 1
    }
  }
}

Expected Behavior:

Here's what npm < 7 spits out for the same command.

Notice the detail in added—we can see what was done, not just how many things were done.

{
  "added": [
    {
      "action": "add",
      "name": "jquery",
      "version": "3.5.1",
      "path": "/Users/bdkjones/Desktop/untitled folder/node_modules/jquery"
    }
  ],
  "removed": [],
  "updated": [],
  "moved": [],
  "failed": [],
  "warnings": [],
  "audit": {
    "actions": [],
    "advisories": {},
    "muted": [],
    "metadata": {
      "vulnerabilities": {
        "info": 0,
        "low": 0,
        "moderate": 0,
        "high": 0,
        "critical": 0
      },
      "dependencies": 1,
      "devDependencies": 0,
      "optionalDependencies": 0,
      "totalDependencies": 1
    }
  },
  "funding": "",
  "elapsed": 745
}

Steps To Reproduce:

1) Just run npm install [any package name] --json on npm 7.x and compare the output to npm 6.x and below.

Environment:

bdkjones commented 3 years ago

Sort-of related (in that another JSON thing got broken): #2740

bdkjones commented 3 years ago

Any progress on this? It's a very large regression from 6.x and I hate staying on an outdated version of npm.

lukekarrys commented 3 years ago

Thanks for the report @bdkjones. I'm tracking down issues like this as we're working on a larger epic of how npm writes output to the terminal. This will likely come after that, but I agree that the additional information is very helpful.