@@ -68,6 +68,25 @@ class VersionSolver {
68
68
for (final package in _root.transitiveWorkspace) package.name: package,
69
69
};
70
70
71
+ /// Set of direct dependencies from root pubspec.yaml
72
+ late final Set <String > _rootDirectDependencies = _root.pubspec.dependencies
73
+ .keys.toSet ();
74
+
75
+ /// Returns true if the root's direct dependency for [packageName] is stable
76
+ /// (not prerelease)
77
+ bool _isRootDirectDependencyStable (String packageName) {
78
+ final dep = _root.pubspec.dependencies[packageName];
79
+ if (dep == null ) return false ;
80
+ final constraint = dep.constraint;
81
+ if (constraint is Version ) {
82
+ return ! constraint.isPreRelease;
83
+ }
84
+ if (constraint is VersionRange && constraint.min != null ) {
85
+ return ! constraint.min! .isPreRelease;
86
+ }
87
+ return false ;
88
+ }
89
+
71
90
/// The lockfile, indicating which package versions were previously selected.
72
91
final LockFile _lockFile;
73
92
@@ -398,7 +417,14 @@ class VersionSolver {
398
417
399
418
PackageId ? version;
400
419
try {
401
- version = await _packageLister (package).bestVersion (package.constraint);
420
+ // Prereleases are allowed only if not direct or not stable.
421
+ final isDirect = _rootDirectDependencies.contains (package.name);
422
+ final isStable = _isRootDirectDependencyStable (package.name);
423
+ final allowPrereleases = ! (isDirect && isStable);
424
+ version = await _packageLister (package).bestVersion (
425
+ package.constraint,
426
+ allowPrereleases: allowPrereleases,
427
+ );
402
428
} on PackageNotFoundException catch (error) {
403
429
_addIncompatibility (
404
430
Incompatibility ([
0 commit comments