Reputation: 2431
I need to provide my client with all dependencies of our projects (library name + github / npm url). I can do this easily with just npm ll
inside every project. But this gives me a tree-structured output. Is there a way to change this output to a table?
I've read the documentation of npm ll command and I haven't found anything.
Upvotes: 2
Views: 954
Reputation: 169
If all else fails, you can extract what you need using jq:
npm ll --json | jq -r 'recurse(.dependencies[]) | [.name, .version, .repository.url?] | @csv'
Sample output:
"express","4.16.4","git+https://github.com/expressjs/express.git"
"accepts","1.3.5","git+https://github.com/jshttp/accepts.git"
"mime-types","2.1.22","git+https://github.com/jshttp/mime-types.git"
"mime-db","1.38.0","git+https://github.com/jshttp/mime-db.git"
"negotiator","0.6.1","git+https://github.com/jshttp/negotiator.git"
Upvotes: 2
Reputation: 3321
Not sure it fully answers the question, but you can always rework the output to something more manageable - for instance a script such as:
#!/bin/bash
# list packages and remove tree structure prefix + "deduped" suffix (keep only module@version)
data=($(npm ls | sed 's/^[┬├│─└ ]*//g' | sed 's/deduped$//g'))
for module in ${data[*]}
do
# split on @ only when it separates module and version
# (not the @ prefix on @username/module@version)
split=($(echo $module | sed -r 's/^(.+)@/\1 /'))
# an example display
printf "%-30s%10s https://www.npmjs.org/packages/%s\n" ${split[0]} ${split[1]} ${split[0]}
done
Upvotes: 2