Skip to content

📦 Installation

This page covers how to install Composer Skills, its dependencies, how to verify the install, and relevant environment variables.

🚀 One-line install

bash
go get github.com/scagogogo/composer-skills

Then tidy up dependencies:

bash
go mod tidy

Speeding things up in China

If you're in China, set a Go module proxy:

bash
go env -w GOPROXY=https://goproxy.cn,direct

📋 Dependencies

Composer Skills ships two SDKs with different runtime requirements:

SDKPackage pathNeeds PHP?Needs Composer?
🌐 Packagist APIpkg/client, pkg/repository❌ No❌ No
🛠️ Composer CLIpkg/composer✅ PHP 7.4+✅ Composer 2.0+

Common requirement:

  • Go 1.23+ (go.mod declares go 1.23.0, toolchain go1.23.2)

Half the SDK works without PHP

As long as your use case is "query Packagist" (search, statistics, security advisories, package listings), pkg/client is enough — pure Go with zero external dependencies. You only need PHP + Composer when calling local commands from pkg/composer (install, audit, require, etc.).

✅ Verifying the install

Save the following as main.go; if it runs, the installation succeeded:

go
package main

import (
    "fmt"
    "time"

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

func main() {
    // 1. Packagist API: pure Go, ready immediately
    c := client.NewComposerClient(30 * time.Second)
    stats, err := c.GetStatistics()
    if err != nil {
        fmt.Printf("❌ Packagist API call failed: %v\n", err)
    } else {
        fmt.Printf("✅ Packagist API OK, total packages: %d\n", stats.Packages)
    }

    // 2. Detect local Composer
    d := detector.NewDetector()
    if d.IsInstalled() {
        path, _ := d.Detect()
        fmt.Printf("✅ Composer detected: %s\n", path)
    } else {
        fmt.Println("ℹ️ Composer not detected; it will be auto-installed when pkg/composer is called")
    }
}

Expected output is something like:

text
✅ Packagist API OK, total packages: 395821
✅ Composer detected: /usr/local/bin/composer

🔧 Optional environment variables

Composer Skills itself doesn't force any environment variables, but the following affect the underlying Composer behavior (passed through to the subprocess via Options.Env):

VariablePurposeExample
COMPOSER_HOMEComposer's home directory (cache, global config)/tmp/composer
COMPOSER_CACHE_DIRCache directory/tmp/composer-cache
COMPOSER_AUTHAuth tokens (JSON), non-interactive{"github-oauth":{"github.com":"xxx"}}
COMPOSER_MEMORY_LIMITMemory limit-1 (unlimited)
HTTP_PROXY / HTTPS_PROXYOutbound proxyhttp://127.0.0.1:7890

Set them in Go code:

go
options := composer.DefaultOptions()
options.Env = append(options.Env,
    "COMPOSER_HOME=/tmp/composer",
    "COMPOSER_MEMORY_LIMIT=-1",
)
comp, err := composer.New(options)

Authenticating to private repos

When accessing private VCS / GitHub Packagist repositories, prefer comp.AddGitHubToken("github.com", "your-token") over hand-writing COMPOSER_AUTH — the SDK writes it into auth.json for you.

🧪 Verifying a dev environment (optional)

If you've cloned the repo and want to run the tests:

bash
git clone https://github.com/scagogogo/composer-skills.git
cd composer-skills
make test           # run all 450+ tests
make test-coverage  # generate a coverage report
make check          # formatting + vet + tests

🧭 Next steps

Released under the MIT License