// src/actions/deplint/packageJsonEditor.ts
import fs2 from "fs";
import chalk from "chalk";
import sortPackageJson from "sort-package-json";

// src/actions/deplint/getRequiredPeerDependencies.ts
import fs from "fs";
import path from "path";
function findDepPackageJson(location, dep) {
  let dir = location;
  while (true) {
    const candidate = path.join(dir, "node_modules", dep, "package.json");
    if (fs.existsSync(candidate)) return candidate;
    const parent = path.dirname(dir);
    if (parent === dir) return void 0;
    dir = parent;
  }
}

// src/actions/deplint/packageJsonEditor.ts
function resolveDepVersion(location, dep) {
  const depPkgPath = findDepPackageJson(location, dep);
  if (depPkgPath) {
    try {
      const depPkg = JSON.parse(fs2.readFileSync(depPkgPath, "utf8"));
      const version = depPkg.version;
      if (version) return `~${version}`;
    } catch {
    }
  }
  return "*";
}

// src/actions/deplint/rulesDiagnostic.ts
function diagnostic(context, id, message, dependency, evidence, fixes) {
  return {
    dependency,
    evidence,
    file: context.packageJsonPath,
    fixes,
    id,
    message,
    severity: "error",
    workspace: context.workspace
  };
}
function resolvedAddFix(context, dependency, section, detail) {
  return {
    action: "add",
    dependency,
    detail,
    section,
    version: resolveDepVersion(context.workspace.location, dependency)
  };
}
export {
  diagnostic,
  resolvedAddFix
};
//# sourceMappingURL=rulesDiagnostic.mjs.map