feat(core-eslint): workspace helper for conformance rules

This commit is contained in:
2026-05-12 23:19:11 +02:00
parent 41ffe9f787
commit 6f8e75accb
2 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import fs from "node:fs";
import path from "node:path";
/**
* Reads the `packages:` list from `pnpm-workspace.yaml` at the given repo
* root. Returns an array of package glob strings (e.g. ["apps/*", "packages/*"]).
* Returns [] when the file is missing or has no `packages:` key.
*
* Uses regex extraction over YAML parsing to avoid a `js-yaml` dependency;
* the `packages:` block in pnpm-workspace.yaml has a stable, well-known
* shape and this approach is sufficient.
*/
export function readWorkspacePackages(repoRoot) {
const yamlPath = path.join(repoRoot, "pnpm-workspace.yaml");
let src;
try {
src = fs.readFileSync(yamlPath, "utf8");
} catch {
return [];
}
const blockMatch = src.match(/^packages:\s*\n((?:\s+-\s+.+\n?)+)/m);
if (!blockMatch) return [];
return blockMatch[1]
.split("\n")
.map((line) => line.match(/^\s+-\s+"?([^"]+?)"?\s*$/))
.filter((m) => m !== null)
.map((m) => m[1]);
}