-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: revalidator, global-config (#1504)
- Loading branch information
1 parent
1472eaf
commit b373c4f
Showing
6 changed files
with
80 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { readFileSync } from "fs"; | ||
import { homedir } from "os"; | ||
import { join } from "path"; | ||
|
||
const DARWIN_AUTH_PATH = "~/Library/Application Support/com.vercel.cli/auth.json"; | ||
const LINUX_AUTH_PATH = "~/.local/share/com.vercel.cli/auth.json"; | ||
|
||
function getAuthJson(): string | undefined { | ||
try { | ||
if (process.platform === "darwin") { | ||
return String(readFileSync(join(homedir(), DARWIN_AUTH_PATH.slice(1)))); | ||
} else if (process.platform === "linux") { | ||
return String(readFileSync(join(homedir(), LINUX_AUTH_PATH.slice(1)))); | ||
} | ||
} catch (_e) { | ||
// do nothing | ||
} | ||
return undefined; | ||
} | ||
|
||
export function getVercelTokenFromGlobalConfig(): string | undefined { | ||
const authJson = getAuthJson(); | ||
|
||
if (authJson == null) { | ||
return undefined; | ||
} | ||
try { | ||
const auth = JSON.parse(authJson); | ||
return auth.token; | ||
} catch (_e) { | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters