Skip to content

Commit 24c38e4

Browse files
committed
code is not cleaner, but doing optional dependencies now too and sorting from top to bottom the semversions
1 parent 34aefed commit 24c38e4

7 files changed

Lines changed: 187 additions & 298 deletions

File tree

cmd/devguard-cli/test/author.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/devguard-cli/test/export.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmd/devguard-cli/test/output.json

Lines changed: 0 additions & 247 deletions
This file was deleted.

cmd/devguard-cli/test/package_manager_functions.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,26 @@ func timeoutDetection(err error) {
1717
// check if error is a timeout error
1818
}
1919

20+
// VersionExists checks if a package version exists on npm registry
21+
func VersionExists(dependency string, version string) bool {
22+
normalizedVersion := strings.Trim(version, "/^\"")
23+
url := "https://registry.npmjs.org/" + dependency + "/" + normalizedVersion
24+
25+
resp, err := http.Head(url)
26+
if err != nil {
27+
return false
28+
}
29+
defer resp.Body.Close()
30+
31+
return resp.StatusCode == 200
32+
}
33+
2034
// get all versions if no version is specified
2135
func GetNPMRegistry(pkg RegistryRequest) (*http.Response, error) {
2236
var req *http.Response
2337
var err error
2438

25-
normalizedVersion := strings.Trim(pkg.Version, "^\"") // remove quotes if present
39+
normalizedVersion := strings.Trim(pkg.Version, "/") // remove quotes if present
2640

2741
if pkg.Version != "" {
2842
req, err = http.Get("https://registry.npmjs.org/" + pkg.Dependency + "/" + normalizedVersion)
@@ -45,8 +59,7 @@ func GetCratesRegistry(pkg RegistryRequest) (*http.Response, error) {
4559
var err error
4660

4761
if pkg.Version != "" {
48-
normalizedVersion := strings.Trim(pkg.Version, "^\"") // remove quotes if present
49-
req, err = http.Get("https://crates.io/api/v1/crates/" + pkg.Dependency + "/" + normalizedVersion)
62+
req, err = http.Get("https://crates.io/api/v1/crates/" + pkg.Dependency + "/" + pkg.Version)
5063
} else {
5164
req, err = http.Get("https://crates.io/api/v1/crates/" + pkg.Dependency)
5265
}

0 commit comments

Comments
 (0)