Improve fnm module - error handling, user configuration, and missing version workflow#1220
Merged
fdncred merged 2 commits intonushell:mainfrom Feb 9, 2026
Merged
Conversation
Lost a line during copy-paste.
Contributor
|
Thanks |
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
Rewrites the fnm integration to be more robust, configurable, and helpful when things go wrong — particularly when a project requires a Node.js version that isn't installed yet.
I started writing this before i found this module in the nu_scripts repo, and I was already pretty far along when i found it. I stole what was good in the original and kept the particulars that I needed from my thing.
What changed
Robustness
fnm env --jsonis wrapped intry/catchso a broken or misconfigured fnm doesn't crash shell startup.if not ... { }wrapper, improving readability.| uniqto stay clean across shell reloads.fnm use --silent-if-unchangedavoids redundant output when the version hasn't changed.Missing version handling
The original hook ran
fnm useand let its raw error print to the terminal with no follow-up. The new hook detects the failure and either:auto_install: true), or[y/N]confirmation.Install failures are caught and reported instead of silently ignored.
User configuration via
$env.FNM_NU_CONFIGAll behavior is configurable without editing the script:
triggers['.nvmrc', '.node-version', 'package.json']auto_installfalseinstall_flags[]fnm installfallback_aliasnullConfig is re-read on every directory change so updates take effect without restarting the shell.
Fallback alias for non-shell processes
Optionally places an fnm alias's bin directory (e.g.
default) in PATH below the multishell path. The active fnm version always wins, but the fallback gives systemd services, IDEs, and other non-shell processes a stable path tonode,pnpm, etc. (See README.md for why that's useful. I'd share my "nu env to systemd env" bridge too, butexport def "yeet nu env vars into systemd"[] {...}tells you the level of polish in that one.)Comments and documentation
The script is documented with inline comments explaining each section and the reasoning behind less obvious choices. README updated with configuration reference and examples.
Motivation
I don't even remember anymore, I started the day trying to get my backend to talk to my sql server, and five digressions later atleast my IDE sees pnpm. It's been a day. Frontend's running now atleast, and I figured I'd share back.