Skip to content

Commit

Permalink
add warning message and its test
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Oct 3, 2023
1 parent 2d588f2 commit 3d75e71
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
3 changes: 1 addition & 2 deletions jscomp/bsb/bsb_config_load.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion jscomp/bsb/bsb_config_parse.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion jscomp/bsb/bsb_ninja_regen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions jscomp/build_tests/warn_legacy_config/bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "warn_legacy_config",
"version": "0.1.0",
"sources": {
"dir": "src",
"subdirs": true
}
}
10 changes: 10 additions & 0 deletions jscomp/build_tests/warn_legacy_config/input.js
Original file line number Diff line number Diff line change
@@ -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
)
);
1 change: 1 addition & 0 deletions jscomp/build_tests/warn_legacy_config/src/demo.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = Js.log("Hello, ReScript")

0 comments on commit 3d75e71

Please sign in to comment.