refactor: assign env[PATH] to constant to remove need for ! (#8680)

This commit is contained in:
Brandon Cheng authored and GitHub committed 2024-10-21 03:27:57 +02:00
1 parent 78412f2e4b
commit 1922b4aa3f
1 file changed
+4 -3
+4 -3
View File
@@ -9,10 +9,11 @@ export interface PrependDirsToPathResult {
export function prependDirsToPath (prependDirs: string[], env = process.env): PrependDirsToPathResult {
const prepend = prependDirs.join(path.delimiter)
if (env[PATH] != null && (env[PATH] === prepend || env[PATH]!.startsWith(`${prepend}${path.delimiter}`))) {
const envPath = env[PATH]
if (envPath != null && (envPath === prepend || envPath.startsWith(`${prepend}${path.delimiter}`))) {
return {
name: PATH,
value: env[PATH]!,
value: envPath,
updated: false,
}
}
@@ -20,7 +21,7 @@ export function prependDirsToPath (prependDirs: string[], env = process.env): Pr
name: PATH,
value: [
prepend,
...(env[PATH] != null ? [env[PATH]] : []),
...(envPath != null ? [envPath] : []),
].join(path.delimiter),
updated: true,
}