"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 scala_exports = {};
__export(scala_exports, {
  sbtParser: () => sbtParser
});
module.exports = __toCommonJS(scala_exports);
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
const sbtParser = {
  name: "sbt",
  manifestFiles: ["build.sbt"],
  language: "scala",
  canParse(manifestPath) {
    return path.basename(manifestPath) === "build.sbt";
  },
  async parse(manifestPath, projectRoot) {
    let content;
    try {
      content = fs.readFileSync(manifestPath, "utf8");
    } catch {
      return [];
    }
    const relDir = path.relative(projectRoot, path.dirname(manifestPath)).replace(/\\/g, "/") || ".";
    const relManifest = path.relative(projectRoot, manifestPath).replace(/\\/g, "/");
    const packages = [];
    const nameMatch = content.match(/name\s*:=\s*"([^"]+)"/);
    const versionMatch = content.match(/version\s*:=\s*"([^"]+)"/);
    const name = nameMatch ? nameMatch[1] : path.basename(path.dirname(manifestPath));
    const version = versionMatch ? versionMatch[1] : void 0;
    const externalDeps = [];
    const depPattern = /"([^"]+)"\s*%%?\s*"([^"]+)"\s*%\s*"([^"]+)"/g;
    let depMatch;
    while ((depMatch = depPattern.exec(content)) !== null) {
      externalDeps.push(`${depMatch[1]}:${depMatch[2]}`);
    }
    const subProjectPattern = /lazy\s+val\s+(\w+)\s*=\s*(?:\(?\s*project\s*(?:\.in\s*\(\s*file\s*\(\s*"([^"]+)"\s*\))?|project\s+in\s+file\s*\(\s*"([^"]+)"\s*\))/g;
    let subMatch;
    const subProjects = [];
    while ((subMatch = subProjectPattern.exec(content)) !== null) {
      const subName = subMatch[1];
      const subDir = subMatch[2] || subMatch[3] || subName;
      subProjects.push({ name: subName, dir: subDir });
    }
    if (subProjects.length > 0) {
      for (const sub of subProjects) {
        const subPath = relDir === "." ? sub.dir : `${relDir}/${sub.dir}`;
        packages.push({
          id: `pkg:sbt:${subPath}`,
          name: sub.name,
          path: subPath,
          source: "manifest",
          language: "scala",
          manifestPath: relManifest,
          version,
          updatedAt: Date.now()
        });
      }
      packages.push({
        id: `pkg:sbt:${relDir}`,
        name,
        path: relDir,
        source: "manifest",
        language: "scala",
        manifestPath: relManifest,
        version,
        externalDeps,
        metadata: { subProjects: subProjects.map((s) => s.name) },
        updatedAt: Date.now()
      });
    } else {
      packages.push({
        id: `pkg:sbt:${relDir}`,
        name,
        path: relDir,
        source: "manifest",
        language: "scala",
        manifestPath: relManifest,
        version,
        externalDeps,
        updatedAt: Date.now()
      });
    }
    return packages;
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  sbtParser
});
//# sourceMappingURL=scala.js.map
