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

environment-enforcer.macro

v1.0.2

Published

[![Babel Macro](https://img.shields.io/badge/babel--macro-%F0%9F%8E%A3-f5da55.svg?style=flat-square)](https://github.com/kentcdodds/babel-plugin-macros)

Downloads

2

Readme

Environment Enforcer

Babel Macro

"When you want your code to work in every environment, call on the Environment Enforcer."

Usage / Examples

  1. run npm install environment-enforcer.macro
  2. Create a single file that will provide your code access to your environment files. Let's call it wrappedEnvVars.ts
  3. Import this macro and pass it the interface that defines all of the environment variables you require to be present at runtime.
// inside src/wrappedEnvVars.ts
import EnvironmentEnforcer from 'environment-enforcer.macro';

interface IExample {
  MY_API_URL: string;
}

export const envVars = EnvironmentEnforcer.parse<IExample>();
  1. create a folder called environments (or see Configuration below for other options) and place it at the level of package.json
  2. create files within this folder that match your environments. For example, if you don't change the default stageNames value, you would want to have 5 files in this folder. So:
package.json
environments/
environments/test.json
environments/development.json
environments/qa.json
environments/staging.json
environments/production.json
node_modules/
  1. The content of each of these files must adhere to the interface you passed into the macro in the step above. So for example, environments/development.json would be:
{
  "MY_API_URL": "dev.whateverMyServerIs.com"
}
  1. EnvironmentEnforcer will make sure that all of your promotions have the expected variables and that your promotions are without fear! :)

Other Examples

For other examples, please check out the __fixtures__/successCases folder in this repo for our integration tests that show working examples.

Configuration

  • environmentsFolderPathRelativeToPackageJSON
    • meaning: this is the folder where you would want to put the files that contain the values of your environment variables
    • default value: "./environments"
    • allowed values: a path string that is relative to package
  • stageNames
    • meaning: this is the array of strings that define the names of the possible NODE_ENV values that this macro will look for
    • default values: ['development', 'qa', 'staging', 'production', 'test']
    • allowed values: an array of any strings that you expect to be setting NODE_ENV to during your applications CICD process.

Setting This Configuration via file

This macro works a lot better if you DO NOT try to configure it. The defaults are industry standard. But we allow you to change the configuration if you wish. This is handled by the standard babel macro PLUGIN config file process which is described below:

  1. Place a file called babel-plugin-macros.config.js next to the file that uses the environmentEnforcer macro.
  2. The content of this file should look like this:
module.exports = {
  environmentEnforcer: {
    environmentsFolderPathRelativeToPackageJSON: 'mySpecialFolder/environments',
  },
};

Contributions

Contributions welcome as long as they come with strong automated test coverage and use conventional commit messages.