So how do we actually collect this data? The primary way we do this is through a tool called TuxScanner. TuxScanner is a static code analysis tool that goes in and looks at our individual files of source code without executing them, and measures how Tux is being used in practice and sends this data all off to an API so we can go and analyze how Tux is being used.
So we start here, we have a file of source code, we go and parse it into an AST, which is just a tree representation of the source code, and then we go and we evaluate a set of metrics on that AST, and those will all give us scores. So that could be like 80% component coverage before, or maybe there's 12 deprecated components being used, or something along the lines of that. It'll just collect us a bunch of scores, we'll conglomerate them all together, and send it off to the API so that we can look at how all our code files are using Tux, and filter over time, by platform, by the metric, and whatnot.
So to do a little bit of a deeper dive into how scanner works. So we start by parsing the source code files into ASTs, abstract syntax truths, which is just a tree representation of the source code, and it shows how all the constructs of the language are related. So the JSX elements related to the class name attribute, and have a tree based on that. And this just allows us to go through and evaluate a set of metrics on there. So a metric is just a function that takes in a set of ASTs, it goes in and traverses those ASTs, and produces a set of scores. And the score is just the number of good cases, the things we're doing right, the number of bad cases, the things we're doing wrong and need to improve to improve our score. The call sites of the good and bad cases, which are just the links to the nodes, usually it's JSX elements, but could also be an import declaration or something just to the place in the code where something's going wrong. And then the coverage source, and then we'll conglomerate that all together, we send it off to the API so we can filter by time and by package and whatnot.
Okay, so now that TuckScanner has collected all this data, how do we utilize it? So, at TikTok, things grow quickly, and our component library is no exception. We need to be able to evolve fast in order to keep up with the dramatic rate of change. And we want to be able to do that in order to stay nimble and keep on evolving. So, we need to be able to keep what's working and throw out and redo what isn't. Now, this is a good truism for how code should best be maintained, but it's not often practiced. And that's because introducing all these breaking changes all the time isn't fun for developers to keep up with. It makes their life hard and introduces a lot of maintenance. But we can't look at these things for the lens of being a maintenance burden. We need to always be striving to introduce breaking changes in order to go and reach for that asymptotic platonic form of what a component library should be, and we can't abandon that for the sake of stability. We've got to stay nimble. So we cannot be afraid of introducing breaking changes to our components. In fact, we want to be making them regularly. We got to embrace the breaking changes. So this is easy to say in theory, but it's hard to do in practice. And at TikTok, we've made a concentrated effort to streamline our architecture to facilitate this. So one such example is we use a monorepo. And in a monorepo, almost all of our consumers are on the latest version of Tux.
Comments