From 6b38bf978b031e15d033256ea3f08bc39e0774ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20Lundga=CC=8Ard?= Date: Thu, 6 Oct 2022 23:58:01 +0200 Subject: [PATCH] fix: make joined paths readable --- src/node/_core/pkg/_loadPkgWithReporting.ts | 26 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/node/_core/pkg/_loadPkgWithReporting.ts b/src/node/_core/pkg/_loadPkgWithReporting.ts index 818ac75a..279cea06 100644 --- a/src/node/_core/pkg/_loadPkgWithReporting.ts +++ b/src/node/_core/pkg/_loadPkgWithReporting.ts @@ -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('') ) } } @@ -27,3 +29,21 @@ export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_Pa process.exit(1) } } + +function _formatPath(segments: Array) { + return segments + .map((s, idx) => { + if (idx === 0) return s + + if (typeof s === 'number') { + return `[${s}]` + } + + if (s.startsWith('.')) { + return `["${s}"]` + } + + return `.${s}` + }) + .join('') +}