@@ -6,6 +6,7 @@ use serde::Serialize;
6
6
use serde_json:: json;
7
7
use std:: fs:: File ;
8
8
use std:: io:: prelude:: * ;
9
+ use std:: path:: PathBuf ;
9
10
10
11
type Dir = String ;
11
12
type PackageName = String ;
@@ -20,33 +21,28 @@ pub struct SourceDirs {
20
21
}
21
22
22
23
pub 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
30
25
let child_packages = buildstate
31
26
. packages
32
27
. par_iter ( )
33
28
. filter ( |( _name, package) | !package. is_root )
34
29
. map ( |( _name, package) | {
35
- let path = package. get_bs_build_path ( ) ;
30
+ let path = package. get_build_path ( ) ;
36
31
37
32
let dirs = package
38
33
. dirs
39
34
. to_owned ( )
40
35
. unwrap_or ( AHashSet :: new ( ) )
41
36
. iter ( )
42
- . filter_map ( |path| path. to_str ( ) . map ( |x| x . to_string ( ) ) )
37
+ . filter_map ( |path| path. to_str ( ) . map ( String :: from ) )
43
38
. collect :: < AHashSet < String > > ( ) ;
44
39
45
40
fn deps_to_pkgs < ' a > (
46
41
packages : & ' a AHashMap < String , Package > ,
47
- xs : & ' a Option < Vec < String > > ,
42
+ dependencies : & ' a Option < Vec < String > > ,
48
43
) -> AHashSet < ( String , PackagePath ) > {
49
- xs. as_ref ( )
44
+ dependencies
45
+ . as_ref ( )
50
46
. unwrap_or ( & vec ! [ ] )
51
47
. iter ( )
52
48
. filter_map ( |name| {
@@ -94,16 +90,30 @@ pub fn print(buildstate: &BuildState) {
94
90
let mut all_dirs = AHashSet :: new ( ) ;
95
91
let mut all_pkgs: AHashMap < PackageName , AbsolutePath > = AHashMap :: new ( ) ;
96
92
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
+
97
100
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
+
98
107
dirs. iter ( ) . for_each ( |dir| {
99
- all_dirs. insert ( format ! ( "{package_path }/{dir}" ) ) ;
108
+ all_dirs. insert ( format ! ( "{relative_filename }/{dir}" ) ) ;
100
109
} ) ;
101
110
102
111
all_pkgs. extend ( pkgs. to_owned ( ) ) ;
103
112
} ) ;
104
113
105
- let path = package . get_bs_build_path ( ) ;
114
+ let path = root_package . get_bs_build_path ( ) ;
106
115
let name = path + "/.sourcedirs.json" ;
116
+
107
117
let _ = File :: create ( name. clone ( ) ) . map ( |mut file| {
108
118
let all_source_files = SourceDirs {
109
119
dirs : all_dirs. into_iter ( ) . collect :: < Vec < String > > ( ) ,
@@ -113,5 +123,47 @@ pub fn print(buildstate: &BuildState) {
113
123
file. write ( json ! ( all_source_files) . to_string ( ) . as_bytes ( ) )
114
124
} ) ;
115
125
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
+ ]
117
168
}
169
+ * */
0 commit comments