Shell Integration & Transparent Aliases
Overview
FNPM’s transparent alias system is a game-changer that allows you to use your favorite package manager commands while FNPM handles everything behind the scenes. No more switching between tools or learning new commands!
Quick Setup
The fastest way to get started with transparent aliases:
# 1. Setup FNPM with your preferred package managerfnpm setup pnpm
# 2. Add to your shell profileecho 'eval "$(fnpm source)"' >> ~/.zshrc
# 3. Reload your shellsource ~/.zshrc
# 4. Use your package manager as usual!pnpm installDetailed Configuration
Step 1: Initialize FNPM Hooks
# Setup with specific package managerfnpm setup npm # For npm usersfnpm setup yarn # For yarn usersfnpm setup pnpm # For pnpm usersfnpm setup bun # For bun users# Interactive setup - choose your package managerfnpm setup# Setup without creating hooks (manual FNPM usage)fnpm setup --no-hooksStep 2: Shell Profile Configuration
Choose your shell and follow the appropriate configuration:
# Add to ~/.zshrcecho 'eval "$(fnpm source)"' >> ~/.zshrc
# Reload configurationsource ~/.zshrc
# Or restart your terminalexec zsh# Add to ~/.bashrc (Linux) or ~/.bash_profile (macOS)echo 'eval "$(fnpm source)"' >> ~/.bashrc
# Reload configurationsource ~/.bashrc
# Or restart your terminalexec bash# Fish shell supportfnpm source --fish >> ~/.config/fish/config.fish
# Reload configurationsource ~/.config/fish/config.fishStep 3: Verification
Test that everything is working correctly:
# Check FNPM statusfnpm hooks status
# Test transparent aliasespnpm --help # Should show FNPM interception messagenpm install # Should be handled by FNPMyarn add lodash # Should be redirected to FNPMHow Transparent Aliases Work
Command Interception
When you type a package manager command, FNPM:
- Detects if you’re in an FNPM-managed project (looks for
.fnpm/directory) - Intercepts the command before it reaches the original package manager
- Maps the command to equivalent FNPM operations
- Executes using FNPM’s optimized workflow
- Provides familiar output and behavior
Command Mapping
| Original Command | FNPM Equivalent | Description |
|---|---|---|
npm install | fnpm install | Install all dependencies |
yarn add pkg | fnpm add pkg | Add a new package |
pnpm remove pkg | fnpm remove pkg | Remove a package |
npm run script | fnpm run script | Run a package.json script |
yarn upgrade | fnpm update | Update packages |
Bypass Mechanisms
Sometimes you need to use the original package manager. Here’s how:
# Use full path to bypass FNPM$(which pnpm) install
# Temporarily disable FNPM hooksFNPM_DISABLE=1 pnpm install
# Use original command in non-FNPM projects# (hooks only work in directories with .fnpm/ folder)Advanced Configuration
Project-Specific Setup
You can have different configurations per project:
# Project A - uses npm aliasescd ~/project-afnpm setup npm
# Project B - uses pnpm aliasescd ~/project-bfnpm setup pnpmGlobal vs Local Hooks
Managing Multiple Package Managers
# Check which hooks are activefnpm hooks status
# Create hooks for multiple package managersfnpm hooks create npm yarn pnpm
# Remove specific hooksfnpm hooks remove yarn
# Remove all hooksfnpm hooks remove --allTroubleshooting
Common Issues
Hooks not working after setup:
# Make sure you've sourced your shell profilesource ~/.zshrc # or ~/.bashrc
# Check if FNPM is in your PATHwhich fnpm
# Verify hooks existls -la .fnpm/Commands still using original package manager:
# Check if you're in an FNPM projectfnpm status
# Verify shell integrationecho $FNPM_HOOKS_ENABLED
# Re-source the setupsource .fnpm/setup.shShell errors on startup:
# Check for syntax errors in your shell profilezsh -n ~/.zshrc # for zshbash -n ~/.bashrc # for bash
# Remove and re-add FNPM integration# Remove the line: eval "$(fnpm source)"# Then add it back: echo 'eval "$(fnpm source)"' >> ~/.zshrcPerformance Considerations
The transparent alias system is designed to be lightweight:
- Minimal overhead: Hook detection adds ~1ms to command execution
- Smart caching: FNPM caches project detection for faster subsequent runs
- Lazy loading: Hooks only activate when needed
Debugging
Enable debug mode to see what’s happening:
# Enable debug outputexport FNPM_DEBUG=1
# Run a command to see the interception processpnpm install
# Disable debug outputunset FNPM_DEBUGBest Practices
Team Adoption
- Document the setup: Share this guide with your team
- Add to onboarding: Include FNPM setup in new developer documentation
- Use in CI/CD: FNPM works great in automated environments
- Be patient: Give team members time to adjust to the new workflow
Shell Profile Management
# Keep your shell profile organized# Add this section to ~/.zshrc or ~/.bashrc:
# === FNPM Configuration ===eval "$(fnpm source)"# === End FNPM Configuration ===Project Documentation
Add this to your project’s README:
## Package Management
This project uses FNPM for unified package management. After cloning:
1. Install FNPM: `curl -fsSL https://raw.githubusercontent.com/ideascoldigital/fnpm/main/install.sh | bash`2. Setup project: `fnpm setup`3. Configure shell: `echo 'eval "$(fnpm source)"' >> ~/.zshrc && source ~/.zshrc`4. Use your preferred package manager: `npm install`, `yarn add pkg`, etc.Next Steps
- Advanced Usage - Learn about FNPM’s advanced features
- Team Integration - Best practices for team workflows
- CI/CD Setup - Setting up FNPM in automated environments