📦 ArchivePackage
Creates an archive file for the specified package, optionally with a specific version. Equivalent to running composer archive <packageName>[=<version>] --dir=<destination>.
When to use
Use when you need to package a dependency package (rather than the whole project) into an archive, for offline distribution or mirror archiving.
Signature
go
func (c *Composer) ArchivePackage(packageName string, version string, destination string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | Name of the package to archive, e.g. symfony/console |
version | string | Package version, e.g. v5.4.0; pass an empty string to use the latest version |
destination | string | Target directory path where the archive file is stored |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Output of the archive command |
| Second return value | error | Returned when archive creation fails |
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)
}
// Archive a specific version of a package
output, err := comp.ArchivePackage("symfony/console", "v5.4.0", "/tmp/pkg-archive")
if err != nil {
log.Fatalf("failed to create package archive: %v", err)
}
fmt.Println("Package archive result:", output)
// Archive the latest version
if _, err := comp.ArchivePackage("symfony/console", "", "/tmp/pkg-archive"); err != nil {
log.Fatalf("failed to create package archive: %v", err)
}
}