Skip to content

Commit 9909eaa

Browse files
committed
(- noop style fix) Run relevant sections thru ocamlformat
These are the portions of the codebase changed in later commits to this branch. I've rebased any whitespace / formatting-only changes back into this commit, to produce a slightly-less-noisy diff.
1 parent e30af84 commit 9909eaa

File tree

8 files changed

+211
-270
lines changed

8 files changed

+211
-270
lines changed

jscomp/bsb/bsb_package_specs.ml

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ let (//) = Ext_path.combine
3131
type format =
3232
| NodeJS | Es6 | Es6_global
3333

34-
type spec = {
35-
format : format;
36-
in_source : bool
37-
}
34+
type spec = { format : format; in_source : bool }
3835

3936
module Spec_set = Set.Make( struct type t = spec
4037
let compare = Pervasives.compare
@@ -68,83 +65,82 @@ let prefix_of_format (x : format) =
6865
| Es6 -> Bsb_config.lib_es6
6966
| Es6_global -> Bsb_config.lib_es6_global )
7067

68+
7169
let rec from_array (arr : Ext_json_types.t array) : Spec_set.t =
7270
let spec = ref Spec_set.empty in
7371
let has_in_source = ref false in
7472
Ext_array.iter arr (fun x ->
75-
let result = from_json_single x in
73+
let result = from_json_single x in
7674
if result.in_source then
77-
(
78-
if not !has_in_source then
79-
has_in_source:= true
80-
else
81-
Bsb_exception.errorf
82-
~loc:(Ext_json.loc_of x)
83-
"package-specs: we've detected two module formats that are both configured to be in-source."
84-
);
85-
spec := Spec_set.add result !spec
86-
);
75+
if not !has_in_source then has_in_source := true
76+
else
77+
Bsb_exception.errorf ~loc:(Ext_json.loc_of x)
78+
"package-specs: we've detected two module formats that are both \
79+
configured to be in-source.";
80+
spec := Spec_set.add result !spec);
8781
!spec
8882

83+
8984
(* TODO: FIXME: better API without mutating *)
9085
and from_json_single (x : Ext_json_types.t) : spec =
9186
match x with
92-
| Str {str = format; loc } ->
93-
{format = supported_format format loc ; in_source = false }
94-
| Obj {map; loc} ->
95-
begin match Map_string.find_exn map "module" with
96-
| Str {str = format} ->
97-
let in_source =
98-
match Map_string.find_opt map Bsb_build_schemas.in_source with
99-
| Some (True _) -> true
100-
| Some _
101-
| None -> false
102-
in
103-
{format = supported_format format loc ; in_source }
87+
| Str { str = format; loc } ->
88+
{ format = supported_format format loc; in_source = false }
89+
| Obj { map; loc } -> (
90+
match Map_string.find_exn map "module" with
91+
| Str { str = format } ->
92+
let in_source =
93+
match Map_string.find_opt map Bsb_build_schemas.in_source with
94+
| Some (True _) -> true
95+
| Some _ | None -> false
96+
in
97+
{ format = supported_format format loc; in_source }
10498
| Arr _ ->
105-
Bsb_exception.errorf ~loc
106-
"package-specs: when the configuration is an object, `module` field should be a string, not an array. If you want to pass multiple module specs, try turning package-specs into an array of objects (or strings) instead."
99+
Bsb_exception.errorf ~loc
100+
"package-specs: when the configuration is an object, `module` \
101+
field should be a string, not an array. If you want to pass \
102+
multiple module specs, try turning package-specs into an array of \
103+
objects (or strings) instead."
107104
| _ ->
108-
Bsb_exception.errorf ~loc
109-
"package-specs: the `module` field of the configuration object should be a string."
105+
Bsb_exception.errorf ~loc
106+
"package-specs: the `module` field of the configuration object \
107+
should be a string."
110108
| exception _ ->
111-
Bsb_exception.errorf ~loc
112-
"package-specs: when the configuration is an object, the `module` field is mandatory."
113-
end
114-
| _ -> Bsb_exception.errorf ~loc:(Ext_json.loc_of x)
115-
"package-specs: we expect either a string or an object."
109+
Bsb_exception.errorf ~loc
110+
"package-specs: when the configuration is an object, the `module` \
111+
field is mandatory." )
112+
| _ ->
113+
Bsb_exception.errorf ~loc:(Ext_json.loc_of x)
114+
"package-specs: we expect either a string or an object."
116115

117-
let from_json (x : Ext_json_types.t) : Spec_set.t =
116+
117+
let from_json (x : Ext_json_types.t) : Spec_set.t =
118118
match x with
119-
| Arr {content ; _} -> from_array content
120-
| _ -> Spec_set.singleton (from_json_single x )
119+
| Arr { content; _ } -> from_array content
120+
| _ -> Spec_set.singleton (from_json_single x)
121121

122122

123123
let bs_package_output = "-bs-package-output"
124124

125125
(** Assume input is valid
126-
{[ -bs-package-output commonjs:lib/js/jscomp/test ]}
127-
*)
128-
let package_flag ({format; in_source } : spec) dir =
129-
Ext_string.inter2
130-
bs_package_output
131-
(Ext_string.concat3
132-
(string_of_format format)
133-
Ext_string.single_colon
134-
(if in_source then dir else
135-
prefix_of_format format // dir))
136-
137-
let package_flag_of_package_specs (package_specs : t)
138-
(dirname : string ) : string =
139-
Spec_set.fold (fun format acc ->
140-
Ext_string.inter2 acc (package_flag format dirname )
141-
) package_specs Ext_string.empty
142126
143-
let default_package_specs =
144-
Spec_set.singleton
145-
{ format = NodeJS ; in_source = false }
127+
{[ -bs-package-output commonjs:lib/js/jscomp/test ]} *)
128+
let package_flag ({ format; in_source } : spec) dir =
129+
Ext_string.inter2 bs_package_output
130+
(Ext_string.concat3 (string_of_format format) Ext_string.single_colon
131+
(if in_source then dir else prefix_of_format format // dir))
146132

147133

134+
let package_flag_of_package_specs (package_specs : t) (dirname : string) :
135+
string =
136+
Spec_set.fold
137+
(fun format acc -> Ext_string.inter2 acc (package_flag format dirname))
138+
package_specs Ext_string.empty
139+
140+
141+
let default_package_specs =
142+
Spec_set.singleton { format = NodeJS; in_source = false }
143+
148144

149145
(**
150146
[get_list_of_output_js specs "src/hi/hello"]

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 53 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ let errorf x fmt =
4444
Bsb_exception.errorf ~loc:(Ext_json.loc_of x) fmt
4545

4646
type cxt = {
47-
toplevel : bool ;
48-
dir_index : Bsb_dir_index.t ;
49-
cwd : string ;
47+
toplevel : bool;
48+
dir_index : Bsb_dir_index.t;
49+
cwd : string;
5050
root : string;
5151
cut_generators : bool;
5252
traverse : bool;
5353
namespace : string option;
54-
bs_suffix: bool;
55-
ignored_dirs : Set_string.t
54+
bs_suffix : bool;
55+
ignored_dirs : Set_string.t;
5656
}
5757

5858
(** [public] has a list of modules, we do a sanity check to see if all the listed
@@ -205,58 +205,46 @@ let classify_suffix (x : string) : suffix_kind =
205205
if i >= 0 then Cmti i
206206
else Not_any
207207

208+
208209
(** This is the only place where we do some removal during scanning,
209-
configurabl
210-
*)
211-
let prune_staled_bs_js_files
212-
(context : cxt)
213-
(cur_sources : _ Map_string.t )
214-
: unit =
210+
configurably. *)
211+
let prune_staled_bs_js_files (context : cxt) (cur_sources : _ Map_string.t) :
212+
unit =
215213
let lib_parent =
216-
Filename.concat (Filename.concat context.root Bsb_config.lib_bs)
217-
context.cwd in
214+
Filename.concat (Filename.concat context.root Bsb_config.lib_bs) context.cwd
215+
in
218216
if Sys.file_exists lib_parent then
219217
let artifacts = Sys.readdir lib_parent in
220218
Ext_array.iter artifacts (fun x ->
221-
let kind = classify_suffix x in
219+
let kind = classify_suffix x in
222220
match kind with
223221
| Not_any -> ()
224222
| Cmi i | Cmt i | Cmj i | Cmti i ->
225-
let j =
226-
if context.namespace = None then i
227-
else
228-
Ext_string.rindex_neg x '-'
229-
in
230-
if j >= 0 then
231-
let cmp = Ext_string.capitalize_sub x j in
232-
if not (Map_string.mem cur_sources cmp) then
233-
begin (* prune action *)
234-
let filepath = Filename.concat lib_parent x in
235-
(match kind with
236-
| Cmt _ ->
237-
let lazy cmd = bs_cmt_post_process_cmd in
238-
239-
if cmd <> "" then
240-
Ext_pervasives.try_it (fun _ ->
241-
Sys.command (
242-
cmd ^
243-
" -cmt-rm " ^ filepath)
244-
)
223+
let j =
224+
if context.namespace = None then i
225+
else Ext_string.rindex_neg x '-'
226+
in
227+
if j >= 0 then
228+
let cmp = Ext_string.capitalize_sub x j in
229+
if not (Map_string.mem cur_sources cmp) then (
230+
(* prune action *)
231+
let filepath = Filename.concat lib_parent x in
232+
( match kind with
233+
| Cmt _ ->
234+
let (lazy cmd) = bs_cmt_post_process_cmd in
235+
236+
if cmd <> "" then
237+
Ext_pervasives.try_it (fun _ ->
238+
Sys.command (cmd ^ " -cmt-rm " ^ filepath))
245239
| Cmj _ ->
246-
(* remove .bs.js *)
247-
if context.bs_suffix then
248-
try_unlink
249-
(Filename.concat context.cwd
250-
(String.sub x 0 j ^ Literals.suffix_bs_js)
251-
)
252-
| _ -> ());
253-
try_unlink filepath
254-
end
255-
else () (* assert false *)
256-
)
257-
258-
259-
240+
(* remove .bs.js *)
241+
if context.bs_suffix then
242+
try_unlink
243+
(Filename.concat context.cwd
244+
(String.sub x 0 j ^ Literals.suffix_bs_js))
245+
| _ -> () );
246+
try_unlink filepath )
247+
else () (* assert false *))
260248

261249

262250
(********************************************************************)
@@ -392,30 +380,25 @@ and parse_sources ( cxt : cxt) (sources : Ext_json_types.t ) =
392380
| _ -> parsing_single_source cxt sources
393381

394382

395-
396-
let scan
397-
~toplevel
398-
~root
399-
~cut_generators
400-
~namespace
401-
~bs_suffix
402-
~ignored_dirs
403-
x : t * int =
383+
let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffix ~ignored_dirs x :
384+
t * int =
404385
Bsb_dir_index.reset ();
405386
let output =
406-
parse_sources {
407-
ignored_dirs;
408-
toplevel;
409-
dir_index = Bsb_dir_index.lib_dir_index;
410-
cwd = Filename.current_dir_name;
411-
root ;
412-
cut_generators;
413-
namespace;
414-
bs_suffix;
415-
traverse = false
416-
} x in
417-
output, Bsb_dir_index.get_current_number_of_dev_groups ()
418-
387+
parse_sources
388+
{
389+
ignored_dirs;
390+
toplevel;
391+
dir_index = Bsb_dir_index.lib_dir_index;
392+
cwd = Filename.current_dir_name;
393+
root;
394+
cut_generators;
395+
namespace;
396+
bs_suffix;
397+
traverse = false;
398+
}
399+
x
400+
in
401+
(output, Bsb_dir_index.get_current_number_of_dev_groups ())
419402

420403

421404
(* Walk through to do some work *)

0 commit comments

Comments
 (0)