Skip to content

Commit 04dc845

Browse files
authored
refactor(runtime): remove hardcoded system paths from DetectInstalled (#127)
1 parent d3f4133 commit 04dc845

3 files changed

Lines changed: 6 additions & 162 deletions

File tree

src/runtimes/node/provider.go

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -359,25 +359,7 @@ func (p *Provider) DetectInstalled() ([]runtime.DetectedVersion, error) {
359359
}
360360
}
361361

362-
// 2. Check common installation locations
363-
locations := getNodeInstallLocations()
364-
for _, loc := range locations {
365-
if _, err := os.Stat(loc); err == nil {
366-
if version, err := getNodeVersion(loc); err == nil {
367-
if !seen[loc] {
368-
detected = append(detected, runtime.DetectedVersion{
369-
Version: version,
370-
Path: loc,
371-
Source: "system",
372-
Validated: true,
373-
})
374-
seen[loc] = true
375-
}
376-
}
377-
}
378-
}
379-
380-
// 3. Check nvm installations
362+
// 2. Check nvm installations
381363
nvmVersions := findNvmVersions()
382364
for _, dv := range nvmVersions {
383365
if !seen[dv.Path] {
@@ -386,7 +368,7 @@ func (p *Provider) DetectInstalled() ([]runtime.DetectedVersion, error) {
386368
}
387369
}
388370

389-
// 4. Check fnm installations
371+
// 3. Check fnm installations
390372
fnmVersions := findFnmVersions()
391373
for _, dv := range fnmVersions {
392374
if !seen[dv.Path] {
@@ -413,34 +395,6 @@ func getNodeVersion(nodePath string) (string, error) {
413395
return version, nil
414396
}
415397

416-
// getNodeInstallLocations returns common Node.js installation paths
417-
func getNodeInstallLocations() []string {
418-
home, _ := os.UserHomeDir()
419-
420-
locations := []string{
421-
// Windows
422-
`C:\Program Files\nodejs\node.exe`,
423-
`C:\Program Files (x86)\nodejs\node.exe`,
424-
425-
// macOS (Homebrew)
426-
"/usr/local/bin/node",
427-
"/opt/homebrew/bin/node",
428-
429-
// Linux
430-
"/usr/bin/node",
431-
"/usr/local/bin/node",
432-
}
433-
434-
// Add user-specific locations
435-
if home != "" {
436-
locations = append(locations,
437-
filepath.Join(home, ".local", "bin", "node"),
438-
)
439-
}
440-
441-
return locations
442-
}
443-
444398
// findNvmVersions scans nvm directory for installed versions
445399
func findNvmVersions() []runtime.DetectedVersion {
446400
detected := make([]runtime.DetectedVersion, 0)

src/runtimes/python/provider.go

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -575,25 +575,7 @@ func (p *Provider) DetectInstalled() ([]runtime.DetectedVersion, error) {
575575
}
576576
}
577577

578-
// 2. Check common installation locations
579-
locations := getPythonInstallLocations()
580-
for _, loc := range locations {
581-
if _, err := os.Stat(loc); err == nil {
582-
if version, err := getPythonVersion(loc); err == nil {
583-
if !seen[loc] {
584-
detected = append(detected, runtime.DetectedVersion{
585-
Version: version,
586-
Path: loc,
587-
Source: "system",
588-
Validated: true,
589-
})
590-
seen[loc] = true
591-
}
592-
}
593-
}
594-
}
595-
596-
// 3. Check pyenv installations
578+
// 2. Check pyenv installations
597579
pyenvVersions := findPyenvVersions()
598580
for _, dv := range pyenvVersions {
599581
if !seen[dv.Path] {
@@ -624,49 +606,6 @@ func getPythonVersion(pythonPath string) (string, error) {
624606
return "", fmt.Errorf("could not parse Python version from: %s", version)
625607
}
626608

627-
// getPythonInstallLocations returns common Python installation paths
628-
func getPythonInstallLocations() []string {
629-
home, _ := os.UserHomeDir()
630-
631-
locations := []string{
632-
// Windows - check multiple Python versions
633-
`C:\Python311\python.exe`,
634-
`C:\Python310\python.exe`,
635-
`C:\Python39\python.exe`,
636-
`C:\Python38\python.exe`,
637-
`C:\Python37\python.exe`,
638-
639-
// macOS (Homebrew and system)
640-
"/usr/local/bin/python3",
641-
"/opt/homebrew/bin/python3",
642-
"/usr/bin/python3",
643-
644-
// Linux
645-
"/usr/bin/python3",
646-
"/usr/local/bin/python3",
647-
}
648-
649-
// Windows - check LocalAppData\Programs\Python
650-
if home != "" {
651-
pythonLocalDir := filepath.Join(home, "AppData", "Local", "Programs", "Python")
652-
if entries, err := os.ReadDir(pythonLocalDir); err == nil {
653-
for _, entry := range entries {
654-
if entry.IsDir() {
655-
pythonExe := filepath.Join(pythonLocalDir, entry.Name(), "python.exe")
656-
locations = append(locations, pythonExe)
657-
}
658-
}
659-
}
660-
661-
// macOS/Linux user installs
662-
locations = append(locations,
663-
filepath.Join(home, ".local", "bin", "python3"),
664-
)
665-
}
666-
667-
return locations
668-
}
669-
670609
// findPyenvVersions scans pyenv directory for installed versions
671610
func findPyenvVersions() []runtime.DetectedVersion {
672611
detected := make([]runtime.DetectedVersion, 0)

src/runtimes/ruby/provider.go

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -572,25 +572,7 @@ func (p *Provider) DetectInstalled() ([]runtime.DetectedVersion, error) {
572572
}
573573
}
574574

575-
// 2. Check common installation locations
576-
locations := getRubyInstallLocations()
577-
for _, loc := range locations {
578-
if _, err := os.Stat(loc); err == nil {
579-
if version, err := getRubyVersion(loc); err == nil {
580-
if !seen[loc] {
581-
detected = append(detected, runtime.DetectedVersion{
582-
Version: version,
583-
Path: loc,
584-
Source: "system",
585-
Validated: true,
586-
})
587-
seen[loc] = true
588-
}
589-
}
590-
}
591-
}
592-
593-
// 3. Check rbenv installations
575+
// 2. Check rbenv installations
594576
rbenvVersions := findRbenvVersions()
595577
for _, dv := range rbenvVersions {
596578
if !seen[dv.Path] {
@@ -599,7 +581,7 @@ func (p *Provider) DetectInstalled() ([]runtime.DetectedVersion, error) {
599581
}
600582
}
601583

602-
// 4. Check rvm installations
584+
// 3. Check rvm installations
603585
rvmVersions := findRvmVersions()
604586
for _, dv := range rvmVersions {
605587
if !seen[dv.Path] {
@@ -608,7 +590,7 @@ func (p *Provider) DetectInstalled() ([]runtime.DetectedVersion, error) {
608590
}
609591
}
610592

611-
// 5. Check chruby installations
593+
// 4. Check chruby installations
612594
chrubyVersions := findChrubyVersions()
613595
for _, dv := range chrubyVersions {
614596
if !seen[dv.Path] {
@@ -639,37 +621,6 @@ func getRubyVersion(rubyPath string) (string, error) {
639621
return "", fmt.Errorf("could not parse Ruby version from: %s", version)
640622
}
641623

642-
// getRubyInstallLocations returns common Ruby installation paths
643-
func getRubyInstallLocations() []string {
644-
home, _ := os.UserHomeDir()
645-
646-
locations := []string{
647-
// Windows
648-
`C:\Ruby33-x64\bin\ruby.exe`,
649-
`C:\Ruby32-x64\bin\ruby.exe`,
650-
`C:\Ruby31-x64\bin\ruby.exe`,
651-
`C:\Ruby30-x64\bin\ruby.exe`,
652-
653-
// macOS (Homebrew and system)
654-
"/usr/local/bin/ruby",
655-
"/opt/homebrew/bin/ruby",
656-
"/usr/bin/ruby",
657-
658-
// Linux
659-
"/usr/bin/ruby",
660-
"/usr/local/bin/ruby",
661-
}
662-
663-
// Add user-specific locations
664-
if home != "" {
665-
locations = append(locations,
666-
filepath.Join(home, ".local", "bin", "ruby"),
667-
)
668-
}
669-
670-
return locations
671-
}
672-
673624
// findRbenvVersions scans rbenv directory for installed versions
674625
func findRbenvVersions() []runtime.DetectedVersion {
675626
detected := make([]runtime.DetectedVersion, 0)

0 commit comments

Comments
 (0)