From 19fda89e56556473132c33a97a9cc8c8c05d347b Mon Sep 17 00:00:00 2001 From: recursivefunk Date: Tue, 10 Jun 2025 09:40:07 -0400 Subject: [PATCH 1/2] add new add function --- README.md | 8 ++++++++ package.json | 2 +- src/index.d.ts | 1 + src/index.js | 4 ++++ test/test.js | 7 +++++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d221f3..c8984ec 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,14 @@ env.assert( ); ``` +#### Adding to the environment + +```javascript +env.add('NEW_ENV_VAR', 'newVal'); +process.env.NEW_ENV_VAR // 'newVal' +env.get('NEW_ENV_VAR'); // 'newVal' +``` + ### AWS Credentials ```javascript diff --git a/package.json b/package.json index d7ce904..26023df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "good-env", - "version": "7.5.0", + "version": "7.6.0", "description": "Better environment variable handling for Twelve-Factor node apps", "main": "src/index.js", "scripts": { diff --git a/src/index.d.ts b/src/index.d.ts index b4401a4..57b98be 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,4 +1,5 @@ declare module "good-env" { + export const add: (key: string, value: string) => void; /** * @description Tell Good Env to go to secrets manager, grab the object under the specified secretId and merge it with the * environment. diff --git a/src/index.js b/src/index.js index 204d4f4..87f8511 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,10 @@ let store = { ...process.env }; module.exports = Object .create({ + add (key, value) { + process.env[key] = value; + store[key] = value; + }, async use (awsSecretsManager, secretId) { const { SecretsManagerClient, GetSecretValueCommand } = awsSecretsManager; const client = new SecretsManagerClient({ diff --git a/test/test.js b/test/test.js index 4905244..13437c9 100644 --- a/test/test.js +++ b/test/test.js @@ -9,6 +9,13 @@ const { SecretsManagerClientHappy } = require('./mocks'); +test('it adds an env var', (t) => { + env.add('NEW_ENV_VAR', 'bar'); + t.equals(process.env.NEW_ENV_VAR, 'bar'); + t.equals(env.get('NEW_ENV_VAR'), 'bar'); + t.end(); +}); + test('it throws when no secretId is given when attempting to use secretsManager', async (t) => { const awsSecretsManager = { SecretsManagerClient: SecretsManagerClientHappy, GetSecretValueCommand }; From df8bac56fc085c5ab6dfff94b6c77b232e96d634 Mon Sep 17 00:00:00 2001 From: recursivefunk Date: Tue, 10 Jun 2025 09:42:25 -0400 Subject: [PATCH 2/2] rename add to set --- README.md | 2 +- src/index.d.ts | 2 +- src/index.js | 2 +- test/test.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c8984ec..b749488 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ env.assert( #### Adding to the environment ```javascript -env.add('NEW_ENV_VAR', 'newVal'); +env.set('NEW_ENV_VAR', 'newVal'); process.env.NEW_ENV_VAR // 'newVal' env.get('NEW_ENV_VAR'); // 'newVal' ``` diff --git a/src/index.d.ts b/src/index.d.ts index 57b98be..a4760c1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,5 +1,5 @@ declare module "good-env" { - export const add: (key: string, value: string) => void; + export const set: (key: string, value: string) => void; /** * @description Tell Good Env to go to secrets manager, grab the object under the specified secretId and merge it with the * environment. diff --git a/src/index.js b/src/index.js index 87f8511..7127e86 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ let store = { ...process.env }; module.exports = Object .create({ - add (key, value) { + set (key, value) { process.env[key] = value; store[key] = value; }, diff --git a/test/test.js b/test/test.js index 13437c9..9aff442 100644 --- a/test/test.js +++ b/test/test.js @@ -9,8 +9,8 @@ const { SecretsManagerClientHappy } = require('./mocks'); -test('it adds an env var', (t) => { - env.add('NEW_ENV_VAR', 'bar'); +test('it adds an env var', (t) => { + env.set('NEW_ENV_VAR', 'bar'); t.equals(process.env.NEW_ENV_VAR, 'bar'); t.equals(env.get('NEW_ENV_VAR'), 'bar'); t.end();