Skip to content

📁 AddPathRepository ​

Adds a local path as a Composer package source (a repository with type set to path), commonly used when developing multiple interdependent packages locally at the same time.

When to use ​

Use when you are developing multiple packages locally and want one package to be depended on by another project via a local path. Composer loads the package directly from the specified path and can create a symlink via the symlink option, so source changes take effect immediately.

Signature ​

go
func (c *Composer) AddPathRepository(name string, path string, options map[string]interface{}) error

Parameters ​

ParameterTypeDescription
namestringRepository name, used as the key of repositories.<name> in composer.json
pathstringRelative or absolute path to the local package, e.g. ../my-package
optionsmap[string]interface{}Repository options, e.g. {"symlink": true}; can be nil

Return value ​

error: Returns the corresponding error message if an error occurs while adding the path repository; 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)
	}

	// Add a local path repository with symlink enabled
	options := map[string]interface{}{
		"symlink": true,
	}
	if err := comp.AddPathRepository("local", "../my-package", options); err != nil {
		log.Fatalf("failed to add path repository: %v", err)
	}

	fmt.Println("Path repository added")
}

Advanced ​

  • To add a Git/SVN or other VCS repository, use AddVcsRepository; to add a private Composer source, use AddComposerRepository.
  • Common keys in options: symlink (whether to symlink), versions (restrict available versions).
  • The underlying implementation is AddRepository(name, Repository{Type: PathRepository, URL: path, Options: options}).
  • After adding, verify with ListRepositories; to remove, use RemoveRepository.

Released under the MIT License