import { pathToFileURL } from "node:url"; import { openUrl as openPlatformUrl } from "./src/pi-ext-browser-open.ts"; export type BrowserOpenResult = | { ok: true; url: string; command: string } | { ok: false; url: string; error: string }; export async function openHtmlFile( file: string, options: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv } = {}, ): Promise { return openUrl(pathToFileURL(file).href, options); } export async function openUrl( url: string, options: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv } = {}, ): Promise { const env = options.env ?? process.env; if (env.NODE_ENV === "test" || env.VITEST) return { ok: false, url, error: "Browser opener disabled" }; const command = await openPlatformUrl(url, { ...options, env, timeoutMs: 1500, }); if (command) return { ok: true, url, command }; return { ok: false, url, error: "No browser opener found" }; }