everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
1 lines • 5.92 kB
Source Map (JSON)
{"version":3,"file":"install-remediation.cjs","names":["FRAMEWORK_EXCLUDE_PACKAGES","join"],"sources":["../../../src/services/scaffold/install-remediation.ts"],"sourcesContent":["import { rmSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n FRAMEWORK_EXCLUDE_PACKAGES,\n reconcileWorkspaceYamlFile,\n} from \"../workspace/catalog-overrides\";\n\nexport interface ReleaseAgeOffender {\n name: string;\n version: string;\n}\n\nconst FRAMEWORK_OFFENDER_NAMES: readonly string[] = FRAMEWORK_EXCLUDE_PACKAGES;\n\n/**\n * Parse pnpm's `ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION` output for the\n * offending `name@version` entries — the lockfile entries the active\n * supply-chain holdback rejected.\n */\nexport function classifyReleaseAgeViolation(output: string): ReleaseAgeOffender[] {\n const offenders: ReleaseAgeOffender[] = [];\n for (const match of output.matchAll(/^\\s*([@a-zA-Z0-9/._-]+)@(\\d\\S*?)\\s+was published at/gm)) {\n offenders.push({ name: match[1]!, version: match[2]! });\n }\n return offenders;\n}\n\nfunction errorOutput(error: unknown): string {\n if (error && typeof error === \"object\") {\n const parts = error as {\n all?: unknown;\n stdout?: unknown;\n stderr?: unknown;\n message?: unknown;\n output?: unknown;\n };\n const collected = [parts.all, parts.stdout, parts.stderr, parts.message, parts.output].filter(\n (part): part is string => typeof part === \"string\",\n );\n if (collected.length > 0) return collected.join(\"\\n\");\n }\n return String(error);\n}\n\nfunction releaseAgeError(offenders: ReleaseAgeOffender[], output: string): Error {\n const listed = offenders.map((o) => `${o.name}@${o.version}`).join(\", \");\n const frameworkListed = offenders.some((o) => FRAMEWORK_OFFENDER_NAMES.includes(o.name));\n const detail = offenders.length > 0 ? ` (${listed})` : \"\";\n const guidance = frameworkListed\n ? \"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\"\n : \"wait for those releases to age past the cutoff, or override the policy locally if you trust them\";\n return new Error(\n `pnpm's supply-chain holdback (minimumReleaseAge) rejected the install${detail} — ${guidance}.` +\n `${output.trim() ? `\\n${output.trim().split(\"\\n\").at(-1)}` : \"\"}`,\n );\n}\n\nexport interface InstallRemediationOptions {\n /** The workspace root (pnpm-workspace.yaml / pnpm-lock.yaml live here). */\n workspaceDir: string;\n /** The install invocation — re-invoked for the post-repair retry. */\n run: (workspaceDir: string) => Promise<void>;\n log?: (message: string) => void;\n}\n\n/**\n * The upgrade install with the release-age remediation (the Nov-03 stranded\n * rc): pnpm's `minimumReleaseAge` holdback rejects a brand-new framework\n * release whose lockfile entry an earlier attempt already wrote — every\n * retry fails on the stale entry even though the workspace excludes allow\n * the resolution. On that error class: repair the exclude posture, discard\n * the polluted lockfile, retry once. Anything else (non-framework offenders,\n * a persistent violation) fails with the targeted remediation instead of the\n * raw pnpm dump — the install's own output already streamed live.\n */\nexport async function installWithReleaseAgeRemediation(\n opts: InstallRemediationOptions,\n): Promise<void> {\n let firstError: unknown;\n try {\n await opts.run(opts.workspaceDir);\n return;\n } catch (error) {\n firstError = error;\n }\n\n const output = errorOutput(firstError);\n if (!output.includes(\"ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION\")) throw firstError;\n\n const offenders = classifyReleaseAgeViolation(output);\n const frameworkOffenders = offenders.filter((o) => FRAMEWORK_OFFENDER_NAMES.includes(o.name));\n if (frameworkOffenders.length === 0) throw releaseAgeError(offenders, output);\n\n reconcileWorkspaceYamlFile(opts.workspaceDir);\n rmSync(join(opts.workspaceDir, \"pnpm-lock.yaml\"), { force: true });\n opts.log?.(\n \"a stale lockfile entry carries a release younger than the supply-chain holdback — regenerating the lockfile and retrying\",\n );\n try {\n await opts.run(opts.workspaceDir);\n } catch (retryError) {\n const retryOutput = errorOutput(retryError);\n throw releaseAgeError(classifyReleaseAgeViolation(retryOutput), retryOutput);\n }\n}\n"],"mappings":";;;;;AAYA,MAAM,2BAA8CA;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