Skip to content

Commit 14668b1

Browse files
committed
feat: use debug module to help debugging
1 parent 250d2d9 commit 14668b1

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ to _your_ definition of valid. See [how to use it](#usage).
5252
- [FAQ](#faq)
5353
- [Where should I call `makeEnv` in my application?](#where-should-i-call-makeenv-in-my-application)
5454
- [Does it support changing env variables dynamically?](#does-it-support-changing-env-variables-dynamically)
55+
- [Can I use the `debug` module with `environment`?](#can-i-use-the-debug-module-with-environment)
5556
- [Can I have more than one env object per application?](#can-i-have-more-than-one-env-object-per-application)
5657
- [Node.js support](#nodejs-support)
5758
- [Maintainers](#maintainers)
@@ -392,6 +393,10 @@ No, when you create an env object it will read the value of
392393
changes to `process.env`, it will not be reflected in the
393394
env object.
394395

396+
### Can I use the [`debug`](https://github.com/visionmedia/debug) module with `environment`?
397+
398+
Yes! Set `DEBUG=environment`.
399+
395400
### Can I have more than one env object per application?
396401

397402
Yes! You can have as many env objects as you want!

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = api => {
22
const babelEnv = api.env();
33

4-
const debug = !!process.env.DEBUG;
4+
const debug = !!process.env.DEBUG_BABEL;
55
const useBuiltIns = false;
66

77
const presets = [

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"scripts": {
1212
"build": "yarn build-lib && yarn build-types",
13-
"build-lib": "cross-env NODE_ENV=production babel --extensions \".ts\" --out-dir dist src",
13+
"build-lib": "cross-env NODE_ENV=production babel --source-maps --extensions \".ts\" --out-dir dist src",
1414
"build-types": "tsc --emitDeclarationOnly",
1515
"prebuild": "yarn clean-dist",
1616
"clean-dist": "rimraf dist",
@@ -29,6 +29,7 @@
2929
"types": "dist/index.d.ts",
3030
"private": false,
3131
"dependencies": {
32+
"debug": "^4.1.1",
3233
"validator": "^10.11.0"
3334
},
3435
"devDependencies": {
@@ -42,6 +43,7 @@
4243
"@commitlint/travis-cli": "7.5.0",
4344
"@semantic-release/changelog": "3.0.2",
4445
"@semantic-release/git": "7.0.8",
46+
"@types/debug": "^4.1.2",
4547
"@types/jest": "24.0.0",
4648
"@types/node": "10.12.24",
4749
"@types/validator": "10.9.0",

src/debug.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import debug from 'debug';
2+
3+
const namespace = 'environment';
4+
5+
export const logDebug = debug(namespace);

src/environment.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import EnvironmentVariableError from './EnvironmentVariableError';
22
import { Parser } from './parsers';
3+
import { logDebug } from './debug';
34

45
export type Env<TSchemaData> = {
56
[TKey in keyof Schema<TSchemaData>]: TSchemaData[TKey]
@@ -49,12 +50,16 @@ export function makeEnv<TSchemaData extends { [key: string]: any }>(
4950
schema: Schema<TSchemaData>,
5051
processEnv: NodeJS.ProcessEnv = process.env,
5152
): Env<TSchemaData> {
53+
logDebug('making env object...');
54+
5255
const env = Object.entries(schema).reduce((acc, [key, schemaEntry]) => {
5356
const value = getValue(key, schemaEntry as any, processEnv);
5457

5558
return { ...acc, [key]: value };
5659
}, {}) as Env<TSchemaData>;
5760

61+
logDebug('env object ready: %o', env);
62+
5863
return env;
5964
}
6065

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,11 @@
984984
into-stream "^4.0.0"
985985
lodash "^4.17.4"
986986

987+
"@types/debug@^4.1.2":
988+
version "4.1.2"
989+
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.2.tgz#84824e9259fc583dd9385635738359c9582f7f82"
990+
integrity sha512-jkf6UiWUjcOqdQbatbvOm54/YbCdjt3JjiAzT/9KS2XtMmOkYHdKsI5u8fulhbuTUuiqNBfa6J5GSDiwjK+zLA==
991+
987992
"@types/jest@24.0.0":
988993
version "24.0.0"
989994
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.0.tgz#848492026c327b3548d92be0352a545c36a21e8a"

0 commit comments

Comments
 (0)