fatal dep error

This commit is contained in:
Chris Wanstrath 2025-10-01 11:29:57 -07:00
parent 14645980af
commit f06425f7ff
2 changed files with 17 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import { watch } from "fs"
import { apps } from "./webapp" import { apps } from "./webapp"
import { expectDir } from "./utils" import { expectDir } from "./utils"
import { NOSE_WWW } from "./config" import { NOSE_WWW } from "./config"
import { expectShellCmd } from "./utils"
export const dnsEntries: Record<string, any> = {} export const dnsEntries: Record<string, any> = {}
@ -17,6 +18,8 @@ let dnsInit = false
export async function initDNS() { export async function initDNS() {
if (process.env.NODE_ENV !== "production") return if (process.env.NODE_ENV !== "production") return
if (!await expectShellCmd("avahi-publish")) return
dnsInit = true dnsInit = true
startWatcher() startWatcher()

View File

@ -1,6 +1,7 @@
//// ////
// Shell utilities and helper functions. // Shell utilities and helper functions.
import { $ } from "bun"
import { statSync } from "fs" import { statSync } from "fs"
import { setFatal } from "./fatal" import { setFatal } from "./fatal"
import { stat } from "fs/promises" import { stat } from "fs/promises"
@ -16,7 +17,7 @@ export function untilde(path: string): string {
return path.replace("~", `/${prefix}/${process.env.USER}`) return path.replace("~", `/${prefix}/${process.env.USER}`)
} }
// End the process with an instructive error if a directory doesn't exist. // Cause a fatal error if a directory doesn't exist.
export function expectDir(path: string): boolean { export function expectDir(path: string): boolean {
if (!isDir(path)) { if (!isDir(path)) {
setFatal(`Missing critical directory: ${path}`) setFatal(`Missing critical directory: ${path}`)
@ -26,6 +27,18 @@ export function expectDir(path: string): boolean {
return true return true
} }
// Cause a fatal error if a system binary doesn't exist.
export async function expectShellCmd(cmd: string): Promise<boolean> {
try {
await $`which ${cmd}`
console.log("WHICH", cmd)
return true
} catch {
setFatal(`Missing critical dependency: avahi-publish`)
return false
}
}
// Is the given `path` a file? // Is the given `path` a file?
export function isFile(path: string): boolean { export function isFile(path: string): boolean {
try { try {