Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

melange-decoders: melange backend #64

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Jest
open Bs_json
open Js_json

external parse_int : string -> int = "parseInt" [@@bs.scope "window"] [@@bs.val]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Jest
open Bs_xml
open Js_xml

let () =
describe
Expand Down Expand Up @@ -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 ->
Expand Down
11 changes: 11 additions & 0 deletions __tests__/dune
Original file line number Diff line number Diff line change
@@ -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))
5 changes: 2 additions & 3 deletions bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion decoders-bencode.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion decoders-cbor.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion decoders-ezjsonm.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion decoders-ezxmlm.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion decoders-jsonaf.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion decoders-jsonm.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion decoders-msgpck.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion decoders-sexplib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion decoders-yojson.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
3 changes: 2 additions & 1 deletion decoders.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
]
Expand Down
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(dirs :standard \ node_modules)
(dirs :standard __tests__ \ node_modules)
19 changes: 18 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(lang dune 3.1)
(lang dune 3.8)

(using melange 0.1)

(name decoders)
(generate_opam_files true)
(license ISC)
Expand Down Expand Up @@ -127,12 +130,26 @@
(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))
mattjbray marked this conversation as resolved.
Show resolved Hide resolved
(odoc :with-doc)
(containers (and :with-test (>= 0.16)))
(melange-jest :with-test)))

(package
(name decoders)
(synopsis "Elm-inspired decoders for Ocaml")
(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.03.0))
melange
(odoc :with-doc)
(containers (and :with-test (>= 0.16)))))
35 changes: 35 additions & 0 deletions melange-decoders.opam
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
authors: ["Matt Bray <[email protected]>"]
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"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src-js/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name decoders_mel)
(flags :standard -warn-error -a+8)
(public_name melange-decoders)
(modes melange)
(libraries decoders))
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
@@ -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)
Expand Down