this repo has no description

odoc extensions: find x-ocaml.js from dune build dir

Both interactive and scrollycode extensions now check
_build/install/default/share/x-ocaml/x-ocaml.js (walking up from CWD)
before falling back to opam share. This avoids requiring 'dune install
x-ocaml' as a separate step.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+24 -10
+24 -10
src/interactive_extension.ml
··· 178 178 Api.Registry.register_code_block (module X_ocaml_code); 179 179 Api.Registry.register_extension_info config_info; 180 180 Api.Registry.register_extension_info code_info; 181 - (* Find x-ocaml.js from the opam share directory. 182 - We use 'opam var share' (the switch-level share dir) rather than 183 - 'opam var x-ocaml:share' which requires x-ocaml to be a registered 184 - opam package. dune install puts the file at <share>/x-ocaml/x-ocaml.js. *) 181 + (* Find x-ocaml.js: check dune's build install dir first (no 'dune install' 182 + needed), then fall back to the opam share directory. 183 + Walk up from CWD to find _build/install since odoc may run from a 184 + subdirectory (e.g. _build/default/site/). *) 185 185 let x_ocaml_js = 186 - try 187 - let ic = Unix.open_process_in "opam var share 2>/dev/null" in 188 - let line = input_line ic in 189 - let _ = Unix.close_process_in ic in 190 - Some (String.trim line ^ "/x-ocaml/x-ocaml.js") 191 - with _ -> None 186 + let find_in_build_install () = 187 + let target = "_build/install/default/share/x-ocaml/x-ocaml.js" in 188 + let rec walk dir = 189 + let candidate = Filename.concat dir target in 190 + if Sys.file_exists candidate then Some candidate 191 + else 192 + let parent = Filename.dirname dir in 193 + if parent = dir then None else walk parent 194 + in 195 + walk (Sys.getcwd ()) 196 + in 197 + match find_in_build_install () with 198 + | Some _ as r -> r 199 + | None -> 200 + try 201 + let ic = Unix.open_process_in "opam var share 2>/dev/null" in 202 + let line = input_line ic in 203 + let _ = Unix.close_process_in ic in 204 + Some (String.trim line ^ "/x-ocaml/x-ocaml.js") 205 + with _ -> None 192 206 in 193 207 (match x_ocaml_js with 194 208 | Some path when Sys.file_exists path ->