mhassan1 / yarn-plugin-licenses

Yarn Berry plugin that adds `yarn licenses` commands
42 stars 11 forks source link

Output with `--json` flag is not valid JSON #46

Closed derwehr closed 1 year ago

derwehr commented 1 year ago

When setting the output to JSON with the --json flag, the output looks like the following

{
  "value": "licenseA",
  "children": {
    "packageA": {
      "value": {
        "locator": "foo",
        "descriptor": "bar"
      },
      "children": {
        "url": "...",
        "vendorName": "...",
        "vendorUrl": "..."
      }
    }
  }
}
{
  "value": "licenseB",
  "children": {
    "packageB": {
      "value": {
        "locator": "foo",
        "descriptor": "bar"
      },
      "children": {
        "url": "...",
        "vendorName": "...",
        "vendorUrl": "..."
      }
    }
  }
}

i.e. it outputs a separate JSON Object literal for each License, separated by a new line.

Would it not make more sense to output on JSON Object literal containing all the licenses, by adding [ ] brackets around them and separating them with commas i.e.:

[
  {
    "value": "licenseA",
    "children": {
      "packageA": {
        "value": {
          "locator": "foo",
          "descriptor": "bar"
        },
        "children": {
          "url": "...",
          "vendorName": "...",
          "vendorUrl": "..."
        }
      }
    }
  },
  {
    "value": "licenseB",
    "children": {
      "packageB": {
        "value": {
          "locator": "foo",
          "descriptor": "bar"
        },
        "children": {
          "url": "...",
          "vendorName": "...",
          "vendorUrl": "..."
        }
      }
    }
  }
]
mhassan1 commented 1 year ago

The output is valid NDJSON. That is the format chosen by Yarn Berry (link), and I don't think this plugin should diverge. See yarn workspaces list --json as an example.