Skip to content

⚠️ GetAbandonedPackagesFromLock

Reads the list of abandoned packages from the composer.lock file without running any Composer commands.

When to use

Use it when you need to quickly identify which packages used by the project have been officially marked as abandoned in an offline environment. It directly parses the abandoned flag in the lock file and is extremely fast.

Signature

go
func (c *Composer) GetAbandonedPackagesFromLock() ([]string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return value[]stringList of abandoned package names; empty slice when there are none
Second return valueerrorReturned when reading or parsing composer.lock 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("initialization failed: %v", err)
	}

	abandoned, err := comp.GetAbandonedPackagesFromLock()
	if err != nil {
		log.Fatalf("failed to read lock: %v", err)
	}
	if len(abandoned) == 0 {
		fmt.Println("No abandoned packages ✅")
	} else {
		fmt.Printf("Found %d abandoned packages:\n", len(abandoned))
		for _, name := range abandoned {
			fmt.Println(" -", name)
		}
	}
}

Advanced

  • To get abandoned packages (with replacement suggestions) via a Composer command, use GetAbandonedPackages.
  • To read the full lock file contents, use ReadComposerLock.
  • This method only reads the packages and packages-dev sections; platform packages are not included.

Released under the MIT License