nodepm

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package nodepm detects which Node package manager governs a repo (pnpm, yarn, npm) from its lockfile. Every TS gate uses this to run project-local binaries via the pm's exec command instead of relying on global PATH.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasLocalBin

func HasLocalBin(root, tool string) bool

HasLocalBin returns true when `node_modules/.bin/<tool>` exists at root. Every TS gate calls this before invoking the package manager: if the project-local binary isn't there, the gate emits a visible SKIP instead of trying to shell out and failing on cryptic pm errors.

Types

type Manager

type Manager struct {
	Name   Name
	Binary string   // the pm binary to invoke ("pnpm", "npm", "yarn")
	Exec   []string // args that prefix the tool name (e.g. ["exec"] for pnpm)
	Run    []string // args that prefix a package.json script name
}

Manager describes how to run a repo-local binary via a specific pm.

func Detect

func Detect(root string) Manager

Detect walks the lockfile hierarchy at `root` and returns the pm. When no lockfile is present it defaults to npm — npx still resolves project-local bins, so this is the least-surprising fallback.

func (Manager) ExecArgs

func (m Manager) ExecArgs(tool string, args ...string) []string

ExecArgs returns the full argv to run a local binary with args.

m := nodepm.Detect(root); cmd := exec.Command(m.Binary, m.ExecArgs("tsc", "--noEmit")...)

func (Manager) RunScriptArgs

func (m Manager) RunScriptArgs(script string) []string

RunScriptArgs returns the argv to run a package.json script.

m := nodepm.Detect(root); cmd := exec.Command(m.Binary, m.RunScriptArgs("build")...)

type Name

type Name string

Name identifies a specific Node package manager.

const (
	PNPM Name = "pnpm"
	Yarn Name = "yarn"
	NPM  Name = "npm"
)

Jump to

Keyboard shortcuts

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