Correctly print differences in nested objects (#35497)
This commit is contained in:
@@ -203,8 +203,12 @@ function printObjectDifference(objFrom, objTo, rawContent, parentKey = '') {
|
||||
for (const [key, value] of Object.entries(objFrom)) {
|
||||
const combinedKey = `${parentKey}.${key}`
|
||||
if (Array.isArray(value) && !equalArray(value, objTo[key])) {
|
||||
console.log(`In frontmatter key: ${chalk.bold(combinedKey)}`)
|
||||
value.forEach((entry, i) => {
|
||||
// If it was an array of objects, we need to go deeper!
|
||||
if (isObject(entry)) {
|
||||
printObjectDifference(entry, objTo[key][i], rawContent, combinedKey)
|
||||
} else {
|
||||
console.log(`In frontmatter key: ${chalk.bold(combinedKey)}`)
|
||||
if (entry !== objTo[key][i]) {
|
||||
console.log(chalk.red(`- ${entry}`))
|
||||
console.log(chalk.green(`+ ${objTo[key][i]}`))
|
||||
@@ -213,6 +217,7 @@ function printObjectDifference(objFrom, objTo, rawContent, parentKey = '') {
|
||||
console.log(' ', chalk.dim(`line ${(index && index + 1) || 'unknown'}`))
|
||||
console.log('')
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if (typeof value === 'object' && value !== null) {
|
||||
printObjectDifference(value, objTo[key], rawContent, combinedKey)
|
||||
|
||||
Reference in New Issue
Block a user