0.0.1 • Published 7 years ago

fooji-serverless-utils v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

Serverless Utilities

This repository contains a set of utility packages for use in the rest of our Serverless infrastructure. Here's an overview of the packages available and what they do:

  • @fooji/aws - Contains AWS, instantiator methods for services like SNS, and an instance of the AWS SDK Mock. Refer to the README for that repository on why this is the case.
  • @fooji/bugsnag - Sets up the Bugsnag error reporting based on configuration values and exports the Bugsnag instance.
  • @fooji/config - The main configuration repository for all Serverless services. Contains the default configuration as well as an interface for accessing local configs. There is an important caveat to take note of, so consult the README for that repository for some more information.
  • @fooji/errors - Contains error constants and error reporting helpers.
  • @fooji/knex - Contains the Knex database instances: an instance for regular use and a test instance for specialized use in unit tests.
  • @fooji/lambda-wrappers - Contains wrappers for the Lambda functions. There are different wrapper types depending on if the Lambda function handles HTTP requests, SNS messages, etc.
  • @fooji/logging - Contains helpers for logging to whichever service we have decided to log to.
  • @fooji/test-utils - Contains helpers for unit testing.

If you're curious about any specific package, feel free to venture into that package's source code or take a look at its README.

Setting up this repository.

You can use the setup script in this repo to install and link everything for you.

yarn run setup

Do not attempt to setup this repository manually. The setup script does a lot of special things that are meant to help. If you setup this repository manually, you'll undoubtedly end up setting up something with a different value, which will result in the rest of the development team publishing new package versions when they don't need to.

So, for the sake of the rest of the team, please follow the instructions.

In this case, the script uses the --hoist flag when calling lerna bootstrap, which is vitally important to the correct versioning of the packages in this repo. If you don't run the above with the --hoist flag, you'll run into all kinds of dependency hell since the packages inside this repo are expecting their dependencies to be installed at the root instead of inside each little package.

Publishing new package versions

If you're ready to publish a new version of your package, do the following in the root:

yarn run publish

Do not attempt to publish packages by running the lerna command manually. The script passes some special flags, and if you end up not passing these special flags you will undoubtedly mess up the versioning we have with the existing packages, causing the rest of the development team to publish new package versions when they don't need to.

So, for the sake of the rest of the team, please follow the instructions.

For the curious, the special flags we're using are calculating the proper git tag to base the version changes off of. For some reason, by default lerna wants to compare against a really old version of serverless-utils, so we have to tell it to use a git command that finds the latest tag a little bit better (using the log instead of the alphabetical order of the tags).

If you don't use the command, you could end up publishing extra versions of a package that you didn't touch, causing some extra confusion for the rest of the team.

Using this repo

You can link all the packages to your repo by using the following fooji cli command from within your repo.

fooji link-serverless-util-packages

Manually

Go through all of the packages and type yarn link. Then type yarn link @fooji/package-name in your repo for each package you want to use.

A caveat with yarn

If you ever run into issues with Serverless packaging node_modules and complaining that a Fooji package does not exist, the likely problem is that you're not logged into the registry that yarn is using.

See when running a script using yarn, yarn forwards all of its configuration to that script, meaning npm is going to attempt to use yarn's registry whenever installing new packages. By default npm login only logs you into the NPM registry, and not yarn's custom registry. In order to fix this, you'll need to do the following:

npm login --registry=https://registry.yarnpkg.com

And then login with your NPM credentials as usual.

Contributing

See CONTRIBUTING.md for more information.