File tree Expand file tree Collapse file tree 5 files changed +48
-24
lines changed Expand file tree Collapse file tree 5 files changed +48
-24
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ const postcssrc = require('postcss-load-config')
1515const reporter = require ( 'postcss-reporter/lib/formatter' ) ( )
1616
1717const argv = require ( './lib/args' )
18- const depGraph = require ( './lib/depGraph ' )
18+ const createDependencyGraph = require ( './lib/DependencyGraph ' )
1919const getMapfile = require ( './lib/getMapfile' )
20+ const depGraph = createDependencyGraph ( )
2021
2122let input = argv . _
2223const { dir, output } = argv
Original file line number Diff line number Diff line change 1+ 'use strict'
2+ const path = require ( 'path' )
3+ const { DepGraph } = require ( 'dependency-graph' )
4+
5+ module . exports = function ( ) {
6+ const graph = new DepGraph ( )
7+ return {
8+ add ( message ) {
9+ message . parent = path . resolve ( message . parent )
10+ message . file = path . resolve ( message . file )
11+
12+ graph . addNode ( message . parent )
13+ graph . addNode ( message . file )
14+ graph . addDependency ( message . parent , message . file )
15+ return message
16+ } ,
17+ dependantsOf ( node ) {
18+ node = path . resolve ( node )
19+
20+ if ( graph . hasNode ( node ) ) return graph . dependantsOf ( node )
21+ return [ ]
22+ } ,
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+ const test = require ( 'ava' )
3+ const path = require ( 'path' )
4+ const createDependencyGraph = require ( './DependencyGraph.js' )
5+
6+ function resolveArray ( arr ) {
7+ return arr . map ( ( p ) => path . resolve ( p ) )
8+ }
9+
10+ test ( 'tracks dependencies' , ( t ) => {
11+ const graph = createDependencyGraph ( )
12+ graph . add ( { file : 'aa' , parent : 'a' } )
13+ graph . add ( { file : 'bb' , parent : 'b' } )
14+ graph . add ( { file : 'ab' , parent : 'a' } )
15+ graph . add ( { file : 'ab' , parent : 'b' } )
16+ t . deepEqual ( graph . dependantsOf ( 'aa' ) , resolveArray ( [ 'a' ] ) )
17+ t . deepEqual ( graph . dependantsOf ( 'bb' ) , resolveArray ( [ 'b' ] ) )
18+ t . deepEqual ( graph . dependantsOf ( 'ab' ) , resolveArray ( [ 'a' , 'b' ] ) )
19+ t . deepEqual ( graph . dependantsOf ( 'nonexistent' ) , [ ] )
20+ } )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 4848 "files" : [
4949 " bin" ,
5050 " index.js" ,
51- " lib"
51+ " lib" ,
52+ " !*.test.js"
5253 ],
5354 "keywords" : [
5455 " cli" ,
You can’t perform that action at this time.
0 commit comments