refactor(core-eslint): readManifestSource delegates to AST parser

This commit is contained in:
2026-05-13 07:34:00 +02:00
parent d83d97755e
commit 171ed20527

View File

@@ -1,35 +1,16 @@
import fs from "node:fs";
import path from "node:path";
import { parseManifestFully } from "./_manifest-ast.js";
/**
* Reads a feature.manifest.ts file and extracts the manifest's `name` field
* and `requiredCores` array via regex. Returns null if the file does not
* exist or does not match the expected literal `as const` manifest shape.
*
* The repo's convention is that every feature.manifest.ts uses defineFeature
* with literal `as const` syntax — this is enforced by the type-system
* design (defineFeature has `<const M>` to preserve literal types). The
* regex extraction is therefore safe; the AST path is overkill.
* Reads a feature.manifest.ts and returns { name, requiredCores }.
* Backed by the AST parser from _manifest-ast.js — no longer uses regex.
*
* Returns: { name: string, requiredCores: string[] } | null
*/
export function readManifestSource(manifestPath) {
let src;
try {
src = fs.readFileSync(manifestPath, "utf8");
} catch {
return null;
}
const nameMatch = src.match(/name:\s*"([^"]+)"/);
if (!nameMatch) return null;
const coresMatch = src.match(/requiredCores:\s*\[([^\]]*)\]/);
const cores = coresMatch
? coresMatch[1]
.split(",")
.map((s) => s.trim().replace(/^"/, "").replace(/"$/, ""))
.filter((s) => s.length > 0)
: [];
return { name: nameMatch[1], requiredCores: cores };
const full = parseManifestFully(manifestPath);
if (!full) return null;
return { name: full.name, requiredCores: full.requiredCores };
}
/**