Skip to content

Commit 4b9142e

Browse files
committed
Fix legacy bsb to use source subdirectory from output_prefix
The previous implementation used a ninja variable $in_d which doesn't exist, causing files to be written to the wrong location. Now bsc extracts the source subdirectory directly from the output_prefix parameter. For in-source builds with output_prefix='src/Node', files are written to: project_root / '.' / 'src' / 'Node.mjs' For out-of-source builds with output_prefix='src/Node', files go to: project_root / 'lib/es6' / 'src' / 'Node.mjs' This ensures source directory structure is preserved in the output.
1 parent c3cc9a8 commit 4b9142e

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

compiler/bsb/bsb_package_specs.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ let from_json suffix (x : Ext_json_types.t) : Spec_set.t =
132132

133133
[@@@warning "+9"]
134134

135-
let package_flag ({format; in_source; suffix} : Bsb_spec_set.spec) dir =
135+
let package_flag ({format; in_source; suffix} : Bsb_spec_set.spec) _dir =
136136
(* Generate separate flags for module system, suffix, and output path *)
137137
let module_system_flag = "-bs-module-system " ^ string_of_format format in
138138
let suffix_flag = "-bs-suffix " ^ suffix in
139+
(* For in-source, use "." as base dir; for out-of-source, use lib/es6 etc.
140+
bsc will extract source subdirectory from output_prefix automatically *)
139141
let output_path =
140-
if in_source then dir else Bsb_config.top_prefix_of_format format // dir
142+
if in_source then "." else Bsb_config.top_prefix_of_format format
141143
in
142144
let output_flag = "-bs-package-output " ^ output_path in
143145
(* Concatenate all three flags *)

compiler/core/lam_compile_main.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,16 @@ let lambda_as_module
304304
let basename =
305305
Ext_namespace.change_ext_ns_suffix (Filename.basename output_prefix) suffix
306306
in
307+
(* Extract source subdirectory from output_prefix (e.g., "src/acyc" from "src/acyc/Node") *)
308+
let source_subdir = Filename.dirname output_prefix in
309+
(* Construct target path:
310+
- path is the base output directory from config (e.g., "." for in-source, "../lib/es6" for out-of-source)
311+
- source_subdir preserves the source directory structure
312+
- basename is the final filename *)
307313
let target_file =
308314
(Lazy.force Ext_path.package_dir //
309315
path //
316+
source_subdir //
310317
basename
311318
(* #913 only generate little-case js file *)
312319
) in

0 commit comments

Comments
 (0)