如何确定实际安装了什么版本的Bower软件包? [英] How do I find out what version of a bower package is actually installed?

查看:216
本文介绍了如何确定实际安装了什么版本的Bower软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常bower.json文件会指定一些依赖关系,但是通常会表达这些依赖关系,以使它们允许使用Bower软件包的各种版本(例如,>=1.0,意味着版本高于1.0的任何版本).

我有一个自动化的过程,该过程需要查找当前在此系统上实际安装了什么版本的Bower软件包.

我怎样才能以编程方式(仅是版本本身)找到问题,理想情况下是使用标准Unix命令行工具/bower命令?

bower info <thepackagename>不会显示此内容-它显示有关Bower存储库中当前可用内容的信息(例如,即使执行bower info apackageIdonthaveinstalled,它仍将显示包含以下内容的有效JSON结构:版本号.

cat bower_components/thepackagename/bower.json | node_modules/json/lib/json.js version适用于某些软件包(假设已安装npm软件包json),但并非全部(例如jquery 2.2.0的bower软件包不包含bower.json).

解决方案

我现在发现的最佳方法似乎适用于我迄今为止遇到的每个软件包,

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

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

bower似乎在.bower.json中存储了一些有关已安装软件包的元数据,其中包括已安装的版本.

<罢工> 到目前为止,我想出的最好的方法是:

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

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

由于多种原因,这很丑陋:

  • 我必须重复软件包名称(尽管可能会有所改善 更好的Perl脚本也可以过滤行,我只是很懒.)

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

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

将有兴趣查看是否可以对此进行改进,尤其是最后一点.

Normally a bower.json file specifies some dependencies, but these are typically expressed so that they allow a range of versions of a bower package to be used (e.g. >=1.0, which means anything higher than version 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> does not show this - it shows information about what is currently available from the bower repository (for example, even if I do bower info apackageIdonthaveinstalled it will still show a valid JSON structure containing a version number).

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

(note the extra . in .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/'

(if, for example, the package I was interested in was jquery).

That's pretty ugly for a variety of reasons:

  • 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 gets information about all installed packages, not just the one I'm interested in - the rest of the information is discarded.

  • bower list seems to require internet connectivity to check the registry, otherwise it fails.

Would be interested to see if this could be improved upon, particularly the last point.

这篇关于如何确定实际安装了什么版本的Bower软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆