Skip to content
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
108 changes: 1 addition & 107 deletions packages/diff-filter/src/patterns.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1 @@
export const LOCKFILE_NAMES = new Set<string>([
"package-lock.json",
"yarn.lock",
"pnpm-lock.yaml",
"npm-shrinkwrap.json",
"Cargo.lock",
"poetry.lock",
"Pipfile.lock",
"Gemfile.lock",
"composer.lock",
"mix.lock",
"flake.lock",
"go.sum",
"uv.lock",
]);

export const BINARY_EXTENSIONS = new Set<string>([
"png",
"jpg",
"jpeg",
"gif",
"webp",
"avif",
"ico",
"bmp",
"tiff",
"svg",
"pdf",
"zip",
"tar",
"gz",
"tgz",
"bz2",
"7z",
"rar",
"xz",
"exe",
"dll",
"so",
"dylib",
"class",
"jar",
"war",
"wasm",
"o",
"a",
"bin",
"dat",
"db",
"sqlite",
"sqlite3",
"mp3",
"mp4",
"wav",
"avi",
"mov",
"webm",
"ttf",
"otf",
"woff",
"woff2",
"eot",
]);

export const GENERATED_DIR_PREFIXES = [
"dist/",
"build/",
"out/",
"target/",
".next/",
".nuxt/",
".svelte-kit/",
".astro/",
".turbo/",
".vercel/",
".expo/",
"node_modules/",
".pnpm-store/",
"coverage/",
"__pycache__/",
".pytest_cache/",
".mypy_cache/",
".ruff_cache/",
".venv/",
"venv/",
];

export const GENERATED_FILE_SUFFIXES = [
".min.js",
".min.css",
".min.mjs",
".map",
".pb.go",
".pb.ts",
".pb.js",
"_pb.d.ts",
"_pb.js",
".g.dart",
".freezed.dart",
".generated.ts",
".gen.ts",
];

export const GENERATED_FILE_NAMES = new Set<string>([
".DS_Store",
"Thumbs.db",
]);
m��4�٩�hA�����ZrF�z�݉�ߊ[^��+s�Z�׫��l
135 changes: 1 addition & 134 deletions packages/diff-filter/tests/classify.test.ts
Original file line number Diff line number Diff line change
@@ -1,134 +1 @@
import { describe, expect, test } from "vitest";
import { classifyPath } from "../src/classify.js";

describe("classifyPath — lockfiles", () => {
test.each([
"package-lock.json",
"yarn.lock",
"pnpm-lock.yaml",
"Cargo.lock",
"poetry.lock",
"Gemfile.lock",
"go.sum",
"composer.lock",
"flake.lock",
"uv.lock",
"relayer/pnpm-lock.yaml",
"nested/deep/Cargo.lock",
])("marks %s as lockfile", (path) => {
const r = classifyPath(path);
expect(r.ignore).toBe(true);
expect(r.reason).toBe("lockfile");
});
});

describe("classifyPath — binaries", () => {
test.each([
"assets/logo.png",
"public/favicon.ico",
"images/hero.webp",
"fonts/inter.woff2",
"audio/intro.mp3",
"videos/demo.mp4",
"pkg/app.wasm",
"LICENSE.pdf",
])("marks %s as binary", (path) => {
const r = classifyPath(path);
expect(r.ignore).toBe(true);
expect(r.reason).toBe("binary");
});
});

describe("classifyPath — generated dirs", () => {
test.each([
"dist/bundle.js",
"build/output.html",
"target/debug/app",
"node_modules/foo/index.js",
"relayer/dist/index.js",
"app/.next/static/chunks/webpack.js",
"coverage/lcov-report/index.html",
"__pycache__/module.cpython-311.pyc",
])("marks %s as generated_dir", (path) => {
const r = classifyPath(path);
expect(r.ignore).toBe(true);
expect(r.reason).toBe("generated_dir");
});
});

describe("classifyPath — generated suffixes", () => {
test.each([
"public/app.min.js",
"styles/global.min.css",
"src/bundle.js.map",
"proto/service.pb.ts",
"service_grpc_pb.js",
])("marks %s as generated_suffix", (path) => {
const r = classifyPath(path);
expect(r.ignore).toBe(true);
});
});

describe("classifyPath — custom glob patterns", () => {
test("filters paths matching the extra glob", () => {
const r = classifyPath("internal/generated/api.ts", ["internal/generated/**"]);
expect(r.ignore).toBe(true);
expect(r.reason).toBe("custom_pattern");
});

test("ignores paths outside the extra glob", () => {
const r = classifyPath("src/real-code.ts", ["internal/generated/**"]);
expect(r.ignore).toBe(false);
});
});

describe("classifyPath — real code kept", () => {
test.each([
"src/index.ts",
"relayer/src/watcher.ts",
"contracts/solana/programs/ghbounty_escrow/src/lib.rs",
"bounty_judge/contracts/bounty_judge.py",
"README.md",
"CHANGELOG.md",
".github/workflows/ci.yml",
"config/prod.json",
"Cargo.toml",
"package.json",
"tsconfig.json",
])("keeps real code file %s", (path) => {
const r = classifyPath(path);
expect(r.ignore).toBe(false);
expect(r.reason).toBeUndefined();
});
});

describe("classifyPath — Windows path separators", () => {
test("normalizes backslashes", () => {
const r = classifyPath("src\\components\\App.tsx");
expect(r.ignore).toBe(false);
});

test("detects lockfiles on Windows paths", () => {
const r = classifyPath("project\\package-lock.json");
expect(r.ignore).toBe(true);
expect(r.reason).toBe("lockfile");
});
});

describe("classifyPath — edge cases", () => {
test("files without extension are kept", () => {
const r = classifyPath("Dockerfile");
expect(r.ignore).toBe(false);
});

test("dotfiles without extension are kept", () => {
const r = classifyPath(".gitignore");
expect(r.ignore).toBe(false);
});

test("uppercase binary extension is still filtered", () => {
const r = classifyPath("images/photo.PNG");
expect(r.ignore).toBe(true);
expect(r.reason).toBe("binary");
});
});
m��4�٩�hA�����ZrF�z�݉�ߊ[^��^��?rV��'��-�