Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to audit dependencies in Yarn 2 (berry)?

I'm looking for a way to audit dependencies for vulnerabilities in Yarn 2. In Yarn 1.x it was possible the same was as in npm, by running yarn audit instead of npm audit. But with Yarn 2 there is no such command. And according to this issue on the berry github, it won't be implemented (project maintainers prefer it was done via plugin).

I have tried running npm install --package-lock-only && npm audit but the install chokes on some of my local packages (which I am listing in package.json using the link: url type).

It wouldn't be a complex plugin to build and I'm up for some fun doing so, but it would not be so muchfun as just installing something and then going about my day. I have looked around but always end up at the same couple of vapourware / abandonware repos.

But I still guess that I'm just not finding them. Or there's an undocumented trick for making it easy. Hence my question :)

PS, yeah I can delete the local packages using link: temporarily while I run the npm install and npm audit commands above, but it's not exactly the kind of thing I want to try and automate for CI.

like image 302
Julian Suggate Avatar asked Aug 11 '20 16:08

Julian Suggate


1 Answers

Update (28-Oct-2020):
Yarn 2 just merged long-awaited yarn npm audit enhancement.

PR - https://github.com/yarnpkg/berry/pull/1892
Docs - https://yarnpkg.com/cli/npm/audit


I was experimenting with Yarn 2 recently, and I saw that you can do this with @efrem/auditdeps utility:

yarn dlx @efrem/auditdeps [--level=(low|moderate|high|critical)] [--production]

The output is not as pretty as from npm audit, but you get more details in JSON format and you can pipe it to other tools or to any custom reformatting script to get exactly what you want.

like image 94
Anton Avatar answered Sep 22 '22 21:09

Anton