-
Notifications
You must be signed in to change notification settings - Fork 732
/
lint-turbo.mjs
43 lines (38 loc) · 1.22 KB
/
lint-turbo.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import assert from "assert";
import { execSync } from "child_process";
import { existsSync, readFileSync } from "fs";
import path from "path";
function readJson(filePath) {
return JSON.parse(readFileSync(filePath, "utf8"));
}
const listResult = execSync(
"pnpm --filter=!wrangler-root list --recursive --depth -1 --parseable"
);
const paths = listResult.toString().trim().split("\n");
for (const p of paths) {
if (!path.isAbsolute(p)) continue;
const pkg = readJson(path.join(p, "package.json"));
// Ensure all packages with a build script have a turbo build output configured
if (pkg.scripts?.build) {
console.log(pkg.name, "has build script. Checking turbo.json");
let turboConfig;
try {
turboConfig = readJson(path.join(p, "turbo.json"));
} catch {
console.log("Failed to read turbo.json for", pkg.name);
process.exit(1);
}
const buildOutputs = turboConfig.tasks.build.outputs;
assert(buildOutputs.length > 0);
}
// Ensure all packages with a vitest config file have a "test:ci" script
if (
existsSync(path.join(p, "vitest.config.ts")) ||
existsSync(path.join(p, "vitest.config.mts"))
) {
assert(
pkg.scripts["test:ci"],
`Package "${p}" is missing a "test:ci" script in package.json`
);
}
}