// src/lib/updo/collectWorkspaceDeps.ts
import { readFileSync } from "node:fs";
import PATH from "node:path";
var DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies"];
function collectWorkspaceDeps(cwd, workspaces, workspaceNames) {
  const declaredDeps = [];
  for (const ws of workspaces) {
    const pkgPath = PATH.resolve(cwd, ws.location, "package.json");
    let pkg;
    try {
      pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
    } catch {
      continue;
    }
    for (const depField of DEP_FIELDS) {
      const deps = pkg[depField];
      if (!deps) continue;
      for (const [name, range] of Object.entries(deps)) {
        if (workspaceNames.has(name)) continue;
        if (range.startsWith("workspace:")) continue;
        declaredDeps.push({
          depType: depField,
          name,
          range,
          workspaceLocation: ws.location,
          workspaceName: ws.name
        });
      }
    }
  }
  return declaredDeps;
}
export {
  collectWorkspaceDeps
};
//# sourceMappingURL=collectWorkspaceDeps.mjs.map
