Merge branch 'fix/perf-d01' into fix/perf-omo-in-tree
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
import { afterEach, describe, expect, test } from "bun:test";
|
||||||
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { randomUUID } from "node:crypto";
|
||||||
|
import { findRuleFilesRecursive } from "./rule-file-scanner";
|
||||||
|
|
||||||
|
const createdDirectories: string[] = [];
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const directory of createdDirectories.splice(0)) {
|
||||||
|
if (existsSync(directory)) {
|
||||||
|
rmSync(directory, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("findRuleFilesRecursive", () => {
|
||||||
|
test("returns rule files outside excluded nested directories", () => {
|
||||||
|
// given
|
||||||
|
const temporaryDirectory = join(tmpdir(), `perf-d01-${randomUUID()}`);
|
||||||
|
createdDirectories.push(temporaryDirectory);
|
||||||
|
|
||||||
|
const rulesDirectory = join(temporaryDirectory, ".sisyphus", "rules");
|
||||||
|
mkdirSync(join(rulesDirectory, "node_modules", "fake"), { recursive: true });
|
||||||
|
mkdirSync(join(rulesDirectory, ".git"), { recursive: true });
|
||||||
|
writeFileSync(join(rulesDirectory, "foo.md"), "root rule");
|
||||||
|
writeFileSync(
|
||||||
|
join(rulesDirectory, "node_modules", "fake", "x.md"),
|
||||||
|
"ignored node_modules rule",
|
||||||
|
);
|
||||||
|
writeFileSync(join(rulesDirectory, ".git", "x.md"), "ignored git rule");
|
||||||
|
|
||||||
|
const results: string[] = [];
|
||||||
|
|
||||||
|
// when
|
||||||
|
findRuleFilesRecursive(rulesDirectory, results);
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(results).toEqual([join(rulesDirectory, "foo.md")]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { existsSync, readdirSync, realpathSync } from "node:fs";
|
import { existsSync, readdirSync, realpathSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
import { EXCLUDED_DIRS } from "../../shared";
|
||||||
import { GITHUB_INSTRUCTIONS_PATTERN, RULE_EXTENSIONS } from "./constants";
|
import { GITHUB_INSTRUCTIONS_PATTERN, RULE_EXTENSIONS } from "./constants";
|
||||||
|
|
||||||
function isGitHubInstructionsDir(dir: string): boolean {
|
function isGitHubInstructionsDir(dir: string): boolean {
|
||||||
@@ -28,6 +29,7 @@ export function findRuleFilesRecursive(dir: string, results: string[]): void {
|
|||||||
const fullPath = join(dir, entry.name);
|
const fullPath = join(dir, entry.name);
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
|
if (EXCLUDED_DIRS.has(entry.name)) continue;
|
||||||
findRuleFilesRecursive(fullPath, results);
|
findRuleFilesRecursive(fullPath, results);
|
||||||
} else if (entry.isFile()) {
|
} else if (entry.isFile()) {
|
||||||
if (isValidRuleFile(entry.name, dir)) {
|
if (isValidRuleFile(entry.name, dir)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user