🗜️ Archive
Package the current project or a specified package into a zip / tar archive for offline distribution or long-term archival.
composer archive packages project code and dependencies (excluding dev dependencies) based on dependency resolution. Composer Skills wraps this with four levels of flexibility: "default zip", "specify format", "custom options", and "specify package", plus WithOptions variants for each package-level method.
When to Use
- 📦 Package the project as a zip for delivery to offline deployment environments (no access to Packagist).
- 🗄️ Generate a tar archive for a specific dependency and archive it to an artifact repository.
- 🚚 Automatically archive the entire project artifact in CI on each release tag.
- 🎛️ Need to exclude certain files (
--ignore-filters) or specify a filename (--file).
Method Signatures
| Method | Signature | Description |
|---|---|---|
| 🗜️ Archive | func (c *Composer) Archive(destination string) (string, error) | Default zip archive to directory |
| 🎨 ArchiveWithFormat | func (c *Composer) ArchiveWithFormat(destination string, format string) (string, error) | Archive with specified format |
| ⚙️ ArchiveWithOptions | func (c *Composer) ArchiveWithOptions(destination string, options map[string]string) (string, error) | Custom options |
| 📦 ArchivePackage | func (c *Composer) ArchivePackage(packageName string, version string, destination string) (string, error) | Archive specified package |
| ⚙️ ArchivePackageWithOptions | func (c *Composer) ArchivePackageWithOptions(packageName string, version string, destination string, options map[string]string) (string, error) | Archive specified package with custom options |
Parameters
Archive / ArchiveWithFormat / ArchiveWithOptions
| Parameter | Type | Description |
|---|---|---|
destination | string | Target directory (passed to --dir=) |
format | string | zip or tar |
ArchivePackage / ArchivePackageWithOptions
| Parameter | Type | Description |
|---|---|---|
packageName | string | Package name to archive, e.g. symfony/console |
version | string | Version, empty string means latest |
destination | string | Target directory |
options | map[string]string | Additional options |
Examples
Archive Current Project as Zip
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatal(err)
}
out, err := comp.Archive("/tmp/releases")
if err != nil {
log.Fatalf("Archive failed: %v", err)
}
fmt.Println(out)
}Archive with Tar Format
out, err := comp.ArchiveWithFormat("/tmp/releases", "tar")
if err != nil {
log.Fatal(err)
}
fmt.Println(out)Custom Filename and Ignore Filters
out, err := comp.ArchiveWithOptions("/tmp/releases", map[string]string{
"format": "tar",
"file": "my-app.tar",
"ignore-filters": "",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(out)Archive a Specific Version of a Package
out, err := comp.ArchivePackage("symfony/console", "v5.4.0", "/tmp/pkg-archives")
if err != nil {
log.Fatal(err)
}
fmt.Println(out)Archive Latest Version with Specified Format
out, err := comp.ArchivePackageWithOptions(
"symfony/console",
"", // empty = latest version
"/tmp/pkg-archives",
map[string]string{"format": "tar"},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(out)Advanced
destination is a Directory, Not a File
The destination for all methods is wrapped as --dir=<destination>, meaning the archive directory, not a filename. To specify a filename, use the --file option (options["file"] in ArchiveWithOptions).
Version Concatenation for ArchivePackage
When version is non-empty, it's concatenated as packageName=version and passed to composer archive; when empty, only the package name is passed, and Composer selects the latest version.
Excludes Dev Dependencies
composer archive excludes require-dev packages by default. If you need to include testing tools in the archive, use the underlying composer archive --include-dev, or pass options via ArchiveWithOptions (note that SDK's options automatically adds -- prefix, so verify Composer supports that flag).