如何找出实际安装的凉亭包的版本?

时间:2022-01-31 07:10:51

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).

通常,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.

我有一个自动化过程,需要立即找到该系统上实际安装的bower包的版本。

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

如何以编程方式(仅版本本身)找到它,理想情况下使用标准的Unix命令行工具/ bower命令?

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).

bower info 没有显示这一点 - 它显示了当前可用于bower存储库的信息(例如,即使我执行bower info apackageIdonthaveinstalled,它仍将显示包含版本号的有效JSON结构)。

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).

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

3 个解决方案

#1


24  

Here's a grep command to do that: grep "version\"\:" bower_components/thepackagename/.bower.json

这是一个grep命令:grep“version \”\:“bower_components / thepackagename / .bower.json

Also, a command to see versions of all bower components for the project - this list can be a handy CI artefact: grep "version\"\:" bower_components/*/.bower.json 如何找出实际安装的凉亭包的版本?

此外,还有一个命令可以查看项目所有bower组件的版本 - 这个列表可以是一个方便的CI artefact:grep“version \”\:“bower_components / * /。bower.json

#2


6  

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

cat bower_components / thepackagename / .bower.json | node_modules / json / lib / json.js版本

(note the extra . in .bower.json).

(注意.bower.json中的额外内容)。

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

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

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).

(例如,如果我感兴趣的包是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).

    我必须重复包名称(虽然这可能会通过更好的Perl脚本来改进,它也会过滤行,我只是在懒惰)。

  • 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获取有关所有已安装软件包的信息,而不仅仅是我感兴趣的软件包 - 其余信息将被丢弃。

  • 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.

有兴趣看看是否可以改进,尤其是最后一点。

#3


5  

Have you ever tried "bower list --json=0 --offline".

你有没有试过“凉亭列表--json = 0 --offline”。

It would list all bower packages info.

它将列出所有凉亭包信息。

#1


24  

Here's a grep command to do that: grep "version\"\:" bower_components/thepackagename/.bower.json

这是一个grep命令:grep“version \”\:“bower_components / thepackagename / .bower.json

Also, a command to see versions of all bower components for the project - this list can be a handy CI artefact: grep "version\"\:" bower_components/*/.bower.json 如何找出实际安装的凉亭包的版本?

此外,还有一个命令可以查看项目所有bower组件的版本 - 这个列表可以是一个方便的CI artefact:grep“version \”\:“bower_components / * /。bower.json

#2


6  

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

cat bower_components / thepackagename / .bower.json | node_modules / json / lib / json.js版本

(note the extra . in .bower.json).

(注意.bower.json中的额外内容)。

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

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

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).

(例如,如果我感兴趣的包是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).

    我必须重复包名称(虽然这可能会通过更好的Perl脚本来改进,它也会过滤行,我只是在懒惰)。

  • 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获取有关所有已安装软件包的信息,而不仅仅是我感兴趣的软件包 - 其余信息将被丢弃。

  • 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.

有兴趣看看是否可以改进,尤其是最后一点。

#3


5  

Have you ever tried "bower list --json=0 --offline".

你有没有试过“凉亭列表--json = 0 --offline”。

It would list all bower packages info.

它将列出所有凉亭包信息。