Blog
`lazyrepo` usage in tldraw codebase.

`lazyrepo` usage in tldraw codebase.

In this article, we review lazyrepo usage in tldraw codebase. We will look at:

  1. What is lazyrepo?

  2. What is lazy.config.ts?

  3. lazyrepo usage in tldraw codebase.

I study patterns used in an open source project found on Github Trending. For this week, I reviewed Codebuff codebase and wrote this article.

Press enter or click to view image in full size

What is lazyrepo?

lazyrepo is a zero-config caching task runner for npm/pnpm/yarn monorepos.

It fits right into the niche that turborepo carved out: making package.json "scripts" scale without adopting a big industrial-strength build system like nx, bazel, rush, or buck.

lazyrepo is scary fast, despite being written in TypeScript rather than some young handsome clever funny systems language.

Aside from perf, lazyrepo comes with some big quality-of-life improvements:

  • A human-friendly config format.

  • Concise and timely feedback to help you tweak and debug your build pipelines.

  • Palpably sensible defaults.

  • You don’t need to learn Rust to contribute.

Basic Usage

Run scripts defined in "scripts" entries using:

lazy run <script-name>

You can pass arguments to the task script after a --

lazy run test -- --runInBand

The default behavior is optimized for "test" scripts, where the order of execution matters if your packages depend on each other.

Let’s say you have three packages: core, utils, and primitives. The core package depends on both utils and primitives, and they all have "test" scripts in their package.json files.

With no config, when you run lazy run test in the project root:

  • The tests for utils and primitives will begin concurrently. The tests for core will only be started if both utils and primitives finish successfully.

  • If you change a source file in core and run lazy run test again, only core's tests will be executed.

  • If you change a source file in utils and run lazy run test again, both utils and core's tests will be executed, in that order.

I picked this above info from the lazyrepo README.

What is lazy.config.ts?

You can create lazy.config.ts file by running the below command in your project’s root folder.

lazy init

This will automatically create the lazy.config.ts file with the default configuration shown below:

export default {
  scripts: {
    test: {
      cache: {
        // by default we consider all files in the package directory
        inputs: ['**/*'],
        // there are no outputs
        outputs: [],
        // a test invocation depends on the input files of any upstream packages
        inheritsInputFromDependencies: true,
      },
    },
  },
}

Here, you can adjust the configuration.

lazyrepo usage in tldraw codebase.

lazy.config.ts file in tldraw codebase has:

  1. baseCacheConfig

  2. scripts

In the scripts object, the following scripts are configured:

  1. build

  2. dev

  3. e2e

  4. e2e-x10

  5. lint

  6. context

  7. pack-tarball

  8. refresh-assets

  9. build-types

  10. build-api

  11. build-i18n

  12. api-check

It is important that you understand the basic usage example provided above, to learn the order of execution of these scripts.

About me:

Hey, my name is Ramu Narasinga. I study codebase architecture in large open-source projects.

Email: ramu.narasinga@gmail.com

Want to learn from open-source? Solve challenges inspired by open-source projects.

References:

  1. https://github.com/tldraw/tldraw/blob/main/lazy.config.ts

  2. https://github.com/ds300/lazyrepo