@@ -13,6 +13,8 @@ import { ChildProcess } from '../utilities/processUtils'
1313import globals , { isWeb } from '../extensionGlobals'
1414import * as devConfig from '../../dev/config'
1515import path from 'path'
16+ import { fs } from '../fs/fs'
17+ import { ToolkitError } from '../errors'
1618
1719/**
1820 * Returns true if the current build is running on CI (build server).
@@ -272,16 +274,28 @@ export async function getMachineId(): Promise<string> {
272274 return ( await proc . run ( ) ) . stdout . trim ( ) ?? 'unknown-host'
273275}
274276
275- export function getApplicationSupportFolder ( ) {
277+ /**
278+ * Gets the application cache folder for the current platform
279+ *
280+ * Follows the cache_dir convention outlined in https://crates.io/crates/dirs
281+ */
282+ export function getApplicationCacheFolder ( ) {
283+ const homeDir = fs . getUserHomeDir ( )
276284 switch ( process . platform ) {
277285 case 'darwin' : {
278- return path . join ( os . homedir ( ) , 'Library/Application Support ' )
286+ return path . join ( homeDir , 'Library/Caches ' )
279287 }
280288 case 'win32' : {
281- return process . env . APPDATA
289+ const localAppData = process . env . LOCALAPPDATA
290+ if ( ! localAppData ) {
291+ throw new ToolkitError ( 'LOCALAPPDATA environment variable not set' , {
292+ code : 'LocalAppDataNotFound' ,
293+ } )
294+ }
295+ return localAppData
282296 }
283297 case 'linux' : {
284- return process . env . XDG_CACHE_HOME || path . join ( os . homedir ( ) , '.cache' )
298+ return path . join ( homeDir , '.cache' )
285299 }
286300 default : {
287301 throw new Error ( `Unsupported platform: ${ process . platform } . Expected 'darwin', 'win32', or 'linux'.` )
0 commit comments