import { join } from './path.js';
const types = ['peerDependencies', 'devDependencies', 'optionalDependencies', 'dependencies'];
export function createWorkspaceGraph(cwd, wsNames, wsPkgNames, wsPackages) {
    const graph = {};
    const getWorkspaceDirs = (pkg, name) => {
        const dirs = new Set();
        for (const type of types) {
            if (pkg.manifest[type]) {
                for (const pkgName in pkg.manifest[type]) {
                    if (wsPkgNames.has(pkgName)) {
                        const wsPackage = wsPackages.get(name);
                        if (wsPackage)
                            dirs.add(wsPackage.dir);
                    }
                }
            }
        }
        return dirs;
    };
    for (const name of wsNames) {
        const pkg = wsPackages.get(name);
        if (pkg)
            graph[join(cwd, name)] = getWorkspaceDirs(pkg, name);
    }
    return graph;
}
