Home

Awesome

Serverless Mono Repo Typescript References example

Example repo on how to use yarn workspaces together with the serverless framework. Utilizes Typescript references.

Stack

Features

Adding a repo

Simply create a new folder in packages and run yarn init. Prefix serverless services with the sls- prefix, such that their dependencies will not be hoisted (the serverless framework doesn't support hoisted packages at the moment). Ensure that the package has a local tsconfig.json. When your Typescript package depends on another typescript package within the mono repo, reference to it using the package's tsconfig.json.

Adding types for external packages

If your external packages does not have types available from the DefinitelyTypes project (e.g. @types/my-package), you can easily define custom typings in the special packages/types package.

Running tests

To run tests in all packages, run yarn test from the root folder.

To run tests in a specific package, run yarn test from the package's folder.

Building

To build all packages based on their dependency graph order, run yarn build from the root folder

To build a specific package including the packages it references to, run yarn build from the package folder.

Deploying

To deploy a serverless service, run yarn deploy --stage=dev --aws-profile=profile-name from the package folder. This will build the Typescript packages used by that serverless service.

To deploy all serverless services, run the same command from the root folder.

Open issues (PRs welcome)

References