From 0c44fb83b526169757fdf07916d6d4ec715f40e0 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 4 Sep 2023 22:31:56 +0900 Subject: [PATCH 1/4] add support rescript.json --- jscomp/bsb/bsb_build_util.ml | 15 +++++----- jscomp/bsb/bsb_config_load.ml | 25 +++++++++++++++++ jscomp/bsb/bsb_config_load.mli | 2 ++ jscomp/bsb/bsb_config_parse.ml | 30 ++++++++++---------- jscomp/bsb/bsb_config_parse.mli | 2 +- jscomp/bsb/bsb_config_types.ml | 2 ++ jscomp/bsb/bsb_ninja_regen.ml | 6 ++-- jscomp/bsb/bsb_ninja_regen.mli | 1 + jscomp/bsb/bsb_world.ml | 3 +- jscomp/bsb_exe/rescript_main.ml | 21 ++++++++++---- jscomp/ext/ext_path.ml | 29 +++++++++++--------- jscomp/ext/ext_path.mli | 20 +++++++------- jscomp/ext/literals.ml | 2 ++ jscomp/gentype/GenTypeConfig.ml | 14 ++++++---- jscomp/gentype/Paths.ml | 16 +++++++---- jscomp/runtime/release.ninja | 6 ++-- jscomp/syntax/src/reactjs_jsx_ppx.mli | 2 +- jscomp/syntax/src/res_multi_printer.ml | 38 +++++++++++++++----------- rescript | 20 +++++++++----- 19 files changed, 161 insertions(+), 93 deletions(-) create mode 100644 jscomp/bsb/bsb_config_load.ml create mode 100644 jscomp/bsb/bsb_config_load.mli diff --git a/jscomp/bsb/bsb_build_util.ml b/jscomp/bsb/bsb_build_util.ml index 8d49c183fe..9982b5b65b 100644 --- a/jscomp/bsb/bsb_build_util.ml +++ b/jscomp/bsb/bsb_build_util.ml @@ -17,7 +17,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) @@ -101,7 +101,7 @@ let resolve_bsb_magic_file ~cwd ~desc p : result = (** converting a file from Linux path format to Windows *) -(** +(** {[ mkp "a/b/c/d";; mkp "/a/b/c/d" @@ -155,9 +155,8 @@ let extract_pinned_dependencies (map : Ext_json_types.t Map_string.t) : Set_stri let rec walk_all_deps_aux (visited : string Hash_string.t) (paths : string list) ~(top : top) (dir : string) (queue : _ Queue.t) ~pinned_dependencies = - let bsconfig_json = dir // Literals.bsconfig_json in - match Ext_json_parse.parse_json_from_file bsconfig_json with - | Obj { map; loc } -> + match Bsb_config_load.load_json ~per_proj_dir:dir ~warn_legacy_config:false with + | _, Obj { map; loc } -> let cur_package_name = match Map_string.find_opt map Bsb_build_schemas.name with | Some (Str { str; loc }) -> @@ -183,7 +182,7 @@ let rec walk_all_deps_aux (visited : string Hash_string.t) (paths : string list) else let explore_deps (deps : string) pinned_dependencies = map - |? ( deps, + |? ( deps, `Arr (fun (new_packages : Ext_json_types.t array) -> Ext_array.iter new_packages (fun js -> @@ -205,8 +204,8 @@ let rec walk_all_deps_aux (visited : string Hash_string.t) (paths : string list) | Expect_name n when Set_string.mem pinned_dependencies n -> true | _ -> false in - let pinned_dependencies = match is_pinned with - | true -> + let pinned_dependencies = match is_pinned with + | true -> let transitive_pinned_dependencies = extract_pinned_dependencies map in Set_string.union transitive_pinned_dependencies pinned_dependencies diff --git a/jscomp/bsb/bsb_config_load.ml b/jscomp/bsb/bsb_config_load.ml new file mode 100644 index 0000000000..e947c920ed --- /dev/null +++ b/jscomp/bsb/bsb_config_load.ml @@ -0,0 +1,25 @@ +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 + (* TODO: warn legacy config *) + (); + match Ext_json_parse.parse_json_from_chan abs in_chan + with + | v -> close_in in_chan ; (filename, v) + | exception e -> close_in in_chan ; raise e diff --git a/jscomp/bsb/bsb_config_load.mli b/jscomp/bsb/bsb_config_load.mli new file mode 100644 index 0000000000..7e8cd97857 --- /dev/null +++ b/jscomp/bsb/bsb_config_load.mli @@ -0,0 +1,2 @@ +val load_json : + per_proj_dir:string -> warn_legacy_config:bool -> string * Ext_json_types.t diff --git a/jscomp/bsb/bsb_config_parse.ml b/jscomp/bsb/bsb_config_parse.ml index 0ef2c2da33..1a6f654ba7 100644 --- a/jscomp/bsb/bsb_config_parse.ml +++ b/jscomp/bsb/bsb_config_parse.ml @@ -70,10 +70,10 @@ let extract_package_name_and_namespace (map : json_map) : string * string option - the running bsb need delete stale build artifacts (kinda check npm upgrade) - Note if the setup is correct: + Note if the setup is correct: the running compiler and node_modules/rescript - should be the same version, - The exact check is that the running compiler should have a + should be the same version, + The exact check is that the running compiler should have a compatible runtime version installed, the location of the compiler is actually not relevant. We disable the check temporarily @@ -235,9 +235,9 @@ let extract_js_post_build (map : json_map) cwd : string option = |> ignore; !js_post_build_cmd -(** ATT: make sure such function is re-entrant. +(** 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) +let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) ~(warn_legacy_config : bool) : Bsb_config_types.t = (* we should not resolve it too early, since it is external configuration, no {!Bsb_build_util.convert_and_resolve_path} @@ -254,9 +254,9 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) 2. we need store it so that we can call ninja correctly *) match - Ext_json_parse.parse_json_from_file (per_proj_dir // Literals.bsconfig_json) + Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config with - | Obj { map } -> ( + | filename, Obj { map } -> ( let package_name, namespace = extract_package_name_and_namespace map in let gentype_config = extract_gentype_config map in @@ -349,17 +349,19 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) (match package_kind with | Toplevel -> extract_uncurried map | Pinned_dependency x | Dependency x -> x.uncurried); + filename; } | None -> - Bsb_exception.invalid_spec "no sources specified in bsconfig.json") - | _ -> Bsb_exception.invalid_spec "bsconfig.json expect a json object {}" + Bsb_exception.invalid_spec ("no sources specified in " ^ filename)) + | filename, _ -> Bsb_exception.invalid_spec (filename ^ " expect a json object {}") let deps_from_bsconfig () = - let json = Ext_json_parse.parse_json_from_file Literals.bsconfig_json in - match json with - | Obj { map } -> - ( Bsb_package_specs.from_map ~cwd:Bsb_global_paths.cwd map, + let cwd = Bsb_global_paths.cwd in + match Bsb_config_load.load_json ~per_proj_dir:cwd ~warn_legacy_config:false + with + | _, Obj { map } -> + ( Bsb_package_specs.from_map ~cwd map, Bsb_jsx.from_map map, extract_uncurried map, Bsb_build_util.extract_pinned_dependencies map ) - | _ -> assert false + | _, _ -> assert false diff --git a/jscomp/bsb/bsb_config_parse.mli b/jscomp/bsb/bsb_config_parse.mli index 3ce5d5e166..84e18eb1ff 100644 --- a/jscomp/bsb/bsb_config_parse.mli +++ b/jscomp/bsb/bsb_config_parse.mli @@ -25,4 +25,4 @@ 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 -> Bsb_config_types.t + package_kind:Bsb_package_kind.t -> per_proj_dir:string -> warn_legacy_config:bool -> Bsb_config_types.t diff --git a/jscomp/bsb/bsb_config_types.ml b/jscomp/bsb/bsb_config_types.ml index 4404ad727d..db5c007e4d 100644 --- a/jscomp/bsb/bsb_config_types.ml +++ b/jscomp/bsb/bsb_config_types.ml @@ -65,4 +65,6 @@ type t = { (* note when used as a dev mode, we will always ignore it *) gentype_config : gentype_config; uncurried: bool; + + filename: string; } diff --git a/jscomp/bsb/bsb_ninja_regen.ml b/jscomp/bsb/bsb_ninja_regen.ml index 9481d6cb63..009918d8c1 100644 --- a/jscomp/bsb/bsb_ninja_regen.ml +++ b/jscomp/bsb/bsb_ninja_regen.ml @@ -30,7 +30,7 @@ let ( // ) = Ext_path.combine return None if we dont need regenerate otherwise return Some info *) -let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir +let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config : 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 @@ -52,7 +52,7 @@ 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 + Bsb_config_parse.interpret_json ~package_kind ~per_proj_dir ~warn_legacy_config in (* create directory, lib/bs, lib/js, lib/es6 etc *) Bsb_build_util.mkp lib_bs_dir; @@ -75,5 +75,5 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir since it may add files in the future *) Bsb_ninja_check.record ~package_kind ~per_proj_dir ~config ~file:output_deps - (Literals.bsconfig_json :: config.file_groups.globbed_dirs); + (config.filename :: config.file_groups.globbed_dirs); Some config diff --git a/jscomp/bsb/bsb_ninja_regen.mli b/jscomp/bsb/bsb_ninja_regen.mli index 5409f022f9..b92cf0b115 100644 --- a/jscomp/bsb/bsb_ninja_regen.mli +++ b/jscomp/bsb/bsb_ninja_regen.mli @@ -26,6 +26,7 @@ val regenerate_ninja : package_kind:Bsb_package_kind.t -> forced:bool -> per_proj_dir:string -> + warn_legacy_config:bool -> Bsb_config_types.t option (** Regenerate ninja file by need based on [.bsdeps] return None if we dont need regenerate diff --git a/jscomp/bsb/bsb_world.ml b/jscomp/bsb/bsb_world.ml index df6cdf747a..e5e9dfdc77 100644 --- a/jscomp/bsb/bsb_world.ml +++ b/jscomp/bsb/bsb_world.ml @@ -30,7 +30,7 @@ let make_world_deps cwd (config : Bsb_config_types.t option) let package_specs, jsx, uncurried, pinned_dependencies = match config with | None -> - (* When this running bsb does not read bsconfig.json, + (* When this running bsb does not read rescript.json, we will read such json file to know which [package-specs] it wants *) @@ -70,6 +70,7 @@ let make_world_deps cwd (config : Bsb_config_types.t option) (if is_pinned then Pinned_dependency { package_specs; jsx; uncurried } else Dependency { package_specs; jsx; uncurried }) ~per_proj_dir:proj_dir ~forced:false + ~warn_legacy_config:false in let command = { Bsb_unix.cmd = vendor_ninja; cwd = lib_bs_dir; args } diff --git a/jscomp/bsb_exe/rescript_main.ml b/jscomp/bsb_exe/rescript_main.ml index 799266ff26..b9050b5700 100644 --- a/jscomp/bsb_exe/rescript_main.ml +++ b/jscomp/bsb_exe/rescript_main.ml @@ -142,8 +142,12 @@ let build_subcommand ~start argv argv_len = | [| "-h" |] -> ninja_command_exit ninja_args | _ -> let config_opt = - Bsb_ninja_regen.regenerate_ninja ~package_kind:Toplevel - ~per_proj_dir:Bsb_global_paths.cwd ~forced:!force_regenerate in + Bsb_ninja_regen.regenerate_ninja + ~package_kind:Toplevel + ~per_proj_dir:Bsb_global_paths.cwd + ~forced:!force_regenerate + ~warn_legacy_config:true + in if not !no_deps_mode then Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args; if !do_install then install_target (); ninja_command_exit ninja_args @@ -171,8 +175,11 @@ let info_subcommand ~start argv = | [] -> ()); if !list_files then match - Bsb_ninja_regen.regenerate_ninja ~package_kind:Toplevel ~forced:true + Bsb_ninja_regen.regenerate_ninja + ~package_kind:Toplevel ~per_proj_dir:Bsb_global_paths.cwd + ~forced:true + ~warn_legacy_config:true with | None -> assert false | Some { file_groups = { files } } -> @@ -198,8 +205,12 @@ let () = if argv_len = 1 then ( (* specialize this path which is used in watcher *) let config_opt = - Bsb_ninja_regen.regenerate_ninja ~package_kind:Toplevel ~forced:false - ~per_proj_dir:Bsb_global_paths.cwd in + Bsb_ninja_regen.regenerate_ninja + ~package_kind:Toplevel + ~per_proj_dir:Bsb_global_paths.cwd + ~forced:false + ~warn_legacy_config:true + in Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||]; ninja_command_exit [||]) else diff --git a/jscomp/ext/ext_path.ml b/jscomp/ext/ext_path.ml index 6b1ec82e8d..31bbe47a67 100644 --- a/jscomp/ext/ext_path.ml +++ b/jscomp/ext/ext_path.ml @@ -1,5 +1,5 @@ (* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -17,7 +17,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) @@ -117,7 +117,7 @@ let ( // ) x y = split_aux "//ghosg//ghsogh/";; - : string * string list = ("/", ["ghosg"; "ghsogh"]) ]} - Note that + Note that {[ Filename.dirname "/a/" = "/" Filename.dirname "/a/b/" = Filename.dirname "/a/b" = "/a" @@ -132,7 +132,7 @@ let ( // ) x y = basename "" = "." dirname "" = "." dirname "" = "." - ]} + ]} *) let split_aux p = let rec go p acc = @@ -149,11 +149,11 @@ let split_aux p = go p [] -(** +(** TODO: optimization - if [from] and [to] resolve to the same path, a zero-length string is returned + if [from] and [to] resolve to the same path, a zero-length string is returned - This function is useed in [es6-global] and + This function is useed in [es6-global] and [amdjs-global] format and tailored for `rollup` *) let rel_normalized_absolute_path ~from to_ = @@ -261,14 +261,17 @@ let concat dirname filename = let check_suffix_case = Ext_string.ends_with (* Input must be absolute directory *) -let rec find_root_filename ~cwd filename = - if Sys.file_exists (Filename.concat cwd filename) then cwd +let rec find_root_filename ~cwd filenames = + let file_exists = Ext_list.exists filenames (fun filename -> + Sys.file_exists (Filename.concat cwd filename)) + in + if file_exists then cwd else let cwd' = Filename.dirname cwd in if String.length cwd' < String.length cwd then - find_root_filename ~cwd:cwd' filename - else Ext_fmt.failwithf ~loc:__LOC__ "%s not found from %s" filename cwd + find_root_filename ~cwd:cwd' filenames + else Ext_fmt.failwithf ~loc:__LOC__ "%s not found from %s" (List.hd filenames) cwd -let find_package_json_dir cwd = find_root_filename ~cwd Literals.bsconfig_json +let find_config_dir cwd = find_root_filename ~cwd [Literals.rescript_json; Literals.bsconfig_json] -let package_dir = lazy (find_package_json_dir (Lazy.force cwd)) +let package_dir = lazy (find_config_dir (Lazy.force cwd)) diff --git a/jscomp/ext/ext_path.mli b/jscomp/ext/ext_path.mli index 76e6e209c9..6a9905688a 100644 --- a/jscomp/ext/ext_path.mli +++ b/jscomp/ext/ext_path.mli @@ -1,5 +1,5 @@ (* Copyright (C) 2017 Authors of ReScript - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -17,7 +17,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) @@ -25,11 +25,11 @@ type t val simple_convert_node_path_to_os_path : string -> string -(** Js_output is node style, which means +(** Js_output is node style, which means separator is only '/' - if the path contains 'node_modules', - [node_relative_path] will discard its prefix and + if the path contains 'node_modules', + [node_relative_path] will discard its prefix and just treat it as a library instead *) @@ -50,14 +50,14 @@ val combine : string -> string -> string val node_rebase_file : from:string -> to_:string -> string -> string val rel_normalized_absolute_path : from:string -> string -> string -(** +(** TODO: could be highly optimized - if [from] and [to] resolve to the same path, a zero-length string is returned + if [from] and [to] resolve to the same path, a zero-length string is returned Given that two paths are directory - A typical use case is + A typical use case is {[ - Filename.concat + Filename.concat (rel_normalized_absolute_path cwd (Filename.dirname a)) (Filename.basename a) ]} @@ -69,7 +69,7 @@ val absolute_cwd_path : string -> string val concat : string -> string -> string (** [concat dirname filename] - The same as {!Filename.concat} except a tiny optimization + The same as {!Filename.concat} except a tiny optimization for current directory simplification *) diff --git a/jscomp/ext/literals.ml b/jscomp/ext/literals.ml index 6810267cf5..ed410ee8d7 100644 --- a/jscomp/ext/literals.ml +++ b/jscomp/ext/literals.ml @@ -76,6 +76,8 @@ let package_json = "package.json" let bsconfig_json = "bsconfig.json" +let rescript_json = "rescript.json" + let build_ninja = "build.ninja" (* Name of the library file created for each external dependency. *) diff --git a/jscomp/gentype/GenTypeConfig.ml b/jscomp/gentype/GenTypeConfig.ml index 125d94fb5c..299e52f945 100644 --- a/jscomp/gentype/GenTypeConfig.ml +++ b/jscomp/gentype/GenTypeConfig.ml @@ -101,10 +101,14 @@ let setDebug ~gtconf = | Some (Obj {map}) -> Map_string.iter map Debug.setItem | _ -> () -let compilerConfigFile = "bsconfig.json" +let compilerConfigFile = "rescript.json" +let legacyCompilerConfigFile = "bsconfig.json" let rec findProjectRoot ~dir = - if Sys.file_exists (Filename.concat dir compilerConfigFile) then dir + if + Sys.file_exists (Filename.concat dir compilerConfigFile) + || Sys.file_exists (Filename.concat dir legacyCompilerConfigFile) + then dir else let parent = dir |> Filename.dirname in if parent = dir then ( @@ -114,7 +118,7 @@ let rec findProjectRoot ~dir = assert false) else findProjectRoot ~dir:parent -let readConfig ~getBsConfigFile ~namespace = +let readConfig ~getConfigFile ~namespace = let projectRoot = findProjectRoot ~dir:(Sys.getcwd ()) in let bsbProjectRoot = match Sys.getenv_opt "BSB_PROJECT_ROOT" with @@ -175,7 +179,7 @@ let readConfig ~getBsConfigFile ~namespace = | Some externalStdlib -> externalStdlib in if !Debug.config then ( - Log_.item "Project root: %s\n" projectRoot; + Log_.item "Project roLiterals.bsconfig_jsonot: %s\n" projectRoot; if bsbProjectRoot <> projectRoot then Log_.item "bsb project root: %s\n" bsbProjectRoot; Log_.item "Config module:%s shims:%d entries \n" @@ -230,7 +234,7 @@ let readConfig ~getBsConfigFile ~namespace = sources; } in - match getBsConfigFile ~projectRoot with + match getConfigFile ~projectRoot with | Some bsConfigFile -> ( try let json = bsConfigFile |> Ext_json_parse.parse_json_from_file in diff --git a/jscomp/gentype/Paths.ml b/jscomp/gentype/Paths.ml index b64b5c0b36..ed95905268 100644 --- a/jscomp/gentype/Paths.ml +++ b/jscomp/gentype/Paths.ml @@ -61,10 +61,14 @@ let getCmtFile cmt = in cmtFile -let getBsConfigFile ~projectRoot = - let bsconfig = concat projectRoot Config.compilerConfigFile in - match bsconfig |> Sys.file_exists with - | true -> Some bsconfig - | false -> None +let getConfigFile ~projectRoot = + let config = concat projectRoot Config.compilerConfigFile in + match config |> Sys.file_exists with + | true -> Some config + | false -> ( + let config = concat projectRoot Config.legacyCompilerConfigFile in + match config |> Sys.file_exists with + | true -> Some config + | false -> None) -let readConfig ~namespace = Config.readConfig ~getBsConfigFile ~namespace +let readConfig ~namespace = Config.readConfig ~getConfigFile ~namespace diff --git a/jscomp/runtime/release.ninja b/jscomp/runtime/release.ninja index b7b44625e4..181ca9fa81 100644 --- a/jscomp/runtime/release.ninja +++ b/jscomp/runtime/release.ninja @@ -21,7 +21,7 @@ o runtime/caml_bytes.cmj : cc_cmi runtime/caml_bytes.res | runtime/caml_bytes.cm o runtime/caml_bytes.cmi : cc runtime/caml_bytes.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_float.cmj : cc_cmi runtime/caml_float.res | runtime/caml_float.cmi runtime/caml_float_extern.cmj o runtime/caml_float.cmi : cc runtime/caml_float.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj +o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj o runtime/caml_format.cmi : cc runtime/caml_format.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj runtime/js.cmj o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj @@ -37,7 +37,7 @@ o runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.res | runtime/caml_array_extern o runtime/caml_md5.cmi : cc runtime/caml_md5.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml.cmj runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj +o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj runtime/js.cmj o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj @@ -54,7 +54,7 @@ o runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj : cc runtime/caml_exce o runtime/caml_external_polyfill.cmi runtime/caml_external_polyfill.cmj : cc runtime/caml_external_polyfill.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj +o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/js.cmi runtime/js.cmj o runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj diff --git a/jscomp/syntax/src/reactjs_jsx_ppx.mli b/jscomp/syntax/src/reactjs_jsx_ppx.mli index 388202edba..36a8468687 100644 --- a/jscomp/syntax/src/reactjs_jsx_ppx.mli +++ b/jscomp/syntax/src/reactjs_jsx_ppx.mli @@ -4,7 +4,7 @@ facilities; https://whitequark.org/blog/2014/04/16/a-guide-to-extension- points-in-ocaml/ You wouldn't use this file directly; it's used by ReScript's - bsconfig.json. Specifically, there's a field called `react-jsx` inside the + rescript.json. Specifically, there's a field called `react-jsx` inside the field `reason`, which enables this ppx through some internal call in bsb *) diff --git a/jscomp/syntax/src/res_multi_printer.ml b/jscomp/syntax/src/res_multi_printer.ml index 354311ce08..81d14d844c 100644 --- a/jscomp/syntax/src/res_multi_printer.ml +++ b/jscomp/syntax/src/res_multi_printer.ml @@ -1,20 +1,26 @@ let defaultPrintWidth = 100 -(* Look at bsconfig.json to set Uncurried or Legacy mode if it contains "uncurried": false *) -let getUncurriedFromBsconfig ~filename = - let rec findBsconfig ~dir = - let bsconfig = Filename.concat dir "bsconfig.json" in - if Sys.file_exists bsconfig then Some (Res_io.readFile ~filename:bsconfig) +(* Look at rescript.json (or bsconfig.json) to set Uncurried or Legacy mode if it contains "uncurried": false *) +let getUncurriedFromConfig ~filename = + let rec findConfig ~dir = + let config = Filename.concat dir "rescript.json" in + if Sys.file_exists config then Some (Res_io.readFile ~filename:config) else - let parent = Filename.dirname dir in - if parent = dir then None else findBsconfig ~dir:parent + let config = Filename.concat dir "bsconfig.json" in + if Sys.file_exists config then Some (Res_io.readFile ~filename:config) + else + let parent = Filename.dirname dir in + if parent = dir then None else findConfig ~dir:parent in let rec findFromNodeModules ~dir = let parent = Filename.dirname dir in if Filename.basename dir = "node_modules" then - let bsconfig = Filename.concat parent "bsconfig.json" in - if Sys.file_exists bsconfig then Some (Res_io.readFile ~filename:bsconfig) - else None + let config = Filename.concat parent "rescript.json" in + if Sys.file_exists config then Some (Res_io.readFile ~filename:config) + else + let config = Filename.concat parent "bsconfig.json" in + if Sys.file_exists config then Some (Res_io.readFile ~filename:config) + else None else if parent = dir then None else findFromNodeModules ~dir:parent in @@ -23,8 +29,8 @@ let getUncurriedFromBsconfig ~filename = Filename.dirname (Filename.concat (Sys.getcwd ()) filename) else Filename.dirname filename in - let bsconfig () = - match findBsconfig ~dir with + let config () = + match findConfig ~dir with | None -> (* The editor calls format on a temporary file. So bsconfig can't be found. This looks outside the node_modules containing the bsc binary *) @@ -32,11 +38,11 @@ let getUncurriedFromBsconfig ~filename = findFromNodeModules ~dir | x -> x in - match bsconfig () with + match config () with | exception _ -> () | None -> () - | Some bsconfig -> - let lines = bsconfig |> String.split_on_char '\n' in + | Some config -> + let lines = config |> String.split_on_char '\n' in let is_legacy_uncurried = lines |> List.exists (fun line -> @@ -60,7 +66,7 @@ let getUncurriedFromBsconfig ~filename = (* print res files to res syntax *) let printRes ~ignoreParseErrors ~isInterface ~filename = - getUncurriedFromBsconfig ~filename; + getUncurriedFromConfig ~filename; if isInterface then ( let parseResult = Res_driver.parsingEngine.parseInterface ~forPrinter:true ~filename diff --git a/rescript b/rescript index 57b639b660..a667e9a46c 100755 --- a/rescript +++ b/rescript @@ -13,7 +13,6 @@ var path = require("path"); var fs = require("fs"); var bsc_exe = require("./scripts/bin_path").bsc_exe; var rescript_exe = require("./scripts/bin_path").rescript_exe; -var bsconfig = "bsconfig.json"; var LAST_SUCCESS_BUILD_STAMP = 0; var cwd = process.cwd(); @@ -23,12 +22,19 @@ process.env.BSB_PROJECT_ROOT = cwd; const isTtyError = process.stderr.isTTY; const isTtyStd = process.stdout.isTTY; +var bsConfig = "bsconfig.json" +var resConfig = "rescript.json"; +var resConfigFile = path.join(cwd, resConfig); +if (!fs.existsSync(resConfigFile)) { + resConfig = bsConfig; + resConfigFile = path.join(cwd, bsConfig); +} + // If the project uses gentype and uses custom file extension // via generatedFileExtension, ignore them in watch mode -var bsConfigFile = path.join(cwd, bsconfig); var genTypeFileExtension = ".gen.tsx"; -if (fs.existsSync(bsConfigFile)) { - var genTypeConfig = require(bsConfigFile).gentypeconfig; +if (fs.existsSync(resConfigFile)) { + var genTypeConfig = require(resConfigFile).gentypeconfig if (genTypeConfig) { genTypeFileExtension = genTypeConfig.generatedFileExtension; } @@ -100,7 +106,7 @@ Subcommands: Run \`rescript -h\` for subcommand help. Examples: rescript build -h rescript format -h -The default \`rescript\` is equivalent to \`rescript build\` subcommand +The default \`rescript\` is equivalent to \`rescript build\` subcommand `); } @@ -321,7 +327,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); watchGenerated = watchConfig.generated; // close and remove all unused watchers watchers = watchers.filter(function (watcher) { - if (watcher.dir === bsconfig) { + if (watcher.dir === resConfig) { return true; } else if (watchFiles.indexOf(watcher.dir) < 0) { dlog(`${watcher.dir} is no longer watched`); @@ -511,7 +517,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); process.stdin.resume(); } - watchers.push({ watcher: fs.watch(bsconfig, onChange), dir: bsconfig }); + watchers.push({ watcher: fs.watch(resConfig, onChange), dir: resConfig }); } logStartCompiling(); From 2d588f29ec084b5dbe6457cf9176f716f1cb2f53 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 4 Sep 2023 23:49:51 +0900 Subject: [PATCH 2/4] migrate to rescript.json --- jscomp/build_tests/case/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/case2/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/case3/{bsconfig.json => rescript.json} | 0 .../build_tests/custom_namespace/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/cycle/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/cycle1/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/devonly/{bsconfig.json => rescript.json} | 0 .../{bsconfig.json => rescript.json} | 0 jscomp/build_tests/exports/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/hyphen2/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/in_source/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/install/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/nested/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/nnest/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/ns/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/post-build/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/react_ppx/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/rerror/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/scoped_ppx/{bsconfig.json => rescript.json} | 0 .../a/{bsconfig.json => rescript.json} | 0 .../a/{bsconfig.json => rescript.json} | 0 .../build_tests/uncurried-always/{bsconfig.json => rescript.json} | 0 .../uncurried_printer/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/unicode/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/weird_deps/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/weird_devdeps/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/weird_names/{bsconfig.json => rescript.json} | 0 .../weird_names_not_found_bug/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/x-y/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/xpkg/{bsconfig.json => rescript.json} | 0 jscomp/build_tests/zerocycle/{bsconfig.json => rescript.json} | 0 .../typescript-react-example/{bsconfig.json => rescript.json} | 0 32 files changed, 0 insertions(+), 0 deletions(-) rename jscomp/build_tests/case/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/case2/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/case3/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/custom_namespace/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/cycle/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/cycle1/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/devonly/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/duplicated_symlinked_packages/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/exports/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/hyphen2/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/in_source/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/install/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/nested/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/nnest/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/ns/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/post-build/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/react_ppx/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/rerror/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/scoped_ppx/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/transitive_pinned_dependency1/a/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/transitive_pinned_dependency2/a/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/uncurried-always/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/uncurried_printer/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/unicode/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/weird_deps/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/weird_devdeps/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/weird_names/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/weird_names_not_found_bug/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/x-y/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/xpkg/{bsconfig.json => rescript.json} (100%) rename jscomp/build_tests/zerocycle/{bsconfig.json => rescript.json} (100%) rename jscomp/gentype_tests/typescript-react-example/{bsconfig.json => rescript.json} (100%) diff --git a/jscomp/build_tests/case/bsconfig.json b/jscomp/build_tests/case/rescript.json similarity index 100% rename from jscomp/build_tests/case/bsconfig.json rename to jscomp/build_tests/case/rescript.json diff --git a/jscomp/build_tests/case2/bsconfig.json b/jscomp/build_tests/case2/rescript.json similarity index 100% rename from jscomp/build_tests/case2/bsconfig.json rename to jscomp/build_tests/case2/rescript.json diff --git a/jscomp/build_tests/case3/bsconfig.json b/jscomp/build_tests/case3/rescript.json similarity index 100% rename from jscomp/build_tests/case3/bsconfig.json rename to jscomp/build_tests/case3/rescript.json diff --git a/jscomp/build_tests/custom_namespace/bsconfig.json b/jscomp/build_tests/custom_namespace/rescript.json similarity index 100% rename from jscomp/build_tests/custom_namespace/bsconfig.json rename to jscomp/build_tests/custom_namespace/rescript.json diff --git a/jscomp/build_tests/cycle/bsconfig.json b/jscomp/build_tests/cycle/rescript.json similarity index 100% rename from jscomp/build_tests/cycle/bsconfig.json rename to jscomp/build_tests/cycle/rescript.json diff --git a/jscomp/build_tests/cycle1/bsconfig.json b/jscomp/build_tests/cycle1/rescript.json similarity index 100% rename from jscomp/build_tests/cycle1/bsconfig.json rename to jscomp/build_tests/cycle1/rescript.json diff --git a/jscomp/build_tests/devonly/bsconfig.json b/jscomp/build_tests/devonly/rescript.json similarity index 100% rename from jscomp/build_tests/devonly/bsconfig.json rename to jscomp/build_tests/devonly/rescript.json diff --git a/jscomp/build_tests/duplicated_symlinked_packages/bsconfig.json b/jscomp/build_tests/duplicated_symlinked_packages/rescript.json similarity index 100% rename from jscomp/build_tests/duplicated_symlinked_packages/bsconfig.json rename to jscomp/build_tests/duplicated_symlinked_packages/rescript.json diff --git a/jscomp/build_tests/exports/bsconfig.json b/jscomp/build_tests/exports/rescript.json similarity index 100% rename from jscomp/build_tests/exports/bsconfig.json rename to jscomp/build_tests/exports/rescript.json diff --git a/jscomp/build_tests/hyphen2/bsconfig.json b/jscomp/build_tests/hyphen2/rescript.json similarity index 100% rename from jscomp/build_tests/hyphen2/bsconfig.json rename to jscomp/build_tests/hyphen2/rescript.json diff --git a/jscomp/build_tests/in_source/bsconfig.json b/jscomp/build_tests/in_source/rescript.json similarity index 100% rename from jscomp/build_tests/in_source/bsconfig.json rename to jscomp/build_tests/in_source/rescript.json diff --git a/jscomp/build_tests/install/bsconfig.json b/jscomp/build_tests/install/rescript.json similarity index 100% rename from jscomp/build_tests/install/bsconfig.json rename to jscomp/build_tests/install/rescript.json diff --git a/jscomp/build_tests/nested/bsconfig.json b/jscomp/build_tests/nested/rescript.json similarity index 100% rename from jscomp/build_tests/nested/bsconfig.json rename to jscomp/build_tests/nested/rescript.json diff --git a/jscomp/build_tests/nnest/bsconfig.json b/jscomp/build_tests/nnest/rescript.json similarity index 100% rename from jscomp/build_tests/nnest/bsconfig.json rename to jscomp/build_tests/nnest/rescript.json diff --git a/jscomp/build_tests/ns/bsconfig.json b/jscomp/build_tests/ns/rescript.json similarity index 100% rename from jscomp/build_tests/ns/bsconfig.json rename to jscomp/build_tests/ns/rescript.json diff --git a/jscomp/build_tests/post-build/bsconfig.json b/jscomp/build_tests/post-build/rescript.json similarity index 100% rename from jscomp/build_tests/post-build/bsconfig.json rename to jscomp/build_tests/post-build/rescript.json diff --git a/jscomp/build_tests/react_ppx/bsconfig.json b/jscomp/build_tests/react_ppx/rescript.json similarity index 100% rename from jscomp/build_tests/react_ppx/bsconfig.json rename to jscomp/build_tests/react_ppx/rescript.json diff --git a/jscomp/build_tests/rerror/bsconfig.json b/jscomp/build_tests/rerror/rescript.json similarity index 100% rename from jscomp/build_tests/rerror/bsconfig.json rename to jscomp/build_tests/rerror/rescript.json diff --git a/jscomp/build_tests/scoped_ppx/bsconfig.json b/jscomp/build_tests/scoped_ppx/rescript.json similarity index 100% rename from jscomp/build_tests/scoped_ppx/bsconfig.json rename to jscomp/build_tests/scoped_ppx/rescript.json diff --git a/jscomp/build_tests/transitive_pinned_dependency1/a/bsconfig.json b/jscomp/build_tests/transitive_pinned_dependency1/a/rescript.json similarity index 100% rename from jscomp/build_tests/transitive_pinned_dependency1/a/bsconfig.json rename to jscomp/build_tests/transitive_pinned_dependency1/a/rescript.json diff --git a/jscomp/build_tests/transitive_pinned_dependency2/a/bsconfig.json b/jscomp/build_tests/transitive_pinned_dependency2/a/rescript.json similarity index 100% rename from jscomp/build_tests/transitive_pinned_dependency2/a/bsconfig.json rename to jscomp/build_tests/transitive_pinned_dependency2/a/rescript.json diff --git a/jscomp/build_tests/uncurried-always/bsconfig.json b/jscomp/build_tests/uncurried-always/rescript.json similarity index 100% rename from jscomp/build_tests/uncurried-always/bsconfig.json rename to jscomp/build_tests/uncurried-always/rescript.json diff --git a/jscomp/build_tests/uncurried_printer/bsconfig.json b/jscomp/build_tests/uncurried_printer/rescript.json similarity index 100% rename from jscomp/build_tests/uncurried_printer/bsconfig.json rename to jscomp/build_tests/uncurried_printer/rescript.json diff --git a/jscomp/build_tests/unicode/bsconfig.json b/jscomp/build_tests/unicode/rescript.json similarity index 100% rename from jscomp/build_tests/unicode/bsconfig.json rename to jscomp/build_tests/unicode/rescript.json diff --git a/jscomp/build_tests/weird_deps/bsconfig.json b/jscomp/build_tests/weird_deps/rescript.json similarity index 100% rename from jscomp/build_tests/weird_deps/bsconfig.json rename to jscomp/build_tests/weird_deps/rescript.json diff --git a/jscomp/build_tests/weird_devdeps/bsconfig.json b/jscomp/build_tests/weird_devdeps/rescript.json similarity index 100% rename from jscomp/build_tests/weird_devdeps/bsconfig.json rename to jscomp/build_tests/weird_devdeps/rescript.json diff --git a/jscomp/build_tests/weird_names/bsconfig.json b/jscomp/build_tests/weird_names/rescript.json similarity index 100% rename from jscomp/build_tests/weird_names/bsconfig.json rename to jscomp/build_tests/weird_names/rescript.json diff --git a/jscomp/build_tests/weird_names_not_found_bug/bsconfig.json b/jscomp/build_tests/weird_names_not_found_bug/rescript.json similarity index 100% rename from jscomp/build_tests/weird_names_not_found_bug/bsconfig.json rename to jscomp/build_tests/weird_names_not_found_bug/rescript.json diff --git a/jscomp/build_tests/x-y/bsconfig.json b/jscomp/build_tests/x-y/rescript.json similarity index 100% rename from jscomp/build_tests/x-y/bsconfig.json rename to jscomp/build_tests/x-y/rescript.json diff --git a/jscomp/build_tests/xpkg/bsconfig.json b/jscomp/build_tests/xpkg/rescript.json similarity index 100% rename from jscomp/build_tests/xpkg/bsconfig.json rename to jscomp/build_tests/xpkg/rescript.json diff --git a/jscomp/build_tests/zerocycle/bsconfig.json b/jscomp/build_tests/zerocycle/rescript.json similarity index 100% rename from jscomp/build_tests/zerocycle/bsconfig.json rename to jscomp/build_tests/zerocycle/rescript.json diff --git a/jscomp/gentype_tests/typescript-react-example/bsconfig.json b/jscomp/gentype_tests/typescript-react-example/rescript.json similarity index 100% rename from jscomp/gentype_tests/typescript-react-example/bsconfig.json rename to jscomp/gentype_tests/typescript-react-example/rescript.json From 3d75e717d7f09909fe01e56ac3aaaf2a3b379d4e Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 4 Sep 2023 23:50:06 +0900 Subject: [PATCH 3/4] add warning message and its test --- jscomp/bsb/bsb_config_load.ml | 3 +-- jscomp/bsb/bsb_config_parse.ml | 13 ++++++++----- jscomp/bsb/bsb_config_parse.mli | 6 +++++- jscomp/bsb/bsb_ninja_regen.ml | 6 +++++- jscomp/build_tests/warn_legacy_config/bsconfig.json | 8 ++++++++ jscomp/build_tests/warn_legacy_config/input.js | 10 ++++++++++ jscomp/build_tests/warn_legacy_config/src/demo.res | 1 + 7 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 jscomp/build_tests/warn_legacy_config/bsconfig.json create mode 100644 jscomp/build_tests/warn_legacy_config/input.js create mode 100644 jscomp/build_tests/warn_legacy_config/src/demo.res diff --git a/jscomp/bsb/bsb_config_load.ml b/jscomp/bsb/bsb_config_load.ml index e947c920ed..0255663763 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 1a6f654ba7..747a2b7e08 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 84e18eb1ff..3aedf9891b 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 009918d8c1..030e98b953 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 0000000000..ff8aa6b4b0 --- /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 0000000000..ad81e9ec49 --- /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 0000000000..8d0b19151f --- /dev/null +++ b/jscomp/build_tests/warn_legacy_config/src/demo.res @@ -0,0 +1 @@ +let () = Js.log("Hello, ReScript") From 555676fc1f9c69415bb45b21d43674653c38dbd8 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 3 Oct 2023 23:04:44 +0900 Subject: [PATCH 4/4] add CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc4ff3c699..5da11628d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Add builtin abstract types for File and Blob APIs. https://github.com/rescript-lang/rescript-compiler/pull/6383 - Untagged variants: Support `promise`, RegExes, Dates, File and Blob. https://github.com/rescript-lang/rescript-compiler/pull/6383 - Support aliased types as payloads to untagged variants. https://github.com/rescript-lang/rescript-compiler/pull/6394 +- Support `rescript.json` configuration file and deprecated `bsconfig.json`. https://github.com/rescript-lang/rescript-compiler/pull/6382 #### :boom: Breaking Change - Add smart printer for pipe-chains. https://github.com/rescript-lang/rescript-compiler/pull/6411 (the formatter will reformat existing code in certain cases)