feat(detector): implement N (tj/n) detection#6
Merged
Conversation
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.
|
✔️ 4039b81 - Conventional commits check succeeded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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),
nis a bash script with no rich metadata — it just echoes its script-internalVERSIONconstant and dumps directory paths fromfind. The implementation is intentionally minimal.Changes
internal/detector/n.go(full implementation):Detect():platform.LookupManagerBinary("n") != ""Version():n --version, returns the script'sVERSIONconstant verbatim (novprefix; e.g.,10.2.0). Both--versionand-Vwork because the upstream script handles both (bin/nline 1694).ListInstalled():n ls, parsesnode/<version>lines. The upstream regex"/[0-9]+\.[0-9]+\.[0-9]+"filters non-semver entries before we see them.ErrNNotImplementedsentinel (matches the ASDF/Mise pattern)internal/detector/n_test.go(24 mocked tests):parseNVersion: standard output (10.2.0),vprefix, leading/trailing whitespace, empty, whitespace-onlyparseNInstalled: realn lsoutput, unsorted input → sorted, empty stdout, blank lines, malformed lines (no slash, trailing slash), non-semver versions, deeper paths (forward-compat fornode/v20/20.11.1)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 vian.exe)MutationMethods_NotImplementedsentinel testDesign notes
platform.LookupManagerBinary("n")won't findn.exein PATH. Users on Windows must use NVMWindows/Nodenv/Volta — nodeup will silently skipnfor them.$N_PREFIXcheck in Detect(): unlike asdf which accepts the data dir as a positive signal,nrequires its$N_PREFIX/bin/nscript to be on PATH to be runnable. A data dir alone is not actionable. This is a deliberate asymmetry — documented in the code comments.LastIndexfor path parsing:n lsoutputsnode/<v>lines today, but the parser usesstrings.LastIndex(line, "/")so a hypothetical futurenode/v20/20.11.1layout would Just Work without code changes.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 greengo vet ./...— cleangofmt -l— clean