-
-
Notifications
You must be signed in to change notification settings - Fork 108
feat: allow NPM autodiscovery to ignore version constraint #6360
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
Conversation
Signed-off-by: Olblak <[email protected]>
Signed-off-by: Olblak <[email protected]>
…ecified Signed-off-by: Olblak <[email protected]>
Signed-off-by: Olblak <[email protected]>
Signed-off-by: Olblak <[email protected]>
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.
Pull Request Overview
This PR introduces a new feature allowing NPM autodiscovery to optionally ignore version constraints defined in package.json, enabling updates to the latest available version regardless of specified constraints. By default, the new ignoreversionconstraints parameter is set to true.
Key changes:
- Added
IgnoreVersionConstraintsfield to the Spec struct with default behavior to ignore constraints - Introduced
HasVersionConstraintmatching rule to filter packages based on version constraint presence - Implemented
convertSemverVersionConstraintToVersionutility to extract versions from constraints
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/plugins/autodiscovery/npm/main.go | Added IgnoreVersionConstraints configuration field and logic to set default behavior |
| pkg/plugins/autodiscovery/npm/dependency.go | Implemented version constraint handling logic based on the new ignore flag |
| pkg/plugins/autodiscovery/npm/utils.go | Added utility function to convert version constraints to semantic versions |
| pkg/plugins/autodiscovery/npm/utils_test.go | Added comprehensive tests for version constraint conversion |
| pkg/plugins/autodiscovery/npm/matchingRule.go | Added HasVersionConstraint field and matching logic |
| pkg/plugins/autodiscovery/npm/matchingRule_test.go | Added tests for version constraint matching rules |
| pkg/plugins/autodiscovery/npm/main_test.go | Added integration tests for ignore version constraint behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…tecli into autodiscovery/npm_constraint
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.
Pull Request Overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: Olblak <[email protected]>
Signed-off-by: Olblak <[email protected]>
…tecli into autodiscovery/npm_constraint
This pull request allows ignoring version constraint from packages.json
After using the NPM autodiscovery plugin for a while, I realize that It would be better to ignore version constraint by default and to suggest the latest version available regardless of the constraint defined in the package.json
More context from here to understand the initial design.
This new behavior can be enabled/disabled using the new parameter
ignoreversionconstraints.By default it's set to false (no breaking change)
Here is an example
While working on this, I am also adding a new matchingrule named "hasversionconstraint" to be able to only/ignore npm modules with or without a version constraint.
If a version constraint is detected and the ignoreVersionConstraint flag is set to true, the code initially sets the version filter pattern to a wildcard (*), meaning any version is acceptable. However, if a custom version filter is also defined and the dependency version is not "latest", it attempts to convert the version constraint into a specific version.
If a version constraint exists but ignoreVersionConstraint is false and a version filter is defined, the code logs a warning. This is because the system does not currently support applying both the package's version constraint and an additional version filter at the same time, as there is no clear use case for this scenario.
Finally, if no version constraint is present, the code constructs a default filter pattern that matches versions greater than or equal to the specified dependency version. If a custom version filter is defined, it uses the filter's kind and attempts to generate a more specific pattern.
Test
To test this pull request, you can run the following commands:
Additional Information
Checklist
Tradeoff
Potential improvement