@@ -6,6 +6,7 @@ use serde::Serialize;
66use serde_json:: json;
77use std:: fs:: File ;
88use std:: io:: prelude:: * ;
9+ use std:: path:: PathBuf ;
910
1011type Dir = String ;
1112type PackageName = String ;
@@ -20,33 +21,28 @@ pub struct SourceDirs {
2021}
2122
2223pub fn print ( buildstate : & BuildState ) {
23- let ( _name, package) = buildstate
24- . packages
25- . iter ( )
26- . find ( |( _name, package) | package. is_root )
27- . expect ( "Could not find root package" ) ;
28-
29- // First do all child packages
24+ // Take all packages apart from the root package
3025 let child_packages = buildstate
3126 . packages
3227 . par_iter ( )
3328 . filter ( |( _name, package) | !package. is_root )
3429 . map ( |( _name, package) | {
35- let path = package. get_bs_build_path ( ) ;
30+ let path = package. get_build_path ( ) ;
3631
3732 let dirs = package
3833 . dirs
3934 . to_owned ( )
4035 . unwrap_or ( AHashSet :: new ( ) )
4136 . iter ( )
42- . filter_map ( |path| path. to_str ( ) . map ( |x| x . to_string ( ) ) )
37+ . filter_map ( |path| path. to_str ( ) . map ( String :: from ) )
4338 . collect :: < AHashSet < String > > ( ) ;
4439
4540 fn deps_to_pkgs < ' a > (
4641 packages : & ' a AHashMap < String , Package > ,
47- xs : & ' a Option < Vec < String > > ,
42+ dependencies : & ' a Option < Vec < String > > ,
4843 ) -> AHashSet < ( String , PackagePath ) > {
49- xs. as_ref ( )
44+ dependencies
45+ . as_ref ( )
5046 . unwrap_or ( & vec ! [ ] )
5147 . iter ( )
5248 . filter_map ( |name| {
@@ -94,16 +90,30 @@ pub fn print(buildstate: &BuildState) {
9490 let mut all_dirs = AHashSet :: new ( ) ;
9591 let mut all_pkgs: AHashMap < PackageName , AbsolutePath > = AHashMap :: new ( ) ;
9692
93+ // Find Root Package
94+ let ( _name, root_package) = buildstate
95+ . packages
96+ . iter ( )
97+ . find ( |( _name, package) | package. is_root )
98+ . expect ( "Could not find root package" ) ;
99+
97100 child_packages. iter ( ) . for_each ( |( package_path, dirs, pkgs) | {
101+ let relative_filename = PathBuf :: from ( & package_path)
102+ . strip_prefix ( PathBuf :: from ( & root_package. path ) )
103+ . unwrap ( )
104+ . to_string_lossy ( )
105+ . to_string ( ) ;
106+
98107 dirs. iter ( ) . for_each ( |dir| {
99- all_dirs. insert ( format ! ( "{package_path }/{dir}" ) ) ;
108+ all_dirs. insert ( format ! ( "{relative_filename }/{dir}" ) ) ;
100109 } ) ;
101110
102111 all_pkgs. extend ( pkgs. to_owned ( ) ) ;
103112 } ) ;
104113
105- let path = package . get_bs_build_path ( ) ;
114+ let path = root_package . get_bs_build_path ( ) ;
106115 let name = path + "/.sourcedirs.json" ;
116+
107117 let _ = File :: create ( name. clone ( ) ) . map ( |mut file| {
108118 let all_source_files = SourceDirs {
109119 dirs : all_dirs. into_iter ( ) . collect :: < Vec < String > > ( ) ,
@@ -113,5 +123,47 @@ pub fn print(buildstate: &BuildState) {
113123 file. write ( json ! ( all_source_files) . to_string ( ) . as_bytes ( ) )
114124 } ) ;
115125
116- let _ = std:: fs:: copy ( package. get_bs_build_path ( ) , package. get_build_path ( ) ) ;
126+ let _ = std:: fs:: copy ( root_package. get_bs_build_path ( ) , root_package. get_build_path ( ) ) ;
127+ }
128+
129+ /*
130+ {
131+ "dirs": [
132+ "/Users/rwjpeelen/Git/rewatch/testrepo/packages/dep02/src",
133+ "/Users/rwjpeelen/Git/rewatch/testrepo/packages/main/src",
134+ "/Users/rwjpeelen/Git/rewatch/testrepo/packages/new-namespace/src",
135+ "/Users/rwjpeelen/Git/rewatch/testrepo/packages/dep01/src"
136+ ],
137+ "generated": [],
138+ "pkgs": [
139+ [
140+ "@testrepo/new-namespace",
141+ "/Users/rwjpeelen/Git/rewatch/testrepo/packages/new-namespace"
142+ ],
143+ ["@testrepo/dep01", "/Users/rwjpeelen/Git/rewatch/testrepo/packages/dep01"],
144+ ["@testrepo/dep02", "/Users/rwjpeelen/Git/rewatch/testrepo/packages/dep02"]
145+ ]
146+ }
147+ */
148+
149+ /*
150+ {
151+ "dirs":[
152+ "src",
153+ "src/assets"
154+ ],
155+ "pkgs":[
156+ [
157+ "@rescript/core",
158+ "/Users/rwjpeelen/Git/walnut/test-reanalyze/node_modules/@rescript/core"
159+ ],
160+ [
161+ "@rescript/react",
162+ "/Users/rwjpeelen/Git/walnut/test-reanalyze/node_modules/@rescript/react"
163+ ]
164+ ],
165+ "generated":[
166+
167+ ]
117168}
169+ * */
0 commit comments