Skip to content

Commit 6dd92c9

Browse files
fix(cli): scan modern module extensions
## Summary Include modern JavaScript and TypeScript module extensions in the repo-wide CLI source scan so `codecontext --report` sees tagged files. ## Changes - add `.mjs`, `.cjs`, `.mts`, and `.cts` to the CLI source matcher - add a CLI regression test covering modern module extensions in repo scans ## Testing - pnpm --filter @recallnet/codecontext-cli test fixes #3
1 parent b18877d commit 6dd92c9

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

packages/cli/src/files.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { join } from "node:path";
33

44
const IGNORED_DIRS = new Set([".git", ".turbo", "coverage", "dist", "node_modules"]);
55

6-
const SOURCE_EXTENSIONS = /\.(ts|tsx|js|jsx|py|rs|go|java|c|cpp|h|hpp|rb|swift|kt)$/;
6+
const SOURCE_EXTENSIONS =
7+
/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs|py|rs|go|java|c|cpp|h|hpp|rb|swift|kt)$/;
78

89
export function isSourceFile(relativePath: string): boolean {
910
return SOURCE_EXTENSIONS.test(relativePath);

packages/cli/test/files.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
2+
import { join } from "node:path";
3+
import { tmpdir } from "node:os";
4+
5+
import { afterEach, describe, expect, it } from "vitest";
6+
7+
import { findSourceFiles, isSourceFile } from "../src/files.js";
8+
9+
const tempDirs: string[] = [];
10+
11+
afterEach(() => {
12+
for (const dir of tempDirs.splice(0)) {
13+
rmSync(dir, { recursive: true, force: true });
14+
}
15+
});
16+
17+
describe("isSourceFile", () => {
18+
it("matches modern JS and TS module extensions", () => {
19+
expect(isSourceFile("src/entry.mjs")).toBe(true);
20+
expect(isSourceFile("src/entry.cjs")).toBe(true);
21+
expect(isSourceFile("src/entry.mts")).toBe(true);
22+
expect(isSourceFile("src/entry.cts")).toBe(true);
23+
});
24+
});
25+
26+
describe("findSourceFiles", () => {
27+
it("includes modern JS and TS module extensions in repo scans", () => {
28+
const root = mkdtempSync(join(tmpdir(), "codecontext-cli-files-"));
29+
tempDirs.push(root);
30+
31+
mkdirSync(join(root, "src"), { recursive: true });
32+
writeFileSync(join(root, "src", "entry.mjs"), "// @context decision - ESM module\n");
33+
writeFileSync(join(root, "src", "entry.cjs"), "// @context decision - CommonJS module\n");
34+
writeFileSync(join(root, "src", "entry.mts"), "// @context decision - TS ESM module\n");
35+
writeFileSync(join(root, "src", "entry.cts"), "// @context decision - TS CJS module\n");
36+
writeFileSync(join(root, "src", "ignored.md"), "@context decision - not a source file\n");
37+
38+
expect(findSourceFiles(root)).toEqual([
39+
join(root, "src", "entry.cjs"),
40+
join(root, "src", "entry.cts"),
41+
join(root, "src", "entry.mjs"),
42+
join(root, "src", "entry.mts"),
43+
]);
44+
});
45+
});

0 commit comments

Comments
 (0)