// src/actions/barrel/getReExportSpecs.ts
import fs from "node:fs";
import PATH from "node:path";
import ts from "typescript";

// src/actions/deplint/getBasePackageName.ts
function getBasePackageName(importName) {
  const importNameScrubbed = importName.replaceAll('"', "").trim();
  if (importNameScrubbed.startsWith("@")) {
    const parts = importNameScrubbed.split("/");
    return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importNameScrubbed;
  }
  return importNameScrubbed.split("/", 1)[0];
}

// src/actions/barrel/getReExportSpecs.ts
function getReExportSpecs(file) {
  let sourceText;
  try {
    sourceText = fs.readFileSync(file, "utf8");
  } catch {
    return [];
  }
  const isJsLike = /\.(?:js|mjs|cjs)$/i.test(file);
  const sourceFile = ts.createSourceFile(
    PATH.basename(file),
    sourceText,
    ts.ScriptTarget.Latest,
    true,
    isJsLike ? ts.ScriptKind.JS : void 0
  );
  const specs = /* @__PURE__ */ new Set();
  function visit(node) {
    if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
      const spec = node.moduleSpecifier.text;
      if (!spec.startsWith(".") && !spec.startsWith("node:")) {
        specs.add(getBasePackageName(spec));
      }
    }
    ts.forEachChild(node, visit);
  }
  visit(sourceFile);
  return [...specs];
}
export {
  getReExportSpecs
};
//# sourceMappingURL=getReExportSpecs.mjs.map
