utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 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, _ []string, _ string) ([]cobra.Completion, cobra.ShellCompDirective)

func DefaultRunCommand

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

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)

Types

type Package

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

Jump to

Keyboard shortcuts

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