fix: do not cache isSudo

This commit is contained in:
Amin Yahyaabadi 2022-08-07 17:31:14 -07:00
parent 860880c69a
commit 2cdfbab204
5 changed files with 6 additions and 17 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.mjs vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,20 +1,9 @@
import which from "which" import which from "which"
import execa from "execa" import execa from "execa"
let isSudoCache: boolean | undefined = undefined /** Detect if sudo is available and the user has root privileges */
/**
* Detect if sudo is available and the user has root privileges
*
* @note it caches the result for the subsequent calls to this function.
*/
export function isSudo(): boolean { export function isSudo(): boolean {
if (isSudoCache !== undefined) { return (Boolean(process.env.CI) || isRoot()) && which.sync("sudo", { nothrow: true }) !== null
return isSudoCache
}
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition
isSudoCache = (Boolean(process.env.CI) || isRoot()) && which.sync("sudo", { nothrow: true }) !== null
return isSudoCache
} }
/** Detect if the process has root privileges */ /** Detect if the process has root privileges */