utils

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 added in v1.2.0

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 GetYarnDependencyKeyFromLocator added in v1.4.0

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 added in v1.4.0

func GetYarnExecutable() (string, error)

func NewNpmCacache

func NewNpmCacache(cachePath string) *cacache

func RunNpmCmd

func RunNpmCmd(executablePath, srcPath string, npmCmd NpmCmd, 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 NpmCmd

type NpmCmd int
const (
	Ls NpmCmd = iota
	Config
	Install
	Ci
	Pack
	Version
)

func (NpmCmd) String

func (nc NpmCmd) String() string

type PackageInfo

type PackageInfo struct {
	Name    string `json:"name,omitempty"`
	Version string `json:"version,omitempty"`
	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 YarnDepDetails added in v1.4.0

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

type YarnDependency added in v1.4.0

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 added in v1.4.0

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@npm:1.0.0'. Pay attention that a package's value won't necessarily contain its version. Use the version in package's details instead. Note that in some versions of Yarn, the version of the root package is '0.0.0-use.local', instead of the version in the package.json file.

func (*YarnDependency) Name added in v1.4.0

func (yd *YarnDependency) Name() string

type YarnDependencyPointer added in v1.4.0

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