"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 manifest_exports = {};
__export(manifest_exports, {
  getAllManifestParsers: () => getAllManifestParsers,
  getManifestParser: () => getManifestParser,
  parseAllManifests: () => parseAllManifests,
  registerManifestParser: () => registerManifestParser
});
module.exports = __toCommonJS(manifest_exports);
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
var import_npm = require("./npm");
var import_go = require("./go");
var import_cargo = require("./cargo");
var import_python = require("./python");
var import_maven = require("./maven");
var import_gradle = require("./gradle");
var import_csproj = require("./csproj");
var import_scala = require("./scala");
var import_ocaml = require("./ocaml");
var import_elm = require("./elm");
const MANIFEST_PARSERS = [
  import_npm.npmParser,
  import_go.goParser,
  import_cargo.cargoParser,
  import_python.pythonParser,
  import_maven.mavenParser,
  import_gradle.gradleParser,
  import_csproj.csprojParser,
  import_scala.sbtParser,
  import_ocaml.ocamlParser,
  import_elm.elmParser
];
const MANIFEST_FILENAMES = new Set(
  MANIFEST_PARSERS.flatMap((p) => p.manifestFiles)
);
const SKIP_DIRS = /* @__PURE__ */ new Set([
  "node_modules",
  ".git",
  "dist",
  "build",
  "target",
  ".gradle",
  "__pycache__",
  ".kirograph",
  "vendor",
  ".cache",
  "coverage",
  ".nyc_output",
  "_build",
  "_opam",
  "elm-stuff",
  "zig-cache",
  "zig-out"
]);
function getAllManifestParsers() {
  return MANIFEST_PARSERS;
}
function getManifestParser(name) {
  return MANIFEST_PARSERS.find((p) => p.name === name);
}
function registerManifestParser(parser) {
  const idx = MANIFEST_PARSERS.findIndex((p) => p.name === parser.name);
  if (idx >= 0) MANIFEST_PARSERS[idx] = parser;
  else MANIFEST_PARSERS.push(parser);
}
async function parseAllManifests(projectRoot) {
  const manifestPaths = _findManifests(projectRoot);
  const all = [];
  const seenIds = /* @__PURE__ */ new Set();
  for (const manifestPath of manifestPaths) {
    const parser = MANIFEST_PARSERS.find((p) => p.canParse(manifestPath));
    if (!parser) continue;
    try {
      const pkgs = await parser.parse(manifestPath, projectRoot);
      for (const pkg of pkgs) {
        if (!seenIds.has(pkg.id)) {
          seenIds.add(pkg.id);
          all.push(pkg);
        }
      }
    } catch {
    }
  }
  return all;
}
function _findManifests(dir, results = []) {
  let entries;
  try {
    entries = fs.readdirSync(dir, { withFileTypes: true });
  } catch {
    return results;
  }
  for (const entry of entries) {
    if (entry.isDirectory()) {
      if (!SKIP_DIRS.has(entry.name)) {
        _findManifests(path.join(dir, entry.name), results);
      }
    } else if (entry.isFile()) {
      if (MANIFEST_FILENAMES.has(entry.name) || entry.name.endsWith(".csproj")) {
        results.push(path.join(dir, entry.name));
      }
    }
  }
  return results;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getAllManifestParsers,
  getManifestParser,
  parseAllManifests,
  registerManifestParser
});
//# sourceMappingURL=index.js.map
