ProvenPin Install

globby ignore patterns: working versions (tested 2026-10-16)

Match files under a temp directory with globby using patterns, ignore, absolute and onlyFiles, asserting sorted paths and excluded files offline.

passed3 passed · 0 failed2026-10-16 15:20 UTC
Status
passed
Last passed
2026-10-16 15:20 UTC
Tests
3 / 3
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
globby@16.2.4@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 38923127324

The code

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

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

export type MatchOptions = {
  patterns: string[];
  ignore?: string[];
  absolute?: boolean;
  onlyFiles?: boolean;
};

export async function matchFiles(cwd: string, options: MatchOptions): Promise<string[]> {
  const matches = await globby(options.patterns, {
    cwd,
    ignore: options.ignore,
    absolute: options.absolute,
    onlyFiles: options.onlyFiles ?? true,
  });
  return matches.map((match) => match.split("\\").join("/")).sort();
}
test/match.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { matchFiles } from "../src/match.ts";

async function makeTree(): Promise<string> {
  const root = await mkdtemp(join(tmpdir(), "globby-recipe-"));
  await mkdir(join(root, "src"), { recursive: true });
  await mkdir(join(root, "dist"), { recursive: true });
  await writeFile(join(root, "src", "a.ts"), "export const a = 1;\n");
  await writeFile(join(root, "src", "b.ts"), "export const b = 2;\n");
  await writeFile(join(root, "src", "c.test.ts"), "test\n");
  await writeFile(join(root, "dist", "a.ts"), "built\n");
  await writeFile(join(root, "README.md"), "# hi\n");
  return root;
}

test("returns sorted relative paths and excludes ignored files", async () => {
  const root = await makeTree();
  try {
    const paths = await matchFiles(root, {
      patterns: ["**/*.ts"],
      ignore: ["**/*.test.ts", "dist/**"],
    });
    assert.deepEqual(paths, ["src/a.ts", "src/b.ts"]);
  } finally {
    await rm(root, { recursive: true, force: true });
  }
});

test("returns absolute paths when absolute is true", async () => {
  const root = await makeTree();
  try {
    const paths = await matchFiles(root, {
      patterns: ["src/*.ts"],
      ignore: ["**/*.test.ts"],
      absolute: true,
    });
    assert.deepEqual(paths, [join(root, "src", "a.ts"), join(root, "src", "b.ts")].sort());
    for (const p of paths) {
      assert.ok(p.startsWith(root), `${p} should start with ${root}`);
    }
  } finally {
    await rm(root, { recursive: true, force: true });
  }
});

test("onlyFiles excludes directories from results", async () => {
  const root = await makeTree();
  try {
    const paths = await matchFiles(root, {
      patterns: ["**/*"],
      onlyFiles: true,
    });
    assert.ok(paths.length > 0);
    assert.ok(!paths.includes("src"));
    assert.ok(!paths.includes("dist"));
    assert.deepEqual(
      paths,
      ["README.md", "dist/a.ts", "src/a.ts", "src/b.ts", "src/c.test.ts"].sort(),
    );
  } finally {
    await rm(root, { recursive: true, force: true });
  }
});

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.