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] Preserve requirement source when updating transtive dep parents #5816

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

mctofu
Copy link
Contributor

@mctofu mctofu commented Sep 30, 2022

We had been setting the source of transitive parent dependencies to nil but this caused the FileUpdater to think the requirement was always changing. This might not be the case for a library with a requirement range that already allows the fixed version. We should prefer to preserve the existing source when an updated source is not provided.

Example:

#<Dependabot::Dependency:0x0000558c3bf7fc48
 @name="serverless-offline",
 @package_manager="npm_and_yarn",
 @previous_requirements=
  [{:requirement=>"8",
    :file=>"package.json",
    :groups=>["devDependencies"],
    :source=>{:type=>"registry", :url=>"https://registry.npmjs.org"}}],
 @previous_version="8.8.0",
 @removed=false,
 @requirements=[{:requirement=>"8", :file=>"package.json", :groups=>["devDependencies"], :source=>nil}],
 @version="8.8.1">

The version is updating from 8.8.0 to 8.8.1 but because this came from a library the requirement did not need to change. However, the source change between the previous/current requirements triggers an attempt to update package.json which results in this failure:

updater | ERROR <> Expected content to change!
updater | ERROR <> /home/dependabot/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/package_json_updater.rb:36:in `block (2 levels) in updated_package_json_content'

The smoke test is failing on this PR because its expectations don't currently include the source populated in the new requirements.

@mctofu mctofu force-pushed the mctofu/transitive-parent-preserve-source branch from 634a816 to c8f27d6 Compare September 30, 2022 17:41
@mctofu mctofu marked this pull request as ready for review September 30, 2022 17:55
@mctofu mctofu requested a review from a team as a code owner September 30, 2022 17:55
@mctofu mctofu changed the title Preserve requirement source when updating transtive dep parents [npm] Preserve requirement source when updating transtive dep parents Sep 30, 2022
@mctofu mctofu force-pushed the mctofu/transitive-parent-preserve-source branch from c8f27d6 to aec9d34 Compare September 30, 2022 23:53
We had been setting the source of the parents to nil but this caused the
FileUpdater to think the requirement was always changing. This might not
be the case for a library with a requirement range that already allows
the fixed version. We should prefer to preserve the existing source when
an updated source is not provided.
@mctofu mctofu force-pushed the mctofu/transitive-parent-preserve-source branch from aec9d34 to ba24176 Compare October 3, 2022 22:02
mctofu added a commit to dependabot/smoke-tests that referenced this pull request Oct 3, 2022
The changes in dependabot/dependabot-core#5816 mean that we expect the source to be populated now. Adjust this test expectation to match.
@mctofu mctofu merged commit 86b4fdf into main Oct 3, 2022
@mctofu mctofu deleted the mctofu/transitive-parent-preserve-source branch October 3, 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