Fast, reliable, and secure dependency management tool for JavaScript/Node.js projects
npx @tessl/cli install tessl/npm-yarn@1.22.0Yarn is a fast, reliable, and secure dependency management tool for JavaScript/Node.js projects. It serves as an alternative to npm with enhanced features including offline mode, deterministic installs, network performance optimizations, and flat dependency resolution. Yarn provides comprehensive dependency management capabilities with caching mechanisms, detailed lockfile format for reproducible builds, and integrity verification through checksums.
npm install -g yarn or download from https://yarnpkg.com/yarn, yarnpkgYarn is a command-line tool, so it doesn't use traditional imports. Instead, it's invoked via shell commands:
# Global installation
npm install -g yarn
# Usage via npx (no installation required)
npx yarn <command>
# Direct binary usage (after global install)
yarn <command>
yarnpkg <command> # Alternative binary nameYarn is primarily used as a command-line tool for managing dependencies:
# Install dependencies
yarn install
# Add a dependency
yarn add react
# Add a dev dependency
yarn add --dev jest
# Remove a dependency
yarn remove lodash
# Run scripts
yarn run build
yarn test
# Upgrade dependencies
yarn upgradeYarn is built around several key components:
Core commands for installing, adding, removing, and upgrading dependencies.
# Install all dependencies from package.json
yarn install [--production] [--frozen-lockfile] [--offline]
# Add dependencies to package.json
yarn add <package> [--dev] [--peer] [--optional] [--exact] [--tilde]
# Remove dependencies from package.json
yarn remove <package>
# Upgrade dependencies
yarn upgrade [package] [--latest] [--exact] [--pattern]Commands for project initialization, script execution, and development workflow.
# Initialize new project
yarn init [-y] [--private]
# Create project from template
yarn create <starter-kit-package> [args]
# Run package scripts
yarn run <script-name> [args]
yarn <script-name>
# Execute binaries
yarn exec <command> [args]
# Run Node.js
yarn node [args]Commands for inspecting packages, dependencies, and project status.
# Show package information
yarn info <package> [field]
# List installed packages
yarn list [--depth] [--pattern]
# Show why package is installed
yarn why <package>
# Show outdated packages
yarn outdated [package]
# Show license information
yarn licenses list|generate-disclaimer
# Show binary locations
yarn bin [package]Commands for interacting with npm registries and package publishing.
# Login to registry
yarn login
# Logout from registry
yarn logout
# Publish package
yarn publish [--tag] [--access] [--registry]
# Manage package access
yarn access public|restricted <package>
yarn access grant|revoke <read-write|read-only> <scope:team> <package>
# Manage package ownership
yarn owner add|remove|list <user> <package>
# Manage package tags
yarn tag add|remove|list <package> <tag>
# Manage organization teams
yarn team create|destroy <scope:team>
yarn team add|remove <scope:team> <user>
yarn team list <scope> [team]Commands for managing monorepos and workspaces.
# Run command in all workspaces
yarn workspaces run <command>
# Get workspace information
yarn workspaces info [--json]
# Run command in specific workspace
yarn workspace <workspace-name> <command>Commands for managing yarn configuration and global packages.
# Manage configuration
yarn config set <key> <value> [--global]
yarn config get <key>
yarn config delete <key>
yarn config list
# Manage global packages
yarn global add <package>
yarn global remove <package>
yarn global list
# Manage symlinks for development
yarn link [package]
yarn unlink [package]Commands for managing yarn's package cache.
# Show cache directory
yarn cache dir
# List cached packages
yarn cache list [--pattern]
# Clean cache
yarn cache clean [package]Additional utility commands for package integrity, security, and maintenance.
# Verify package integrity
yarn check [--integrity] [--verify-tree]
# Run security audit
yarn audit [--level] [--json]
# Create package tarball
yarn pack [--filename]
# Import dependencies from package-lock.json
yarn import
# Generate lockfile entry
yarn generate-lock-entry
# Clean unnecessary files
yarn autoclean [--init] [--force]
# Temporarily unplug Plug'n'Play packages for debugging
yarn unplug <package> [--clear] [--clear-all]
# Manage release policies and yarn version
yarn policies set-version <version>
# Show help
yarn help [command]
# Show version
yarn version [--new-version] [--major] [--minor] [--patch]
# Show versions of dependencies
yarn versions// Command-line options for yarn install
interface InstallOptions {
production?: boolean; // Install only production dependencies
"frozen-lockfile"?: boolean; // Don't generate lockfile and fail if update needed
"pure-lockfile"?: boolean; // Don't generate lockfile
offline?: boolean; // Use only cached packages
"ignore-scripts"?: boolean; // Don't run lifecycle scripts
"ignore-platform"?: boolean; // Don't check platform compatibility
"ignore-engines"?: boolean; // Don't check engines compatibility
"ignore-optional"?: boolean; // Don't install optional dependencies
"force"?: boolean; // Force re-download of packages
"har"?: boolean; // Save HAR file for network requests
"non-interactive"?: boolean; // Disable interactive prompts
"no-bin-links"?: boolean; // Don't create symlinks for binaries
"flat"?: boolean; // Install all dependencies in root node_modules
"focus"?: boolean; // Focus on workspace dependencies
"verbose"?: boolean; // Show additional logging
}
// Command-line options for yarn add
interface AddOptions {
dev?: boolean; // Add to devDependencies
peer?: boolean; // Add to peerDependencies
optional?: boolean; // Add to optionalDependencies
exact?: boolean; // Install exact version
tilde?: boolean; // Install with tilde range
"ignore-workspace-root-check"?: boolean; // Allow install on workspace root
"audit"?: boolean; // Run audit after install
}
// Configuration values
interface YarnConfig {
registry?: string; // Package registry URL
"cache-folder"?: string; // Cache directory path
"global-folder"?: string; // Global packages directory
"modules-folder"?: string; // Local node_modules directory name
"offline-mirror"?: string; // Offline mirror directory
"disable-self-update-check"?: boolean; // Disable update checks
"ignore-engines"?: boolean; // Ignore engines field
"ignore-scripts"?: boolean; // Don't run lifecycle scripts
workspaces?: boolean; // Enable workspaces
"workspace-experimental"?: boolean; // Enable experimental features
}Yarn uses standard exit codes to indicate success or failure:
# Cache directory override
YARN_CACHE_FOLDER=/path/to/cache
# Registry override
YARN_REGISTRY=https://registry.npmjs.org
# Disable update checks
YARN_DISABLE_SELF_UPDATE_CHECK=true
# Enable offline mode
YARN_ENABLE_OFFLINE_MODE=true
# HTTP proxy settings
HTTP_PROXY=http://proxy.example.com:8080
HTTPS_PROXY=https://proxy.example.com:8080