ProvenPin Install

ignore gitignore-style path filter: working versions (tested 2026-10-16)

Apply gitignore-style rules (directory patterns, negation) to a list of paths with the ignore package, using ignores, filter and createFilter offline.

passed6 passed · 0 failed2026-10-16 17:50 UTC
Status
passed
Last passed
2026-10-16 17:50 UTC
Tests
6 / 6
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
ignore@7.0.12@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38942732901

The code

Exactly the files that passed. Your agent can pull them with get_recipe("ignore-gitignore-filter") (install), or see them on GitHub.

package.json
{
  "name": "ignore-gitignore-filter",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "ignore": "7.0.12"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/filter.ts
import ignore from "ignore";

export type IgnoreInstance = ReturnType<typeof ignore>;

export const DEFAULT_PATTERNS = [
  "node_modules/",
  "dist/",
  "coverage/",
  "*.log",
  "!important.log",
];

export function createIgnoreFilter(
  patterns: readonly string[] = DEFAULT_PATTERNS,
): IgnoreInstance {
  return ignore().add([...patterns]);
}

export function isIgnored(
  patterns: readonly string[],
  pathname: string,
): boolean {
  return createIgnoreFilter(patterns).ignores(pathname);
}

export function filterPaths(
  patterns: readonly string[],
  paths: readonly string[],
): string[] {
  return createIgnoreFilter(patterns).filter([...paths]);
}

export function partitionPaths(
  patterns: readonly string[],
  paths: readonly string[],
): { kept: string[]; ignored: string[] } {
  const ig = createIgnoreFilter(patterns);
  const kept: string[] = [];
  const ignored: string[] = [];
  for (const pathname of paths) {
    if (ig.ignores(pathname)) {
      ignored.push(pathname);
    } else {
      kept.push(pathname);
    }
  }
  return { kept, ignored };
}

export function makePathTest(
  patterns: readonly string[] = DEFAULT_PATTERNS,
): (pathname: string) => boolean {
  return createIgnoreFilter(patterns).createFilter();
}
test/filter.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import {
  DEFAULT_PATTERNS,
  createIgnoreFilter,
  filterPaths,
  isIgnored,
  makePathTest,
  partitionPaths,
} from "../src/filter.ts";

test("directory pattern ignores every file below it", () => {
  const ig = createIgnoreFilter(DEFAULT_PATTERNS);
  assert.equal(ig.ignores("node_modules/pkg/index.js"), true);
  assert.equal(ig.ignores("dist/bundle.js"), true);
  assert.equal(ig.ignores("coverage/lcov.info"), true);
  assert.equal(ig.ignores("src/distractor.ts"), false);
});

test("glob pattern matches at any depth", () => {
  assert.equal(isIgnored(DEFAULT_PATTERNS, "server.log"), true);
  assert.equal(isIgnored(DEFAULT_PATTERNS, "logs/deep/server.log"), true);
  assert.equal(isIgnored(DEFAULT_PATTERNS, "src/server.ts"), false);
});

test("negation keeps a previously ignored file", () => {
  assert.equal(isIgnored(DEFAULT_PATTERNS, "debug.log"), true);
  assert.equal(isIgnored(DEFAULT_PATTERNS, "important.log"), false);
});

test("filter returns only kept paths", () => {
  const paths = [
    "src/index.ts",
    "dist/bundle.js",
    "node_modules/ignore/index.js",
    "debug.log",
    "important.log",
    "coverage/lcov.info",
  ];
  assert.deepEqual(filterPaths(DEFAULT_PATTERNS, paths), [
    "src/index.ts",
    "important.log",
  ]);
});

test("partitionPaths splits ignored from kept", () => {
  const paths = ["src/index.ts", "dist/bundle.js", "important.log"];
  assert.deepEqual(partitionPaths(DEFAULT_PATTERNS, paths), {
    kept: ["src/index.ts", "important.log"],
    ignored: ["dist/bundle.js"],
  });
});

test("createFilter is a reusable boolean predicate", () => {
  const kept = makePathTest(DEFAULT_PATTERNS);
  assert.equal(kept("src/main.ts"), true);
  assert.equal(kept("dist/main.js"), false);
  const selected = ["src/a.ts", "dist/a.js", "trace.log", "important.log"].filter(
    kept,
  );
  assert.deepEqual(selected, ["src/a.ts", "important.log"]);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.