@@ -57,14 +57,17 @@ fn recursion(pkg_name: String, res: Vec<(String, String)>, duplicate_dependents:
5757 }
5858 return ;
5959}
60+
6061#[ neon:: export]
61- fn get_affected_pkg ( pkg_name : String ) {
62+ fn get_affected_pkg < ' a > ( cx : & mut FunctionContext < ' a > , pkg_name : String ) -> JsResult < ' a , JsArray > {
6263 let filter = vec ! [ ".yarn" , "node_modules" ] ;
6364 let paths = find_pkg_json:: find_pkg_json ( filter) ;
6465 let mut res: Vec < ( String , String ) > = Vec :: new ( ) ;
6566 let mut pkg_names = Vec :: new ( ) ;
6667 let mut unique_dependents = HashSet :: < String > :: new ( ) ;
6768 let mut duplicate_dependents = Vec :: new ( ) ;
69+ let mut dependents = Vec :: new ( ) ;
70+ let dependents_js = JsArray :: new ( cx, 0 ) ;
6871
6972 for path in paths. clone ( ) {
7073 pkg_names. push ( get_pkg_name ( path. clone ( ) ) ) ;
@@ -77,19 +80,20 @@ fn get_affected_pkg(pkg_name: String) {
7780
7881 recursion ( pkg_name, res, & mut duplicate_dependents) ;
7982
80- if duplicate_dependents . len ( ) == 0 {
81- println ! ( "No dependents found on this pkg" ) ;
83+ for pkg in duplicate_dependents {
84+ unique_dependents . insert ( pkg) ;
8285 }
83- else {
84- for pkg in duplicate_dependents {
85- unique_dependents. insert ( pkg) ;
86- }
87- for pkg in unique_dependents {
88- println ! ( "{}" , pkg) ;
89- }
90-
86+ for pkg in unique_dependents. clone ( ) {
87+ dependents. push ( pkg) ;
88+ }
89+
90+ for ( i, s) in unique_dependents. iter ( ) . enumerate ( ) {
91+ let v = cx. string ( s) ;
92+ dependents_js. set ( cx, i as u32 , v) ?;
9193 }
94+ Ok ( dependents_js)
9295}
96+
9397#[ neon:: export]
9498fn dag < ' a > ( cx : & mut FunctionContext < ' a > ) -> JsResult < ' a , JsArray > {
9599 let js_array = JsArray :: new ( cx, 0 ) ;
0 commit comments