Skip to content

Commit e07422a

Browse files
committed
feat: sort the dev and runtime packages in bsf.hcl
Signed-off-by: hanshal101 <122217807+hanshal101@users.noreply.github.com>
1 parent a2c73d1 commit e07422a

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

cmd/init/config.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"regexp"
8+
"sort"
89
"strings"
910

1011
"github.com/buildsafedev/bsf/pkg/hcl2nix"
@@ -64,8 +65,8 @@ func generateEmptyConf(imageName string, addCommonDeps bool, commonDepsType stri
6465
}
6566
return hcl2nix.Config{
6667
Packages: hcl2nix.Packages{
67-
Development: devDeps,
68-
Runtime: commonRTDeps,
68+
Development: sortPackages(devDeps),
69+
Runtime: sortPackages(commonRTDeps),
6970
},
7071
OCIArtifact: []hcl2nix.OCIArtifact{
7172
{
@@ -109,8 +110,8 @@ func genRustCargoConf() (hcl2nix.Config, error) {
109110
rustDevDeps := append(commonDevDeps, rustDeps...)
110111
return hcl2nix.Config{
111112
Packages: hcl2nix.Packages{
112-
Development: rustDevDeps,
113-
Runtime: commonRTDeps,
113+
Development: sortPackages(rustDevDeps),
114+
Runtime: sortPackages(commonRTDeps),
114115
},
115116
RustApp: &hcl2nix.RustApp{
116117
WorkspaceSrc: "./.",
@@ -126,8 +127,8 @@ func genPythonPoetryConf() hcl2nix.Config {
126127
poetryDevDeps := append(commonDevDeps, pythonDeps...)
127128
return hcl2nix.Config{
128129
Packages: hcl2nix.Packages{
129-
Development: poetryDevDeps,
130-
Runtime: commonRTDeps,
130+
Development: sortPackages(poetryDevDeps),
131+
Runtime: sortPackages(commonRTDeps),
131132
},
132133
PoetryApp: &hcl2nix.PoetryApp{
133134
ProjectDir: "./.",
@@ -157,9 +158,9 @@ func genGoModuleConf(pd *langdetect.ProjectDetails) hcl2nix.Config {
157158
goDevDeps := append(commonDevDeps, goDeps...)
158159
return hcl2nix.Config{
159160
Packages: hcl2nix.Packages{
160-
Development: goDevDeps,
161+
Development: sortPackages(goDevDeps),
161162
// todo: maybe we should dynamically inject the latest version of such runtime packages(cacert)?
162-
Runtime: commonRTDeps,
163+
Runtime: sortPackages(commonRTDeps),
163164
},
164165
GoModule: &hcl2nix.GoModule{
165166
Name: name,
@@ -188,12 +189,19 @@ func genJsNpmConf() (hcl2nix.Config, error) {
188189
nodeDevDeps := append(commonDevDeps, jsNpmDeps...)
189190
return hcl2nix.Config{
190191
Packages: hcl2nix.Packages{
191-
Development: nodeDevDeps,
192-
Runtime: commonRTDeps,
192+
Development: sortPackages(nodeDevDeps),
193+
Runtime: sortPackages(commonRTDeps),
193194
},
194195
JsNpmApp: &hcl2nix.JsNpmApp{
195196
PackageName: name,
196197
PackageRoot: "./.",
197198
},
198199
}, nil
199200
}
201+
202+
func sortPackages(packages []string) []string {
203+
sort.Slice(packages, func(i, j int) bool {
204+
return strings.Split(packages[i], "@")[0] < strings.Split(packages[j], "@")[0]
205+
})
206+
return packages
207+
}

pkg/strings/set.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package strings
22

3+
import (
4+
"sort"
5+
"strings"
6+
)
7+
38
type parse func(string) string
49

510
// SliceToSet converts a slice of strings to a set of strings
@@ -42,6 +47,10 @@ func PreferNewSliceElements(existing []string, new []string, parseFunc parse) []
4247
finalEle = append(finalEle, v)
4348
}
4449

50+
sort.Slice(finalEle, func(i, j int) bool {
51+
return strings.Split(finalEle[i], "@")[0] < strings.Split(finalEle[j], "@")[0]
52+
})
53+
4554
return finalEle
4655
}
4756

0 commit comments

Comments
 (0)