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
+42
View File
@@ -0,0 +1,42 @@
import { describe, it, expect } from "vitest";
import { extractFileAST } from "../src/ast-extract.js";
import { mkdtempSync, writeFileSync } from "fs";
import { join } from "path";
import { tmpdir } from "os";
describe("ast-extract", () => {
it("extracts TypeScript exports and imports", async () => {
const dir = mkdtempSync(join(tmpdir(), "pi-map-ast-"));
const file = join(dir, "test.ts");
writeFileSync(
file,
`import { foo } from "./bar";
import type { Qux } from "qux-lib";
export function hello() {}
export class MyClass {}
export const value = 1;
export interface Config {}
export type MyType = string;
export { foo as renamedFoo };
`,
);
const result = await extractFileAST(file);
expect(result).not.toBeNull();
expect(result!.exports).toContain("hello");
expect(result!.exports).toContain("MyClass");
expect(result!.exports).toContain("value");
expect(result!.exports).toContain("Config");
expect(result!.exports).toContain("MyType");
expect(result!.deps).toContain("./bar");
expect(result!.deps).toContain("qux-lib");
});
it("returns null for unsupported languages", async () => {
const dir = mkdtempSync(join(tmpdir(), "pi-map-ast-"));
const file = join(dir, "test.xyz");
writeFileSync(file, `some content`);
const result = await extractFileAST(file);
expect(result).toBeNull();
});
});