Skip to content

Commit 5448b24

Browse files
fix: Installing eslint in Linux (WSL) [PLUTO-1419] (#99)
This change resolves the "node: No such file or directory" error when installing ESLint on WSL by properly configuring the Node.js runtime path. - Add special path handling for Node.js binaries in Linux/WSL - Ensure Node.js binary directory is added to PATH during ESLint installation - Use Linux path separator when modifying PATH environment variable - Maintain existing PATH while prepending Node.js directory
1 parent 0a57dfa commit 5448b24

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

codacy-cli.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ case "$arch" in
1717
"x86")
1818
arch="386"
1919
;;
20+
"aarch64"|"arm64")
21+
arch="arm64"
22+
;;
2023
esac
2124

2225
if [ -z "$CODACY_CLI_V2_TMP_FOLDER" ]; then

config/tools-installer.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"codacy/cli-v2/utils"
77
"codacy/cli-v2/utils/logger"
88
"fmt"
9+
"log"
910
"os"
1011
"os/exec"
1112
"path/filepath"
13+
"runtime"
1214
"strings"
1315
"text/template"
1416

@@ -164,6 +166,31 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo, registry string
164166

165167
// Execute the installation command using the package manager
166168
cmd := exec.Command(packageManagerBinary, strings.Split(installCmd, " ")...)
169+
170+
// Special handling for ESLint installation in Linux (WSL) environment
171+
if toolInfo.Name == "eslint" && runtime.GOOS == "linux" {
172+
// Get node binary directory to add to PATH
173+
nodeBinary, exist := runtimeInfo.Binaries["node"]
174+
if exist {
175+
nodeDir := filepath.Dir(nodeBinary)
176+
// Get current PATH
177+
currentPath := os.Getenv("PATH")
178+
// For Linux (WSL), always use Linux path separator
179+
pathSeparator := ":"
180+
newPath := nodeDir + pathSeparator + currentPath
181+
cmd.Env = append(os.Environ(), "PATH="+newPath)
182+
logger.Debug("Setting PATH environment for ESLint installation", logrus.Fields{
183+
"nodeDir": nodeDir,
184+
"currentPath": currentPath,
185+
"newPath": newPath,
186+
})
187+
}
188+
}
189+
190+
log.Printf("Installing %s v%s...\n", toolInfo.Name, toolInfo.Version)
191+
logger.Debug("Running command", logrus.Fields{
192+
"command": fmt.Sprintf("%s %s", packageManagerBinary, installCmd),
193+
})
167194
output, err := cmd.CombinedOutput()
168195
if err != nil {
169196
return fmt.Errorf("failed to install tool: %s: %w", string(output), err)

0 commit comments

Comments
 (0)