-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly label packages as dev-only in yarn audit #6970
Conversation
|
Much better, thanks! It looks good to me - @rally25rs, want to have a look? |
Anything I can do to help this through? 🙏 |
@arcanis Bump |
@arcanis? 😁 |
@arcanis @rally25rs I've just rebased off latest master. I'd really appreciate if I could get some further 👀 here. |
Hey - sorry for not taking a look sooner. Most of my time the past few week has been spent on the v2 codebase, and since I'm not super familiar with the audit code it wasn't at the top of my priorities 😅 I'll try to take a look this week unless @rally25rs beats me to it 🙂 |
Sorry for the extremely slow response... I remember just ignoring the prod vs dev thing when I originally did the audit code because there wasn't an easy way to tell from the data that was available. I'll try to take a look at this as soon as I find some free time. Do you know what will happen if a dep is both a prod and a dev dep? From a quick glance at the code I think it might flag it as a dev dep, which I think it only should if it is also not in the production deps tree. |
This isn't the case; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's unfortunate that we have to traverse over all the packages again, but not sure that there is a better solution given the information we have available at that time.
Thanks for the contribution, and sorry again that this took so long to look at. 👍
Thanks for taking the time @arcanis @rally25rs 😁 |
Summary
yarn audit
currently does not distinguish packages that are depended on only in dev versus packages that are depended on in prod (in particular it doesn't send adev: true
key in the payload for the registry audit API endpoint).Because of this, the registry endpoint implicitly assumes that every package is depended on in prod, and yields
dev: false
for every finding of every advisory it uncovers, even if that instance of the package is only a (transitive) dev dependency.yarn audit --json
basically echos the response verbatim, hence those findings are incorrectly labelled as affecting production in the output.I initially attempted to fix this in #6910. While that solution worked adequately, I was told (and I agree) that the additional complexity introduced to the hoister wasn't worth the improvement.
In this PR, I take an alternative approach: I introduced a new utility function that, given a package manifest, workspace layout, and lockfile, walks the dependency tree, enumerating transitive dependencies that are strictly development-only (i.e. transitive development dependencies that are not also transitive production dependencies).
With this machinery, we can enumerate dev-only dependencies in
yarn audit
, and trivially label any such dependencies withdev: true
in the request. This causes the registry to correctly label any advisories against such dependencies withdev: true
in the response. Sinceyarn audit --json
basically echoes the response from the registry verbatim, we get the correct client-side behavior for free.In the interest of keeping the PR small and focused, I didn't add the dev-vs.-prod information to the human-readable output of
yarn audit
.Test plan
Running
yarn audit --json
and trimming out the noise:1.13.0
My PR
In the first case, the second advisory's findings are incorrectly labelled as affecting production; my PR demonstrates the correct behavior.