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

oneenv

v0.9.9

Published

Distributes .env files from one master .env file to different folders/workspaces in a monorepo.

Downloads

3

Readme

oneenv

OneEnv helps keep all .env files' content in one file or one NPM (or yarn) task call in a monorepo. The content is then distributed to the specified folders (targets). This is to help the developers to easily share just one master .env file (in the root of the project), but can also be used to set up CI/CD pipelines. It uses dotenv under the hood.

REMEMBER TO GITIGNORE ALL .env FILES IN YOUR PROJECT.

Install

npm i oneenv

or

yarn add oneenv

Syntax examples

Master .env file (root of your project):

# special separator for handle and variable (default is '__')
__ENV_CONFIG_SEPARATOR=--

# handles and targets definitions
front--env_config_target=frontend
back--env_config_target=backend

# handles starting with 'sv--' can be used as variables
sv--SHARED_SECRET=mysharedsecret

# all these will be in an .env file in the '/frontend' folder (without the 'front--' handle)
front--VITE_SECRET=anothersecretforfrontend
front--VITE_SHARED_SECRET=sv--SHARED_SECRET

# all these will be in an .env file in the '/backend' folder (without the 'back--' handle)
back--SECRET=anothersecretforbackend
back--SHARED_SECRET=sv--SHARED_SECRET

# root level .env variable (without any handle and separator)
SOME_ROOT_SECRET=rootsecret

Config file, oneenv.config.json (root of your project):

{
  "targets": {
    "front": "frontend",
    "back": "backend",
    "calcService": "calcService/src"
  },
  "separator": "--"
}

You need to specify the target in the root .env file, in the config file, or in a package.json script task. The defining of the separator is optional, default is __.

Targets

Targets define the handle and the folder (as the value) where the .env file is created. Targets can be set in three different ways (one of these ways is required):

  1. In the master .env file:
front__env_config_target=frontend
back__env_config_target=backend
  1. In the oneenv.config.json file:
{
  "targets": {
    "front": "frontend",
    "back": "backend",
  },
}
  1. In a package.json script task:
"scripts": {
  "env": "front__env_config_target=frontend back__env_config_target=backend oneenv"
}

Variables

The variables are defined as [handle][separator][VARIABLEKEY]=[VALUE]. The root .env file:

front__VARIABLE_KEY=somefrontendsecret
back__VARIABLE_KEY=somebackendsecret

or in a terminal call:

front__VARIABLE_KEY=somefrontendsecret back__VARIABLE_KEY=somebackendsecret npm run env

Shared values (sv)

The variables can share a value by using sv as the handle. For example:

sv__SOME_SHARED_VALUE=somesharedvalue

front__VARIABLE_KEY=sv__SOME_SHARED_VALUE
back__VARIABLE_KEY=sv__SOME_SHARED_VALUE