fix(cli): handle pnpm 10+ ERR_PNPM_TRUST_DOWNGRADE in docs preview#14965
fix(cli): handle pnpm 10+ ERR_PNPM_TRUST_DOWNGRADE in docs preview#14965fern-support wants to merge 2 commits intomainfrom
Conversation
Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
| ); | ||
| if (pnpmWorkspaceExists) { | ||
| const content = (await readFile(pnpmWorkspacePath)).toString(); | ||
| const updatedContent = content.replace(/^trustPolicy:.*$/gm, ""); |
There was a problem hiding this comment.
🔴 Regex only strips the trustPolicy: header line, leaving orphaned indented YAML that invalidates the file
The regex /^trustPolicy:.*$/gm at line 450 only removes lines that start with trustPolicy:, but in pnpm 10+ the trustPolicy setting is typically a multi-line YAML block with nested indented content (e.g., dependencies:, package names, version constraints, attestation settings). After the replacement, the indented sub-keys remain as orphaned YAML content, producing an invalid pnpm-workspace.yaml that will cause the retry pnpm install to also fail — this time with a YAML parse error rather than the trust downgrade error, resulting in a confusing error message.
Example of incompletely stripped YAML
Before:
packages:
- '.'
trustPolicy:
dependencies:
undici-types:
- version: ">=6.21.0"
attestation: npmAfter the regex replace:
packages:
- '.'
dependencies:
undici-types:
- version: ">=6.21.0"
attestation: npmThe orphaned indented lines make the YAML invalid or attach to the wrong key.
| const updatedContent = content.replace(/^trustPolicy:.*$/gm, ""); | |
| const updatedContent = content.replace(/^trustPolicy:.*$(?:\n(?=[ \t]).*$)*/gm, ""); |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Good catch — trustPolicy is a simple scalar in practice (trustPolicy: no-downgrade), but the more defensive regex is a reasonable safety measure. Applied the suggested regex to also strip any indented sub-keys: b204c22.
…keys Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
Description
Fixes
fern docs devfailing on Windows 11 with pnpm 10+ whentrustPolicy: no-downgradeis configured. The error occurs because pnpm propagates supply-chain security settings asnpm_config_*env vars to child processes, causingpnpm installin the standalone preview bundle to fail withERR_PNPM_TRUST_DOWNGRADEfor packages likeundici-types@6.21.0that have lost provenance attestation between versions.Changes Made
getCleanPnpmEnv()helper that strips pnpm supply-chain security env vars (npm_config_trust_policy,npm_config_strict_dep_builds,npm_config_minimum_release_age,npm_config_block_exotic_subdeps) before running pnpm commands in the preview bundle folderextendEnv: falseto all threepnpmcalls indownloadLocalDocsBundle.ts(twopnpm i esbuildcalls and onepnpm install)ERR_PNPM_TRUST_DOWNGRADEerror detection in the Windowspnpm installcatch block — when detected, stripstrustPolicyfrom the standalonepnpm-workspace.yamland retriesTesting
pnpm run check)Link to Devin session: https://app.devin.ai/sessions/1be76045381f46ec95ceb354512677b1
Requested by: @cdonel707