From b4397531169f466a0fb4a778b32183d2f64c55c2 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Tue, 15 Feb 2022 15:43:43 +0100 Subject: [PATCH] fix(windows): invalid path when resolving killswitch directory --- lib/common/services/cancellation.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/common/services/cancellation.ts b/lib/common/services/cancellation.ts index 98d25eaacf..f6517b8731 100644 --- a/lib/common/services/cancellation.ts +++ b/lib/common/services/cancellation.ts @@ -66,11 +66,13 @@ class CancellationService implements ICancellationService { } private static get killSwitchDir(): string { - return path.join( - os.tmpdir(), - process.env.SUDO_USER || process.env.USER || process.env.USERNAME || "", - "KillSwitches" - ); + try { + const { username } = os.userInfo(); + return path.join(os.tmpdir(), username, "KillSwitches"); + } catch (err) { + // os.userInfo throws when there's no username of home directory - we'll default to a generic folder + return path.join(os.tmpdir(), ".nativescript-cli", "KillSwitches"); + } } private static makeKillSwitchFileName(name: string): string {