11(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
2- *
2+ *
33 * This program is free software: you can redistribute it and/or modify
44 * it under the terms of the GNU Lesser General Public License as published by
55 * the Free Software Foundation, either version 3 of the License, or
1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1919 * GNU Lesser General Public License for more details.
20- *
20+ *
2121 * You should have received a copy of the GNU Lesser General Public License
2222 * along with this program; if not, write to the Free Software
2323 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
@@ -43,18 +43,18 @@ let split_by_sep_per_os : string -> string list =
4343
4444(* * example
4545 {[
46- "/bb/mbigc/mbig2899/bgit/bucklescript /jscomp/stdlib/external/pervasives.cmj"
47- "/bb/mbigc/mbig2899/bgit/bucklescript /jscomp/stdlib/ocaml_array.ml"
46+ "/bb/mbigc/mbig2899/bgit/rescript /jscomp/stdlib/external/pervasives.cmj"
47+ "/bb/mbigc/mbig2899/bgit/rescript /jscomp/stdlib/ocaml_array.ml"
4848 ]}
4949
5050 The other way
5151 {[
5252
53- "/bb/mbigc/mbig2899/bgit/bucklescript /jscomp/stdlib/ocaml_array.ml"
54- "/bb/mbigc/mbig2899/bgit/bucklescript /jscomp/stdlib/external/pervasives.cmj"
53+ "/bb/mbigc/mbig2899/bgit/rescript /jscomp/stdlib/ocaml_array.ml"
54+ "/bb/mbigc/mbig2899/bgit/rescript /jscomp/stdlib/external/pervasives.cmj"
5555 ]}
5656 {[
57- "/bb/mbigc/mbig2899/bgit/bucklescript /jscomp/stdlib//ocaml_array.ml"
57+ "/bb/mbigc/mbig2899/bgit/rescript /jscomp/stdlib//ocaml_array.ml"
5858 ]}
5959 {[
6060 /a/b
@@ -117,7 +117,7 @@ let ( // ) x y =
117117 split_aux "//ghosg//ghsogh/";;
118118 - : string * string list = ("/", ["ghosg"; "ghsogh"])
119119 ]}
120- Note that
120+ Note that
121121 {[
122122 Filename.dirname "/a/" = "/"
123123 Filename.dirname "/a/b/" = Filename.dirname "/a/b" = "/a"
@@ -132,7 +132,7 @@ let ( // ) x y =
132132 basename "" = "."
133133 dirname "" = "."
134134 dirname "" = "."
135- ]}
135+ ]}
136136*)
137137let split_aux p =
138138 let rec go p acc =
@@ -149,11 +149,11 @@ let split_aux p =
149149
150150 go p []
151151
152- (* *
152+ (* *
153153 TODO: optimization
154- if [from] and [to] resolve to the same path, a zero-length string is returned
154+ if [from] and [to] resolve to the same path, a zero-length string is returned
155155
156- This function is useed in [es6-global] and
156+ This function is useed in [es6-global] and
157157 [amdjs-global] format and tailored for `rollup`
158158*)
159159let rel_normalized_absolute_path ~from to_ =
@@ -261,14 +261,17 @@ let concat dirname filename =
261261let check_suffix_case = Ext_string. ends_with
262262
263263(* Input must be absolute directory *)
264- let rec find_root_filename ~cwd filename =
265- if Sys. file_exists (Filename. concat cwd filename) then cwd
264+ let rec find_root_filename ~cwd filenames =
265+ let file_exists = Ext_list. exists filenames (fun filename ->
266+ Sys. file_exists (Filename. concat cwd filename))
267+ in
268+ if file_exists then cwd
266269 else
267270 let cwd' = Filename. dirname cwd in
268271 if String. length cwd' < String. length cwd then
269- find_root_filename ~cwd: cwd' filename
270- else Ext_fmt. failwithf ~loc: __LOC__ " %s not found from %s" filename cwd
272+ find_root_filename ~cwd: cwd' filenames
273+ else Ext_fmt. failwithf ~loc: __LOC__ " %s not found from %s" ( List. hd filenames) cwd
271274
272- let find_package_json_dir cwd = find_root_filename ~cwd Literals. bsconfig_json
275+ let find_config_dir cwd = find_root_filename ~cwd [ Literals. rescript_json; Literals. bsconfig_json]
273276
274- let package_dir = lazy (find_package_json_dir (Lazy. force cwd))
277+ let package_dir = lazy (find_config_dir (Lazy. force cwd))
0 commit comments