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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#### :rocket: New Feature

- Add `rescript compile-file` command for one-shot compilation of a single ReScript file to JavaScript, outputting to stdout. Supports `--module-format` flag to select output format when multiple package-specs are configured. https://github.com/rescript-lang/rescript/pull/8002

#### :bug: Bug fix

- Reanalyze: fix reactive/server stale results when cross-file references change without changing dead declarations (non-transitive mode). https://github.com/rescript-lang/rescript/pull/8173
Expand Down
17 changes: 15 additions & 2 deletions compiler/bsc/rescript_compiler_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,23 @@ let command_line_flags : (string * Bsc_args.spec * string) array =
string_call ignore,
"*internal* Set jsx mode, this is no longer used and is a no-op." );
("-bs-jsx-preserve", set Js_config.jsx_preserve, "*internal* Preserve jsx");
( "-bs-module-system",
string_call (fun s ->
Js_config.default_module_system :=
match Js_packages_info.module_system_of_string s with
| Some ms -> ms
| None ->
Bsc_args.bad_arg
("Invalid module system: " ^ s
^ ". Use: commonjs, esmodule, or es6-global")),
"*internal* Set module system: commonjs, esmodule, es6-global" );
( "-bs-suffix",
string_call (fun s -> Js_config.default_suffix := s),
"*internal* Set import file suffix: .js, .mjs, .cjs" );
( "-bs-package-output",
string_call Js_packages_state.update_npm_package_path,
"*internal* Set npm-output-path: [opt_module]:path, for example: \
'lib/cjs', 'amdjs:lib/amdjs', 'es6:lib/es6' " );
"*internal* Set output path (when combined with -bs-module-system and \
-bs-suffix)" );
( "-bs-ast",
unit_call (fun _ ->
Js_config.binary_ast := true;
Expand Down
2 changes: 2 additions & 0 deletions compiler/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ let jsx_version = ref None
let jsx_module = ref React
let jsx_preserve = ref false
let js_stdout = ref true
let default_module_system = ref Ext_module_system.Commonjs
let default_suffix = ref Literals.suffix_js
let all_module_aliases = ref false
let no_stdlib = ref false
let no_export = ref false
Expand Down
4 changes: 4 additions & 0 deletions compiler/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ val jsx_preserve : bool ref

val js_stdout : bool ref

val default_module_system : Ext_module_system.t ref

val default_suffix : string ref

val all_module_aliases : bool ref

val no_stdlib : bool ref
Expand Down
4 changes: 3 additions & 1 deletion compiler/core/js_name_of_module_id.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ let get_runtime_module_path
let current_info_query =
Js_packages_info.query_package_infos current_package_info
module_system in
(* Runtime package is pre-compiled and always uses .js suffix *)
let js_file =
Ext_namespace.js_name_of_modulename dep_module_id.id.name
Upper Literals.suffix_js in
Expand Down Expand Up @@ -177,8 +178,9 @@ let string_of_module_id
end
| Package_script, Package_script
->
(* Use configured suffix instead of hardcoded .js *)
let js_file =
Ext_namespace.js_name_of_modulename dep_module_id.id.name case Literals.suffix_js in
Ext_namespace.js_name_of_modulename dep_module_id.id.name case !Js_config.default_suffix in
match Config_util.find_opt js_file with
| Some file ->
let basename = Filename.basename file in
Expand Down
12 changes: 10 additions & 2 deletions compiler/core/js_packages_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,21 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
in
let m =
match Ext_string.split ~keep_empty:true s ':' with
| [path] -> {module_system = Esmodule; path; suffix = Literals.suffix_js}
(* NEW: Just path - use configured module system and suffix *)
| [path] ->
{
module_system = !Js_config.default_module_system;
path;
suffix = !Js_config.default_suffix;
}
(* OLD: module_system:path - use configured suffix *)
| [module_system; path] ->
{
module_system = handle_module_system module_system;
path;
suffix = Literals.suffix_js;
suffix = !Js_config.default_suffix;
}
(* OLD: Full format - all explicit *)
| [module_system; path; suffix] ->
{module_system = handle_module_system module_system; path; suffix}
| _ -> Bsc_args.bad_arg ("invalid npm package path: " ^ s)
Expand Down
3 changes: 3 additions & 0 deletions compiler/core/js_packages_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ val is_empty : t -> bool

val dump_packages_info : Format.formatter -> t -> unit

val module_system_of_string : string -> module_system option
(** Parse module system from string (commonjs, esmodule, es6, es6-global) *)

val add_npm_package_path : t -> string -> t
(** used by command line option
e.g [-bs-package-output commonjs:xx/path]
Expand Down
Loading
Loading