diff --git a/README.md b/README.md index 5977546e..1b1dccad 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ to _your_ definition of valid. See [how to use it](#usage). - [FAQ](#faq) - [Where should I call `makeEnv` in my application?](#where-should-i-call-makeenv-in-my-application) - [Does it support changing env variables dynamically?](#does-it-support-changing-env-variables-dynamically) + - [Can I use the `debug` module with `environment`?](#can-i-use-the-debug-module-with-environment) - [Can I have more than one env object per application?](#can-i-have-more-than-one-env-object-per-application) - [Node.js support](#nodejs-support) - [Maintainers](#maintainers) @@ -392,6 +393,10 @@ No, when you create an env object it will read the value of changes to `process.env`, it will not be reflected in the env object. +### Can I use the [`debug`](https://github.com/visionmedia/debug) module with `environment`? + +Yes! Set `DEBUG=environment`. + ### Can I have more than one env object per application? Yes! You can have as many env objects as you want! diff --git a/babel.config.js b/babel.config.js index 7ac4b177..db3bff19 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,7 +1,7 @@ module.exports = api => { const babelEnv = api.env(); - const debug = !!process.env.DEBUG; + const debug = !!process.env.DEBUG_BABEL; const useBuiltIns = false; const presets = [ diff --git a/package.json b/package.json index 70d8f756..92d706a3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "scripts": { "build": "yarn build-lib && yarn build-types", - "build-lib": "cross-env NODE_ENV=production babel --extensions \".ts\" --out-dir dist src", + "build-lib": "cross-env NODE_ENV=production babel --source-maps --extensions \".ts\" --out-dir dist src", "build-types": "tsc --emitDeclarationOnly", "prebuild": "yarn clean-dist", "clean-dist": "rimraf dist", @@ -29,6 +29,7 @@ "types": "dist/index.d.ts", "private": false, "dependencies": { + "debug": "^4.1.1", "validator": "^10.11.0" }, "devDependencies": { @@ -42,6 +43,7 @@ "@commitlint/travis-cli": "7.5.0", "@semantic-release/changelog": "3.0.2", "@semantic-release/git": "7.0.8", + "@types/debug": "^4.1.2", "@types/jest": "24.0.0", "@types/node": "10.12.24", "@types/validator": "10.9.0", diff --git a/src/debug.ts b/src/debug.ts new file mode 100644 index 00000000..d3c9efbc --- /dev/null +++ b/src/debug.ts @@ -0,0 +1,5 @@ +import debug from 'debug'; + +const namespace = 'environment'; + +export const logDebug = debug(namespace); diff --git a/src/environment.ts b/src/environment.ts index 8d2ee0c8..81d7ad1d 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -1,5 +1,6 @@ import EnvironmentVariableError from './EnvironmentVariableError'; import { Parser } from './parsers'; +import { logDebug } from './debug'; export type Env = { [TKey in keyof Schema]: TSchemaData[TKey] @@ -49,12 +50,16 @@ export function makeEnv( schema: Schema, processEnv: NodeJS.ProcessEnv = process.env, ): Env { + logDebug('making env object...'); + const env = Object.entries(schema).reduce((acc, [key, schemaEntry]) => { const value = getValue(key, schemaEntry as any, processEnv); return { ...acc, [key]: value }; }, {}) as Env; + logDebug('env object ready: %o', env); + return env; } diff --git a/yarn.lock b/yarn.lock index 95825f6b..ff5977ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -984,6 +984,11 @@ into-stream "^4.0.0" lodash "^4.17.4" +"@types/debug@^4.1.2": + version "4.1.2" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.2.tgz#84824e9259fc583dd9385635738359c9582f7f82" + integrity sha512-jkf6UiWUjcOqdQbatbvOm54/YbCdjt3JjiAzT/9KS2XtMmOkYHdKsI5u8fulhbuTUuiqNBfa6J5GSDiwjK+zLA== + "@types/jest@24.0.0": version "24.0.0" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.0.tgz#848492026c327b3548d92be0352a545c36a21e8a"