Add AST extraction tests, broader ignore patterns, build dist

- ast-extract.ts: Support tree-sitter-python and tree-sitter-go grammar
  loading (pkg.language fallback)
- discover.ts: Add cache directories to default ignore (.cache, tmp,
  temp, .turbo, .parcel-cache, .eslintcache, .prettiercache)
- tests: Add TypeScript AST extraction tests (exports + imports)
- Verified on real project: media_library_viewer (196 .pi-map.md files)
  with accurate React component extraction
- Build: npm run build produces clean dist/ output

All 16 tests pass.
This commit is contained in:
2026-06-09 19:25:56 +02:00
parent 3dbb3cb7b2
commit ab45859d65
6 changed files with 111 additions and 16 deletions
+17 -15
View File
@@ -1,5 +1,11 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { mkdtempSync, writeFileSync, mkdirSync, rmSync, readFileSync } from "fs";
import {
mkdtempSync,
writeFileSync,
mkdirSync,
rmSync,
readFileSync,
} from "fs";
import { join } from "path";
import { tmpdir } from "os";
import { initProject } from "../src/init.js";
@@ -19,10 +25,7 @@ describe("integration", () => {
it("init creates .pi-map.md files", async () => {
mkdirSync(join(dir, "src"));
writeFileSync(
join(dir, "src", "index.ts"),
`export function foo() {}\n`,
);
writeFileSync(join(dir, "src", "index.ts"), `export function foo() {}\n`);
await initProject(dir);
const map = readFileSync(join(dir, "src", ".pi-map.md"), "utf8");
@@ -32,14 +35,8 @@ describe("integration", () => {
it("patch updates a file entry", async () => {
mkdirSync(join(dir, "src"));
writeFileSync(
join(dir, "src", "index.ts"),
`export function foo() {}\n`,
);
writeFileSync(
join(dir, "src", "utils.ts"),
`export const bar = 1;\n`,
);
writeFileSync(join(dir, "src", "index.ts"), `export function foo() {}\n`);
writeFileSync(join(dir, "src", "utils.ts"), `export const bar = 1;\n`);
await initProject(dir);
// Modify a file
@@ -110,10 +107,15 @@ describe("integration", () => {
await initProject(dir);
// Change exports
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\nexport const c = 3;\n`);
writeFileSync(
join(dir, "src", "a.ts"),
`export const a = 1;\nexport const c = 3;\n`,
);
const result = await validateMaps(dir);
expect(result.clean).toBe(false);
expect(result.discrepancies.some((d) => d.type === "stale-signature")).toBe(true);
expect(result.discrepancies.some((d) => d.type === "stale-signature")).toBe(
true,
);
});
});