UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

76 lines (74 loc) • 3.65 kB
const require_catalog_overrides = require("../workspace/catalog-overrides.cjs"); let node_fs = require("node:fs"); let node_path = require("node:path"); //#region src/services/scaffold/install-remediation.ts const FRAMEWORK_OFFENDER_NAMES = require_catalog_overrides.FRAMEWORK_EXCLUDE_PACKAGES; /** * Parse pnpm's `ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION` output for the * offending `name@version` entries — the lockfile entries the active * supply-chain holdback rejected. */ function classifyReleaseAgeViolation(output) { const offenders = []; for (const match of output.matchAll(/^\s*([@a-zA-Z0-9/._-]+)@(\d\S*?)\s+was published at/gm)) offenders.push({ name: match[1], version: match[2] }); return offenders; } function errorOutput(error) { if (error && typeof error === "object") { const parts = error; const collected = [ parts.all, parts.stdout, parts.stderr, parts.message, parts.output ].filter((part) => typeof part === "string"); if (collected.length > 0) return collected.join("\n"); } return String(error); } function releaseAgeError(offenders, output) { const listed = offenders.map((o) => `${o.name}@${o.version}`).join(", "); const frameworkListed = offenders.some((o) => FRAMEWORK_OFFENDER_NAMES.includes(o.name)); const detail = offenders.length > 0 ? ` (${listed})` : ""; return /* @__PURE__ */ new Error(`pnpm's supply-chain holdback (minimumReleaseAge) rejected the install${detail} — ${frameworkListed ? "the framework rows are reconciled automatically — a persistent failure means the holdback window is still open; wait for the release to age past the cutoff, or override the policy locally if you trust the packages" : "wait for those releases to age past the cutoff, or override the policy locally if you trust them"}.${output.trim() ? `\n${output.trim().split("\n").at(-1)}` : ""}`); } /** * The upgrade install with the release-age remediation (the Nov-03 stranded * rc): pnpm's `minimumReleaseAge` holdback rejects a brand-new framework * release whose lockfile entry an earlier attempt already wrote — every * retry fails on the stale entry even though the workspace excludes allow * the resolution. On that error class: repair the exclude posture, discard * the polluted lockfile, retry once. Anything else (non-framework offenders, * a persistent violation) fails with the targeted remediation instead of the * raw pnpm dump — the install's own output already streamed live. */ async function installWithReleaseAgeRemediation(opts) { let firstError; try { await opts.run(opts.workspaceDir); return; } catch (error) { firstError = error; } const output = errorOutput(firstError); if (!output.includes("ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION")) throw firstError; const offenders = classifyReleaseAgeViolation(output); if (offenders.filter((o) => FRAMEWORK_OFFENDER_NAMES.includes(o.name)).length === 0) throw releaseAgeError(offenders, output); require_catalog_overrides.reconcileWorkspaceYamlFile(opts.workspaceDir); (0, node_fs.rmSync)((0, node_path.join)(opts.workspaceDir, "pnpm-lock.yaml"), { force: true }); opts.log?.("a stale lockfile entry carries a release younger than the supply-chain holdback — regenerating the lockfile and retrying"); try { await opts.run(opts.workspaceDir); } catch (retryError) { const retryOutput = errorOutput(retryError); throw releaseAgeError(classifyReleaseAgeViolation(retryOutput), retryOutput); } } //#endregion exports.classifyReleaseAgeViolation = classifyReleaseAgeViolation; exports.installWithReleaseAgeRemediation = installWithReleaseAgeRemediation; //# sourceMappingURL=install-remediation.cjs.map