Skip to content

feat(detector): implement N (tj/n) detection#6

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

feat(detector): implement N (tj/n) detection#6
dipto0321 merged 1 commit into
mainfrom
feat/detector/add-n

Conversation

@dipto0321

Copy link
Copy Markdown
Owner

Summary

Add the N (tj/n) detector — the 6th of 8 Node.js version managers in the Phase 1 detection rollout.

Unlike the other Unix-binary managers (asdf/mise), n is a bash script with no rich metadata — it just echoes its script-internal VERSION constant and dumps directory paths from find. The implementation is intentionally minimal.

Changes

  • internal/detector/n.go (full implementation):
    • Detect(): platform.LookupManagerBinary("n") != ""
    • Version(): n --version, returns the script's VERSION constant verbatim (no v prefix; e.g., 10.2.0). Both --version and -V work because the upstream script handles both (bin/n line 1694).
    • ListInstalled(): n ls, parses node/<version> lines. The upstream regex "/[0-9]+\.[0-9]+\.[0-9]+" filters non-semver entries before we see them.
    • Mutation methods return ErrNNotImplemented sentinel (matches the ASDF/Mise pattern)
  • internal/detector/n_test.go (24 mocked tests):
    • parseNVersion: standard output (10.2.0), v prefix, leading/trailing whitespace, empty, whitespace-only
    • parseNInstalled: real n ls output, unsorted input → sorted, empty stdout, blank lines, malformed lines (no slash, trailing slash), non-semver versions, deeper paths (forward-compat for node/v20/20.11.1)
    • Method tests: Name, Version (success/V-prefixed/runShell error/parsing error), ListInstalled (success/empty/runShell error/skips unparseable)
    • Detect: PATH-without-binary, PATH-with-binary on the stub (Windows-safe via n.exe)
    • MutationMethods_NotImplemented sentinel test

Design notes

  • n is Unix-only per its README (explicitly says no PowerShell/Git Bash/Cygwin support). On Windows the detector returns false because platform.LookupManagerBinary("n") won't find n.exe in PATH. Users on Windows must use NVMWindows/Nodenv/Volta — nodeup will silently skip n for them.
  • No $N_PREFIX check in Detect(): unlike asdf which accepts the data dir as a positive signal, n requires its $N_PREFIX/bin/n script to be on PATH to be runnable. A data dir alone is not actionable. This is a deliberate asymmetry — documented in the code comments.
  • LastIndex for path parsing: n ls outputs node/<v> lines today, but the parser uses strings.LastIndex(line, "/") so a hypothetical future node/v20/20.11.1 layout would Just Work without code changes.
  • Pre-sorted upstream: n's own sort -k 1,1 -k 2,2n -k 3,3n -k 4,4n -t . produces numeric-by-semver ordering. We re-sort defensively in case upstream changes the algorithm.

Test plan

  • go test ./... — all packages green
  • go vet ./... — clean
  • gofmt -l — clean
  • CI matrix: lint (ubuntu), test on ubuntu/macos/windows, build on 5 platforms — pending

Phase 1 detector: PATH lookup for the n binary, parses
`n --version` (returns the script's VERSION constant verbatim,
e.g. 10.2.0), and lists installed Node versions via `n ls`
(parsed from 'node/<semver>' lines). 24 mocked tests cover all
paths including malformed input, deeper paths, and Windows-safe
n.exe binary naming.
@cocogitto-bot

cocogitto-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

✔️ 4039b81 - Conventional commits check succeeded.

@dipto0321 dipto0321 merged commit 19a7404 into main Jun 29, 2026
10 checks passed
@dipto0321 dipto0321 deleted the feat/detector/add-n branch June 29, 2026 12:41
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