Skip to content
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

[npm] Flag indirect transitive updates to be ignored by the FileUpdater #5873

Merged
merged 4 commits into from
Oct 12, 2022

Conversation

mctofu
Copy link
Contributor

@mctofu mctofu commented Oct 11, 2022

When we need to update a parent dependency to fix an alert on a transitive child dependency we currently return both the parent & child as dependencies to update. Only the parent actually needs to be directly updated as its child dependencies will be automatically updated as part of that process. Still, we include the child dependency in the updated dependency list so it will be included in the PR title/description for context.

Since introducing #5822 that means we'll attempt to do a sub-dependency update of the child which has no effect.

This adds a flag to indicate dependencies returned by the updater that don't need to be directly updated and then filters them out before sending them to the FileUpdater. This also works for removed dependencies so we no longer need to filter them explicitly.

I'm making use of the new dependency metadata field that was added in #5801. It's currently meant for temporary data that doesn't need to be persisted or used in equals checks so I ended up working on some custom matchers to help validate the metadata output in tests. Let me know if theres a better way I could have done that!

@mctofu mctofu force-pushed the mctofu/optimize-transitive-update branch from b8ddf55 to 3beae68 Compare October 11, 2022 20:47
@mctofu mctofu marked this pull request as ready for review October 11, 2022 21:02
@mctofu mctofu requested a review from a team as a code owner October 11, 2022 21:02
Copy link
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization!

# Ignore dependencies that are tagged as information_only. These will be
# updated indirectly as a result of a parent dependency update and are
# only included here to be included in the PR info.
deps_to_update = updated_dependencies.reject { |d| d.metadata[:information_only] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the thought of whether it makes sense to move this to a dependency method like #informational_only? or something, but I'm not sure if other ecosystems will need something like this so probably premature. I just thought that deps_to_update = updated_dependencies.reject(&:informational_only?) would read a bit better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I was on the fence about adding that but you've persuaded me!

@@ -1426,14 +1443,15 @@
let(:registry_listing_url) { "https://registry.npmjs.org/transitive-dependency-locked-by-intermediate" }

it "correctly updates the transitive dependency" do
expect(checker.send(:updated_dependencies_after_full_unlock)).to eq([
expect(checker.send(:updated_dependencies_after_full_unlock)).to eq_with_metadata([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I would maybe have chosen eq_including_metadata but I'm not great at English 😛.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that wording better as well so updated to use it!

@mctofu mctofu force-pushed the mctofu/optimize-transitive-update branch from dbac3c2 to 9930d5f Compare October 12, 2022 21:46
mctofu and others added 3 commits October 12, 2022 14:47
Co-authored-by: David Rodriguez <deivid-rodriguez@riseup.net>
Co-authored-by: David Rodriguez <deivid-rodriguez@riseup.net>
@mctofu mctofu force-pushed the mctofu/optimize-transitive-update branch from 9930d5f to c92d679 Compare October 12, 2022 21:47
@mctofu mctofu merged commit 119fcb0 into main Oct 12, 2022
@mctofu mctofu deleted the mctofu/optimize-transitive-update branch October 12, 2022 23:26
@pavera pavera mentioned this pull request Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants