Skip to content

Commit

Permalink
fix: avoid printing undefined for package version when reporting error
Browse files Browse the repository at this point in the history
  • Loading branch information
gluxon committed Feb 23, 2025
1 parent 4368152 commit 6430444
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cli/default-reporter/src/reportError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ function getErrorInfo (logObj: Log, config?: Config, peerDependencyRules?: PeerD
return { title: logObj.message! }
}

function formatPkgsStack (pkgsStack: Array<{ id: string, name: string, version: string }>) {
function formatPkgNameVer ({ name, version }: { name: string, version?: string }) {
return version == null
? name
: `${name}@${version}`
}

function formatPkgsStack (pkgsStack: Array<{ id: string, name: string, version?: string }>) {
return `This error happened while installing the dependencies of \
${pkgsStack[0].name}@${pkgsStack[0].version}\
${pkgsStack.slice(1).map(({ name, version }) => `${EOL} at ${name}@${version}`).join('')}`
${formatPkgNameVer(pkgsStack[0])}\
${pkgsStack.slice(1).map((pkgInfo) => `${EOL} at ${formatPkgNameVer(pkgInfo)}`).join('')}`
}

interface PackageMeta {
Expand Down Expand Up @@ -489,7 +495,7 @@ protocol are replaced with real specifiers on 'pnpm publish'.
This is likely a bug in the publishing automation of this package. Consider filing
a bug with the authors of:
${highlight(`${problemDep.name}@${problemDep.version}`)}
${highlight(formatPkgNameVer(problemDep))}
`
}

Expand Down

0 comments on commit 6430444

Please sign in to comment.