Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export const resolveDependenciesForNpmProject = async (
const arborist = new Arborist({ path });
const topNode = await arborist.loadActual();

const visitedNodes = new Set<Node | Link>();

const parseNode = async (node: Node | Link) => {
if (visitedNodes.has(node)) {
return;
}
visitedNodes.add(node);

if (node.dev || node.peer) {
return;
}
Expand Down Expand Up @@ -73,13 +80,19 @@ export const resolveDependenciesForNpmProject = async (
logger.warn(warningLines.join("\n"));
}

for (const child of node.children.values()) {
await parseNode(child);
for (const edgeOut of node.edgesOut.values()) {
const edgeNode = edgeOut.to;
if (edgeNode) {
await parseNode(edgeNode);
}
}
};

for (const child of topNode.children.values()) {
await parseNode(child);
const isTopLevel = isTopLevelDependency(child);
if (isTopLevel) {
await parseNode(child);
}
}
};

Expand All @@ -88,3 +101,13 @@ const resolvePath = (path: string): string => {

return dirname(absolutePackageJson);
};

const isTopLevelDependency = (node: Node | Link): boolean => {
for (const edge of node.edgesIn) {
if (edge.from?.isRoot) {
return true;
}
}

return false;
};
Loading