Skip to content

Commit f88643e

Browse files
committed
add warning message and its test
1 parent 073d108 commit f88643e

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

jscomp/bsb/bsb_config_load.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ let load_json ~(per_proj_dir : string) ~(warn_legacy_config : bool)
1717
| exception _ -> raise e (* forward error from rescript.json *)
1818
in
1919
if warn_legacy_config && filename = Literals.bsconfig_json then
20-
(* TODO: warn legacy config *)
21-
();
20+
print_endline "Warning: bsconfig.json is deprecated. Migrate it to rescript.json\n";
2221
match Ext_json_parse.parse_json_from_chan abs in_chan
2322
with
2423
| v -> close_in in_chan ; (filename, v)

jscomp/bsb/bsb_config_parse.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ let extract_js_post_build (map : json_map) cwd : string option =
237237

238238
(** ATT: make sure such function is re-entrant.
239239
With a given [cwd] it works anywhere*)
240-
let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) ~(warn_legacy_config : bool)
240+
let interpret_json
241+
~(filename : string)
242+
~(json : Ext_json_types.t)
243+
~(package_kind : Bsb_package_kind.t)
244+
~(per_proj_dir : string)
241245
: Bsb_config_types.t =
242246
(* we should not resolve it too early,
243247
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)
253257
1. if [build.ninja] does use [ninja] we need set a variable
254258
2. we need store it so that we can call ninja correctly
255259
*)
256-
match
257-
Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config
260+
match json
258261
with
259-
| filename, Obj { map } -> (
262+
| Obj { map } -> (
260263
let package_name, namespace = extract_package_name_and_namespace map in
261264
let gentype_config = extract_gentype_config map in
262265

@@ -353,7 +356,7 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
353356
}
354357
| None ->
355358
Bsb_exception.invalid_spec ("no sources specified in " ^ filename))
356-
| filename, _ -> Bsb_exception.invalid_spec (filename ^ " expect a json object {}")
359+
| _ -> Bsb_exception.invalid_spec (filename ^ " expect a json object {}")
357360

358361
let deps_from_bsconfig () =
359362
let cwd = Bsb_global_paths.cwd in

jscomp/bsb/bsb_config_parse.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * bool * Set_string.t
2626

2727
val interpret_json :
28-
package_kind:Bsb_package_kind.t -> per_proj_dir:string -> warn_legacy_config:bool -> Bsb_config_types.t
28+
filename:string ->
29+
json:Ext_json_types.t ->
30+
package_kind:Bsb_package_kind.t ->
31+
per_proj_dir:string ->
32+
Bsb_config_types.t

jscomp/bsb/bsb_ninja_regen.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
3838
let check_result =
3939
Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~file:output_deps
4040
in
41+
let config_filename, config_json =
42+
Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config
43+
in
4144
match check_result with
4245
| Good -> None (* Fast path, no need regenerate ninja *)
4346
| 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
5255
Bsb_clean.clean_self per_proj_dir);
5356

5457
let config : Bsb_config_types.t =
55-
Bsb_config_parse.interpret_json ~package_kind ~per_proj_dir ~warn_legacy_config
58+
Bsb_config_parse.interpret_json
59+
~filename:config_filename ~json:config_json ~package_kind ~per_proj_dir
5660
in
5761
(* create directory, lib/bs, lib/js, lib/es6 etc *)
5862
Bsb_build_util.mkp lib_bs_dir;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "warn_legacy_config",
3+
"version": "0.1.0",
4+
"sources": {
5+
"dir": "src",
6+
"subdirs": true
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { spawnSync } = require("child_process");
2+
const assert = require("assert");
3+
const rescript_exe = require("../../../scripts/bin_path").rescript_exe;
4+
5+
const output = spawnSync(rescript_exe, { encoding: "utf8" });
6+
assert(
7+
/^Warning: bsconfig.json is deprecated. Migrate it to rescript.json/.test(
8+
output.stdout
9+
)
10+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let () = Js.log("Hello, ReScript")

0 commit comments

Comments
 (0)