Skip to content

feat(detector): implement Nodenv detection#7

Merged
dipto0321 merged 1 commit into
mainfrom
feat/detector/add-nodenv
Jun 29, 2026
Merged

feat(detector): implement Nodenv detection#7
dipto0321 merged 1 commit into
mainfrom
feat/detector/add-nodenv

Conversation

@dipto0321

Copy link
Copy Markdown
Owner

Changes

  • internal/detector/nodenv.go (full implementation):

    • Detect(): platform.LookupManagerBinary("nodenv") != "" OR $NODENV_ROOT env OR ~/.nodenv on disk (ASDF pattern)
    • Version(): nodenv --version, strips literal "nodenv " prefix, first whitespace-separated token, optional v prefix stripped
    • ListInstalled(): nodenv versions, lines * <v> / <v>, the trailing (set by <origin>) on current-version lines is stripped before semver parse; system sentinel filtered out
    • nodenvRoot() helper: $NODENV_ROOT~/.nodenv, mirrors asdfDataDir
    • Mutation methods return ErrNodenvNotImplemented sentinel (ASDF pattern)
  • internal/detector/nodenv_test.go (24 mocked tests):

    • parseNodenvVersion: standard, git-revision suffix (1.6.2-12-gabc1234), v-prefixed, whitespace, empty, whitespace-only, no-version-after-prefix
    • parseNodenvInstalled: real output (with (set by ...) suffix), filters system sentinel, unsorted → sorted ascending, empty stdout, only blank lines, skips unparseable lines
    • Method tests: Name, Version (success capturing command, v-prefixed, runShell error, parsing error), ListInstalled (success, empty stdout, runShell error)
    • Detect: PATH-without-binary, dir-on-disk, $NODENV_ROOT override, empty env falls through, binary-on-PATH Windows-safe via nodenv.exe
    • MutationMethods_NotImplemented sentinel test
    • nodenvRoot helper: env-precedence, home-fallback, empty-when-no-home, whitespace-only-env-falls-through

Design notes

  • The * <v> (current) line in nodenv versions carries a trailing (set by <origin>) annotation that asdf's output does NOT have. The parser strips everything from the first whitespace after the digits before handing to semver.NewVersion — this is the only behavioral divergence from parseASDFInstalled.
  • The system sentinel is filtered explicitly (the system line is emitted iff nodenv-which node succeeds, i.e., there is a node on the system PATH outside Nodenv's managed versions — not a managed install).
  • nodenvRoot() mirrors asdfDataDir() (same env → home fallback, same whitespace handling) for consistency.
  • We use strings.CutPrefix("nodenv ") in parseNodenvVersion so unexpected branding like "Nodenv v1.6.2" errors loudly rather than silently returning the wrong token.
  • Nodenv is documented as Unix-only — same posture as N; Windows users must use WSL or fall back to NVMWindows.

Mirrors the ASDF pattern (PATH binary + env var + ~/.nodenv fallback)
since Nodenv and ASDF share a near-identical install layout. Filters the
'system' sentinel from 'nodenv versions' and strips the ' (set by
<origin>)' annotation that asdf's output lacks. Mutation methods
return ErrNodenvNotImplemented (Phase 4 work).
@cocogitto-bot

cocogitto-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

✔️ 4fd9baa - Conventional commits check succeeded.

@dipto0321 dipto0321 merged commit dc227e1 into main Jun 29, 2026
10 checks passed
@dipto0321 dipto0321 deleted the feat/detector/add-nodenv branch June 29, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant