Alexander Mills Alexander Mills - 6 days ago 4
Node.js Question

view local NPM packages that depend on package X

I am getting some

node-gyp
warnings for a particular NPM package, in this case the package is "get-cursor-position". I would like to find out which packages in my local node_modules directory depend on this package. (This might not be easy to do).

if I run:

$ npm view get-cursor-position


I get:

{ name: 'get-cursor-position',
description: 'Get the cursor\'s current position in your terminal.',
'dist-tags': { latest: '1.0.3' },
versions:
[ '0.0.1',
'0.0.2',
'0.0.4',
'0.0.5',
'1.0.0',
'1.0.1',
'1.0.2',
'1.0.3' ],
maintainers: [ 'bubkoo <bubkoo@163.com>' ],
time:
{ modified: '2016-11-01T02:36:07.728Z',
created: '2016-03-05T03:42:31.517Z',
'0.0.1': '2016-03-05T03:42:31.517Z',
'0.0.2': '2016-03-07T00:35:36.627Z',
'0.0.4': '2016-03-10T07:21:21.364Z',
'0.0.5': '2016-03-10T07:25:04.846Z',
'1.0.0': '2016-04-16T08:11:34.546Z',
'1.0.1': '2016-06-03T15:57:55.767Z',
'1.0.2': '2016-06-13T14:19:32.966Z',
'1.0.3': '2016-11-01T02:36:07.728Z' },
homepage: 'https://github.com/bubkoo/get-cursor-position',
keywords: [ 'terminal', 'console', 'cursor', 'position', 'ansi', 'escape' ],
repository:
{ type: 'git',
url: 'git+https://github.com/bubkoo/get-cursor-position.git' },
author: 'bubkoo <bubkoo.wy@gmail.com>',
bugs: { url: 'https://github.com/bubkoo/get-cursor-position/issues' },
license: 'MIT',
readmeFilename: 'README.md',
version: '1.0.3',
main: 'index.js',
scripts:
{ test: 'echo "Error: no test specified" && exit 1',
install: 'node-gyp rebuild' },
gypfile: true,
gitHead: '56d403bb0e554532d17c403c47421ce8d2db2dec',
dist:
{ shasum: '0e41d60343b705836a528d69a5e099e2c5108d63',
tarball: 'https://registry.npmjs.org/get-cursor-position/-/get-cursor-position-1.0.3.tgz' },
directories: {} }


I believe npm view will just look up the remote data for the package, I am happy to use the aggregate data on NPM showing all the packages that depend on
get-cursor-position
, and I can do some manual work on my end to compare with local packages.

I also tried:

npm ls foo


In my case, I tried:

npm ls suman-events


and it didn't seem to pick up what I expected it to pick up. I would have expected it to pick up "suman-example-reporter" in my case =>

as you can see in the image below, "suman-example-reporter" is a direct dependency in my project (it's in package.json) and suman-example-reporter depends on "suman-events" (and "suman-events" is in package.json as well, because it's also a direct dependency of my project).

enter image description here

Anyone know how to do this right?

Answer

The npm ls <options> command is definitely what you want. Here are the docs for the command:

https://docs.npmjs.com/cli/ls

it says

"When run as ll or la, it shows extended information by default."

So to get a full list of dependencies in your project that depend on x, try:

$ npm la x

instead of

$ npm ls x