42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const SRC_ROOT = join(__dirname, "..", "src");
|
|
|
|
function walkTypescript(dir: string): string[] {
|
|
const entries = readdirSync(dir);
|
|
const files: string[] = [];
|
|
for (const entry of entries) {
|
|
const full = join(dir, entry);
|
|
const st = statSync(full);
|
|
if (st.isDirectory()) {
|
|
files.push(...walkTypescript(full));
|
|
} else if (
|
|
entry.endsWith(".ts") &&
|
|
!entry.endsWith(".test.ts") &&
|
|
!entry.endsWith(".spec.ts")
|
|
) {
|
|
files.push(full);
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
describe("universal dep graph", () => {
|
|
it("src contains no node/bun/fs/path/stream/net/http/crypto imports", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const banned =
|
|
/from\s+['"](node:|bun:|fs|path|stream|net|http|crypto)['"]/;
|
|
const offenders: string[] = [];
|
|
for (const file of walkTypescript(SRC_ROOT)) {
|
|
const text = readFileSync(file, "utf8");
|
|
if (banned.test(text)) {
|
|
offenders.push(file);
|
|
}
|
|
}
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
});
|