import { D as registerTerminationHook, g as gracefulError, k as setupProcessTermination } from "./util-CsmUMRtR.js";
import fs from "node:fs";
import { fileURLToPath, pathToFileURL } from "node:url";
//#region src/entry-util.ts
function isDirectExecution(importMetaUrl) {
	const entryPath = process.argv[1];
	if (!entryPath) return false;
	try {
		return fs.realpathSync(fileURLToPath(importMetaUrl)) === fs.realpathSync(entryPath);
	} catch {
		return importMetaUrl === pathToFileURL(entryPath).href;
	}
}
var CliInterruptError = class extends Error {
	constructor(exitCode) {
		super(exitCode === 130 ? "Interrupted by SIGINT" : `Terminated by signal: ${exitCode}`);
		this.name = "CliInterruptError";
		this.exitCode = exitCode;
	}
};
var PromptCancelError = class extends Error {
	constructor() {
		super("Prompt canceled");
		this.name = "PromptCancelError";
	}
};
async function runCliCommand(command) {
	setupProcessTermination();
	const controller = new AbortController();
	const unregisterTerminationHook = registerTerminationHook((exitCode) => {
		if (!controller.signal.aborted) controller.abort(new CliInterruptError(exitCode));
	});
	try {
		await command(controller.signal);
	} catch (err) {
		if (err === controller.signal.reason) return;
		if (err instanceof PromptCancelError) return;
		if (err instanceof Error) {
			await gracefulError(err);
			return;
		}
		throw err;
	} finally {
		unregisterTerminationHook();
	}
}
//#endregion
export { isDirectExecution as n, runCliCommand as r, PromptCancelError as t };

//# sourceMappingURL=entry-util-Bh1ksaYK.js.map