env-schema
Advanced tools
Comparing version 5.2.0 to 5.2.1
21
index.js
@@ -57,19 +57,16 @@ 'use strict' | ||
const schema = opts.schema | ||
const { schema } = opts | ||
schema.additionalProperties = false | ||
let data = opts.data | ||
if (!Array.isArray(opts.data)) { | ||
let { data, dotenv, env, expandEnv } = opts | ||
if (!Array.isArray(data)) { | ||
data = [data] | ||
} | ||
if (opts.dotenv) { | ||
require('dotenv').config(Object.assign({}, opts.dotenv)) | ||
if (dotenv) { | ||
require('dotenv').config(Object.assign({}, dotenv)) | ||
} | ||
/* istanbul ignore else */ | ||
if (opts.env) { | ||
if (opts.expandEnv) { | ||
require('dotenv-expand').expand({ parsed: process.env }) | ||
} | ||
if (env) { | ||
data.unshift(process.env) | ||
@@ -81,2 +78,6 @@ } | ||
if (expandEnv) { | ||
require('dotenv-expand').expand({ ignoreProcessEnv: true, parsed: merge }) | ||
} | ||
const ajv = chooseAjvInstance(sharedAjvInstance, opts.ajv) | ||
@@ -100,3 +101,3 @@ | ||
if (!(ajv instanceof Ajv)) { | ||
throw new Error('customOptions function must return an instance of Ajv') | ||
throw new TypeError('customOptions function must return an instance of Ajv') | ||
} | ||
@@ -103,0 +104,0 @@ return ajv |
{ | ||
"name": "env-schema", | ||
"version": "5.2.0", | ||
"version": "5.2.1", | ||
"description": "Validate your env variable using Ajv and dotenv", | ||
@@ -35,7 +35,7 @@ "main": "index.js", | ||
"dotenv": "^16.0.0", | ||
"dotenv-expand": "^9.0.0" | ||
"dotenv-expand": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"@fastify/pre-commit": "^2.0.2", | ||
"@sinclair/typebox": "^0.25.1", | ||
"@sinclair/typebox": "^0.31.1", | ||
"ajv-formats": "^2.1.1", | ||
@@ -46,3 +46,3 @@ "fluent-json-schema": "^4.0.0", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.24.1" | ||
"tsd": "^0.29.0" | ||
}, | ||
@@ -49,0 +49,0 @@ "pre-commit": [ |
@@ -10,2 +10,4 @@ # env-schema | ||
See [supporting resources](#supporting-resources) section for helpful guides on getting started. | ||
## Install | ||
@@ -104,2 +106,10 @@ | ||
### Order of configuration loading | ||
The order of precedence for configuration data is as follows, from least | ||
significant to most: | ||
1. Data sourced from `.env` file (when `dotenv` configuration option is set) | ||
2. Data sourced from environment variables in `process.env` | ||
3. Data provided via the `data` configuration option | ||
### Fluent-Schema API | ||
@@ -161,3 +171,3 @@ | ||
// config.data => ['127.0.0.1', '0.0.0.0'] | ||
// config.ALLOWED_HOSTS => ['127.0.0.1', '0.0.0.0'] | ||
``` | ||
@@ -251,2 +261,9 @@ | ||
## Supporting resources | ||
The following section lists helpful reference applications, articles, guides and other | ||
resources that demonstrate the use of env-schema in different use-cases and scenarios: | ||
* A reference application using [Fastify with env-schema and dotenv](https://github.com/lirantal/fastify-dotenv-envschema-example) | ||
## Acknowledgements | ||
@@ -253,0 +270,0 @@ |
@@ -5,3 +5,3 @@ 'use strict' | ||
const makeTest = require('./make-test') | ||
const { join } = require('path') | ||
const { join } = require('node:path') | ||
@@ -8,0 +8,0 @@ process.env.VALUE_FROM_ENV = 'pippo' |
@@ -6,3 +6,3 @@ 'use strict' | ||
const makeTest = require('./make-test') | ||
const { join } = require('path') | ||
const { join } = require('node:path') | ||
@@ -9,0 +9,0 @@ process.env.VALUE_FROM_ENV = 'pippo' |
@@ -5,3 +5,3 @@ 'use strict' | ||
const makeTest = require('./make-test') | ||
const { join } = require('path') | ||
const { join } = require('node:path') | ||
@@ -50,2 +50,26 @@ process.env.K8S_NAMESPACE = 'pippo' | ||
} | ||
}, | ||
{ | ||
name: 'simple object - ok - expandEnv works when passed an arbitrary new object based on process.env as data', | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
URL: { | ||
type: 'string' | ||
}, | ||
K8S_NAMESPACE: { | ||
type: 'string' | ||
} | ||
} | ||
}, | ||
expandEnv: true, | ||
isOk: true, | ||
data: { | ||
...process.env, | ||
K8S_NAMESPACE: 'hello' | ||
}, | ||
confExpected: { | ||
URL: 'https://prefix.hello.pluto.my.domain.com', | ||
K8S_NAMESPACE: 'hello' | ||
} | ||
} | ||
@@ -52,0 +76,0 @@ ] |
@@ -5,3 +5,3 @@ 'use strict' | ||
if (parseInt(process.versions.node.split('.')[0]) <= 8) { | ||
if (parseInt(process.versions.node.split('.', 1)[0]) <= 8) { | ||
t.skip('not supported') | ||
@@ -8,0 +8,0 @@ } else { |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
33088
17
1046
273
1
+ Addeddotenv-expand@10.0.0(transitive)
- Removeddotenv-expand@9.0.0(transitive)
Updateddotenv-expand@^10.0.0