Skip to content

Commit 8eb0318

Browse files
committed
(- NF fix) Remove all .bs.m?js-suffixed build-products, not just .bs.js
1 parent 01b3888 commit 8eb0318

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

jscomp/bsb/bsb_config_parse.ml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,6 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
179179
| _ -> assert false
180180

181181
end
182-
let extract_bs_suffix_exn (map : json_map) =
183-
match Map_string.find_opt map Bsb_build_schemas.suffix with
184-
| None -> false
185-
| Some (Str {str} as config ) ->
186-
if str = Literals.suffix_js then false
187-
else if str = Literals.suffix_bs_js then true
188-
else Bsb_exception.config_error config
189-
"expect .bs.js or .js string here"
190-
| Some config ->
191-
Bsb_exception.config_error config
192-
"expect .bs.js or .js string here"
193182

194183
let extract_gentype_config (map : json_map) cwd
195184
: Bsb_config_types.gentype_config option =
@@ -402,7 +391,6 @@ let interpret_json
402391
extract_package_name_and_namespace map in
403392
let refmt = extract_refmt map per_proj_dir in
404393
let gentype_config = extract_gentype_config map per_proj_dir in
405-
let bs_suffix = extract_bs_suffix_exn map in
406394
(* The default situation is empty *)
407395
let built_in_package = check_stdlib map per_proj_dir in
408396
let package_specs =
@@ -411,6 +399,7 @@ let interpret_json
411399
Bsb_package_specs.from_json x
412400
| None -> Bsb_package_specs.default_package_specs
413401
in
402+
let bs_suffixes = Bsb_package_specs.extract_in_source_bs_suffixes package_specs in
414403
let pp_flags : string option =
415404
extract_string map Bsb_build_schemas.pp_flags (fun p ->
416405
if p = "" then
@@ -434,12 +423,11 @@ let interpret_json
434423
~toplevel
435424
~root: per_proj_dir
436425
~cut_generators
437-
~bs_suffix
426+
~bs_suffixes
438427
~namespace
439428
sources in
440429
{
441430
gentype_config;
442-
bs_suffix ;
443431
package_name ;
444432
namespace ;
445433
warning = extract_warning map;

jscomp/bsb/bsb_package_specs.ml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ let default_suffix format in_source =
9393
| _, false -> Literals.suffix_mjs
9494
| _, true -> Literals.suffix_bs_mjs
9595

96+
module SS = Set.Make(String)
97+
98+
let supported_bs_suffixes = Literals.[suffix_bs_js; suffix_bs_mjs]
99+
100+
(** Produces a [list] of supported, bs-prefixed file-suffixes used in
101+
[in-source] package-specs.
102+
*)
103+
let extract_in_source_bs_suffixes (package_specs : Spec_set.t) =
104+
let f spec suffixes =
105+
if spec.in_source && List.mem spec.suffix supported_bs_suffixes then
106+
SS.add spec.suffix suffixes
107+
else suffixes
108+
in
109+
let suffixes = Spec_set.fold f package_specs SS.empty in
110+
SS.elements suffixes
96111

97112
let rec from_array (arr : Ext_json_types.t array) : Spec_set.t =
98113
let spec = ref Spec_set.empty in
@@ -176,9 +191,9 @@ let package_flag_of_package_specs (package_specs : t)
176191
Ext_string.inter2 acc (package_flag format dirname )
177192
) package_specs Ext_string.empty
178193

179-
let default_package_specs =
180-
Spec_set.singleton
181-
{ format = NodeJS ; in_source = false ; suffix = Literals.suffix_js }
194+
let default_package_specs =
195+
Spec_set.singleton
196+
{format = NodeJS; in_source = false; suffix = default_suffix NodeJS false }
182197

183198

184199

jscomp/bsb/bsb_package_specs.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ val from_json:
3333
val get_list_of_output_js :
3434
t -> bool -> string -> string list
3535

36+
val extract_in_source_bs_suffixes :
37+
t -> string list
38+
3639
(**
3740
Sample output: {[ -bs-package-output commonjs:lib/js/jscomp/test]}
3841
*)

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type cxt = {
5151
cut_generators : bool;
5252
traverse : bool;
5353
namespace : string option;
54-
bs_suffix: bool;
54+
bs_suffixes: string list;
5555
ignored_dirs : Set_string.t
5656
}
5757

@@ -205,9 +205,17 @@ let classify_suffix (x : string) : suffix_kind =
205205
if i >= 0 then Cmti i
206206
else Not_any
207207

208+
209+
(** Attempt to delete any [.bs.m?js] files for a given artifact. *)
210+
let unlink_bs_suffixes context artifact =
211+
List.iter (fun suffix ->
212+
try_unlink (Filename.concat context.cwd (artifact ^ suffix)) ;
213+
) context.bs_suffixes
214+
215+
208216
(** This is the only place where we do some removal during scanning,
209-
configurabl
210-
*)
217+
configurably
218+
*)
211219
let prune_staled_bs_js_files
212220
(context : cxt)
213221
(cur_sources : _ Map_string.t )
@@ -242,13 +250,8 @@ let prune_staled_bs_js_files
242250
cmd ^
243251
" -cmt-rm " ^ filepath)
244252
)
245-
| 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-
)
253+
| Cmj _ ->
254+
unlink_bs_suffixes context (String.sub x 0 j)
252255
| _ -> ());
253256
try_unlink filepath
254257
end
@@ -398,7 +401,7 @@ let scan
398401
~root
399402
~cut_generators
400403
~namespace
401-
~bs_suffix
404+
~bs_suffixes
402405
~ignored_dirs
403406
x : t * int =
404407
Bsb_dir_index.reset ();
@@ -411,7 +414,7 @@ let scan
411414
root ;
412415
cut_generators;
413416
namespace;
414-
bs_suffix;
417+
bs_suffixes;
415418
traverse = false
416419
} x in
417420
output, Bsb_dir_index.get_current_number_of_dev_groups ()

jscomp/bsb/bsb_parse_sources.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ val scan :
3434
root: string ->
3535
cut_generators: bool ->
3636
namespace : string option ->
37-
bs_suffix:bool ->
37+
bs_suffixes : string list ->
3838
ignored_dirs:Set_string.t ->
3939
Ext_json_types.t ->
4040
Bsb_file_groups.t * int

0 commit comments

Comments
 (0)