Files
scriptc/tests/harness/workspace-source.test.ts
Chris TateandYegor Shovkun 62b90e6d10 fix: compile TypeScript workspace sources (#344)
- Route source-only workspace package entries through the program module graph.

- Preserve JavaScript package resolution and add cross-backend workspace coverage.

- Document the workspace dependency boundary.

Fixes #187

Co-authored-by: Yegor Shovkun <6272356+ankhzet@users.noreply.github.com>
2026-09-17 18:26:20 -05:00

34 lines
1.2 KiB
TypeScript

import { execFile } from "node:child_process";
import { mkdirSync } from "node:fs";
import { join } from "node:path";
import { promisify } from "node:util";
import { expect, test } from "vitest";
import { compile } from "@scriptc/compiler";
const execFileAsync = promisify(execFile);
const repoRoot = join(import.meta.dirname, "../..");
const entry = join(repoRoot, "tests/fixtures/workspace-source/main.ts");
const cacheDir = join(repoRoot, "node_modules/.cache/scriptc-tests/workspace-source");
const sanitize = process.env["SCRIPTC_SAN"] === "1";
test.for(["c", "llvm"] as const)(
"a TypeScript-source workspace package compiles as program modules with the %s backend",
async (backend) => {
const outDir = join(cacheDir, `${backend}-${sanitize ? "san" : "plain"}`);
mkdirSync(outDir, { recursive: true });
const result = await compile(entry, {
outPath: join(outDir, "program"),
outDir,
backend,
sanitize,
});
if (!result.ok) {
throw new Error(result.diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join("\n"));
}
const { stdout } = await execFileAsync(result.binaryPath, [], { encoding: "utf8" });
expect(stdout).toBe("wssource:linked:6\n");
},
120_000,
);