我需要为我的客户提供我们项目的所有依赖项(库名称+ github / npm url)。只需在每个项目中使用npm ll,我就可以轻松地做到这一点。但是这给了我一个树状结构的输出。有没有办法将此输出更改为表?
我已经阅读了npm ll命令的文档,但我没有找到任何东西。
发布于 2019-03-05 00:55:47
如果所有方法都失败了,您可以使用jq提取所需的内容
npm ll --json | jq -r 'recurse(.dependencies[]) | [.name, .version, .repository.url?] | @csv'
示例输出:
"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"发布于 2019-03-04 22:50:33
我不确定它是否完全回答了这个问题,但您始终可以将输出修改为更易于管理的内容-例如,以下脚本:
#!/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]}
donehttps://stackoverflow.com/questions/54983949
复制相似问题