Skip to content

📁 HasVendorDir

Checks whether a vendor directory exists in the current working directory, used to determine whether the project has installed dependencies.

When to use

The vendor directory is produced after Composer installs dependencies. Use this when you need to confirm whether dependencies are in place, or whether you should run composer install before running the project. It only checks whether the directory exists and does not verify dependency integrity.

Signature

go
func (c *Composer) HasVendorDir() bool

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
Single return valueboolReturns true when a vendor directory exists in the current working directory, otherwise false

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

	if comp.HasVendorDir() {
		fmt.Println("vendor directory exists, dependencies installed ✅")
	} else {
		fmt.Println("vendor directory missing, run composer install first ⚠️")
	}
}

Advanced

  • To get the actual path of the vendor directory (which may be customized via vendor-dir), use GetVendorDir.
  • To confirm whether versions are locked, combine with HasComposerLock.
  • To actually install dependencies, use Install.

Released under the MIT License