openclaw/scripts/lib/npm-json-output.mts
Peter Steinberger a162944f54
improve(release): prepare publication artifacts during validation (#135639)
* perf(release): prepare publication artifacts during validation

* fix(release): scope npm registry environment restoration

* test(ci): align release artifact verification fixtures

Account for newly tracked artifact tests and internal workflow-only inputs. Keep synthetic runner timing checks independent of unrelated suite budgets. Reuse the catalog-row selector fix already landed in #135597.

* fix(release): preserve correction identity across prepared artifacts
2026-09-01 18:41:09 -07:00

33 lines
1.2 KiB
TypeScript

/**
* Normalize npm <=11 entry/array JSON and npm 12 name-keyed JSON.
* Keep pack consumers on one dependency-contract boundary so a package-manager
* upgrade cannot silently bypass release, installer, or security checks.
*/
export function resolveNpmJsonEntries(value: unknown): unknown[] {
if (Array.isArray(value)) {
return value;
}
if (value && typeof value === "object") {
const looksLikeEntry =
("id" in value && typeof value.id === "string") ||
("name" in value && typeof value.name === "string") ||
("version" in value && typeof value.version === "string") ||
("filename" in value && typeof value.filename === "string");
if (!looksLikeEntry) {
const entries = Object.values(value).filter(
(entry) => Boolean(entry) && typeof entry === "object" && !Array.isArray(entry),
);
if (entries.length > 0) {
return entries;
}
}
}
return [value];
}
/** npm 12 keeps scalar view results in an array; exact-package reads require one value. */
export function resolveNpmJsonString(value: unknown): string {
const entries = resolveNpmJsonEntries(value);
const entry = entries.length === 1 ? entries[0] : undefined;
return typeof entry === "string" ? entry.trim() : "";
}