File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,7 +48,13 @@ func (p *Package) dependsOn(dep Node) bool {
4848 return done
4949}
5050
51- func comparePackages (a , b * Package ) int {
51+ // ComparePackages compares two WIT packages, based on dependence.
52+ // When used with [slices.SortFunc], this function will sort packages
53+ // based on their mutual dependence. Packages with fewer or no dependencies will sort last.
54+ // If package a depends on package b, this function returns 1.
55+ // If package b depends on package a, this function returns -1.
56+ // If package a == package b, this function returns 0.
57+ func ComparePackages (a , b * Package ) int {
5258 // fmt.Fprintln(os.Stderr, "comparing "+b.Name.String()+" to "+a.Name.String())
5359 switch {
5460 case a == b :
Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ func (*Resolve) WITKind() string { return "resolve" }
133133func (r * Resolve ) WIT (ctx Node , _ string ) string {
134134 // Sort packages topologically by dependency
135135 packages := slices .Clone (r .Packages )
136- slices .SortFunc (packages , comparePackages )
136+ slices .SortFunc (packages , ComparePackages )
137137 slices .Reverse (packages )
138138
139139 var b strings.Builder
You can’t perform that action at this time.
0 commit comments