Skip to content

Commit 67c554d

Browse files
authored
Merge pull request #4430 from BuckleScript/gentype
When cleaning generated files, read `language` from `gentypeconfig` t…
2 parents 0dd79f0 + 0d64eb7 commit 67c554d

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

jscomp/bsb/bsb_build_schemas.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@ let number = "number"
8181
let error = "error"
8282
let suffix = "suffix"
8383
let gentypeconfig = "gentypeconfig"
84+
let language = "language"
8485
let path = "path"
8586
let ignored_dirs = "ignored-dirs"

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ type walk_cxt = {
422422
root : string;
423423
traverse : bool;
424424
ignored_dirs : Set_string.t;
425+
gentype_language: string;
425426
}
426427

427428
let rec walk_sources (cxt : walk_cxt) (sources : Ext_json_types.t) =
@@ -449,10 +450,11 @@ and walk_source_dir_map (cxt : walk_cxt) sub_dirs_field =
449450
let working_dir = Filename.concat cxt.root cxt.cwd in
450451
if not (Set_string.mem cxt.ignored_dirs cxt.cwd) then begin
451452
let file_array = Sys.readdir working_dir in
452-
(* Remove .re.js when clean up *)
453-
Ext_array.iter file_array begin fun file ->
454-
if Ext_string.ends_with file Literals.suffix_gen_js
455-
|| Ext_string.ends_with file Literals.suffix_gen_tsx
453+
(* Remove .gen.js/.gen.tsx during clean up *)
454+
Ext_array.iter file_array begin fun file ->
455+
let is_typescript = cxt.gentype_language = "typescript" in
456+
if ((not is_typescript) && Ext_string.ends_with file Literals.suffix_gen_js)
457+
|| (is_typescript && Ext_string.ends_with file Literals.suffix_gen_tsx)
456458
then
457459
Sys.remove (Filename.concat working_dir file)
458460
end;
@@ -487,13 +489,20 @@ let clean_re_js root =
487489
| Some (Arr {content = x}) -> Set_string.of_list (Bsb_build_util.get_list_string x )
488490
| Some _
489491
| None -> Set_string.empty
490-
in
492+
in
493+
let gentype_language =
494+
match Map_string.find_opt map Bsb_build_schemas.language with
495+
| None -> ""
496+
| Some (Str {str}) -> str
497+
| Some _ -> ""
498+
in
491499
Ext_option.iter (Map_string.find_opt map Bsb_build_schemas.sources) begin fun config ->
492500
try (
493501
walk_sources { root ;
494502
traverse = true;
495503
cwd = Filename.current_dir_name;
496-
ignored_dirs
504+
ignored_dirs;
505+
gentype_language;
497506
} config
498507
) with _ -> ()
499508
end

lib/4.06.1/bsb.ml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ let number = "number"
147147
let error = "error"
148148
let suffix = "suffix"
149149
let gentypeconfig = "gentypeconfig"
150+
let language = "language"
150151
let path = "path"
151152
let ignored_dirs = "ignored-dirs"
152153

@@ -10885,6 +10886,7 @@ type walk_cxt = {
1088510886
root : string;
1088610887
traverse : bool;
1088710888
ignored_dirs : Set_string.t;
10889+
gentype_language: string;
1088810890
}
1088910891

1089010892
let rec walk_sources (cxt : walk_cxt) (sources : Ext_json_types.t) =
@@ -10912,10 +10914,11 @@ and walk_source_dir_map (cxt : walk_cxt) sub_dirs_field =
1091210914
let working_dir = Filename.concat cxt.root cxt.cwd in
1091310915
if not (Set_string.mem cxt.ignored_dirs cxt.cwd) then begin
1091410916
let file_array = Sys.readdir working_dir in
10915-
(* Remove .re.js when clean up *)
10916-
Ext_array.iter file_array begin fun file ->
10917-
if Ext_string.ends_with file Literals.suffix_gen_js
10918-
|| Ext_string.ends_with file Literals.suffix_gen_tsx
10917+
(* Remove .gen.js/.gen.tsx during clean up *)
10918+
Ext_array.iter file_array begin fun file ->
10919+
let is_typescript = cxt.gentype_language = "typescript" in
10920+
if ((not is_typescript) && Ext_string.ends_with file Literals.suffix_gen_js)
10921+
|| (is_typescript && Ext_string.ends_with file Literals.suffix_gen_tsx)
1091910922
then
1092010923
Sys.remove (Filename.concat working_dir file)
1092110924
end;
@@ -10950,13 +10953,20 @@ let clean_re_js root =
1095010953
| Some (Arr {content = x}) -> Set_string.of_list (Bsb_build_util.get_list_string x )
1095110954
| Some _
1095210955
| None -> Set_string.empty
10953-
in
10956+
in
10957+
let gentype_language =
10958+
match Map_string.find_opt map Bsb_build_schemas.language with
10959+
| None -> ""
10960+
| Some (Str {str}) -> str
10961+
| Some _ -> ""
10962+
in
1095410963
Ext_option.iter (Map_string.find_opt map Bsb_build_schemas.sources) begin fun config ->
1095510964
try (
1095610965
walk_sources { root ;
1095710966
traverse = true;
1095810967
cwd = Filename.current_dir_name;
10959-
ignored_dirs
10968+
ignored_dirs;
10969+
gentype_language;
1096010970
} config
1096110971
) with _ -> ()
1096210972
end

lib/4.06.1/unstable/bsb_native.ml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ let number = "number"
147147
let error = "error"
148148
let suffix = "suffix"
149149
let gentypeconfig = "gentypeconfig"
150+
let language = "language"
150151
let path = "path"
151152
let ignored_dirs = "ignored-dirs"
152153

@@ -10917,6 +10918,7 @@ type walk_cxt = {
1091710918
root : string;
1091810919
traverse : bool;
1091910920
ignored_dirs : Set_string.t;
10921+
gentype_language: string;
1092010922
}
1092110923

1092210924
let rec walk_sources (cxt : walk_cxt) (sources : Ext_json_types.t) =
@@ -10944,10 +10946,11 @@ and walk_source_dir_map (cxt : walk_cxt) sub_dirs_field =
1094410946
let working_dir = Filename.concat cxt.root cxt.cwd in
1094510947
if not (Set_string.mem cxt.ignored_dirs cxt.cwd) then begin
1094610948
let file_array = Sys.readdir working_dir in
10947-
(* Remove .re.js when clean up *)
10948-
Ext_array.iter file_array begin fun file ->
10949-
if Ext_string.ends_with file Literals.suffix_gen_js
10950-
|| Ext_string.ends_with file Literals.suffix_gen_tsx
10949+
(* Remove .gen.js/.gen.tsx during clean up *)
10950+
Ext_array.iter file_array begin fun file ->
10951+
let is_typescript = cxt.gentype_language = "typescript" in
10952+
if ((not is_typescript) && Ext_string.ends_with file Literals.suffix_gen_js)
10953+
|| (is_typescript && Ext_string.ends_with file Literals.suffix_gen_tsx)
1095110954
then
1095210955
Sys.remove (Filename.concat working_dir file)
1095310956
end;
@@ -10982,13 +10985,20 @@ let clean_re_js root =
1098210985
| Some (Arr {content = x}) -> Set_string.of_list (Bsb_build_util.get_list_string x )
1098310986
| Some _
1098410987
| None -> Set_string.empty
10985-
in
10988+
in
10989+
let gentype_language =
10990+
match Map_string.find_opt map Bsb_build_schemas.language with
10991+
| None -> ""
10992+
| Some (Str {str}) -> str
10993+
| Some _ -> ""
10994+
in
1098610995
Ext_option.iter (Map_string.find_opt map Bsb_build_schemas.sources) begin fun config ->
1098710996
try (
1098810997
walk_sources { root ;
1098910998
traverse = true;
1099010999
cwd = Filename.current_dir_name;
10991-
ignored_dirs
11000+
ignored_dirs;
11001+
gentype_language;
1099211002
} config
1099311003
) with _ -> ()
1099411004
end

0 commit comments

Comments
 (0)