Practical example of a
TypeScript
monorepo withpnpm
,turborepo
, andjest
.
pnpm
workspace, whose configuration is stored inpnpm-workspace.yaml
. Two example packages are included,common-utils
andexample
, with the latter importingcommon-utils
as a dependency. All local packages are decorated with a@jkomyno/*
scope (you may want to substitute these instances in thename
entries of anypackage.json
with yours or your company's name).turborepo
, whose configuration is stored inturbo.json
- an example
Dockerfile
that can be built and used as a base image for your Node.js Docker containers. - the
jest
test engine, whose configuration is stored in thepackages/jest
folder. - opinionated
prettier
andeslint
setups.
pnpm install
: install the dependencies needed for each package.pnpm build
: transpile the local TypeScript packages to JavaScript.pnpm eslint-check
: check that the code follows theeslint
guidelines.pnpm prettier-check
: check that the code follows theprettier
guidelines.pnpm prettier-write
: override the code to follow theprettier
guidelines.pnpm test:unit
: run unit tests.pnpm test:integration
: run integration tests.
We follow an opinionated convention for storing an running tests.
All tests should be written in the __tests__
directory of a local package.
Moreover, unit tests should be placed in the __tests__/unit
folder; similarly, integration tests should be placed in the __tests__/integration
folder.
This allows for easily running groups of tests (for instance, you might want to run unit tests locally, while deferring integration tests - that will probably need access to external services like Docker containers - to the CI only).
In each local package's package.json
file, make sure to replace the JEST_LIB_UNDER_TEST
environment variable declaration with the local package name, for each test*
command in the scripts
section.
- How do I add a new package to the local workspace?
- Create a new folder
$packageName
inpackages/
. Initialize it with atsconfig.json
file (which will reference thetsconfig.base.node.json
file at the root level) and apackage.json
file similarly to how it's done in thecommon-utils
package.
- How do I add a new depedency that should be available to each package in the local workspace?
pnpm add -w $dependencyName
Hi, I'm Alberto Schiabel, you can follow me on:
Give a ⭐️ if this project helped or inspired you!
Built with ❤️ by Alberto Schiabel.
This project is MIT licensed.