zaphyra's git: haumea

fork of https://github.com/nix-community/haumea

commit 45ee9e3179202350fe35cdc42ac76846fde8ce03
parent 0baf2243c2b14359bfed72047dd82b3416eb47a0
Author: figsoda <figsoda@pm.me>
Date: Fri, 26 May 2023 16:16:15 -0400

matchers.json: init
5 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/docs/src/api/matchers.md b/docs/src/api/matchers.md
@@ -41,6 +41,14 @@ Type: `String -> ({ self, super, root, ... } -> Path -> a }) -> Matcher`
 Matches files with the given extension.
 `matchers.extension "foo"` matches `a.foo` and `a.b.foo`, but not `.foo`.
 
+## `matchers.json`
+
+Source: [`src/matchers/json.nix`](https://github.com/nix-community/haumea/blob/main/src/matchers/json.nix)
+
+Type: `Matcher`
+
+Matches all JSON files and loads them using `lib.importJSON`.
+
 ## `matchers.nix`
 
 Source: [`src/matchers/nix.nix`](https://github.com/nix-community/haumea/blob/main/src/matchers/nix.nix)
diff --git a/src/matchers/json.nix b/src/matchers/json.nix
@@ -0,0 +1,3 @@
+{ lib, super }:
+
+super.extension "json" (_: lib.importJSON)
diff --git a/tests/matchers/__fixture/baz/bar.json b/tests/matchers/__fixture/baz/bar.json
@@ -0,0 +1,3 @@
+{
+  "answer": 42
+}
diff --git a/tests/matchers/expected.nix b/tests/matchers/expected.nix
@@ -4,6 +4,7 @@
   baz = {
     ".nix" = ./__fixture/baz/.nix;
     "foo.yml." = ./__fixture/baz/foo.yml.;
+    bar.answer = 42;
     me."me.yaml" = "baz.me";
   };
   rest = 42;
diff --git a/tests/matchers/expr.nix b/tests/matchers/expr.nix
@@ -27,6 +27,7 @@ haumea.load {
   loader = [
     (matchers.regex ''^(.+)\.(yaml|yml)$'' fakeLoadYaml)
     (matchers.nix haumea.loaders.default)
+    matchers.json
     (matchers.always haumea.loaders.path)
   ];
 }