packagemanager

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 11 Imported by: 0

README

js packagemanager

This is a go module to deal with javascript ecosystem packagemanager.

features

  • detection of common package managers such as yarn, npm, pnpm.
  • get workspaces package.json when dealing with mono[repo|space]
  • load a package.json into a struct (provided by the packageJson module in case you only need this)

Other features are planed like some common commands to launch on the sytem with thoose package managers, a better documentation is also planed. All of this depending on the interest manifested by the module.

history of this package

The code in this repository was originally inspired by https://github.com/replit/upm and largely modified by the turbo team at vercel This derivative work is not affiliated to any of thoose, but it is important to know the origin of the code in this repository.

This package was then extracted from turbo and cleaned up to be usable in other contexts than turbo repo. This we lost some capabilities proposed by the original code, like pruning lock files, that will perhaps be re-integrated in the future, but there's no particular plan on this. I hope this will be helpful for a bunch of crazy devs around and as always you can propose PR to make this a better tool.

Fundings

If you want, you can sponsors my work on this project here: https://github.com/sponsors/malko

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(path string) bool

func FindupFrom

func FindupFrom(name, dir string) (string, error)

func ParsePackageManagerString

func ParsePackageManagerString(packageManager string) (manager string, version string, err error)

ParsePackageManagerString takes a package manager version string parses it into consituent components

func PathExists

func PathExists(path string) bool

Types

type PackageManager

type PackageManager struct {
	// The descriptive name of the Package Manager.
	Name string

	// The unique identifier of the Package Manager.
	Slug string

	// The command used to invoke the Package Manager.
	Command string

	// The location of the package spec file used by the Package Manager.
	Specfile string

	// The location of the package lock file used by the Package Manager.
	Lockfile string

	// The directory in which package assets are stored by the Package Manager.
	PackageDir string

	// The location of the file that defines the workspace. Empty if workspaces defined in package.json
	WorkspaceConfigurationPath string

	// The separator that the Package Manger uses to identify arguments that
	// should be passed through to the underlying script.
	ArgSeparator []string

	// Test a manager and version tuple to see if it is the Package Manager.
	Matches func(manager string, version string) (bool, error)
	// contains filtered or unexported fields
}

PackageManager is an abstraction across package managers

func DetectPackageManager added in v0.0.5

func DetectPackageManager(projectDirectory string) (packageManager *PackageManager, err error)

detectPackageManager attempts to detect the package manager by inspecting the project directory state.

func GetPackageManager

func GetPackageManager(projectDirectory string, pkg *packageJson.PackageJSON) (packageManager *PackageManager, err error)

GetPackageManager attempts all methods for identifying the package manager in use.

func GetPackageManagerFromString added in v0.0.3

func GetPackageManagerFromString(packageManagerStr string) (packageManager *PackageManager, err error)

func (PackageManager) CanPrune

func (pm PackageManager) CanPrune(projectDirectory string) (bool, error)

CanPrune returns if we can produce a pruned workspace. Can error if fs issues occur

func (PackageManager) GetVersion added in v0.0.5

func (pm PackageManager) GetVersion() (string, error)

func (PackageManager) GetWorkspaceIgnores

func (pm PackageManager) GetWorkspaceIgnores(rootpath string) ([]string, error)

GetWorkspaceIgnores returns an array of globs not to search for workspaces.

func (PackageManager) GetWorkspaces

func (pm PackageManager) GetWorkspaces(rootpath string, relativePath bool) ([]string, error)

GetWorkspaces returns the list of package.json files for the current mono[space|repo].

func (PackageManager) PrunePatchedPackages

func (pm PackageManager) PrunePatchedPackages(pkgJSON *packageJson.PackageJSON, patches []string) error

PrunePatchedPackages will alter the provided pkgJSON to only reference the provided patches

type Pnpm6Workspaces

type Pnpm6Workspaces struct {
	Packages []string `yaml:"packages,omitempty"`
}

Pnpm6Workspaces is a representation of workspace package globs found in pnpm-workspace.yaml

type PnpmWorkspaces

type PnpmWorkspaces struct {
	Packages []string `yaml:"packages,omitempty"`
}

PnpmWorkspaces is a representation of workspace package globs found in pnpm-workspace.yaml

type YarnRC

type YarnRC struct {
	NodeLinker string `yaml:"nodeLinker"`
}

YarnRC Represents contents of .yarnrc.yml

Jump to

Keyboard shortcuts

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