npm

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NonEmptyPackage = &Package{Dependencies: map[string]string{"not-empty": "not-empty"}}

NonEmptyPackage returns a Package with a dummy dependency. This is useful when you need to run npm install but don't have a package.json to read.

Functions

func InstallDependencies

func InstallDependencies(ctx context.Context, exec executor.Executor, pkg *Package, additionalParams ...string) error

InstallDependencies runs npm install using the given executor. Additional parameters can be passed to customize the install behavior.

func InstallDependenciesStreamed

func InstallDependenciesStreamed(ctx context.Context, exec executor.Executor, pkg *Package, out io.Writer, additionalParams ...string) error

InstallDependenciesStreamed behaves like InstallDependencies but, when out is non-nil, streams the combined npm output to it live instead of buffering it and only surfacing it on failure.

func NodeModulesExists

func NodeModulesExists(root string) bool

NodeModulesExists checks if a node_modules directory exists in the given root.

func PatchPackageLockToRemoveCanIUse

func PatchPackageLockToRemoveCanIUse(packageLockPath string) error

PatchPackageLockToRemoveCanIUse removes caniuse-lite from a package-lock.json file. This is needed because the caniuse-lite package is often outdated in lock files and causes issues with browserslist.

Types

type Package

type Package struct {
	Dependencies    map[string]string `json:"dependencies"`
	DevDependencies map[string]string `json:"devDependencies"`
	Scripts         map[string]string `json:"scripts"`
}

Package represents a parsed package.json file.

func ReadPackage

func ReadPackage(dir string) (*Package, error)

ReadPackage reads and parses a package.json file from the given directory.

func (Package) HasDevDependency

func (p Package) HasDevDependency(name string) bool

HasDevDependency checks if the package.json contains a dev dependency with the given name.

func (Package) HasScript

func (p Package) HasScript(name string) bool

HasScript checks if the package.json contains a script with the given name.

Jump to

Keyboard shortcuts

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