"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
async function runTscCommand(args, ctx, vfs) {
  const cwd = ctx.cwd || "/";
  if (!ctx.exec) {
    return {
      stdout: "",
      stderr: "tsc: execution context unavailable\n",
      exitCode: 1
    };
  }
  const findTscBin = () => {
    const candidates = [
      `${cwd}/node_modules/typescript/bin/tsc`.replace(/\/+/g, "/"),
      "/node_modules/typescript/bin/tsc"
    ];
    return candidates.find((p) => vfs.existsSync(p)) ?? null;
  };
  let tscBinPath = findTscBin();
  if (!tscBinPath) {
    await ctx.exec("npm install typescript", { cwd, env: {} });
    tscBinPath = findTscBin();
  }
  if (!tscBinPath) {
    return {
      stdout: "",
      stderr: "Error: TypeScript could not be installed. Run `npm install typescript` manually.\n",
      exitCode: 1
    };
  }
  const quotedArgs = args.map((a) => JSON.stringify(a)).join(" ");
  const command = `node ${tscBinPath}${quotedArgs ? " " + quotedArgs : ""}`;
  return ctx.exec(command, { cwd, env: {} });
}
exports.runTscCommand = runTscCommand;
//# sourceMappingURL=tsc-command-DnvFxQcv.cjs.map
