Skip to content

Commit

Permalink
fix: make joined paths readable
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard committed Oct 6, 2022
1 parent 2210dd5 commit 6b38bf9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/node/_core/pkg/_loadPkgWithReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_Pa
for (const issue of err.issues) {
if (issue.code === 'invalid_type') {
console.log(
`${chalk.red('invalid type')} in ./package.json at ${chalk.magenta(
`\`${issue.path.join('.')}\``
)} (expected ${issue.expected}, received ${issue.received})`
[
`${chalk.red('fail')} \`${_formatPath(issue.path)}\` `,
`in ./package.json must be of type ${chalk.magenta(issue.expected)} `,
`(received ${chalk.magenta(issue.received)})`,
].join('')
)
}
}
Expand All @@ -27,3 +29,21 @@ export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_Pa
process.exit(1)
}
}

function _formatPath(segments: Array<string | number>) {
return segments
.map((s, idx) => {
if (idx === 0) return s

if (typeof s === 'number') {
return `[${s}]`
}

if (s.startsWith('.')) {
return `["${s}"]`
}

return `.${s}`
})
.join('')
}

0 comments on commit 6b38bf9

Please sign in to comment.