-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(dart): use first version of constraint for dependencies using SDK version #6239
feat(dart): use first version of constraint for dependencies using SDK version #6239
Conversation
This PR is stale because it has been labeled with inactivity. |
// firstVersionOfConstrain returns the first acceptable version for constraint | ||
func firstVersionOfConstrain(constraint string) string { | ||
// cf. https://dart.dev/tools/pub/dependencies#traditional-syntax | ||
switch { | ||
case strings.HasPrefix(constraint, ">="): | ||
constraint = strings.TrimPrefix(constraint, ">=") | ||
constraint, _, _ = strings.Cut(constraint, " ") | ||
return constraint | ||
case strings.HasPrefix(constraint, "^"): | ||
return strings.TrimPrefix(constraint, "^") | ||
} | ||
return "" | ||
} |
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 think we want to parse the constraints in a more stable way. What if we export constraint
and add methods like func (c *Constraint) Version() string
and func (c *Constraint) Operator() string
in go-version?
https://github.com/aquasecurity/go-version/blob/637058cfe4921e395b56f195224538d7eac61520/pkg/version/constraint.go#L55-L59
type Constraint struct {
version Version
operator string // e.g. "=", ">=", "^"
operatorFunc operatorFunc
original string
}
func (c *Constraint) Version() string {
return c.version
}
func (c *Constraint) Operator() string {
return c.operator
}
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.
Good idea!
Created aquasecurity/go-version#6
And updated this PR - 0bbe7c5
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.
Merged
aquasecurity/go-version#6
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.
Updated this PR -91c2b1b
f70d7ac
to
eb67467
Compare
// cf. https://dart.dev/tools/pub/dependencies#traditional-syntax | ||
constraints := css.List() | ||
// We only need to get the first version from the range | ||
if constraints[0][0].Operator() != ">=" && constraints[0][0].Operator() != "^" { |
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.
Can we check the length of constratints
so it won't panic? I presume css.List()
doesn't return empty, but unexpected things always happen. It's better to ensure it's non-empty.
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.
it won't hurt.
Added check in 35a6f0a
Signed-off-by: knqyf263 <knqyf263@gmail.com>
if constraint, ok := l.Sdks[string(dep.Description)]; ok { | ||
v, err := firstVersionOfConstrain(constraint) | ||
if err != nil { | ||
p.logger.Warn("unable to get sdk version from constraint: %w", log.Err(err)) |
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.
p.logger.Warn("unable to get sdk version from constraint: %w", log.Err(err)) | |
p.logger.Warn("Unable to get sdk version from constraint", log.Err(err)) |
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.
Fixed in 191270c
Description
Use first version of constraint for dependencies using SDK version.
e.g. in this case the version of
flutter_test
should be3.3.0
:More information in #5984
Related issues
Checklist