0

I would like to list all NPM packages available in a repository on GitHub and use code parsing to get just needed information of the packages using PowerShell.

How do I identify these packages?. if they are in packages.json file, there seems to be many of the "packages.json" file name in some repos.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Why do you want to do this? (And why does seeing multiple `package.json` files surprise you?) – Dai Jan 19 '22 at 07:32
  • I am new to NPM packages. And I just want to list out all NPM packages available in a repo. it is basically for a Github repo audit i am doing using PowerShell and Github API – Caleb Adepoju Jan 19 '22 at 07:49
  • NPM already maintains its own package-to-repo database, so there's no need to do it yourself. You describe it as an "audit" but it sounds like you're running your code on public repos instead of your org's own and internal repos, which sounds like a fool's errand to me because plenty of software projects don't have a `package.json` file at all in their repos, but will generate a `package.json` as part of their build-process, and your scripts won't be able to detect that. – Dai Jan 19 '22 at 07:51
  • I understand that the package.json file is generated as part of the build process. I just need to get information about the package names from the json file. – Caleb Adepoju Jan 19 '22 at 17:33
  • That wasn't my point - my point was that there will still be project repos that don't have any package.json or any other JSON files with the package name hardcoded in it - and there is nothing you can do to try to get those. – Dai Jan 19 '22 at 17:36
  • Yea I agree, However in this case I will work with what I can get from the package.json files – Caleb Adepoju Jan 19 '22 at 19:05

1 Answers1

0

You can see multiple package.json files are part of nested dependencies, as seen here.

If you somehow had to see those dependencies (direct and indirect) as one package.json, that is what json-merge or package-merge are for.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250