简体   繁体   English

如何找到 github 存储库中使用的 npm 模块的版本?

[英]How can I find what version of an npm module is used across github repo?

I have an npm module I develop.我有一个我开发的 npm 模块。 I want to know which version of this module is being used across the different projects in my company's organization repository.我想知道我公司组织存储库中的不同项目正在使用该模块的哪个版本。 Is there a way to run a search for a specific versions of a module?有没有办法搜索模块的特定版本?

For example my latest version of the module is "5.xx" .例如我最新版本的模块是"5.xx" I want to find all usages that are not "^5.xx" .我想找到所有不是"^5.xx"的用法。

I tried searching for filename:package.json my-module but this gives me too many results, which most of them is the latest version ( "^5.xx" ).我尝试搜索filename:package.json my-module但这给了我太多结果,其中大多数是最新版本( "^5.xx" )。

Maybe there is some other way to achieve it which is not the Github search?也许还有其他方法可以实现它,而不是 Github 搜索?

Edit :编辑

  • The organization repository is huge and it is impossible to have it all cloned on the disk.组织存储库很大,不可能将其全部克隆到磁盘上。
  • In our organization we have a solution that solves this problem using coding (a service that manages all dependencies across the organization which exposes REST).在我们的组织中,我们有一个解决方案,它使用编码(一种管理整个组织的所有依赖项的服务,它公开了 REST)来解决这个问题。 I am looking for something that can be achieved easily without coding (too much).我正在寻找无需编码(太多)即可轻松实现的东西。

You can use find and grep commands in Bash:您可以在 Bash 中使用findgrep命令:

$ cd path/to/your/repo
$ find . -name package.json | xargs grep '"my_module":'

This command lists all lines with your module in all package.json files across the repository.此命令列出存储库中所有 package.json 文件中包含您的模块的所有行。 If this yields too many results, you can grep some more, for example:如果这会产生太多结果,您可以grep更多一些,例如:

$ find . -name package.json | xargs grep '"my_module":' | grep -v '\^5\.'

which excludes any lines mentioning your module with major version number of 5.其中不包括任何提及您的模块的主要版本号为 5 的行。

Given the restrictions placed on GitHub search , it's unlikely you'll be able to easily do this in the GitHub interface.鉴于对 GitHub 搜索的限制,您不太可能在 GitHub 界面中轻松执行此操作。

If you have all your repositories cloned inside a single directory and you're on a UNIX-like operating system, you can use grep (or do all kinds of programmatic searches):如果您将所有存储库克隆到一个目录中,并且您使用的是类 UNIX 操作系统,则可以使用grep (或进行各种编程搜索):

grep '"my-module": ' */package.json | grep -v '"\^5\.'

The above assumes that the entry starts with ^ and not ~ or a digit.以上假设条目以^而不是~或数字开头。 Modify as needed.根据需要进行修改。 In your case, it's probably fine.在你的情况下,它可能没问题。 If it isn't, it will show some version 5 instances, which is better than having it not show earlier instances.如果不是,它将显示一些版本 5 实例,这比显示早期实例要好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM