@@ -28,10 +28,14 @@ let findNameSpace cmt =
28
28
cmt |> Filename. basename |> (Filename. chop_extension [@ doesNotRaise])
29
29
|> keepAfterDash
30
30
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])
31
+ let removePathPrefix ~prefix path =
32
+ let normalizedPrefix = Filename. concat prefix " " in
33
+ let prefixLen = String. length normalizedPrefix in
34
+ let pathLen = String. length path in
35
+ let isPrefix =
36
+ prefixLen < = pathLen && String. sub path 0 prefixLen = normalizedPrefix
37
+ in
38
+ if isPrefix then String. sub path prefixLen (pathLen - prefixLen) else path
35
39
36
40
let appendSuffix ~config sourcePath =
37
41
(sourcePath |> handleNamespace) ^ ModuleExtension. tsInputFileSuffix ~config
@@ -40,7 +44,7 @@ let getOutputFileRelative ~config sourcePath =
40
44
if Filename. is_relative sourcePath then appendSuffix ~config sourcePath
41
45
else
42
46
let relative_path =
43
- remove_project_root_from_absolute_path ~ config sourcePath
47
+ removePathPrefix ~prefix: config.projectRoot sourcePath
44
48
in
45
49
appendSuffix ~config relative_path
46
50
@@ -54,7 +58,7 @@ let getOutputFile ~(config : Config.t) sourcePath =
54
58
else
55
59
(* for absolute paths we want to place the output beside the source file *)
56
60
let relative_path =
57
- remove_project_root_from_absolute_path ~ config sourcePath
61
+ removePathPrefix ~prefix: config.projectRoot sourcePath
58
62
in
59
63
computeAbsoluteOutputFilePath ~config relative_path
60
64
0 commit comments