Skip to content

which

import { tryWhich, which, resolveTools } from 'sysopkit/op/which';

Resolves one tool name to an absolute path. Throws when the tool is not installed — paths drift across releases, so resolve at runtime instead of hardcoding.

const shPath = await which('sh');

Resolves one tool name to an absolute path. Returns undefined when the tool is not installed (still throws on malformed tool names).

if ((await tryWhich('cloud-init')) !== undefined) {
// tool is present
}

Resolves several tool names to absolute paths, in order. Throws on the first missing tool.

const [parted, wipefs] = await resolveTools(['parted', 'wipefs']);