// 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("/")[0];
}

// src/actions/deplint/checkPackage/getMismatchedPeerDevVersions.ts
import chalk2 from "chalk";
import semver2 from "semver";

// src/actions/deplint/packageJsonEditor.ts
import fs2 from "fs";
import chalk from "chalk";
import semver from "semver";
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;
  }
}
function getRequiredPeerDependencies(location, allDeps) {
  const required = /* @__PURE__ */ new Set();
  for (const dep of allDeps) {
    const depPkgPath = findDepPackageJson(location, dep);
    if (!depPkgPath) continue;
    try {
      const raw = fs.readFileSync(depPkgPath, "utf8");
      const pkg = JSON.parse(raw);
      const peerDeps = pkg.peerDependencies;
      const meta = pkg.peerDependenciesMeta;
      if (peerDeps) {
        for (const peer of Object.keys(peerDeps)) {
          if (meta?.[peer]?.optional) continue;
          required.add(peer);
        }
      }
    } catch {
    }
  }
  return required;
}

// src/actions/deplint/packageJsonEditor.ts
function formatPeerRange(version, boundType = "major") {
  const parsed = semver.parse(version);
  if (!parsed) return `~${version}`;
  if (boundType === "minor") return `>=${parsed.version} <${parsed.major}.${parsed.minor + 1}`;
  return `>=${parsed.version} <${parsed.major + 1}`;
}
function inferPeerBoundType(devRange) {
  return devRange?.startsWith("~") ? "minor" : "major";
}
function readInstalledVersion(location, dep) {
  const depPkgPath = findDepPackageJson(location, dep);
  if (!depPkgPath) return void 0;
  try {
    const depPkg = JSON.parse(fs2.readFileSync(depPkgPath, "utf8"));
    return depPkg.version;
  } catch {
    return void 0;
  }
}
function resolvePeerLowerBound(location, dep, devRange) {
  if (devRange && devRange !== "*" && !devRange.startsWith("workspace:") && !devRange.startsWith("catalog:") && !devRange.startsWith("npm:")) {
    try {
      const min = semver.minVersion(devRange);
      if (min) return min.version;
    } catch {
    }
  }
  return readInstalledVersion(location, dep);
}
function resolveDepVersion(location, dep) {
  const version = readInstalledVersion(location, dep);
  return version ? `~${version}` : "*";
}
function resolvePeerDepVersion(location, dep, devRange) {
  const lower = resolvePeerLowerBound(location, dep, devRange);
  return lower ? formatPeerRange(lower, inferPeerBoundType(devRange)) : "*";
}
function resolveExpectedPeerVersion(location, dep, devRange) {
  const lower = resolvePeerLowerBound(location, dep, devRange);
  return lower ? formatPeerRange(lower, inferPeerBoundType(devRange)) : "*";
}
function resolveExpectedDevVersion(location, dep) {
  const version = readInstalledVersion(location, dep);
  if (!version) return "*";
  const match = /^(\d+)\.(\d+)/.exec(version);
  return match ? `~${match[1]}.${match[2]}` : `~${version}`;
}

// src/actions/deplint/checkPackage/getMismatchedPeerDevVersions.ts
function findMismatchedPeerDevVersions({
  peerDependencies,
  peerDependencyVersions,
  devDependencyVersions
}, exclude) {
  const mismatches = [];
  for (const dep of peerDependencies) {
    if (exclude?.has(dep)) continue;
    const peerVersion = peerDependencyVersions[dep];
    const devVersion = devDependencyVersions[dep];
    const hasWorkspaceProtocol = devVersion?.startsWith("workspace:") || peerVersion?.startsWith("workspace:");
    if (devVersion && peerVersion !== devVersion && !hasWorkspaceProtocol && !semver2.subset(devVersion, peerVersion)) {
      mismatches.push({
        dep,
        devVersion,
        peerVersion
      });
    }
  }
  return mismatches;
}

// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
import { builtinModules } from "module";
import chalk3 from "chalk";

// src/actions/deplint/isTerminalPackage.ts
import fs3 from "fs";
var EXPORT_META_KEYS = /* @__PURE__ */ new Set([".", "./package.json", "./README.md"]);
function exportsLookCliOnly(exports) {
  if (exports === void 0) return true;
  if (typeof exports === "string") return true;
  return Object.keys(exports).every((k) => EXPORT_META_KEYS.has(k));
}
function isTerminalPackage(location) {
  try {
    const pkg = JSON.parse(
      fs3.readFileSync(`${location}/package.json`, "utf8")
    );
    if (pkg.private === true) return true;
    if (pkg.xy?.commands?.deplint?.terminal === true) return true;
    const hasBin = pkg.bin !== void 0;
    const hasNoLegacyEntries = !pkg.main && !pkg.module;
    if (hasBin && hasNoLegacyEntries && exportsLookCliOnly(pkg.exports)) {
      return true;
    }
    return false;
  } catch {
    return false;
  }
}

// src/actions/deplint/tsScriptsAliases.ts
var VARIANT_MAP = {
  "@xylabs/ts-scripts-yarn3": "@xylabs/ts-scripts-pnpm",
  "@xylabs/ts-scripts-pnpm": "@xylabs/ts-scripts-yarn3",
  "@xylabs/ts-scripts-react-yarn3": "@xylabs/ts-scripts-react-pnpm",
  "@xylabs/ts-scripts-react-pnpm": "@xylabs/ts-scripts-react-yarn3"
};
function isSatisfiedByTsScriptsVariant(imp, allDeps) {
  const variant = VARIANT_MAP[imp];
  return variant !== void 0 && allDeps.includes(variant);
}
function isUsedViaTsScriptsVariant(dep, imports) {
  const variant = VARIANT_MAP[dep];
  return variant !== void 0 && imports.includes(variant);
}

// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
function isRuntimeImportListed(imp, name, dependencies, peerDependencies) {
  return dependencies.includes(imp) || imp === name || peerDependencies.includes(imp) || builtinModules.includes(imp);
}
function isDistTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies) {
  return dependencies.includes(imp) || imp === name || dependencies.includes(`@types/${imp}`) || devDependencies.includes(`@types/${imp}`) || peerDependencies.includes(imp) || peerDependencies.includes(`@types/${imp}`) || builtinModules.includes(imp);
}
function shouldBePeerDependency(imp, _location, _currentPeers, _distImports, workspaceNames) {
  if (workspaceNames?.has(imp)) return false;
  if (imp.startsWith("@types/")) return false;
  return true;
}
function findUnlistedDependencies(name, dependencies, devDependencies, peerDependencies, externalDistImports, externalDistTypeImports) {
  const allDeps = [...dependencies, ...devDependencies, ...peerDependencies];
  const results = [];
  for (const imp of externalDistImports) {
    if (!isRuntimeImportListed(imp, name, dependencies, peerDependencies) && !isSatisfiedByTsScriptsVariant(imp, allDeps)) {
      results.push({ imp, section: "dependencies" });
    }
  }
  for (const imp of externalDistTypeImports) {
    if (!isDistTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies) && !isSatisfiedByTsScriptsVariant(imp, allDeps)) {
      results.push({ imp, section: "dependencies" });
    }
  }
  return results;
}

// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
import { builtinModules as builtinModules2 } from "module";
import chalk4 from "chalk";
function findUnlistedDevDeps(name, dependencies, devDependencies, peerDependencies, externalAllImports, distImports, externalDistTypeImports) {
  const results = [];
  for (const imp of externalAllImports) {
    if (!distImports.includes(imp) && !externalDistTypeImports.includes(imp) && imp !== name && !dependencies.includes(imp) && !dependencies.includes(`@types/${imp}`) && !peerDependencies.includes(imp) && !peerDependencies.includes(`@types/${imp}`) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`) && !builtinModules2.includes(imp) && !isSatisfiedByTsScriptsVariant(imp, [...dependencies, ...devDependencies, ...peerDependencies])) {
      results.push(imp);
    }
  }
  return results;
}

// src/actions/deplint/checkPackage/getUnnecessaryPeerDependencies.ts
import chalk6 from "chalk";

// src/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.ts
import fs4 from "fs";
import chalk5 from "chalk";
import semver3 from "semver";
import sortPackageJson2 from "sort-package-json";
function readDepPackageJson(location, dep) {
  const depPkgPath = findDepPackageJson(location, dep);
  if (!depPkgPath) return void 0;
  try {
    return JSON.parse(fs4.readFileSync(depPkgPath, "utf8"));
  } catch {
    return void 0;
  }
}
function readPeerDeps(location, dep) {
  const pkg = readDepPackageJson(location, dep);
  if (!pkg) return [];
  const peers = pkg.peerDependencies;
  return Object.keys(peers ?? {});
}
function readPeerVersionRange(location, dep, peer) {
  const pkg = readDepPackageJson(location, dep);
  if (!pkg) return void 0;
  const peers = pkg.peerDependencies;
  return peers?.[peer];
}
function readInstalledVersion2(location, dep) {
  const pkg = readDepPackageJson(location, dep);
  if (!pkg) return void 0;
  return pkg.version;
}
function isPeerOptionalInAll(location, peer, sources) {
  for (const source of sources) {
    const pkg = readDepPackageJson(location, source.requiredBy);
    if (!pkg) continue;
    const meta = pkg.peerDependenciesMeta?.[peer];
    if (!meta?.optional) return false;
  }
  return true;
}
var MAX_TRANSITIVE_DEPTH = 2;
function collectPeerSources(location, dependencies, devDependencies, peerDependencies = []) {
  const peerSources = /* @__PURE__ */ new Map();
  const visited = /* @__PURE__ */ new Set();
  function addPeerSource(peer, source) {
    const sources = peerSources.get(peer) ?? [];
    sources.push(source);
    peerSources.set(peer, sources);
  }
  function collectFromDeps(deps, isRuntime, chain) {
    for (const dep of deps) {
      const visitKey = `${dep}:${chain.join(">")}`;
      if (visited.has(visitKey)) continue;
      visited.add(visitKey);
      for (const peer of readPeerDeps(location, dep)) {
        addPeerSource(peer, {
          chain: chain.length > 0 ? [...chain, dep] : void 0,
          isRuntimeDep: isRuntime,
          requiredBy: dep
        });
      }
      if (chain.length < MAX_TRANSITIVE_DEPTH) {
        const depPkg = readDepPackageJson(location, dep);
        if (depPkg) {
          const transitiveDeps = Object.keys(depPkg.dependencies ?? {});
          collectFromDeps(transitiveDeps, isRuntime, [...chain, dep]);
        }
      }
    }
  }
  const runtimeRoots = [.../* @__PURE__ */ new Set([...dependencies, ...peerDependencies])];
  collectFromDeps(runtimeRoots, true, []);
  const devOnly = devDependencies.filter((d) => !runtimeRoots.includes(d));
  collectFromDeps(devOnly, false, []);
  return peerSources;
}
function getRequiredTransitivePeers(location, { dependencies, devDependencies, peerDependencies }) {
  const peerSources = collectPeerSources(location, dependencies, devDependencies, peerDependencies);
  return new Set(peerSources.keys());
}
function resolveVersionRange(location, sources, peer) {
  for (const source of sources) {
    const range = readPeerVersionRange(location, source.requiredBy, peer);
    if (range) return range;
  }
  return "*";
}
function checkVersionSatisfaction(location, peer, requestedRange) {
  const installedVersion = readInstalledVersion2(location, peer);
  if (!installedVersion) return { satisfied: true };
  if (requestedRange === "*") return { installedVersion, satisfied: true };
  if (requestedRange.startsWith("workspace:")) return { installedVersion, satisfied: true };
  try {
    const satisfied = semver3.satisfies(installedVersion, requestedRange, { includePrerelease: true });
    return { installedVersion, satisfied };
  } catch {
    return { installedVersion, satisfied: true };
  }
}
function findDeclaredPeerVersionMismatches(name, location, peerDependencies, peerDependencyVersions, exclude) {
  const results = [];
  for (const peer of peerDependencies) {
    if (exclude?.has(peer) || peer === name) continue;
    const declaredRange = peerDependencyVersions[peer];
    if (!declaredRange || declaredRange === "*") continue;
    const { installedVersion, satisfied } = checkVersionSatisfaction(location, peer, declaredRange);
    if (!satisfied) {
      results.push({
        hasRuntimeSource: true,
        installedVersion,
        peer,
        reason: "version-mismatch",
        sources: [{ isRuntimeDep: true, requiredBy: name }],
        versionRange: declaredRange
      });
    }
  }
  return results;
}
function findUnsatisfiedPeers({ name, location }, {
  dependencies,
  devDependencies,
  peerDependencies,
  peerDependencyVersions
}, exclude, isTerminal, forcePeerOptional) {
  const peerSources = collectPeerSources(location, dependencies, devDependencies, peerDependencies);
  const depsSet = new Set(dependencies);
  const devDepsSet = new Set(devDependencies);
  const peerDepsSet = new Set(peerDependencies);
  const isTerminalResolved = isTerminal ?? isTerminalPackage(location);
  const unsatisfied = [];
  for (const [peer, sources] of peerSources) {
    if (exclude?.has(peer) || peer === name) continue;
    if (!forcePeerOptional?.has(peer) && isPeerOptionalInAll(location, peer, sources)) continue;
    const hasRuntimeSource = sources.some((s) => s.isRuntimeDep);
    const isPresent = depsSet.has(peer) || devDepsSet.has(peer);
    if (!isPresent) {
      const versionRange2 = resolveVersionRange(location, sources, peer);
      unsatisfied.push({
        hasRuntimeSource,
        peer,
        reason: "missing",
        sources,
        versionRange: versionRange2
      });
      continue;
    }
    const hasDirectRuntimeSource = sources.some((s) => s.isRuntimeDep && !s.chain);
    if (hasDirectRuntimeSource && !isTerminalResolved && !depsSet.has(peer) && !peerDepsSet.has(peer)) {
      const versionRange2 = resolveVersionRange(location, sources, peer);
      unsatisfied.push({
        hasRuntimeSource,
        peer,
        reason: "under-exposed",
        sources,
        versionRange: versionRange2
      });
      continue;
    }
    const versionRange = resolveVersionRange(location, sources, peer);
    const { installedVersion, satisfied } = checkVersionSatisfaction(location, peer, versionRange);
    if (!satisfied) {
      const mismatchedSources = findMismatchedSources(location, sources, peer, installedVersion);
      unsatisfied.push({
        hasRuntimeSource,
        installedVersion,
        mismatchedSources,
        peer,
        reason: "version-mismatch",
        sources,
        versionRange
      });
    }
  }
  return [
    ...unsatisfied,
    ...findDeclaredPeerVersionMismatches(name, location, peerDependencies, peerDependencyVersions, exclude)
  ];
}
function findMismatchedSources(location, sources, peer, installedVersion) {
  if (!installedVersion) return [];
  return sources.filter((source) => {
    const range = readPeerVersionRange(location, source.requiredBy, peer);
    if (!range || range === "*" || range.startsWith("workspace:")) return false;
    try {
      return !semver3.satisfies(installedVersion, range, { includePrerelease: true });
    } catch {
      return false;
    }
  });
}
function resolvePeerTargetSections(hasRuntimeSource, isTerminal) {
  if (!hasRuntimeSource) return ["devDependencies"];
  if (isTerminal) return ["dependencies"];
  return ["peerDependencies", "devDependencies"];
}

// src/actions/deplint/checkPackage/getUnnecessaryPeerDependencies.ts
function isPeerImportedInDist(dep, externalDistImports, externalDistTypeImports) {
  const baseName = dep.replace(/^@types\//, "");
  return externalDistImports.includes(dep) || externalDistImports.includes(baseName) || externalDistTypeImports.includes(dep) || externalDistTypeImports.includes(baseName);
}
function findUnrequestedPeerDeps(location, packageParams, { externalDistImports, externalDistTypeImports }, isTerminal, exclude) {
  const requiredPeers = isTerminal ? null : getRequiredTransitivePeers(location, packageParams);
  const unrequested = [];
  for (const dep of packageParams.peerDependencies) {
    if (exclude?.has(dep)) continue;
    if (packageParams.dependencies.includes(dep)) continue;
    if (!isPeerImportedInDist(dep, externalDistImports, externalDistTypeImports)) continue;
    if (!requiredPeers?.has(dep)) {
      unrequested.push(dep);
    }
  }
  return unrequested;
}
function findRedundantPeerDeps({ peerDependencies, dependencies }, exclude) {
  const depsSet = new Set(dependencies);
  const redundant = [];
  for (const dep of peerDependencies) {
    if (exclude?.has(dep)) continue;
    if (depsSet.has(dep)) {
      redundant.push(dep);
    }
  }
  return redundant;
}

// src/actions/deplint/checkPackage/getUnusedDependencies.ts
import chalk7 from "chalk";
function isDepImported(dep, distImports, distTypeImports) {
  const baseName = dep.replace(/^@types\//, "");
  return distImports.includes(dep) || distImports.includes(baseName) || distTypeImports.includes(dep) || distTypeImports.includes(baseName);
}
function findUnusedDependencies(location, dependencies, devDependencies, externalDistImports, externalDistTypeImports, externalAllImports, exclude) {
  const runtimeRequiredPeers = getRequiredPeerDependencies(location, dependencies);
  const devRequiredPeers = getRequiredPeerDependencies(location, devDependencies);
  const results = [];
  for (const dep of dependencies) {
    if (exclude?.has(dep)) continue;
    if (runtimeRequiredPeers.has(dep)) continue;
    const isImported = isDepImported(dep, externalDistImports, externalDistTypeImports);
    if (isImported || isUsedViaTsScriptsVariant(dep, [...externalDistImports, ...externalDistTypeImports])) continue;
    if (devRequiredPeers.has(dep)) {
      results.push({
        dep,
        kind: "move-to-dev",
        reason: "only needed as peer of devDependencies"
      });
    } else if (externalAllImports.includes(dep)) {
      results.push({ dep, kind: "move-to-dev" });
    } else {
      results.push({ dep, kind: "remove" });
    }
  }
  return results;
}

// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
import chalk8 from "chalk";

// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
import fs6 from "fs";
import path3 from "path";
import ts from "typescript";

// src/actions/deplint/getScriptReferencedPackages.ts
import fs5 from "fs";
import path2 from "path";
function getBinNames(location, dep) {
  const depPkgPath = findDepPackageJson(location, dep);
  if (!depPkgPath) return [];
  try {
    const raw = fs5.readFileSync(depPkgPath, "utf8");
    const pkg = JSON.parse(raw);
    if (!pkg.bin) return [];
    if (typeof pkg.bin === "string") return [pkg.name?.split("/").pop() ?? dep];
    return Object.keys(pkg.bin);
  } catch {
    return [];
  }
}
function tokenizeScript(script) {
  return script.split(/[&|;$()"`\s]+/).map((t) => t.trim()).filter(Boolean);
}
function getScriptReferencedPackages(location, allDeps) {
  const pkgPath = path2.join(location, "package.json");
  let scripts;
  try {
    const raw = fs5.readFileSync(pkgPath, "utf8");
    const pkg = JSON.parse(raw);
    scripts = pkg.scripts ?? {};
  } catch {
    return /* @__PURE__ */ new Set();
  }
  const scriptText = Object.values(scripts).join(" ");
  const tokens = new Set(tokenizeScript(scriptText));
  const binToPackage = /* @__PURE__ */ new Map();
  for (const dep of allDeps) {
    const bins = getBinNames(location, dep);
    for (const bin of bins) {
      binToPackage.set(bin, dep);
    }
  }
  const referenced = /* @__PURE__ */ new Set();
  for (const token of tokens) {
    const baseName = getBasePackageName(token);
    if (allDeps.includes(baseName)) {
      referenced.add(baseName);
    }
    const pkg = binToPackage.get(token);
    if (pkg) {
      referenced.add(pkg);
    }
  }
  return referenced;
}

// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
var shellCommandFunctions = /* @__PURE__ */ new Set(["execSync", "exec"]);
var directExecFunctions = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
var allExecFunctions = /* @__PURE__ */ new Set([...shellCommandFunctions, ...directExecFunctions]);
function getCommandTokensFromFile(filePath) {
  const tokens = /* @__PURE__ */ new Set();
  let sourceCode;
  try {
    sourceCode = fs6.readFileSync(filePath, "utf8");
  } catch {
    return tokens;
  }
  const isMjsFile = filePath.endsWith(".mjs");
  const sourceFile = ts.createSourceFile(
    path3.basename(filePath),
    sourceCode,
    ts.ScriptTarget.Latest,
    true,
    isMjsFile ? ts.ScriptKind.JS : void 0
  );
  function visit(node) {
    if (ts.isCallExpression(node) && node.arguments.length > 0) {
      const fnName = getFunctionName(node.expression);
      if (fnName && allExecFunctions.has(fnName)) {
        const firstArg = node.arguments[0];
        if (ts.isStringLiteral(firstArg) || ts.isNoSubstitutionTemplateLiteral(firstArg)) {
          const value = firstArg.text;
          if (shellCommandFunctions.has(fnName)) {
            for (const token of tokenizeScript(value)) {
              tokens.add(token);
            }
          } else {
            tokens.add(value);
          }
        } else if (ts.isTemplateExpression(firstArg)) {
          const head = firstArg.head.text;
          if (head) {
            for (const token of tokenizeScript(head)) {
              tokens.add(token);
            }
          }
        }
      }
    }
    ts.forEachChild(node, visit);
  }
  visit(sourceFile);
  return tokens;
}
function getFunctionName(expr) {
  if (ts.isIdentifier(expr)) {
    return expr.text;
  }
  if (ts.isPropertyAccessExpression(expr) && ts.isIdentifier(expr.name)) {
    return expr.name.text;
  }
  return void 0;
}
function getCliReferencedPackagesFromFiles(allFiles, location, allDeps) {
  const allTokens = /* @__PURE__ */ new Set();
  for (const file of allFiles) {
    for (const token of getCommandTokensFromFile(file)) {
      allTokens.add(token);
    }
  }
  if (allTokens.size === 0) return /* @__PURE__ */ new Set();
  const binToPackage = /* @__PURE__ */ new Map();
  for (const dep of allDeps) {
    for (const bin of getBinNames(location, dep)) {
      binToPackage.set(bin, dep);
    }
  }
  const referenced = /* @__PURE__ */ new Set();
  for (const token of allTokens) {
    const baseName = getBasePackageName(token);
    if (allDeps.includes(baseName)) {
      referenced.add(baseName);
    }
    const pkg = binToPackage.get(token);
    if (pkg) {
      referenced.add(pkg);
    }
  }
  return referenced;
}

// src/actions/deplint/implicitDevDependencies.ts
import fs7 from "fs";
var hasFileWithExtension = (files, extensions) => files.some((f) => extensions.some((ext) => f.endsWith(ext)));
var tsExtensions = [".ts", ".tsx", ".mts", ".cts"];
var hasTypescriptFiles = ({ allFiles }) => hasFileWithExtension(allFiles, tsExtensions);
var decoratorPattern = /^\s*@[a-zA-Z]\w*/m;
var hasDecorators = ({ allFiles }) => allFiles.filter((f) => tsExtensions.some((ext) => f.endsWith(ext))).some((file) => {
  try {
    const content = fs7.readFileSync(file, "utf8");
    return decoratorPattern.test(content);
  } catch {
    return false;
  }
});
var hasDependencyRequiringTslib = ({ location, allDependencies }) => allDependencies.some((dep) => {
  const pkgPath = findDepPackageJson(location, dep);
  if (!pkgPath) return false;
  try {
    const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf8"));
    const peers = pkg.peerDependencies;
    return peers !== void 0 && "tslib" in peers;
  } catch {
    return false;
  }
});
var importPlugins = /* @__PURE__ */ new Set(["eslint-plugin-import-x", "eslint-plugin-import"]);
function hasImportPlugin({ location, allDependencies }) {
  if (allDependencies.some((d) => importPlugins.has(d))) return true;
  for (const dep of allDependencies) {
    const pkgPath = findDepPackageJson(location, dep);
    if (!pkgPath) continue;
    try {
      const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf8"));
      const transitiveDeps = [
        ...Object.keys(pkg.dependencies ?? {}),
        ...Object.keys(pkg.peerDependencies ?? {})
      ];
      if (transitiveDeps.some((d) => importPlugins.has(d))) return true;
    } catch {
    }
  }
  return false;
}
var hasVitest = ({ allDependencies }) => allDependencies.includes("vitest");
var rules = [
  {
    package: "typescript",
    isNeeded: hasTypescriptFiles
  },
  {
    package: "eslint-import-resolver-typescript",
    isNeeded: (context) => hasTypescriptFiles(context) && context.allDependencies.includes("eslint") && hasImportPlugin(context)
  },
  {
    package: "tslib",
    isNeeded: (context) => hasDecorators(context) || hasDependencyRequiringTslib(context)
  },
  {
    package: "@vitest/coverage-v8",
    isNeeded: hasVitest
  },
  {
    package: "@xylabs/toolchain",
    isNeeded: hasTypescriptFiles
  }
];
function getImplicitDevDependencies(context) {
  const implicit = /* @__PURE__ */ new Set();
  for (const rule of rules) {
    if (rule.isNeeded(context)) {
      implicit.add(rule.package);
    }
  }
  return implicit;
}

// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
var allExternalImports = ({
  externalAllImports,
  externalDistImports,
  externalDistTypeImports
}) => {
  return /* @__PURE__ */ new Set([
    ...externalAllImports,
    ...externalDistImports,
    ...externalDistTypeImports
  ]);
};
function isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs) {
  if (implicitDeps.has(dep)) return true;
  if (requiredPeers.has(dep)) return true;
  if (scriptRefs.has(dep)) return true;
  if (cliRefs.has(dep)) return true;
  if (dep.startsWith("@types/")) {
    const baseName = dep.replace(/^@types\//, "");
    return allImports.has(baseName) || allImports.has(dep) || implicitDeps.has(baseName);
  }
  if (allImports.has(dep)) return true;
  return isUsedViaTsScriptsVariant(dep, [...allImports]);
}
function findUnusedDevDeps(location, dependencies, devDependencies, peerDependencies, sourceParams, fileContext, exclude) {
  const allImports = allExternalImports(sourceParams);
  const allDeps = [...dependencies, ...devDependencies, ...peerDependencies];
  const implicitDeps = getImplicitDevDependencies({
    ...fileContext,
    allDependencies: allDeps,
    location
  });
  const requiredPeers = getRequiredPeerDependencies(location, allDeps);
  const scriptRefs = getScriptReferencedPackages(location, allDeps);
  const cliRefs = getCliReferencedPackagesFromFiles(fileContext.allFiles, location, allDeps);
  const unused = [];
  for (const dep of devDependencies) {
    if (exclude?.has(dep)) continue;
    if (dependencies.includes(dep) || peerDependencies.includes(dep)) continue;
    if (!isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs)) {
      unused.push(dep);
    }
  }
  return unused;
}

// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
import chalk9 from "chalk";
function isPeerUsed(dep, externalDistImports, externalDistTypeImports) {
  const baseName = dep.replace(/^@types\//, "");
  return externalDistImports.includes(dep) || externalDistImports.includes(baseName) || externalDistTypeImports.includes(dep) || externalDistTypeImports.includes(baseName);
}
function findUnusedPeerDeps(peerDependencies, externalDistImports, externalDistTypeImports, exclude) {
  const unused = [];
  for (const dep of peerDependencies) {
    if (exclude?.has(dep)) continue;
    if (!isPeerUsed(dep, externalDistImports, externalDistTypeImports)) {
      unused.push(dep);
    }
  }
  return unused;
}

// src/actions/deplint/checkPackage/getWorkspaceVersionProblems.ts
import chalk10 from "chalk";
import semver4 from "semver";
function checkSection(deps, versions, section, workspaceNames, problems) {
  for (const dep of deps) {
    if (!workspaceNames.has(dep)) continue;
    const version = versions[dep];
    if (version && !version.startsWith("workspace:")) {
      problems.push({
        dep,
        section,
        version
      });
    }
  }
}
function findWorkspaceVersionProblems(packageParams, workspaceNames) {
  const problems = [];
  checkSection(packageParams.dependencies, packageParams.dependencyVersions, "dependencies", workspaceNames, problems);
  checkSection(packageParams.devDependencies, packageParams.devDependencyVersions, "devDependencies", workspaceNames, problems);
  checkSection(packageParams.peerDependencies, packageParams.peerDependencyVersions, "peerDependencies", workspaceNames, problems);
  return problems;
}

// src/actions/deplint/rulesDiagnostic.ts
function resolvedAddFix(context, dependency, section, detail, optional) {
  const devRange = context.packageParams.devDependencyVersions[dependency];
  const version = section === "peerDependencies" ? resolvePeerDepVersion(context.workspace.location, dependency, devRange) : resolveDepVersion(context.workspace.location, dependency);
  return {
    action: "add",
    dependency,
    detail,
    ...section === "peerDependencies" && optional !== void 0 ? { optional } : {},
    section,
    version
  };
}

// src/actions/deplint/rulesMisplaced.ts
var misplacedDependenciesRule = {
  category: "dependencies",
  id: "deplint.dependencies.misplaced",
  meta: {
    description: "Dependencies declared in the wrong package.json section",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    for (const dep of context.packageParams.dependencies) {
      if (context.forceDevs.has(dep)) {
        context.report({
          data: { dep, mode: "to-dev" },
          dependency: dep,
          message: `dependency ${dep} should be a devDependency \u2014 configured as refType "dev"`
        });
        continue;
      }
      if (context.isTerminalPackage) continue;
      if (context.forceDeps.has(dep)) continue;
      if (context.packageParams.dependencyVersions[dep]?.startsWith("workspace:")) continue;
      if (context.forcePeers.has(dep) || shouldBePeerDependency(dep, context.workspace.location, context.packageParams.peerDependencies, context.sourceParams.externalDistImports, context.workspaceNames)) {
        const reason = context.forcePeers.has(dep) ? 'configured as refType "peer"' : "external runtime dep \u2014 consumers should control the version";
        context.report({
          data: {
            dep,
            mode: "to-peer",
            needsDevCompanion: !context.packageParams.devDependencies.includes(dep)
          },
          dependency: dep,
          message: `dependency ${dep} should be a peerDependency \u2014 ${reason}`
        });
      }
    }
  },
  resolveFixes(diagnostic, context) {
    const data = diagnostic.data;
    if (!data) return [];
    if (data.mode === "to-dev") {
      return [{
        action: "move",
        dependency: data.dep,
        detail: "moved from dependencies to devDependencies",
        fromSection: "dependencies",
        toSection: "devDependencies"
      }];
    }
    const optional = context.forcePeerOptional.get(data.dep);
    const fixes = [{
      action: "move",
      dependency: data.dep,
      detail: "moved from dependencies to peerDependencies",
      fromSection: "dependencies",
      ...optional === void 0 ? {} : { optional },
      toSection: "peerDependencies"
    }];
    if (data.needsDevCompanion) {
      fixes.push(resolvedAddFix(context, data.dep, "devDependencies", "added to devDependencies"));
    }
    return fixes;
  }
};
var misplacedPeerDependenciesRule = {
  category: "peerDependencies",
  id: "deplint.peerDependencies.misplaced",
  meta: {
    description: "Peer dependencies declared in the wrong package.json section",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    for (const dep of context.packageParams.peerDependencies) {
      const version = context.packageParams.peerDependencyVersions[dep] ?? (context.workspaceNames?.has(dep) ? "workspace:~" : "*");
      if (context.forceDeps.has(dep)) {
        context.report({
          data: {
            dep,
            mode: "to-dep",
            version
          },
          dependency: dep,
          message: `peerDependency ${dep} should be a dependency \u2014 configured as refType "dep"`
        });
        continue;
      }
      if (context.forceDevs.has(dep)) {
        context.report({
          data: {
            dep,
            mode: "to-dev",
            version
          },
          dependency: dep,
          message: `peerDependency ${dep} should be a devDependency \u2014 configured as refType "dev"`
        });
        continue;
      }
      if (context.workspaceNames?.has(dep) && !context.forcePeers.has(dep)) {
        context.report({
          data: {
            dep,
            mode: "to-dep",
            version
          },
          dependency: dep,
          message: `peerDependency ${dep} should be a dependency \u2014 sibling workspace packages ship in lockstep; set refType "peer" in xy.config.ts to override`
        });
      }
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    if (!data) return [];
    return [{
      action: "move",
      dependency: data.dep,
      detail: data.mode === "to-dep" ? "moved from peerDependencies to dependencies" : "moved from peerDependencies to devDependencies",
      fromSection: "peerDependencies",
      toSection: data.mode === "to-dep" ? "dependencies" : "devDependencies",
      version: data.version
    }];
  }
};

// src/actions/deplint/versionMismatchFixes.ts
function sectionLookupsFor(context) {
  const {
    dependencies,
    devDependencies,
    peerDependencies,
    dependencyVersions,
    devDependencyVersions,
    peerDependencyVersions
  } = context.packageParams;
  return [
    ["dependencies", dependencies, dependencyVersions],
    ["devDependencies", devDependencies, devDependencyVersions],
    ["peerDependencies", peerDependencies, peerDependencyVersions]
  ];
}
function addSourceBumpFixes(context, finding, fixes) {
  if (!finding.installedVersion || !finding.mismatchedSources) return;
  const sectionLookups = sectionLookupsFor(context);
  const seen = /* @__PURE__ */ new Set();
  for (const source of finding.mismatchedSources) {
    const dep = source.requiredBy;
    if (seen.has(dep) || dep === context.workspace.name) continue;
    seen.add(dep);
    for (const [section, names, versions] of sectionLookups) {
      if (!names.includes(dep)) continue;
      const current = versions[dep];
      if (!current || current.startsWith("workspace:")) continue;
      fixes.push({
        action: "resolve-peer-bump",
        currentRange: current,
        dependency: dep,
        detail: `bump ${section} range so a newer version of ${dep} is installed that accepts peer ${finding.peer}@${finding.installedVersion}`,
        installedPeerVersion: finding.installedVersion,
        peer: finding.peer,
        section
      });
    }
  }
}
function generateVersionMismatchFixes(context, finding) {
  const fixes = [];
  const devRange = context.packageParams.devDependencyVersions[finding.peer];
  const expectedPeerVersion = resolveExpectedPeerVersion(context.workspace.location, finding.peer, devRange);
  const expectedDevVersion = resolveExpectedDevVersion(context.workspace.location, finding.peer);
  if (expectedPeerVersion !== "*" && context.packageParams.peerDependencies.includes(finding.peer)) {
    const peerVersion = context.packageParams.peerDependencyVersions[finding.peer];
    if (!peerVersion?.startsWith("workspace:")) {
      fixes.push({
        action: "set-version",
        dependency: finding.peer,
        detail: `updated peerDependency version to match installed (${finding.installedVersion})`,
        section: "peerDependencies",
        version: expectedPeerVersion
      });
    }
  }
  if (expectedDevVersion !== "*" && context.packageParams.devDependencies.includes(finding.peer)) {
    const devVersion = context.packageParams.devDependencyVersions[finding.peer];
    if (devVersion && !devVersion.startsWith("workspace:")) {
      fixes.push({
        action: "set-version",
        dependency: finding.peer,
        detail: `updated devDependency version to match installed (${finding.installedVersion})`,
        section: "devDependencies",
        version: expectedDevVersion
      });
    }
  }
  addSourceBumpFixes(context, finding, fixes);
  return fixes;
}

// src/actions/deplint/rules.ts
function resolvePromotedPeerOptional(context, peer, sources) {
  const override = context.forcePeerOptional.get(peer);
  if (override !== void 0) return override;
  if (!sources || sources.length === 0) return void 0;
  return isPeerOptionalInAll(context.workspace.location, peer, sources);
}
var unlistedDependenciesRule = {
  category: "dependencies",
  id: "deplint.dependencies.unlisted",
  meta: {
    description: "Runtime imports missing from package.json",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findUnlistedDependencies(
      context.workspace.name,
      context.packageParams.dependencies,
      context.packageParams.devDependencies,
      context.packageParams.peerDependencies,
      context.sourceParams.externalDistImports,
      context.sourceParams.externalDistTypeImports
    );
    for (const { imp, section } of findings) {
      if (context.forceDevs.has(imp)) {
        if (context.packageParams.devDependencies.includes(imp)) continue;
        context.report({
          data: { imp, mode: "forced-dev" },
          dependency: imp,
          evidence: context.sourceParams.distImportPaths[imp],
          message: `Missing devDependency in package.json: ${imp}`
        });
        continue;
      }
      const isPeer = !context.isTerminalPackage && section === "dependencies" && !context.forceDeps.has(imp) && shouldBePeerDependency(imp, context.workspace.location, context.packageParams.peerDependencies, context.sourceParams.externalDistImports, context.workspaceNames);
      context.report({
        data: {
          imp,
          mode: isPeer ? "peer-companion" : "direct",
          section
        },
        dependency: imp,
        evidence: context.sourceParams.distImportPaths[imp],
        message: `Missing dependency in package.json: ${imp}`
      });
    }
  },
  resolveFixes(diagnostic, context) {
    const data = diagnostic.data;
    if (!data) return [];
    if (data.mode === "forced-dev") {
      return [resolvedAddFix(context, data.imp, "devDependencies", "added to devDependencies")];
    }
    if (data.mode === "peer-companion") {
      const optional = resolvePromotedPeerOptional(context, data.imp);
      return ["peerDependencies", "devDependencies"].map(
        (section) => resolvedAddFix(
          context,
          data.imp,
          section,
          `added to ${section}`,
          section === "peerDependencies" ? optional : void 0
        )
      );
    }
    return data.section ? [resolvedAddFix(context, data.imp, data.section, `added to ${data.section}`)] : [];
  }
};
var unusedDependenciesRule = {
  category: "dependencies",
  id: "deplint.dependencies.unused",
  meta: {
    description: "Dependencies declared but not used at runtime",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findUnusedDependencies(
      context.workspace.location,
      context.packageParams.dependencies,
      context.packageParams.devDependencies,
      context.sourceParams.externalDistImports,
      context.sourceParams.externalDistTypeImports,
      context.sourceParams.externalAllImports,
      context.unusedDependencyExclude
    );
    for (const finding of findings) {
      context.report({
        data: finding,
        dependency: finding.dep,
        message: finding.kind === "move-to-dev" ? `dependency should be devDependency in package.json: ${finding.dep}${finding.reason ? ` (${finding.reason})` : ""}` : `Unused dependency in package.json: ${finding.dep}`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    if (!data) return [];
    return [data.kind === "move-to-dev" ? {
      action: "move",
      dependency: data.dep,
      detail: "moved to devDependencies",
      fromSection: "dependencies",
      toSection: "devDependencies"
    } : {
      action: "remove",
      dependency: data.dep,
      detail: "removed from dependencies",
      section: "dependencies"
    }];
  }
};
var unlistedDevDependenciesRule = {
  category: "devDependencies",
  id: "deplint.devDependencies.unlisted",
  meta: {
    description: "Dev-only imports missing from package.json",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findUnlistedDevDeps(
      context.workspace.name,
      context.packageParams.dependencies,
      context.packageParams.devDependencies,
      context.packageParams.peerDependencies,
      context.sourceParams.externalAllImports,
      context.sourceParams.distImports,
      context.sourceParams.externalDistTypeImports
    );
    for (const imp of findings) {
      context.report({
        data: { imp },
        dependency: imp,
        evidence: context.sourceParams.allImportPaths[imp],
        message: `Missing devDependency in package.json: ${imp}`
      });
    }
  },
  resolveFixes(diagnostic, context) {
    const data = diagnostic.data;
    return data ? [resolvedAddFix(context, data.imp, "devDependencies", "added to devDependencies")] : [];
  }
};
var unusedDevDependenciesRule = {
  category: "devDependencies",
  id: "deplint.devDependencies.unused",
  meta: {
    description: "Dev dependencies declared but never referenced",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findUnusedDevDeps(
      context.workspace.location,
      context.packageParams.dependencies,
      context.packageParams.devDependencies,
      context.packageParams.peerDependencies,
      context.sourceParams,
      context.fileContext,
      context.unusedDependencyExclude
    );
    for (const dep of findings) {
      context.report({
        data: { dep },
        dependency: dep,
        message: `Unused devDependency in package.json: ${dep}`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    return data ? [{
      action: "remove",
      dependency: data.dep,
      detail: "removed from devDependencies",
      section: "devDependencies"
    }] : [];
  }
};
var redundantDevDependenciesRule = {
  category: "devDependencies",
  id: "deplint.devDependencies.redundant",
  meta: {
    description: "Dependencies duplicated in devDependencies",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    for (const dep of context.packageParams.devDependencies) {
      if (!context.packageParams.dependencies.includes(dep)) continue;
      if (!context.isTerminalPackage && !context.forceDeps.has(dep) && shouldBePeerDependency(dep, context.workspace.location, context.packageParams.peerDependencies, context.sourceParams.externalDistImports, context.workspaceNames)) {
        continue;
      }
      context.report({
        data: { dep },
        dependency: dep,
        message: `Redundant devDependency ${dep} \u2014 already listed in dependencies`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    return data ? [{
      action: "remove",
      dependency: data.dep,
      detail: "removed redundant devDependency (kept in dependencies)",
      section: "devDependencies"
    }] : [];
  }
};
var unsatisfiedPeersRule = {
  category: "peerDependencies",
  id: "deplint.peerDependencies.unsatisfied",
  meta: {
    description: "Missing, under-exposed, or incompatible peer dependencies",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findUnsatisfiedPeers(
      context.workspace,
      context.packageParams,
      context.exclude,
      context.isTerminalPackage,
      context.forcePeerOptional
    );
    for (const finding of findings) {
      const requiredBy = finding.sources.map((source) => source.requiredBy).join(", ");
      const chain = finding.sources.find((source) => source.chain && source.chain.length > 0)?.chain?.join(" -> ");
      const evidence = chain ? [`via ${chain}`] : void 0;
      const message = finding.reason === "version-mismatch" ? `Peer dependency version mismatch ${finding.peer} \u2014 installed ${finding.installedVersion ?? "unknown"} does not satisfy ${finding.versionRange} (required by ${requiredBy})` : finding.reason === "under-exposed" ? `Under-exposed peer dependency ${finding.peer} (required by ${requiredBy}) \u2014 in devDependencies only; must also be in dependencies or peerDependencies` : finding.hasRuntimeSource ? `Unsatisfied peer dependency ${finding.peer} (required by ${requiredBy}) \u2014 must be in dependencies or peerDependencies` : `Unsatisfied peer dependency ${finding.peer} (required by devDependency ${requiredBy}) \u2014 must be in dependencies, devDependencies, or peerDependencies`;
      context.report({
        data: { finding },
        dependency: finding.peer,
        evidence,
        message
      });
    }
  },
  resolveFixes(diagnostic, context) {
    const data = diagnostic.data;
    const finding = data?.finding;
    if (!finding) return [];
    const addVersion = context.workspaceNames?.has(finding.peer) ? "workspace:~" : finding.versionRange;
    if (finding.reason === "missing") {
      const optional = resolvePromotedPeerOptional(context, finding.peer, finding.sources);
      return resolvePeerTargetSections(finding.hasRuntimeSource, context.isTerminalPackage).map((section) => ({
        action: "add",
        dependency: finding.peer,
        detail: `added to ${section}`,
        ...section === "peerDependencies" && optional !== void 0 ? { optional } : {},
        section,
        version: addVersion
      }));
    }
    if (finding.reason === "under-exposed") {
      const optional = resolvePromotedPeerOptional(context, finding.peer, finding.sources);
      return [{
        action: "add",
        dependency: finding.peer,
        detail: "added to peerDependencies",
        ...optional === void 0 ? {} : { optional },
        section: "peerDependencies",
        version: addVersion
      }];
    }
    if (finding.reason === "version-mismatch") {
      return generateVersionMismatchFixes(context, finding);
    }
    return [];
  }
};
var unusedPeerDependenciesRule = {
  category: "peerDependencies",
  id: "deplint.peerDependencies.unused",
  meta: {
    description: "Peer dependencies declared but not used in dist",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findUnusedPeerDeps(
      context.packageParams.peerDependencies,
      context.sourceParams.externalDistImports,
      context.sourceParams.externalDistTypeImports,
      context.unusedPeerDependencyExclude
    );
    for (const dep of findings) {
      context.report({
        data: { dep, alreadyDependency: context.packageParams.dependencies.includes(dep) },
        dependency: dep,
        message: context.packageParams.dependencies.includes(dep) ? `Unused peerDependency [already a dependency] in package.json: ${dep}` : `Unused peerDependency in package.json: ${dep}`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    return data ? [{
      action: "remove",
      dependency: data.dep,
      detail: "removed from peerDependencies",
      section: "peerDependencies"
    }] : [];
  }
};
var unrequestedPeerDependenciesRule = {
  category: "peerDependencies",
  id: "deplint.peerDependencies.unrequested",
  meta: {
    description: "Terminal-package peers that should be regular dependencies",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    if (!context.isTerminalPackage) return;
    const findings = findUnrequestedPeerDeps(
      context.workspace.location,
      context.packageParams,
      context.sourceParams,
      true,
      // rule already early-returned for non-terminal packages
      context.exclude
    );
    for (const dep of findings) {
      context.report({
        data: { dep, version: context.packageParams.peerDependencyVersions[dep] ?? "*" },
        dependency: dep,
        message: `Unnecessary peerDependency ${dep} \u2014 imported in dist but no dependency requires it as a peer; should be a dependency`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    return data ? [{
      action: "move",
      dependency: data.dep,
      detail: "moved from peerDependencies to dependencies",
      fromSection: "peerDependencies",
      toSection: "dependencies",
      version: data.version
    }] : [];
  }
};
var redundantPeerDependenciesRule = {
  category: "peerDependencies",
  id: "deplint.peerDependencies.redundant",
  meta: {
    description: "Dependencies duplicated in peerDependencies",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findRedundantPeerDeps(context.packageParams, context.exclude);
    for (const dep of findings) {
      context.report({
        data: { dep },
        dependency: dep,
        message: `Redundant peerDependency ${dep} \u2014 already listed in dependencies`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    return data ? [{
      action: "remove",
      dependency: data.dep,
      detail: "removed redundant peerDependency (kept in dependencies)",
      section: "peerDependencies"
    }] : [];
  }
};
var mismatchedPeerDevVersionsRule = {
  category: "peerDependencies",
  id: "deplint.peerDependencies.version-mismatch",
  meta: {
    description: "Peer and dev ranges for the same package are out of sync",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    const findings = findMismatchedPeerDevVersions(context.packageParams, context.exclude);
    for (const finding of findings) {
      context.report({
        data: finding,
        dependency: finding.dep,
        message: `Peer/dev version mismatch ${finding.dep} \u2014 peer: ${finding.peerVersion}, dev: ${finding.devVersion}`
      });
    }
  },
  resolveFixes(diagnostic, context) {
    const data = diagnostic.data;
    if (!data) return [];
    const expected = resolveExpectedPeerVersion(context.workspace.location, data.dep, data.devVersion);
    const version = expected === "*" ? data.devVersion : expected;
    return [{
      action: "set-version",
      dependency: data.dep,
      detail: "synced peerDependency to broad range derived from devDependency",
      section: "peerDependencies",
      version
    }];
  }
};
var peerDependencyRangeStyleRule = {
  category: "peerDependencies",
  id: "deplint.peerDependencies.range-style",
  meta: {
    description: "Peer dependency ranges should use broad installed-version form",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    for (const dep of context.packageParams.peerDependencies) {
      if (context.exclude?.has(dep)) continue;
      const current = context.packageParams.peerDependencyVersions[dep];
      if (!current) continue;
      if (current === "*") continue;
      if (current.startsWith("workspace:") || current.startsWith("catalog:") || current.startsWith("npm:")) continue;
      if (context.workspaceNames?.has(dep)) continue;
      const devRange = context.packageParams.devDependencyVersions[dep];
      const expected = resolveExpectedPeerVersion(context.workspace.location, dep, devRange);
      if (expected === "*" || current === expected) continue;
      context.report({
        data: { dep, expected },
        dependency: dep,
        message: `peerDependency ${dep} range ${current} should use broad form ${expected}`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    return data ? [{
      action: "set-version",
      dependency: data.dep,
      detail: `updated peerDependency range to ${data.expected}`,
      section: "peerDependencies",
      version: data.expected
    }] : [];
  }
};
var workspaceVersionProblemsRule = {
  category: "workspace",
  id: "deplint.workspace.protocol",
  meta: {
    description: "Workspace dependencies should use the workspace: protocol",
    fixable: ["manifest"],
    severity: "error"
  },
  evaluate(context) {
    if (!context.workspaceNames) return;
    const findings = findWorkspaceVersionProblems(context.packageParams, context.workspaceNames);
    for (const finding of findings) {
      context.report({
        data: finding,
        dependency: finding.dep,
        message: `Workspace dependency ${finding.dep} in ${finding.section} should use workspace: protocol \u2014 found ${finding.version}`
      });
    }
  },
  resolveFixes(diagnostic) {
    const data = diagnostic.data;
    return data ? [{
      action: "set-version",
      dependency: data.dep,
      detail: `set workspace:~ for ${data.section}`,
      section: data.section,
      version: "workspace:~"
    }] : [];
  }
};
var deplintRules = [
  unlistedDependenciesRule,
  unusedDependenciesRule,
  misplacedDependenciesRule,
  unlistedDevDependenciesRule,
  unusedDevDependenciesRule,
  redundantDevDependenciesRule,
  unsatisfiedPeersRule,
  unusedPeerDependenciesRule,
  unrequestedPeerDependenciesRule,
  misplacedPeerDependenciesRule,
  redundantPeerDependenciesRule,
  mismatchedPeerDevVersionsRule,
  peerDependencyRangeStyleRule,
  workspaceVersionProblemsRule
];
var builtInDeplintPlugin = { name: "builtin", rules: deplintRules };
export {
  builtInDeplintPlugin,
  deplintRules
};
//# sourceMappingURL=rules.mjs.map