@@ -4,6 +4,7 @@ import { join } from "node:path";
44import semver from "semver" ;
55
66const isWindows = process . platform === "win32" ;
7+ const isMacOS = process . platform === "darwin" ;
78
89let cachedPaths : string | null = null ;
910let cachedPathsPromise : Promise < string > | null = null ;
@@ -65,14 +66,21 @@ const scanVersionedNodePaths = async (
6566export const resolveFnmBaseDir = async ( home = process . env . HOME ) : Promise < string | null > => {
6667 if ( ! home ) return null ;
6768
68- const legacyFnmPath = join ( home , ".fnm" ) ;
69- if ( await pathExists ( legacyFnmPath ) ) {
70- // Older fnm installs keep everything under ~/.fnm instead of XDG data directories
71- return legacyFnmPath ;
69+ const xdgBaseDir = join ( process . env . XDG_DATA_HOME || join ( home , ".local" , "share" ) , "fnm" ) ;
70+ const fnmBaseDirCandidates = [ xdgBaseDir , join ( home , ".fnm" ) ] ;
71+
72+ if ( isMacOS ) {
73+ fnmBaseDirCandidates . push ( join ( home , "Library" , "Application Support" , "fnm" ) ) ;
74+ }
75+
76+ for ( const dir of fnmBaseDirCandidates ) {
77+ if ( await pathExists ( dir ) ) {
78+ return dir ;
79+ }
7280 }
7381
74- const xdgDataHome = process . env . XDG_DATA_HOME || join ( home , ".local" , "share" ) ;
75- return join ( xdgDataHome , "fnm" ) ;
82+ // Default to the XDG data dir even if it does not exist yet
83+ return xdgBaseDir ;
7684} ;
7785
7886export const resolveVersionManagerPaths = async ( ) : Promise < string [ ] > => {
0 commit comments