diff --git a/package-lock.json b/package-lock.json index cb74b89..342fe41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6495,6 +6495,8 @@ "ts-morph": "^23.0.0" }, "devDependencies": { + "@kidkender/archmind-laravel-parser": "*", + "@kidkender/archmind-springboot-parser": "*", "@types/jest": "^29.5.0", "@types/js-yaml": "^4.0.9", "@types/node": "^20.0.0", diff --git a/package.json b/package.json index 32891ad..522c144 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "apps/*" ], "scripts": { - "build": "npm run build --workspaces --if-present", + "build": "node scripts/build-workspaces.mjs", "test": "npm run test --workspaces --if-present", "trace": "node apps/cli/dist/index.js trace" }, diff --git a/packages/explainer/tsconfig.json b/packages/explainer/tsconfig.json index fa59074..1819e6a 100644 --- a/packages/explainer/tsconfig.json +++ b/packages/explainer/tsconfig.json @@ -5,5 +5,5 @@ "outDir": "dist" }, "include": ["src"], - "exclude": ["dist", "node_modules"] + "exclude": ["dist", "node_modules", "src/__tests__", "src/benchmark"] } diff --git a/packages/go-parser/src/scanner.ts b/packages/go-parser/src/scanner.ts index 13005a5..468885c 100644 --- a/packages/go-parser/src/scanner.ts +++ b/packages/go-parser/src/scanner.ts @@ -34,7 +34,7 @@ export function isGinProject(root: string): boolean { /** * Walks the project for every `*.go` file (excluding `_test.go` — test * files aren't part of the routing surface and only add noise), skipping - * vendor/build/VCS directories. Returns paths relative to `root`. + * vendor/build/VCS directories. Returns paths relative to `root`, with `/` separators on every OS. */ export function findGoFiles(root: string, opts: ScanOptions = {}): string[] { const out: string[] = [] @@ -63,7 +63,7 @@ function walk(root: string, dir: string, out: string[], depth: number, includeTe if (isDir) { walk(root, abs, out, depth + 1, includeTests) } else if (entry.endsWith(".go") && (includeTests || !entry.endsWith("_test.go"))) { - out.push(relative(root, abs)) + out.push(relative(root, abs).replace(/\\/g, "/")) } } } diff --git a/packages/lsp/build.mjs b/packages/lsp/build.mjs index 02e235b..a670af1 100644 --- a/packages/lsp/build.mjs +++ b/packages/lsp/build.mjs @@ -10,7 +10,10 @@ await build({ platform: "node", format: "cjs", outfile: join(__dirname, "dist/lsp.cjs"), - external: ["tree-sitter", "tree-sitter-php", "tree-sitter-java", "ts-morph"], + // analysis is loaded at runtime from its own install: it pulls in go-parser, + // which needs tree-sitter 0.25 and tree-sitter-go (a native module esbuild + // cannot bundle), while lsp itself runs tree-sitter 0.21. + external: ["tree-sitter", "tree-sitter-php", "tree-sitter-java", "ts-morph", "@kidkender/archmind-analysis"], banner: { js: "#!/usr/bin/env node" }, minify: false, }) diff --git a/packages/mcp-server/jest.config.js b/packages/mcp-server/jest.config.js index c158c8b..cfeae98 100644 --- a/packages/mcp-server/jest.config.js +++ b/packages/mcp-server/jest.config.js @@ -2,6 +2,10 @@ export default { preset: "ts-jest/presets/default-esm", testEnvironment: "node", + // The server's caches load the Laravel and Go parsers, whose module-level + // tree-sitter Parser intermittently fails when Jest reuses one worker process + // across test files (see packages/laravel-parser/jest.config.js). + maxWorkers: 50, extensionsToTreatAsEsm: [".ts"], testPathIgnorePatterns: ["/node_modules/", "/dist/"], moduleNameMapper: { diff --git a/packages/mcp-server/src/__tests__/cache.test.ts b/packages/mcp-server/src/__tests__/cache.test.ts index bc0bdb2..17deda6 100644 --- a/packages/mcp-server/src/__tests__/cache.test.ts +++ b/packages/mcp-server/src/__tests__/cache.test.ts @@ -440,12 +440,12 @@ describe("getGraphs() Go/Gin (integration)", () => { test("re-parses after a tracked file's mtime changes", () => { const { tmp, mainFile } = makeGinTmp() getGraphs(tmp) - const before = _getGoTrackedFiles(tmp)!.get(join("cmd", "server", "main.go"))! + const before = _getGoTrackedFiles(tmp)!.get("cmd/server/main.go")! bumpMtime(mainFile) getGraphs(tmp) - const after = _getGoTrackedFiles(tmp)!.get(join("cmd", "server", "main.go"))! + const after = _getGoTrackedFiles(tmp)!.get("cmd/server/main.go")! expect(after).toBeGreaterThan(before) }) diff --git a/packages/nestjs-parser/jest.config.js b/packages/nestjs-parser/jest.config.js index 29918b5..ae35050 100644 --- a/packages/nestjs-parser/jest.config.js +++ b/packages/nestjs-parser/jest.config.js @@ -2,6 +2,10 @@ export default { preset: "ts-jest/presets/default-esm", testEnvironment: "node", + // The cross-framework tests load the Laravel and Spring Boot parsers, whose + // module-level tree-sitter Parser intermittently fails when Jest reuses one + // worker process across test files (see packages/laravel-parser/jest.config.js). + maxWorkers: 50, extensionsToTreatAsEsm: [".ts"], testPathIgnorePatterns: ["/node_modules/", "/dist/", "/fixtures/"], moduleNameMapper: { diff --git a/packages/nestjs-parser/package.json b/packages/nestjs-parser/package.json index f5a3753..2914065 100644 --- a/packages/nestjs-parser/package.json +++ b/packages/nestjs-parser/package.json @@ -41,6 +41,8 @@ "ts-morph": "^23.0.0" }, "devDependencies": { + "@kidkender/archmind-laravel-parser": "*", + "@kidkender/archmind-springboot-parser": "*", "@types/jest": "^29.5.0", "@types/js-yaml": "^4.0.9", "@types/node": "^20.0.0", diff --git a/packages/retrieval/jest.config.js b/packages/retrieval/jest.config.js index c158c8b..04eb59f 100644 --- a/packages/retrieval/jest.config.js +++ b/packages/retrieval/jest.config.js @@ -2,6 +2,10 @@ export default { preset: "ts-jest/presets/default-esm", testEnvironment: "node", + // These tests load the Laravel / NestJS parsers, whose module-level tree-sitter + // Parser intermittently fails when Jest reuses one worker process across test + // files (see packages/laravel-parser/jest.config.js). One process per file. + maxWorkers: 50, extensionsToTreatAsEsm: [".ts"], testPathIgnorePatterns: ["/node_modules/", "/dist/"], moduleNameMapper: { diff --git a/scripts/build-workspaces.mjs b/scripts/build-workspaces.mjs new file mode 100644 index 0000000..69acaa6 --- /dev/null +++ b/scripts/build-workspaces.mjs @@ -0,0 +1,65 @@ +#!/usr/bin/env node +// Builds every workspace in dependency order. +// +// `npm run build --workspaces` builds in alphabetical order, so on a clean +// checkout (no dist/ yet) a package is compiled before the packages it imports +// — `aql` before `protocol` — and the build fails. This script orders the +// workspaces so each one is built after the workspaces it depends on. +// +// `dependencies` / `peerDependencies` are hard edges. `devDependencies` are soft: +// honored when possible, dropped only to get past a cycle (explainer's tests use +// scorer, and scorer → llm-client → prompt-builder → explainer). + +import { readFileSync, readdirSync, existsSync } from "fs" +import { join } from "path" +import { spawnSync } from "child_process" +import { fileURLToPath } from "url" + +const root = fileURLToPath(new URL("..", import.meta.url)) +const rootPkg = JSON.parse(readFileSync(join(root, "package.json"), "utf-8")) + +const workspaces = [] +for (const pattern of rootPkg.workspaces) { + const base = pattern.replace(/\/\*$/, "") + for (const name of readdirSync(join(root, base)).sort()) { + const dir = `${base}/${name}` + const pkgPath = join(root, dir, "package.json") + if (!existsSync(pkgPath)) continue + const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")) + workspaces.push({ dir, pkg }) + } +} + +const byName = new Map(workspaces.map((w) => [w.pkg.name, w])) +const internal = (deps) => Object.keys(deps ?? {}).filter((d) => byName.has(d)) +for (const w of workspaces) { + w.hard = new Set([...internal(w.pkg.dependencies), ...internal(w.pkg.peerDependencies)]) + w.soft = new Set(internal(w.pkg.devDependencies).filter((d) => !w.hard.has(d))) +} + +const order = [] +const done = new Set() +while (order.length < workspaces.length) { + const pending = workspaces.filter((w) => !done.has(w.pkg.name)) + const ready = (w, useSoft) => + [...w.hard].every((d) => done.has(d)) && (!useSoft || [...w.soft].every((d) => done.has(d))) + const next = pending.find((w) => ready(w, true)) ?? pending.find((w) => ready(w, false)) + if (!next) { + console.error(`Dependency cycle among: ${pending.map((w) => w.pkg.name).join(", ")}`) + process.exit(1) + } + order.push(next) + done.add(next.pkg.name) +} + +const npm = process.platform === "win32" ? "npm.cmd" : "npm" +for (const w of order) { + if (!w.pkg.scripts?.build) continue + console.log(`\n▶ ${w.pkg.name} (${w.dir})`) + const result = spawnSync(npm, ["run", "build", "-w", w.dir], { cwd: root, stdio: "inherit", shell: process.platform === "win32" }) + if (result.status !== 0) { + console.error(`\n✘ build failed in ${w.dir}`) + process.exit(result.status ?? 1) + } +} +console.log(`\n✔ built ${order.filter((w) => w.pkg.scripts?.build).length} workspaces`)