The Ultimate Guide to TypeScript Monorepos

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • Scout APM - Less time debugging, more time building
  • OPS - Build and Run Open Source Unikernels
  • SonarQube - Static code analysis for 29 languages.
  • GitHub repo berry

    📦🐈 Active development trunk for Yarn ⚒

    Unfortunately a few challenges remain in using Yarn 2 workspaces. Chiefly, using this approach will conflict with any packages that depend on reading files directly from their node_modules folder. But there are also issues with ESM modules that are not yet supported in Yarn 2. Note there is a workaround for this by defining a different node linker.

  • GitHub repo terraform

    Terraform enables you to safely and predictably create, change, and improve infrastructure. It is an open source tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

    Most solutions presented so far for the JavaScript/TypeScript monorepo have taken advantage of common JavaScript tools, frameworks and libraries. Unfortunately, I was not able to find a framework that met my requirements for setting up infrastructure and deployment. Very important to me was being able to use Terraform, which I believe provides the most ‘standard’ way to define infrastructure as code. Almost any kind of infrastructure that can be deployed on any of the popular cloud platforms can be defined in Terraform, and there are plenty of examples and documentation available. Alternatives such as the Serverless framework or AWS SAM in comparison more lean towards being special purpose tools. Pulumi is also a great option but I am not yet convinced that the additional magic it provides on top of basic infrastructure definition (which is based on Terraform) is required over vanialla Terraform.

  • Scout APM

    Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.

  • GitHub repo eslint-plugin-prettier

    ESLint plugin for Prettier formatting

    When installing the Prettier and ESLint extensions for VSCode, formatting and linting will also work within VSCode for any files in the monorepo. Only tweak required to make this work is to configure the Prettier plugin for ESLint (see example .eslintrc.json). Otherwise Prettier and ESLint will get in each other’s way and make for a poor editing experience. To make this work, the following two settings will also need to be configured in a .vscode/settings.json configuration (see settings.json):

  • GitHub repo serverless-graphql

    Serverless GraphQL Examples for AWS AppSync and Apollo

    Most solutions presented so far for the JavaScript/TypeScript monorepo have taken advantage of common JavaScript tools, frameworks and libraries. Unfortunately, I was not able to find a framework that met my requirements for setting up infrastructure and deployment. Very important to me was being able to use Terraform, which I believe provides the most ‘standard’ way to define infrastructure as code. Almost any kind of infrastructure that can be deployed on any of the popular cloud platforms can be defined in Terraform, and there are plenty of examples and documentation available. Alternatives such as the Serverless framework or AWS SAM in comparison more lean towards being special purpose tools. Pulumi is also a great option but I am not yet convinced that the additional magic it provides on top of basic infrastructure definition (which is based on Terraform) is required over vanialla Terraform.

  • GitHub repo goldstack

    JavaScript Project Builder

    When installing the Prettier and ESLint extensions for VSCode, formatting and linting will also work within VSCode for any files in the monorepo. Only tweak required to make this work is to configure the Prettier plugin for ESLint (see example .eslintrc.json). Otherwise Prettier and ESLint will get in each other’s way and make for a poor editing experience. To make this work, the following two settings will also need to be configured in a .vscode/settings.json configuration (see settings.json):

  • GitHub repo webpack

    A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.

    Similar to Jest, it is very easy to use Webpack in a monorepo configured to use TypeScript project references. We can simply use the ts-loader loader, and everything should work automatically.

  • GitHub repo ts-jest

    A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.

    Thankfully using TypeScript and TypeScript project references makes the intricate problem of using Jest easier since we can make use of the excellent ts-jest Jest transformer. All we need to do it point ts-jest to the respective tsconfig.json file for each package (see example jest.config.js). Since we have configured TypeScript to be composite and incremental, we do not need to recompile TypeScript for dependencies of a package we want to test, which significantly reduces the runtime for unit tests. ts-jest will also ensure that any error message will reference the line numbers in the source TypeScript files.

  • OPS

    OPS - Build and Run Open Source Unikernels. Quickly and easily build and deploy open source unikernels in tens of seconds. Deploy in any language to any cloud.

  • GitHub repo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

    React/Next.js for UI development

  • GitHub repo esbuild

    An extremely fast JavaScript and CSS bundler and minifier

    Likewise it is easy to use esbuild. esbuild supports TypeScript by default and will automatically resolve all local references since we have TypeScript project references configured. Only additional configuration we need to provide is to use the plugin [@yarnpkg/esbuild-plugin-pnp](https://github.com/yarnpkg/berry/tree/master/packages/esbuild-plugin-pnp) so that esbuild can resolve external dependencies from the local Yarn cache. Find below an example script ( build.ts) to bundle code for a AWS lambda:

  • GitHub repo prettier

    Prettier is an opinionated code formatter.

    Prettier is a great tool for maintaining consistent formatting in a project. Prettier works quite well for a monorepo. One can simply define a .prettierrc file in the root of the monorepo and run Prettier using that configuration file. It will automatically apply to all packages in the monorepo.

  • GitHub repo svelte-jester

    A Jest transformer for Svelte - compile your components before importing them into tests.

    While I mentioned in the beginning of the article that I am relatively happy with the current state of my reference TypeScript monorepo template, I still think there are a couple of things that can be improved. Chiefly I think that Yarn 2 (‘Berry’) is still not as mature as I would like it to be. Support for ESM for instance would be awesome, the lack of which caused me some problems in trying to make Svelte work within the monorepo. However, I think it is very worthwhile what the Yarn team attempts to achieve with Yarn 2 and I am happy to support it by trying to make it work in the monorepo template.

  • GitHub repo Next.js

    The React Framework

    Next.js is a very powerful framework for React development and it is not too difficult to make this framework work in a TypeScript monorepo. Again, thanks to Next.js native support for both Yarn 2 workspaces and TypeScript project references there is not much we need to configure in this monorepo. We can simply define a tsconfig.json that references all local dependencies and Next.js will pick that up automatically.

  • GitHub repo jest

    Delightful JavaScript Testing.

    Jest is a great tool for running Unit tests within a JavaScript or TypeScript project. Unfortunately, running tests in Jest is often more difficult than one wishes it to be due to the somewhat fragmented nature of the JavaScript ecosystem. For instance, when using TypeScript and/or React, we need to ensure that source files are transpiled into JavaScript before running tests. When using Yarn workspaces, we also need to ensure that Jest is able to resolve local dependencies.

  • GitHub repo Express

    Fast, unopinionated, minimalist web framework for node.

    There are many ways to develop, deploy and test Node.js lambda functions. In my reference template, I provide an example that uses an Express.js server. That is not necessarily the optimal way to deploy lambdas, chiefly because this results in deploying one lambda function that handles multiple routes. The most ‘serverless’ way to deploy a backend using functions would be to use different functions for different endpoints.

  • GitHub repo ESLint

    Find and fix problems in your JavaScript code.

    ESLint provides sophisticated analysis of JavaScript or TypeScript sourcecode. Thankfully it can be configured as easy as Prettier for a monorepo. We can define an .eslintrc.json file in the project root and that will apply to all files in the Monorepo.

  • GitHub repo serverless-application-model

    AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications

    Most solutions presented so far for the JavaScript/TypeScript monorepo have taken advantage of common JavaScript tools, frameworks and libraries. Unfortunately, I was not able to find a framework that met my requirements for setting up infrastructure and deployment. Very important to me was being able to use Terraform, which I believe provides the most ‘standard’ way to define infrastructure as code. Almost any kind of infrastructure that can be deployed on any of the popular cloud platforms can be defined in Terraform, and there are plenty of examples and documentation available. Alternatives such as the Serverless framework or AWS SAM in comparison more lean towards being special purpose tools. Pulumi is also a great option but I am not yet convinced that the additional magic it provides on top of basic infrastructure definition (which is based on Terraform) is required over vanialla Terraform.

  • GitHub repo aws-lambda-java-libs

    Official mirror for interface definitions and helper classes for Java code running on the AWS Lambda platform.

    AWS Lambda for backend development

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts