From f47214b2b342da41c87942dfbbb75be2c7daf36f Mon Sep 17 00:00:00 2001 From: attiasas Date: Wed, 31 Jan 2024 17:07:27 +0200 Subject: [PATCH 1/4] Add pnpm technology --- utils/coreutils/techutils.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/coreutils/techutils.go b/utils/coreutils/techutils.go index 78e2321e6..ca63dc653 100644 --- a/utils/coreutils/techutils.go +++ b/utils/coreutils/techutils.go @@ -24,6 +24,7 @@ const ( Maven Technology = "maven" Gradle Technology = "gradle" Npm Technology = "npm" + Pnpm Technology = "pnpm" Yarn Technology = "yarn" Go Technology = "go" Pip Technology = "pip" @@ -77,7 +78,7 @@ var technologiesData = map[Technology]TechData{ }, Npm: { indicators: []string{"package.json", "package-lock.json", "npm-shrinkwrap.json"}, - exclude: []string{".yarnrc.yml", "yarn.lock", ".yarn"}, + exclude: []string{"pnpm-lock.yaml", ".yarnrc.yml", "yarn.lock", ".yarn"}, ciSetupSupport: true, packageDescriptors: []string{"package.json"}, formal: string(Npm), @@ -85,8 +86,16 @@ var technologiesData = map[Technology]TechData{ packageInstallationCommand: "install", applicabilityScannable: true, }, + Pnpm: { + indicators: []string{"pnpm-lock.yaml"}, + exclude: []string{".yarnrc.yml", "yarn.lock", ".yarn"}, + packageDescriptors: []string{"package.json"}, + packageVersionOperator: "@", + applicabilityScannable: true, + }, Yarn: { indicators: []string{".yarnrc.yml", "yarn.lock", ".yarn", ".yarnrc"}, + exclude: []string{"pnpm-lock.yaml"}, packageDescriptors: []string{"package.json"}, packageVersionOperator: "@", applicabilityScannable: true, From d7320456a58c748268b4f08993846f3d6b47c3c1 Mon Sep 17 00:00:00 2001 From: attiasas Date: Wed, 31 Jan 2024 17:17:23 +0200 Subject: [PATCH 2/4] fix tests --- utils/coreutils/techutils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/coreutils/techutils_test.go b/utils/coreutils/techutils_test.go index 7d170b9da..031e50d2f 100644 --- a/utils/coreutils/techutils_test.go +++ b/utils/coreutils/techutils_test.go @@ -78,7 +78,7 @@ func TestMapFilesToRelevantWorkingDirectories(t *testing.T) { paths: []string{filepath.Join("dir", "package.json"), filepath.Join("dir", ".yarn")}, requestedDescriptors: noRequest, expectedWorkingDir: map[string][]string{"dir": {filepath.Join("dir", "package.json"), filepath.Join("dir", ".yarn")}}, - expectedExcluded: map[string][]Technology{"dir": {Npm}}, + expectedExcluded: map[string][]Technology{"dir": {Npm, Pnpm}}, }, { name: "golangTest", From e122c6dc5f27cbf93caa000b2ac87ce5cfc09cc5 Mon Sep 17 00:00:00 2001 From: attiasas Date: Wed, 31 Jan 2024 17:26:51 +0200 Subject: [PATCH 3/4] fix flaky test --- utils/coreutils/techutils_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/coreutils/techutils_test.go b/utils/coreutils/techutils_test.go index 031e50d2f..6eb1447b6 100644 --- a/utils/coreutils/techutils_test.go +++ b/utils/coreutils/techutils_test.go @@ -138,13 +138,20 @@ func TestMapFilesToRelevantWorkingDirectories(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { detectedWd, detectedExcluded := mapFilesToRelevantWorkingDirectories(test.paths, test.requestedDescriptors) + // Assert working directories expectedKeys := maps.Keys(test.expectedWorkingDir) actualKeys := maps.Keys(detectedWd) assert.ElementsMatch(t, expectedKeys, actualKeys, "expected: %s, actual: %s", expectedKeys, actualKeys) for key, value := range test.expectedWorkingDir { assert.ElementsMatch(t, value, detectedWd[key], "expected: %s, actual: %s", value, detectedWd[key]) } - assert.True(t, reflect.DeepEqual(test.expectedExcluded, detectedExcluded), "expected: %s, actual: %s", test.expectedExcluded, detectedExcluded) + // Assert excluded + expectedKeys = maps.Keys(test.expectedExcluded) + actualKeys = maps.Keys(detectedExcluded) + assert.ElementsMatch(t, expectedKeys, actualKeys, "expected: %s, actual: %s", expectedKeys, actualKeys) + for key, value := range test.expectedExcluded { + assert.ElementsMatch(t, value, detectedExcluded[key], "expected: %s, actual: %s", value, detectedExcluded[key]) + } }) } } From ef4276849d1f0f7f5a702416ff6f78d127e53488 Mon Sep 17 00:00:00 2001 From: attiasas Date: Sun, 11 Feb 2024 10:58:21 +0200 Subject: [PATCH 4/4] add all tests for pnpm --- artifactory/commands/repository/template.go | 6 +++--- utils/coreutils/techutils_test.go | 23 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/artifactory/commands/repository/template.go b/artifactory/commands/repository/template.go index 4f4a6f59f..435df31b0 100644 --- a/artifactory/commands/repository/template.go +++ b/artifactory/commands/repository/template.go @@ -856,9 +856,9 @@ var questionMap = map[string]ioutils.QuestionInfo{ Writer: ioutils.WriteStringAnswer, }, PrimaryKeyPairRef: ioutils.FreeStringQuestionInfo, - Username: ioutils.FreeStringQuestionInfo, - Password: ioutils.FreeStringQuestionInfo, - Proxy: ioutils.FreeStringQuestionInfo, + Username: ioutils.FreeStringQuestionInfo, + Password: ioutils.FreeStringQuestionInfo, + Proxy: ioutils.FreeStringQuestionInfo, RemoteRepoChecksumPolicyType: { Options: []prompt.Suggest{ {Text: GenerateIfAbsentPolicy}, diff --git a/utils/coreutils/techutils_test.go b/utils/coreutils/techutils_test.go index 6eb1447b6..c69d58ebe 100644 --- a/utils/coreutils/techutils_test.go +++ b/utils/coreutils/techutils_test.go @@ -17,6 +17,7 @@ func TestDetectTechnologiesByFilePaths(t *testing.T) { }{ {"simpleMavenTest", []string{"pom.xml"}, map[Technology]bool{Maven: true}}, {"npmTest", []string{"../package.json"}, map[Technology]bool{Npm: true}}, + {"pnpmTest", []string{"../package.json", "pnpm-lock.yaml"}, map[Technology]bool{Pnpm: true}}, {"yarnTest", []string{"./package.json", "./.yarn"}, map[Technology]bool{Yarn: true}}, {"windowsGradleTest", []string{"c:\\users\\test\\package\\build.gradle"}, map[Technology]bool{Gradle: true}}, {"windowsPipTest", []string{"c:\\users\\test\\package\\setup.py"}, map[Technology]bool{Pip: true}}, @@ -73,6 +74,13 @@ func TestMapFilesToRelevantWorkingDirectories(t *testing.T) { }, expectedExcluded: noExclude, }, + { + name: "pnpmTest", + paths: []string{filepath.Join("dir", "package.json"), filepath.Join("dir", "pnpm-lock.yaml")}, + requestedDescriptors: noRequest, + expectedWorkingDir: map[string][]string{"dir": {filepath.Join("dir", "package.json"), filepath.Join("dir", "pnpm-lock.yaml")}}, + expectedExcluded: map[string][]Technology{"dir": {Npm, Yarn}}, + }, { name: "yarnTest", paths: []string{filepath.Join("dir", "package.json"), filepath.Join("dir", ".yarn")}, @@ -185,6 +193,7 @@ func TestMapWorkingDirectoriesToTechnologies(t *testing.T) { "dir": {filepath.Join("dir", "package.json"), filepath.Join("dir", "package-lock.json"), filepath.Join("dir", "build.gradle.kts"), filepath.Join("dir", "project.sln")}, "directory": {filepath.Join("directory", "npm-shrinkwrap.json")}, "dir3": {filepath.Join("dir3", "package.json"), filepath.Join("dir3", ".yarn")}, + filepath.Join("dir3", "dir"): {filepath.Join("dir3", "dir", "package.json"), filepath.Join("dir3", "dir", "pnpm-lock.yaml")}, filepath.Join("dir", "dir2"): {filepath.Join("dir", "dir2", "go.mod")}, filepath.Join("users_dir", "test", "package"): {filepath.Join("users_dir", "test", "package", "setup.py")}, filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")}, @@ -193,7 +202,8 @@ func TestMapWorkingDirectoriesToTechnologies(t *testing.T) { }, excludedTechAtWorkingDir: map[string][]Technology{ filepath.Join("users", "test", "package"): {Pip}, - "dir3": {Npm}, + "dir3": {Npm}, + filepath.Join("dir3", "dir"): {Npm, Yarn}, }, requestedTechs: noRequestTech, requestedDescriptors: noRequestSpecialDescriptors, @@ -203,6 +213,7 @@ func TestMapWorkingDirectoriesToTechnologies(t *testing.T) { "dir": {filepath.Join("dir", "package.json")}, "directory": {}, }, + Pnpm: {filepath.Join("dir3", "dir"): {filepath.Join("dir3", "dir", "package.json")}}, Yarn: {"dir3": {filepath.Join("dir3", "package.json")}}, Go: {filepath.Join("dir", "dir2"): {filepath.Join("dir", "dir2", "go.mod")}}, Pip: { @@ -361,6 +372,7 @@ func TestGetTechInformationFromWorkingDir(t *testing.T) { "dir": {filepath.Join("dir", "package.json"), filepath.Join("dir", "package-lock.json"), filepath.Join("dir", "build.gradle.kts"), filepath.Join("dir", "project.sln"), filepath.Join("dir", "blabla.txt")}, "directory": {filepath.Join("directory", "npm-shrinkwrap.json")}, "dir3": {filepath.Join("dir3", "package.json"), filepath.Join("dir3", ".yarn")}, + filepath.Join("dir3", "dir"): {filepath.Join("dir3", "dir", "package.json"), filepath.Join("dir3", "dir", "pnpm-lock.yaml")}, filepath.Join("dir", "dir2"): {filepath.Join("dir", "dir2", "go.mod")}, filepath.Join("users_dir", "test", "package"): {filepath.Join("users_dir", "test", "package", "setup.py")}, filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")}, @@ -369,7 +381,8 @@ func TestGetTechInformationFromWorkingDir(t *testing.T) { } excludedTechAtWorkingDir := map[string][]Technology{ filepath.Join("users", "test", "package"): {Pip}, - "dir3": {Npm}, + "dir3": {Npm, Pnpm}, + filepath.Join("dir3", "dir"): {Npm, Yarn}, } tests := []struct { @@ -399,6 +412,12 @@ func TestGetTechInformationFromWorkingDir(t *testing.T) { "directory": {}, }, }, + { + name: "pnpmTest", + tech: Pnpm, + requestedDescriptors: map[Technology][]string{}, + expected: map[string][]string{filepath.Join("dir3", "dir"): {filepath.Join("dir3", "dir", "package.json")}}, + }, { name: "yarnTest", tech: Yarn,