In this article, we review lazyrepo
usage in tldraw codebase. We will look at:
What is lazyrepo?
What is lazy.config.ts?
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
andprimitives
will begin concurrently. The tests forcore
will only be started if bothutils
andprimitives
finish successfully.If you change a source file in
core
and runlazy run test
again, onlycore
's tests will be executed.If you change a source file in
utils
and runlazy run test
again, bothutils
andcore
'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:
baseCacheConfig
scripts
In the scripts object, the following scripts are configured:
build
dev
e2e
e2e-x10
lint
context
pack-tarball
refresh-assets
build-types
build-api
build-i18n
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.
Top comments (0)