"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var type_exports = {};
__export(type_exports, {
  getTypeCoverage: () => getTypeCoverage
});
module.exports = __toCommonJS(type_exports);
var import_node_process = __toESM(require("node:process"));
var import_spawn = require("../spawn/spawn");
var import_error = require("../primordials/error");
var import_number = require("../primordials/number");
async function getTypeCoverage(options) {
  const opts = {
    __proto__: null,
    cwd: import_node_process.default.cwd(),
    generateIfMissing: false,
    ...options
  };
  const { cwd, generateIfMissing } = opts;
  if (!cwd) {
    throw new import_error.ErrorCtor("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 void 0;
    }
    return {
      covered: (0, import_number.NumberParseInt)(match[1], 10),
      percent: match[3],
      total: (0, import_number.NumberParseInt)(match[2], 10)
    };
  } catch (e) {
    if (generateIfMissing) {
      throw new import_error.ErrorCtor(
        "Unable to generate type coverage. Ensure type-coverage is installed.",
        { cause: e }
      );
    }
    return void 0;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getTypeCoverage
});
