通常,bower.json文件指定一些依赖项,但这些依赖项通常被表示为允许使用Bower包的一系列版本(例如,>=1.0,这意味着任何高于1.0版的版本).

I have an automated process which needs to find what version of a bower package is actually installed on this system right now.

How can I find this out programmatically (just the version itself), ideally using standard Unix command line tools / the bower command?

bower info <thepackagename>not确实显示了这一点-它显示了有关Bower存储库当前可用内容的信息(例如,即使我显示bower info apackageIdonthaveinstalled,它仍然会显示包含版本号的有效JSON struct ).

cat bower_components/thepackagename/bower.json | node_modules/json/lib/json.js version works for some packages (assuming the npm package json is installed), but not all (e.g. jquery 2.2.0's bower package does not contain a bower.json).

推荐答案

The best approach I've now found, which seems to work for every package I've come across so far, is:

cat bower_components/thepackagename/.bower.json | node_modules/json/lib/json.js version

(注意.bower.json中额外的.).

It would appear that bower stores some metadata about the installed package in .bower.json, and that includes the installed version.

The best I've come up with so far is:

bower list | grep jquery | perl -pe 's/.*jquery#(.*?) .*$/$1/'

(例如,如果我感兴趣的包裹是jquery).

这是相当丑陋的,原因有很多:

  • I have to repeat the package name (although this could probably be improved with a better Perl script which filters lines too, I'm just being lazy).

  • bower list获取所有已安装软件包的信息,而不仅仅是我感兴趣的软件包——其余信息将被丢弃.

  • bower list似乎需要互联网连接才能判断注册表,否则它会失败.

我很想看看是否可以改进,尤其是最后一点.

Json相关问答推荐

筛选JSON数组以使用Jolt仅保留具有最新日期/时间的条目

PowerShell:将Invoke-WebRequest与变量一起使用

对面的行/列进行排序时可能出现错误

递归解码嵌套列表(具有任意深度的列表列表)

使用 jq 重新格式化 JSON 输出

json 字符串到 Postgres 14 中的表视图

如何用 Xidel 正确读取这个 JSON 文件?

N1QL 聚合查询 Couchbase

一起使用 Argparse 和 Json

为什么我不能在 C# 中引用 System.Runtime.Serialization.Json

JSON 语法错误:'unexpected number' 或 'JSON.parse: expected ',' or '}' after property value in object'

读取 HttpwebResponse json 响应,C#

使用杰克逊创建一个 json 对象

有什么方法可以在 elasticsearch 服务器中导入 json 文件(包含 100 个文档).?

Jackson:忽略 Json 配置值

如何访问 JSON 对象数组的第一个元素?

如何让 javascript 从 .json 文件中读取?

如何在spark 上将json字符串转换为数据帧

使用 JSONArray 和 JSONObject 进行 Foreach

在播放框架 JsObject 中解析 Json 数组