Generate a Dependency Graph for Monorepos Using Turborepo

Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

A dependency graph is exactly what it sounds like! A visual graph created by Turborepo to show you your dependencies and what dependencies the projects rely on. For our Monorepo, we'll run npx turbo run build --graph in the root of our project and that will build the dependency graph for all of our projects.

We can also do one with a graphic but that requires the Graphviz library. We can edit our command to have some arguments: npx turbo run build --graph=graph.pdf and it will create a graphic in a .pdf file.

Instructor: [0:00] When you have a monorepo, it is difficult to keep track of what depends on what in terms of packages inside the monorepo. Turborepo has this super handy tool that will generate a graph for you so you can understand better what is going on. [0:18] To see the dependencies in the build pipeline, we have to add the --graph flag at the end. This is going to tell us what depends on what. In this case, the build command in the blog project depends on the @monorepo/utils#build, the dashboard build depends on the @monorepo/utils#build, and the @monorepo/utils#build depends on nothing.

[0:43] We can also generate graphics. For that, we will need to install the Graphviz library first. You can see how to install it in your system depending whether you have Linux, Windows, or macOS.

[0:58] I already have Graphviz installed in my system. All I need to do here is to give graph some arguments. I'm going to use the equal sign here. I'm going to say graph.pdf. As you can see here, it generated a PDF inside the Turborepo project.

[1:22] If we open that PDF, it is telling us basically the same that we saw in the output in the terminal. These two, dashboard and blog, depend on utils and utils doesn't depend on anything else. You can even generate the graph as an HTML page just by changing the extension from .pdf to .html and it will generate this HTML page for you.

[1:48] To recap, Turborepo has this handy --graph flag that we can use to generate files that explain how our dependencies are connected together. We can generate different file types. For instance, what we have to do to generate a different file is to just specify the name and then add the extension that we want.

[2:11] It could be a JPEG. It could be an HTML page. It could be a PDF file as well. If we don't want to generate any file, we can just use the --graph flag as it is. It will generate this output into terminal.

egghead
egghead
~ 2 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today