🎯 SetPreferredInstall
Sets the project's preferred-install configuration, controlling whether Composer prefers dist (packaged distribution) or source (source code) when installing packages. Equivalent to running composer config preferred-install <value>.
When to use
Use this when you want to unify the team's installation strategy. For example, prefer dist in production to speed up installation and avoid pulling Git history; prefer source in debugging scenarios to view or modify the source directly.
Signature
go
func (c *Composer) SetPreferredInstall(value string) errorParameters
| Parameter | Type | Description |
|---|---|---|
value | string | Install strategy; must be one of dist, source, or auto |
Return value
error: returns the corresponding error message when an error occurs while setting the config; nil on success.
Note
This method validates the value and only accepts dist, source, or auto. Passing any other value returns an error directly.
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("init failed: %v", err)
}
// Prefer the packaged distribution
if err := comp.SetPreferredInstall("dist"); err != nil {
log.Fatalf("set preferred-install failed: %v", err)
}
fmt.Println("preferred-install set to dist")
}Advanced
- To read the current
preferred-installconfig, useGetPreferredInstall(). - Value meanings:
dist(prefer distribution),source(prefer source),auto(automatic, default). - Shortcuts that apply only to a single install:
InstallWithPreferSource()/InstallWithPreferDist().