Skip to content

Commit d65beae

Browse files
committed
fix: no longer downloads node binary if it is already present
1 parent d73a10a commit d65beae

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

.codacy/codacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
runtimes:
22
- node@22.2.0
33
tools:
4-
- eslint@8.57.0
4+
- eslint@9.3.0

config/node-utils.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"path"
9+
"path/filepath"
910
"runtime"
1011
)
1112

@@ -37,9 +38,9 @@ func genInfoNode(r *Runtime) map[string]string {
3738

3839
return map[string]string{
3940
"nodeFileName": nodeFileName,
40-
"installDir": path.Join(Config.RuntimesDirectory(), nodeFileName),
41-
"node": path.Join(Config.RuntimesDirectory(), nodeFileName, "bin", "node"),
42-
"npm": path.Join(Config.RuntimesDirectory(), nodeFileName, "bin", "npm"),
41+
"installDir": path.Join(Config.RuntimesDirectory(), nodeFileName),
42+
"node": path.Join(Config.RuntimesDirectory(), nodeFileName, "bin", "node"),
43+
"npm": path.Join(Config.RuntimesDirectory(), nodeFileName, "bin", "npm"),
4344
}
4445
}
4546

@@ -60,24 +61,30 @@ func getNodeDownloadURL(nodeRuntime *Runtime) string {
6061
func InstallNode(r *Runtime) error {
6162
// TODO should delete downloaded archive
6263
// TODO check for deflated archive
63-
log.Println("Fetching node...")
6464
downloadNodeURL := getNodeDownloadURL(r)
65-
nodeTar, err := utils.DownloadFile(downloadNodeURL, Config.RuntimesDirectory())
66-
if err != nil {
67-
return err
68-
}
69-
70-
// deflate node archive
71-
t, err := os.Open(nodeTar)
65+
fileName := filepath.Base(downloadNodeURL)
66+
t, err := os.Open(filepath.Join(Config.RuntimesDirectory(), fileName))
7267
defer t.Close()
7368
if err != nil {
74-
return err
69+
log.Println("Node is not present, fetching node...")
70+
nodeTar, err := utils.DownloadFile(downloadNodeURL, Config.RuntimesDirectory())
71+
if err != nil {
72+
return err
73+
}
74+
t, err = os.Open(nodeTar)
75+
defer t.Close()
76+
if err != nil {
77+
return err
78+
}
79+
} else {
80+
fmt.Println("Node is already present...")
7581
}
82+
fmt.Println("Extracting node...")
83+
// deflate node archive
84+
7685
err = utils.ExtractTarGz(t, Config.RuntimesDirectory())
7786
if err != nil {
7887
return err
7988
}
80-
8189
return nil
8290
}
83-

0 commit comments

Comments
 (0)