utils

package
v1.9.21 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendNpmCommand added in v1.9.6

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, npmListParams NpmTreeDepListParam, 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, npmParams NpmTreeDepListParam, 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 added in v1.9.7

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

GetVersion getVersion gets the current project's yarn version

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, 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 NpmTreeDepListParam added in v1.9.12

type NpmTreeDepListParam struct {
	// Required for the 'install' and 'ls' commands that could be triggered during the construction of the NPM dependency tree
	Args []string
	// Optional user-supplied arguments for the 'install' command. These arguments are not available from all entry points. They may be employed when constructing the NPM dependency tree, which could necessitate the execution of 'npm install...'
	InstallCommandArgs []string
	// Ignore the node_modules folder if exists, using the '--package-lock-only' flag
	IgnoreNodeModules bool
	// Rewrite package-lock.json, if exists.
	OverwritePackageLock bool
}

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

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

Read and populate package name, version and scope from the package.json file in the provided directory. If package.json does not exist, return an empty PackageInfo struct.

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

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

type Yarn1DependencyDetails added in v1.9.7

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

type Yarn1DependencyPointer added in v1.9.7

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

type Yarn1DependencyTree added in v1.9.7

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

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@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 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