@@ -3,16 +3,21 @@ import { join, basename } from "node:path";
33import { stat , readdir , readFile , realpath , lstat } from "node:fs/promises" ;
44import type { Stats } from "node:fs" ;
55
6- const default_home = join ( homedir ( ) , ".cache" ) ;
7- export const HF_HOME : string =
8- process . env [ "HF_HOME" ] ?? join ( process . env [ "XDG_CACHE_HOME" ] ?? default_home , "huggingface" ) ;
6+ function getDefaultHome ( ) : string {
7+ return join ( homedir ( ) , ".cache" ) ;
8+ }
99
10- const default_cache_path = join ( HF_HOME , "hub" ) ;
10+ function getDefaultCachePath ( ) : string {
11+ return process . env [ "HF_HOME" ] ?? join ( process . env [ "XDG_CACHE_HOME" ] ?? getDefaultHome ( ) , "huggingface" )
12+ }
1113
12- // Legacy env variable
13- export const HUGGINGFACE_HUB_CACHE = process . env [ "HUGGINGFACE_HUB_CACHE" ] ?? default_cache_path ;
14- // New env variable
15- export const HF_HUB_CACHE = process . env [ "HF_HUB_CACHE" ] ?? HUGGINGFACE_HUB_CACHE ;
14+ function getHuggingFaceHubCache ( ) : string {
15+ return process . env [ "HUGGINGFACE_HUB_CACHE" ] ?? getDefaultCachePath ( ) ;
16+ }
17+
18+ function getHFHubCache ( ) : string {
19+ return process . env [ "HF_HUB_CACHE" ] ?? getHuggingFaceHubCache ( ) ;
20+ }
1621
1722const FILES_TO_IGNORE : string [ ] = [ ".DS_Store" ] ;
1823
@@ -61,7 +66,7 @@ export interface HFCacheInfo {
6166}
6267
6368export async function scanCacheDir ( cacheDir : string | undefined = undefined ) : Promise < HFCacheInfo > {
64- if ( ! cacheDir ) cacheDir = HF_HUB_CACHE ;
69+ if ( ! cacheDir ) cacheDir = getHFHubCache ( ) ;
6570
6671 const s = await stat ( cacheDir ) ;
6772 if ( ! s . isDirectory ( ) ) {
0 commit comments