Pragmatic template for a
TypeScriptmonorepo withpnpm,turborepo, andvitest.
Tested with:
- Node.js v20.17.0
- pnpm v9.15.0
- vitest v2.1.8
pnpmworkspace, whose configuration is stored inpnpm-workspace.yaml. Two example packages are included,common-utilsandexample, with the latter importingcommon-utilsas a dependency. All local packages are decorated with a@jkomyno/*scope (you may want to substitute these instances in thenameentries of anypackage.jsonwith yours or your company's name).tsupbundler, whose configuration is stored intsup.config.ts.turborepo, whose configuration is stored inturbo.json- an example
Dockerfilethat can be built and used as a base image for your Node.js Docker containers. - the
vitesttest engine, whose configuration is stored invitest.workspace.ts. - opinionated linting setups via
biome, whose configuration is defined in thebiome.jsoncfile.
pnpm install: install the dependencies needed for each package.pnpm build: transpile the local TypeScript packages to JavaScript.pnpm build:watch: transpile the local TypeScript packages to JavaScript, and watch for changes.pnpm check:exports: check that theexportsfield in thepackage.jsonfiles of each exported package is correctly set, using@arethetypeswrong/cli.pnpm lint:ci: check that the code follows thebiomeguidelines.pnpm lint: check that the code follows thebiomeguidelines, and override it to follow them if possible.pnpm test:unit: run unit tests.pnpm test:integration: run integration tests.pnpm test: run all 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).
- How do I add a new package to the local workspace?
- Create a new folder
$packageNameinpackages/. Initialize it with atsconfig.jsonfile (which will reference thetsconfig.base.node.jsonfile at the root level) and apackage.jsonfile similarly to how it's done in thecommon-utilspackage.
- 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.