"use strict";
/* Socket Lib - Built with esbuild */
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var type_exports = {};
__export(type_exports, {
  getTypeCoverage: () => getTypeCoverage
});
module.exports = __toCommonJS(type_exports);
var import_spawn = require("../spawn");
async function getTypeCoverage(options) {
  const opts = {
    __proto__: null,
    cwd: process.cwd(),
    generateIfMissing: false,
    ...options
  };
  const { cwd, generateIfMissing } = opts;
  if (!cwd) {
    throw new Error("Working directory is required.");
  }
  try {
    const result = await (0, import_spawn.spawn)("type-coverage", ["--detail"], {
      cwd,
      stdio: ["ignore", "pipe", "pipe"]
    });
    const outputText = result.stdout ? result.stdout.toString() : "";
    const match = /(\d+) \/ (\d+) ([\d.]+)%/.exec(outputText);
    if (!match || !match[1] || !match[2] || !match[3]) {
      return null;
    }
    return {
      covered: Number.parseInt(match[1], 10),
      percent: match[3],
      total: Number.parseInt(match[2], 10)
    };
  } catch (e) {
    if (generateIfMissing) {
      throw new Error(
        "Unable to generate type coverage. Ensure type-coverage is installed.",
        { cause: e }
      );
    }
    return null;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getTypeCoverage
});
