2023-04-22 12:14:22 +08:00
|
|
|
import { warning } from "ci-log"
|
2023-05-24 12:26:47 +08:00
|
|
|
import { promises } from "fs"
|
|
|
|
const { readFile } = promises
|
2023-04-22 12:14:22 +08:00
|
|
|
import { join } from "path"
|
2023-05-25 02:18:46 +08:00
|
|
|
import { isInstalled } from "./utils/std/resolve"
|
2023-04-22 12:14:22 +08:00
|
|
|
|
|
|
|
// auto self update notifier
|
|
|
|
export async function checkUpdates() {
|
|
|
|
try {
|
2023-05-25 02:18:46 +08:00
|
|
|
if (await isInstalled("update-notifier")) {
|
|
|
|
const [un, packageJsonString] = await Promise.all([
|
|
|
|
import("update-notifier"),
|
|
|
|
readFile(join(__dirname, "..", "package.json"), "utf8"),
|
|
|
|
])
|
2023-05-24 12:37:34 +08:00
|
|
|
|
2023-05-25 02:18:46 +08:00
|
|
|
const packageJson = JSON.parse(packageJsonString)
|
2023-05-24 12:37:34 +08:00
|
|
|
|
2023-05-25 02:18:46 +08:00
|
|
|
// the types do not match the actual export
|
|
|
|
const updateNotifier = un as unknown as (typeof un)["default"]
|
2023-05-24 12:37:34 +08:00
|
|
|
|
2023-05-25 02:18:46 +08:00
|
|
|
updateNotifier({ pkg: packageJson }).notify()
|
|
|
|
} else {
|
|
|
|
warning("setup-cpp could not find its dependency update-notifier, skipping check for updates")
|
|
|
|
}
|
2023-04-22 12:14:22 +08:00
|
|
|
} catch (err) {
|
2023-05-24 12:37:34 +08:00
|
|
|
warning(`Failed to check for updates: ${err instanceof Error ? err.message + err.stack : err}`)
|
2023-04-22 12:14:22 +08:00
|
|
|
}
|
|
|
|
}
|