Description
Is there an existing issue for this?
- I have searched the existing issues
This is a CLI Docs Problem, not another kind of Docs Problem.
- This is a CLI Docs Problem.
Description of Problem
When using npm ls
, with no depth
option specified, the output is the same as when npm ls --depth=0
is specified. The documentation npm ls --depth however states that the default depth is 1
, not 0
:
depth
- Default:
Infinity
if--all
is set, otherwise1
- Type: null or Number
The depth to go when recursing packages for
npm ls
.If not set,
npm ls
will show only the immediate dependencies of the root project. If--all
is set, then npm will show all dependencies by default.
Steps to reproduce
Ubuntu 24.04.1
LTS, Node.js v22.12.0
LTS
npm v10.9.2
git clone https://github.com/npm/cli
cd cli
git checkout v10.9.2
npm ci
npm install npm@latest -g
npm -v
npm ls | wc -l
npm ls --depth=0 | wc -l
npm ls --depth=1 | wc -l
npm ls --depth=2 | wc -l
Results
Line count resulting from running npm ls --depth=n
against https://github.com/npm/cli tag v10.9.2
npm ls --depth=n |
Line count |
---|---|
unspecified | 276 |
0 |
276 |
1 |
592 |
2 |
1086 |
Potential Solution
Change the documented default depth for npm ls --depth
from 1
to 0