📥 InstallWithPreferSource
Installs dependencies with the --prefer-source option, forcing packages to be cloned from source code (usually Git repositories) instead of downloading distribution packages.
When to use
Use this when you need to modify a package's source code for debugging, contribute a patch, when distribution packages are unavailable, or when you want version-control history. Equivalent to running composer install --prefer-source. Source installation is slower but yields the .git directory.
Signature
go
func (c *Composer) InstallWithPreferSource() errorParameters
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)
}
// Install from source for easier modification and debugging
if err := comp.InstallWithPreferSource(); err != nil {
log.Fatalf("Failed to install dependencies: %v", err)
}
fmt.Println("Dependencies installed (source mode)")
}Advanced
- Production deployment should prefer
InstallWithPreferDist; distribution packages install faster and contain no VCS metadata. - To combine
--prefer-sourcewith other options, useInstallWithOptions. - For the base install method, see
Install.