diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eba50de..2a99062 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,3 +72,44 @@ jobs: - run: npm ci - run: npm run build - run: npm test + + build-melange: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + node-version: + - 16.x + ocaml-compiler: + - 4.14.x + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + + - run: npm ci + + - name: Use OCaml ${{ matrix.ocaml-compiler }} + uses: ocaml/setup-ocaml@v2 + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + opam-local-packages: | + decoders.opam + melange-decoders.opam + + - run: | + opam pin -y -n melange-jest git+https://github.com/melange-community/melange-jest.git + opam pin -y -n melange-fetch git+https://github.com/melange-community/melange-fetch.git + opam pin -y -n melange-webapi git+https://github.com/melange-community/melange-webapi.git + + - run: opam install ./melange-decoders.opam --with-test + - run: opam exec -- dune build @melange + - run: npx jest _build/default/__tests__ diff --git a/__tests__/decoders_bs_json_test.ml b/__tests__/decoders_json_test.ml similarity index 99% rename from __tests__/decoders_bs_json_test.ml rename to __tests__/decoders_json_test.ml index bfae460..e4a51d4 100644 --- a/__tests__/decoders_bs_json_test.ml +++ b/__tests__/decoders_json_test.ml @@ -1,5 +1,5 @@ open Jest -open Bs_json +open Js_json external parse_int : string -> int = "parseInt" [@@bs.scope "window"] [@@bs.val] diff --git a/__tests__/decoders_bs_xml_test.ml b/__tests__/decoders_xml_test.ml similarity index 98% rename from __tests__/decoders_bs_xml_test.ml rename to __tests__/decoders_xml_test.ml index d6610ef..be16ea5 100644 --- a/__tests__/decoders_bs_xml_test.ml +++ b/__tests__/decoders_xml_test.ml @@ -1,5 +1,5 @@ open Jest -open Bs_xml +open Js_xml let () = describe @@ -257,7 +257,7 @@ let () = test "tree" (fun () -> let encoded = encode_string root xml_tree in let expected = - Js.String.splitByRe [%re "/\\n/"] xml_str + Js.String.splitByRe (Js.Re.fromString "\\n") xml_str |> Array.to_list |> Decoders.Util.My_list.filter_map (function | None -> diff --git a/__tests__/dune b/__tests__/dune new file mode 100644 index 0000000..9d25be9 --- /dev/null +++ b/__tests__/dune @@ -0,0 +1,11 @@ +(melange.emit + (target decoders_json_test) + (modules decoders_json_test) + (compile_flags :standard -open Decoders_mel) + (libraries decoders_mel melange-jest.jest)) + +(melange.emit + (target decoders_xml_test) + (modules decoders_xml_test) + (compile_flags :standard -open Decoders_mel) + (libraries decoders_mel melange-jest.jest)) diff --git a/bsconfig.json b/bsconfig.json index 742c0c8..2729627 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -18,14 +18,13 @@ "xml.ml" ] }, { - "dir" : "src-bs" + "dir" : "src-js" }, { "dir": "__tests__", "type": "dev" }], "package-specs": { - "module": "commonjs", - "in-source": true + "module": "commonjs" }, "suffix": ".bs.js", "bs-dependencies": [ diff --git a/decoders-bencode.opam b/decoders-bencode.opam index bfc0e21..1865743 100644 --- a/decoders-bencode.opam +++ b/decoders-bencode.opam @@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "bencode" {>= "2.0"} diff --git a/decoders-cbor.opam b/decoders-cbor.opam index 50535eb..8d5779a 100644 --- a/decoders-cbor.opam +++ b/decoders-cbor.opam @@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "cbor" diff --git a/decoders-ezjsonm.opam b/decoders-ezjsonm.opam index d0e0485..840720c 100644 --- a/decoders-ezjsonm.opam +++ b/decoders-ezjsonm.opam @@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "ezjsonm" {>= "0.4.0"} diff --git a/decoders-ezxmlm.opam b/decoders-ezxmlm.opam index c5073d8..640fefa 100644 --- a/decoders-ezxmlm.opam +++ b/decoders-ezxmlm.opam @@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "ezxmlm" {>= "1.1.0"} diff --git a/decoders-jsonaf.opam b/decoders-jsonaf.opam index 4a88fbb..af0253e 100644 --- a/decoders-jsonaf.opam +++ b/decoders-jsonaf.opam @@ -12,7 +12,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.10.0"} "decoders" {= version} "jsonaf" {>= "0.15.0"} diff --git a/decoders-jsonm.opam b/decoders-jsonm.opam index 7b398f8..ef57e19 100644 --- a/decoders-jsonm.opam +++ b/decoders-jsonm.opam @@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "jsonm" diff --git a/decoders-msgpck.opam b/decoders-msgpck.opam index 6ac7f13..e6e503c 100644 --- a/decoders-msgpck.opam +++ b/decoders-msgpck.opam @@ -12,7 +12,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "msgpck" {>= "1.3"} diff --git a/decoders-sexplib.opam b/decoders-sexplib.opam index d1487c5..f862b9b 100644 --- a/decoders-sexplib.opam +++ b/decoders-sexplib.opam @@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "sexplib0" diff --git a/decoders-yojson.opam b/decoders-yojson.opam index 44c5f3f..d7cc6f6 100644 --- a/decoders-yojson.opam +++ b/decoders-yojson.opam @@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} "decoders" {= version} "yojson" {>= "1.6.0"} diff --git a/decoders.opam b/decoders.opam index c5ade6f..ced82de 100644 --- a/decoders.opam +++ b/decoders.opam @@ -10,8 +10,9 @@ homepage: "https://github.com/mattjbray/ocaml-decoders" doc: "https://mattjbray.github.io/ocaml-decoders/" bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" depends: [ - "dune" {>= "3.1"} + "dune" {>= "3.8"} "ocaml" {>= "4.03.0"} + "melange" "odoc" {with-doc} "containers" {with-test & >= "0.16"} ] diff --git a/dune b/dune index 8765da5..9b11947 100644 --- a/dune +++ b/dune @@ -1 +1 @@ -(dirs :standard \ node_modules) +(dirs :standard __tests__ \ node_modules) diff --git a/dune-project b/dune-project index 1ff060a..a22997a 100644 --- a/dune-project +++ b/dune-project @@ -1,4 +1,7 @@ -(lang dune 3.1) +(lang dune 3.8) + +(using melange 0.1) + (name decoders) (generate_opam_files true) (license ISC) @@ -127,6 +130,19 @@ (containers (and :with-test (>= 0.16))) (ounit2 :with-test))) +(package + (name melange-decoders) + (synopsis "Melange backend for decoders") + (description + "A combinator library for \"decoding\" JSON-like values into your own Ocaml types, inspired by Elm's `Json.Decode` and `Json.Encode`.") + (depends + (ocaml (>= 4.13.0)) + melange + (decoders (= :version)) + (odoc :with-doc) + (containers (and :with-test (>= 0.16))) + (melange-jest :with-test))) + (package (name decoders) (synopsis "Elm-inspired decoders for Ocaml") @@ -134,5 +150,6 @@ "A combinator library for \"decoding\" JSON-like values into your own Ocaml types, inspired by Elm's `Json.Decode` and `Json.Encode`.") (depends (ocaml (>= 4.03.0)) + melange (odoc :with-doc) (containers (and :with-test (>= 0.16))))) diff --git a/melange-decoders.opam b/melange-decoders.opam new file mode 100644 index 0000000..4fd7c0d --- /dev/null +++ b/melange-decoders.opam @@ -0,0 +1,35 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "Melange backend for decoders" +description: + "A combinator library for \"decoding\" JSON-like values into your own Ocaml types, inspired by Elm's `Json.Decode` and `Json.Encode`." +maintainer: ["Matt Bray "] +authors: ["Matt Bray "] +license: "ISC" +homepage: "https://github.com/mattjbray/ocaml-decoders" +doc: "https://mattjbray.github.io/ocaml-decoders/" +bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues" +depends: [ + "dune" {>= "3.8"} + "ocaml" {>= "4.13.0"} + "melange" + "decoders" {= version} + "odoc" {with-doc} + "containers" {with-test & >= "0.16"} + "melange-jest" {with-test} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/mattjbray/ocaml-decoders.git" diff --git a/src-bs/bs_json.ml b/src-js/Js_json.ml similarity index 100% rename from src-bs/bs_json.ml rename to src-js/Js_json.ml diff --git a/src-bs/bs_json.mli b/src-js/Js_json.mli similarity index 100% rename from src-bs/bs_json.mli rename to src-js/Js_json.mli diff --git a/src-bs/bs_xml.ml b/src-js/Js_xml.ml similarity index 100% rename from src-bs/bs_xml.ml rename to src-js/Js_xml.ml diff --git a/src-bs/bs_xml.mli b/src-js/Js_xml.mli similarity index 100% rename from src-bs/bs_xml.mli rename to src-js/Js_xml.mli diff --git a/src-js/dune b/src-js/dune new file mode 100644 index 0000000..2434856 --- /dev/null +++ b/src-js/dune @@ -0,0 +1,6 @@ +(library + (name decoders_mel) + (flags :standard -warn-error -a+8) + (public_name melange-decoders) + (modes melange) + (libraries decoders)) diff --git a/src-bs/shims_let_ops_.ml b/src-js/shims_let_ops_.ml similarity index 100% rename from src-bs/shims_let_ops_.ml rename to src-js/shims_let_ops_.ml diff --git a/src-bs/util.ml b/src-js/util.ml similarity index 100% rename from src-bs/util.ml rename to src-js/util.ml diff --git a/src-bs/util.mli b/src-js/util.mli similarity index 100% rename from src-bs/util.mli rename to src-js/util.mli diff --git a/src/dune b/src/dune index e60d8a2..94312a0 100644 --- a/src/dune +++ b/src/dune @@ -1,7 +1,8 @@ (library (name decoders) (flags :standard -warn-error -a+8) - (public_name decoders)) + (public_name decoders) + (modes native byte melange)) (rule (targets shims_let_ops_.ml)