Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proof of concept: one shot file compilation#8002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
nojaf wants to merge10 commits intorescript-lang:master
base:master
Choose a base branch
Loading
fromnojaf:one-shot
Draft
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Extract -bs-package-output into multiple arguments
  • Loading branch information
@nojaf
nojaf committedNov 4, 2025
commitc3cc9a8e503465ff61b75ae74eac66a392396fed
15 changes: 9 additions & 6 deletionscompiler/bsb/bsb_package_specs.ml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,15 +130,18 @@ let from_json suffix (x : Ext_json_types.t) : Spec_set.t =
| Arr {content; _} -> from_array suffix content
| _ -> Spec_set.singleton (from_json_single suffix x)

let bs_package_output = "-bs-package-output"

[@@@warning "+9"]

let package_flag ({format; in_source; suffix} : Bsb_spec_set.spec) dir =
Ext_string.inter2 bs_package_output
(Ext_string.concat5 (string_of_format format) Ext_string.single_colon
(if in_source then dir else Bsb_config.top_prefix_of_format format // dir)
Ext_string.single_colon suffix)
(* Generate separate flags for module system, suffix, and output path *)
let module_system_flag = "-bs-module-system " ^ string_of_format format in
let suffix_flag = "-bs-suffix " ^ suffix in
let output_path =
if in_source then dir else Bsb_config.top_prefix_of_format format // dir
in
let output_flag = "-bs-package-output " ^ output_path in
(* Concatenate all three flags *)
module_system_flag ^ " " ^ suffix_flag ^ " " ^ output_flag

(* FIXME: we should adapt it *)
let package_flag_of_package_specs (package_specs : t) ~(dirname : string) :
Expand Down
17 changes: 15 additions & 2 deletionscompiler/bsc/rescript_compiler_main.ml
View file
Open in desktop
Original file line numberDiff line numberDiff 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* Setnpm-output-path: [opt_module]:path, for example: \
'lib/cjs', 'amdjs:lib/amdjs', 'es6:lib/es6'" );
"*internal* Set outputpath (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 deletionscompiler/common/js_config.ml
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionscompiler/common/js_config.mli
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,6 +84,10 @@ val jsx_preserve : bool ref

valjs_stdout :boolref

valdefault_module_system :Ext_module_system.tref

valdefault_suffix :stringref

valall_module_aliases :boolref

valno_stdlib :boolref
Expand Down
4 changes: 3 additions & 1 deletioncompiler/core/js_name_of_module_id.ml
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 caseLiterals.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 deletionscompiler/core/js_packages_info.ml
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionscompiler/core/js_packages_info.mli
View file
Open in desktop
Original file line numberDiff line numberDiff 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
3 changes: 2 additions & 1 deletioncompiler/core/lam_compile_main.ml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -292,7 +292,8 @@ let lambda_as_module
: unit =
let package_info = Js_packages_state.get_packages_info () in
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
Js_dump_program.dump_deps_program ~output_prefix Commonjs (lambda_output) stdout
(* Use configured module system instead of hardcoded Commonjs *)
Js_dump_program.dump_deps_program ~output_prefix !Js_config.default_module_system (lambda_output) stdout
end else
Js_packages_info.iter package_info (fun {module_system; path; suffix} ->
let output_chan chan =
Expand Down
3 changes: 2 additions & 1 deletioncompiler/core/lam_compile_primitive.ml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,8 @@ let get_module_system () =
let package_info = Js_packages_state.get_packages_info () in
let module_system =
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then
[Ext_module_system.Commonjs]
(* Use configured module system instead of hardcoded Commonjs *)
[!Js_config.default_module_system]
else
Js_packages_info.map package_info (fun {module_system} -> module_system)
in
Expand Down
34 changes: 17 additions & 17 deletionsrewatch/src/build/compile.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -493,25 +493,25 @@ pub fn compiler_args(
specs
.iter()
.flat_map(|spec|{
// Pass module system, suffix, and output path as separate flags
vec![
"-bs-module-system".to_string(),
spec.module.clone(),
"-bs-suffix".to_string(),
root_config.get_suffix(spec),
"-bs-package-output".to_string(),
format!(
"{}:{}:{}",
spec.module,
if spec.in_source{
file_path.parent().unwrap().to_str().unwrap().to_string()
} else{
Path::new("lib")
.join(Path::join(
Path::new(&spec.get_out_of_source_dir()),
file_path.parent().unwrap(),
))
.to_str()
.unwrap()
.to_string()
},
root_config.get_suffix(spec),
),
if spec.in_source{
file_path.parent().unwrap().to_str().unwrap().to_string()
} else{
Path::new("lib")
.join(Path::join(
Path::new(&spec.get_out_of_source_dir()),
file_path.parent().unwrap(),
))
.to_str()
.unwrap()
.to_string()
},
]
})
.collect()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp