Skip to content

Commit 1718675

Browse files
jeremyfuksaclaude
andcommitted
fix(zsh): remove NVM lazy loading for agent/CLI reliability
Replace lazy loading pattern with traditional NVM initialization to fix failures in non-interactive shells and agent/automation contexts. Problem: - NVM lazy loading (v2.0) used wrapper functions that only work in interactive shells - AI agents, scripts, and tools using `bash -c "npm install"` failed because wrapper functions weren't defined in non-interactive contexts - Commands via absolute paths bypassed wrappers but couldn't find node bins Solution: - Remove lazy-load wrapper functions (_lazy_load_nvm, nvm(), node(), etc) - Restore traditional NVM initialization (source nvm.sh on shell startup) - Accept ~200-400ms startup penalty in exchange for reliability Trade-off: - Shell startup is slower (~200-400ms) but node/npm work everywhere - Users needing fast startup can re-enable lazy loading in ~/.franklin.local.zsh Fixes: Node.js tools now work reliably in: - Non-interactive shells (bash -c, zsh -c) - Agent-spawned subprocesses - CI/CD pipelines - Automation scripts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 96b1af0 commit 1718675

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ and the project aims to follow [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
## [2.0.2] - 2025-12-02
11+
12+
### Changed
13+
14+
- **BREAKING:** Removed NVM lazy loading in favor of traditional eager initialization for reliability in non-interactive shells and agent/CLI tool contexts.
15+
16+
### Fixed
17+
18+
- Node.js and npm now work correctly in non-interactive shells, subprocesses, and when invoked by AI agents or automation tools.
19+
- Commands like `bash -c "npm install"` no longer fail due to undefined wrapper functions.
20+
21+
### Technical
22+
23+
This patch prioritizes reliability over the ~200-400ms shell startup time penalty from loading NVM. The lazy loading pattern (introduced in v2.0) was causing failures when:
24+
- Agents spawned non-interactive subshells
25+
- Scripts used absolute paths to node/npm
26+
- Commands were invoked via `bash -c` or similar
27+
28+
Users who need sub-100ms startup can re-enable lazy loading via `~/.franklin.local.zsh`.
29+
1030
## [2.0.1] - 2025-12-02
1131

1232
### Added

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.0.2

franklin/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "franklin-cli"
7-
version = "2.0.1"
7+
version = "2.0.2"
88
description = "A modern Zsh environment manager with cross-platform support"
99
authors = [
1010
{name = "Jeremy Fuksa", email = "jeremy.fuksa@gmail.com"}

franklin/templates/zshrc.zsh

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -213,41 +213,14 @@ if command -v starship >/dev/null 2>&1; then
213213
eval "$(starship init zsh)"
214214
fi
215215

216-
# --- NVM Lazy Loading ---
217-
# NVM is expensive to load on every shell startup, so we lazy-load it
218-
# The first time you run 'nvm', 'node', 'npm', or 'npx', it will load NVM
219-
216+
# --- NVM (Node Version Manager) ---
217+
# Load NVM if installed
220218
export NVM_DIR="${HOME}/.nvm"
219+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
220+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
221221

222-
# Lazy-load function
223-
_lazy_load_nvm() {
224-
unset -f nvm node npm npx
225-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
226-
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
227-
}
228-
229-
nvm() {
230-
_lazy_load_nvm
231-
nvm "$@"
232-
}
233-
234-
node() {
235-
_lazy_load_nvm
236-
node "$@"
237-
}
238-
239-
npm() {
240-
_lazy_load_nvm
241-
npm "$@"
242-
}
243-
244-
npx() {
245-
_lazy_load_nvm
246-
npx "$@"
247-
}
248-
249-
# --- UV (Python Package Manager) Lazy Loading ---
250-
# Similar to NVM, lazy-load uv
222+
# --- UV (Python Package Manager) ---
223+
# Ensure uv is on PATH if installed
251224
if [ -f "${HOME}/.local/bin/uv" ]; then
252225
export PATH="${HOME}/.local/bin:${PATH}"
253226
fi

0 commit comments

Comments
 (0)