mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
fix: chord boundary test allows pi-telemetry, the dependency of Context.telemetry
This commit is contained in:
parent
48909d987a
commit
1402973a9d
1 changed files with 12 additions and 5 deletions
|
|
@ -8,13 +8,18 @@ const sourceDirectory = resolve(packageDirectory, "src");
|
|||
const IMPORT_SPECIFIER = /(?:import|export)\s+(?:type\s+)?(?:[^;]*?\sfrom\s*)?["']([^"']+)["']/gu;
|
||||
|
||||
describe("package boundary", () => {
|
||||
test("does not depend on Pi packages or files outside Chord", async () => {
|
||||
// pi-telemetry is the one allowed Pi package: a leaf without dependencies, needed for Context.telemetry.
|
||||
const ALLOWED = new Set(["@earendil-works/pi-telemetry"]);
|
||||
|
||||
test("does not depend on Pi packages other than pi-telemetry, or on files outside Chord", async () => {
|
||||
const manifest = JSON.parse(await readFile(resolve(packageDirectory, "package.json"), "utf8")) as {
|
||||
dependencies?: Record<string, string>;
|
||||
};
|
||||
expect(Object.keys(manifest.dependencies ?? {}).filter((name) => name.startsWith("@earendil-works/pi-"))).toEqual(
|
||||
[],
|
||||
);
|
||||
expect(
|
||||
Object.keys(manifest.dependencies ?? {}).filter(
|
||||
(name) => name.startsWith("@earendil-works/pi-") && !ALLOWED.has(name),
|
||||
),
|
||||
).toEqual([]);
|
||||
|
||||
const paths = (await readdir(sourceDirectory, { recursive: true })).filter((path) => path.endsWith(".ts")).sort();
|
||||
const violations: string[] = [];
|
||||
|
|
@ -23,7 +28,9 @@ describe("package boundary", () => {
|
|||
const source = await readFile(file, "utf8");
|
||||
for (const match of source.matchAll(IMPORT_SPECIFIER)) {
|
||||
const specifier = match[1]!;
|
||||
if (specifier.startsWith("@earendil-works/pi-")) violations.push(`${path}: ${specifier}`);
|
||||
const pkg = specifier.split("/").slice(0, 2).join("/");
|
||||
if (specifier.startsWith("@earendil-works/pi-") && !ALLOWED.has(pkg))
|
||||
violations.push(`${path}: ${specifier}`);
|
||||
if (specifier.startsWith(".") && !resolve(dirname(file), specifier).startsWith(`${sourceDirectory}/`)) {
|
||||
violations.push(`${path}: ${specifier}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue