Skip to content

Commit 06f4f56

Browse files
committed
fix(windows): add LOCALAPPDATA fallback for app data path
Add fallback path resolution when LOCALAPPDATA environment variable is missing on Windows systems. This resolves 76 test failures in Windows CI where missing LOCALAPPDATA caused undefined app data path, leading to empty config and exit code mismatches. Changes: - src/constants/paths.mts: Construct fallback from homedir() + AppData/Local - Maintains existing behavior on macOS and Linux - Logs warning when fallback is used - Updated comments to reflect new fallback behavior Root cause chain: Missing LOCALAPPDATA → getSocketAppDataPath() returns undefined → empty config → org resolution fails → exit code 1
1 parent af46aff commit 06f4f56

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

packages/cli/src/constants/paths.mts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,33 @@ export function getBlessedOptions() {
176176

177177
export function getSocketAppDataPath(): string | undefined {
178178
// Get the OS app data directory:
179-
// - Win: %LOCALAPPDATA% or fail?
179+
// - Win: %LOCALAPPDATA% or fallback to %USERPROFILE%/AppData/Local
180180
// - Mac: %XDG_DATA_HOME% or fallback to "~/Library/Application Support/"
181181
// - Linux: %XDG_DATA_HOME% or fallback to "~/.local/share/"
182-
// Note: LOCALAPPDATA is typically: C:\Users\USERNAME\AppData
182+
// Note: LOCALAPPDATA typically points to user's AppData\Local directory.
183183
// Note: XDG stands for "X Desktop Group", nowadays "freedesktop.org"
184184
// On most systems that path is: $HOME/.local/share
185185
// Then append `socket/settings`, so:
186-
// - Win: %LOCALAPPDATA%\socket\settings or return undefined
186+
// - Win: %LOCALAPPDATA%\socket\settings or %USERPROFILE%\AppData\Local\socket\settings
187187
// - Mac: %XDG_DATA_HOME%/socket/settings or "~/Library/Application Support/socket/settings"
188188
// - Linux: %XDG_DATA_HOME%/socket/settings or "~/.local/share/socket/settings"
189189
const isWin32 = process.platform === 'win32'
190190
let dataHome: string | undefined = isWin32
191191
? process.env['LOCALAPPDATA']
192192
: process.env['XDG_DATA_HOME']
193193
if (!dataHome) {
194+
const home = homedir()
194195
if (isWin32) {
195-
logger.warn('Missing %LOCALAPPDATA%.')
196-
return undefined
196+
// Fallback: Use USERPROFILE or HOME when LOCALAPPDATA is missing.
197+
dataHome = path.join(home, 'AppData', 'Local')
198+
logger.warn('LOCALAPPDATA not set, using fallback path.')
199+
} else {
200+
const isDarwin = process.platform === 'darwin'
201+
dataHome = path.join(
202+
home,
203+
isDarwin ? 'Library/Application Support' : '.local/share',
204+
)
197205
}
198-
const home = homedir()
199-
const isDarwin = process.platform === 'darwin'
200-
dataHome = path.join(
201-
home,
202-
isDarwin ? 'Library/Application Support' : '.local/share',
203-
)
204206
}
205207
return dataHome ? path.join(dataHome, 'socket', 'settings') : undefined
206208
}

0 commit comments

Comments
 (0)