openclaw/scripts/lib/workspace-package-entries.mts
RoboClaw 5ae011b735
fix(build): package preparation fails on unrelated test types (#157318)
* fix(build): bound standalone package declaration graphs

Co-authored-by: steipete <58493+steipete@users.noreply.github.com>

* fix(build): migrate declaration producer audit and fixture consumers

Derive public audit roots from the existing canonical export mapper and supply the editor augmentation graph to maintained lint fixtures. Keep producer entries, public exports, diagnostics and runtime behavior unchanged.

Co-authored-by: steipete <58493+steipete@users.noreply.github.com>

---------

Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
2026-09-24 11:25:18 -07:00

30 lines
1.2 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
/** Canonical source entries for workspace packages with dist ESM exports. */
export function buildPackageDistEntriesFromExports(packageDir: string): Record<string, string> {
const packageJsonPath = path.join("packages", packageDir, "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) as {
exports?: Record<string, unknown>;
};
const entries: Record<string, string> = {};
for (const [exportKey, value] of Object.entries(packageJson.exports ?? {})) {
const entry =
exportKey === "." ? "index" : exportKey.startsWith("./") ? exportKey.slice(2) : "";
if (!entry || entry.includes("..")) {
continue;
}
const importPath =
typeof value === "object" && value !== null && !Array.isArray(value)
? (value as Record<string, unknown>).import
: value;
if (typeof importPath !== "string" || !importPath.startsWith("./dist/")) {
continue;
}
const sourcePath = importPath
.replace(/^\.\/dist\//u, `packages/${packageDir}/src/`)
.replace(/\.mjs$/u, ".ts");
entries[entry] = sourcePath;
}
return Object.fromEntries(Object.entries(entries).toSorted(([a], [b]) => a.localeCompare(b)));
}