aboutsummaryrefslogtreecommitdiff
path: root/node_modules/postcss-cli/lib/depGraph.js
blob: 19bd6b70a4419844e008244fa097a33f504fb0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict'
const path = require('path')
const DepGraph = require('dependency-graph').DepGraph

const graph = new DepGraph()

exports.add = message => {
  message.parent = path.resolve(message.parent)
  message.file = path.resolve(message.file)

  graph.addNode(message.parent)
  graph.addNode(message.file)
  graph.addDependency(message.parent, message.file)
  return message
}

exports.dependantsOf = node => {
  node = path.resolve(node)

  if (graph.hasNode(node)) return graph.dependantsOf(node)
  return []
}