Skip to content

Commit 0d64eb7

Browse files
committed
When cleaning generated files, read language from gentypeconfig to determine the file extension.
In case the language is "typescript", remove .gen.js or .gen.tsx. Fixes #4417.
1 parent fef665e commit 0d64eb7

File tree

9 files changed

+56
-58
lines changed

9 files changed

+56
-58
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
@@ -425,6 +425,7 @@ type walk_cxt = {
425425
root : string;
426426
traverse : bool;
427427
ignored_dirs : Set_string.t;
428+
gentype_language: string;
428429
}
429430

430431
let rec walk_sources (cxt : walk_cxt) (sources : Ext_json_types.t) =
@@ -452,10 +453,11 @@ and walk_source_dir_map (cxt : walk_cxt) sub_dirs_field =
452453
let working_dir = Filename.concat cxt.root cxt.cwd in
453454
if not (Set_string.mem cxt.ignored_dirs cxt.cwd) then begin
454455
let file_array = Sys.readdir working_dir in
455-
(* Remove .re.js when clean up *)
456-
Ext_array.iter file_array begin fun file ->
457-
if Ext_string.ends_with file Literals.suffix_gen_js
458-
|| Ext_string.ends_with file Literals.suffix_gen_tsx
456+
(* Remove .gen.js/.gen.tsx during clean up *)
457+
Ext_array.iter file_array begin fun file ->
458+
let is_typescript = cxt.gentype_language = "typescript" in
459+
if ((not is_typescript) && Ext_string.ends_with file Literals.suffix_gen_js)
460+
|| (is_typescript && Ext_string.ends_with file Literals.suffix_gen_tsx)
459461
then
460462
Sys.remove (Filename.concat working_dir file)
461463
end;
@@ -490,13 +492,20 @@ let clean_re_js root =
490492
| Some (Arr {content = x}) -> Set_string.of_list (Bsb_build_util.get_list_string x )
491493
| Some _
492494
| None -> Set_string.empty
493-
in
495+
in
496+
let gentype_language =
497+
match Map_string.find_opt map Bsb_build_schemas.language with
498+
| None -> ""
499+
| Some (Str {str}) -> str
500+
| Some _ -> ""
501+
in
494502
Ext_option.iter (Map_string.find_opt map Bsb_build_schemas.sources) begin fun config ->
495503
try (
496504
walk_sources { root ;
497505
traverse = true;
498506
cwd = Filename.current_dir_name;
499-
ignored_dirs
507+
ignored_dirs;
508+
gentype_language;
500509
} config
501510
) with _ -> ()
502511
end

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 1 addition & 5 deletions
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 1 addition & 5 deletions
Large diffs are not rendered by default.

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

@@ -10977,6 +10978,7 @@ type walk_cxt = {
1097710978
root : string;
1097810979
traverse : bool;
1097910980
ignored_dirs : Set_string.t;
10981+
gentype_language: string;
1098010982
}
1098110983

1098210984
let rec walk_sources (cxt : walk_cxt) (sources : Ext_json_types.t) =
@@ -11004,10 +11006,11 @@ and walk_source_dir_map (cxt : walk_cxt) sub_dirs_field =
1100411006
let working_dir = Filename.concat cxt.root cxt.cwd in
1100511007
if not (Set_string.mem cxt.ignored_dirs cxt.cwd) then begin
1100611008
let file_array = Sys.readdir working_dir in
11007-
(* Remove .re.js when clean up *)
11008-
Ext_array.iter file_array begin fun file ->
11009-
if Ext_string.ends_with file Literals.suffix_gen_js
11010-
|| Ext_string.ends_with file Literals.suffix_gen_tsx
11009+
(* Remove .gen.js/.gen.tsx during clean up *)
11010+
Ext_array.iter file_array begin fun file ->
11011+
let is_typescript = cxt.gentype_language = "typescript" in
11012+
if ((not is_typescript) && Ext_string.ends_with file Literals.suffix_gen_js)
11013+
|| (is_typescript && Ext_string.ends_with file Literals.suffix_gen_tsx)
1101111014
then
1101211015
Sys.remove (Filename.concat working_dir file)
1101311016
end;
@@ -11042,13 +11045,20 @@ let clean_re_js root =
1104211045
| Some (Arr {content = x}) -> Set_string.of_list (Bsb_build_util.get_list_string x )
1104311046
| Some _
1104411047
| None -> Set_string.empty
11045-
in
11048+
in
11049+
let gentype_language =
11050+
match Map_string.find_opt map Bsb_build_schemas.language with
11051+
| None -> ""
11052+
| Some (Str {str}) -> str
11053+
| Some _ -> ""
11054+
in
1104611055
Ext_option.iter (Map_string.find_opt map Bsb_build_schemas.sources) begin fun config ->
1104711056
try (
1104811057
walk_sources { root ;
1104911058
traverse = true;
1105011059
cwd = Filename.current_dir_name;
11051-
ignored_dirs
11060+
ignored_dirs;
11061+
gentype_language;
1105211062
} config
1105311063
) with _ -> ()
1105411064
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

@@ -11009,6 +11010,7 @@ type walk_cxt = {
1100911010
root : string;
1101011011
traverse : bool;
1101111012
ignored_dirs : Set_string.t;
11013+
gentype_language: string;
1101211014
}
1101311015

1101411016
let rec walk_sources (cxt : walk_cxt) (sources : Ext_json_types.t) =
@@ -11036,10 +11038,11 @@ and walk_source_dir_map (cxt : walk_cxt) sub_dirs_field =
1103611038
let working_dir = Filename.concat cxt.root cxt.cwd in
1103711039
if not (Set_string.mem cxt.ignored_dirs cxt.cwd) then begin
1103811040
let file_array = Sys.readdir working_dir in
11039-
(* Remove .re.js when clean up *)
11040-
Ext_array.iter file_array begin fun file ->
11041-
if Ext_string.ends_with file Literals.suffix_gen_js
11042-
|| Ext_string.ends_with file Literals.suffix_gen_tsx
11041+
(* Remove .gen.js/.gen.tsx during clean up *)
11042+
Ext_array.iter file_array begin fun file ->
11043+
let is_typescript = cxt.gentype_language = "typescript" in
11044+
if ((not is_typescript) && Ext_string.ends_with file Literals.suffix_gen_js)
11045+
|| (is_typescript && Ext_string.ends_with file Literals.suffix_gen_tsx)
1104311046
then
1104411047
Sys.remove (Filename.concat working_dir file)
1104511048
end;
@@ -11074,13 +11077,20 @@ let clean_re_js root =
1107411077
| Some (Arr {content = x}) -> Set_string.of_list (Bsb_build_util.get_list_string x )
1107511078
| Some _
1107611079
| None -> Set_string.empty
11077-
in
11080+
in
11081+
let gentype_language =
11082+
match Map_string.find_opt map Bsb_build_schemas.language with
11083+
| None -> ""
11084+
| Some (Str {str}) -> str
11085+
| Some _ -> ""
11086+
in
1107811087
Ext_option.iter (Map_string.find_opt map Bsb_build_schemas.sources) begin fun config ->
1107911088
try (
1108011089
walk_sources { root ;
1108111090
traverse = true;
1108211091
cwd = Filename.current_dir_name;
11083-
ignored_dirs
11092+
ignored_dirs;
11093+
gentype_language;
1108411094
} config
1108511095
) with _ -> ()
1108611096
end

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 2 additions & 10 deletions
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 2 additions & 10 deletions
Large diffs are not rendered by default.

lib/4.06.1/whole_compiler.ml

Lines changed: 2 additions & 10 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)