refactor(core-eslint): readManifestSource delegates to AST parser
This commit is contained in:
@@ -1,35 +1,16 @@
|
|||||||
import fs from "node:fs";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import { parseManifestFully } from "./_manifest-ast.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a feature.manifest.ts file and extracts the manifest's `name` field
|
* Reads a feature.manifest.ts and returns { name, requiredCores }.
|
||||||
* and `requiredCores` array via regex. Returns null if the file does not
|
* Backed by the AST parser from _manifest-ast.js — no longer uses regex.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* Returns: { name: string, requiredCores: string[] } | null
|
* Returns: { name: string, requiredCores: string[] } | null
|
||||||
*/
|
*/
|
||||||
export function readManifestSource(manifestPath) {
|
export function readManifestSource(manifestPath) {
|
||||||
let src;
|
const full = parseManifestFully(manifestPath);
|
||||||
try {
|
if (!full) return null;
|
||||||
src = fs.readFileSync(manifestPath, "utf8");
|
return { name: full.name, requiredCores: full.requiredCores };
|
||||||
} 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 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user