From f06425f7ff417a814cd6b5855414a628283ac2d3 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:29:57 -0700 Subject: [PATCH] fatal dep error --- src/dns.ts | 3 +++ src/utils.tsx | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dns.ts b/src/dns.ts index 12d337f..1c1ee13 100644 --- a/src/dns.ts +++ b/src/dns.ts @@ -5,6 +5,7 @@ import { watch } from "fs" import { apps } from "./webapp" import { expectDir } from "./utils" import { NOSE_WWW } from "./config" +import { expectShellCmd } from "./utils" export const dnsEntries: Record = {} @@ -17,6 +18,8 @@ let dnsInit = false export async function initDNS() { if (process.env.NODE_ENV !== "production") return + if (!await expectShellCmd("avahi-publish")) return + dnsInit = true startWatcher() diff --git a/src/utils.tsx b/src/utils.tsx index 8f43b86..d0c5814 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -1,6 +1,7 @@ //// // Shell utilities and helper functions. +import { $ } from "bun" import { statSync } from "fs" import { setFatal } from "./fatal" import { stat } from "fs/promises" @@ -16,7 +17,7 @@ export function untilde(path: string): string { 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 { if (!isDir(path)) { setFatal(`Missing critical directory: ${path}`) @@ -26,6 +27,18 @@ export function expectDir(path: string): boolean { return true } +// Cause a fatal error if a system binary doesn't exist. +export async function expectShellCmd(cmd: string): Promise { + 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? export function isFile(path: string): boolean { try {