diff --git a/jscomp/bsb/bsb_config_load.ml b/jscomp/bsb/bsb_config_load.ml index e947c920ed1..02556637631 100644 --- a/jscomp/bsb/bsb_config_load.ml +++ b/jscomp/bsb/bsb_config_load.ml @@ -17,8 +17,7 @@ let load_json ~(per_proj_dir : string) ~(warn_legacy_config : bool) | exception _ -> raise e (* forward error from rescript.json *) in if warn_legacy_config && filename = Literals.bsconfig_json then - (* TODO: warn legacy config *) - (); + print_endline "Warning: bsconfig.json is deprecated. Migrate it to rescript.json\n"; match Ext_json_parse.parse_json_from_chan abs in_chan with | v -> close_in in_chan ; (filename, v) diff --git a/jscomp/bsb/bsb_config_parse.ml b/jscomp/bsb/bsb_config_parse.ml index 1a6f654ba70..747a2b7e085 100644 --- a/jscomp/bsb/bsb_config_parse.ml +++ b/jscomp/bsb/bsb_config_parse.ml @@ -237,7 +237,11 @@ let extract_js_post_build (map : json_map) cwd : string option = (** ATT: make sure such function is re-entrant. With a given [cwd] it works anywhere*) -let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) ~(warn_legacy_config : bool) +let interpret_json + ~(filename : string) + ~(json : Ext_json_types.t) + ~(package_kind : Bsb_package_kind.t) + ~(per_proj_dir : string) : Bsb_config_types.t = (* we should not resolve it too early, since it is external configuration, no {!Bsb_build_util.convert_and_resolve_path} @@ -253,10 +257,9 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) 1. if [build.ninja] does use [ninja] we need set a variable 2. we need store it so that we can call ninja correctly *) - match - Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config + match json with - | filename, Obj { map } -> ( + | Obj { map } -> ( let package_name, namespace = extract_package_name_and_namespace map in let gentype_config = extract_gentype_config map in @@ -353,7 +356,7 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) } | None -> Bsb_exception.invalid_spec ("no sources specified in " ^ filename)) - | filename, _ -> Bsb_exception.invalid_spec (filename ^ " expect a json object {}") + | _ -> Bsb_exception.invalid_spec (filename ^ " expect a json object {}") let deps_from_bsconfig () = let cwd = Bsb_global_paths.cwd in diff --git a/jscomp/bsb/bsb_config_parse.mli b/jscomp/bsb/bsb_config_parse.mli index 84e18eb1ff0..3aedf9891b1 100644 --- a/jscomp/bsb/bsb_config_parse.mli +++ b/jscomp/bsb/bsb_config_parse.mli @@ -25,4 +25,8 @@ val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * bool * Set_string.t val interpret_json : - package_kind:Bsb_package_kind.t -> per_proj_dir:string -> warn_legacy_config:bool -> Bsb_config_types.t + filename:string -> + json:Ext_json_types.t -> + package_kind:Bsb_package_kind.t -> + per_proj_dir:string -> + Bsb_config_types.t diff --git a/jscomp/bsb/bsb_ninja_regen.ml b/jscomp/bsb/bsb_ninja_regen.ml index 009918d8c14..030e98b953f 100644 --- a/jscomp/bsb/bsb_ninja_regen.ml +++ b/jscomp/bsb/bsb_ninja_regen.ml @@ -38,6 +38,9 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir let check_result = Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~file:output_deps in + let config_filename, config_json = + Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config + in match check_result with | Good -> None (* Fast path, no need regenerate ninja *) | Bsb_forced | Bsb_bsc_version_mismatch | Bsb_package_kind_inconsistent @@ -52,7 +55,8 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir Bsb_clean.clean_self per_proj_dir); let config : Bsb_config_types.t = - Bsb_config_parse.interpret_json ~package_kind ~per_proj_dir ~warn_legacy_config + Bsb_config_parse.interpret_json + ~filename:config_filename ~json:config_json ~package_kind ~per_proj_dir in (* create directory, lib/bs, lib/js, lib/es6 etc *) Bsb_build_util.mkp lib_bs_dir; diff --git a/jscomp/build_tests/warn_legacy_config/bsconfig.json b/jscomp/build_tests/warn_legacy_config/bsconfig.json new file mode 100644 index 00000000000..ff8aa6b4b0f --- /dev/null +++ b/jscomp/build_tests/warn_legacy_config/bsconfig.json @@ -0,0 +1,8 @@ +{ + "name": "warn_legacy_config", + "version": "0.1.0", + "sources": { + "dir": "src", + "subdirs": true + } +} diff --git a/jscomp/build_tests/warn_legacy_config/input.js b/jscomp/build_tests/warn_legacy_config/input.js new file mode 100644 index 00000000000..ad81e9ec498 --- /dev/null +++ b/jscomp/build_tests/warn_legacy_config/input.js @@ -0,0 +1,10 @@ +const { spawnSync } = require("child_process"); +const assert = require("assert"); +const rescript_exe = require("../../../scripts/bin_path").rescript_exe; + +const output = spawnSync(rescript_exe, { encoding: "utf8" }); +assert( + /^Warning: bsconfig.json is deprecated. Migrate it to rescript.json/.test( + output.stdout + ) +); diff --git a/jscomp/build_tests/warn_legacy_config/src/demo.res b/jscomp/build_tests/warn_legacy_config/src/demo.res new file mode 100644 index 00000000000..8d0b19151fc --- /dev/null +++ b/jscomp/build_tests/warn_legacy_config/src/demo.res @@ -0,0 +1 @@ +let () = Js.log("Hello, ReScript")