Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
describe("dep-graph: runtime @suaveplan/* deps", () => {
it("only depends on @suaveplan/error and @suaveplan/types", {
timeout: 5000,
}, () => {
const pkgPath = join(import.meta.dirname, "..", "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")) as {
dependencies?: Record<string, string>;
};
const suaveDeps = Object.keys(pkg.dependencies ?? {})
.filter((dep) => dep.startsWith("@suaveplan/"))
.sort();
expect(suaveDeps).toEqual(
["@suaveplan/error", "@suaveplan/types"].sort()
);
});
});

View File

@@ -0,0 +1,69 @@
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const DISALLOWED_PATTERNS = [
"node:fs",
"node:path",
"node:url",
"process.env",
"Buffer",
"document.",
"window.",
];
// Allow ReadableStream (Web Streams API — explicitly permitted)
function walkDir(dir: string, results: string[] = []): string[] {
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
if (statSync(full).isDirectory()) {
if (
entry !== "__benchmarks__" &&
entry !== "node_modules" &&
entry !== "dist"
) {
walkDir(full, results);
}
} else if (
full.endsWith(".ts") &&
!full.endsWith(".test.ts") &&
!full.endsWith(".bench.ts") &&
!full.endsWith(".types.ts")
) {
results.push(full);
}
}
return results;
}
describe("no-disallowed: source files must not use banned APIs", () => {
it("source files do not use node:fs, node:path, node:url, process.env, Buffer, document, window", {
timeout: 10000,
}, () => {
const srcDir = join(import.meta.dirname, "..", "src");
const files = walkDir(srcDir);
const violations: string[] = [];
for (const file of files) {
const content = readFileSync(file, "utf-8");
const relativePath = file.split("/src/")[1] ?? file;
for (const pattern of DISALLOWED_PATTERNS) {
if (content.includes(pattern)) {
violations.push(`${relativePath}: contains "${pattern}"`);
}
}
}
if (violations.length > 0) {
throw new Error(
`Disallowed patterns found in source:\n${violations.join("\n")}`
);
}
// At least checked one file
expect(files.length).toBeGreaterThan(0);
});
});

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,27 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
describe("tree-shake: main bundle isolation", () => {
it("package.json has sideEffects: false", { timeout: 5000 }, () => {
const pkgPath = join(import.meta.dirname, "..", "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")) as {
sideEffects?: boolean;
};
expect(pkg.sideEffects).toBe(false);
});
it("dist/index.js does not reference serialize-javascript", {
timeout: 5000,
}, () => {
const distPath = join(import.meta.dirname, "..", "dist", "index.js");
let content: string;
try {
content = readFileSync(distPath, "utf-8");
} catch {
// Build hasn't run yet in test-only mode — skip gracefully.
return;
}
expect(content).not.toContain("serialize-javascript");
});
});