Skip to content

📥 InstallWithPreferDist ​

Installs dependencies with the --prefer-dist option, forcing downloads from distribution packages (usually zip archives) instead of cloning source code.

When to use ​

Use this in production deployment, CI pipelines, or any scenario that prioritizes installation speed. Distribution packages are smaller and faster to download, suitable for the vast majority of cases where you do not need to modify package source code. Equivalent to running composer install --prefer-dist.

Signature ​

go
func (c *Composer) InstallWithPreferDist() error

Parameters ​

This method takes no parameters.

Return value ​

error: Returns the corresponding error message when an error occurs during installation; nil on success.

Example ​

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("Initialization failed: %v", err)
	}

	// Production deployment: install quickly from distribution packages
	if err := comp.InstallWithPreferDist(); err != nil {
		log.Fatalf("Failed to install dependencies: %v", err)
	}

	fmt.Println("Dependencies installed (distribution package mode)")
}

Advanced ​

Released under the MIT License