CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-nodeenv

Node.js virtual environment builder for creating isolated Node.js environments

80

1.25x
Overview
Eval results
Files

package-management.mddocs/

Package Management

npm installation and package management functionality including npm setup, requirements file processing, and package installation with version management.

Capabilities

npm Installation

Installs npm package manager in the Node.js virtual environment with platform-specific optimizations.

def install_npm(env_dir, _src_dir, args):
    """
    Install npm package manager in Node.js environment.
    
    Parameters:
    env_dir (str): Environment directory path
    _src_dir (str): Source directory (unused in current implementation)
    args (argparse.Namespace): Configuration arguments
    
    Installs npm using the version specified in args.npm:
    - 'latest' for most recent npm version
    - Specific version number (e.g., '8.19.0')
    - Downloads and configures npm for the environment
    - Sets up proper npm configuration and cache directories
    """

Windows npm Installation

Platform-specific npm installation function optimized for Windows environments.

def install_npm_win(env_dir, src_dir, args):
    """
    Install npm on Windows platforms with Windows-specific handling.
    
    Parameters:
    env_dir (str): Environment directory path
    src_dir (str): Source/download directory
    args (argparse.Namespace): Configuration arguments
    
    Handles Windows-specific npm installation requirements:
    - Windows path separators and executable extensions
    - npm.cmd and npm batch file setup
    - Windows registry and environment variable configuration
    - PowerShell execution policy considerations
    """

Package Installation from Requirements

Installs npm packages from requirements files, similar to pip's requirements.txt functionality.

def install_packages(env_dir, args):
    """
    Install npm packages from requirements file.
    
    Parameters:
    env_dir (str): Environment directory path
    args (argparse.Namespace): Configuration arguments containing requirements file path
    
    Processes requirements file containing package specifications:
    - Package names with specific versions (e.g., 'express@4.18.0')
    - Package names with version ranges
    - Git repository URLs
    - Local file paths
    
    Requirements file format example:
    express@4.18.0
    lodash@^4.17.21
    moment@>=2.29.0
    
    Installs packages globally within the Node.js environment
    and handles dependency resolution and version conflicts.
    """

Shell Functions

The activation scripts created by nodeenv include built-in package management functions:

freeze Function

The freeze function is available in activated environments and provides functionality similar to pip freeze.

# In bash/zsh environments
freeze [output_file]

# List installed packages
freeze

# Save to requirements file  
freeze requirements.txt

# List local packages only
freeze -l requirements.txt
# In fish shell environments
freeze [output_file]

# List installed packages
freeze

# Save to requirements file
freeze requirements.txt

# List local packages only  
freeze -l requirements.txt

The freeze function:

  • Lists all globally installed npm packages in the environment
  • Outputs package names with exact version numbers
  • Supports saving to requirements files for environment reproduction
  • Provides local package listing with -l flag
  • Compatible with requirements file format for --requirements option

Usage Examples

Install npm with Specific Version

import nodeenv
from argparse import Namespace

args = Namespace(
    npm='8.19.0',  # Specific npm version
    with_npm=True
)

nodeenv.install_npm('/path/to/env', '/tmp/src', args)

Install Packages from Requirements File

import nodeenv
from argparse import Namespace

# Create requirements.txt with content:
# express@4.18.0
# lodash@4.17.21
# moment@2.29.4

args = Namespace(
    requirements='/path/to/requirements.txt',
    jobs='2'
)

nodeenv.install_packages('/path/to/env', args)

Complete Environment with Packages

import nodeenv
from argparse import Namespace

# Create environment and install packages
args = Namespace(
    node='18.17.0',
    npm='9.8.0', 
    with_npm=True,
    requirements='/path/to/requirements.txt',
    jobs='4'
)

env_dir = '/path/to/myenv'
src_dir = '/tmp/nodeenv-src'

# Create environment
nodeenv.create_environment(env_dir, args)

# Packages are automatically installed if requirements file specified

Using freeze in Activated Environment

# Activate environment
source myenv/bin/activate

# Install some packages
npm install -g express lodash moment

# List installed packages
freeze

# Output:
# express@4.18.2
# lodash@4.17.21  
# moment@2.29.4

# Save to requirements file
freeze requirements.txt

# Deactivate environment
deactivate_node

Install with Tessl CLI

npx tessl i tessl/pypi-nodeenv

docs

cli.md

configuration.md

environment.md

index.md

node-install.md

package-management.md

utilities.md

version-management.md

tile.json