diff --git a/cmd/install.go b/cmd/install.go index 8bbf11e8..b80266d6 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -148,7 +148,7 @@ var installCmd = &cobra.Command{ for name, tool := range cfg.Config.Tools() { if !cfg.Config.IsToolInstalled(name, tool) { progressBar.Describe(fmt.Sprintf("Installing tool: %s v%s...", name, tool.Version)) - err := cfg.InstallTool(name, tool) + err := cfg.InstallTool(name, tool, registry) if err != nil { log.Fatal(err) } @@ -179,15 +179,15 @@ var installCmd = &cobra.Command{ } func installRuntimes(config *cfg.ConfigType) { - err := cfg.InstallRuntimes() + err := cfg.InstallRuntimes(config) if err != nil { log.Fatal(err) } } -func installTools(config *cfg.ConfigType) { +func installTools(config *cfg.ConfigType, registry string) { // Use the new tools-installer instead of manual installation - err := cfg.InstallTools() + err := cfg.InstallTools(config, registry) if err != nil { log.Fatal(err) } diff --git a/config/runtimes-installer.go b/config/runtimes-installer.go index 0abdb1ff..bb632f6e 100644 --- a/config/runtimes-installer.go +++ b/config/runtimes-installer.go @@ -11,8 +11,8 @@ import ( ) // InstallRuntimes installs all runtimes defined in the configuration -func InstallRuntimes() error { - for name, runtimeInfo := range Config.Runtimes() { +func InstallRuntimes(config *ConfigType) error { + for name, runtimeInfo := range config.Runtimes() { err := InstallRuntime(name, runtimeInfo) if err != nil { return fmt.Errorf("failed to install runtime %s: %w", name, err) diff --git a/config/tools-installer.go b/config/tools-installer.go index 19f19300..787b6f5f 100644 --- a/config/tools-installer.go +++ b/config/tools-installer.go @@ -14,10 +14,10 @@ import ( ) // InstallTools installs all tools defined in the configuration -func InstallTools() error { - for name, toolInfo := range Config.Tools() { +func InstallTools(config *ConfigType, registry string) error { + for name, toolInfo := range config.Tools() { fmt.Printf("Installing tool: %s v%s...\n", name, toolInfo.Version) - err := InstallTool(name, toolInfo) + err := InstallTool(name, toolInfo, registry) if err != nil { return fmt.Errorf("failed to install tool %s: %w", name, err) } @@ -27,7 +27,7 @@ func InstallTools() error { } // InstallTool installs a specific tool -func InstallTool(name string, toolInfo *plugins.ToolInfo) error { +func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error { // Check if the tool is already installed if isToolInstalled(toolInfo) { fmt.Printf("Tool %s v%s is already installed\n", name, toolInfo.Version) @@ -55,10 +55,10 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo) error { // For runtime-based tools fmt.Printf("Installing %s using %s runtime...\n", name, toolInfo.Runtime) - return installRuntimeTool(name, toolInfo) + return installRuntimeTool(name, toolInfo, registry) } -func installRuntimeTool(name string, toolInfo *plugins.ToolInfo) error { +func installRuntimeTool(name string, toolInfo *plugins.ToolInfo, registry string) error { // Get the runtime for this tool runtimeInfo, ok := Config.Runtimes()[toolInfo.Runtime] if !ok { @@ -70,7 +70,7 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo) error { "InstallDir": toolInfo.InstallDir, "PackageName": toolInfo.Name, "Version": toolInfo.Version, - "Registry": "", // TODO: Get registry from config + "Registry": registry, } // Get package manager binary based on the tool configuration @@ -81,12 +81,14 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo) error { } // Set registry if provided - if toolInfo.RegistryCommand != "" { + if registry != "" { regCmd, err := executeToolTemplate(toolInfo.RegistryCommand, templateData) if err != nil { return fmt.Errorf("failed to prepare registry command: %w", err) } + log.Printf("Setting registry...\n %s %s\n", packageManagerBinary, regCmd) + if regCmd != "" { registryCmd := exec.Command(packageManagerBinary, strings.Split(regCmd, " ")...) if output, err := registryCmd.CombinedOutput(); err != nil { diff --git a/plugins/tool-utils_test.go b/plugins/tool-utils_test.go index 915d8137..a2e90caf 100644 --- a/plugins/tool-utils_test.go +++ b/plugins/tool-utils_test.go @@ -65,7 +65,7 @@ func TestProcessTools(t *testing.T) { // Assert installation command templates are correctly set assert.Equal(t, "install --prefix {{.InstallDir}} {{.PackageName}}@{{.Version}} @microsoft/eslint-formatter-sarif", eslintInfo.InstallCommand) - assert.Equal(t, "{{if .Registry}}config set registry {{.Registry}}{{end}}", eslintInfo.RegistryCommand) + assert.Equal(t, "config set registry {{.Registry}}", eslintInfo.RegistryCommand) } func TestProcessToolsWithDownload(t *testing.T) { diff --git a/plugins/tools/eslint/plugin.yaml b/plugins/tools/eslint/plugin.yaml index d7af3231..b049aebf 100644 --- a/plugins/tools/eslint/plugin.yaml +++ b/plugins/tools/eslint/plugin.yaml @@ -6,7 +6,7 @@ runtime_binaries: execution: node installation: command: "install --prefix {{.InstallDir}} {{.PackageName}}@{{.Version}} @microsoft/eslint-formatter-sarif" - registry_template: "{{if .Registry}}config set registry {{.Registry}}{{end}}" + registry_template: "config set registry {{.Registry}}" binaries: - name: eslint path: "node_modules/.bin/eslint"