Node.js virtual environment builder for creating isolated Node.js environments
80
Node.js version discovery, parsing, and selection functionality including fetching available versions from remote repositories and determining latest stable and LTS releases.
Retrieves available Node.js versions from remote repositories for version selection and validation.
def get_node_versions():
"""
Get list of available Node.js versions.
Returns:
list: Available Node.js version strings
Fetches version information from Node.js official repositories
and returns a list of all available versions. Used for version
validation and selection in environment creation.
Handles network requests with proper error handling and
caching to avoid repeated remote calls.
"""Prints available Node.js versions in a formatted display for user selection.
def print_node_versions():
"""
Print available Node.js versions to console.
Displays all available Node.js versions in a formatted layout
suitable for command-line display. Used by the --list option
to show users what versions are available for installation.
Formats versions in columns for readability and includes
indicators for LTS and latest releases when available.
"""Determines the most recent stable Node.js release for automatic version selection.
def get_last_stable_node_version():
"""
Get the latest stable Node.js version.
Returns:
str: Latest stable Node.js version string
Identifies and returns the most recent stable Node.js release.
Used when 'latest' is specified as the Node.js version or
when no specific version is provided.
Filters out pre-release versions and development builds
to ensure stability.
"""Identifies the most recent Long Term Support Node.js release for production environments.
def get_last_lts_node_version():
"""
Get the latest LTS (Long Term Support) Node.js version.
Returns:
str: Latest LTS Node.js version string
Identifies and returns the most recent Node.js LTS release.
Used when 'lts' is specified as the Node.js version for
production environments requiring long-term stability.
LTS versions provide:
- Extended support and maintenance
- Security updates and bug fixes
- Stability for production deployments
"""Parses and normalizes version strings for comparison and validation.
def parse_version(version_str):
"""
Parse version string into comparable components.
Parameters:
version_str (str): Version string (e.g., '16.20.0', 'v18.17.1')
Returns:
tuple: Parsed version components for comparison
Parses version strings into standardized format for:
- Version comparison and sorting
- Validation of version format
- Normalization of version prefixes (removes 'v' prefix)
- Support for semantic versioning comparisons
Handles various version string formats and edge cases.
"""Extracts and validates Node.js version from command-line arguments.
def node_version_from_args(args):
"""
Extract Node.js version from parsed arguments.
Parameters:
args (argparse.Namespace): Parsed command-line arguments
Returns:
str: Resolved Node.js version string
Resolves version specification from arguments:
- 'latest' -> latest stable version
- 'lts' -> latest LTS version
- 'system' -> use system Node.js
- Specific version -> validates and returns
Performs version validation and provides error messages
for invalid version specifications.
"""def _get_versions_json():
"""
Fetch Node.js version data from remote repository.
Returns:
dict: Raw version information from Node.js repository
Internal function that fetches version metadata from
the Node.js official repository. Handles caching and
network error recovery.
"""import nodeenv
# Get list of all available versions
versions = nodeenv.get_node_versions()
print(f"Available versions: {len(versions)}")
print(f"Latest versions: {versions[-5:]}")
# Display versions to user
nodeenv.print_node_versions()import nodeenv
# Get latest stable version
latest = nodeenv.get_last_stable_node_version()
print(f"Latest stable: {latest}")
# Get latest LTS version
lts = nodeenv.get_last_lts_node_version()
print(f"Latest LTS: {lts}")
# Parse and compare versions
v1 = nodeenv.parse_version("16.20.0")
v2 = nodeenv.parse_version("v18.17.1")
print(f"v16.20.0 parsed: {v1}")
print(f"v18.17.1 parsed: {v2}")
print(f"18.17.1 > 16.20.0: {v2 > v1}")import nodeenv
from argparse import Namespace
# Create environment with latest LTS
args = Namespace(node='lts')
version = nodeenv.node_version_from_args(args)
print(f"Using Node.js version: {version}")
# Create environment with specific version
args = Namespace(node='16.20.0')
version = nodeenv.node_version_from_args(args)
print(f"Using Node.js version: {version}")import nodeenv
import sys
# Simulate --list command
sys.argv = ['nodeenv', '--list']
nodeenv.main() # Will call print_node_versions()Install with Tessl CLI
npx tessl i tessl/pypi-nodeenvdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10