npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@orangejellyfish/serverless-config-merge

v0.2.0

Published

An opinionated command-line utility to merge [Serverless Framework][sls] configuration files. Move common configuration into smaller, maintainable individual files and import them prior to deployment.

Downloads

5

Readme

serverless-config-merge

An opinionated command-line utility to merge Serverless Framework configuration files. Move common configuration into smaller, maintainable individual files and import them prior to deployment.

service: example-service

provider:
  $<<: ${file(provider-defaults.yml)}
  region: eu-west-1

Installation

Install as a dev dependency to your Serverless Framework project with npm. This is preferred to a global install to allow you to have control over the version of the tool on a per-project basis.

npm install --save-dev @orangejellyfish/serverless-config-merge

Usage

Move common configuration into YAML files. For example, a common "provider" config might include the provider name and region in provider-defaults.yml:

name: aws
region: eu-west-1

Reference a file with a special key. The key is $<< by default, inspired by the YAML merge key proposal. The value must be a Serverless Framework "file" variable, or an array of them. If a key appears in a file that is merged in and also in the source, the value in the source takes precedence:

service: example-service

provider:
  $<<: ${file(provider-defaults.yml)} # Merge in the defaults
  region: eu-west-2 # Override the default from the merged file

plugins:
  $<<:
    - ${file(plugin-defaults-1.yml)} # Merge in multiple files
    - ${file(plugin-defaults-2.yml)}

Run serverless-config-merge (or the alias sls-config-merge) prior to your deployment. For example:

MERGED_CONFIG_FILE=serverless-merged.yml
npx serverless-config-merge -o $MERGED_CONFIG_FILE
sls deploy --config $MERGED_CONFIG_FILE
rm $MERGED_CONFIG_FILE

Options

  • -i - input file, defaults to serverless.yml
  • -o - output file, defaults to serverless-merge.yml
  • -k - merge key, defaults to $<<

Design choices

  • Designed as a standalone executable to run prior to deployment because the Severless Framework plugin system does not provide an early enough hook to merge all relevant properties. For example, the serverless-merge-config plugin is unable to merge the provider.name property because it's presence is validated by the framework too early.

  • Writes a new config file alongside your existing Serverless Framework config file. It would have been preferable to write this file to a hidden directory such as .serverless but that would require rewriting any other paths in the file. As it stands, you'll have to add this file to .gitignore or delete it post-deployment, as shown in the example above.

  • The new config file is written as JSON rather than YAML, simply because the Serverless Framework supports both and since the output is already a JavaScript object it's slightly easier to output it as JSON.

  • Only supports Serverless Framework configuration files written in YAML. If your configuration file is written in JSON you can use the same idea with minor tweaks - pull requests welcome!