Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 3 additions & 9 deletions analysis/reanalyze/src/Paths.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module StringMap = Map_string

let bsconfig = "bsconfig.json"
let rescriptJson = "rescript.json"

let readFile filename =
Expand All @@ -14,8 +13,7 @@ let readFile filename =

let rec findProjectRoot ~dir =
let rescriptJsonFile = Filename.concat dir rescriptJson in
let bsconfigFile = Filename.concat dir bsconfig in
if Sys.file_exists rescriptJsonFile || Sys.file_exists bsconfigFile then dir
if Sys.file_exists rescriptJsonFile then dir
else
let parent = dir |> Filename.dirname in
if parent = dir then (
Expand Down Expand Up @@ -83,10 +81,9 @@ module Config = struct
| _ -> ()

(* Read the config from rescript.json and apply it to runConfig and suppress and unsuppress *)
let processBsconfig () =
let processConfig () =
Lazy.force setReScriptProjectRoot;
let rescriptFile = Filename.concat runConfig.projectRoot rescriptJson in
let bsconfigFile = Filename.concat runConfig.projectRoot bsconfig in

let processText text =
match Json.parse text with
Expand All @@ -105,10 +102,7 @@ module Config = struct

match readFile rescriptFile with
| Some text -> processText text
| None -> (
match readFile bsconfigFile with
| Some text -> processText text
| None -> ())
| None -> ()
end

(**
Expand Down
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/Reanalyze.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ let cli () =
cmtRootRef := cmtRoot;
analysisKindSet := true
and setConfig () =
Paths.Config.processBsconfig ();
Paths.Config.processConfig ();
analysisKindSet := true
and setDCE cmtRoot =
RunConfig.dce ();
Expand Down
6 changes: 1 addition & 5 deletions analysis/src/FindFiles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ let findDependencyFiles base config =
(ModuleResolution.resolveNodeModulePath ~startPath:base name)
(fun path ->
let rescriptJsonPath = path /+ "rescript.json" in
let bsconfigJsonPath = path /+ "bsconfig.json" in

let parseText text =
match Json.parse text with
Expand Down Expand Up @@ -272,10 +271,7 @@ let findDependencyFiles base config =

match Files.readFile rescriptJsonPath with
| Some text -> parseText text
| None -> (
match Files.readFile bsconfigJsonPath with
| Some text -> parseText text
| None -> None))
| None -> None)
in

match result with
Expand Down
15 changes: 4 additions & 11 deletions analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ let getReScriptVersion () =

let newBsPackage ~rootPath =
let rescriptJson = Filename.concat rootPath "rescript.json" in
let bsconfigJson = Filename.concat rootPath "bsconfig.json" in

let parseRaw raw =
let libBs =
Expand Down Expand Up @@ -192,23 +191,17 @@ let newBsPackage ~rootPath =

match Files.readFile rescriptJson with
| Some raw -> parseRaw raw
| None -> (
| None ->
Log.log ("Unable to read " ^ rescriptJson);
match Files.readFile bsconfigJson with
| Some raw -> parseRaw raw
| None ->
Log.log ("Unable to read " ^ bsconfigJson);
None)
None

let findRoot ~uri packagesByRoot =
let path = Uri.toPath uri in
let rec loop path =
if path = "/" then None
else if Hashtbl.mem packagesByRoot path then Some (`Root path)
else if
Files.exists (Filename.concat path "rescript.json")
|| Files.exists (Filename.concat path "bsconfig.json")
then Some (`Bs path)
else if Files.exists (Filename.concat path "rescript.json") then
Some (`Bs path)
else
let parent = Filename.dirname path in
if parent = path then (* reached root *) None else loop parent
Expand Down
6 changes: 1 addition & 5 deletions cli/common/bsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ function watch(args) {
let webSocketHost = "localhost";
let webSocketPort = 9999;

let resConfig = "rescript.json";
if (!fs.existsSync(resConfig)) {
resConfig = "bsconfig.json";
}

const resConfig = "rescript.json";
const sourcedirs = path.join("lib", "bs", ".sourcedirs.json");

let LAST_SUCCESS_BUILD_STAMP = 0;
Expand Down
4 changes: 1 addition & 3 deletions compiler/bsb/bsb_build_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ let pp_packages_rev ppf lst =

let rec walk_all_deps_aux (visited : string Hash_string.t) (paths : string list)
~(top : top) (dir : string) (queue : _ Queue.t) =
match
Bsb_config_load.load_json ~per_proj_dir:dir ~warn_legacy_config:false
with
match Bsb_config_load.load_json ~per_proj_dir:dir with
| _, Obj {map; loc} ->
let cur_package_name =
match Map_string.find_opt map Bsb_build_schemas.name with
Expand Down
21 changes: 4 additions & 17 deletions compiler/bsb/bsb_config_load.ml
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
let ( // ) = Ext_path.combine

let load_json ~(per_proj_dir : string) ~(warn_legacy_config : bool) :
string * Ext_json_types.t =
let filename, abs, in_chan =
let filename = Literals.rescript_json in
let abs = per_proj_dir // filename in
match open_in abs with
| in_chan -> (filename, abs, in_chan)
| exception e -> (
let filename = Literals.bsconfig_json in
let abs = per_proj_dir // filename in
match open_in abs with
| in_chan -> (filename, abs, in_chan)
| exception _ -> raise e (* forward error from rescript.json *))
in
if warn_legacy_config && filename = Literals.bsconfig_json then
print_endline
"Warning: bsconfig.json is deprecated. Migrate it to rescript.json\n";
let load_json ~(per_proj_dir : string) : string * Ext_json_types.t =
let filename = Literals.rescript_json in
let abs = per_proj_dir // filename in
let in_chan = open_in abs in
match Ext_json_parse.parse_json_from_chan abs in_chan with
| v ->
close_in in_chan;
Expand Down
3 changes: 1 addition & 2 deletions compiler/bsb/bsb_config_load.mli
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
val load_json :
per_proj_dir:string -> warn_legacy_config:bool -> string * Ext_json_types.t
val load_json : per_proj_dir:string -> string * Ext_json_types.t
4 changes: 1 addition & 3 deletions compiler/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ let interpret_json ~(filename : string) ~(json : Ext_json_types.t)

let deps_from_bsconfig () =
let cwd = Bsb_global_paths.cwd in
match
Bsb_config_load.load_json ~per_proj_dir:cwd ~warn_legacy_config:false
with
match Bsb_config_load.load_json ~per_proj_dir:cwd with
| _, Obj {map} -> (Bsb_package_specs.from_map ~cwd map, Bsb_jsx.from_map map)
| _, _ -> assert false
6 changes: 2 additions & 4 deletions compiler/bsb/bsb_ninja_regen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ let ( // ) = Ext_path.combine
otherwise return Some info
*)
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
~warn_legacy_config ~warn_as_error : Bsb_config_types.t option =
~warn_as_error : Bsb_config_types.t option =
let lib_artifacts_dir = Bsb_config.lib_bs in
let lib_bs_dir = per_proj_dir // lib_artifacts_dir in
let output_deps = lib_bs_dir // bsdeps in
let check_result =
Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~warn_as_error
~file:output_deps
in
let config_filename, config_json =
Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config
in
let config_filename, config_json = Bsb_config_load.load_json ~per_proj_dir in
match check_result with
| Good -> None (* Fast path, no need regenerate ninja *)
| Bsb_forced | Bsb_bsc_version_mismatch | Bsb_package_kind_inconsistent
Expand Down
1 change: 0 additions & 1 deletion compiler/bsb/bsb_ninja_regen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ val regenerate_ninja :
package_kind:Bsb_package_kind.t ->
forced:bool ->
per_proj_dir:string ->
warn_legacy_config:bool ->
warn_as_error:string option ->
Bsb_config_types.t option
(** Regenerate ninja file by need based on [.bsdeps]
Expand Down
2 changes: 1 addition & 1 deletion compiler/bsb/bsb_parse_sources.ml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ and walk_source_dir_map (cxt : walk_cxt) sub_dirs_field =
let clean_re_js root =
match
Ext_json_parse.parse_json_from_file
(Filename.concat root Literals.bsconfig_json)
(Filename.concat root Literals.rescript_json)
with
| Obj {map} ->
let ignored_dirs =
Expand Down
3 changes: 1 addition & 2 deletions compiler/bsb/bsb_world.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
let _config : _ option =
Bsb_ninja_regen.regenerate_ninja
~package_kind:(Dependency {package_specs; jsx})
~per_proj_dir:proj_dir ~forced:false ~warn_legacy_config:false
~warn_as_error:None
~per_proj_dir:proj_dir ~forced:false ~warn_as_error:None
in
let command =
{Bsb_unix.cmd = vendor_ninja; cwd = lib_bs_dir; args}
Expand Down
8 changes: 3 additions & 5 deletions compiler/bsb_exe/rescript_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ let build_subcommand ~start argv argv_len =
let config_opt =
Bsb_ninja_regen.regenerate_ninja ~package_kind:Toplevel
~per_proj_dir:Bsb_global_paths.cwd ~forced:!force_regenerate
~warn_legacy_config:true ~warn_as_error
~warn_as_error
in
if not !no_deps_mode then
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
Expand Down Expand Up @@ -204,8 +204,7 @@ let info_subcommand ~start argv =
if !list_files then
match
Bsb_ninja_regen.regenerate_ninja ~package_kind:Toplevel
~per_proj_dir:Bsb_global_paths.cwd ~forced:true
~warn_legacy_config:true ~warn_as_error:None
~per_proj_dir:Bsb_global_paths.cwd ~forced:true ~warn_as_error:None
with
| None -> assert false
| Some {file_groups = {files}} ->
Expand All @@ -229,8 +228,7 @@ let () =
(* specialize this path which is used in watcher *)
let config_opt =
Bsb_ninja_regen.regenerate_ninja ~package_kind:Toplevel
~per_proj_dir:Bsb_global_paths.cwd ~forced:false
~warn_legacy_config:true ~warn_as_error:None
~per_proj_dir:Bsb_global_paths.cwd ~forced:false ~warn_as_error:None
in
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
ninja_command_exit [||])
Expand Down
3 changes: 1 addition & 2 deletions compiler/ext/ext_path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ let rec find_root_filename ~cwd filenames =
Ext_fmt.failwithf ~loc:__LOC__ "%s not found from %s" (List.hd filenames)
cwd

let find_config_dir cwd =
find_root_filename ~cwd [Literals.rescript_json; Literals.bsconfig_json]
let find_config_dir cwd = find_root_filename ~cwd [Literals.rescript_json]

let package_dir = lazy (find_config_dir (Lazy.force cwd))
2 changes: 0 additions & 2 deletions compiler/ext/literals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ let node_modules_length = String.length "node_modules"

let package_json = "package.json"

let bsconfig_json = "bsconfig.json"

let rescript_json = "rescript.json"

let build_ninja = "build.ninja"
Expand Down
8 changes: 2 additions & 6 deletions compiler/gentype/GenTypeConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,9 @@ let set_debug ~gtconf =
| _ -> ()

let compiler_config_file = "rescript.json"
let legacy_compiler_config_file = "bsconfig.json"

let rec find_project_root ~dir =
if
Sys.file_exists (Filename.concat dir compiler_config_file)
|| Sys.file_exists (Filename.concat dir legacy_compiler_config_file)
then dir
if Sys.file_exists (Filename.concat dir compiler_config_file) then dir
else
let parent = dir |> Filename.dirname in
if parent = dir then (
Expand Down Expand Up @@ -184,7 +180,7 @@ let read_config ~get_config_file ~namespace =
| Some external_stdlib -> external_stdlib
in
if !Debug.config then (
Log_.item "Project roLiterals.bsconfig_jsonot: %s\n" project_root;
Log_.item "Project roLiterals.rescript_jsonot: %s\n" project_root;
if bsb_project_root <> project_root then
Log_.item "bsb project root: %s\n" bsb_project_root;
Log_.item "Config module:%s shims:%d entries \n"
Expand Down
6 changes: 1 addition & 5 deletions compiler/gentype/Paths.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ let get_config_file ~project_root =
let config = concat project_root Config.compiler_config_file in
match config |> Sys.file_exists with
| true -> Some config
| false -> (
let config = concat project_root Config.legacy_compiler_config_file in
match config |> Sys.file_exists with
| true -> Some config
| false -> None)
| false -> None

let read_config ~namespace = Config.read_config ~get_config_file ~namespace
2 changes: 1 addition & 1 deletion rewatch/CompilerConfigurationSpec.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## ReScript build configuration

This document contains a list of all bsconfig parameters with remarks, and whether they are already implemented in rewatch. It is based on https://rescript-lang.org/docs/manual/latest/build-configuration-schema.
This document contains a list of all config parameters with remarks, and whether they are already implemented in rewatch. It is based on https://rescript-lang.org/docs/manual/latest/build-configuration-schema.

| Parameter | JSON type | Remark | Implemented? |
| --------------------- | ----------------------- | ------ | :----------: |
Expand Down
8 changes: 1 addition & 7 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,7 @@ fn get_source_dirs(source: config::Source, sub_path: Option<PathBuf>) -> AHashSe

pub fn read_config(package_dir: &Path) -> Result<Config> {
let rescript_json_path = package_dir.join("rescript.json");
let bsconfig_json_path = package_dir.join("bsconfig.json");

if Path::new(&rescript_json_path).exists() {
Config::new(&rescript_json_path)
} else {
Config::new(&bsconfig_json_path)
}
Config::new(&rescript_json_path)
}

pub fn read_dependency(
Expand Down
2 changes: 1 addition & 1 deletion rewatch/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ pub fn compute_file_hash(path: &Path) -> Option<blake3::Hash> {
}

fn has_rescript_config(path: &Path) -> bool {
path.join("bsconfig.json").exists() || path.join("rescript.json").exists()
path.join("rescript.json").exists()
}

// traverse up the directory tree until we find a config.json, if not return None
Expand Down
8 changes: 0 additions & 8 deletions tests/build_tests/warn_legacy_config/bsconfig.json

This file was deleted.

12 changes: 0 additions & 12 deletions tests/build_tests/warn_legacy_config/input.js

This file was deleted.

1 change: 0 additions & 1 deletion tests/build_tests/warn_legacy_config/src/demo.res

This file was deleted.

2 changes: 1 addition & 1 deletion tools/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ let main () =
(Error
(Printf.sprintf
"error: failed to load ReScript project at %s (missing \
bsconfig.json/rescript.json?)"
rescript.json?)"
rootPath))
| Some package ->
let moduleNames =
Expand Down
Loading