mirror of
https://github.com/numtide/nix-filter.git
synced 2024-10-05 18:37:14 +03:00
Make it work
This commit is contained in:
parent
e404d1fd74
commit
a1e0618f4c
@ -32,7 +32,7 @@ want total control.
|
||||
stdenv.mkDerivation {
|
||||
name = "my-project";
|
||||
src = nix-filter {
|
||||
src = ./.;
|
||||
path = ./.;
|
||||
allow = [
|
||||
"src" # strings are automatically converted to ./src filter
|
||||
./package.json # paths are automatically converted to path filters
|
||||
|
45
default.nix
45
default.nix
@ -1,17 +1,4 @@
|
||||
# This is a pure and self-contained library
|
||||
let
|
||||
hasSuffix =
|
||||
# Suffix to check for
|
||||
suffix:
|
||||
# Input string
|
||||
content:
|
||||
let
|
||||
lenContent = builtins.length content;
|
||||
lenSuffix = builtins.length suffix;
|
||||
in
|
||||
lenContent >= lenSuffix &&
|
||||
builtins.substring (lenContent - lenSuffix) lenContent content == suffix;
|
||||
in
|
||||
rec {
|
||||
# Default to filter when calling this lib.
|
||||
__functor = self: filter;
|
||||
@ -37,12 +24,13 @@ rec {
|
||||
# sub-folders.
|
||||
toMatcher = f:
|
||||
let
|
||||
# Push these here to memoize the result
|
||||
path_ = toString f;
|
||||
path__ = "${toString path}/${f}";
|
||||
in
|
||||
if builtins.isFunction f then f
|
||||
else if builtins.isPath f then (path: type: path_ == toString path)
|
||||
else if builtins.isString f then (path: type: path__ == toString path)
|
||||
else if builtins.isPath f then (path: _: path_ == path)
|
||||
else if builtins.isString f then (path: _: path__ == path)
|
||||
else
|
||||
throw "Unsupported type ${builtins.typeOf f}";
|
||||
|
||||
@ -57,7 +45,30 @@ rec {
|
||||
};
|
||||
|
||||
# Match paths with the given extension
|
||||
byExt = ext:
|
||||
matchExt = ext:
|
||||
path: type:
|
||||
(hasSuffix ".${ext} " path);
|
||||
_hasSuffix ".${ext}" path;
|
||||
|
||||
# Used to debug matchers.
|
||||
debugMatch = label: fn:
|
||||
path: type:
|
||||
let
|
||||
ret = fn path type;
|
||||
in
|
||||
builtins.trace "label=${label} path=${path} type=${type} ret=${toString ret}"
|
||||
ret;
|
||||
|
||||
# Lib stuff
|
||||
|
||||
_hasSuffix =
|
||||
# Suffix to check for
|
||||
suffix:
|
||||
# Input string
|
||||
content:
|
||||
let
|
||||
lenContent = builtins.stringLength content;
|
||||
lenSuffix = builtins.stringLength suffix;
|
||||
in
|
||||
lenContent >= lenSuffix
|
||||
&& builtins.substring (lenContent - lenSuffix) lenContent content == suffix;
|
||||
}
|
||||
|
23
tests/default.nix
Normal file
23
tests/default.nix
Normal file
@ -0,0 +1,23 @@
|
||||
let
|
||||
nix-filter = import ../.;
|
||||
in
|
||||
{
|
||||
all = nix-filter {
|
||||
path = ./demo1;
|
||||
};
|
||||
|
||||
without-readme = nix-filter {
|
||||
path = ./demo1;
|
||||
deny = [
|
||||
"README.md"
|
||||
];
|
||||
};
|
||||
|
||||
with-matchExt = nix-filter {
|
||||
path = ./demo1;
|
||||
allow = [
|
||||
"package.json"
|
||||
(nix-filter.matchExt "js")
|
||||
];
|
||||
};
|
||||
}
|
0
tests/demo1/README.md
Normal file
0
tests/demo1/README.md
Normal file
0
tests/demo1/main.js
Normal file
0
tests/demo1/main.js
Normal file
0
tests/demo1/package.json
Normal file
0
tests/demo1/package.json
Normal file
Loading…
Reference in New Issue
Block a user