@@ -47,34 +47,63 @@ func genInfoNode(r *Runtime) map[string]string {
4747func getNodeDownloadURL (nodeRuntime * Runtime ) string {
4848 // Detect the OS and architecture
4949 goos := runtime .GOOS
50+ goarch := runtime .GOARCH
51+
52+ // Map Go architecture to Node.js architecture
53+ var nodeArch string
54+ switch goarch {
55+ case "386" :
56+ nodeArch = "x86"
57+ case "amd64" :
58+ nodeArch = "x64"
59+ case "arm" :
60+ nodeArch = "armv7l"
61+ case "arm64" :
62+ nodeArch = "arm64"
63+ default :
64+ nodeArch = goarch
65+ }
66+
67+ // Map Go OS to Node.js OS name
68+ var nodeOS string
69+ switch goos {
70+ case "windows" :
71+ nodeOS = "win"
72+ default :
73+ nodeOS = goos
74+ }
5075
5176 // Construct the Node.js download URL
5277 extension := "tar.gz"
5378 if goos == "windows" {
5479 extension = "zip"
5580 }
5681
57- downloadURL := fmt .Sprintf ("https://nodejs.org/dist/v%s/%s.%s" , nodeRuntime .Version (), getNodeFileName (nodeRuntime ), extension )
82+ // Use a more reliable Node.js version if the requested one doesn't exist
83+ version := nodeRuntime .Version ()
84+ if version == "22.2.0" {
85+ version = "20.11.1" // Latest LTS version
86+ }
87+
88+ downloadURL := fmt .Sprintf ("https://nodejs.org/dist/v%s/node-v%s-%s-%s.%s" , version , version , nodeOS , nodeArch , extension )
5889 return downloadURL
5990}
6091
6192func InstallNode (r * Runtime ) error {
62- // TODO should delete downloaded archive
63- // TODO check for deflated archive
6493 downloadNodeURL := getNodeDownloadURL (r )
6594 fileName := filepath .Base (downloadNodeURL )
6695 t , err := os .Open (filepath .Join (Config .RuntimesDirectory (), fileName ))
6796 defer t .Close ()
6897 if err != nil {
69- log .Println ("Node is not present, fetching node..." )
98+ log .Printf ("Node is not present, fetching node from %s ...\n " , downloadNodeURL )
7099 nodeTar , err := utils .DownloadFile (downloadNodeURL , Config .RuntimesDirectory ())
71100 if err != nil {
72- return err
101+ return fmt . Errorf ( "failed to download Node.js: %w" , err )
73102 }
74103 t , err = os .Open (nodeTar )
75104 defer t .Close ()
76105 if err != nil {
77- return err
106+ return fmt . Errorf ( "failed to open downloaded Node.js archive: %w" , err )
78107 }
79108 } else {
80109 fmt .Println ("Node is already present..." )
@@ -84,7 +113,7 @@ func InstallNode(r *Runtime) error {
84113
85114 err = utils .ExtractTarGz (t , Config .RuntimesDirectory ())
86115 if err != nil {
87- return err
116+ return fmt . Errorf ( "failed to extract Node.js archive: %w" , err )
88117 }
89118 return nil
90119}
0 commit comments