@@ -6,50 +6,31 @@ const Fs = require('fs');
66const Npm = require ( 'libnpm' ) ;
77const Path = require ( 'path' ) ;
88const Semver = require ( 'semver' ) ;
9- const Topo = require ( 'topo' ) ;
109
1110
1211const internals = { } ;
1312
1413
15- internals . scan = ( tree , parent , map = new Map ( ) , scanned = new Set ( ) ) => {
14+ internals . queue = ( tree , queue = [ ] , scanned = new Set ( ) ) => {
1615
1716 for ( const [ , v ] of tree . dependencies ) {
1817
19- if ( v . hasCycle ( ) ) {
20- console . warn ( `==========> skip ${ v . path ( ) } (because it has a cycle in dependencies)` ) ;
21- continue ;
22- }
23-
2418 const path = v . path ( ) ;
25- if ( ! map . has ( path ) ) {
26- map . set ( path , [ ] ) ;
27- }
28-
29- const node = map . get ( path ) ;
30- node . push ( parent ) ;
3119
32- if ( ! scanned . has ( v ) ) {
33- scanned . add ( v ) ;
34- internals . scan ( v , v . path ( ) , map , scanned ) ;
20+ if ( scanned . has ( path ) ) {
21+ // prevent cycles
22+ continue ;
3523 }
36- }
37-
38- return map ;
39- } ;
4024
41-
42- internals . queue = ( tree ) => {
43-
44- const map = internals . scan ( tree ) ;
45- const topo = new Topo ( ) ;
46- for ( const [ group , before ] of map ) {
47- topo . add ( group , { group, before } ) ;
25+ scanned . add ( path ) ;
26+ internals . queue ( v , queue , scanned ) ;
27+ queue . push ( v . path ( ) ) ; // adding deepest deps into the queue first
4828 }
4929
50- return topo . nodes ;
30+ return queue ;
5131} ;
5232
33+
5334internals . runScript = ( stage , { pkg, path, cwd, unsafePerm } , options ) => {
5435
5536 if ( ! pkg . scripts || ! pkg . scripts [ stage ] ) {
0 commit comments