utils

package
v0.0.0-...-e472556 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendNpmCommand

func AppendNpmCommand(npmArgs []string, command string) []string

This function appends the Npm command as the first element in npmArgs strings array. For example, if npmArgs equals {"--json", "--all"}, and we call appendNpmCommand(npmArgs, "ls"), we will get npmArgs = {"ls", "--json", "--all"}.

func CalculateDependenciesMap

func CalculateDependenciesMap(executablePath, srcPath, moduleId string, npmArgs []string, log utils.Log) (map[string]*dependencyInfo, error)

Run 'npm list ...' command and parse the returned result to create a dependencies map of. The dependencies map looks like name:version -> entities.Dependency.

func CalculateNpmDependenciesList

func CalculateNpmDependenciesList(executablePath, srcPath, moduleId string, npmArgs []string, calculateChecksums bool, log utils.Log) ([]entities.Dependency, error)

CalculateNpmDependenciesList gets an npm project's dependencies.

func GetNpmConfigCache

func GetNpmConfigCache(srcPath, executablePath string, npmArgs []string, log utils.Log) (string, error)

Return the npm cache path. Default: Windows: %LocalAppData%\npm-cache, Posix: ~/.npm

func GetNpmVersion

func GetNpmVersion(executablePath string, log utils.Log) (*version.Version, error)

func GetNpmVersionAndExecPath

func GetNpmVersionAndExecPath(log utils.Log) (*version.Version, string, error)

func GetVersion

func GetVersion(executablePath, srcPath string) (string, error)

GetVersion getVersion gets the current project's yarn version

func GetYarnDependencyKeyFromLocator

func GetYarnDependencyKeyFromLocator(yarnDepLocator string) string

GetYarnDependencyKeyFromLocator gets a Yarn dependency locator and returns its key in the dependencies map. Yarn dependency locator usually looks like this: package-name@npm:1.2.3, which is used as the key in the dependencies map. But sometimes it points to a virtual package, so it looks different: package-name@virtual:[ID of virtual package]#npm:1.2.3. In this case we need to omit the part of the virtual package ID, to get the key as it is found in the dependencies map.

func GetYarnExecutable

func GetYarnExecutable() (string, error)

func NewNpmCacache

func NewNpmCacache(cachePath string) *cacache

func RunNpmCmd

func RunNpmCmd(executablePath, srcPath string, npmArgs []string, log utils.Log) (stdResult, errResult []byte, err error)

func TraverseDependencies

func TraverseDependencies(dependenciesMap map[string]*entities.Dependency, traverseDependenciesFunc func(dependency *entities.Dependency) (bool, error), threads int) (dependenciesList []entities.Dependency, err error)

Executes traverseDependenciesFunc on all dependencies in dependenciesMap. Each dependency that gets true in return, is added to dependenciesList.

Types

type PackageInfo

type PackageInfo struct {
	Name                 string            `json:"name"`
	Version              string            `json:"version"`
	Dependencies         map[string]string `json:"dependencies"`
	DevDependencies      map[string]string `json:"devDependencies"`
	PeerDependencies     map[string]string `json:"peerDependencies"`
	OptionalDependencies map[string]string `json:"optionalDependencies"`
	Scope                string
}

func ReadPackageInfo

func ReadPackageInfo(data []byte, npmVersion *version.Version) (*PackageInfo, error)

func ReadPackageInfoFromPackageJson

func ReadPackageInfoFromPackageJson(packageJsonDirectory string, npmVersion *version.Version) (*PackageInfo, error)

func (*PackageInfo) BuildInfoModuleId

func (pi *PackageInfo) BuildInfoModuleId() string

func (*PackageInfo) FullName

func (pi *PackageInfo) FullName() string

func (*PackageInfo) GetDeployPath

func (pi *PackageInfo) GetDeployPath() string

type Yarn1Data

type Yarn1Data struct {
	Data Yarn1DependencyTree `json:"data,omitempty"`
}

type Yarn1DependencyDetails

type Yarn1DependencyDetails struct {
	Name         string                   `json:"name,omitempty"`
	Dependencies []Yarn1DependencyPointer `json:"children,omitempty"`
}

type Yarn1DependencyPointer

type Yarn1DependencyPointer struct {
	DependencyName string `json:"name,omitempty"`
	Shadow         bool   `json:"shadow,omitempty"`
}

type Yarn1DependencyTree

type Yarn1DependencyTree struct {
	DepTree []Yarn1DependencyDetails `json:"trees,omitempty"`
}

type YarnDepDetails

type YarnDepDetails struct {
	Version      string                  `json:"Version,omitempty"`
	Dependencies []YarnDependencyPointer `json:"Dependencies,omitempty"`
}

type YarnDependency

type YarnDependency struct {
	// The value is usually in this structure: @scope/package-name@npm:1.0.0
	Value   string         `json:"value,omitempty"`
	Details YarnDepDetails `json:"children,omitempty"`
}

func GetYarnDependencies

func GetYarnDependencies(executablePath, srcPath string, packageInfo *PackageInfo, log utils.Log) (dependenciesMap map[string]*YarnDependency, root *YarnDependency, err error)

GetYarnDependencies returns a map of the dependencies of a Yarn project and the root package of the project. The keys are the packages' values (Yarn's full identifiers of the packages), for example: '@scope/package-name@1.0.0' (for yarn v < 2.0.0) or @scope/package-name@npm:1.0.0 (for yarn v >= 2.0.0). Pay attention that a package's value won't necessarily contain its version. Use the version in package's details instead.

func (*YarnDependency) Name

func (yd *YarnDependency) Name() string

type YarnDependencyPointer

type YarnDependencyPointer struct {
	Descriptor string `json:"descriptor,omitempty"`
	Locator    string `json:"locator,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL