Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render json output #7

Merged
merged 2 commits into from
Feb 23, 2023
Merged

Render json output #7

merged 2 commits into from
Feb 23, 2023

Conversation

gabotechs
Copy link
Owner

@gabotechs gabotechs commented Feb 23, 2023

As requested in #6, this PR introduces the ability to output a machine readable output in json format with the --json flag:

dep-tree render src/file.ts --json

The output format looks like this:

{
  "tree": {
    "index.ts": {
      "file-1.ts": {
        "file-2.ts": {
          "file-3.ts": null,
          "file-4.ts": null
        },
        "file-4.ts": null
      },
      "file-2.ts": {
        "file-3.ts": null,
        "file-4.ts": null
      },
      "file-3.ts": null
    }
  },
  "circularDependencies": [],
  "errors": {
    "file-1.ts": [
      "could not import file-4275.ts, not found"
    ],
    "file-3.ts": [
      "could not import file-1423.ts, not found"
    ]
  }
}

If a node is a leaf node (meaning that it is not importing more other files), its value will be null, otherwise, its value will be a key-value object that goes from its file path to either another key-value object or null.

circularDependencies is of type [][]String, and it will look something like this:

{
"circularDependencies": [
    [
      "file-2.ts",
      "file-3.ts",
      "file-4.ts",
      "file-2.ts"
    ]
  ]
}

closing the loop of the circular import stack.

While parsing files, it can happen that there are some errors. Instead of failing, dep-tree just stores the errors and keeps trying to parse the file. Those errors will be gathered in the errors key in the json output, which is a map from file to array of errors in that file.

@belong-bryce
Copy link

This looks great!

@gabotechs gabotechs merged commit 4cdea72 into main Feb 23, 2023
@gabotechs gabotechs deleted the render-json-output branch February 23, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants