ab45859d65
- 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.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
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();
|
|
});
|
|
});
|