diff --git a/packages/ppx/src/main.re b/packages/ppx/src/main.re index 569716483..e71474673 100644 --- a/packages/ppx/src/main.re +++ b/packages/ppx/src/main.re @@ -353,8 +353,6 @@ let static_pattern = ) ); -let compatibleModeWithBsEmotionPpx = Config.getArgsBeforeConfigLoaded(); - module Mapper = { let match = module_expr => { open Ast_pattern; @@ -736,7 +734,7 @@ Driver.register_transformation( ), Context_free.Rule.extension( Extension.declare( - compatibleModeWithBsEmotionPpx ? "css_" : "css", + Config.compatibleModeWithBsEmotionPpx() ? "css_" : "css", Extension.Context.Expression, string_payload, (~loc as _, ~path as _, payload, _label, _) => { diff --git a/packages/ppx/src/ppx_config.re b/packages/ppx/src/ppx_config.re index fb277b9de..a7ee16b56 100644 --- a/packages/ppx/src/ppx_config.re +++ b/packages/ppx/src/ppx_config.re @@ -1,5 +1,3 @@ -exception ConfigNotFound; - type t = { compatibleModeWithBsEmotionPpx: bool, production: bool, @@ -14,24 +12,18 @@ let value = ref(None); let set = config => value := Some(config); let setDefault = () => set(default); -let getUnsafe = () => { - switch (value^) { - | Some(v) => v - | None => raise(ConfigNotFound) - } -}; +let get = () => value^ let update = fn => value := value^ |> Option.map(fn); let updateCompatibleModeWithBsEmotionPpx = bool => { - let config = getUnsafe(); - set({ ...config, compatibleModeWithBsEmotionPpx: bool }) + get() + |> Option.map(config => set({ ...config, compatibleModeWithBsEmotionPpx: bool })) + |> Option.value(~default=()) }; -let compatibleModeWithBsEmotionPpx = () => - getUnsafe().compatibleModeWithBsEmotionPpx; - -let find = (name, args) => args |> Array.to_list |> List.find_opt(a => a == name); -let getArgsBeforeConfigLoaded = () => { - Sys.argv |> find("--compat-with-bs-emotion-ppx") |> Option.is_some; -}; +let compatibleModeWithBsEmotionPpx = () => { + get() + |> Option.map(c => c.compatibleModeWithBsEmotionPpx) + |> Option.value(~default=default.compatibleModeWithBsEmotionPpx) +}