@@ -6,50 +6,31 @@ const Fs = require('fs');
6
6
const Npm = require ( 'libnpm' ) ;
7
7
const Path = require ( 'path' ) ;
8
8
const Semver = require ( 'semver' ) ;
9
- const Topo = require ( 'topo' ) ;
10
9
11
10
12
11
const internals = { } ;
13
12
14
13
15
- internals . scan = ( tree , parent , map = new Map ( ) , scanned = new Set ( ) ) => {
14
+ internals . queue = ( tree , queue = [ ] , scanned = new Set ( ) ) => {
16
15
17
16
for ( const [ , v ] of tree . dependencies ) {
18
17
19
- if ( v . hasCycle ( ) ) {
20
- console . warn ( `==========> skip ${ v . path ( ) } (because it has a cycle in dependencies)` ) ;
21
- continue ;
22
- }
23
-
24
18
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 ) ;
31
19
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 ;
35
23
}
36
- }
37
-
38
- return map ;
39
- } ;
40
24
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
48
28
}
49
29
50
- return topo . nodes ;
30
+ return queue ;
51
31
} ;
52
32
33
+
53
34
internals . runScript = ( stage , { pkg, path, cwd, unsafePerm } , options ) => {
54
35
55
36
if ( ! pkg . scripts || ! pkg . scripts [ stage ] ) {
0 commit comments