@@ -29,17 +29,43 @@ let find_name_space cmt =
29
29
cmt |> Filename. basename |> (Filename. chop_extension [@ doesNotRaise])
30
30
|> keep_after_dash
31
31
32
- let get_output_file_relative ~config cmt =
33
- (cmt |> handle_namespace) ^ ModuleExtension. ts_input_file_suffix ~config
32
+ let remove_project_root_from_absolute_path ~(config : Config.t ) source_path =
33
+ let i = String. length config.project_root + 1 in
34
+ let n = String. length source_path - i in
35
+ (String. sub source_path i n [@ doesNotRaise])
34
36
35
- let get_output_file ~(config : Config.t ) cmt =
36
- Filename. concat config.project_root (get_output_file_relative ~config cmt)
37
+ let get_output_file_relative ~config source_path =
38
+ if Filename. is_relative source_path then
39
+ (source_path |> handle_namespace)
40
+ ^ ModuleExtension. ts_input_file_suffix ~config
41
+ else
42
+ let relative_path =
43
+ remove_project_root_from_absolute_path ~config source_path
44
+ in
45
+ (relative_path |> handle_namespace)
46
+ ^ ModuleExtension. ts_input_file_suffix ~config
47
+
48
+ let get_output_file ~(config : Config.t ) sourcePath =
49
+ if Filename. is_relative sourcePath then
50
+ (* assuming a relative path from the project root *)
51
+ Filename. concat config.project_root
52
+ (get_output_file_relative ~config sourcePath)
53
+ else
54
+ (* we want to place the output beside the source file *)
55
+ let relative_path =
56
+ remove_project_root_from_absolute_path ~config sourcePath
57
+ in
58
+ Filename. concat config.project_root
59
+ (get_output_file_relative ~config relative_path)
37
60
38
61
let get_module_name cmt =
39
62
cmt |> handle_namespace |> Filename. basename |> ModuleName. from_string_unsafe
40
63
41
64
let get_cmt_file cmt =
42
- let path_cmt = Filename. concat (Sys. getcwd () ) cmt in
65
+ let path_cmt =
66
+ if Filename. is_relative cmt then Filename. concat (Sys. getcwd () ) cmt
67
+ else cmt
68
+ in
43
69
let cmt_file =
44
70
if Filename. check_suffix path_cmt " .cmt" then
45
71
let path_cmt_lower_case =
0 commit comments