Skip to content

Commit 3157a3a

Browse files
committed
feat: melange-decoders
1 parent 501d137 commit 3157a3a

33 files changed

+250
-25
lines changed

.github/workflows/build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,40 @@ jobs:
7272
- run: npm ci
7373
- run: npm run build
7474
- run: npm test
75+
76+
build-melange:
77+
strategy:
78+
fail-fast: false
79+
matrix:
80+
os:
81+
- ubuntu-latest
82+
ocaml-compiler:
83+
- 4.14.x
84+
package:
85+
- melange-decoders
86+
87+
runs-on: ${{ matrix.os }}
88+
89+
steps:
90+
- uses: actions/checkout@v3
91+
92+
- name: Use Node.js ${{ matrix.node-version }}
93+
uses: actions/setup-node@v3
94+
with:
95+
node-version: 16.x
96+
cache: 'npm'
97+
98+
- run: npm ci
99+
100+
- name: Use OCaml ${{ matrix.ocaml-compiler }}
101+
uses: ocaml/setup-ocaml@v2
102+
with:
103+
ocaml-compiler: ${{ matrix.ocaml-compiler }}
104+
opam-depext-flags: --with-test
105+
opam-local-packages: |
106+
decoders.opam
107+
${{ matrix.package }}.opam
108+
109+
- run: opam install "${{ matrix.package }}" --with-test
110+
- run: opam exec -- dune build @melange
111+
- run: npx jest

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: all
2-
all: build test build-bs test-bs
2+
all: build test build-bs test-bs test-mel
33

44
.PHONY: clean-all
55
clean-all: clean clean-bs
@@ -34,7 +34,7 @@ clean:
3434

3535
_opam:
3636
opam switch create . --empty
37-
opam install -y ocaml-base-compiler.4.12.0 utop ocaml-lsp-server
37+
opam switch set-invariant ocaml-base-compiler.4.14.1
3838

3939
install-dependencies: _opam
4040
opam install . --deps-only --with-test
@@ -61,11 +61,11 @@ build-bs:
6161
test-bs:
6262
npm test
6363

64-
watch-build-bs:
65-
npm run build-watch
66-
67-
watch-test-bs:
68-
npm run test-watch
69-
7064
clean-bs:
7165
npm run clean
66+
67+
build-mel:
68+
dune build @melange
69+
70+
test-mel:
71+
npx jest _build/default/out/

__tests__/decoders_bs_json_test.ml renamed to __tests__/decoders_js_json_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
open Jest
2-
open Bs_json
2+
open Js_json
33

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

__tests__/decoders_bs_xml_test.ml renamed to __tests__/decoders_js_xml_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
open Jest
2-
open Bs_xml
2+
open Js_xml
33

44
let () =
55
describe

__tests__/dune

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(subdir
2+
melange
3+
(library
4+
(name decoders_tests_melange)
5+
(modes melange)
6+
(libraries decoders_mel melange-jest.jest)
7+
(preprocess (pps melange.ppx))
8+
(flags -open Decoders_mel)
9+
(wrapped false))
10+
(copy_files# "../*.ml")
11+
(copy_files# "../*.re"))

bsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"xml.ml"
1919
]
2020
}, {
21-
"dir" : "src-bs"
21+
"dir" : "src-js",
22+
"files": {
23+
"excludes": ["decoders_mel.ml"]
24+
}
2225
}, {
2326
"dir": "__tests__",
2427
"type": "dev"

decoders-bencode.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"decoders" {= version}
1616
"bencode" {>= "2.0"}

decoders-cbor.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"decoders" {= version}
1616
"cbor"

decoders-ezjsonm.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"decoders" {= version}
1616
"ezjsonm" {>= "0.4.0"}

decoders-ezxmlm.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"decoders" {= version}
1616
"ezxmlm" {>= "1.1.0"}

decoders-jsonaf.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1212
doc: "https://mattjbray.github.io/ocaml-decoders/"
1313
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1414
depends: [
15-
"dune" {>= "3.1"}
15+
"dune" {>= "3.8"}
1616
"ocaml" {>= "4.10.0"}
1717
"decoders" {= version}
1818
"jsonaf" {>= "0.15.0"}

decoders-jsonm.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"decoders" {= version}
1616
"jsonm"

decoders-msgpck.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1212
doc: "https://mattjbray.github.io/ocaml-decoders/"
1313
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1414
depends: [
15-
"dune" {>= "3.1"}
15+
"dune" {>= "3.8"}
1616
"ocaml" {>= "4.03.0"}
1717
"decoders" {= version}
1818
"msgpck" {>= "1.3"}

decoders-sexplib.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"decoders" {= version}
1616
"sexplib0"

decoders-yojson.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"decoders" {= version}
1616
"yojson" {>= "1.6.0"}

decoders.opam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ homepage: "https://github.com/mattjbray/ocaml-decoders"
1010
doc: "https://mattjbray.github.io/ocaml-decoders/"
1111
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
1212
depends: [
13-
"dune" {>= "3.1"}
13+
"dune" {>= "3.8"}
1414
"ocaml" {>= "4.03.0"}
1515
"odoc" {with-doc}
16+
"melange"
1617
"containers" {with-test & >= "0.16"}
1718
]
1819
build: [

dune

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
(dirs :standard \ node_modules)
1+
(dirs :standard __tests__ \ node_modules)
2+
3+
(melange.emit
4+
(target out)
5+
(preprocess (pps melange.ppx))
6+
(libraries decoders_mel decoders_tests_melange))

dune-project

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(lang dune 3.1)
1+
(lang dune 3.8)
2+
(using melange 0.1)
23
(name decoders)
34
(generate_opam_files true)
45
(license ISC)
@@ -135,4 +136,21 @@
135136
(depends
136137
(ocaml (>= 4.03.0))
137138
(odoc :with-doc)
139+
melange
138140
(containers (and :with-test (>= 0.16)))))
141+
142+
;; melange lib convention is to put `melange-` as the prefix, rather than the
143+
;; suffix, which unfortunately contradicts the `decoders-` prefix convention
144+
(package
145+
(name melange-decoders)
146+
(synopsis "Melange backend for decoders")
147+
(description
148+
"A combinator library for \"decoding\" JSON-like values into your own Ocaml types, inspired by Elm's `Json.Decode` and `Json.Encode`.")
149+
(depends
150+
(ocaml (>= 4.14.1))
151+
(odoc :with-doc)
152+
(decoders (= :version))
153+
melange
154+
(melange-fetch :with-test)
155+
(melange-jest :with-test)
156+
(melange-webapi :with-test)))

flake.lock

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "nixpkgs/nixos-22.11";
4+
flake-utils.url = "github:numtide/flake-utils";
5+
};
6+
7+
outputs = { self, nixpkgs, flake-utils }@attrs:
8+
flake-utils.lib.eachDefaultSystem (system:
9+
let pkgs = nixpkgs.legacyPackages.${system};
10+
in { devShells.default = import ./shell.nix { inherit pkgs; }; });
11+
}

melange-decoders.opam

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This file is generated by dune, edit dune-project instead
2+
opam-version: "2.0"
3+
synopsis: "Melange backend for decoders"
4+
description:
5+
"A combinator library for \"decoding\" JSON-like values into your own Ocaml types, inspired by Elm's `Json.Decode` and `Json.Encode`."
6+
maintainer: ["Matt Bray <[email protected]>"]
7+
authors: ["Matt Bray <[email protected]>"]
8+
license: "ISC"
9+
homepage: "https://github.com/mattjbray/ocaml-decoders"
10+
doc: "https://mattjbray.github.io/ocaml-decoders/"
11+
bug-reports: "https://github.com/mattjbray/ocaml-decoders/issues"
12+
depends: [
13+
"dune" {>= "3.8"}
14+
"ocaml" {>= "4.14.1"}
15+
"odoc" {with-doc}
16+
"decoders" {= version}
17+
"melange"
18+
"melange-fetch" {with-test}
19+
"melange-jest" {with-test}
20+
"melange-webapi" {with-test}
21+
]
22+
build: [
23+
["dune" "subst"] {dev}
24+
[
25+
"dune"
26+
"build"
27+
"-p"
28+
name
29+
"-j"
30+
jobs
31+
"@install"
32+
"@runtest" {with-test}
33+
"@doc" {with-doc}
34+
]
35+
]
36+
dev-repo: "git+https://github.com/mattjbray/ocaml-decoders.git"
37+
pin-depends: [
38+
[
39+
"melange-fetch.dev"
40+
"git+https://github.com/melange-community/melange-fetch.git#d2183ec245cbf5c7a8f99f8c41d2de0758c8cda7"
41+
]
42+
[
43+
"melange-jest.~dev"
44+
"git+https://github.com/melange-community/melange-jest.git#9cd5449738ab6387880ad0ec7a31b78e08f4476d"
45+
]
46+
[
47+
"melange-webapi.~dev"
48+
"git+https://github.com/melange-community/melange-webapi.git#6052d83efa2f29a295d83fb93a6121a232701033"
49+
]
50+
]

melange-decoders.opam.template

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pin-depends: [
2+
[
3+
"melange-fetch.dev"
4+
"git+https://github.com/melange-community/melange-fetch.git#d2183ec245cbf5c7a8f99f8c41d2de0758c8cda7"
5+
]
6+
[
7+
"melange-jest.~dev"
8+
"git+https://github.com/melange-community/melange-jest.git#9cd5449738ab6387880ad0ec7a31b78e08f4476d"
9+
]
10+
[
11+
"melange-webapi.~dev"
12+
"git+https://github.com/melange-community/melange-webapi.git#6052d83efa2f29a295d83fb93a6121a232701033"
13+
]
14+
]

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"build": "bsb -make-world",
1111
"build-watch": "bsb -make-world -w",
1212
"test": "bsb -make-world && jest",
13-
"test-watch": "jest --watch",
1413
"clean": "bsb -clean-world"
1514
},
1615
"repository": {

0 commit comments

Comments
 (0)