Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rescript.json #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions src/Paths.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
open Common
module StringMap = Map.Make (String)

let bsconfig = "bsconfig.json"
let bsconfigs = ["bsconfig.json"; "rescript.json"]

let rec string_of_bsconfigs = function
| [] -> ""
| [x] -> x
| x :: xs -> x ^ " | " ^ string_of_bsconfigs xs

let readFile filename =
try
Expand All @@ -13,13 +18,17 @@ let readFile filename =
with _ -> None

let rec findProjectRoot ~dir =
let bsconfigFile = Filename.concat dir bsconfig in
if Sys.file_exists bsconfigFile then dir
let bsconfigFile =
bsconfigs |> List.map (fun config -> Filename.concat dir config)
in
if bsconfigFile |> List.exists (fun file -> Sys.file_exists file) then dir
else
let parent = dir |> Filename.dirname in
if parent = dir then (
prerr_endline
("Error: cannot find project root containing " ^ bsconfig ^ ".");
("Error: cannot find project root containing ("
^ string_of_bsconfigs bsconfigs
^ ").");
assert false)
else findProjectRoot ~dir:parent

Expand Down Expand Up @@ -73,21 +82,26 @@ module Config = struct
(* Read the config from bsconfig.json and apply it to runConfig and suppress and unsuppress *)
let processBsconfig () =
Lazy.force setReScriptProjectRoot;
let bsconfigFile = Filename.concat runConfig.projectRoot bsconfig in
match readFile bsconfigFile with
| None -> ()
| Some text -> (
match Json.parse text with
| None -> ()
| Some json -> (
match Json.get "reanalyze" json with
| Some conf ->
readSuppress conf;
readUnsuppress conf;
readAnalysis conf
| None ->
(* if no "analysis" specified, default to dce *)
RunConfig.dce ()))
let rec process = function
| [] -> ()
| bsconfig :: rest -> (
let bsconfigFile = Filename.concat runConfig.projectRoot bsconfig in
match readFile bsconfigFile with
| None -> process rest
| Some text -> (
match Json.parse text with
| None -> ()
| Some json -> (
match Json.get "reanalyze" json with
| Some conf ->
readSuppress conf;
readUnsuppress conf;
readAnalysis conf
| None ->
(* if no "analysis" specified, default to dce *)
RunConfig.dce ())))
in
process bsconfigs
end

(**
Expand Down
Loading