Skip to content

🔒 UpdateWithLock

Only refreshes the hash of the composer.lock file without actually upgrading any package versions.

When to use

Use this when you have manually edited composer.json (e.g. adjusted description fields or scripts other than require), causing the composer.lock content-hash to fall out of sync with the json and Composer to emit a warning. Equivalent to running composer update --lock, it repairs the lock file without changing package versions.

Signature

go
func (c *Composer) UpdateWithLock() error

Parameters

This method takes no parameters.

Return value

error: returns the corresponding error message when an error occurs while updating the lock file; nil on success.

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)
	}

	// After modifying non-dependency fields of composer.json, re-sync the lock hash
	if err := comp.UpdateWithLock(); err != nil {
		log.Fatalf("update lock file failed: %v", err)
	}

	fmt.Println("composer.lock hash synced")
}

Advanced

  • This method does not download or upgrade any packages; it is lighter and safer than a full update.
  • To actually upgrade dependency versions, see Update or UpdateWithOptions.
  • To simulate an upgrade, see UpdateDryRun.

Released under the MIT License