Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pnpm technology #1122

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions artifactory/commands/repository/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
11 changes: 10 additions & 1 deletion utils/coreutils/techutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -77,16 +78,24 @@ 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),
packageVersionOperator: "@",
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,
Expand Down
34 changes: 30 additions & 4 deletions utils/coreutils/techutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down Expand Up @@ -73,12 +74,19 @@ 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")},
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",
Expand Down Expand Up @@ -138,13 +146,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])
}
})
}
}
Expand Down Expand Up @@ -178,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")},
Expand All @@ -186,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,
Expand All @@ -196,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: {
Expand Down Expand Up @@ -354,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")},
Expand All @@ -362,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 {
Expand Down Expand Up @@ -392,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,
Expand Down
Loading