-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix: dep flag calculation #8645
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
base: latest
Are you sure you want to change the base?
Conversation
A few more words on dep flags... Their intention is documented here: https://github.com/npm/cli/blob/latest/workspaces/arborist/README.md#package-dependency-flags
Pruning means both the The Consider the following
If Maybe another edge case that can be fixed by recalculating dep flags again after diffing? Or is it before diffing? After we check if a package is omitted but before we check if it is installable? I think there are a lot of subtle bugs caused by this fragile pre-calculation of dep flags and trying to keep it in sync. Why are dep flags pre-calculated at all? We only need them when pruning or handling install failures. Could this be done lazily in diff/reify? Why are dep flags persisted to lockfiles and not just re-calculated? Performance? Curiosity? Preserving inconsistent dep flag calculations across different npm versions? 🤔 |
I believe the reason is so that things like ref:
Do we have enough info from a shrinkwrap install to still calculate all of this without the flags IN the shrinkwrap? Does this question even make sense anymore (i.e. are we currently still pulling in the same info anyways that we would if the flags weren't in the shrinkwrap?) These are all good questions you have. I think this is a case of things making sense at the time, and the software having iterated enough over time that we can rethink some decisions. Removing these flags from the lockfile is a pretty significant breaking change, however. Making changes that aren't breaking would be the challenge here. Can we still persist them but have the new code ignore them? |
Yes, flags are always calculated from a tree. If shrinkwrap provides a tree, deps can be calculated. There are already many checks in shrinkwrap load that may set
Yes, very possible. Would be interesting to see if there is much of a performance difference too. I definitely won't be doing this in this PR and doubt I'll have any time for this in the near future. |
Yep understood, that's a much larger task than these cleanup PRs. |
node.peer = true | ||
node.resetDepFlags() | ||
} | ||
calcDepFlags(this.virtualTree, !this.#rootOptionProvided) |
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.
I don't think it needs to be part of this PR but we definitely have some duplicate/inefficient logic going on w/ this #rootOptionProvided
flag and the resetRoot
parameter. I will make a note to follow up after this PR clean some things up.
For instance in this block flagsSuspect
is only true if rootOptionProvided
is not true.
peer
andoptional
- these flags don't mean that this node is an optional peer!extraneous
when following optional peer edges (how fix: prune optional peer dependencies that are no longer explicitly depended on #8431, should have been fixed)if ((!edge.to && edge.type !== 'peerOptional') || !edge.valid) {
)shake out Link target timing issue
test, which was testing code removed a while backselflink
fixture when writing snapshotsFixes #8535, the last issue being that
encoding
was incorrectly pruned on subsequent installs. See the below dependency diagram produced fromlatest
branch (since 11.6.1).Code to generate
Note that
encoding
should not have thepeer
flag. This incorrect flag plus the incorrect pruning ofoptional && peer
when building ideal tree from shrinkwrap causes this node to be removed from the tree.encoding
s de-deduped deps (not shown) were NOT removed and whencheckEngineAndPlatform
marks@abandonware/bluetooth-hci-socket
asinert
, it cannot follow the removed node to also mark these deps asinert
. No longerinert
, the diff algorithm now sees them as missing and they are installed.