-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix npm_and_yarn engine detection #11392
Conversation
2da40d9
to
403bf06
Compare
Thanks @ntkme ! Can you please add a test please? |
424692b
to
b1b823e
Compare
@abdulapopoola Test added. For reference, the added test fails on the main branch with:
It passes with the fix in this PR. |
7f1f8ae
to
1d1c8b2
Compare
@ntkme , Sorry for let reply. Checking it now. |
Thank you, @ntkme, for identifying the issue and proposing a solution. I’ll be making further updates to enhance the stability of the solution. Once it’s ready, I’ll let you know. CC: @abdulapopoola |
does this PR also fix the following cases?
|
@jkowalleck As you’ve noticed, there are some version range syntax that are currently not parsable, but supporting those additional syntax is out of my scope of this PR, which is just fixing the side effect of In my opinion additional range syntax can be a separate feature request, but I will leave it to @kbukum1 to decide what to do with other unsupported npm version range syntax. |
Thank you for the information, @ntkme. @jkowalleck, yes, I am currently working on this and plan to include semver specification validation as part of this PR. I believe it’s better to address all related issues together in one PR to ensure a comprehensive fix. CC: @abdulapopoola |
Hi @jkowalleck, just to clarify: the fix I am working on will handle all valid [semver specifications](https://semver.org/#ranges) for version ranges. However, it will not include support for If there's anything specific you believe is missing or should be addressed, please let me know! CC: @abdulapopoola |
As a user, any chance we can get this merged in and you work out further improvements later? We have multiple repositories not getting any security or dependabot updates due to this bug (assuming it fixes #11234 (comment), which I believe it does) |
Adds handler for null versions reqs ending up in requirements (#11396)
Hi @ntkme, @jkowalleck, @broksonic21, I’ve made changes to address most of the issues related to checking engine constraints and retrieving versions from constraints. Please let me know if you see any issue that is not covered related to that? @ntkme, I’ve retained your changes, particularly the spec modifications, and integrated them with the new implementation. If the new changes are accepted successfully, they should align with the solution you initially proposed. Looking forward to your feedback! CC: @abdulapopoola |
Review Tip: We’ve implemented a more comprehensive method for extracting versions from constraints, ensuring that the version is obtained only when it fits the requirements and does not risk issues such as version deprecation. This approach focuses on providing accurate version detection without causing unintended behavior. Note: We return versions from constraints only when we can confidently determine the version falls within the same major version or is an exact match. For example, constraints like CC: @sachin-sandhu , @abdulapopoola |
This change improves our ability to detect the version from the To provide a more accurate answer, I would need additional details about your configuration, such as the Tagging @amazimbe, who may have more insight into the specific scenarios where the unsupported error is raised. |
In my case, these would be for packages that don't specify an engines field or have a committed lockfile in the repo, a scenario not uncommon in module codebases. This arrangement has been working in dependabot for years prior to whatever change was deployed last week. EDIT: Related issue #11373 It's really important you restore previous functionality as whatever was changed last week effectively disabled dependeabot on thousands (at least!) of modules. |
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.
Approving after the discussion.
Thanks both. The unsupported error is only raised when we detect npm 6 as the version. https://github.com/dependabot/dependabot-core/blob/main/npm_and_yarn/lib/dependabot/npm_and_yarn/helpers.rb#L61 . if the npm lockfile has no content or it's version is >=2, the detected version will be npm8. Otherwise, we return npm 6. |
In some cases, the package.json engines field also defined "npm": ">=10" but received the same unsupported error starting last week. It seems like if no npm version is specified anywhere, or the engine parsing/resolution fails for whatever reason, you should default to whatever version ships with node lts with a warning, rather than defaulting to not working. |
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.
To me looks good. Please proceed.
else | ||
Dependabot.logger.warn("Unrecognized constraint format for #{name}: #{constraint}") | ||
constraint | ||
end |
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.
To ensure a safe deployment, a feature flag has been added.
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.
LGTM
Hi @ntkme, The feature flag for this change is now enabled. I’d greatly appreciate your feedback on whether everything is working as intended or if you encounter any issues. If the approach proves problematic, I may disable the feature flag and address any concerns. Thank you for your time and support! |
Can you clarify? All of my repos have this issue. Dependabot updates were working before this issue, which I assume they passed before because they used whatever npm version came with the node version and that npm version was acceptable. I believe I am the typical case on Github (no All my repos have their A search on Github reveals 801 PRs are affected which may reflect the typical case I described. Before I apply my fixes - from what I gathered from the previous comments and other issues, for These types of
These types of
Similarly for the
Are my assumptions correct? |
What are you trying to accomplish?
Detect
npm
engine version is broken without a lockfile even if the version is specified inpackage.json
in some cases:{ "packageManager": "[email protected]" }
works{ "engines": { "npm": "10.0.0" } }
works{ "engines": { "npm": ">=10" } }
is broken with messageNo version requirement found for npm
Anything you want to highlight for special attention from reviewers?
The root cause is that while trying to setup the engine,
delete_if
in ruby was used.delete_if
modifies the input array in place, and effectively removes entries from@engines
unless they match a very specific format.The side effect of removing valid entries from
@engines
breaks the version detection fromengines
at a later time.How will you know you've accomplished your goal?
I don't know for sure as I don't know how to test this end to end. I just manually walked through the code and found that the side effect seems to be the problem here.
dependabot-core/npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb
Lines 312 to 325 in 0a0e9c0
At line 312, the call to
detect_version
callsVersionSelector
and removesengines
entries not matching a specific format due to side effect usingdelete_if
:At line 325, because the
engines
entries got removed, it fails to detect the constraints:Checklist