4

I have an npm module I develop. 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.x.x". I want to find all usages that are not "^5.x.x".

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

Maybe there is some other way to achieve it which is not the Github search?

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). I am looking for something that can be achieved easily without coding (too much).
Technotronic
  • 8,424
  • 4
  • 40
  • 53

2 Answers2

1

You can use find and grep commands in Bash:

$ 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. If this yields too many results, you can grep some more, for example:

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

which excludes any lines mentioning your module with major version number of 5.

Jindra Helcl
  • 3,457
  • 1
  • 20
  • 26
  • 1
    I'm guessing the search needs to be across all repos in an org, on GitHub, without cloning. – jessehouwing Nov 28 '20 at 16:55
  • In that case, maybe using github search API to get all the package.json URLs, download these into a folder and do a grep over these files.. – Jindra Helcl Nov 28 '20 at 17:04
  • The `find` command here will end up grabbing all the `package.json` files of subdependencies. That's not necessarily a bad thing although it could greatly slow the command. It's not what the OP is doing in the question, where they're searching just `package.json` in the project itself on GitHub. – Trott Nov 28 '20 at 17:17
1

Given the restrictions placed on GitHub search, it's unlikely you'll be able to easily do this in the GitHub interface.

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

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.

Trott
  • 66,479
  • 23
  • 173
  • 212