Skip to content

Commit 3356ffa

Browse files
committed
Do not use regex to figure out package name
1 parent eba0f1c commit 3356ffa

File tree

3 files changed

+36
-39
lines changed

3 files changed

+36
-39
lines changed

jscomp/bsb/bsb_pkg.ml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,19 @@ let custom_resolution = lazy
9292
| exception Not_found -> false
9393
| "true" -> true
9494
| _ -> false)
95-
9695

97-
let regex_at = Str.regexp "@"
98-
let regex_unders = Str.regexp "_+"
99-
let regex_slash = Str.regexp "\\/"
100-
let regex_dot = Str.regexp "\\."
101-
let regex_hyphen = Str.regexp "-"
102-
let pkg_name_as_variable pkg =
103-
Bsb_pkg_types.to_string pkg
104-
|> Str.replace_first regex_at ""
105-
|> Str.global_replace regex_unders "\\0_"
106-
|> Str.global_replace regex_slash "__slash__"
107-
|> Str.global_replace regex_dot "__dot__"
108-
|> Str.global_replace regex_hyphen "_"
96+
let pkg_name_as_variable package =
97+
Bsb_pkg_types.to_string package
98+
|> fun s -> Ext_string.split s '@'
99+
|> String.concat ""
100+
|> fun s -> Ext_string.split s '_'
101+
|> String.concat "__"
102+
|> fun s -> Ext_string.split s '/'
103+
|> String.concat "__slash__"
104+
|> fun s -> Ext_string.split s '.'
105+
|> String.concat "__dot__"
106+
|> fun s -> Ext_string.split s '-'
107+
|> String.concat "_"
109108

110109
(** TODO: collect all warnings and print later *)
111110
let resolve_bs_package ~cwd (package : t) =

lib/4.02.3/bsb.ml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8558,20 +8558,19 @@ let custom_resolution = lazy
85588558
| exception Not_found -> false
85598559
| "true" -> true
85608560
| _ -> false)
8561-
85628561

8563-
let regex_at = Str.regexp "@"
8564-
let regex_unders = Str.regexp "_+"
8565-
let regex_slash = Str.regexp "\\/"
8566-
let regex_dot = Str.regexp "\\."
8567-
let regex_hyphen = Str.regexp "-"
8568-
let pkg_name_as_variable pkg =
8569-
Bsb_pkg_types.to_string pkg
8570-
|> Str.replace_first regex_at ""
8571-
|> Str.global_replace regex_unders "\\0_"
8572-
|> Str.global_replace regex_slash "__slash__"
8573-
|> Str.global_replace regex_dot "__dot__"
8574-
|> Str.global_replace regex_hyphen "_"
8562+
let pkg_name_as_variable package =
8563+
Bsb_pkg_types.to_string package
8564+
|> fun s -> Ext_string.split s '@'
8565+
|> String.concat ""
8566+
|> fun s -> Ext_string.split s '_'
8567+
|> String.concat "__"
8568+
|> fun s -> Ext_string.split s '/'
8569+
|> String.concat "__slash__"
8570+
|> fun s -> Ext_string.split s '.'
8571+
|> String.concat "__dot__"
8572+
|> fun s -> Ext_string.split s '-'
8573+
|> String.concat "_"
85758574

85768575
(** TODO: collect all warnings and print later *)
85778576
let resolve_bs_package ~cwd (package : t) =

lib/4.06.1/bsb.ml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8528,20 +8528,19 @@ let custom_resolution = lazy
85288528
| exception Not_found -> false
85298529
| "true" -> true
85308530
| _ -> false)
8531-
85328531

8533-
let regex_at = Str.regexp "@"
8534-
let regex_unders = Str.regexp "_+"
8535-
let regex_slash = Str.regexp "\\/"
8536-
let regex_dot = Str.regexp "\\."
8537-
let regex_hyphen = Str.regexp "-"
8538-
let pkg_name_as_variable pkg =
8539-
Bsb_pkg_types.to_string pkg
8540-
|> Str.replace_first regex_at ""
8541-
|> Str.global_replace regex_unders "\\0_"
8542-
|> Str.global_replace regex_slash "__slash__"
8543-
|> Str.global_replace regex_dot "__dot__"
8544-
|> Str.global_replace regex_hyphen "_"
8532+
let pkg_name_as_variable package =
8533+
Bsb_pkg_types.to_string package
8534+
|> fun s -> Ext_string.split s '@'
8535+
|> String.concat ""
8536+
|> fun s -> Ext_string.split s '_'
8537+
|> String.concat "__"
8538+
|> fun s -> Ext_string.split s '/'
8539+
|> String.concat "__slash__"
8540+
|> fun s -> Ext_string.split s '.'
8541+
|> String.concat "__dot__"
8542+
|> fun s -> Ext_string.split s '-'
8543+
|> String.concat "_"
85458544

85468545
(** TODO: collect all warnings and print later *)
85478546
let resolve_bs_package ~cwd (package : t) =

0 commit comments

Comments
 (0)