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 support #65

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 20 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
cache-prefix: v2
ocaml-compiler: ${{ matrix.ocaml-compiler }}
opam-depext-flags: --with-test
opam-local-packages: |
Expand All @@ -49,14 +50,16 @@ jobs:

- run: opam install "${{ matrix.package }}" --with-test

build-node:
build-melange:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
node-version:
- 16.x
ocaml-compiler:
- 5.1.x
package:
- melange-decoders

runs-on: ${{ matrix.os }}

Expand All @@ -66,9 +69,20 @@ jobs:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: 16.x
cache: 'npm'

- run: npm ci
- run: npm run build
- run: npm test

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
opam-depext-flags: --with-test
opam-local-packages: |
decoders.opam
${{ matrix.package }}.opam

- run: opam install "${{ matrix.package }}" --with-test
- run: opam exec -- dune build @melange
- run: npx jest
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: build test build-bs test-bs
all: build test build-bs test-bs test-mel

.PHONY: clean-all
clean-all: clean clean-bs
Expand Down Expand Up @@ -34,9 +34,9 @@ clean:

_opam:
opam switch create . --empty
opam install -y ocaml-base-compiler.4.12.0 utop ocaml-lsp-server

install-dependencies: _opam
opam switch set-invariant ocaml-base-compiler.5.1.1
opam install . --deps-only --with-test

DOCS_WORKTREE_PATH=../ocaml-decoders-doc
Expand All @@ -61,11 +61,11 @@ build-bs:
test-bs:
npm test

watch-build-bs:
npm run build-watch

watch-test-bs:
npm run test-watch

clean-bs:
npm run clean

build-mel:
dune build @melange

test-mel:
npx jest _build/default/out/
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Jest
open Bs_json
open Js_json

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

let () =
describe
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
11 changes: 11 additions & 0 deletions __tests__/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(subdir
melange
(library
(name decoders_tests_melange)
(modes melange)
(libraries decoders_mel melange-jest.jest)
(preprocess (pps melange.ppx))
(flags -open Decoders_mel)
(wrapped false))
(copy_files# "../*.ml")
(copy_files# "../*.re"))
5 changes: 4 additions & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"xml.ml"
]
}, {
"dir" : "src-bs"
"dir" : "src-js",
"files": {
"excludes": ["decoders_mel.ml"]
}
}, {
"dir": "__tests__",
"type": "dev"
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,9 +10,10 @@ 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"}
"odoc" {with-doc}
"melange"
"containers" {with-test & >= "0.16"}
]
build: [
Expand Down
7 changes: 6 additions & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
(dirs :standard \ node_modules)
(dirs :standard __tests__ \ node_modules)

(melange.emit
(target out)
(preprocess (pps melange.ppx))
(libraries decoders_mel decoders_tests_melange))
20 changes: 19 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(lang dune 3.1)
(lang dune 3.8)
(using melange 0.1)
(name decoders)
(generate_opam_files true)
(license ISC)
Expand Down Expand Up @@ -135,4 +136,21 @@
(depends
(ocaml (>= 4.03.0))
(odoc :with-doc)
melange
(containers (and :with-test (>= 0.16)))))

;; melange lib convention is to put `melange-` as the prefix, rather than the
;; suffix, which unfortunately contradicts the `decoders-` prefix convention
(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.14.1))
(odoc :with-doc)
(decoders (= :version))
(melange (>= 3.0.0))
(melange-fetch :with-test)
(melange-jest :with-test)
(melange-webapi :with-test)))
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-22.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }@attrs:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in { devShells.default = import ./shell.nix { inherit pkgs; }; });
}
36 changes: 36 additions & 0 deletions melange-decoders.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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.14.1"}
"odoc" {with-doc}
"decoders" {= version}
"melange" {>= "3.0.0"}
"melange-fetch" {with-test}
"melange-jest" {with-test}
"melange-webapi" {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"
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"build": "bsb -make-world",
"build-watch": "bsb -make-world -w",
"test": "bsb -make-world && jest",
"test-watch": "jest --watch",
"clean": "bsb -clean-world"
},
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
buildInputs =
[ pkgs.opam pkgs.pkg-config pkgs.gmp pkgs.zlib ]
++ (if pkgs.stdenv.isDarwin then
(with pkgs.darwin.apple_sdk.frameworks; [ CoreServices Foundation ])
else
[ pkgs.inotify-tools ]);
}
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)
(public_name melange-decoders)
(preprocess (pps melange.ppx))
(modes melange)
(libraries decoders melange.dom melange.belt))
Loading
Loading