Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions config/runtimes-installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions config/tools-installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion plugins/tool-utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/tools/eslint/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down