@@ -28,17 +28,42 @@ let findNameSpace cmt =
28
28
cmt |> Filename. basename |> (Filename. chop_extension [@ doesNotRaise])
29
29
|> keepAfterDash
30
30
31
- let getOutputFileRelative ~config cmt =
32
- (cmt |> handleNamespace) ^ ModuleExtension. tsInputFileSuffix ~config
31
+ let remove_project_root_from_absolute_path ~(config : Config.t ) source_path =
32
+ let i = String. length config.projectRoot + 1 in
33
+ let n = String. length source_path - i in
34
+ (String. sub source_path i n [@ doesNotRaise])
33
35
34
- let getOutputFile ~(config : Config.t ) cmt =
35
- Filename. concat config.projectRoot (getOutputFileRelative ~config cmt)
36
+ let getOutputFileRelative ~config source_path =
37
+ if Filename. is_relative source_path then
38
+ (source_path |> handleNamespace) ^ ModuleExtension. tsInputFileSuffix ~config
39
+ else
40
+ let relative_path =
41
+ remove_project_root_from_absolute_path ~config source_path
42
+ in
43
+ (relative_path |> handleNamespace)
44
+ ^ ModuleExtension. tsInputFileSuffix ~config
45
+
46
+ let getOutputFile ~(config : Config.t ) sourcePath =
47
+ if Filename. is_relative sourcePath then
48
+ (* assuming a relative path from the project root *)
49
+ Filename. concat config.projectRoot
50
+ (getOutputFileRelative ~config sourcePath)
51
+ else
52
+ (* we want to place the output beside the source file *)
53
+ let relative_path =
54
+ remove_project_root_from_absolute_path ~config sourcePath
55
+ in
56
+ Filename. concat config.projectRoot
57
+ (getOutputFileRelative ~config relative_path)
36
58
37
59
let getModuleName cmt =
38
60
cmt |> handleNamespace |> Filename. basename |> ModuleName. fromStringUnsafe
39
61
40
62
let getCmtFile cmt =
41
- let pathCmt = Filename. concat (Sys. getcwd () ) cmt in
63
+ let pathCmt =
64
+ if Filename. is_relative cmt then Filename. concat (Sys. getcwd () ) cmt
65
+ else cmt
66
+ in
42
67
let cmtFile =
43
68
if Filename. check_suffix pathCmt " .cmt" then
44
69
let pathCmtLowerCase =
0 commit comments