UNPKG

preferred-node-version

Version:

Get the preferred Node.js version of a project or user

33 lines (20 loc) 573 B
import{homedir as getHomeDir}from"node:os"; import{dirname}from"node:path"; import{env}from"node:process"; export const getSearchDirs=(cwd,globalOpt)=>{ const homeDir=env.TEST_HOME_DIR===undefined?HOME_DIR:env.TEST_HOME_DIR; if(globalOpt){ return[homeDir] } const parentDirs=getParentDirs(cwd); if(parentDirs.includes(homeDir)){ return parentDirs } return[...parentDirs,homeDir] }; const getParentDirs=(dir)=>{ const parentDir=dirname(dir); const parentDirs=parentDir===dir?[]:getParentDirs(parentDir); return[dir,...parentDirs] }; const HOME_DIR=getHomeDir();