This repository has been archived on 2024-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
fediversity.eu/node_modules/postcss-cli/lib/DependencyGraph.js
2024-03-26 16:28:28 +01:00

31 lines
802 B
JavaScript

import path from 'path'
import { DepGraph } from 'dependency-graph'
export default function createDependencyGraph() {
const graph = new DepGraph()
return {
add(message) {
message.parent = path.resolve(message.parent)
graph.addNode(message.parent)
if (message.type === 'dir-dependency') {
message.dir = path.resolve(message.dir)
graph.addNode(message.dir)
graph.addDependency(message.parent, message.dir)
} else {
message.file = path.resolve(message.file)
graph.addNode(message.file)
graph.addDependency(message.parent, message.file)
}
return message
},
dependantsOf(node) {
node = path.resolve(node)
if (graph.hasNode(node)) return graph.dependantsOf(node)
return []
},
}
}