| 525 | } |
| 526 | |
| 527 | const jsonOutput = ({ path, problems, result, rootError, seenItems }) => { |
| 528 | if (problems.size) { |
| 529 | result.problems = [...problems] |
| 530 | } |
| 531 | |
| 532 | if (rootError) { |
| 533 | result.problems = [ |
| 534 | ...(result.problems || []), |
| 535 | ...[`error in ${path}: Failed to parse root package.json`], |
| 536 | ] |
| 537 | result.invalid = true |
| 538 | } |
| 539 | |
| 540 | // we need to traverse the entire tree in order to determine which items should be included (since a nested transitive included dep will make it so that all its ancestors should be displayed) |
| 541 | // here is where we put items in their expected place for json output |
| 542 | for (const item of seenItems) { |
| 543 | // append current item to its parent item.dependencies obj in order to provide a json object structure that represents the installed tree |
| 544 | if (item[_include] && item[_parent]) { |
| 545 | if (!item[_parent].dependencies) { |
| 546 | item[_parent].dependencies = {} |
| 547 | } |
| 548 | |
| 549 | item[_parent].dependencies[item[_name]] = item |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | return result |
| 554 | } |
| 555 | |
| 556 | const parseableOutput = ({ global, long, seenNodes }) => { |
| 557 | let out = '' |