Skip to content

Commit 93e7706

Browse files
bug: handle case where node_modules is deleted in local tool dev
1 parent 1c75954 commit 93e7706

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/repos/runtimes/node/node.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var releasesData []byte
2626
const (
2727
downloadURL = "https://nodejs.org/dist/%s/"
2828
packageJSON = "package.json"
29+
nodeModules = "node_modules"
2930
)
3031

3132
type Runtime struct {
@@ -64,8 +65,15 @@ func (r *Runtime) supports(testCmd string, cmd []string) bool {
6465

6566
func (r *Runtime) GetHash(tool types.Tool) (string, error) {
6667
if !tool.Source.IsGit() && tool.WorkingDir != "" {
68+
var prefix string
69+
// This hashes if the node_modules directory was deleted
70+
if s, err := os.Stat(filepath.Join(tool.WorkingDir, nodeModules)); err == nil {
71+
prefix = hash.Digest(tool.WorkingDir + s.ModTime().String())[:7]
72+
} else if s, err := os.Stat(tool.WorkingDir); err == nil {
73+
prefix = hash.Digest(tool.WorkingDir + s.ModTime().String())[:7]
74+
}
6775
if s, err := os.Stat(filepath.Join(tool.WorkingDir, packageJSON)); err == nil {
68-
return hash.Digest(tool.WorkingDir + s.ModTime().String())[:7], nil
76+
return prefix + hash.Digest(tool.WorkingDir + s.ModTime().String())[:7], nil
6977
}
7078
}
7179
return "", nil

0 commit comments

Comments
 (0)