70 lines
1.5 KiB
JavaScript
70 lines
1.5 KiB
JavaScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { spawnSync } from "node:child_process";
|
|
|
|
await mkdir("artifacts/quality", { recursive: true });
|
|
|
|
const pnpmCli = /** @type {string} */ (process.env.npm_execpath);
|
|
|
|
if (!pnpmCli) {
|
|
throw new Error("check:architecture must run through the pnpm script");
|
|
}
|
|
|
|
/** @param {string[]} arguments_ */
|
|
function runPnpm(arguments_) {
|
|
return spawnSync(process.execPath, [pnpmCli, ...arguments_], {
|
|
encoding: "utf8",
|
|
});
|
|
}
|
|
|
|
const production = runPnpm(
|
|
[
|
|
"exec",
|
|
"depcruise",
|
|
"src",
|
|
"--config",
|
|
".dependency-cruiser.cjs",
|
|
"--output-type",
|
|
"json",
|
|
],
|
|
);
|
|
|
|
await writeFile(
|
|
"artifacts/quality/dependency-report.json",
|
|
production.stdout || JSON.stringify({ summary: { errors: 1 } }),
|
|
);
|
|
|
|
if (production.status !== 0) {
|
|
process.stderr.write(
|
|
production.error?.message ?? production.stderr ?? production.stdout ?? "failed",
|
|
);
|
|
process.exit(production.status ?? 1);
|
|
}
|
|
|
|
const allowed = runPnpm(
|
|
[
|
|
"exec",
|
|
"eslint",
|
|
"tests/fixtures/architecture/allowed",
|
|
"--no-ignore",
|
|
"--max-warnings=0",
|
|
],
|
|
);
|
|
|
|
const forbidden = runPnpm(
|
|
[
|
|
"exec",
|
|
"eslint",
|
|
"tests/fixtures/architecture/forbidden",
|
|
"--no-ignore",
|
|
"--max-warnings=0",
|
|
],
|
|
);
|
|
|
|
if (allowed.status !== 0 || forbidden.status === 0) {
|
|
process.stderr.write(allowed.stderr || allowed.stdout);
|
|
process.stderr.write(forbidden.stderr || forbidden.stdout);
|
|
process.exit(1);
|
|
}
|
|
|
|
process.stdout.write("Architecture fixtures: allowed PASS, forbidden rejected\n");
|