Skip to content

Commit 5d67c6a

Browse files
committed
migrate .resi files as well
1 parent debe9db commit 5d67c6a

File tree

6 files changed

+71
-3
lines changed

6 files changed

+71
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Implementation to satisfy interface build for tests */
2+
3+
external arr: array<int> = "arr"
4+
external reT: RegExp.t = "re"
5+
external json: JSON.t = "json"
6+
external nestedArr: array<RegExp.t> = "nestedArr"
7+
8+
external useSet: Set.t<int> => unit = "useSet"
9+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* Migration tests for interface (.resi) files using stdlib deprecations */
2+
3+
// Type alias migrations exercised via externals
4+
external arr: JSON.t<int> = "arr"
5+
external reT: Js.Re.t = "re"
6+
external json: Js.Json.t = "json"
7+
external nestedArr: Js.Array.t<Js.Re.t> = "nestedArr"
8+
9+
// Function type using a deprecated alias
10+
external useSet: Js.Set.t<int> => unit = "useSet"
11+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* Implementation to satisfy interface build for tests */
2+
3+
external arr: Js.Array.t<int> = "arr"
4+
external reT: Js.Re.t = "re"
5+
external json: Js.Json.t = "json"
6+
external nestedArr: Js.Array.t<Js.Re.t> = "nestedArr"
7+
8+
external useSet: Js.Set.t<int> => unit = "useSet"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* Migration tests for interface (.resi) files using stdlib deprecations */
2+
3+
// Type alias migrations exercised via externals
4+
external arr: Js.Array.t<int> = "arr"
5+
external reT: Js.Re.t = "re"
6+
external json: Js.Json.t = "json"
7+
external nestedArr: Js.Array.t<Js.Re.t> = "nestedArr"
8+
9+
// Function type using a deprecated alias
10+
external useSet: Js.Set.t<int> => unit = "useSet"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is autogenerated so it can be type checked.
2+
// It's the migrated version of src/migrate/StdlibMigration_Interface.res.
3+
/* Implementation to satisfy interface build for tests */
4+
5+
external arr: array<int> = "arr"
6+
external reT: RegExp.t = "re"
7+
external json: JSON.t = "json"
8+
external nestedArr: array<RegExp.t> = "nestedArr"
9+
10+
external useSet: Set.t<int> => unit = "useSet"

tools/src/migrate.ml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,29 @@ let migrate ~entryPointFile ~outputMode =
703703
let {Res_driver.parsetree = signature; comments; source} =
704704
parser ~filename:path
705705
in
706-
let mapper = makeMapper [] in
707-
let astMapped = mapper.signature mapper signature in
708-
Ok (Res_printer.print_interface astMapped ~comments, source)
706+
(* Load cmti/cmt info to obtain deprecation migration templates, just like .res *)
707+
match
708+
(* Prefer implementation cmt info when available, since cmti may not
709+
record deprecated usages. Fallback to cmti if needed. *)
710+
let impl_path =
711+
if Filename.check_suffix path ".resi" then
712+
Filename.chop_suffix path ".resi" ^ ".res"
713+
else path
714+
in
715+
match Cmt.loadCmtInfosFromPath ~path:impl_path with
716+
| Some infos -> Some infos
717+
| None -> Cmt.loadCmtInfosFromPath ~path
718+
with
719+
| None ->
720+
Error
721+
(Printf.sprintf
722+
"error: failed to run migration for %s because build artifacts \
723+
could not be found. try to build the project"
724+
path)
725+
| Some {cmt_extra_info = {deprecated_used}} ->
726+
let mapper = makeMapper deprecated_used in
727+
let astMapped = mapper.signature mapper signature in
728+
Ok (Res_printer.print_interface astMapped ~comments, source)
709729
else
710730
Error
711731
(Printf.sprintf

0 commit comments

Comments
 (0)