utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetPackageJson = sync.OnceValue(func() *Package {
	data, err := os.ReadFile("package.json")
	if err != nil {
		if !errors.Is(err, fs.ErrNotExist) {
			fmt.Println("warn: failed to read 1package.json")
		}
		return nil
	}
	var pkg Package
	err = json.Unmarshal(data, &pkg)
	if err != nil {
		fmt.Println("warn: failed to parse package.json")
		return nil
	}
	return &pkg
})

Functions

func CmdExists

func CmdExists(cmd string) bool

func CompleteDependencies

func CompleteDependencies(_ *cobra.Command, args []string, _ string) ([]cobra.Completion, cobra.ShellCompDirective)

func DefaultRunCommand

func DefaultRunCommand(cmd *cobra.Command, remaining []string)

DefaultRunCommand passes through all arguments to the default package manager

func FileExists

func FileExists(path string) bool

func GetCorepackManager

func GetCorepackManager() string

func GetPackageManager

func GetPackageManager() string

func GetShebang added in v1.1.0

func GetShebang(filePath string) (string, []string)

GetShebang returns the interpreter and args from a file's shebang line. If no shebang is present, returns empty manager and nil args.

func GuessPackageManager

func GuessPackageManager() string

func RunAliasCommand

func RunAliasCommand(name string, alias string, args []string, remaining ...string)

func RunCommand

func RunCommand(name string, args []string, remaining ...string)

func RunScriptCommand

func RunScriptCommand(cmd *cobra.Command, remaining []string)

RunScriptCommand passes through all arguments to the pm's run command

Types

type Package

type Package struct {
	Scripts             map[string]string
	Dependencies        map[string]string
	DevDependencies     map[string]string
	PeerDependencies    map[string]string
	PackageManager      string
	PatchedDependencies map[string]string
	Pnpm                struct {
		PatchedDependencies map[string]string
	}
}

Jump to

Keyboard shortcuts

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