"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_primordials_error = require('../primordials/error.js');
const require_primordials_number = require('../primordials/number.js');
const require_process_spawn_child = require('../process/spawn/child.js');
let node_process = require("node:process");
node_process = require_runtime.__toESM(node_process);

//#region src/cover/type.ts
/**
* @file TypeScript type coverage utilities.
*/
/**
* Get TypeScript type coverage metrics.
*
* @throws {Error} When type-coverage command fails (if generateIfMissing is
*   false).
*/
async function getTypeCoverage(options) {
	const { cwd, generateIfMissing } = {
		__proto__: null,
		cwd: node_process.default.cwd(),
		generateIfMissing: false,
		...options
	};
	if (!cwd) throw new require_primordials_error.ErrorCtor("Working directory is required.");
	try {
		const result = await require_process_spawn_child.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;
		return {
			covered: require_primordials_number.NumberParseInt(match[1], 10),
			percent: match[3],
			total: require_primordials_number.NumberParseInt(match[2], 10)
		};
	} catch (e) {
		if (generateIfMissing) throw new require_primordials_error.ErrorCtor("Unable to generate type coverage. Ensure type-coverage is installed.", { cause: e });
		return;
	}
}

//#endregion
exports.getTypeCoverage = getTypeCoverage;