this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: wire @x-ocaml.requires through to worker init

- Add --copy-file flag to jtw opam/opam-all for including x-ocaml.js
and other assets in universe output
- Pass findlib_requires and findlib_index from meta tags through to
the JTW worker init, so @x-ocaml.requires packages are loaded
during setup
- x_ocaml.ml reads <meta name="x-ocaml-packages"> and
<meta name="x-ocaml-universe"> before creating the backend

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

+42 -12
+4 -4
src/backend.ml
··· 25 25 let make_builtin ?extra_load url = 26 26 Builtin (Client.make ?extra_load url) 27 27 28 - let make_jtw url = 28 + let make_jtw ?findlib_requires ?findlib_index url = 29 29 let client = Jtw_client.make url in 30 - Jtw_client.init client; 30 + Jtw_client.init ?findlib_requires ?findlib_index client; 31 31 Jtw client 32 32 33 - let make ~backend ?extra_load url = 33 + let make ~backend ?extra_load ?findlib_requires ?findlib_index url = 34 34 match String.lowercase_ascii backend with 35 - | "jtw" | "js_top_worker" -> make_jtw url 35 + | "jtw" | "js_top_worker" -> make_jtw ?findlib_requires ?findlib_index url 36 36 | "builtin" | "x-ocaml" | _ -> make_builtin ?extra_load url 37 37 38 38 let on_message t fn =
+7 -3
src/backend.mli
··· 57 57 (** Create a client with the built-in x-ocaml worker backend *) 58 58 val make_builtin : ?extra_load:string -> string -> t 59 59 60 - (** Create a client with the js_top_worker backend *) 61 - val make_jtw : string -> t 60 + (** Create a client with the js_top_worker backend. 61 + @param findlib_requires Packages to load during worker init 62 + @param findlib_index URL to findlib_index.json *) 63 + val make_jtw : ?findlib_requires:string list -> ?findlib_index:string -> string -> t 62 64 63 65 (** Create a client with the specified backend. 64 66 @param backend Backend name: "builtin", "x-ocaml", "jtw", or "js_top_worker" 65 67 @param extra_load Optional URL to load before the worker (builtin only) 68 + @param findlib_requires Packages to load during worker init (jtw only) 69 + @param findlib_index URL to findlib_index.json (jtw only) 66 70 @param url URL to the worker script *) 67 - val make : backend:string -> ?extra_load:string -> string -> t 71 + val make : backend:string -> ?extra_load:string -> ?findlib_requires:string list -> ?findlib_index:string -> string -> t 68 72 69 73 (** Set the response handler *) 70 74 val on_message : t -> (X_protocol.response -> unit) -> unit
+3 -3
src/jtw_client.ml
··· 96 96 in 97 97 (loc, `String t.type_str, tail) 98 98 99 - let init t = 99 + let init ?(findlib_requires = []) ?findlib_index t = 100 100 let config : Msg.init_config = { 101 - findlib_requires = []; 101 + findlib_requires; 102 102 stdlib_dcs = None; 103 - findlib_index = None; 103 + findlib_index; 104 104 } in 105 105 Lwt.async (fun () -> 106 106 let open Lwt.Infix in
+1 -1
src/jtw_client.mli
··· 2 2 type t 3 3 val make : string -> t 4 4 val on_message : t -> (X_protocol.response -> unit) -> unit 5 - val init : t -> unit 5 + val init : ?findlib_requires:string list -> ?findlib_index:string -> t -> unit 6 6 val post : t -> X_protocol.request -> unit 7 7 val eval : id:int -> line_number:int -> t -> string -> unit 8 8 val fmt : id:int -> t -> string -> unit
+27 -1
src/x_ocaml.ml
··· 21 21 else "" 22 22 | Some url -> Jstr.to_string url 23 23 24 - let backend = Backend.make ~backend:backend_name ?extra_load worker_url 24 + let read_meta name = 25 + let doc = Brr.Document.to_jv Brr.G.document in 26 + let selector = Jstr.of_string ("meta[name=\"" ^ name ^ "\"]") in 27 + let result = Jv.call doc "querySelector" [| Jv.of_jstr selector |] in 28 + if Jv.is_none result then None 29 + else 30 + let content = Jv.call result "getAttribute" [| Jv.of_string "content" |] in 31 + if Jv.is_none content then None 32 + else Some (Jv.to_string content) 33 + 34 + let findlib_requires = 35 + match read_meta "x-ocaml-packages" with 36 + | None -> None 37 + | Some s -> 38 + let pkgs = List.filter (fun s -> s <> "") 39 + (List.map String.trim (String.split_on_char ',' s)) in 40 + if pkgs = [] then None else Some pkgs 41 + 42 + let findlib_index = 43 + match read_meta "x-ocaml-universe" with 44 + | None -> None 45 + | Some base -> 46 + let base = if String.length base > 0 && base.[String.length base - 1] = '/' 47 + then base else base ^ "/" in 48 + Some (base ^ "findlib_index.json") 49 + 50 + let backend = Backend.make ~backend:backend_name ?extra_load ?findlib_requires ?findlib_index worker_url 25 51 26 52 let format_config = 27 53 match current_attribute "x-ocamlformat" with