build: one tsc -b build and a source export condition (P2.1)
- tsconfig.build.json references the nine in-scope packages; each package is composite and references the workspace packages it depends on. build:packages is now `tsc -b tsconfig.build.json` instead of a chain of cd commands. - Every in-scope package exports its TypeScript entry under a `source` condition next to the dist/ entries. Vitest, tsx (dev:server, the Tauri dev launch, the e2e server), the sidecar and launcher bundles and the web app resolve it, so none of them needs build:packages first or can pick up a stale dist/. The vitest src aliases remain only for the excluded packages that have no source export. - Published packages with a files list (agent, cli, marketplace) pack src/ too, so the source condition never points at a missing file. - tsconfig.tests.json and `npm run typecheck:tests` type-check the test suites of the in-scope packages. They report 426 existing errors, so the CI step is advisory for now. - The root test run leaves out the excluded and postponed packages (hive-mind-*, memory-mcp, wiki-compiler, team-server, waggle-dance, worker, weaver); they are not built either. - CI runs the test job on Ubuntu, macOS and Windows with Node 22.23.2 (ADR-0008), and no longer builds the hook runtime and the memory MCP server.
This commit is contained in:
@@ -1,35 +1,36 @@
|
||||
import { readdirSync, existsSync } from 'node:fs';
|
||||
import { readdirSync, existsSync, readFileSync } from 'node:fs';
|
||||
import { resolve, join } from 'node:path';
|
||||
|
||||
/**
|
||||
* Map every `@waggle/<dir>` workspace package to its TypeScript source entry
|
||||
* (`packages/<dir>/src/index.ts`) so vitest resolves them from source without
|
||||
* a build step.
|
||||
*
|
||||
* Why: several packages (shared, all hive-mind-*, cli, mcp-server) declare a
|
||||
* `dist/` entry in package.json `exports` — correct for publishing, but on a
|
||||
* fresh checkout (including CI) `dist/` isn't built, so importing them in tests
|
||||
* fails with "Failed to resolve entry for package". Aliasing to `src/` — the
|
||||
* same trick the former inline `@waggle/marketplace` alias used — makes the test
|
||||
* environment build-independent. Packages that already export `src/` (agent,
|
||||
* core, …) resolve to the same place, so the alias is a no-op for them.
|
||||
*
|
||||
* Only packages with a real `src/index.ts` are aliased (guarded), so dirs
|
||||
* without that entry (e.g. admin-web) are left to normal resolution.
|
||||
* Resolve conditions for the test runs: workspace packages export their
|
||||
* TypeScript source under the `source` condition (P2.1), so tests run against
|
||||
* src/ without a build step, the same way tsx and the sidecar bundle do.
|
||||
*/
|
||||
export const WAGGLE_SOURCE_CONDITIONS = ['source', 'module', 'node', 'development|production'];
|
||||
|
||||
/**
|
||||
* Map the `@waggle/<dir>` packages that do not export a `source` condition to
|
||||
* their `src/` directory. Only the packages excluded from the community
|
||||
* edition (hive-mind-*, memory-mcp, wiki-compiler and the postponed team
|
||||
* packages) still need this; it goes away with them.
|
||||
*
|
||||
* The alias target is the `src/` DIRECTORY (not `src/index.ts`): vite resolves
|
||||
* a bare `@waggle/x` import to the directory's index, AND a subpath import like
|
||||
* `@waggle/server/local/service` to `…/src/local/service`. Pointing at the file
|
||||
* instead would rewrite the subpath to `…/src/index.ts/local/service` and break.
|
||||
* `@waggle/x/scope` to `…/src/scope`.
|
||||
*/
|
||||
export function waggleSrcAliases(repoRoot: string): Record<string, string> {
|
||||
const pkgsDir = resolve(repoRoot, 'packages');
|
||||
const aliases: Record<string, string> = {};
|
||||
for (const dir of readdirSync(pkgsDir)) {
|
||||
const srcDir = join(pkgsDir, dir, 'src');
|
||||
if (existsSync(join(srcDir, 'index.ts'))) {
|
||||
aliases[`@waggle/${dir}`] = srcDir;
|
||||
}
|
||||
if (!existsSync(join(srcDir, 'index.ts')) || exportsSource(join(pkgsDir, dir, 'package.json'))) continue;
|
||||
aliases[`@waggle/${dir}`] = srcDir;
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
|
||||
function exportsSource(manifestPath: string): boolean {
|
||||
if (!existsSync(manifestPath)) return false;
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')) as { exports?: unknown };
|
||||
return JSON.stringify(manifest.exports ?? null).includes('"source"');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user