mirror of https://github.com/aminya/setup-cpp
fix: do not cache isSudo
This commit is contained in:
parent
860880c69a
commit
2cdfbab204
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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 */
|
||||||
|
|
Loading…
Reference in New Issue