Skip to content

🗜️ 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

MethodSignatureDescription
🗜️ Archivefunc (c *Composer) Archive(destination string) (string, error)Default zip archive to directory
🎨 ArchiveWithFormatfunc (c *Composer) ArchiveWithFormat(destination string, format string) (string, error)Archive with specified format
⚙️ ArchiveWithOptionsfunc (c *Composer) ArchiveWithOptions(destination string, options map[string]string) (string, error)Custom options
📦 ArchivePackagefunc (c *Composer) ArchivePackage(packageName string, version string, destination string) (string, error)Archive specified package
⚙️ ArchivePackageWithOptionsfunc (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

ParameterTypeDescription
destinationstringTarget directory (passed to --dir=)
formatstringzip or tar

ArchivePackage / ArchivePackageWithOptions

ParameterTypeDescription
packageNamestringPackage name to archive, e.g. symfony/console
versionstringVersion, empty string means latest
destinationstringTarget directory
optionsmap[string]stringAdditional options

Examples

Archive Current Project as Zip

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.Fatal(err)
	}

	out, err := comp.Archive("/tmp/releases")
	if err != nil {
		log.Fatalf("Archive failed: %v", err)
	}
	fmt.Println(out)
}

Archive with Tar Format

go
out, err := comp.ArchiveWithFormat("/tmp/releases", "tar")
if err != nil {
	log.Fatal(err)
}
fmt.Println(out)

Custom Filename and Ignore Filters

go
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

go
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

go
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).

Released under the MIT License