jsdependency

package
v2.0.0-alpha.50 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package jsdependency provides helpers to build npm/yarn install and remove commands for a detected JS package manager.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommand

func AddCommand(factory command.Factory, tool Tool, scope CommandScope, pkgs ...string) command.Command

AddCommand returns the command that installs the given packages in the requested scope for the given tool, built via factory.

func RemoveCommand

func RemoveCommand(factory command.Factory, tool Tool, scope CommandScope, pkgs ...string) command.Command

RemoveCommand returns the command that removes the given packages in the requested scope for the given tool, built via factory.

Types

type CommandScope

type CommandScope string

CommandScope describes whether a package manager command applies globally or locally.

const (
	Local  CommandScope = "local"
	Global CommandScope = "global"
)

Supported command scopes.

type InstallCommand

type InstallCommand struct {
	Command     command.Command
	IgnoreError bool
}

InstallCommand pairs a command with a flag indicating whether its failure can be ignored (e.g. yarn exits non-zero when removing a package that is not installed).

func InstallGlobalDependencyCommand

func InstallGlobalDependencyCommand(factory command.Factory, tool Tool, dependency, version string) ([]InstallCommand, error)

InstallGlobalDependencyCommand returns the sequence of commands that removes any existing local copy and adds the dependency globally at the requested version.

type Tool

type Tool string

Tool identifies a JS package manager.

const (
	Npm  Tool = "npm"
	Yarn Tool = "yarn"
)

Supported JS package manager tools.

func DetectTool

func DetectTool(packageJSONDir string) (Tool, error)

DetectTool reports which JS package manager to use by checking for a yarn.lock file next to package.json. Falls back to Npm when absent.

Jump to

Keyboard shortcuts

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